blob: fd642fd24a7d882083936e8de9758b799f1fe2dd [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
sprang3911c262016-04-15 01:24:14 -07002* Copyright (c) 2012 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*/
niklase@google.com470e71d2011-07-07 08:21:25 +000010
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/generic_encoder.h"
philipel9d3ab612015-12-21 04:12:39 -080012
13#include <vector>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/optional.h"
16#include "api/video/i420_buffer.h"
17#include "modules/pacing/alr_detector.h"
18#include "modules/video_coding/encoded_frame.h"
19#include "modules/video_coding/media_optimization.h"
20#include "rtc_base/checks.h"
21#include "rtc_base/logging.h"
22#include "rtc_base/timeutils.h"
23#include "rtc_base/trace_event.h"
24#include "system_wrappers/include/field_trial.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26namespace webrtc {
Sergey Ulanov525df3f2016-08-02 17:46:41 -070027
Peter Boström4f5db112015-10-29 16:53:59 +010028VCMGenericEncoder::VCMGenericEncoder(
29 VideoEncoder* encoder,
Peter Boström4f5db112015-10-29 16:53:59 +010030 VCMEncodedFrameCallback* encoded_frame_callback,
sprang3911c262016-04-15 01:24:14 -070031 bool internal_source)
pbos@webrtc.org891d4832015-02-26 13:15:22 +000032 : encoder_(encoder),
Peter Boström4f5db112015-10-29 16:53:59 +010033 vcm_encoded_frame_callback_(encoded_frame_callback),
sprang3911c262016-04-15 01:24:14 -070034 internal_source_(internal_source),
Erik Språng08127a92016-11-16 16:41:30 +010035 encoder_params_({BitrateAllocation(), 0, 0, 0}),
ilnik04f4d122017-06-19 07:18:55 -070036 streams_or_svc_num_(0) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000037
Peter Boström4f5db112015-10-29 16:53:59 +010038VCMGenericEncoder::~VCMGenericEncoder() {}
39
40int32_t VCMGenericEncoder::Release() {
Peter Boström02bafc62016-07-01 12:45:15 +020041 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
Peter Boström4fd6cda2016-01-26 10:19:53 +010042 TRACE_EVENT0("webrtc", "VCMGenericEncoder::Release");
Peter Boström4f5db112015-10-29 16:53:59 +010043 return encoder_->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
45
Peter Boström4f5db112015-10-29 16:53:59 +010046int32_t VCMGenericEncoder::InitEncode(const VideoCodec* settings,
sprang3911c262016-04-15 01:24:14 -070047 int32_t number_of_cores,
48 size_t max_payload_size) {
Peter Boström02bafc62016-07-01 12:45:15 +020049 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
pbosd9eec762015-11-17 06:03:43 -080050 TRACE_EVENT0("webrtc", "VCMGenericEncoder::InitEncode");
ilnik04f4d122017-06-19 07:18:55 -070051 streams_or_svc_num_ = settings->numberOfSimulcastStreams;
Ilya Nikolaevskiye0da9ea2017-11-08 14:39:02 +010052 codec_type_ = settings->codecType;
ilnik04f4d122017-06-19 07:18:55 -070053 if (settings->codecType == kVideoCodecVP9) {
54 streams_or_svc_num_ = settings->VP9().numberOfSpatialLayers;
55 }
56 if (streams_or_svc_num_ == 0)
57 streams_or_svc_num_ = 1;
58
59 vcm_encoded_frame_callback_->SetTimingFramesThresholds(
60 settings->timing_frame_thresholds);
61 vcm_encoded_frame_callback_->OnFrameRateChanged(settings->maxFramerate);
62
sprang3911c262016-04-15 01:24:14 -070063 if (encoder_->InitEncode(settings, number_of_cores, max_payload_size) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010064 RTC_LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
65 "payload name: "
66 << settings->plName;
Peter Boström4f5db112015-10-29 16:53:59 +010067 return -1;
68 }
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +020069 vcm_encoded_frame_callback_->Reset();
Peter Boström4f5db112015-10-29 16:53:59 +010070 encoder_->RegisterEncodeCompleteCallback(vcm_encoded_frame_callback_);
71 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000072}
73
sprang3911c262016-04-15 01:24:14 -070074int32_t VCMGenericEncoder::Encode(const VideoFrame& frame,
75 const CodecSpecificInfo* codec_specific,
76 const std::vector<FrameType>& frame_types) {
Peter Boström02bafc62016-07-01 12:45:15 +020077 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
pbosd9eec762015-11-17 06:03:43 -080078 TRACE_EVENT1("webrtc", "VCMGenericEncoder::Encode", "timestamp",
sprang3911c262016-04-15 01:24:14 -070079 frame.timestamp());
pbosd9eec762015-11-17 06:03:43 -080080
sprang3911c262016-04-15 01:24:14 -070081 for (FrameType frame_type : frame_types)
pbos22993e12015-10-19 02:39:06 -070082 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta);
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000083
ilnik04f4d122017-06-19 07:18:55 -070084 for (size_t i = 0; i < streams_or_svc_num_; ++i)
85 vcm_encoded_frame_callback_->OnEncodeStarted(frame.render_time_ms(), i);
Peter Boströmb7d9a972015-12-18 16:01:11 +010086
ilnike9973812017-09-12 10:24:46 -070087 return encoder_->Encode(frame, codec_specific, &frame_types);
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
Peter Boström69ccb332015-10-29 16:30:23 +010090void VCMGenericEncoder::SetEncoderParameters(const EncoderParameters& params) {
Peter Boström02bafc62016-07-01 12:45:15 +020091 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
Peter Boström69ccb332015-10-29 16:30:23 +010092 bool channel_parameters_have_changed;
93 bool rates_have_changed;
94 {
95 rtc::CritScope lock(&params_lock_);
96 channel_parameters_have_changed =
97 params.loss_rate != encoder_params_.loss_rate ||
98 params.rtt != encoder_params_.rtt;
99 rates_have_changed =
100 params.target_bitrate != encoder_params_.target_bitrate ||
101 params.input_frame_rate != encoder_params_.input_frame_rate;
102 encoder_params_ = params;
103 }
Erik Språng08127a92016-11-16 16:41:30 +0100104 if (channel_parameters_have_changed) {
105 int res = encoder_->SetChannelParameters(params.loss_rate, params.rtt);
106 if (res != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100107 RTC_LOG(LS_WARNING) << "Error set encoder parameters (loss = "
108 << params.loss_rate << ", rtt = " << params.rtt
109 << "): " << res;
Erik Språng08127a92016-11-16 16:41:30 +0100110 }
111 }
Peter Boström69ccb332015-10-29 16:30:23 +0100112 if (rates_have_changed) {
Erik Språng08127a92016-11-16 16:41:30 +0100113 int res = encoder_->SetRateAllocation(params.target_bitrate,
114 params.input_frame_rate);
115 if (res != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100116 RTC_LOG(LS_WARNING) << "Error set encoder rate (total bitrate bps = "
117 << params.target_bitrate.get_sum_bps()
118 << ", framerate = " << params.input_frame_rate
119 << "): " << res;
Erik Språng08127a92016-11-16 16:41:30 +0100120 }
ilnik04f4d122017-06-19 07:18:55 -0700121 vcm_encoded_frame_callback_->OnFrameRateChanged(params.input_frame_rate);
122 for (size_t i = 0; i < streams_or_svc_num_; ++i) {
123 size_t layer_bitrate_bytes_per_sec =
124 params.target_bitrate.GetSpatialLayerSum(i) / 8;
125 // VP9 rate control is not yet moved out of VP9Impl. Due to that rates
Ilya Nikolaevskiye0da9ea2017-11-08 14:39:02 +0100126 // are not split among spatial layers. Use default 1:2:4 bitrate
127 // distribution.
128 // TODO(ilnik): move bitrate per spatial layer calculations out of
129 // vp9_impl.cc and drop the check below.
130 if (codec_type_ == kVideoCodecVP9) {
131 int scaling_factor_num = 1 << i; // 1, 2 or 4
132 int scaling_factor_den = (1 << streams_or_svc_num_) - 1; // 1 + 2 + 4
133 layer_bitrate_bytes_per_sec = params.target_bitrate.get_sum_bps() / 8 *
134 scaling_factor_num / scaling_factor_den;
135 }
ilnik04f4d122017-06-19 07:18:55 -0700136 vcm_encoded_frame_callback_->OnTargetBitrateChanged(
137 layer_bitrate_bytes_per_sec, i);
138 }
Peter Boström69ccb332015-10-29 16:30:23 +0100139 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000140}
141
Peter Boström69ccb332015-10-29 16:30:23 +0100142EncoderParameters VCMGenericEncoder::GetEncoderParameters() const {
143 rtc::CritScope lock(&params_lock_);
144 return encoder_params_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000145}
146
philipel9d3ab612015-12-21 04:12:39 -0800147int32_t VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) {
Peter Boström02bafc62016-07-01 12:45:15 +0200148 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
philipel9d3ab612015-12-21 04:12:39 -0800149 return encoder_->SetPeriodicKeyFrames(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000150}
151
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +0000152int32_t VCMGenericEncoder::RequestFrame(
stefan@webrtc.orgcf216862012-10-25 11:29:51 +0000153 const std::vector<FrameType>& frame_types) {
Peter Boström02bafc62016-07-01 12:45:15 +0200154 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
nissedf2ceb82016-12-15 06:29:53 -0800155
156 // TODO(nisse): Used only with internal source. Delete as soon as
157 // that feature is removed. The only implementation I've been able
nisse01d5a0b2017-05-31 06:33:21 -0700158 // to find ignores what's in the frame. With one exception: It seems
159 // a few test cases, e.g.,
160 // VideoSendStreamTest.VideoSendStreamStopSetEncoderRateToZero, set
161 // internal_source to true and use FakeEncoder. And the latter will
162 // happily encode this 1x1 frame and pass it on down the pipeline.
nissedf2ceb82016-12-15 06:29:53 -0800163 return encoder_->Encode(VideoFrame(I420Buffer::Create(1, 1),
164 kVideoRotation_0, 0),
165 NULL, &frame_types);
166 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167}
168
philipel9d3ab612015-12-21 04:12:39 -0800169bool VCMGenericEncoder::InternalSource() const {
170 return internal_source_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171}
172
Peter Boströmeb66e802015-06-05 11:08:03 +0200173bool VCMGenericEncoder::SupportsNativeHandle() const {
Peter Boström02bafc62016-07-01 12:45:15 +0200174 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
Peter Boströmeb66e802015-06-05 11:08:03 +0200175 return encoder_->SupportsNativeHandle();
176}
177
andresp@webrtc.org1df9dc32014-01-09 08:01:57 +0000178VCMEncodedFrameCallback::VCMEncodedFrameCallback(
perkj376b1922016-05-02 11:35:24 -0700179 EncodedImageCallback* post_encode_callback,
180 media_optimization::MediaOptimization* media_opt)
181 : internal_source_(false),
182 post_encode_callback_(post_encode_callback),
ilnik04f4d122017-06-19 07:18:55 -0700183 media_opt_(media_opt),
184 framerate_(1),
185 last_timing_frame_time_ms_(-1),
ilnik6d5b4d62017-08-30 03:32:14 -0700186 timing_frames_thresholds_({-1, 0}) {
187 rtc::Optional<AlrDetector::AlrExperimentSettings> experiment_settings =
188 AlrDetector::ParseAlrSettingsFromFieldTrial(
189 AlrDetector::kStrictPacingAndProbingExperimentName);
190 if (experiment_settings) {
191 experiment_groups_[0] = experiment_settings->group_id + 1;
192 } else {
193 experiment_groups_[0] = 0;
194 }
195 experiment_settings = AlrDetector::ParseAlrSettingsFromFieldTrial(
196 AlrDetector::kScreenshareProbingBweExperimentName);
197 if (experiment_settings) {
198 experiment_groups_[1] = experiment_settings->group_id + 1;
199 } else {
200 experiment_groups_[1] = 0;
201 }
202}
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
sprang3911c262016-04-15 01:24:14 -0700204VCMEncodedFrameCallback::~VCMEncodedFrameCallback() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
ilnik04f4d122017-06-19 07:18:55 -0700206void VCMEncodedFrameCallback::OnTargetBitrateChanged(
207 size_t bitrate_bytes_per_second,
208 size_t simulcast_svc_idx) {
209 rtc::CritScope crit(&timing_params_lock_);
210 if (timing_frames_info_.size() < simulcast_svc_idx + 1)
211 timing_frames_info_.resize(simulcast_svc_idx + 1);
212 timing_frames_info_[simulcast_svc_idx].target_bitrate_bytes_per_sec =
213 bitrate_bytes_per_second;
214}
215
216void VCMEncodedFrameCallback::OnFrameRateChanged(size_t framerate) {
217 rtc::CritScope crit(&timing_params_lock_);
218 framerate_ = framerate;
219}
220
221void VCMEncodedFrameCallback::OnEncodeStarted(int64_t capture_time_ms,
222 size_t simulcast_svc_idx) {
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200223 if (internal_source_) {
224 return;
225 }
ilnik04f4d122017-06-19 07:18:55 -0700226 rtc::CritScope crit(&timing_params_lock_);
227 if (timing_frames_info_.size() < simulcast_svc_idx + 1)
228 timing_frames_info_.resize(simulcast_svc_idx + 1);
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200229 RTC_DCHECK(
230 timing_frames_info_[simulcast_svc_idx].encode_start_list.empty() ||
231 rtc::TimeDiff(capture_time_ms, timing_frames_info_[simulcast_svc_idx]
232 .encode_start_list.back()
233 .capture_time_ms) >= 0);
Ilya Nikolaevskiye0da9ea2017-11-08 14:39:02 +0100234 // If stream is disabled due to low bandwidth OnEncodeStarted still will be
235 // called and have to be ignored.
236 if (timing_frames_info_[simulcast_svc_idx].target_bitrate_bytes_per_sec == 0)
237 return;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200238 if (timing_frames_info_[simulcast_svc_idx].encode_start_list.size() ==
239 kMaxEncodeStartTimeListSize) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100240 RTC_LOG(LS_WARNING) << "Too many frames in the encode_start_list."
241 " Did encoder stall?";
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200242 post_encode_callback_->OnDroppedFrame(DropReason::kDroppedByEncoder);
243 timing_frames_info_[simulcast_svc_idx].encode_start_list.pop_front();
244 }
245 timing_frames_info_[simulcast_svc_idx].encode_start_list.emplace_back(
246 capture_time_ms, rtc::TimeMillis());
ilnik04f4d122017-06-19 07:18:55 -0700247}
248
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700249EncodedImageCallback::Result VCMEncodedFrameCallback::OnEncodedImage(
Peter Boströmb7d9a972015-12-18 16:01:11 +0100250 const EncodedImage& encoded_image,
sprang3911c262016-04-15 01:24:14 -0700251 const CodecSpecificInfo* codec_specific,
252 const RTPFragmentationHeader* fragmentation_header) {
pbosd9eec762015-11-17 06:03:43 -0800253 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded",
Peter Boströmb7d9a972015-12-18 16:01:11 +0100254 "timestamp", encoded_image._timeStamp);
ilnik04f4d122017-06-19 07:18:55 -0700255 size_t simulcast_svc_idx = 0;
256 if (codec_specific->codecType == kVideoCodecVP9) {
257 if (codec_specific->codecSpecific.VP9.num_spatial_layers > 1)
258 simulcast_svc_idx = codec_specific->codecSpecific.VP9.spatial_idx;
259 } else if (codec_specific->codecType == kVideoCodecVP8) {
260 simulcast_svc_idx = codec_specific->codecSpecific.VP8.simulcastIdx;
261 } else if (codec_specific->codecType == kVideoCodecGeneric) {
262 simulcast_svc_idx = codec_specific->codecSpecific.generic.simulcast_idx;
263 } else if (codec_specific->codecType == kVideoCodecH264) {
264 // TODO(ilnik): When h264 simulcast is landed, extract simulcast idx here.
265 }
266
ilnik29d08402017-07-11 08:08:12 -0700267 rtc::Optional<size_t> outlier_frame_size;
268 rtc::Optional<int64_t> encode_start_ms;
ilnik6d5b4d62017-08-30 03:32:14 -0700269 size_t num_simulcast_svc_streams = 1;
Niels Möllerc241af92017-11-10 08:51:29 +0100270 uint8_t timing_flags = TimingFrameFlags::kNotTriggered;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200271 if (!internal_source_) {
ilnik04f4d122017-06-19 07:18:55 -0700272 rtc::CritScope crit(&timing_params_lock_);
ilnik0b1e2f32017-07-10 12:25:29 -0700273
ilnik29d08402017-07-11 08:08:12 -0700274 // Encoders with internal sources do not call OnEncodeStarted and
275 // OnFrameRateChanged. |timing_frames_info_| may be not filled here.
ilnik6d5b4d62017-08-30 03:32:14 -0700276 num_simulcast_svc_streams = timing_frames_info_.size();
277 if (simulcast_svc_idx < num_simulcast_svc_streams) {
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200278 auto encode_start_list =
279 &timing_frames_info_[simulcast_svc_idx].encode_start_list;
280 // Skip frames for which there was OnEncodeStarted but no OnEncodedImage
281 // call. These are dropped by encoder internally.
282 while (!encode_start_list->empty() &&
283 encode_start_list->front().capture_time_ms <
284 encoded_image.capture_time_ms_) {
285 post_encode_callback_->OnDroppedFrame(DropReason::kDroppedByEncoder);
286 encode_start_list->pop_front();
287 }
288 if (encode_start_list->size() > 0 &&
289 encode_start_list->front().capture_time_ms ==
290 encoded_image.capture_time_ms_) {
291 encode_start_ms.emplace(
292 encode_start_list->front().encode_start_time_ms);
293 encode_start_list->pop_front();
Ilya Nikolaevskiye0da9ea2017-11-08 14:39:02 +0100294 } else {
295 LOG(LS_WARNING) << "Frame with no encode started time recordings. "
296 "Encoder may be reordering frames.";
ilnik3635f442017-06-28 03:53:19 -0700297 }
298
ilnik29d08402017-07-11 08:08:12 -0700299 size_t target_bitrate =
300 timing_frames_info_[simulcast_svc_idx].target_bitrate_bytes_per_sec;
301 if (framerate_ > 0 && target_bitrate > 0) {
302 // framerate and target bitrate were reported by encoder.
303 size_t average_frame_size = target_bitrate / framerate_;
304 outlier_frame_size.emplace(
305 average_frame_size *
306 timing_frames_thresholds_.outlier_ratio_percent / 100);
ilnik0b1e2f32017-07-10 12:25:29 -0700307 }
ilnik29d08402017-07-11 08:08:12 -0700308 }
309
310 // Check if it's time to send a timing frame.
311 int64_t timing_frame_delay_ms =
312 encoded_image.capture_time_ms_ - last_timing_frame_time_ms_;
313 // Trigger threshold if it's a first frame, too long passed since the last
314 // timing frame, or we already sent timing frame on a different simulcast
315 // stream with the same capture time.
316 if (last_timing_frame_time_ms_ == -1 ||
317 timing_frame_delay_ms >= timing_frames_thresholds_.delay_ms ||
318 timing_frame_delay_ms == 0) {
sprangba050a62017-08-18 02:51:12 -0700319 timing_flags = TimingFrameFlags::kTriggeredByTimer;
ilnik29d08402017-07-11 08:08:12 -0700320 last_timing_frame_time_ms_ = encoded_image.capture_time_ms_;
321 }
322
323 // Outliers trigger timing frames, but do not affect scheduled timing
324 // frames.
325 if (outlier_frame_size && encoded_image._length >= *outlier_frame_size) {
sprangba050a62017-08-18 02:51:12 -0700326 timing_flags |= TimingFrameFlags::kTriggeredBySize;
ilnik04f4d122017-06-19 07:18:55 -0700327 }
ilnik04f4d122017-06-19 07:18:55 -0700328 }
329
ilnik29d08402017-07-11 08:08:12 -0700330 // If encode start is not available that means that encoder uses internal
331 // source. In that case capture timestamp may be from a different clock with a
332 // drift relative to rtc::TimeMillis(). We can't use it for Timing frames,
333 // because to being sent in the network capture time required to be less than
334 // all the other timestamps.
Niels Möllerc241af92017-11-10 08:51:29 +0100335 if (encode_start_ms) {
ilnik29d08402017-07-11 08:08:12 -0700336 encoded_image.SetEncodeTime(*encode_start_ms, rtc::TimeMillis());
sprangba050a62017-08-18 02:51:12 -0700337 encoded_image.timing_.flags = timing_flags;
338 } else {
339 encoded_image.timing_.flags = TimingFrameFlags::kInvalid;
ilnik04f4d122017-06-19 07:18:55 -0700340 }
341
ilnik6d5b4d62017-08-30 03:32:14 -0700342 // Piggyback ALR experiment group id and simulcast id into the content type.
343 uint8_t experiment_id =
344 experiment_groups_[videocontenttypehelpers::IsScreenshare(
345 encoded_image.content_type_)];
346
347 // TODO(ilnik): This will force content type extension to be present even
348 // for realtime video. At the expense of miniscule overhead we will get
349 // sliced receive statistics.
350 RTC_CHECK(videocontenttypehelpers::SetExperimentId(
351 &encoded_image.content_type_, experiment_id));
352 // We count simulcast streams from 1 on the wire. That's why we set simulcast
353 // id in content type to +1 of that is actual simulcast index. This is because
354 // value 0 on the wire is reserved for 'no simulcast stream specified'.
355 RTC_CHECK(videocontenttypehelpers::SetSimulcastId(
356 &encoded_image.content_type_,
357 static_cast<uint8_t>(simulcast_svc_idx + 1)));
358
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700359 Result result = post_encode_callback_->OnEncodedImage(
360 encoded_image, codec_specific, fragmentation_header);
361 if (result.error != Result::OK)
362 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
sprang3911c262016-04-15 01:24:14 -0700364 if (media_opt_) {
365 media_opt_->UpdateWithEncodedData(encoded_image);
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700366 if (internal_source_) {
367 // Signal to encoder to drop next frame.
368 result.drop_next_frame = media_opt_->DropFrame();
369 }
changbin.shao@webrtc.orgf31f56d2015-02-09 09:14:03 +0000370 }
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700371 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372}
373
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000374} // namespace webrtc