blob: 381f62867d73c56f4f6420709c8a608a7941e87d [file] [log] [blame]
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000011
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +000012#include <algorithm> // std::max
13
Mirko Bonadei71207422017-09-15 13:58:09 +020014#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "common_video/include/video_bitrate_allocator.h"
16#include "common_video/libyuv/include/webrtc_libyuv.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/encoded_frame.h"
18#include "modules/video_coding/include/video_codec_interface.h"
19#include "modules/video_coding/utility/default_video_bitrate_allocator.h"
20#include "modules/video_coding/utility/quality_scaler.h"
21#include "modules/video_coding/video_coding_impl.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/logging.h"
24#include "system_wrappers/include/clock.h"
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000025
26namespace webrtc {
27namespace vcm {
28
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000029VideoSender::VideoSender(Clock* clock,
Niels Möllera0565992017-10-24 11:37:08 +020030 EncodedImageCallback* post_encode_callback)
31 : _encoder(nullptr),
32 _mediaOpt(clock),
perkj376b1922016-05-02 11:35:24 -070033 _encodedFrameCallback(post_encode_callback, &_mediaOpt),
kthelgason876222f2016-11-29 01:44:11 -080034 post_encode_callback_(post_encode_callback),
perkjf5b2e512016-07-05 08:34:04 -070035 _codecDataBase(&_encodedFrameCallback),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000036 frame_dropper_enabled_(true),
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000037 current_codec_(),
Erik Språng08127a92016-11-16 16:41:30 +010038 encoder_params_({BitrateAllocation(), 0, 0, 0}),
Peter Boström233bfd22016-01-18 20:23:40 +010039 encoder_has_internal_source_(false),
40 next_frame_types_(1, kVideoFrameDelta) {
Peter Boströmad6fc5a2016-05-12 03:01:31 +020041 _mediaOpt.Reset();
tommi@webrtc.org658d2012015-03-05 12:21:54 +000042 // Allow VideoSender to be created on one thread but used on another, post
43 // construction. This is currently how this class is being used by at least
44 // one external project (diffractor).
perkj4e417b22016-07-14 23:35:55 -070045 sequenced_checker_.Detach();
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000046}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000047
Peter Boströmdcb89982015-09-15 14:43:47 +020048VideoSender::~VideoSender() {}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000049
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000050// Register the send codec to be used.
51int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec,
52 uint32_t numberOfCores,
53 uint32_t maxPayloadSize) {
perkj4e417b22016-07-14 23:35:55 -070054 RTC_DCHECK(sequenced_checker_.CalledSequentially());
Peter Boström233bfd22016-01-18 20:23:40 +010055 rtc::CritScope lock(&encoder_crit_);
mflodmanfcf54bd2015-04-14 21:28:08 +020056 if (sendCodec == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000057 return VCM_PARAMETER_ERROR;
58 }
59
Peter Boström4f5db112015-10-29 16:53:59 +010060 bool ret =
61 _codecDataBase.SetSendCodec(sendCodec, numberOfCores, maxPayloadSize);
pbos@webrtc.orgda2c4ce2013-09-17 09:38:41 +000062
63 // Update encoder regardless of result to make sure that we're not holding on
64 // to a deleted instance.
65 _encoder = _codecDataBase.GetEncoder();
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000066 // Cache the current codec here so they can be fetched from this thread
67 // without requiring the _sendCritSect lock.
68 current_codec_ = *sendCodec;
pbos@webrtc.orgda2c4ce2013-09-17 09:38:41 +000069
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000070 if (!ret) {
Niels Möller2e1d7842018-02-23 15:41:13 +010071 RTC_LOG(LS_ERROR) << "Failed to initialize set encoder with codec type '"
72 << sendCodec->codecType << "'.";
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000073 return VCM_CODEC_ERROR;
74 }
75
Peter Boström233bfd22016-01-18 20:23:40 +010076 // SetSendCodec succeeded, _encoder should be set.
77 RTC_DCHECK(_encoder);
78
ivicac7199c22015-10-07 06:43:33 -070079 int numLayers;
80 if (sendCodec->codecType == kVideoCodecVP8) {
hta257dc392016-10-25 09:05:06 -070081 numLayers = sendCodec->VP8().numberOfTemporalLayers;
ivicac7199c22015-10-07 06:43:33 -070082 } else if (sendCodec->codecType == kVideoCodecVP9) {
hta257dc392016-10-25 09:05:06 -070083 numLayers = sendCodec->VP9().numberOfTemporalLayers;
sprang4847ae62017-06-27 07:06:52 -070084 } else if (sendCodec->codecType == kVideoCodecGeneric &&
85 sendCodec->numberOfSimulcastStreams > 0) {
86 // This is mainly for unit testing, disabling frame dropping.
87 // TODO(sprang): Add a better way to disable frame dropping.
88 numLayers = sendCodec->simulcastStream[0].numberOfTemporalLayers;
ivicac7199c22015-10-07 06:43:33 -070089 } else {
90 numLayers = 1;
91 }
92
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000093 // If we have screensharing and we have layers, we disable frame dropper.
94 bool disable_frame_dropper =
95 numLayers > 1 && sendCodec->mode == kScreensharing;
96 if (disable_frame_dropper) {
97 _mediaOpt.EnableFrameDropper(false);
98 } else if (frame_dropper_enabled_) {
99 _mediaOpt.EnableFrameDropper(true);
100 }
sprang1a646ee2016-12-01 06:34:11 -0800101
Peter Boström233bfd22016-01-18 20:23:40 +0100102 {
103 rtc::CritScope cs(&params_crit_);
104 next_frame_types_.clear();
105 next_frame_types_.resize(VCM_MAX(sendCodec->numberOfSimulcastStreams, 1),
106 kVideoFrameKey);
107 // Cache InternalSource() to have this available from IntraFrameRequest()
108 // without having to acquire encoder_crit_ (avoid blocking on encoder use).
109 encoder_has_internal_source_ = _encoder->InternalSource();
110 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000111
Mirko Bonadei675513b2017-11-09 11:09:25 +0100112 RTC_LOG(LS_VERBOSE) << " max bitrate " << sendCodec->maxBitrate
113 << " start bitrate " << sendCodec->startBitrate
114 << " max frame rate " << sendCodec->maxFramerate
115 << " max payload size " << maxPayloadSize;
Per69b332d2016-06-02 15:45:42 +0200116 _mediaOpt.SetEncodingData(sendCodec->maxBitrate * 1000,
asapersson60dfbdb2017-08-07 00:03:03 -0700117 sendCodec->startBitrate * 1000,
118 sendCodec->maxFramerate);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000119 return VCM_OK;
120}
121
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000122// Register an external decoder object.
123// This can not be used together with external decoder callbacks.
Peter Boström795dbe42015-11-27 14:09:07 +0100124void VideoSender::RegisterExternalEncoder(VideoEncoder* externalEncoder,
philipel5908c712015-12-21 08:23:20 -0800125 uint8_t payloadType,
126 bool internalSource /*= false*/) {
perkj4e417b22016-07-14 23:35:55 -0700127 RTC_DCHECK(sequenced_checker_.CalledSequentially());
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000128
Peter Boström233bfd22016-01-18 20:23:40 +0100129 rtc::CritScope lock(&encoder_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000130
mflodmanfcf54bd2015-04-14 21:28:08 +0200131 if (externalEncoder == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000132 bool wasSendCodec = false;
Peter Boström795dbe42015-11-27 14:09:07 +0100133 RTC_CHECK(
134 _codecDataBase.DeregisterExternalEncoder(payloadType, &wasSendCodec));
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000135 if (wasSendCodec) {
136 // Make sure the VCM doesn't use the de-registered codec
Peter Boström233bfd22016-01-18 20:23:40 +0100137 rtc::CritScope params_lock(&params_crit_);
mflodmanfcf54bd2015-04-14 21:28:08 +0200138 _encoder = nullptr;
Peter Boström233bfd22016-01-18 20:23:40 +0100139 encoder_has_internal_source_ = false;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000140 }
Peter Boström795dbe42015-11-27 14:09:07 +0100141 return;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000142 }
philipel5908c712015-12-21 08:23:20 -0800143 _codecDataBase.RegisterExternalEncoder(externalEncoder, payloadType,
144 internalSource);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000145}
146
Erik Språng08127a92016-11-16 16:41:30 +0100147EncoderParameters VideoSender::UpdateEncoderParameters(
148 const EncoderParameters& params,
149 VideoBitrateAllocator* bitrate_allocator,
150 uint32_t target_bitrate_bps) {
asapersson9abd2752016-12-08 02:19:40 -0800151 uint32_t video_target_rate_bps = _mediaOpt.SetTargetRates(target_bitrate_bps);
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000152 uint32_t input_frame_rate = _mediaOpt.InputFrameRate();
sprang40217c32016-11-21 05:41:52 -0800153 if (input_frame_rate == 0)
154 input_frame_rate = current_codec_.maxFramerate;
155
Erik Språng08127a92016-11-16 16:41:30 +0100156 BitrateAllocation bitrate_allocation;
sprang4847ae62017-06-27 07:06:52 -0700157 // Only call allocators if bitrate > 0 (ie, not suspended), otherwise they
158 // might cap the bitrate to the min bitrate configured.
159 if (target_bitrate_bps > 0) {
160 if (bitrate_allocator) {
161 bitrate_allocation = bitrate_allocator->GetAllocation(
162 video_target_rate_bps, input_frame_rate);
163 } else {
164 DefaultVideoBitrateAllocator default_allocator(current_codec_);
165 bitrate_allocation = default_allocator.GetAllocation(
166 video_target_rate_bps, input_frame_rate);
167 }
Erik Språng08127a92016-11-16 16:41:30 +0100168 }
Erik Språng08127a92016-11-16 16:41:30 +0100169 EncoderParameters new_encoder_params = {bitrate_allocation, params.loss_rate,
170 params.rtt, input_frame_rate};
171 return new_encoder_params;
172}
173
Niels Möller96d7f762018-01-30 11:27:16 +0100174void VideoSender::UpdateChannelParameters(
sprang1a646ee2016-12-01 06:34:11 -0800175 VideoBitrateAllocator* bitrate_allocator,
176 VideoBitrateAllocationObserver* bitrate_updated_callback) {
177 BitrateAllocation target_rate;
178 {
179 rtc::CritScope cs(&params_crit_);
180 encoder_params_ =
181 UpdateEncoderParameters(encoder_params_, bitrate_allocator,
182 encoder_params_.target_bitrate.get_sum_bps());
183 target_rate = encoder_params_.target_bitrate;
184 }
sprang4847ae62017-06-27 07:06:52 -0700185 if (bitrate_updated_callback && target_rate.get_sum_bps() > 0)
sprang1a646ee2016-12-01 06:34:11 -0800186 bitrate_updated_callback->OnBitrateAllocationUpdated(target_rate);
Erik Språng08127a92016-11-16 16:41:30 +0100187}
188
189int32_t VideoSender::SetChannelParameters(
190 uint32_t target_bitrate_bps,
sprang1a646ee2016-12-01 06:34:11 -0800191 uint8_t loss_rate,
Erik Språng08127a92016-11-16 16:41:30 +0100192 int64_t rtt,
sprang1a646ee2016-12-01 06:34:11 -0800193 VideoBitrateAllocator* bitrate_allocator,
194 VideoBitrateAllocationObserver* bitrate_updated_callback) {
Erik Språng08127a92016-11-16 16:41:30 +0100195 EncoderParameters encoder_params;
sprang1a646ee2016-12-01 06:34:11 -0800196 encoder_params.loss_rate = loss_rate;
Erik Språng08127a92016-11-16 16:41:30 +0100197 encoder_params.rtt = rtt;
198 encoder_params = UpdateEncoderParameters(encoder_params, bitrate_allocator,
199 target_bitrate_bps);
sprang4847ae62017-06-27 07:06:52 -0700200 if (bitrate_updated_callback && target_bitrate_bps > 0) {
sprang1a646ee2016-12-01 06:34:11 -0800201 bitrate_updated_callback->OnBitrateAllocationUpdated(
202 encoder_params.target_bitrate);
203 }
Erik Språng08127a92016-11-16 16:41:30 +0100204
noahricd4badbc2016-04-13 14:59:48 -0700205 bool encoder_has_internal_source;
206 {
207 rtc::CritScope cs(&params_crit_);
208 encoder_params_ = encoder_params;
209 encoder_has_internal_source = encoder_has_internal_source_;
210 }
211
212 // For encoders with internal sources, we need to tell the encoder directly,
213 // instead of waiting for an AddVideoFrame that will never come (internal
214 // source encoders don't get input frames).
215 if (encoder_has_internal_source) {
216 rtc::CritScope cs(&encoder_crit_);
217 if (_encoder) {
perkj57c21f92016-06-17 07:27:16 -0700218 SetEncoderParameters(encoder_params, encoder_has_internal_source);
noahricd4badbc2016-04-13 14:59:48 -0700219 }
220 }
Erik Språng66a641a2015-06-11 14:20:07 +0200221
222 return VCM_OK;
223}
224
perkj57c21f92016-06-17 07:27:16 -0700225void VideoSender::SetEncoderParameters(EncoderParameters params,
226 bool has_internal_source) {
perkjfea93092016-05-14 00:58:48 -0700227 // |target_bitrate == 0 | means that the network is down or the send pacer is
perkj57c21f92016-06-17 07:27:16 -0700228 // full. We currently only report this if the encoder has an internal source.
229 // If the encoder does not have an internal source, higher levels are expected
230 // to not call AddVideoFrame. We do this since its unclear how current
231 // encoder implementations behave when given a zero target bitrate.
232 // TODO(perkj): Make sure all known encoder implementations handle zero
233 // target bitrate and remove this check.
Erik Språng08127a92016-11-16 16:41:30 +0100234 if (!has_internal_source && params.target_bitrate.get_sum_bps() == 0)
Peter Boströmdcb89982015-09-15 14:43:47 +0200235 return;
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000236
Erik Språng66a641a2015-06-11 14:20:07 +0200237 if (params.input_frame_rate == 0) {
238 // No frame rate estimate available, use default.
239 params.input_frame_rate = current_codec_.maxFramerate;
240 }
Peter Boström69ccb332015-10-29 16:30:23 +0100241 if (_encoder != nullptr)
242 _encoder->SetEncoderParameters(params);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000243}
244
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000245// Add one raw video frame to the encoder, blocking.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700246int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame,
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000247 const CodecSpecificInfo* codecSpecificInfo) {
Peter Boströmdcb89982015-09-15 14:43:47 +0200248 EncoderParameters encoder_params;
Peter Boström233bfd22016-01-18 20:23:40 +0100249 std::vector<FrameType> next_frame_types;
perkj57c21f92016-06-17 07:27:16 -0700250 bool encoder_has_internal_source = false;
Peter Boströmdcb89982015-09-15 14:43:47 +0200251 {
Peter Boström233bfd22016-01-18 20:23:40 +0100252 rtc::CritScope lock(&params_crit_);
Peter Boströmdcb89982015-09-15 14:43:47 +0200253 encoder_params = encoder_params_;
Peter Boström233bfd22016-01-18 20:23:40 +0100254 next_frame_types = next_frame_types_;
perkj57c21f92016-06-17 07:27:16 -0700255 encoder_has_internal_source = encoder_has_internal_source_;
Peter Boströmdcb89982015-09-15 14:43:47 +0200256 }
Peter Boström233bfd22016-01-18 20:23:40 +0100257 rtc::CritScope lock(&encoder_crit_);
Peter Boström69ccb332015-10-29 16:30:23 +0100258 if (_encoder == nullptr)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000259 return VCM_UNINITIALIZED;
perkj57c21f92016-06-17 07:27:16 -0700260 SetEncoderParameters(encoder_params, encoder_has_internal_source);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000261 if (_mediaOpt.DropFrame()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100262 RTC_LOG(LS_VERBOSE) << "Drop Frame "
263 << "target bitrate "
264 << encoder_params.target_bitrate.get_sum_bps()
265 << " loss rate " << encoder_params.loss_rate << " rtt "
266 << encoder_params.rtt << " input frame rate "
267 << encoder_params.input_frame_rate;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200268 post_encode_callback_->OnDroppedFrame(
269 EncodedImageCallback::DropReason::kDroppedByMediaOptimizations);
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000270 return VCM_OK;
271 }
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000272 // TODO(pbos): Make sure setting send codec is synchronized with video
273 // processing so frame size always matches.
274 if (!_codecDataBase.MatchesCurrentResolution(videoFrame.width(),
275 videoFrame.height())) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100276 RTC_LOG(LS_ERROR)
277 << "Incoming frame doesn't match set resolution. Dropping.";
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000278 return VCM_PARAMETER_ERROR;
279 }
Peter Boströmeb66e802015-06-05 11:08:03 +0200280 VideoFrame converted_frame = videoFrame;
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000281 const VideoFrameBuffer::Type buffer_type =
282 converted_frame.video_frame_buffer()->type();
283 const bool is_buffer_type_supported =
284 buffer_type == VideoFrameBuffer::Type::kI420 ||
285 (buffer_type == VideoFrameBuffer::Type::kNative &&
286 _encoder->SupportsNativeHandle());
287 if (!is_buffer_type_supported) {
Peter Boströmeb66e802015-06-05 11:08:03 +0200288 // This module only supports software encoding.
289 // TODO(pbos): Offload conversion from the encoder thread.
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000290 rtc::scoped_refptr<I420BufferInterface> converted_buffer(
291 converted_frame.video_frame_buffer()->ToI420());
nisseca6d5d12016-06-17 05:03:04 -0700292
293 if (!converted_buffer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100294 RTC_LOG(LS_ERROR) << "Frame conversion failed, dropping frame.";
nisseca6d5d12016-06-17 05:03:04 -0700295 return VCM_PARAMETER_ERROR;
296 }
297 converted_frame = VideoFrame(converted_buffer,
298 converted_frame.timestamp(),
299 converted_frame.render_time_ms(),
300 converted_frame.rotation());
Peter Boströmeb66e802015-06-05 11:08:03 +0200301 }
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000302 int32_t ret =
Peter Boström233bfd22016-01-18 20:23:40 +0100303 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types);
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000304 if (ret < 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100305 RTC_LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret;
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000306 return ret;
307 }
perkj376b1922016-05-02 11:35:24 -0700308
Peter Boström233bfd22016-01-18 20:23:40 +0100309 {
Peter Boström233bfd22016-01-18 20:23:40 +0100310 rtc::CritScope lock(&params_crit_);
perkj376b1922016-05-02 11:35:24 -0700311 // Change all keyframe requests to encode delta frames the next time.
Peter Boström233bfd22016-01-18 20:23:40 +0100312 for (size_t i = 0; i < next_frame_types_.size(); ++i) {
313 // Check for equality (same requested as before encoding) to not
314 // accidentally drop a keyframe request while encoding.
315 if (next_frame_types[i] == next_frame_types_[i])
316 next_frame_types_[i] = kVideoFrameDelta;
317 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000318 }
319 return VCM_OK;
320}
321
perkj600246e2016-05-04 11:26:51 -0700322int32_t VideoSender::IntraFrameRequest(size_t stream_index) {
Peter Boström233bfd22016-01-18 20:23:40 +0100323 {
324 rtc::CritScope lock(&params_crit_);
perkj600246e2016-05-04 11:26:51 -0700325 if (stream_index >= next_frame_types_.size()) {
Peter Boström233bfd22016-01-18 20:23:40 +0100326 return -1;
327 }
328 next_frame_types_[stream_index] = kVideoFrameKey;
329 if (!encoder_has_internal_source_)
330 return VCM_OK;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000331 }
Peter Boström233bfd22016-01-18 20:23:40 +0100332 // TODO(pbos): Remove when InternalSource() is gone. Both locks have to be
333 // held here for internal consistency, since _encoder could be removed while
334 // not holding encoder_crit_. Checks have to be performed again since
335 // params_crit_ was dropped to not cause lock-order inversions with
336 // encoder_crit_.
337 rtc::CritScope lock(&encoder_crit_);
338 rtc::CritScope params_lock(&params_crit_);
perkj600246e2016-05-04 11:26:51 -0700339 if (stream_index >= next_frame_types_.size())
Peter Boström233bfd22016-01-18 20:23:40 +0100340 return -1;
mflodmanfcf54bd2015-04-14 21:28:08 +0200341 if (_encoder != nullptr && _encoder->InternalSource()) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000342 // Try to request the frame if we have an external encoder with
343 // internal source since AddVideoFrame never will be called.
Peter Boström233bfd22016-01-18 20:23:40 +0100344 if (_encoder->RequestFrame(next_frame_types_) == WEBRTC_VIDEO_CODEC_OK) {
345 // Try to remove just-performed keyframe request, if stream still exists.
346 next_frame_types_[stream_index] = kVideoFrameDelta;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000347 }
348 }
349 return VCM_OK;
350}
351
352int32_t VideoSender::EnableFrameDropper(bool enable) {
Peter Boström233bfd22016-01-18 20:23:40 +0100353 rtc::CritScope lock(&encoder_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000354 frame_dropper_enabled_ = enable;
355 _mediaOpt.EnableFrameDropper(enable);
356 return VCM_OK;
357}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000358} // namespace vcm
359} // namespace webrtc