Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 19 matching lines...) Expand all Loading... | |
| 30 VideoSender::VideoSender(Clock* clock, | 30 VideoSender::VideoSender(Clock* clock, |
| 31 EncodedImageCallback* post_encode_callback, | 31 EncodedImageCallback* post_encode_callback, |
| 32 VCMSendStatisticsCallback* send_stats_callback) | 32 VCMSendStatisticsCallback* send_stats_callback) |
| 33 : clock_(clock), | 33 : clock_(clock), |
| 34 _encoder(nullptr), | 34 _encoder(nullptr), |
| 35 _mediaOpt(clock_), | 35 _mediaOpt(clock_), |
| 36 _encodedFrameCallback(post_encode_callback, &_mediaOpt), | 36 _encodedFrameCallback(post_encode_callback, &_mediaOpt), |
| 37 send_stats_callback_(send_stats_callback), | 37 send_stats_callback_(send_stats_callback), |
| 38 _codecDataBase(&_encodedFrameCallback), | 38 _codecDataBase(&_encodedFrameCallback), |
| 39 frame_dropper_enabled_(true), | 39 frame_dropper_enabled_(true), |
| 40 _sendStatsTimer(1000, clock_), | 40 _sendStatsTimer(VCMProcessTimer::kDefaultProcessIntervalMs, clock_), |
| 41 current_codec_(), | 41 current_codec_(), |
| 42 encoder_params_({BitrateAllocation(), 0, 0, 0}), | 42 encoder_params_({BitrateAllocation(), 0, 0, 0}), |
| 43 has_received_frame_(false), | |
| 43 encoder_has_internal_source_(false), | 44 encoder_has_internal_source_(false), |
| 44 next_frame_types_(1, kVideoFrameDelta) { | 45 next_frame_types_(1, kVideoFrameDelta) { |
| 45 _mediaOpt.Reset(); | 46 _mediaOpt.Reset(); |
| 46 // Allow VideoSender to be created on one thread but used on another, post | 47 // Allow VideoSender to be created on one thread but used on another, post |
| 47 // construction. This is currently how this class is being used by at least | 48 // construction. This is currently how this class is being used by at least |
| 48 // one external project (diffractor). | 49 // one external project (diffractor). |
| 49 sequenced_checker_.Detach(); | 50 sequenced_checker_.Detach(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 VideoSender::~VideoSender() {} | 53 VideoSender::~VideoSender() {} |
| 53 | 54 |
| 54 void VideoSender::Process() { | 55 void VideoSender::Process() { |
| 55 if (_sendStatsTimer.TimeUntilProcess() == 0) { | 56 if (_sendStatsTimer.TimeUntilProcess() == 0) { |
| 56 // |_sendStatsTimer.Processed()| must be called. Otherwise | 57 // |_sendStatsTimer.Processed()| must be called. Otherwise |
| 57 // VideoSender::Process() will be called in an infinite loop. | 58 // VideoSender::Process() will be called in an infinite loop. |
| 58 _sendStatsTimer.Processed(); | 59 _sendStatsTimer.Processed(); |
| 59 if (send_stats_callback_) { | 60 if (send_stats_callback_) { |
| 60 uint32_t bitRate = _mediaOpt.SentBitRate(); | 61 uint32_t bitRate = _mediaOpt.SentBitRate(); |
| 61 uint32_t frameRate = _mediaOpt.SentFrameRate(); | 62 uint32_t frameRate = _mediaOpt.SentFrameRate(); |
| 62 send_stats_callback_->SendStatistics(bitRate, frameRate); | 63 send_stats_callback_->SendStatistics(bitRate, frameRate); |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 | 66 |
| 66 { | 67 { |
| 67 rtc::CritScope cs(¶ms_crit_); | 68 rtc::CritScope cs(¶ms_crit_); |
| 68 // Force an encoder parameters update, so that incoming frame rate is | 69 // Force an encoder parameters update, so that incoming frame rate is |
| 69 // updated even if bandwidth hasn't changed. | 70 // updated even if bandwidth hasn't changed. |
| 70 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate(); | 71 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate(); |
|
danilchap
2016/11/21 12:45:42
shouldn't you adjust frame_rate here too?
if not,
sprang_webrtc
2016/11/21 13:01:20
Looking close, SetEncoderParameters() actually tre
| |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 int64_t VideoSender::TimeUntilNextProcess() { | 75 int64_t VideoSender::TimeUntilNextProcess() { |
| 75 return _sendStatsTimer.TimeUntilProcess(); | 76 return _sendStatsTimer.TimeUntilProcess(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Register the send codec to be used. | 79 // Register the send codec to be used. |
| 79 int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec, | 80 int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec, |
| 80 uint32_t numberOfCores, | 81 uint32_t numberOfCores, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 if (disable_frame_dropper) { | 120 if (disable_frame_dropper) { |
| 120 _mediaOpt.EnableFrameDropper(false); | 121 _mediaOpt.EnableFrameDropper(false); |
| 121 } else if (frame_dropper_enabled_) { | 122 } else if (frame_dropper_enabled_) { |
| 122 _mediaOpt.EnableFrameDropper(true); | 123 _mediaOpt.EnableFrameDropper(true); |
| 123 } | 124 } |
| 124 { | 125 { |
| 125 rtc::CritScope cs(¶ms_crit_); | 126 rtc::CritScope cs(¶ms_crit_); |
| 126 next_frame_types_.clear(); | 127 next_frame_types_.clear(); |
| 127 next_frame_types_.resize(VCM_MAX(sendCodec->numberOfSimulcastStreams, 1), | 128 next_frame_types_.resize(VCM_MAX(sendCodec->numberOfSimulcastStreams, 1), |
| 128 kVideoFrameKey); | 129 kVideoFrameKey); |
| 130 has_received_frame_ = false; | |
| 129 // Cache InternalSource() to have this available from IntraFrameRequest() | 131 // Cache InternalSource() to have this available from IntraFrameRequest() |
| 130 // without having to acquire encoder_crit_ (avoid blocking on encoder use). | 132 // without having to acquire encoder_crit_ (avoid blocking on encoder use). |
| 131 encoder_has_internal_source_ = _encoder->InternalSource(); | 133 encoder_has_internal_source_ = _encoder->InternalSource(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 LOG(LS_VERBOSE) << " max bitrate " << sendCodec->maxBitrate | 136 LOG(LS_VERBOSE) << " max bitrate " << sendCodec->maxBitrate |
| 135 << " start bitrate " << sendCodec->startBitrate | 137 << " start bitrate " << sendCodec->startBitrate |
| 136 << " max frame rate " << sendCodec->maxFramerate | 138 << " max frame rate " << sendCodec->maxFramerate |
| 137 << " max payload size " << maxPayloadSize; | 139 << " max payload size " << maxPayloadSize; |
| 138 _mediaOpt.SetEncodingData(sendCodec->maxBitrate * 1000, | 140 _mediaOpt.SetEncodingData(sendCodec->maxBitrate * 1000, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 return 0; | 194 return 0; |
| 193 } | 195 } |
| 194 | 196 |
| 195 EncoderParameters VideoSender::UpdateEncoderParameters( | 197 EncoderParameters VideoSender::UpdateEncoderParameters( |
| 196 const EncoderParameters& params, | 198 const EncoderParameters& params, |
| 197 VideoBitrateAllocator* bitrate_allocator, | 199 VideoBitrateAllocator* bitrate_allocator, |
| 198 uint32_t target_bitrate_bps) { | 200 uint32_t target_bitrate_bps) { |
| 199 uint32_t video_target_rate_bps = _mediaOpt.SetTargetRates( | 201 uint32_t video_target_rate_bps = _mediaOpt.SetTargetRates( |
| 200 target_bitrate_bps, params.loss_rate, params.rtt); | 202 target_bitrate_bps, params.loss_rate, params.rtt); |
| 201 uint32_t input_frame_rate = _mediaOpt.InputFrameRate(); | 203 uint32_t input_frame_rate = _mediaOpt.InputFrameRate(); |
| 204 if (input_frame_rate > 0) { | |
| 205 has_received_frame_ = true; | |
|
danilchap
2016/11/21 12:45:42
variable name make impression it should be set to
sprang_webrtc
2016/11/21 13:01:20
Ack, but removed instead.
| |
| 206 } else if (input_frame_rate == 0 && !has_received_frame_) { | |
|
danilchap
2016/11/21 12:45:42
This mean input_frame_rate ~= 0 mid call is a vali
sprang_webrtc
2016/11/21 13:01:20
My impression was that 0 could be a valid framerat
| |
| 207 input_frame_rate = current_codec_.maxFramerate; | |
| 208 } | |
| 209 | |
| 202 BitrateAllocation bitrate_allocation; | 210 BitrateAllocation bitrate_allocation; |
| 203 if (bitrate_allocator) { | 211 if (bitrate_allocator) { |
| 204 bitrate_allocation = bitrate_allocator->GetAllocation(video_target_rate_bps, | 212 bitrate_allocation = bitrate_allocator->GetAllocation(video_target_rate_bps, |
| 205 input_frame_rate); | 213 input_frame_rate); |
| 206 } else { | 214 } else { |
| 207 DefaultVideoBitrateAllocator default_allocator(current_codec_); | 215 DefaultVideoBitrateAllocator default_allocator(current_codec_); |
| 208 bitrate_allocation = default_allocator.GetAllocation(video_target_rate_bps, | 216 bitrate_allocation = default_allocator.GetAllocation(video_target_rate_bps, |
| 209 input_frame_rate); | 217 input_frame_rate); |
| 210 } | 218 } |
| 211 | 219 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 223 } | 231 } |
| 224 | 232 |
| 225 int32_t VideoSender::SetChannelParameters( | 233 int32_t VideoSender::SetChannelParameters( |
| 226 uint32_t target_bitrate_bps, | 234 uint32_t target_bitrate_bps, |
| 227 uint8_t lossRate, | 235 uint8_t lossRate, |
| 228 int64_t rtt, | 236 int64_t rtt, |
| 229 VideoBitrateAllocator* bitrate_allocator) { | 237 VideoBitrateAllocator* bitrate_allocator) { |
| 230 EncoderParameters encoder_params; | 238 EncoderParameters encoder_params; |
| 231 encoder_params.loss_rate = lossRate; | 239 encoder_params.loss_rate = lossRate; |
| 232 encoder_params.rtt = rtt; | 240 encoder_params.rtt = rtt; |
| 233 encoder_params = UpdateEncoderParameters(encoder_params, bitrate_allocator, | |
| 234 target_bitrate_bps); | |
| 235 | 241 |
| 236 bool encoder_has_internal_source; | 242 bool encoder_has_internal_source; |
| 237 { | 243 { |
| 238 rtc::CritScope cs(¶ms_crit_); | 244 rtc::CritScope cs(¶ms_crit_); |
| 239 encoder_params_ = encoder_params; | 245 encoder_params_ = UpdateEncoderParameters(encoder_params, bitrate_allocator, |
| 246 target_bitrate_bps); | |
| 247 encoder_params = encoder_params_; | |
|
danilchap
2016/11/21 12:45:42
may be other way around make slightly more sense:
sprang_webrtc
2016/11/21 13:01:20
Ack, but reverted instead.
| |
| 240 encoder_has_internal_source = encoder_has_internal_source_; | 248 encoder_has_internal_source = encoder_has_internal_source_; |
| 241 } | 249 } |
| 242 | 250 |
| 243 // For encoders with internal sources, we need to tell the encoder directly, | 251 // For encoders with internal sources, we need to tell the encoder directly, |
| 244 // instead of waiting for an AddVideoFrame that will never come (internal | 252 // instead of waiting for an AddVideoFrame that will never come (internal |
| 245 // source encoders don't get input frames). | 253 // source encoders don't get input frames). |
| 246 if (encoder_has_internal_source) { | 254 if (encoder_has_internal_source) { |
| 247 rtc::CritScope cs(&encoder_crit_); | 255 rtc::CritScope cs(&encoder_crit_); |
| 248 if (_encoder) { | 256 if (_encoder) { |
| 249 SetEncoderParameters(encoder_params, encoder_has_internal_source); | 257 SetEncoderParameters(encoder_params, encoder_has_internal_source); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 } | 393 } |
| 386 | 394 |
| 387 int32_t VideoSender::EnableFrameDropper(bool enable) { | 395 int32_t VideoSender::EnableFrameDropper(bool enable) { |
| 388 rtc::CritScope lock(&encoder_crit_); | 396 rtc::CritScope lock(&encoder_crit_); |
| 389 frame_dropper_enabled_ = enable; | 397 frame_dropper_enabled_ = enable; |
| 390 _mediaOpt.EnableFrameDropper(enable); | 398 _mediaOpt.EnableFrameDropper(enable); |
| 391 return VCM_OK; | 399 return VCM_OK; |
| 392 } | 400 } |
| 393 } // namespace vcm | 401 } // namespace vcm |
| 394 } // namespace webrtc | 402 } // namespace webrtc |
| OLD | NEW |