OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "webrtc/transport.h" | 33 #include "webrtc/transport.h" |
34 | 34 |
35 namespace webrtc { | 35 namespace webrtc { |
36 | 36 |
37 class RateLimiter; | 37 class RateLimiter; |
38 class RtcEventLog; | 38 class RtcEventLog; |
39 class RtpPacketToSend; | 39 class RtpPacketToSend; |
40 class RTPSenderAudio; | 40 class RTPSenderAudio; |
41 class RTPSenderVideo; | 41 class RTPSenderVideo; |
42 | 42 |
43 class RTPSenderInterface { | 43 class RTPSender { |
44 public: | |
45 RTPSenderInterface() {} | |
46 virtual ~RTPSenderInterface() {} | |
47 | |
48 virtual uint32_t SSRC() const = 0; | |
49 virtual uint32_t Timestamp() const = 0; | |
50 | |
51 // Deprecated version of BuildRtpHeader(). |timestamp_provided| and | |
52 // |inc_sequence_number| are ignored. | |
53 // TODO(sergeyu): Remove this method. | |
54 virtual int32_t BuildRTPheader(uint8_t* data_buffer, | |
55 int8_t payload_type, | |
56 bool marker_bit, | |
57 uint32_t capture_timestamp, | |
58 int64_t capture_time_ms, | |
59 bool timestamp_provided = true, | |
60 bool inc_sequence_number = true) = 0; | |
61 | |
62 virtual int32_t BuildRtpHeader(uint8_t* data_buffer, | |
63 int8_t payload_type, | |
64 bool marker_bit, | |
65 uint32_t capture_timestamp, | |
66 int64_t capture_time_ms) = 0; | |
67 | |
68 // This returns the expected header length taking into consideration | |
69 // the optional RTP header extensions that may not be currently active. | |
70 virtual size_t RtpHeaderLength() const = 0; | |
71 // Returns the next sequence number to use for a packet and allocates | |
72 // 'packets_to_send' number of sequence numbers. It's important all allocated | |
73 // sequence numbers are used in sequence to avoid perceived packet loss. | |
74 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; | |
75 virtual uint16_t SequenceNumber() const = 0; | |
76 virtual size_t MaxPayloadLength() const = 0; | |
77 virtual size_t MaxDataPayloadLength() const = 0; | |
78 virtual uint16_t ActualSendBitrateKbit() const = 0; | |
79 | |
80 virtual bool SendToNetwork(uint8_t* data_buffer, | |
81 size_t payload_length, | |
82 size_t rtp_header_length, | |
83 int64_t capture_time_ms, | |
84 StorageType storage, | |
85 RtpPacketSender::Priority priority) = 0; | |
86 | |
87 virtual bool UpdateVideoRotation(uint8_t* rtp_packet, | |
88 size_t rtp_packet_length, | |
89 const RTPHeader& rtp_header, | |
90 VideoRotation rotation) const = 0; | |
91 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0; | |
92 virtual bool ActivateCVORtpHeaderExtension() = 0; | |
93 }; | |
94 | |
95 class RTPSender : public RTPSenderInterface { | |
96 public: | 44 public: |
97 RTPSender(bool audio, | 45 RTPSender(bool audio, |
98 Clock* clock, | 46 Clock* clock, |
99 Transport* transport, | 47 Transport* transport, |
100 RtpPacketSender* paced_sender, | 48 RtpPacketSender* paced_sender, |
101 TransportSequenceNumberAllocator* sequence_number_allocator, | 49 TransportSequenceNumberAllocator* sequence_number_allocator, |
102 TransportFeedbackObserver* transport_feedback_callback, | 50 TransportFeedbackObserver* transport_feedback_callback, |
103 BitrateStatisticsObserver* bitrate_callback, | 51 BitrateStatisticsObserver* bitrate_callback, |
104 FrameCountObserver* frame_count_observer, | 52 FrameCountObserver* frame_count_observer, |
105 SendSideDelayObserver* send_side_delay_observer, | 53 SendSideDelayObserver* send_side_delay_observer, |
106 RtcEventLog* event_log, | 54 RtcEventLog* event_log, |
107 SendPacketObserver* send_packet_observer, | 55 SendPacketObserver* send_packet_observer, |
108 RateLimiter* nack_rate_limiter); | 56 RateLimiter* nack_rate_limiter); |
109 | 57 |
110 virtual ~RTPSender(); | 58 ~RTPSender(); |
111 | 59 |
112 void ProcessBitrate(); | 60 void ProcessBitrate(); |
113 | 61 |
114 uint16_t ActualSendBitrateKbit() const override; | 62 uint16_t ActualSendBitrateKbit() const; |
115 | 63 |
116 uint32_t VideoBitrateSent() const; | 64 uint32_t VideoBitrateSent() const; |
117 uint32_t FecOverheadRate() const; | 65 uint32_t FecOverheadRate() const; |
118 uint32_t NackOverheadRate() const; | 66 uint32_t NackOverheadRate() const; |
119 | 67 |
120 // Includes size of RTP and FEC headers. | 68 // Includes size of RTP and FEC headers. |
121 size_t MaxDataPayloadLength() const override; | 69 size_t MaxDataPayloadLength() const; |
122 | 70 |
123 int32_t RegisterPayload(const char* payload_name, | 71 int32_t RegisterPayload(const char* payload_name, |
124 const int8_t payload_type, | 72 const int8_t payload_type, |
125 const uint32_t frequency, | 73 const uint32_t frequency, |
126 const size_t channels, | 74 const size_t channels, |
127 const uint32_t rate); | 75 const uint32_t rate); |
128 | 76 |
129 int32_t DeRegisterSendPayload(const int8_t payload_type); | 77 int32_t DeRegisterSendPayload(const int8_t payload_type); |
130 | 78 |
131 void SetSendPayloadType(int8_t payload_type); | 79 void SetSendPayloadType(int8_t payload_type); |
132 | 80 |
133 int8_t SendPayloadType() const; | 81 int8_t SendPayloadType() const; |
134 | 82 |
135 int SendPayloadFrequency() const; | 83 int SendPayloadFrequency() const; |
136 | 84 |
137 void SetSendingStatus(bool enabled); | 85 void SetSendingStatus(bool enabled); |
138 | 86 |
139 void SetSendingMediaStatus(bool enabled); | 87 void SetSendingMediaStatus(bool enabled); |
140 bool SendingMedia() const; | 88 bool SendingMedia() const; |
141 | 89 |
142 void GetDataCounters(StreamDataCounters* rtp_stats, | 90 void GetDataCounters(StreamDataCounters* rtp_stats, |
143 StreamDataCounters* rtx_stats) const; | 91 StreamDataCounters* rtx_stats) const; |
144 | 92 |
145 uint32_t StartTimestamp() const; | 93 uint32_t StartTimestamp() const; |
146 void SetStartTimestamp(uint32_t timestamp, bool force); | 94 void SetStartTimestamp(uint32_t timestamp, bool force); |
147 | 95 |
148 uint32_t GenerateNewSSRC(); | 96 uint32_t GenerateNewSSRC(); |
149 void SetSSRC(uint32_t ssrc); | 97 void SetSSRC(uint32_t ssrc); |
150 | 98 |
151 uint16_t SequenceNumber() const override; | 99 uint16_t SequenceNumber() const; |
152 void SetSequenceNumber(uint16_t seq); | 100 void SetSequenceNumber(uint16_t seq); |
153 | 101 |
154 void SetCsrcs(const std::vector<uint32_t>& csrcs); | 102 void SetCsrcs(const std::vector<uint32_t>& csrcs); |
155 | 103 |
156 void SetMaxPayloadLength(size_t max_payload_length); | 104 void SetMaxPayloadLength(size_t max_payload_length); |
157 | 105 |
158 bool SendOutgoingData(FrameType frame_type, | 106 bool SendOutgoingData(FrameType frame_type, |
159 int8_t payload_type, | 107 int8_t payload_type, |
160 uint32_t timestamp, | 108 uint32_t timestamp, |
161 int64_t capture_time_ms, | 109 int64_t capture_time_ms, |
162 const uint8_t* payload_data, | 110 const uint8_t* payload_data, |
163 size_t payload_size, | 111 size_t payload_size, |
164 const RTPFragmentationHeader* fragmentation, | 112 const RTPFragmentationHeader* fragmentation, |
165 const RTPVideoHeader* rtp_header, | 113 const RTPVideoHeader* rtp_header, |
166 uint32_t* transport_frame_id_out); | 114 uint32_t* transport_frame_id_out); |
167 | 115 |
168 // RTP header extension | 116 // RTP header extension |
169 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); | 117 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset); |
170 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); | 118 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time); |
171 void SetVideoRotation(VideoRotation rotation); | 119 void SetVideoRotation(VideoRotation rotation); |
172 int32_t SetTransportSequenceNumber(uint16_t sequence_number); | 120 int32_t SetTransportSequenceNumber(uint16_t sequence_number); |
173 | 121 |
174 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); | 122 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); |
175 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override; | 123 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type); |
176 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); | 124 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); |
177 | 125 |
178 size_t RtpHeaderExtensionLength() const; | 126 size_t RtpHeaderExtensionLength() const; |
179 | 127 |
180 uint16_t BuildRtpHeaderExtension(uint8_t* data_buffer, bool marker_bit) const | 128 uint16_t BuildRtpHeaderExtension(uint8_t* data_buffer, bool marker_bit) const |
181 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_); | 129 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_); |
182 | 130 |
183 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t* data_buffer) const | 131 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t* data_buffer) const |
184 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_); | 132 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_); |
185 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const | 133 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 165 |
218 bool UpdateAudioLevel(uint8_t* rtp_packet, | 166 bool UpdateAudioLevel(uint8_t* rtp_packet, |
219 size_t rtp_packet_length, | 167 size_t rtp_packet_length, |
220 const RTPHeader& rtp_header, | 168 const RTPHeader& rtp_header, |
221 bool is_voiced, | 169 bool is_voiced, |
222 uint8_t dBov) const; | 170 uint8_t dBov) const; |
223 | 171 |
224 bool UpdateVideoRotation(uint8_t* rtp_packet, | 172 bool UpdateVideoRotation(uint8_t* rtp_packet, |
225 size_t rtp_packet_length, | 173 size_t rtp_packet_length, |
226 const RTPHeader& rtp_header, | 174 const RTPHeader& rtp_header, |
227 VideoRotation rotation) const override; | 175 VideoRotation rotation) const; |
228 | 176 |
229 bool TimeToSendPacket(uint16_t sequence_number, | 177 bool TimeToSendPacket(uint16_t sequence_number, |
230 int64_t capture_time_ms, | 178 int64_t capture_time_ms, |
231 bool retransmission, | 179 bool retransmission, |
232 int probe_cluster_id); | 180 int probe_cluster_id); |
233 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id); | 181 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id); |
234 | 182 |
235 // NACK. | 183 // NACK. |
236 int SelectiveRetransmissions() const; | 184 int SelectiveRetransmissions() const; |
237 int SetSelectiveRetransmissions(uint8_t settings); | 185 int SetSelectiveRetransmissions(uint8_t settings); |
(...skipping 18 matching lines...) Expand all Loading... |
256 | 204 |
257 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 205 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
258 | 206 |
259 // Functions wrapping RTPSenderInterface. | 207 // Functions wrapping RTPSenderInterface. |
260 int32_t BuildRTPheader(uint8_t* data_buffer, | 208 int32_t BuildRTPheader(uint8_t* data_buffer, |
261 int8_t payload_type, | 209 int8_t payload_type, |
262 bool marker_bit, | 210 bool marker_bit, |
263 uint32_t capture_timestamp, | 211 uint32_t capture_timestamp, |
264 int64_t capture_time_ms, | 212 int64_t capture_time_ms, |
265 bool timestamp_provided = true, | 213 bool timestamp_provided = true, |
266 bool inc_sequence_number = true) override; | 214 bool inc_sequence_number = true); |
267 int32_t BuildRtpHeader(uint8_t* data_buffer, | 215 int32_t BuildRtpHeader(uint8_t* data_buffer, |
268 int8_t payload_type, | 216 int8_t payload_type, |
269 bool marker_bit, | 217 bool marker_bit, |
270 uint32_t capture_timestamp, | 218 uint32_t capture_timestamp, |
271 int64_t capture_time_ms) override; | 219 int64_t capture_time_ms); |
272 | 220 |
273 size_t RtpHeaderLength() const override; | 221 size_t RtpHeaderLength() const; |
274 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override; | 222 uint16_t AllocateSequenceNumber(uint16_t packets_to_send); |
275 size_t MaxPayloadLength() const override; | 223 size_t MaxPayloadLength() const; |
276 | 224 |
277 // Current timestamp. | 225 // Current timestamp. |
278 uint32_t Timestamp() const override; | 226 uint32_t Timestamp() const; |
279 uint32_t SSRC() const override; | 227 uint32_t SSRC() const; |
280 | 228 |
281 // Deprecated. Create RtpPacketToSend instead and use next function. | 229 // Deprecated. Create RtpPacketToSend instead and use next function. |
282 bool SendToNetwork(uint8_t* data_buffer, | 230 bool SendToNetwork(uint8_t* data_buffer, |
283 size_t payload_length, | 231 size_t payload_length, |
284 size_t rtp_header_length, | 232 size_t rtp_header_length, |
285 int64_t capture_time_ms, | 233 int64_t capture_time_ms, |
286 StorageType storage, | 234 StorageType storage, |
287 RtpPacketSender::Priority priority) override; | 235 RtpPacketSender::Priority priority); |
288 bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, | 236 bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
289 StorageType storage, | 237 StorageType storage, |
290 RtpPacketSender::Priority priority); | 238 RtpPacketSender::Priority priority); |
291 | 239 |
292 // Audio. | 240 // Audio. |
293 | 241 |
294 // Send a DTMF tone using RFC 2833 (4733). | 242 // Send a DTMF tone using RFC 2833 (4733). |
295 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level); | 243 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level); |
296 | 244 |
297 // Set audio packet size, used to determine when it's time to send a DTMF | 245 // Set audio packet size, used to determine when it's time to send a DTMF |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Called on update of RTP statistics. | 285 // Called on update of RTP statistics. |
338 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); | 286 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); |
339 StreamDataCountersCallback* GetRtpStatisticsCallback() const; | 287 StreamDataCountersCallback* GetRtpStatisticsCallback() const; |
340 | 288 |
341 uint32_t BitrateSent() const; | 289 uint32_t BitrateSent() const; |
342 | 290 |
343 void SetRtpState(const RtpState& rtp_state); | 291 void SetRtpState(const RtpState& rtp_state); |
344 RtpState GetRtpState() const; | 292 RtpState GetRtpState() const; |
345 void SetRtxRtpState(const RtpState& rtp_state); | 293 void SetRtxRtpState(const RtpState& rtp_state); |
346 RtpState GetRtxRtpState() const; | 294 RtpState GetRtxRtpState() const; |
347 bool ActivateCVORtpHeaderExtension() override; | 295 bool ActivateCVORtpHeaderExtension(); |
348 | 296 |
349 protected: | 297 protected: |
350 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); | 298 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); |
351 | 299 |
352 private: | 300 private: |
353 // Maps capture time in milliseconds to send-side delay in milliseconds. | 301 // Maps capture time in milliseconds to send-side delay in milliseconds. |
354 // Send-side delay is the difference between transmission time and capture | 302 // Send-side delay is the difference between transmission time and capture |
355 // time. | 303 // time. |
356 typedef std::map<int64_t, int> SendDelayMap; | 304 typedef std::map<int64_t, int> SendDelayMap; |
357 | 305 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); | 429 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); |
482 | 430 |
483 RateLimiter* const retransmission_rate_limiter_; | 431 RateLimiter* const retransmission_rate_limiter_; |
484 | 432 |
485 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); | 433 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
486 }; | 434 }; |
487 | 435 |
488 } // namespace webrtc | 436 } // namespace webrtc |
489 | 437 |
490 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 438 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
OLD | NEW |