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

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: Rebased and fixed SendStatisics const uint. 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 _mediaOpt(clock_), 34 _mediaOpt(clock_),
35 _sendStatsCallback(nullptr), 35 _encodedFrameCallback(post_encode_callback, &_mediaOpt),
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();
50 main_thread_.DetachFromThread(); 51 main_thread_.DetachFromThread();
51 } 52 }
52 53
53 VideoSender::~VideoSender() {} 54 VideoSender::~VideoSender() {}
54 55
55 void VideoSender::Process() { 56 void VideoSender::Process() {
56 if (_sendStatsTimer.TimeUntilProcess() == 0) { 57 if (_sendStatsTimer.TimeUntilProcess() == 0) {
58 // |_sendStatsTimer.Processed()| must be called. Otherwise
59 // VideoSender::Process() will be called in an infinite loop.
57 _sendStatsTimer.Processed(); 60 _sendStatsTimer.Processed();
58 rtc::CritScope cs(&process_crit_); 61 if (send_stats_callback_) {
59 if (_sendStatsCallback != nullptr) {
60 uint32_t bitRate = _mediaOpt.SentBitRate(); 62 uint32_t bitRate = _mediaOpt.SentBitRate();
61 uint32_t frameRate = _mediaOpt.SentFrameRate(); 63 uint32_t frameRate = _mediaOpt.SentFrameRate();
62 _sendStatsCallback->SendStatistics(bitRate, frameRate); 64 std::string encoder_name;
65 {
66 rtc::CritScope cs(&params_crit_);
67 // Copy the string here so that we don't hold |params_crit_| in the CB.
68 encoder_name = encoder_name_;
69 }
70 send_stats_callback_->SendStatistics(bitRate, frameRate, encoder_name);
63 } 71 }
64 } 72 }
65 73
66 { 74 {
67 rtc::CritScope cs(&params_crit_); 75 rtc::CritScope cs(&params_crit_);
68 // Force an encoder parameters update, so that incoming frame rate is 76 // Force an encoder parameters update, so that incoming frame rate is
69 // updated even if bandwidth hasn't changed. 77 // updated even if bandwidth hasn't changed.
70 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate(); 78 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate();
71 } 79 }
72 } 80 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return; 236 return;
229 237
230 if (params.input_frame_rate == 0) { 238 if (params.input_frame_rate == 0) {
231 // No frame rate estimate available, use default. 239 // No frame rate estimate available, use default.
232 params.input_frame_rate = current_codec_.maxFramerate; 240 params.input_frame_rate = current_codec_.maxFramerate;
233 } 241 }
234 if (_encoder != nullptr) 242 if (_encoder != nullptr)
235 _encoder->SetEncoderParameters(params); 243 _encoder->SetEncoderParameters(params);
236 } 244 }
237 245
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 246 // Register a video protection callback which will be called to deliver the
257 // requested FEC rate and NACK status (on/off). 247 // requested FEC rate and NACK status (on/off).
258 // Note: this callback is assumed to only be registered once and before it is 248 // Note: this callback is assumed to only be registered once and before it is
259 // used in this class. 249 // used in this class.
260 int32_t VideoSender::RegisterProtectionCallback( 250 int32_t VideoSender::RegisterProtectionCallback(
261 VCMProtectionCallback* protection_callback) { 251 VCMProtectionCallback* protection_callback) {
262 RTC_DCHECK(protection_callback == nullptr || protection_callback_ == nullptr); 252 RTC_DCHECK(protection_callback == nullptr || protection_callback_ == nullptr);
263 protection_callback_ = protection_callback; 253 protection_callback_ = protection_callback;
264 return VCM_OK; 254 return VCM_OK;
265 } 255 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 converted_frame = converted_frame.ConvertNativeToI420Frame(); 312 converted_frame = converted_frame.ConvertNativeToI420Frame();
323 RTC_CHECK(!converted_frame.IsZeroSize()) 313 RTC_CHECK(!converted_frame.IsZeroSize())
324 << "Frame conversion failed, won't be able to encode frame."; 314 << "Frame conversion failed, won't be able to encode frame.";
325 } 315 }
326 int32_t ret = 316 int32_t ret =
327 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types); 317 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types);
328 if (ret < 0) { 318 if (ret < 0) {
329 LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret; 319 LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret;
330 return ret; 320 return ret;
331 } 321 }
322
332 { 323 {
324 rtc::CritScope lock(&params_crit_);
325 encoder_name_ = _encoder->ImplementationName();
326
333 // Change all keyframe requests to encode delta frames the next time. 327 // 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) { 328 for (size_t i = 0; i < next_frame_types_.size(); ++i) {
336 // Check for equality (same requested as before encoding) to not 329 // Check for equality (same requested as before encoding) to not
337 // accidentally drop a keyframe request while encoding. 330 // accidentally drop a keyframe request while encoding.
338 if (next_frame_types[i] == next_frame_types_[i]) 331 if (next_frame_types[i] == next_frame_types_[i])
339 next_frame_types_[i] = kVideoFrameDelta; 332 next_frame_types_[i] = kVideoFrameDelta;
340 } 333 }
341 } 334 }
342 return VCM_OK; 335 return VCM_OK;
343 } 336 }
344 337
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // 10 kbps. 385 // 10 kbps.
393 int window_bps = std::max(threshold_bps / 10, 10000); 386 int window_bps = std::max(threshold_bps / 10, 10000);
394 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps); 387 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps);
395 } 388 }
396 389
397 bool VideoSender::VideoSuspended() const { 390 bool VideoSender::VideoSuspended() const {
398 return _mediaOpt.IsVideoSuspended(); 391 return _mediaOpt.IsVideoSuspended();
399 } 392 }
400 } // namespace vcm 393 } // namespace vcm
401 } // namespace webrtc 394 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/video_coding_impl.cc ('k') | webrtc/modules/video_coding/video_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698