blob: 4c1e24361204dc059b8e37adaffa401b6e5363ef [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
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020011
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +000012#include <algorithm> // std::max
13
Jiawei Ou4206a0a2018-07-20 15:49:43 -070014#include "api/video/video_bitrate_allocator.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#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"
Rasmus Brandt5438bce2018-09-03 13:30:46 +020025#include "system_wrappers/include/field_trial.h"
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000026
27namespace webrtc {
28namespace vcm {
29
Rasmus Brandt5438bce2018-09-03 13:30:46 +020030namespace {
31
32constexpr char kFrameDropperFieldTrial[] = "WebRTC-FrameDropper";
33
34} // namespace
35
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000036VideoSender::VideoSender(Clock* clock,
Niels Möllera0565992017-10-24 11:37:08 +020037 EncodedImageCallback* post_encode_callback)
38 : _encoder(nullptr),
39 _mediaOpt(clock),
perkj376b1922016-05-02 11:35:24 -070040 _encodedFrameCallback(post_encode_callback, &_mediaOpt),
kthelgason876222f2016-11-29 01:44:11 -080041 post_encode_callback_(post_encode_callback),
perkjf5b2e512016-07-05 08:34:04 -070042 _codecDataBase(&_encodedFrameCallback),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000043 frame_dropper_enabled_(true),
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000044 current_codec_(),
Erik Språng566124a2018-04-23 12:32:22 +020045 encoder_params_({VideoBitrateAllocation(), 0, 0, 0}),
Peter Boström233bfd22016-01-18 20:23:40 +010046 encoder_has_internal_source_(false),
47 next_frame_types_(1, kVideoFrameDelta) {
tommi@webrtc.org658d2012015-03-05 12:21:54 +000048 // Allow VideoSender to be created on one thread but used on another, post
49 // construction. This is currently how this class is being used by at least
50 // one external project (diffractor).
perkj4e417b22016-07-14 23:35:55 -070051 sequenced_checker_.Detach();
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000052}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000053
Peter Boströmdcb89982015-09-15 14:43:47 +020054VideoSender::~VideoSender() {}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000055
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000056// Register the send codec to be used.
57int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec,
58 uint32_t numberOfCores,
59 uint32_t maxPayloadSize) {
perkj4e417b22016-07-14 23:35:55 -070060 RTC_DCHECK(sequenced_checker_.CalledSequentially());
Peter Boström233bfd22016-01-18 20:23:40 +010061 rtc::CritScope lock(&encoder_crit_);
mflodmanfcf54bd2015-04-14 21:28:08 +020062 if (sendCodec == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000063 return VCM_PARAMETER_ERROR;
64 }
65
Peter Boström4f5db112015-10-29 16:53:59 +010066 bool ret =
67 _codecDataBase.SetSendCodec(sendCodec, numberOfCores, maxPayloadSize);
pbos@webrtc.orgda2c4ce2013-09-17 09:38:41 +000068
69 // Update encoder regardless of result to make sure that we're not holding on
70 // to a deleted instance.
71 _encoder = _codecDataBase.GetEncoder();
tommi@webrtc.orge07710c2015-02-19 17:43:25 +000072 // Cache the current codec here so they can be fetched from this thread
73 // without requiring the _sendCritSect lock.
74 current_codec_ = *sendCodec;
pbos@webrtc.orgda2c4ce2013-09-17 09:38:41 +000075
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000076 if (!ret) {
Niels Möller2e1d7842018-02-23 15:41:13 +010077 RTC_LOG(LS_ERROR) << "Failed to initialize set encoder with codec type '"
78 << sendCodec->codecType << "'.";
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000079 return VCM_CODEC_ERROR;
80 }
81
Peter Boström233bfd22016-01-18 20:23:40 +010082 // SetSendCodec succeeded, _encoder should be set.
83 RTC_DCHECK(_encoder);
84
ivicac7199c22015-10-07 06:43:33 -070085 int numLayers;
86 if (sendCodec->codecType == kVideoCodecVP8) {
hta257dc392016-10-25 09:05:06 -070087 numLayers = sendCodec->VP8().numberOfTemporalLayers;
ivicac7199c22015-10-07 06:43:33 -070088 } else if (sendCodec->codecType == kVideoCodecVP9) {
hta257dc392016-10-25 09:05:06 -070089 numLayers = sendCodec->VP9().numberOfTemporalLayers;
sprang4847ae62017-06-27 07:06:52 -070090 } else if (sendCodec->codecType == kVideoCodecGeneric &&
91 sendCodec->numberOfSimulcastStreams > 0) {
92 // This is mainly for unit testing, disabling frame dropping.
93 // TODO(sprang): Add a better way to disable frame dropping.
94 numLayers = sendCodec->simulcastStream[0].numberOfTemporalLayers;
ivicac7199c22015-10-07 06:43:33 -070095 } else {
96 numLayers = 1;
97 }
98
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000099 // If we have screensharing and we have layers, we disable frame dropper.
Rasmus Brandt5438bce2018-09-03 13:30:46 +0200100 const bool disable_frame_dropper =
101 field_trial::IsDisabled(kFrameDropperFieldTrial) ||
102 (numLayers > 1 && sendCodec->mode == VideoCodecMode::kScreensharing);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000103 if (disable_frame_dropper) {
104 _mediaOpt.EnableFrameDropper(false);
105 } else if (frame_dropper_enabled_) {
106 _mediaOpt.EnableFrameDropper(true);
107 }
sprang1a646ee2016-12-01 06:34:11 -0800108
Peter Boström233bfd22016-01-18 20:23:40 +0100109 {
110 rtc::CritScope cs(&params_crit_);
111 next_frame_types_.clear();
112 next_frame_types_.resize(VCM_MAX(sendCodec->numberOfSimulcastStreams, 1),
113 kVideoFrameKey);
114 // Cache InternalSource() to have this available from IntraFrameRequest()
115 // without having to acquire encoder_crit_ (avoid blocking on encoder use).
116 encoder_has_internal_source_ = _encoder->InternalSource();
117 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000118
Mirko Bonadei675513b2017-11-09 11:09:25 +0100119 RTC_LOG(LS_VERBOSE) << " max bitrate " << sendCodec->maxBitrate
120 << " start bitrate " << sendCodec->startBitrate
121 << " max frame rate " << sendCodec->maxFramerate
122 << " max payload size " << maxPayloadSize;
Per69b332d2016-06-02 15:45:42 +0200123 _mediaOpt.SetEncodingData(sendCodec->maxBitrate * 1000,
asapersson60dfbdb2017-08-07 00:03:03 -0700124 sendCodec->startBitrate * 1000,
125 sendCodec->maxFramerate);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000126 return VCM_OK;
127}
128
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000129// Register an external decoder object.
130// This can not be used together with external decoder callbacks.
Peter Boström795dbe42015-11-27 14:09:07 +0100131void VideoSender::RegisterExternalEncoder(VideoEncoder* externalEncoder,
philipel5908c712015-12-21 08:23:20 -0800132 bool internalSource /*= false*/) {
perkj4e417b22016-07-14 23:35:55 -0700133 RTC_DCHECK(sequenced_checker_.CalledSequentially());
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000134
Peter Boström233bfd22016-01-18 20:23:40 +0100135 rtc::CritScope lock(&encoder_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000136
mflodmanfcf54bd2015-04-14 21:28:08 +0200137 if (externalEncoder == nullptr) {
Niels Möllerbf3dbb42018-03-16 13:38:46 +0100138 _codecDataBase.DeregisterExternalEncoder();
139 {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000140 // Make sure the VCM doesn't use the de-registered codec
Peter Boström233bfd22016-01-18 20:23:40 +0100141 rtc::CritScope params_lock(&params_crit_);
mflodmanfcf54bd2015-04-14 21:28:08 +0200142 _encoder = nullptr;
Peter Boström233bfd22016-01-18 20:23:40 +0100143 encoder_has_internal_source_ = false;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000144 }
Peter Boström795dbe42015-11-27 14:09:07 +0100145 return;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000146 }
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200147 _codecDataBase.RegisterExternalEncoder(externalEncoder,
148 internalSource);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000149}
150
Erik Språng08127a92016-11-16 16:41:30 +0100151EncoderParameters VideoSender::UpdateEncoderParameters(
152 const EncoderParameters& params,
153 VideoBitrateAllocator* bitrate_allocator,
154 uint32_t target_bitrate_bps) {
asapersson9abd2752016-12-08 02:19:40 -0800155 uint32_t video_target_rate_bps = _mediaOpt.SetTargetRates(target_bitrate_bps);
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000156 uint32_t input_frame_rate = _mediaOpt.InputFrameRate();
sprang40217c32016-11-21 05:41:52 -0800157 if (input_frame_rate == 0)
158 input_frame_rate = current_codec_.maxFramerate;
159
Erik Språng566124a2018-04-23 12:32:22 +0200160 VideoBitrateAllocation bitrate_allocation;
sprang4847ae62017-06-27 07:06:52 -0700161 // Only call allocators if bitrate > 0 (ie, not suspended), otherwise they
162 // might cap the bitrate to the min bitrate configured.
163 if (target_bitrate_bps > 0) {
164 if (bitrate_allocator) {
165 bitrate_allocation = bitrate_allocator->GetAllocation(
166 video_target_rate_bps, input_frame_rate);
167 } else {
168 DefaultVideoBitrateAllocator default_allocator(current_codec_);
169 bitrate_allocation = default_allocator.GetAllocation(
170 video_target_rate_bps, input_frame_rate);
171 }
Erik Språng08127a92016-11-16 16:41:30 +0100172 }
Erik Språng08127a92016-11-16 16:41:30 +0100173 EncoderParameters new_encoder_params = {bitrate_allocation, params.loss_rate,
174 params.rtt, input_frame_rate};
175 return new_encoder_params;
176}
177
Niels Möller96d7f762018-01-30 11:27:16 +0100178void VideoSender::UpdateChannelParameters(
sprang1a646ee2016-12-01 06:34:11 -0800179 VideoBitrateAllocator* bitrate_allocator,
180 VideoBitrateAllocationObserver* bitrate_updated_callback) {
Erik Språng566124a2018-04-23 12:32:22 +0200181 VideoBitrateAllocation target_rate;
sprang1a646ee2016-12-01 06:34:11 -0800182 {
183 rtc::CritScope cs(&params_crit_);
184 encoder_params_ =
185 UpdateEncoderParameters(encoder_params_, bitrate_allocator,
186 encoder_params_.target_bitrate.get_sum_bps());
187 target_rate = encoder_params_.target_bitrate;
188 }
sprang4847ae62017-06-27 07:06:52 -0700189 if (bitrate_updated_callback && target_rate.get_sum_bps() > 0)
sprang1a646ee2016-12-01 06:34:11 -0800190 bitrate_updated_callback->OnBitrateAllocationUpdated(target_rate);
Erik Språng08127a92016-11-16 16:41:30 +0100191}
192
193int32_t VideoSender::SetChannelParameters(
194 uint32_t target_bitrate_bps,
sprang1a646ee2016-12-01 06:34:11 -0800195 uint8_t loss_rate,
Erik Språng08127a92016-11-16 16:41:30 +0100196 int64_t rtt,
sprang1a646ee2016-12-01 06:34:11 -0800197 VideoBitrateAllocator* bitrate_allocator,
198 VideoBitrateAllocationObserver* bitrate_updated_callback) {
Erik Språng08127a92016-11-16 16:41:30 +0100199 EncoderParameters encoder_params;
sprang1a646ee2016-12-01 06:34:11 -0800200 encoder_params.loss_rate = loss_rate;
Erik Språng08127a92016-11-16 16:41:30 +0100201 encoder_params.rtt = rtt;
202 encoder_params = UpdateEncoderParameters(encoder_params, bitrate_allocator,
203 target_bitrate_bps);
sprang4847ae62017-06-27 07:06:52 -0700204 if (bitrate_updated_callback && target_bitrate_bps > 0) {
sprang1a646ee2016-12-01 06:34:11 -0800205 bitrate_updated_callback->OnBitrateAllocationUpdated(
206 encoder_params.target_bitrate);
207 }
Erik Språng08127a92016-11-16 16:41:30 +0100208
noahricd4badbc2016-04-13 14:59:48 -0700209 bool encoder_has_internal_source;
210 {
211 rtc::CritScope cs(&params_crit_);
212 encoder_params_ = encoder_params;
213 encoder_has_internal_source = encoder_has_internal_source_;
214 }
215
216 // For encoders with internal sources, we need to tell the encoder directly,
217 // instead of waiting for an AddVideoFrame that will never come (internal
218 // source encoders don't get input frames).
219 if (encoder_has_internal_source) {
220 rtc::CritScope cs(&encoder_crit_);
221 if (_encoder) {
perkj57c21f92016-06-17 07:27:16 -0700222 SetEncoderParameters(encoder_params, encoder_has_internal_source);
noahricd4badbc2016-04-13 14:59:48 -0700223 }
224 }
Erik Språng66a641a2015-06-11 14:20:07 +0200225
226 return VCM_OK;
227}
228
perkj57c21f92016-06-17 07:27:16 -0700229void VideoSender::SetEncoderParameters(EncoderParameters params,
230 bool has_internal_source) {
perkjfea93092016-05-14 00:58:48 -0700231 // |target_bitrate == 0 | means that the network is down or the send pacer is
perkj57c21f92016-06-17 07:27:16 -0700232 // full. We currently only report this if the encoder has an internal source.
233 // If the encoder does not have an internal source, higher levels are expected
234 // to not call AddVideoFrame. We do this since its unclear how current
235 // encoder implementations behave when given a zero target bitrate.
236 // TODO(perkj): Make sure all known encoder implementations handle zero
237 // target bitrate and remove this check.
Erik Språng08127a92016-11-16 16:41:30 +0100238 if (!has_internal_source && params.target_bitrate.get_sum_bps() == 0)
Peter Boströmdcb89982015-09-15 14:43:47 +0200239 return;
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000240
Erik Språng66a641a2015-06-11 14:20:07 +0200241 if (params.input_frame_rate == 0) {
242 // No frame rate estimate available, use default.
243 params.input_frame_rate = current_codec_.maxFramerate;
244 }
Peter Boström69ccb332015-10-29 16:30:23 +0100245 if (_encoder != nullptr)
246 _encoder->SetEncoderParameters(params);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000247}
248
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000249// Add one raw video frame to the encoder, blocking.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700250int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame,
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000251 const CodecSpecificInfo* codecSpecificInfo) {
Peter Boströmdcb89982015-09-15 14:43:47 +0200252 EncoderParameters encoder_params;
Peter Boström233bfd22016-01-18 20:23:40 +0100253 std::vector<FrameType> next_frame_types;
perkj57c21f92016-06-17 07:27:16 -0700254 bool encoder_has_internal_source = false;
Peter Boströmdcb89982015-09-15 14:43:47 +0200255 {
Peter Boström233bfd22016-01-18 20:23:40 +0100256 rtc::CritScope lock(&params_crit_);
Peter Boströmdcb89982015-09-15 14:43:47 +0200257 encoder_params = encoder_params_;
Peter Boström233bfd22016-01-18 20:23:40 +0100258 next_frame_types = next_frame_types_;
perkj57c21f92016-06-17 07:27:16 -0700259 encoder_has_internal_source = encoder_has_internal_source_;
Peter Boströmdcb89982015-09-15 14:43:47 +0200260 }
Peter Boström233bfd22016-01-18 20:23:40 +0100261 rtc::CritScope lock(&encoder_crit_);
Peter Boström69ccb332015-10-29 16:30:23 +0100262 if (_encoder == nullptr)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000263 return VCM_UNINITIALIZED;
perkj57c21f92016-06-17 07:27:16 -0700264 SetEncoderParameters(encoder_params, encoder_has_internal_source);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000265 if (_mediaOpt.DropFrame()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100266 RTC_LOG(LS_VERBOSE) << "Drop Frame "
267 << "target bitrate "
268 << encoder_params.target_bitrate.get_sum_bps()
269 << " loss rate " << encoder_params.loss_rate << " rtt "
270 << encoder_params.rtt << " input frame rate "
271 << encoder_params.input_frame_rate;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200272 post_encode_callback_->OnDroppedFrame(
273 EncodedImageCallback::DropReason::kDroppedByMediaOptimizations);
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000274 return VCM_OK;
275 }
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000276 // TODO(pbos): Make sure setting send codec is synchronized with video
277 // processing so frame size always matches.
278 if (!_codecDataBase.MatchesCurrentResolution(videoFrame.width(),
279 videoFrame.height())) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100280 RTC_LOG(LS_ERROR)
281 << "Incoming frame doesn't match set resolution. Dropping.";
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000282 return VCM_PARAMETER_ERROR;
283 }
Peter Boströmeb66e802015-06-05 11:08:03 +0200284 VideoFrame converted_frame = videoFrame;
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000285 const VideoFrameBuffer::Type buffer_type =
286 converted_frame.video_frame_buffer()->type();
287 const bool is_buffer_type_supported =
288 buffer_type == VideoFrameBuffer::Type::kI420 ||
289 (buffer_type == VideoFrameBuffer::Type::kNative &&
290 _encoder->SupportsNativeHandle());
291 if (!is_buffer_type_supported) {
Peter Boströmeb66e802015-06-05 11:08:03 +0200292 // This module only supports software encoding.
293 // TODO(pbos): Offload conversion from the encoder thread.
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000294 rtc::scoped_refptr<I420BufferInterface> converted_buffer(
295 converted_frame.video_frame_buffer()->ToI420());
nisseca6d5d12016-06-17 05:03:04 -0700296
297 if (!converted_buffer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100298 RTC_LOG(LS_ERROR) << "Frame conversion failed, dropping frame.";
nisseca6d5d12016-06-17 05:03:04 -0700299 return VCM_PARAMETER_ERROR;
300 }
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200301 converted_frame = VideoFrame(converted_buffer,
302 converted_frame.timestamp(),
nisseca6d5d12016-06-17 05:03:04 -0700303 converted_frame.render_time_ms(),
304 converted_frame.rotation());
Peter Boströmeb66e802015-06-05 11:08:03 +0200305 }
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000306 int32_t ret =
Peter Boström233bfd22016-01-18 20:23:40 +0100307 _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types);
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000308 if (ret < 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100309 RTC_LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret;
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000310 return ret;
311 }
perkj376b1922016-05-02 11:35:24 -0700312
Peter Boström233bfd22016-01-18 20:23:40 +0100313 {
Peter Boström233bfd22016-01-18 20:23:40 +0100314 rtc::CritScope lock(&params_crit_);
perkj376b1922016-05-02 11:35:24 -0700315 // Change all keyframe requests to encode delta frames the next time.
Peter Boström233bfd22016-01-18 20:23:40 +0100316 for (size_t i = 0; i < next_frame_types_.size(); ++i) {
317 // Check for equality (same requested as before encoding) to not
318 // accidentally drop a keyframe request while encoding.
319 if (next_frame_types[i] == next_frame_types_[i])
320 next_frame_types_[i] = kVideoFrameDelta;
321 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000322 }
323 return VCM_OK;
324}
325
perkj600246e2016-05-04 11:26:51 -0700326int32_t VideoSender::IntraFrameRequest(size_t stream_index) {
Peter Boström233bfd22016-01-18 20:23:40 +0100327 {
328 rtc::CritScope lock(&params_crit_);
perkj600246e2016-05-04 11:26:51 -0700329 if (stream_index >= next_frame_types_.size()) {
Peter Boström233bfd22016-01-18 20:23:40 +0100330 return -1;
331 }
332 next_frame_types_[stream_index] = kVideoFrameKey;
333 if (!encoder_has_internal_source_)
334 return VCM_OK;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000335 }
Peter Boström233bfd22016-01-18 20:23:40 +0100336 // TODO(pbos): Remove when InternalSource() is gone. Both locks have to be
337 // held here for internal consistency, since _encoder could be removed while
338 // not holding encoder_crit_. Checks have to be performed again since
339 // params_crit_ was dropped to not cause lock-order inversions with
340 // encoder_crit_.
341 rtc::CritScope lock(&encoder_crit_);
342 rtc::CritScope params_lock(&params_crit_);
perkj600246e2016-05-04 11:26:51 -0700343 if (stream_index >= next_frame_types_.size())
Peter Boström233bfd22016-01-18 20:23:40 +0100344 return -1;
mflodmanfcf54bd2015-04-14 21:28:08 +0200345 if (_encoder != nullptr && _encoder->InternalSource()) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000346 // Try to request the frame if we have an external encoder with
347 // internal source since AddVideoFrame never will be called.
Peter Boström233bfd22016-01-18 20:23:40 +0100348 if (_encoder->RequestFrame(next_frame_types_) == WEBRTC_VIDEO_CODEC_OK) {
349 // Try to remove just-performed keyframe request, if stream still exists.
350 next_frame_types_[stream_index] = kVideoFrameDelta;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000351 }
352 }
353 return VCM_OK;
354}
355
356int32_t VideoSender::EnableFrameDropper(bool enable) {
Peter Boström233bfd22016-01-18 20:23:40 +0100357 rtc::CritScope lock(&encoder_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000358 frame_dropper_enabled_ = enable;
359 _mediaOpt.EnableFrameDropper(enable);
360 return VCM_OK;
361}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000362} // namespace vcm
363} // namespace webrtc