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

Side by Side Diff: webrtc/modules/video_coding/video_sender.cc

Issue 1900193004: Remove VCMPacketizationCallback (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed bug. Created 4 years, 7 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) 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
11 11
12 #include <algorithm> // std::max 12 #include <algorithm> // std::max
13 13
14 #include "webrtc/base/checks.h" 14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/logging.h" 15 #include "webrtc/base/logging.h"
16 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 18 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
19 #include "webrtc/modules/video_coding/encoded_frame.h" 19 #include "webrtc/modules/video_coding/encoded_frame.h"
20 #include "webrtc/modules/video_coding/utility/quality_scaler.h" 20 #include "webrtc/modules/video_coding/utility/quality_scaler.h"
21 #include "webrtc/modules/video_coding/video_coding_impl.h" 21 #include "webrtc/modules/video_coding/video_coding_impl.h"
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 VCMSendStatisticsCallback* send_stats_callback)
31 : clock_(clock), 32 : clock_(clock),
32 _encoder(nullptr), 33 _encoder(nullptr),
33 _encodedFrameCallback(post_encode_callback), 34 _encodedFrameCallback(post_encode_callback),
34 _mediaOpt(clock_), 35 _mediaOpt(clock_),
35 _sendStatsCallback(nullptr), 36 send_stats_callback_(send_stats_callback),
36 _codecDataBase(encoder_rate_observer, &_encodedFrameCallback), 37 _codecDataBase(encoder_rate_observer, &_encodedFrameCallback),
37 frame_dropper_enabled_(true), 38 frame_dropper_enabled_(true),
38 _sendStatsTimer(1000, clock_), 39 _sendStatsTimer(1000, clock_),
39 current_codec_(), 40 current_codec_(),
40 qm_settings_callback_(qm_settings_callback), 41 qm_settings_callback_(qm_settings_callback),
41 protection_callback_(nullptr), 42 protection_callback_(nullptr),
42 encoder_params_({0, 0, 0, 0}), 43 encoder_params_({0, 0, 0, 0}),
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 // Allow VideoSender to be created on one thread but used on another, post 46 // Allow VideoSender to be created on one thread but used on another, post
46 // construction. This is currently how this class is being used by at least 47 // construction. This is currently how this class is being used by at least
47 // one external project (diffractor). 48 // one external project (diffractor).
48 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr); 49 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr);
49 _mediaOpt.Reset(); 50 _mediaOpt.Reset();
51 _encodedFrameCallback.SetMediaOpt(&_mediaOpt);
pbos-webrtc 2016/05/02 00:16:06 Can we make this a ctor param to _encodedFrameCall
perkj_webrtc 2016/05/02 12:02:12 Done.
50 main_thread_.DetachFromThread(); 52 main_thread_.DetachFromThread();
51 } 53 }
52 54
53 VideoSender::~VideoSender() {} 55 VideoSender::~VideoSender() {}
54 56
55 void VideoSender::Process() { 57 void VideoSender::Process() {
56 if (_sendStatsTimer.TimeUntilProcess() == 0) { 58 if (_sendStatsTimer.TimeUntilProcess() == 0) {
59 // |_sendStatsTimer.Processed()| must be called. Otherwise
60 // VideoSender::Process() will be called in an infinit loop.
pbos-webrtc 2016/05/02 00:16:06 infinite
perkj_webrtc 2016/05/02 12:02:12 Done.
57 _sendStatsTimer.Processed(); 61 _sendStatsTimer.Processed();
58 rtc::CritScope cs(&process_crit_); 62 if (send_stats_callback_) {
59 if (_sendStatsCallback != nullptr) {
60 uint32_t bitRate = _mediaOpt.SentBitRate(); 63 uint32_t bitRate = _mediaOpt.SentBitRate();
61 uint32_t frameRate = _mediaOpt.SentFrameRate(); 64 uint32_t frameRate = _mediaOpt.SentFrameRate();
62 _sendStatsCallback->SendStatistics(bitRate, frameRate); 65 std::string encoder_name;
66 {
67 rtc::CritScope cs(&params_crit_);
68 // Copy the string here so that we don't hold |params_crit_| in the CB.
69 encoder_name = encoder_name_;
70 }
71 send_stats_callback_->SendStatistics(bitRate, frameRate,
72 std::move(encoder_name));
63 } 73 }
64 } 74 }
65 75
66 { 76 {
67 rtc::CritScope cs(&params_crit_); 77 rtc::CritScope cs(&params_crit_);
68 // Force an encoder parameters update, so that incoming frame rate is 78 // Force an encoder parameters update, so that incoming frame rate is
69 // updated even if bandwidth hasn't changed. 79 // updated even if bandwidth hasn't changed.
70 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate(); 80 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate();
71 } 81 }
72 } 82 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return; 238 return;
229 239
230 if (params.input_frame_rate == 0) { 240 if (params.input_frame_rate == 0) {
231 // No frame rate estimate available, use default. 241 // No frame rate estimate available, use default.
232 params.input_frame_rate = current_codec_.maxFramerate; 242 params.input_frame_rate = current_codec_.maxFramerate;
233 } 243 }
234 if (_encoder != nullptr) 244 if (_encoder != nullptr)
235 _encoder->SetEncoderParameters(params); 245 _encoder->SetEncoderParameters(params);
236 } 246 }
237 247
238 int32_t VideoSender::RegisterTransportCallback(
239 VCMPacketizationCallback* transport) {
240 rtc::CritScope lock(&encoder_crit_);
241 _encodedFrameCallback.SetMediaOpt(&_mediaOpt);
242 _encodedFrameCallback.SetTransportCallback(transport);
243 return VCM_OK;
244 }
245
246 // Register video output information callback which will be called to deliver
247 // information about the video stream produced by the encoder, for instance the
248 // average frame rate and bit rate.
249 int32_t VideoSender::RegisterSendStatisticsCallback(
250 VCMSendStatisticsCallback* sendStats) {
251 rtc::CritScope cs(&process_crit_);
252 _sendStatsCallback = sendStats;
253 return VCM_OK;
254 }
255
256 // Register a video protection callback which will be called to deliver the 248 // Register a video protection callback which will be called to deliver the
257 // requested FEC rate and NACK status (on/off). 249 // requested FEC rate and NACK status (on/off).
258 // Note: this callback is assumed to only be registered once and before it is 250 // Note: this callback is assumed to only be registered once and before it is
259 // used in this class. 251 // used in this class.
260 int32_t VideoSender::RegisterProtectionCallback( 252 int32_t VideoSender::RegisterProtectionCallback(
261 VCMProtectionCallback* protection_callback) { 253 VCMProtectionCallback* protection_callback) {
262 RTC_DCHECK(protection_callback == nullptr || protection_callback_ == nullptr); 254 RTC_DCHECK(protection_callback == nullptr || protection_callback_ == nullptr);
263 protection_callback_ = protection_callback; 255 protection_callback_ = protection_callback;
264 return VCM_OK; 256 return VCM_OK;
265 } 257 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 converted_frame = converted_frame.ConvertNativeToI420Frame(); 314 converted_frame = converted_frame.ConvertNativeToI420Frame();
323 RTC_CHECK(!converted_frame.IsZeroSize()) 315 RTC_CHECK(!converted_frame.IsZeroSize())
324 << "Frame conversion failed, won't be able to encode frame."; 316 << "Frame conversion failed, won't be able to encode frame.";
325 } 317 }
326 int32_t ret = 318 int32_t ret =
327 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types); 319 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types);
328 if (ret < 0) { 320 if (ret < 0) {
329 LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret; 321 LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret;
330 return ret; 322 return ret;
331 } 323 }
324
332 { 325 {
326 rtc::CritScope lock(&params_crit_);
327 encoder_name_ = _encoder->ImplementationName();
328
333 // Change all keyframe requests to encode delta frames the next time. 329 // Change all keyframe requests to encode delta frames the next time.
334 rtc::CritScope lock(&params_crit_);
335 for (size_t i = 0; i < next_frame_types_.size(); ++i) { 330 for (size_t i = 0; i < next_frame_types_.size(); ++i) {
336 // Check for equality (same requested as before encoding) to not 331 // Check for equality (same requested as before encoding) to not
337 // accidentally drop a keyframe request while encoding. 332 // accidentally drop a keyframe request while encoding.
338 if (next_frame_types[i] == next_frame_types_[i]) 333 if (next_frame_types[i] == next_frame_types_[i])
339 next_frame_types_[i] = kVideoFrameDelta; 334 next_frame_types_[i] = kVideoFrameDelta;
340 } 335 }
341 } 336 }
342 if (qm_settings_callback_) 337 if (qm_settings_callback_)
343 qm_settings_callback_->SetTargetFramerate(_encoder->GetTargetFramerate()); 338 qm_settings_callback_->SetTargetFramerate(_encoder->GetTargetFramerate());
344 return VCM_OK; 339 return VCM_OK;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // 10 kbps. 389 // 10 kbps.
395 int window_bps = std::max(threshold_bps / 10, 10000); 390 int window_bps = std::max(threshold_bps / 10, 10000);
396 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps); 391 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps);
397 } 392 }
398 393
399 bool VideoSender::VideoSuspended() const { 394 bool VideoSender::VideoSuspended() const {
400 return _mediaOpt.IsVideoSuspended(); 395 return _mediaOpt.IsVideoSuspended();
401 } 396 }
402 } // namespace vcm 397 } // namespace vcm
403 } // namespace webrtc 398 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698