|
5 | 5 |
|
6 | 6 | namespace SharpRTSPServer |
7 | 7 | { |
| 8 | + /// <summary> |
| 9 | + /// G711 PCMU (U-LAW) track. |
| 10 | + /// </summary> |
8 | 11 | public class PCMUTrack : ITrack |
9 | 12 | { |
| 13 | + /// <summary> |
| 14 | + /// PCMU Audio Codec name. |
| 15 | + /// </summary> |
| 16 | + public string Codec => "PCMU"; |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// Track ID. Used to identify the track in the SDP. |
| 20 | + /// </summary> |
10 | 21 | public int ID { get; set; } = 1; |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Sampling rate. |
| 25 | + /// </summary> |
11 | 26 | public int SamplingRate { get; } = 8000; |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Number of channels. 1 for Mono. |
| 30 | + /// </summary> |
12 | 31 | public int Channels { get; } = 1; |
13 | 32 |
|
| 33 | + /// <summary> |
| 34 | + /// Is the track ready? |
| 35 | + /// </summary> |
14 | 36 | public bool IsReady { get { return true; } } |
15 | 37 |
|
| 38 | + /// <summary> |
| 39 | + /// Payload type. PCMU uses static payload type 0. |
| 40 | + /// </summary> |
16 | 41 | public int PayloadType { get; set; } = 0; |
17 | 42 |
|
| 43 | + /// <summary> |
| 44 | + /// Build the SDP for this track. |
| 45 | + /// </summary> |
| 46 | + /// <param name="sdp">SDP <see cref="StringBuilder"/>.</param> |
| 47 | + /// <returns><see cref="StringBuilder"/>.</returns> |
18 | 48 | public StringBuilder BuildSDP(StringBuilder sdp) |
19 | 49 | { |
20 | | - sdp.Append($"m=audio 0 RTP/AVP {PayloadType}\n"); // <---- Payload Type 0 means G711 ULAW |
| 50 | + sdp.Append($"m=audio 0 RTP/AVP {PayloadType}\n"); |
21 | 51 | sdp.Append($"a=control:trackID={ID}\n"); |
22 | | - sdp.Append($"a=rtpmap:{PayloadType} PCMU/{SamplingRate}\n"); |
| 52 | + sdp.Append($"a=rtpmap:{PayloadType} {Codec}/{SamplingRate}\n"); |
23 | 53 | return sdp; |
24 | 54 | } |
25 | 55 |
|
| 56 | + /// <summary> |
| 57 | + /// Creates RTP packets. |
| 58 | + /// </summary> |
| 59 | + /// <param name="samples">An array of PCMU fragments. By default single fragment is expected.</param> |
| 60 | + /// <param name="rtpTimestamp">RTP timestamp in the timescale of the track.</param> |
| 61 | + /// <returns>RTP packets.</returns> |
26 | 62 | public (List<Memory<byte>>, List<IMemoryOwner<byte>>) CreateRtpPackets(List<byte[]> samples, uint rtpTimestamp) |
27 | 63 | { |
28 | 64 | List<Memory<byte>> rtpPackets = new List<Memory<byte>>(); |
@@ -54,24 +90,60 @@ public StringBuilder BuildSDP(StringBuilder sdp) |
54 | 90 | } |
55 | 91 | } |
56 | 92 |
|
| 93 | + /// <summary> |
| 94 | + /// G711 PCMA (A-LAW) track. |
| 95 | + /// </summary> |
57 | 96 | public class PCMATrack : ITrack |
58 | 97 | { |
| 98 | + /// <summary> |
| 99 | + /// PCMA Audio Codec name. |
| 100 | + /// </summary> |
| 101 | + public string Codec => "PCMA"; |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Track ID. Used to identify the track in the SDP. |
| 105 | + /// </summary> |
59 | 106 | public int ID { get; set; } = 1; |
| 107 | + |
| 108 | + /// <summary> |
| 109 | + /// Sampling rate. |
| 110 | + /// </summary> |
60 | 111 | public int SamplingRate { get; } = 8000; |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// Number of channels. 1 for Mono. |
| 115 | + /// </summary> |
61 | 116 | public int Channels { get; } = 1; |
62 | 117 |
|
| 118 | + /// <summary> |
| 119 | + /// Is the track ready? |
| 120 | + /// </summary> |
63 | 121 | public bool IsReady { get { return true; } } |
64 | 122 |
|
| 123 | + /// <summary> |
| 124 | + /// Payload type. PCMA uses static payload type 8. |
| 125 | + /// </summary> |
65 | 126 | public int PayloadType { get; set; } = 8; |
66 | 127 |
|
| 128 | + /// <summary> |
| 129 | + /// Build the SDP for this track. |
| 130 | + /// </summary> |
| 131 | + /// <param name="sdp">SDP <see cref="StringBuilder"/>.</param> |
| 132 | + /// <returns><see cref="StringBuilder"/>.</returns> |
67 | 133 | public StringBuilder BuildSDP(StringBuilder sdp) |
68 | 134 | { |
69 | | - sdp.Append($"m=audio 0 RTP/AVP {PayloadType}\n"); // <---- Payload Type 8 means G711 ALAW |
| 135 | + sdp.Append($"m=audio 0 RTP/AVP {PayloadType}\n"); |
70 | 136 | sdp.Append($"a=control:trackID={ID}\n"); |
71 | | - sdp.Append($"a=rtpmap:{PayloadType} PCMA/{SamplingRate}\n"); |
| 137 | + sdp.Append($"a=rtpmap:{PayloadType} {Codec}/{SamplingRate}\n"); |
72 | 138 | return sdp; |
73 | 139 | } |
74 | 140 |
|
| 141 | + /// <summary> |
| 142 | + /// Creates RTP packets. |
| 143 | + /// </summary> |
| 144 | + /// <param name="samples">An array of PCMA fragments. By default single fragment is expected.</param> |
| 145 | + /// <param name="rtpTimestamp">RTP timestamp in the timescale of the track.</param> |
| 146 | + /// <returns>RTP packets.</returns> |
75 | 147 | public (List<Memory<byte>>, List<IMemoryOwner<byte>>) CreateRtpPackets(List<byte[]> samples, uint rtpTimestamp) |
76 | 148 | { |
77 | 149 | List<Memory<byte>> rtpPackets = new List<Memory<byte>>(); |
|
0 commit comments