-
Notifications
You must be signed in to change notification settings - Fork 0
/
RtpExtensionHeader.cs
79 lines (69 loc) · 2.48 KB
/
RtpExtensionHeader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: AGPL-3.0-only
/**
* Digital Voice Modem - Fixed Network Equipment Core Library
* AGPLv3 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Fixed Network Equipment Core Library
* @license AGPLv3 License (https://opensource.org/licenses/AGPL-3.0)
*
* Copyright (C) 2023 Bryan Biedenkapp, N2PLL
*
*/
using System;
namespace fnecore
{
/// <summary>
///
/// </summary>
public class RtpExtensionHeader
{
protected int offset = 0;
/// <summary>
/// Format of the extension header payload contained within the packet.
/// </summary>
public ushort PayloadType { get; set; }
/// <summary>
/// Length of the extension header payload (in 32-bit units).
/// </summary>
public ushort PayloadLength { get; set; }
/*
** Methods
*/
/// <summary>
/// Initializes a new instance of the <see cref="RtpExtensionHeader"/> class.
/// </summary>
/// <param name="offset"></param>
public RtpExtensionHeader(int offset = 12) // 12 bytes is the length of the RTP Header
{
this.offset = offset;
PayloadType = 0;
PayloadLength = 0;
}
/// <summary>
/// Decode a RTP header.
/// </summary>
/// <param name="data"></param>
public virtual bool Decode(byte[] data)
{
if (data == null)
return false;
PayloadType = (ushort)((data[0 + offset] << 8) | (data[1 + offset] << 0)); // Payload Type
PayloadLength = (ushort)((data[2 + offset] << 8) | (data[3 + offset] << 0)); // Payload Length
return true;
}
/// <summary>
/// Encode a RTP header.
/// </summary>
/// <param name="data"></param>
public virtual void Encode(ref byte[] data)
{
if (data == null)
return;
data[0 + offset] = (byte)((PayloadType >> 8) & 0xFFU); // Payload Type MSB
data[1 + offset] = (byte)((PayloadType >> 0) & 0xFFU); // Payload Type LSB
data[2 + offset] = (byte)((PayloadLength >> 8) & 0xFFU); // Payload Length MSB
data[3 + offset] = (byte)((PayloadLength >> 0) & 0xFFU); // Payload Length LSB
}
} // public class RtpExtensionHeader
} // namespace fnecore