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

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

Issue 1877253002: Replaced CriticalSectionWrapper with rtc::CriticalSection in rtp_rtcp module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: git cl format dtmf_queue.cc Created 4 years, 8 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
11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
12 12
13 #include <stdlib.h> // srand 13 #include <stdlib.h> // srand
14 #include <algorithm> 14 #include <algorithm>
15 #include <utility> 15 #include <utility>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/trace_event.h" 19 #include "webrtc/base/trace_event.h"
20 #include "webrtc/call.h" 20 #include "webrtc/call.h"
21 #include "webrtc/call/rtc_event_log.h" 21 #include "webrtc/call/rtc_event_log.h"
22 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" 22 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
23 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 23 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" 24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h"
25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" 25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
26 #include "webrtc/modules/rtp_rtcp/source/time_util.h" 26 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
27 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
28 #include "webrtc/system_wrappers/include/tick_util.h" 27 #include "webrtc/system_wrappers/include/tick_util.h"
29 28
30 namespace webrtc { 29 namespace webrtc {
31 30
32 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. 31 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP.
33 static const size_t kMaxPaddingLength = 224; 32 static const size_t kMaxPaddingLength = 224;
34 static const int kSendSideDelayWindowMs = 1000; 33 static const int kSendSideDelayWindowMs = 1000;
35 static const uint32_t kAbsSendTimeFraction = 18; 34 static const uint32_t kAbsSendTimeFraction = 18;
36 35
37 namespace { 36 namespace {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 absolute_send_time_(0), 139 absolute_send_time_(0),
141 rotation_(kVideoRotation_0), 140 rotation_(kVideoRotation_0),
142 cvo_mode_(kCVONone), 141 cvo_mode_(kCVONone),
143 transport_sequence_number_(0), 142 transport_sequence_number_(0),
144 // NACK. 143 // NACK.
145 nack_byte_count_times_(), 144 nack_byte_count_times_(),
146 nack_byte_count_(), 145 nack_byte_count_(),
147 nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()), 146 nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()),
148 packet_history_(clock), 147 packet_history_(clock),
149 // Statistics 148 // Statistics
150 statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()),
151 rtp_stats_callback_(NULL), 149 rtp_stats_callback_(NULL),
152 frame_count_observer_(frame_count_observer), 150 frame_count_observer_(frame_count_observer),
153 send_side_delay_observer_(send_side_delay_observer), 151 send_side_delay_observer_(send_side_delay_observer),
154 event_log_(event_log), 152 event_log_(event_log),
155 // RTP variables 153 // RTP variables
156 start_timestamp_forced_(false), 154 start_timestamp_forced_(false),
157 start_timestamp_(0), 155 start_timestamp_(0),
158 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), 156 ssrc_db_(SSRCDatabase::GetSSRCDatabase()),
159 remote_ssrc_(0), 157 remote_ssrc_(0),
160 sequence_number_forced_(false), 158 sequence_number_forced_(false),
161 ssrc_forced_(false), 159 ssrc_forced_(false),
162 timestamp_(0), 160 timestamp_(0),
163 capture_time_ms_(0), 161 capture_time_ms_(0),
164 last_timestamp_time_ms_(0), 162 last_timestamp_time_ms_(0),
165 media_has_been_sent_(false), 163 media_has_been_sent_(false),
166 last_packet_marker_bit_(false), 164 last_packet_marker_bit_(false),
167 csrcs_(), 165 csrcs_(),
168 rtx_(kRtxOff), 166 rtx_(kRtxOff),
169 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
170 target_bitrate_(0) { 167 target_bitrate_(0) {
171 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); 168 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_));
172 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); 169 memset(nack_byte_count_, 0, sizeof(nack_byte_count_));
173 // We need to seed the random generator for BuildPaddingPacket() below. 170 // We need to seed the random generator for BuildPaddingPacket() below.
174 // TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac 171 // TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac
175 // early on in the process. 172 // early on in the process.
176 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); 173 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds()));
177 ssrc_ = ssrc_db_->CreateSSRC(); 174 ssrc_ = ssrc_db_->CreateSSRC();
178 RTC_DCHECK(ssrc_ != 0); 175 RTC_DCHECK(ssrc_ != 0);
179 ssrc_rtx_ = ssrc_db_->CreateSSRC(); 176 ssrc_rtx_ = ssrc_db_->CreateSSRC();
(...skipping 23 matching lines...) Expand all
203 SSRCDatabase::ReturnSSRCDatabase(); 200 SSRCDatabase::ReturnSSRCDatabase();
204 while (!payload_type_map_.empty()) { 201 while (!payload_type_map_.empty()) {
205 std::map<int8_t, RtpUtility::Payload*>::iterator it = 202 std::map<int8_t, RtpUtility::Payload*>::iterator it =
206 payload_type_map_.begin(); 203 payload_type_map_.begin();
207 delete it->second; 204 delete it->second;
208 payload_type_map_.erase(it); 205 payload_type_map_.erase(it);
209 } 206 }
210 } 207 }
211 208
212 void RTPSender::SetTargetBitrate(uint32_t bitrate) { 209 void RTPSender::SetTargetBitrate(uint32_t bitrate) {
213 CriticalSectionScoped cs(target_bitrate_critsect_.get()); 210 rtc::CritScope cs(&target_bitrate_critsect_);
214 target_bitrate_ = bitrate; 211 target_bitrate_ = bitrate;
215 } 212 }
216 213
217 uint32_t RTPSender::GetTargetBitrate() { 214 uint32_t RTPSender::GetTargetBitrate() {
218 CriticalSectionScoped cs(target_bitrate_critsect_.get()); 215 rtc::CritScope cs(&target_bitrate_critsect_);
219 return target_bitrate_; 216 return target_bitrate_;
220 } 217 }
221 218
222 uint16_t RTPSender::ActualSendBitrateKbit() const { 219 uint16_t RTPSender::ActualSendBitrateKbit() const {
223 return (uint16_t)(total_bitrate_sent_.BitrateNow() / 1000); 220 return (uint16_t)(total_bitrate_sent_.BitrateNow() / 1000);
224 } 221 }
225 222
226 uint32_t RTPSender::VideoBitrateSent() const { 223 uint32_t RTPSender::VideoBitrateSent() const {
227 if (video_) { 224 if (video_) {
228 return video_->VideoBitrateSent(); 225 return video_->VideoBitrateSent();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 522
526 if (frame_type == kEmptyFrame) 523 if (frame_type == kEmptyFrame)
527 return 0; 524 return 0;
528 525
529 ret_val = 526 ret_val =
530 video_->SendVideo(video_type, frame_type, payload_type, 527 video_->SendVideo(video_type, frame_type, payload_type,
531 capture_timestamp, capture_time_ms, payload_data, 528 capture_timestamp, capture_time_ms, payload_data,
532 payload_size, fragmentation, rtp_hdr); 529 payload_size, fragmentation, rtp_hdr);
533 } 530 }
534 531
535 CriticalSectionScoped cs(statistics_crit_.get()); 532 rtc::CritScope cs(&statistics_crit_);
536 // Note: This is currently only counting for video. 533 // Note: This is currently only counting for video.
537 if (frame_type == kVideoFrameKey) { 534 if (frame_type == kVideoFrameKey) {
538 ++frame_counts_.key_frames; 535 ++frame_counts_.key_frames;
539 } else if (frame_type == kVideoFrameDelta) { 536 } else if (frame_type == kVideoFrameDelta) {
540 ++frame_counts_.delta_frames; 537 ++frame_counts_.delta_frames;
541 } 538 }
542 if (frame_count_observer_) { 539 if (frame_count_observer_) {
543 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); 540 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc);
544 } 541 }
545 542
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 956
960 void RTPSender::UpdateRtpStats(const uint8_t* buffer, 957 void RTPSender::UpdateRtpStats(const uint8_t* buffer,
961 size_t packet_length, 958 size_t packet_length,
962 const RTPHeader& header, 959 const RTPHeader& header,
963 bool is_rtx, 960 bool is_rtx,
964 bool is_retransmit) { 961 bool is_retransmit) {
965 StreamDataCounters* counters; 962 StreamDataCounters* counters;
966 // Get ssrc before taking statistics_crit_ to avoid possible deadlock. 963 // Get ssrc before taking statistics_crit_ to avoid possible deadlock.
967 uint32_t ssrc = is_rtx ? RtxSsrc() : SSRC(); 964 uint32_t ssrc = is_rtx ? RtxSsrc() : SSRC();
968 965
969 CriticalSectionScoped lock(statistics_crit_.get()); 966 rtc::CritScope lock(&statistics_crit_);
970 if (is_rtx) { 967 if (is_rtx) {
971 counters = &rtx_rtp_stats_; 968 counters = &rtx_rtp_stats_;
972 } else { 969 } else {
973 counters = &rtp_stats_; 970 counters = &rtp_stats_;
974 } 971 }
975 972
976 total_bitrate_sent_.Update(packet_length); 973 total_bitrate_sent_.Update(packet_length);
977 974
978 if (counters->first_packet_time_ms == -1) { 975 if (counters->first_packet_time_ms == -1) {
979 counters->first_packet_time_ms = clock_->TimeInMilliseconds(); 976 counters->first_packet_time_ms = clock_->TimeInMilliseconds();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 return; 1099 return;
1103 1100
1104 uint32_t ssrc; 1101 uint32_t ssrc;
1105 int avg_delay_ms = 0; 1102 int avg_delay_ms = 0;
1106 int max_delay_ms = 0; 1103 int max_delay_ms = 0;
1107 { 1104 {
1108 rtc::CritScope lock(&send_critsect_); 1105 rtc::CritScope lock(&send_critsect_);
1109 ssrc = ssrc_; 1106 ssrc = ssrc_;
1110 } 1107 }
1111 { 1108 {
1112 CriticalSectionScoped cs(statistics_crit_.get()); 1109 rtc::CritScope cs(&statistics_crit_);
1113 // TODO(holmer): Compute this iteratively instead. 1110 // TODO(holmer): Compute this iteratively instead.
1114 send_delays_[now_ms] = now_ms - capture_time_ms; 1111 send_delays_[now_ms] = now_ms - capture_time_ms;
1115 send_delays_.erase(send_delays_.begin(), 1112 send_delays_.erase(send_delays_.begin(),
1116 send_delays_.lower_bound(now_ms - 1113 send_delays_.lower_bound(now_ms -
1117 kSendSideDelayWindowMs)); 1114 kSendSideDelayWindowMs));
1118 int num_delays = 0; 1115 int num_delays = 0;
1119 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs); 1116 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs);
1120 it != send_delays_.end(); ++it) { 1117 it != send_delays_.end(); ++it) {
1121 max_delay_ms = std::max(max_delay_ms, it->second); 1118 max_delay_ms = std::max(max_delay_ms, it->second);
1122 avg_delay_ms += it->second; 1119 avg_delay_ms += it->second;
(...skipping 27 matching lines...) Expand all
1150 1147
1151 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { 1148 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
1152 rtc::CritScope lock(&send_critsect_); 1149 rtc::CritScope lock(&send_critsect_);
1153 uint16_t first_allocated_sequence_number = sequence_number_; 1150 uint16_t first_allocated_sequence_number = sequence_number_;
1154 sequence_number_ += packets_to_send; 1151 sequence_number_ += packets_to_send;
1155 return first_allocated_sequence_number; 1152 return first_allocated_sequence_number;
1156 } 1153 }
1157 1154
1158 void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats, 1155 void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats,
1159 StreamDataCounters* rtx_stats) const { 1156 StreamDataCounters* rtx_stats) const {
1160 CriticalSectionScoped lock(statistics_crit_.get()); 1157 rtc::CritScope lock(&statistics_crit_);
1161 *rtp_stats = rtp_stats_; 1158 *rtp_stats = rtp_stats_;
1162 *rtx_stats = rtx_rtp_stats_; 1159 *rtx_stats = rtx_rtp_stats_;
1163 } 1160 }
1164 1161
1165 size_t RTPSender::CreateRtpHeader(uint8_t* header, 1162 size_t RTPSender::CreateRtpHeader(uint8_t* header,
1166 int8_t payload_type, 1163 int8_t payload_type,
1167 uint32_t ssrc, 1164 uint32_t ssrc,
1168 bool marker_bit, 1165 bool marker_bit,
1169 uint32_t timestamp, 1166 uint32_t timestamp,
1170 uint16_t sequence_number, 1167 uint16_t sequence_number,
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 ptr += 2; 1848 ptr += 2;
1852 1849
1853 // Add original payload data. 1850 // Add original payload data.
1854 memcpy(ptr, buffer + rtp_header.headerLength, 1851 memcpy(ptr, buffer + rtp_header.headerLength,
1855 *length - rtp_header.headerLength); 1852 *length - rtp_header.headerLength);
1856 *length += 2; 1853 *length += 2;
1857 } 1854 }
1858 1855
1859 void RTPSender::RegisterRtpStatisticsCallback( 1856 void RTPSender::RegisterRtpStatisticsCallback(
1860 StreamDataCountersCallback* callback) { 1857 StreamDataCountersCallback* callback) {
1861 CriticalSectionScoped cs(statistics_crit_.get()); 1858 rtc::CritScope cs(&statistics_crit_);
1862 rtp_stats_callback_ = callback; 1859 rtp_stats_callback_ = callback;
1863 } 1860 }
1864 1861
1865 StreamDataCountersCallback* RTPSender::GetRtpStatisticsCallback() const { 1862 StreamDataCountersCallback* RTPSender::GetRtpStatisticsCallback() const {
1866 CriticalSectionScoped cs(statistics_crit_.get()); 1863 rtc::CritScope cs(&statistics_crit_);
1867 return rtp_stats_callback_; 1864 return rtp_stats_callback_;
1868 } 1865 }
1869 1866
1870 uint32_t RTPSender::BitrateSent() const { 1867 uint32_t RTPSender::BitrateSent() const {
1871 return total_bitrate_sent_.BitrateLast(); 1868 return total_bitrate_sent_.BitrateLast();
1872 } 1869 }
1873 1870
1874 void RTPSender::SetRtpState(const RtpState& rtp_state) { 1871 void RTPSender::SetRtpState(const RtpState& rtp_state) {
1875 rtc::CritScope lock(&send_critsect_); 1872 rtc::CritScope lock(&send_critsect_);
1876 sequence_number_ = rtp_state.sequence_number; 1873 sequence_number_ = rtp_state.sequence_number;
(...skipping 27 matching lines...) Expand all
1904 rtc::CritScope lock(&send_critsect_); 1901 rtc::CritScope lock(&send_critsect_);
1905 1902
1906 RtpState state; 1903 RtpState state;
1907 state.sequence_number = sequence_number_rtx_; 1904 state.sequence_number = sequence_number_rtx_;
1908 state.start_timestamp = start_timestamp_; 1905 state.start_timestamp = start_timestamp_;
1909 1906
1910 return state; 1907 return state;
1911 } 1908 }
1912 1909
1913 } // namespace webrtc 1910 } // 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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698