Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender.cc

Issue 1350163005: Avoid circular dependency rtp_rtcp <-> paced_sender (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 BitrateStatistics statistics_; 90 BitrateStatistics statistics_;
91 const BitrateAggregator& aggregator_; 91 const BitrateAggregator& aggregator_;
92 }; 92 };
93 93
94 BitrateStatisticsObserver* const callback_; 94 BitrateStatisticsObserver* const callback_;
95 BitrateObserver total_bitrate_observer_; 95 BitrateObserver total_bitrate_observer_;
96 BitrateObserver retransmit_bitrate_observer_; 96 BitrateObserver retransmit_bitrate_observer_;
97 uint32_t ssrc_; 97 uint32_t ssrc_;
98 }; 98 };
99 99
100 RTPSender::RTPSender(bool audio, 100 RTPSender::RTPSender(
101 Clock* clock, 101 bool audio,
102 Transport* transport, 102 Clock* clock,
103 RtpAudioFeedback* audio_feedback, 103 Transport* transport,
104 PacedSender* paced_sender, 104 RtpAudioFeedback* audio_feedback,
105 PacketRouter* packet_router, 105 RtpPacketSender* paced_sender,
106 TransportFeedbackObserver* transport_feedback_observer, 106 TransportSequenceNumberAllocator* sequence_number_allocator,
107 BitrateStatisticsObserver* bitrate_callback, 107 TransportFeedbackObserver* transport_feedback_observer,
108 FrameCountObserver* frame_count_observer, 108 BitrateStatisticsObserver* bitrate_callback,
109 SendSideDelayObserver* send_side_delay_observer) 109 FrameCountObserver* frame_count_observer,
110 SendSideDelayObserver* send_side_delay_observer)
110 : clock_(clock), 111 : clock_(clock),
111 // TODO(holmer): Remove this conversion when we remove the use of 112 // TODO(holmer): Remove this conversion when we remove the use of
112 // TickTime. 113 // TickTime.
113 clock_delta_ms_(clock_->TimeInMilliseconds() - 114 clock_delta_ms_(clock_->TimeInMilliseconds() -
114 TickTime::MillisecondTimestamp()), 115 TickTime::MillisecondTimestamp()),
115 bitrates_(new BitrateAggregator(bitrate_callback)), 116 bitrates_(new BitrateAggregator(bitrate_callback)),
116 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), 117 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()),
117 audio_configured_(audio), 118 audio_configured_(audio),
118 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), 119 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr),
119 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), 120 video_(audio ? nullptr : new RTPSenderVideo(clock, this)),
120 paced_sender_(paced_sender), 121 paced_sender_(paced_sender),
121 packet_router_(packet_router), 122 transport_sequence_number_allocator_(sequence_number_allocator),
122 transport_feedback_observer_(transport_feedback_observer), 123 transport_feedback_observer_(transport_feedback_observer),
123 last_capture_time_ms_sent_(0), 124 last_capture_time_ms_sent_(0),
124 send_critsect_(CriticalSectionWrapper::CreateCriticalSection()), 125 send_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
125 transport_(transport), 126 transport_(transport),
126 sending_media_(true), // Default to sending media. 127 sending_media_(true), // Default to sending media.
127 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. 128 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP.
128 packet_over_head_(28), 129 packet_over_head_(28),
129 payload_type_(-1), 130 payload_type_(-1),
130 payload_type_map_(), 131 payload_type_map_(),
131 rtp_header_extension_map_(), 132 rtp_header_extension_map_(),
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 580 }
580 // Set number of padding bytes in the last byte of the packet. 581 // Set number of padding bytes in the last byte of the packet.
581 packet[header_length + padding_length - 1] = 582 packet[header_length + padding_length - 1] =
582 static_cast<uint8_t>(padding_length); 583 static_cast<uint8_t>(padding_length);
583 } 584 }
584 585
585 size_t RTPSender::SendPadData(size_t bytes, 586 size_t RTPSender::SendPadData(size_t bytes,
586 bool timestamp_provided, 587 bool timestamp_provided,
587 uint32_t timestamp, 588 uint32_t timestamp,
588 int64_t capture_time_ms) { 589 int64_t capture_time_ms) {
589 // Always send full padding packets. This is accounted for by the PacedSender, 590 // Always send full padding packets. This is accounted for by the
591 // RtpPacketSender,
590 // which will make sure we don't send too much padding even if a single packet 592 // which will make sure we don't send too much padding even if a single packet
591 // is larger than requested. 593 // is larger than requested.
592 size_t padding_bytes_in_packet = 594 size_t padding_bytes_in_packet =
593 std::min(MaxDataPayloadLength(), kMaxPaddingLength); 595 std::min(MaxDataPayloadLength(), kMaxPaddingLength);
594 size_t bytes_sent = 0; 596 size_t bytes_sent = 0;
595 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( 597 bool using_transport_seq = rtp_header_extension_map_.IsRegistered(
596 kRtpExtensionTransportSequenceNumber) && 598 kRtpExtensionTransportSequenceNumber) &&
597 packet_router_; 599 transport_sequence_number_allocator_;
598 for (; bytes > 0; bytes -= padding_bytes_in_packet) { 600 for (; bytes > 0; bytes -= padding_bytes_in_packet) {
599 if (bytes < padding_bytes_in_packet) 601 if (bytes < padding_bytes_in_packet)
600 bytes = padding_bytes_in_packet; 602 bytes = padding_bytes_in_packet;
601 603
602 uint32_t ssrc; 604 uint32_t ssrc;
603 uint16_t sequence_number; 605 uint16_t sequence_number;
604 int payload_type; 606 int payload_type;
605 bool over_rtx; 607 bool over_rtx;
606 { 608 {
607 CriticalSectionScoped cs(send_critsect_.get()); 609 CriticalSectionScoped cs(send_critsect_.get());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 RtpUtility::RtpHeaderParser rtp_parser(data_buffer, length); 706 RtpUtility::RtpHeaderParser rtp_parser(data_buffer, length);
705 RTPHeader header; 707 RTPHeader header;
706 if (!rtp_parser.Parse(header)) { 708 if (!rtp_parser.Parse(header)) {
707 assert(false); 709 assert(false);
708 return -1; 710 return -1;
709 } 711 }
710 // Convert from TickTime to Clock since capture_time_ms is based on 712 // Convert from TickTime to Clock since capture_time_ms is based on
711 // TickTime. 713 // TickTime.
712 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_; 714 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_;
713 if (!paced_sender_->SendPacket( 715 if (!paced_sender_->SendPacket(
714 PacedSender::kHighPriority, header.ssrc, header.sequenceNumber, 716 RtpPacketSender::kHighPriority, header.ssrc, header.sequenceNumber,
715 corrected_capture_tims_ms, length - header.headerLength, true)) { 717 corrected_capture_tims_ms, length - header.headerLength, true)) {
716 // We can't send the packet right now. 718 // We can't send the packet right now.
717 // We will be called when it is time. 719 // We will be called when it is time.
718 return length; 720 return length;
719 } 721 }
720 } 722 }
721 int rtx = kRtxOff; 723 int rtx = kRtxOff;
722 { 724 {
723 CriticalSectionScoped lock(send_critsect_.get()); 725 CriticalSectionScoped lock(send_critsect_.get());
724 rtx = rtx_; 726 rtx = rtx_;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 int64_t now_ms = clock_->TimeInMilliseconds(); 912 int64_t now_ms = clock_->TimeInMilliseconds();
911 int64_t diff_ms = now_ms - capture_time_ms; 913 int64_t diff_ms = now_ms - capture_time_ms;
912 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header, 914 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header,
913 diff_ms); 915 diff_ms);
914 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms); 916 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms);
915 917
916 uint16_t transport_seq = 0; 918 uint16_t transport_seq = 0;
917 // TODO(sprang): Potentially too much overhead in IsRegistered()? 919 // TODO(sprang): Potentially too much overhead in IsRegistered()?
918 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( 920 bool using_transport_seq = rtp_header_extension_map_.IsRegistered(
919 kRtpExtensionTransportSequenceNumber) && 921 kRtpExtensionTransportSequenceNumber) &&
920 packet_router_ && !is_retransmit; 922 transport_sequence_number_allocator_ &&
923 !is_retransmit;
921 if (using_transport_seq) { 924 if (using_transport_seq) {
922 transport_seq = 925 transport_seq =
923 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header); 926 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header);
924 } 927 }
925 928
926 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length); 929 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length);
927 if (ret) { 930 if (ret) {
928 CriticalSectionScoped lock(send_critsect_.get()); 931 CriticalSectionScoped lock(send_critsect_.get());
929 media_has_been_sent_ = true; 932 media_has_been_sent_ = true;
930 } 933 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 if (!sending_media_) 996 if (!sending_media_)
994 return 0; 997 return 0;
995 } 998 }
996 size_t bytes_sent = TrySendRedundantPayloads(bytes); 999 size_t bytes_sent = TrySendRedundantPayloads(bytes);
997 if (bytes_sent < bytes) 1000 if (bytes_sent < bytes)
998 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); 1001 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0);
999 return bytes_sent; 1002 return bytes_sent;
1000 } 1003 }
1001 1004
1002 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. 1005 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again.
1003 int32_t RTPSender::SendToNetwork( 1006 int32_t RTPSender::SendToNetwork(uint8_t* buffer,
1004 uint8_t *buffer, size_t payload_length, size_t rtp_header_length, 1007 size_t payload_length,
1005 int64_t capture_time_ms, StorageType storage, 1008 size_t rtp_header_length,
1006 PacedSender::Priority priority) { 1009 int64_t capture_time_ms,
1010 StorageType storage,
1011 RtpPacketSender::Priority priority) {
1007 RtpUtility::RtpHeaderParser rtp_parser(buffer, 1012 RtpUtility::RtpHeaderParser rtp_parser(buffer,
1008 payload_length + rtp_header_length); 1013 payload_length + rtp_header_length);
1009 RTPHeader rtp_header; 1014 RTPHeader rtp_header;
1010 rtp_parser.Parse(rtp_header); 1015 rtp_parser.Parse(rtp_header);
1011 1016
1012 int64_t now_ms = clock_->TimeInMilliseconds(); 1017 int64_t now_ms = clock_->TimeInMilliseconds();
1013 1018
1014 // |capture_time_ms| <= 0 is considered invalid. 1019 // |capture_time_ms| <= 0 is considered invalid.
1015 // TODO(holmer): This should be changed all over Video Engine so that negative 1020 // TODO(holmer): This should be changed all over Video Engine so that negative
1016 // time is consider invalid, while 0 is considered a valid time. 1021 // time is consider invalid, while 0 is considered a valid time.
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 return 0; 1613 return 0;
1609 case ExtensionStatus::kError: 1614 case ExtensionStatus::kError:
1610 LOG(LS_WARNING) << "Failed to update transport sequence number"; 1615 LOG(LS_WARNING) << "Failed to update transport sequence number";
1611 return 0; 1616 return 0;
1612 case ExtensionStatus::kOk: 1617 case ExtensionStatus::kOk:
1613 break; 1618 break;
1614 default: 1619 default:
1615 RTC_NOTREACHED(); 1620 RTC_NOTREACHED();
1616 } 1621 }
1617 1622
1618 uint16_t seq = packet_router_->AllocateSequenceNumber(); 1623 uint16_t seq = transport_sequence_number_allocator_->AllocateSequenceNumber();
1619 BuildTransportSequenceNumberExtension(rtp_packet + offset, seq); 1624 BuildTransportSequenceNumberExtension(rtp_packet + offset, seq);
1620 return seq; 1625 return seq;
1621 } 1626 }
1622 1627
1623 void RTPSender::SetSendingStatus(bool enabled) { 1628 void RTPSender::SetSendingStatus(bool enabled) {
1624 if (enabled) { 1629 if (enabled) {
1625 uint32_t frequency_hz = SendPayloadFrequency(); 1630 uint32_t frequency_hz = SendPayloadFrequency();
1626 uint32_t RTPtime = RtpUtility::GetCurrentRTP(clock_, frequency_hz); 1631 uint32_t RTPtime = RtpUtility::GetCurrentRTP(clock_, frequency_hz);
1627 1632
1628 // Will be ignored if it's already configured via API. 1633 // Will be ignored if it's already configured via API.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 CriticalSectionScoped lock(send_critsect_.get()); 1900 CriticalSectionScoped lock(send_critsect_.get());
1896 1901
1897 RtpState state; 1902 RtpState state;
1898 state.sequence_number = sequence_number_rtx_; 1903 state.sequence_number = sequence_number_rtx_;
1899 state.start_timestamp = start_timestamp_; 1904 state.start_timestamp = start_timestamp_;
1900 1905
1901 return state; 1906 return state;
1902 } 1907 }
1903 1908
1904 } // namespace webrtc 1909 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698