| 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 11 matching lines...) Expand all Loading... |
| 22 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 | 23 |
| 24 namespace webrtc { | 24 namespace webrtc { |
| 25 namespace vcm { | 25 namespace vcm { |
| 26 | 26 |
| 27 VideoSender::VideoSender(Clock* clock, | 27 VideoSender::VideoSender(Clock* clock, |
| 28 EncodedImageCallback* post_encode_callback, | 28 EncodedImageCallback* post_encode_callback, |
| 29 VideoEncoderRateObserver* encoder_rate_observer, | 29 VideoEncoderRateObserver* encoder_rate_observer, |
| 30 VCMQMSettingsCallback* qm_settings_callback) | 30 VCMQMSettingsCallback* qm_settings_callback) |
| 31 : clock_(clock), | 31 : clock_(clock), |
| 32 process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 33 _encoder(nullptr), | 32 _encoder(nullptr), |
| 34 _encodedFrameCallback(post_encode_callback), | 33 _encodedFrameCallback(post_encode_callback), |
| 35 _mediaOpt(clock_), | 34 _mediaOpt(clock_), |
| 36 _sendStatsCallback(nullptr), | 35 _sendStatsCallback(nullptr), |
| 37 _codecDataBase(encoder_rate_observer, &_encodedFrameCallback), | 36 _codecDataBase(encoder_rate_observer, &_encodedFrameCallback), |
| 38 frame_dropper_enabled_(true), | 37 frame_dropper_enabled_(true), |
| 39 _sendStatsTimer(1000, clock_), | 38 _sendStatsTimer(1000, clock_), |
| 40 current_codec_(), | 39 current_codec_(), |
| 41 qm_settings_callback_(qm_settings_callback), | 40 qm_settings_callback_(qm_settings_callback), |
| 42 protection_callback_(nullptr), | 41 protection_callback_(nullptr), |
| 43 encoder_params_({0, 0, 0, 0}), | 42 encoder_params_({0, 0, 0, 0}), |
| 44 encoder_has_internal_source_(false), | 43 encoder_has_internal_source_(false), |
| 45 next_frame_types_(1, kVideoFrameDelta) { | 44 next_frame_types_(1, kVideoFrameDelta) { |
| 46 // Allow VideoSender to be created on one thread but used on another, post | 45 // 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 | 46 // construction. This is currently how this class is being used by at least |
| 48 // one external project (diffractor). | 47 // one external project (diffractor). |
| 49 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr); | 48 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr); |
| 50 _mediaOpt.Reset(); | 49 _mediaOpt.Reset(); |
| 51 main_thread_.DetachFromThread(); | 50 main_thread_.DetachFromThread(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 VideoSender::~VideoSender() {} | 53 VideoSender::~VideoSender() {} |
| 55 | 54 |
| 56 void VideoSender::Process() { | 55 void VideoSender::Process() { |
| 57 if (_sendStatsTimer.TimeUntilProcess() == 0) { | 56 if (_sendStatsTimer.TimeUntilProcess() == 0) { |
| 58 _sendStatsTimer.Processed(); | 57 _sendStatsTimer.Processed(); |
| 59 CriticalSectionScoped cs(process_crit_sect_.get()); | 58 rtc::CritScope cs(&process_crit_); |
| 60 if (_sendStatsCallback != nullptr) { | 59 if (_sendStatsCallback != nullptr) { |
| 61 uint32_t bitRate = _mediaOpt.SentBitRate(); | 60 uint32_t bitRate = _mediaOpt.SentBitRate(); |
| 62 uint32_t frameRate = _mediaOpt.SentFrameRate(); | 61 uint32_t frameRate = _mediaOpt.SentFrameRate(); |
| 63 _sendStatsCallback->SendStatistics(bitRate, frameRate); | 62 _sendStatsCallback->SendStatistics(bitRate, frameRate); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 | 65 |
| 67 { | 66 { |
| 68 rtc::CritScope cs(¶ms_crit_); | 67 rtc::CritScope cs(¶ms_crit_); |
| 69 // Force an encoder parameters update, so that incoming frame rate is | 68 // Force an encoder parameters update, so that incoming frame rate is |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 _encodedFrameCallback.SetMediaOpt(&_mediaOpt); | 241 _encodedFrameCallback.SetMediaOpt(&_mediaOpt); |
| 243 _encodedFrameCallback.SetTransportCallback(transport); | 242 _encodedFrameCallback.SetTransportCallback(transport); |
| 244 return VCM_OK; | 243 return VCM_OK; |
| 245 } | 244 } |
| 246 | 245 |
| 247 // Register video output information callback which will be called to deliver | 246 // Register video output information callback which will be called to deliver |
| 248 // information about the video stream produced by the encoder, for instance the | 247 // information about the video stream produced by the encoder, for instance the |
| 249 // average frame rate and bit rate. | 248 // average frame rate and bit rate. |
| 250 int32_t VideoSender::RegisterSendStatisticsCallback( | 249 int32_t VideoSender::RegisterSendStatisticsCallback( |
| 251 VCMSendStatisticsCallback* sendStats) { | 250 VCMSendStatisticsCallback* sendStats) { |
| 252 CriticalSectionScoped cs(process_crit_sect_.get()); | 251 rtc::CritScope cs(&process_crit_); |
| 253 _sendStatsCallback = sendStats; | 252 _sendStatsCallback = sendStats; |
| 254 return VCM_OK; | 253 return VCM_OK; |
| 255 } | 254 } |
| 256 | 255 |
| 257 // Register a video protection callback which will be called to deliver the | 256 // Register a video protection callback which will be called to deliver the |
| 258 // requested FEC rate and NACK status (on/off). | 257 // requested FEC rate and NACK status (on/off). |
| 259 // Note: this callback is assumed to only be registered once and before it is | 258 // Note: this callback is assumed to only be registered once and before it is |
| 260 // used in this class. | 259 // used in this class. |
| 261 int32_t VideoSender::RegisterProtectionCallback( | 260 int32_t VideoSender::RegisterProtectionCallback( |
| 262 VCMProtectionCallback* protection_callback) { | 261 VCMProtectionCallback* protection_callback) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // 10 kbps. | 393 // 10 kbps. |
| 395 int window_bps = std::max(threshold_bps / 10, 10000); | 394 int window_bps = std::max(threshold_bps / 10, 10000); |
| 396 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps); | 395 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps); |
| 397 } | 396 } |
| 398 | 397 |
| 399 bool VideoSender::VideoSuspended() const { | 398 bool VideoSender::VideoSuspended() const { |
| 400 return _mediaOpt.IsVideoSuspended(); | 399 return _mediaOpt.IsVideoSuspended(); |
| 401 } | 400 } |
| 402 } // namespace vcm | 401 } // namespace vcm |
| 403 } // namespace webrtc | 402 } // namespace webrtc |
| OLD | NEW |