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 |
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
23 #include "webrtc/base/rate_statistics.h" | |
23 #include "webrtc/base/thread_annotations.h" | 24 #include "webrtc/base/thread_annotations.h" |
24 #include "webrtc/common_types.h" | 25 #include "webrtc/common_types.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
26 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | |
27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" | 27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
30 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
31 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 31 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
32 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" | 32 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" |
33 #include "webrtc/transport.h" | 33 #include "webrtc/transport.h" |
34 | 34 |
35 namespace webrtc { | 35 namespace webrtc { |
36 | 36 |
(...skipping 20 matching lines...) Expand all Loading... | |
57 // This returns the expected header length taking into consideration | 57 // This returns the expected header length taking into consideration |
58 // the optional RTP header extensions that may not be currently active. | 58 // the optional RTP header extensions that may not be currently active. |
59 virtual size_t RtpHeaderLength() const = 0; | 59 virtual size_t RtpHeaderLength() const = 0; |
60 // Returns the next sequence number to use for a packet and allocates | 60 // Returns the next sequence number to use for a packet and allocates |
61 // 'packets_to_send' number of sequence numbers. It's important all allocated | 61 // 'packets_to_send' number of sequence numbers. It's important all allocated |
62 // sequence numbers are used in sequence to avoid perceived packet loss. | 62 // sequence numbers are used in sequence to avoid perceived packet loss. |
63 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; | 63 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0; |
64 virtual uint16_t SequenceNumber() const = 0; | 64 virtual uint16_t SequenceNumber() const = 0; |
65 virtual size_t MaxPayloadLength() const = 0; | 65 virtual size_t MaxPayloadLength() const = 0; |
66 virtual size_t MaxDataPayloadLength() const = 0; | 66 virtual size_t MaxDataPayloadLength() const = 0; |
67 virtual uint16_t ActualSendBitrateKbit() const = 0; | 67 virtual uint16_t ActualSendBitrateKbit() = 0; |
68 | 68 |
69 virtual int32_t SendToNetwork(uint8_t* data_buffer, | 69 virtual int32_t SendToNetwork(uint8_t* data_buffer, |
70 size_t payload_length, | 70 size_t payload_length, |
71 size_t rtp_header_length, | 71 size_t rtp_header_length, |
72 int64_t capture_time_ms, | 72 int64_t capture_time_ms, |
73 StorageType storage, | 73 StorageType storage, |
74 RtpPacketSender::Priority priority) = 0; | 74 RtpPacketSender::Priority priority) = 0; |
75 | 75 |
76 virtual bool UpdateVideoRotation(uint8_t* rtp_packet, | 76 virtual bool UpdateVideoRotation(uint8_t* rtp_packet, |
77 size_t rtp_packet_length, | 77 size_t rtp_packet_length, |
(...skipping 14 matching lines...) Expand all Loading... | |
92 BitrateStatisticsObserver* bitrate_callback, | 92 BitrateStatisticsObserver* bitrate_callback, |
93 FrameCountObserver* frame_count_observer, | 93 FrameCountObserver* frame_count_observer, |
94 SendSideDelayObserver* send_side_delay_observer, | 94 SendSideDelayObserver* send_side_delay_observer, |
95 RtcEventLog* event_log, | 95 RtcEventLog* event_log, |
96 SendPacketObserver* send_packet_observer); | 96 SendPacketObserver* send_packet_observer); |
97 | 97 |
98 virtual ~RTPSender(); | 98 virtual ~RTPSender(); |
99 | 99 |
100 void ProcessBitrate(); | 100 void ProcessBitrate(); |
101 | 101 |
102 uint16_t ActualSendBitrateKbit() const override; | 102 uint16_t ActualSendBitrateKbit() override; |
103 | 103 |
104 uint32_t VideoBitrateSent() const; | 104 uint32_t VideoBitrateSent() const; |
105 uint32_t FecOverheadRate() const; | 105 uint32_t FecOverheadRate() const; |
106 uint32_t NackOverheadRate() const; | 106 uint32_t NackOverheadRate(); |
107 | 107 |
108 void SetTargetBitrate(uint32_t bitrate); | 108 void SetTargetBitrate(uint32_t bitrate); |
109 uint32_t GetTargetBitrate(); | 109 uint32_t GetTargetBitrate(); |
110 | 110 |
111 // Includes size of RTP and FEC headers. | 111 // Includes size of RTP and FEC headers. |
112 size_t MaxDataPayloadLength() const override; | 112 size_t MaxDataPayloadLength() const override; |
113 | 113 |
114 int32_t RegisterPayload(const char* payload_name, | 114 int32_t RegisterPayload(const char* payload_name, |
115 const int8_t payload_type, | 115 const int8_t payload_type, |
116 const uint32_t frequency, | 116 const uint32_t frequency, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 int SetSelectiveRetransmissions(uint8_t settings); | 220 int SetSelectiveRetransmissions(uint8_t settings); |
221 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, | 221 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, |
222 int64_t avg_rtt); | 222 int64_t avg_rtt); |
223 | 223 |
224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); | 224 void SetStorePacketsStatus(bool enable, uint16_t number_to_store); |
225 | 225 |
226 bool StorePackets() const; | 226 bool StorePackets() const; |
227 | 227 |
228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); | 228 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); |
229 | 229 |
230 bool ProcessNACKBitRate(uint32_t now); | |
231 | |
232 // Feedback to decide when to stop sending playout delay. | 230 // Feedback to decide when to stop sending playout delay. |
233 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); | 231 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); |
234 | 232 |
235 // RTX. | 233 // RTX. |
236 void SetRtxStatus(int mode); | 234 void SetRtxStatus(int mode); |
237 int RtxStatus() const; | 235 int RtxStatus() const; |
238 | 236 |
239 uint32_t RtxSsrc() const; | 237 uint32_t RtxSsrc() const; |
240 void SetRtxSsrc(uint32_t ssrc); | 238 void SetRtxSsrc(uint32_t ssrc); |
241 | 239 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 size_t SendPadData(size_t bytes, | 306 size_t SendPadData(size_t bytes, |
309 bool timestamp_provided, | 307 bool timestamp_provided, |
310 uint32_t timestamp, | 308 uint32_t timestamp, |
311 int64_t capture_time_ms, | 309 int64_t capture_time_ms, |
312 int probe_cluster_id); | 310 int probe_cluster_id); |
313 | 311 |
314 // Called on update of RTP statistics. | 312 // Called on update of RTP statistics. |
315 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); | 313 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); |
316 StreamDataCountersCallback* GetRtpStatisticsCallback() const; | 314 StreamDataCountersCallback* GetRtpStatisticsCallback() const; |
317 | 315 |
318 uint32_t BitrateSent() const; | 316 uint32_t BitrateSent(); |
319 | 317 |
320 void SetRtpState(const RtpState& rtp_state); | 318 void SetRtpState(const RtpState& rtp_state); |
321 RtpState GetRtpState() const; | 319 RtpState GetRtpState() const; |
322 void SetRtxRtpState(const RtpState& rtp_state); | 320 void SetRtxRtpState(const RtpState& rtp_state); |
323 RtpState GetRtxRtpState() const; | 321 RtpState GetRtxRtpState() const; |
324 bool ActivateCVORtpHeaderExtension() override; | 322 bool ActivateCVORtpHeaderExtension() override; |
325 | 323 |
326 protected: | 324 protected: |
327 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); | 325 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); |
328 | 326 |
329 private: | 327 private: |
330 // Maps capture time in milliseconds to send-side delay in milliseconds. | 328 // Maps capture time in milliseconds to send-side delay in milliseconds. |
331 // Send-side delay is the difference between transmission time and capture | 329 // Send-side delay is the difference between transmission time and capture |
332 // time. | 330 // time. |
333 typedef std::map<int64_t, int> SendDelayMap; | 331 typedef std::map<int64_t, int> SendDelayMap; |
334 | 332 |
335 size_t CreateRtpHeader(uint8_t* header, | 333 size_t CreateRtpHeader(uint8_t* header, |
336 int8_t payload_type, | 334 int8_t payload_type, |
337 uint32_t ssrc, | 335 uint32_t ssrc, |
338 bool marker_bit, | 336 bool marker_bit, |
339 uint32_t timestamp, | 337 uint32_t timestamp, |
340 uint16_t sequence_number, | 338 uint16_t sequence_number, |
341 const std::vector<uint32_t>& csrcs) const; | 339 const std::vector<uint32_t>& csrcs) const; |
342 | 340 |
343 void UpdateNACKBitRate(uint32_t bytes, int64_t now); | |
344 | |
345 bool PrepareAndSendPacket(uint8_t* buffer, | 341 bool PrepareAndSendPacket(uint8_t* buffer, |
346 size_t length, | 342 size_t length, |
347 int64_t capture_time_ms, | 343 int64_t capture_time_ms, |
348 bool send_over_rtx, | 344 bool send_over_rtx, |
349 bool is_retransmit, | 345 bool is_retransmit, |
350 int probe_cluster_id); | 346 int probe_cluster_id); |
351 | 347 |
352 // Return the number of bytes sent. Note that both of these functions may | 348 // Return the number of bytes sent. Note that both of these functions may |
353 // return a larger value that their argument. | 349 // return a larger value that their argument. |
354 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); | 350 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 395 |
400 bool AllocateTransportSequenceNumber(int* packet_id) const; | 396 bool AllocateTransportSequenceNumber(int* packet_id) const; |
401 | 397 |
402 void UpdateRtpStats(const uint8_t* buffer, | 398 void UpdateRtpStats(const uint8_t* buffer, |
403 size_t packet_length, | 399 size_t packet_length, |
404 const RTPHeader& header, | 400 const RTPHeader& header, |
405 bool is_rtx, | 401 bool is_rtx, |
406 bool is_retransmit); | 402 bool is_retransmit); |
407 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; | 403 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; |
408 | 404 |
409 class BitrateAggregator { | |
410 public: | |
411 explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback); | |
412 | |
413 void OnStatsUpdated() const; | |
414 | |
415 Bitrate::Observer* total_bitrate_observer(); | |
416 Bitrate::Observer* retransmit_bitrate_observer(); | |
417 void set_ssrc(uint32_t ssrc); | |
418 | |
419 private: | |
420 // We assume that these observers are called on the same thread, which is | |
421 // true for RtpSender as they are called on the Process thread. | |
422 class BitrateObserver : public Bitrate::Observer { | |
423 public: | |
424 explicit BitrateObserver(const BitrateAggregator& aggregator); | |
425 | |
426 // Implements Bitrate::Observer. | |
427 void BitrateUpdated(const BitrateStatistics& stats) override; | |
428 const BitrateStatistics& statistics() const; | |
429 | |
430 private: | |
431 BitrateStatistics statistics_; | |
432 const BitrateAggregator& aggregator_; | |
433 }; | |
434 | |
435 BitrateStatisticsObserver* const callback_; | |
436 BitrateObserver total_bitrate_observer_; | |
437 BitrateObserver retransmit_bitrate_observer_; | |
438 uint32_t ssrc_; | |
439 }; | |
440 | |
441 Clock* const clock_; | 405 Clock* const clock_; |
442 const int64_t clock_delta_ms_; | 406 const int64_t clock_delta_ms_; |
443 Random random_ GUARDED_BY(send_critsect_); | 407 Random random_ GUARDED_BY(send_critsect_); |
444 | 408 |
445 BitrateAggregator bitrates_; | 409 rtc::CriticalSection stats_critsect_; |
danilchap
2016/06/23 12:46:12
may be use already existent statistics_crit_ inst
sprang_webrtc
2016/06/28 09:12:33
Done.
| |
446 Bitrate total_bitrate_sent_; | 410 BitrateStatisticsObserver* const bitrate_callback_; |
411 RateStatistics total_bitrate_sent_ GUARDED_BY(stats_critsect_); | |
412 RateStatistics nack_bitrate_sent_ GUARDED_BY(stats_critsect_); | |
447 | 413 |
448 const bool audio_configured_; | 414 const bool audio_configured_; |
449 const std::unique_ptr<RTPSenderAudio> audio_; | 415 const std::unique_ptr<RTPSenderAudio> audio_; |
450 const std::unique_ptr<RTPSenderVideo> video_; | 416 const std::unique_ptr<RTPSenderVideo> video_; |
451 | 417 |
452 RtpPacketSender* const paced_sender_; | 418 RtpPacketSender* const paced_sender_; |
453 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; | 419 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; |
454 TransportFeedbackObserver* const transport_feedback_observer_; | 420 TransportFeedbackObserver* const transport_feedback_observer_; |
455 int64_t last_capture_time_ms_sent_; | 421 int64_t last_capture_time_ms_sent_; |
456 rtc::CriticalSection send_critsect_; | 422 rtc::CriticalSection send_critsect_; |
457 | 423 |
458 Transport *transport_; | 424 Transport *transport_; |
459 bool sending_media_ GUARDED_BY(send_critsect_); | 425 bool sending_media_ GUARDED_BY(send_critsect_); |
460 | 426 |
461 size_t max_payload_length_; | 427 size_t max_payload_length_; |
462 | 428 |
463 int8_t payload_type_ GUARDED_BY(send_critsect_); | 429 int8_t payload_type_ GUARDED_BY(send_critsect_); |
464 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; | 430 std::map<int8_t, RtpUtility::Payload*> payload_type_map_; |
465 | 431 |
466 RtpHeaderExtensionMap rtp_header_extension_map_; | 432 RtpHeaderExtensionMap rtp_header_extension_map_; |
467 int32_t transmission_time_offset_; | 433 int32_t transmission_time_offset_; |
468 uint32_t absolute_send_time_; | 434 uint32_t absolute_send_time_; |
469 VideoRotation rotation_; | 435 VideoRotation rotation_; |
470 bool video_rotation_active_; | 436 bool video_rotation_active_; |
471 uint16_t transport_sequence_number_; | 437 uint16_t transport_sequence_number_; |
472 | 438 |
473 // NACK | |
474 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; | |
475 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; | |
476 Bitrate nack_bitrate_; | |
477 | |
478 // Tracks the current request for playout delay limits from application | 439 // Tracks the current request for playout delay limits from application |
479 // and decides whether the current RTP frame should include the playout | 440 // and decides whether the current RTP frame should include the playout |
480 // delay extension on header. | 441 // delay extension on header. |
481 PlayoutDelayOracle playout_delay_oracle_; | 442 PlayoutDelayOracle playout_delay_oracle_; |
482 bool playout_delay_active_ GUARDED_BY(send_critsect_); | 443 bool playout_delay_active_ GUARDED_BY(send_critsect_); |
483 | 444 |
484 RTPPacketHistory packet_history_; | 445 RTPPacketHistory packet_history_; |
485 | 446 |
486 // Statistics | 447 // Statistics |
487 rtc::CriticalSection statistics_crit_; | 448 rtc::CriticalSection statistics_crit_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 // that the target bitrate is still valid. | 483 // that the target bitrate is still valid. |
523 rtc::CriticalSection target_bitrate_critsect_; | 484 rtc::CriticalSection target_bitrate_critsect_; |
524 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); | 485 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); |
525 | 486 |
526 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); | 487 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
527 }; | 488 }; |
528 | 489 |
529 } // namespace webrtc | 490 } // namespace webrtc |
530 | 491 |
531 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ | 492 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
OLD | NEW |