forked from sipsorcery-org/sipsorcery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTPHeaderExtension.cs
More file actions
135 lines (114 loc) · 4.53 KB
/
RTPHeaderExtension.cs
File metadata and controls
135 lines (114 loc) · 4.53 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
namespace SIPSorcery.Net
{
public abstract class RTPHeaderExtension
{
/// <summary>
/// Create an RTPHeaderExtension (<see cref="AbsSendTimeExtension"/>, <see cref="CVOExtension"/>, etc ...) based on the URI provided
/// If found, id permits to store the "extmap" value related to this extension
/// It not found returns null
/// </summary>
/// <param name="id">extmap value</param>
/// <param name="uri">URI of the extension - for example: "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" or "urn:3gpp:video-orientation" </param>
/// <returns>A Specific RTPHeaderExtension</returns>
public static RTPHeaderExtension GetRTPHeaderExtension(int id, string uri, SDPMediaTypesEnum media)
{
RTPHeaderExtension result = null;
switch (uri)
{
case AbsSendTimeExtension.RTP_HEADER_EXTENSION_URI:
result = new AbsSendTimeExtension(id);
break;
case CVOExtension.RTP_HEADER_EXTENSION_URI:
result = new CVOExtension(id);
break;
case AudioLevelExtension.RTP_HEADER_EXTENSION_URI:
result = new AudioLevelExtension(id);
break;
case TransportWideCCExtension.RTP_HEADER_EXTENSION_URI:
//case TransportWideCCExtension.RTP_HEADER_EXTENSION_URI_ALT:
result = new TransportWideCCExtension(id);
break;
}
if ( (result != null) && result.IsMediaSupported(media) )
{
return result;
}
return null;
}
/// <summary>
/// To create a RTP Header Extension
/// </summary>
/// <param name="id"><see cref="int"/> Id / extmap</param>
/// <param name="uri"><see cref="String"/>uri</param>
/// <param name="type"><see cref="RTPHeaderExtension"/>type (one or two bytes)</param>
/// <param name="medias"><see cref="SDPMediaTypesEnum"/>media(s) supported by this extension - set null/empty if all medias are supported</param>
public RTPHeaderExtension(int id, string uri, int extensionSize, RTPHeaderExtensionType type, params SDPMediaTypesEnum[] medias )
{
Id = id;
Uri = uri;
ExtensionSize = extensionSize;
Type = type;
if (medias != null)
{
Medias = medias.ToList();
}
else
{
Medias = new List<SDPMediaTypesEnum>();
}
}
/// <summary>
/// Checks if the URI provided matches the URI of this extension
/// Override this method if the extension can have multiple URIs (for example TransportWideCCExtension)
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
public virtual bool MatchesExtension(string uri)
{
return Uri.Equals(uri, StringComparison.InvariantCultureIgnoreCase);
}
// Id / "extmap"
public int Id { get; internal set; }
// Uri
public string Uri { get; set; }
public int ExtensionSize { get; }
// Medias supported by this extension - if null/empty all medias are supported
public List<SDPMediaTypesEnum> Medias { get;}
// Type (one or two bytes)
public RTPHeaderExtensionType Type { get; }
public Boolean IsMediaSupported(SDPMediaTypesEnum media)
{
if (Medias.Count == 0)
{
return true;
}
return Medias.Contains(media);
}
// Function to call to set a new value to this extension
public abstract void Set(Object obj);
// Function to call to get the payload when writting the RTP header
public abstract byte[] Marshal();
// Function to call when reading the RTP header
public abstract Object Unmarshal(RTPHeader header, byte[] data);
}
public enum RTPHeaderExtensionType
{
OneByte,
TwoByte
}
public class RTPHeaderExtensionData
{
public RTPHeaderExtensionData(int id, byte[] data, RTPHeaderExtensionType type)
{
Id = id;
Data = data;
Type = type;
}
public int Id { get; }
public byte[] Data { get; }
public RTPHeaderExtensionType Type { get; }
}
}