OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | |
12 | |
13 #include "webrtc/base/checks.h" | |
14 #include "webrtc/base/logging.h" | |
15 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | |
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
17 | |
18 namespace webrtc { | |
19 // Absolute send time in RTP streams. | |
20 // | |
21 // The absolute send time is signaled to the receiver in-band using the | |
22 // general mechanism for RTP header extensions [RFC5285]. The payload | |
23 // of this extension (the transmitted value) is a 24-bit unsigned integer | |
24 // containing the sender's current time in seconds as a fixed point number | |
25 // with 18 bits fractional part. | |
26 // | |
27 // The form of the absolute send time extension block: | |
28 // | |
29 // 0 1 2 3 | |
30 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
32 // | ID | len=2 | absolute send time | | |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
34 const char* AbsoluteSendTime::kName = | |
35 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; | |
36 const uint8_t AbsoluteSendTime::kValueSizeBytes = 3; | |
37 bool AbsoluteSendTime::IsSupportedFor(MediaType type) { | |
38 return true; | |
39 } | |
40 | |
41 bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* value) { | |
42 *value = ByteReader<uint32_t, 3>::ReadBigEndian(data); | |
43 return true; | |
44 } | |
45 | |
46 bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) { | |
47 const uint32_t kAbsSendTimeFraction = 18; | |
48 uint32_t time_24_bits = | |
49 static_cast<uint32_t>(((time_ms << kAbsSendTimeFraction) + 500) / 1000) & | |
50 0x00FFFFFF; | |
51 | |
52 ByteWriter<uint32_t, 3>::WriteBigEndian(data, time_24_bits); | |
53 return time_24_bits; | |
54 } | |
55 | |
56 // An RTP Header Extension for Client-to-Mixer Audio Level Indication | |
57 // | |
58 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/ | |
59 // | |
60 // The form of the audio level extension block: | |
61 // | |
62 // 0 1 | |
63 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | |
64 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
65 // | ID | len=0 |V| level | | |
66 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
67 // | |
68 const char* AudioLevel::kName = "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; | |
69 const uint8_t AudioLevel::kValueSizeBytes = 1; | |
70 bool AudioLevel::IsSupportedFor(MediaType type) { | |
71 switch (type) { | |
72 case MediaType::ANY: | |
philipel
2016/04/13 12:01:18
Why does MediaType::ANY support this extension, sh
danilchap
2016/04/13 16:18:33
MediaType ANY seems used when caller doesn't not s
philipel
2016/04/14 10:32:02
Acknowledged.
| |
73 case MediaType::AUDIO: | |
74 return true; | |
75 case MediaType::VIDEO: | |
76 case MediaType::DATA: | |
77 return false; | |
78 } | |
79 RTC_NOTREACHED(); | |
80 return false; | |
81 } | |
82 | |
83 bool AudioLevel::Parse(const uint8_t* data, | |
84 bool* voice_activity, | |
85 uint8_t* audio_level) { | |
86 *voice_activity = (data[0] & 0x80) != 0; | |
87 *audio_level = data[0] & 0x7F; | |
88 return true; | |
89 } | |
90 | |
91 bool AudioLevel::Write(uint8_t* data, | |
92 bool voice_activity, | |
93 uint8_t audio_level) { | |
94 RTC_CHECK_LE(audio_level, 0x7f); | |
95 data[0] = (voice_activity ? 0x80 : 0x00) | audio_level; | |
96 return true; | |
97 } | |
98 | |
99 // From RFC 5450: Transmission Time Offsets in RTP Streams. | |
100 // | |
101 // The transmission time is signaled to the receiver in-band using the | |
102 // general mechanism for RTP header extensions [RFC5285]. The payload | |
103 // of this extension (the transmitted value) is a 24-bit signed integer. | |
104 // When added to the RTP timestamp of the packet, it represents the | |
105 // "effective" RTP transmission time of the packet, on the RTP | |
106 // timescale. | |
107 // | |
108 // The form of the transmission offset extension block: | |
109 // | |
110 // 0 1 2 3 | |
111 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
112 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
113 // | ID | len=2 | transmission offset | | |
114 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
115 const char* TransmissionOffset::kName = "urn:ietf:params:rtp-hdrext:toffset"; | |
116 const uint8_t TransmissionOffset::kValueSizeBytes = 3; | |
117 bool TransmissionOffset::IsSupportedFor(MediaType type) { | |
118 switch (type) { | |
119 case MediaType::ANY: | |
120 case MediaType::VIDEO: | |
121 return true; | |
122 case MediaType::AUDIO: | |
123 case MediaType::DATA: | |
124 return false; | |
125 } | |
126 RTC_NOTREACHED(); | |
127 return false; | |
128 } | |
129 | |
130 bool TransmissionOffset::Parse(const uint8_t* data, int32_t* value) { | |
131 *value = ByteReader<int32_t, 3>::ReadBigEndian(data); | |
132 return true; | |
133 } | |
134 | |
135 bool TransmissionOffset::Write(uint8_t* data, int64_t value) { | |
136 RTC_CHECK_LE(value, 0x00ffffff); | |
137 ByteWriter<int32_t, 3>::WriteBigEndian(data, value); | |
138 return true; | |
139 } | |
140 | |
141 // 0 1 2 | |
142 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 | |
143 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
144 // | ID | L=1 |transport wide sequence number | | |
145 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
146 const char* TransportSequenceNumber::kName = | |
147 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions"; | |
148 const uint8_t TransportSequenceNumber::kValueSizeBytes = 2; | |
149 bool TransportSequenceNumber::IsSupportedFor(MediaType type) { | |
150 return true; | |
151 } | |
152 | |
153 bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) { | |
154 *value = ByteReader<uint16_t>::ReadBigEndian(data); | |
155 return true; | |
156 } | |
157 | |
158 bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) { | |
159 ByteWriter<uint16_t>::WriteBigEndian(data, value); | |
160 return true; | |
161 } | |
162 | |
163 // Coordination of Video Orientation in RTP streams. | |
164 // | |
165 // Coordination of Video Orientation consists in signaling of the current | |
166 // orientation of the image captured on the sender side to the receiver for | |
167 // appropriate rendering and displaying. | |
168 // | |
169 // 0 1 | |
170 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | |
171 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
172 // | ID | len=0 |0 0 0 0 C F R R| | |
173 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
174 const char* VideoOrientation::kName = "urn:3gpp:video-orientation"; | |
175 const uint8_t VideoOrientation::kValueSizeBytes = 1; | |
176 bool VideoOrientation::IsSupportedFor(MediaType type) { | |
177 switch (type) { | |
178 case MediaType::ANY: | |
philipel
2016/04/13 12:01:18
Again, should MediaType::ANY support video orienta
| |
179 case MediaType::VIDEO: | |
180 return true; | |
181 case MediaType::AUDIO: | |
182 case MediaType::DATA: | |
183 return false; | |
184 } | |
185 RTC_NOTREACHED(); | |
186 return false; | |
187 } | |
188 | |
189 bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) { | |
190 *rotation = ConvertCVOByteToVideoRotation(data[0] & 0x03); | |
191 return true; | |
192 } | |
193 | |
194 bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) { | |
195 data[0] = ConvertVideoRotationToCVOByte(rotation); | |
196 return true; | |
197 } | |
198 | |
199 bool VideoOrientation::Parse(const uint8_t* data, uint8_t* value) { | |
200 *value = data[0]; | |
201 return true; | |
202 } | |
203 | |
204 bool VideoOrientation::Write(uint8_t* data, uint8_t value) { | |
205 data[0] = value; | |
206 return true; | |
207 } | |
208 } // namespace webrtc | |
OLD | NEW |