blob: d10e8fc5cda67313556eddbcb1cfa48875020394 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org07b45a52012-02-02 08:37:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Peter Boström7623ce42015-12-09 12:13:30 +010011#include "webrtc/video/vie_encoder.h"
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14
stefan@webrtc.orgc3cc3752013-06-04 09:36:56 +000015#include <algorithm>
niklase@google.com470e71d2011-07-07 08:21:25 +000016
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000017#include "webrtc/base/checks.h"
Peter Boström415d2cd2015-10-26 11:35:17 +010018#include "webrtc/base/logging.h"
tommie4f96502015-10-20 23:00:48 -070019#include "webrtc/base/trace_event.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020020#include "webrtc/base/timeutils.h"
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +010021#include "webrtc/modules/pacing/paced_sender.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010022#include "webrtc/modules/video_coding/include/video_coding.h"
23#include "webrtc/modules/video_coding/include/video_coding_defines.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010024#include "webrtc/system_wrappers/include/metrics.h"
Peter Boströme4499152016-02-05 11:13:28 +010025#include "webrtc/video/overuse_frame_detector.h"
pbos@webrtc.org273a4142014-12-01 15:23:21 +000026#include "webrtc/video/send_statistics_proxy.h"
Peter Boströme4499152016-02-05 11:13:28 +010027#include "webrtc/video_frame.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000028
niklase@google.com470e71d2011-07-07 08:21:25 +000029namespace webrtc {
30
stefan@webrtc.org3e005052013-10-18 15:05:29 +000031static const float kStopPaddingThresholdMs = 2000;
mflodmanc4a1c372015-11-06 04:33:51 -080032
mflodman0dbf0092015-10-19 08:12:12 -070033ViEEncoder::ViEEncoder(uint32_t number_of_cores,
Peter Boström7083e112015-09-22 16:28:51 +020034 ProcessThread* module_process_thread,
35 SendStatisticsProxy* stats_proxy,
Peter Boström00b9d212016-05-19 16:59:03 +020036 OveruseFrameDetector* overuse_detector,
37 EncodedImageCallback* sink)
mflodman0dbf0092015-10-19 08:12:12 -070038 : number_of_cores_(number_of_cores),
Peter Boström00b9d212016-05-19 16:59:03 +020039 sink_(sink),
mflodmana8565422015-12-07 01:09:52 -080040 vp_(VideoProcessing::Create()),
Peter Boströmad6fc5a2016-05-12 03:01:31 +020041 video_sender_(Clock::GetRealTimeClock(), this, this, this),
Peter Boström7083e112015-09-22 16:28:51 +020042 stats_proxy_(stats_proxy),
Peter Boströme4499152016-02-05 11:13:28 +010043 overuse_detector_(overuse_detector),
Noah Richards099323e2015-04-15 09:14:12 -070044 time_of_last_frame_activity_ms_(0),
Peter Boströmd153a372015-11-10 15:27:12 +000045 encoder_config_(),
Peter Boströma03785e2016-03-03 11:36:18 +010046 min_transmit_bitrate_bps_(0),
pbos@webrtc.org143451d2015-03-18 14:40:03 +000047 last_observed_bitrate_bps_(0),
perkjbc75d972016-05-02 06:31:25 -070048 encoder_paused_(true),
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000049 encoder_paused_and_dropped_frame_(false),
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000050 module_process_thread_(module_process_thread),
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000051 has_received_sli_(false),
52 picture_id_sli_(0),
53 has_received_rpsi_(false),
54 picture_id_rpsi_(0),
asaperssondec5ebf2015-10-05 02:36:17 -070055 video_suspended_(false) {
Peter Boströmcd5c25c2016-04-21 16:48:08 +020056 module_process_thread_->RegisterModule(&video_sender_);
mflodmana8565422015-12-07 01:09:52 -080057 vp_->EnableTemporalDecimation(true);
niklase@google.com470e71d2011-07-07 08:21:25 +000058}
59
Peter Boströmcd5c25c2016-04-21 16:48:08 +020060vcm::VideoSender* ViEEncoder::video_sender() {
61 return &video_sender_;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000062}
63
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000064ViEEncoder::~ViEEncoder() {
Peter Boströmcd5c25c2016-04-21 16:48:08 +020065 module_process_thread_->DeRegisterModule(&video_sender_);
asapersson@webrtc.org96dc6852014-11-03 14:40:38 +000066}
67
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000068void ViEEncoder::Pause() {
Tommi97888bd2016-01-21 23:24:59 +010069 rtc::CritScope lock(&data_cs_);
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +000070 encoder_paused_ = true;
niklase@google.com470e71d2011-07-07 08:21:25 +000071}
72
perkjbc75d972016-05-02 06:31:25 -070073void ViEEncoder::Start() {
Tommi97888bd2016-01-21 23:24:59 +010074 rtc::CritScope lock(&data_cs_);
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +000075 encoder_paused_ = false;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000076}
77
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000078int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder,
79 uint8_t pl_type,
80 bool internal_source) {
Peter Boströmcd5c25c2016-04-21 16:48:08 +020081 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000082 return 0;
83}
84
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000085int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) {
Peter Boströmcd5c25c2016-04-21 16:48:08 +020086 video_sender_.RegisterExternalEncoder(nullptr, pl_type, false);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000087 return 0;
88}
Peter Boström00b9d212016-05-19 16:59:03 +020089
Peter Boströma03785e2016-03-03 11:36:18 +010090void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec,
perkjbc75d972016-05-02 06:31:25 -070091 int min_transmit_bitrate_bps,
Peter Boström00b9d212016-05-19 16:59:03 +020092 size_t max_data_payload_length) {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000093 // Setting target width and height for VPM.
Peter Boström905f8e72016-03-02 16:59:56 +010094 RTC_CHECK_EQ(VPM_OK,
95 vp_->SetTargetResolution(video_codec.width, video_codec.height,
96 video_codec.maxFramerate));
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000097
mflodman86aabb22016-03-11 15:44:32 +010098 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated
Peter Boströmd153a372015-11-10 15:27:12 +000099 // that makes use of the number of simulcast streams configured).
stefan@webrtc.org9075d512014-02-14 09:45:58 +0000100 {
Tommi97888bd2016-01-21 23:24:59 +0100101 rtc::CritScope lock(&data_cs_);
Peter Boströmd153a372015-11-10 15:27:12 +0000102 encoder_config_ = video_codec;
Peter Boströma03785e2016-03-03 11:36:18 +0100103 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps;
stefan@webrtc.org9075d512014-02-14 09:45:58 +0000104 }
Stefan Holmere5904162015-03-26 11:11:06 +0100105
Peter Boströmcd5c25c2016-04-21 16:48:08 +0200106 bool success = video_sender_.RegisterSendCodec(
mflodman86aabb22016-03-11 15:44:32 +0100107 &video_codec, number_of_cores_,
Peter Boström905f8e72016-03-02 16:59:56 +0100108 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK;
109 if (!success) {
110 LOG(LS_ERROR) << "Failed to configure encoder.";
111 RTC_DCHECK(success);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000112 }
Peter Boström905f8e72016-03-02 16:59:56 +0100113
Peter Boströma03785e2016-03-03 11:36:18 +0100114 if (stats_proxy_) {
Peter Boström79a5cf92016-03-03 11:49:06 +0100115 VideoEncoderConfig::ContentType content_type =
116 VideoEncoderConfig::ContentType::kRealtimeVideo;
Peter Boströma03785e2016-03-03 11:36:18 +0100117 switch (video_codec.mode) {
118 case kRealtimeVideo:
119 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo;
120 break;
121 case kScreensharing:
122 content_type = VideoEncoderConfig::ContentType::kScreen;
123 break;
124 default:
125 RTC_NOTREACHED();
126 break;
127 }
128 stats_proxy_->SetContentType(content_type);
129 }
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000130}
131
stefana4a8d4a2015-07-15 04:39:22 -0700132int ViEEncoder::GetPaddingNeededBps() const {
Noah Richards099323e2015-04-15 09:14:12 -0700133 int64_t time_of_last_frame_activity_ms;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000134 int min_transmit_bitrate_bps;
stefana4a8d4a2015-07-15 04:39:22 -0700135 int bitrate_bps;
Peter Boströmd153a372015-11-10 15:27:12 +0000136 VideoCodec send_codec;
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +0000137 {
Tommi97888bd2016-01-21 23:24:59 +0100138 rtc::CritScope lock(&data_cs_);
Peter Boströmd153a372015-11-10 15:27:12 +0000139 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 ||
Peter Boströma03785e2016-03-03 11:36:18 +0100140 video_suspended_ || min_transmit_bitrate_bps_ > 0;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000141 if (!send_padding)
142 return 0;
Noah Richards099323e2015-04-15 09:14:12 -0700143 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_;
Peter Boströma03785e2016-03-03 11:36:18 +0100144 min_transmit_bitrate_bps = min_transmit_bitrate_bps_;
stefana4a8d4a2015-07-15 04:39:22 -0700145 bitrate_bps = last_observed_bitrate_bps_;
Peter Boströmd153a372015-11-10 15:27:12 +0000146 send_codec = encoder_config_;
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +0000147 }
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000148
Peter Boströmcd5c25c2016-04-21 16:48:08 +0200149 bool video_is_suspended = video_sender_.VideoSuspended();
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000150
151 // Find the max amount of padding we can allow ourselves to send at this
152 // point, based on which streams are currently active and what our current
153 // available bandwidth is.
154 int pad_up_to_bitrate_bps = 0;
155 if (send_codec.numberOfSimulcastStreams == 0) {
156 pad_up_to_bitrate_bps = send_codec.minBitrate * 1000;
157 } else {
stefana4a8d4a2015-07-15 04:39:22 -0700158 SimulcastStream* stream_configs = send_codec.simulcastStream;
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000159 pad_up_to_bitrate_bps =
160 stream_configs[send_codec.numberOfSimulcastStreams - 1].minBitrate *
161 1000;
162 for (int i = 0; i < send_codec.numberOfSimulcastStreams - 1; ++i) {
163 pad_up_to_bitrate_bps += stream_configs[i].targetBitrate * 1000;
164 }
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000165 }
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000166
167 // Disable padding if only sending one stream and video isn't suspended and
168 // min-transmit bitrate isn't used (applied later).
169 if (!video_is_suspended && send_codec.numberOfSimulcastStreams <= 1)
170 pad_up_to_bitrate_bps = 0;
171
172 // The amount of padding should decay to zero if no frames are being
Noah Richards099323e2015-04-15 09:14:12 -0700173 // captured/encoded unless a min-transmit bitrate is used.
Niels Möllerd28db7f2016-05-10 16:31:47 +0200174 int64_t now_ms = rtc::TimeMillis();
Noah Richards099323e2015-04-15 09:14:12 -0700175 if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs)
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000176 pad_up_to_bitrate_bps = 0;
177
178 // Pad up to min bitrate.
179 if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps)
180 pad_up_to_bitrate_bps = min_transmit_bitrate_bps;
181
182 // Padding may never exceed bitrate estimate.
183 if (pad_up_to_bitrate_bps > bitrate_bps)
184 pad_up_to_bitrate_bps = bitrate_bps;
185
186 return pad_up_to_bitrate_bps;
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000187}
188
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +0000189bool ViEEncoder::EncoderPaused() const {
pwestin@webrtc.org91563e42013-04-25 22:20:08 +0000190 // Pause video if paused by caller or as long as the network is down or the
191 // pacer queue has grown too large in buffered mode.
perkjfea93092016-05-14 00:58:48 -0700192 // If the pacer queue has grown to large or the network is down,
193 // last_observed_bitrate_bps_ will be 0.
194 return encoder_paused_ || video_suspended_ || last_observed_bitrate_bps_ == 0;
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +0000195}
196
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000197void ViEEncoder::TraceFrameDropStart() {
198 // Start trace event only on the first frame after encoder is paused.
199 if (!encoder_paused_and_dropped_frame_) {
200 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this);
201 }
202 encoder_paused_and_dropped_frame_ = true;
203 return;
204}
205
206void ViEEncoder::TraceFrameDropEnd() {
207 // End trace event on first frame after encoder resumes, if frame was dropped.
208 if (encoder_paused_and_dropped_frame_) {
209 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this);
210 }
211 encoder_paused_and_dropped_frame_ = false;
212}
213
Peter Boströma4c76882016-03-03 16:29:02 +0100214void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) {
Peter Boströmd153a372015-11-10 15:27:12 +0000215 VideoCodecType codec_type;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000216 {
Tommi97888bd2016-01-21 23:24:59 +0100217 rtc::CritScope lock(&data_cs_);
Niels Möllerd28db7f2016-05-10 16:31:47 +0200218 time_of_last_frame_activity_ms_ = rtc::TimeMillis();
pwestin@webrtc.org52b4e882013-05-02 19:02:17 +0000219 if (EncoderPaused()) {
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000220 TraceFrameDropStart();
pwestin@webrtc.org52b4e882013-05-02 19:02:17 +0000221 return;
222 }
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000223 TraceFrameDropEnd();
Peter Boströmd153a372015-11-10 15:27:12 +0000224 codec_type = encoder_config_.codecType;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000225 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
Magnus Jedvert26679d62015-04-07 14:07:41 +0200227 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(),
hclam@chromium.org1a7b9b92013-07-08 21:31:18 +0000228 "Encode");
mflodmana8565422015-12-07 01:09:52 -0800229 const VideoFrame* frame_to_send = &video_frame;
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +0000230 // TODO(wuchengli): support texture frames.
nisse26acec42016-04-15 03:43:39 -0700231 if (!video_frame.video_frame_buffer()->native_handle()) {
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +0000232 // Pass frame via preprocessor.
mflodmana8565422015-12-07 01:09:52 -0800233 frame_to_send = vp_->PreprocessFrame(video_frame);
234 if (!frame_to_send) {
235 // Drop this frame, or there was an error processing it.
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +0000236 return;
237 }
pwestin@webrtc.org2f476ed2012-10-30 16:21:52 +0000238 }
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000239
Peter Boströmd153a372015-11-10 15:27:12 +0000240 if (codec_type == webrtc::kVideoCodecVP8) {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000241 webrtc::CodecSpecificInfo codec_specific_info;
242 codec_specific_info.codecType = webrtc::kVideoCodecVP8;
stefan@webrtc.org7af12be2014-07-09 14:46:31 +0000243 {
Tommi97888bd2016-01-21 23:24:59 +0100244 rtc::CritScope lock(&data_cs_);
stefan@webrtc.org7af12be2014-07-09 14:46:31 +0000245 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI =
246 has_received_rpsi_;
247 codec_specific_info.codecSpecific.VP8.hasReceivedSLI =
248 has_received_sli_;
249 codec_specific_info.codecSpecific.VP8.pictureIdRPSI =
250 picture_id_rpsi_;
251 codec_specific_info.codecSpecific.VP8.pictureIdSLI =
252 picture_id_sli_;
253 has_received_sli_ = false;
254 has_received_rpsi_ = false;
255 }
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000256
Peter Boströmad6fc5a2016-05-12 03:01:31 +0200257 video_sender_.AddVideoFrame(*frame_to_send, &codec_specific_info);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000258 return;
259 }
Peter Boströmad6fc5a2016-05-12 03:01:31 +0200260 video_sender_.AddVideoFrame(*frame_to_send, nullptr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000261}
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
Peter Boström233bfd22016-01-18 20:23:40 +0100263void ViEEncoder::SendKeyFrame() {
Peter Boströmcd5c25c2016-04-21 16:48:08 +0200264 video_sender_.IntraFrameRequest(0);
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000265}
266
Peter Boströmd153a372015-11-10 15:27:12 +0000267void ViEEncoder::SetProtectionMethod(bool nack, bool fec) {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000268 // Set Video Protection for VCM.
pbosba8c15b2015-07-14 09:36:34 -0700269 VCMVideoProtection protection_mode;
Peter Boströmd153a372015-11-10 15:27:12 +0000270 if (fec) {
pbosba8c15b2015-07-14 09:36:34 -0700271 protection_mode =
Peter Boströmd153a372015-11-10 15:27:12 +0000272 nack ? webrtc::kProtectionNackFEC : kProtectionFEC;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000273 } else {
Peter Boströmd153a372015-11-10 15:27:12 +0000274 protection_mode = nack ? kProtectionNack : kProtectionNone;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000275 }
Peter Boströmcd5c25c2016-04-21 16:48:08 +0200276 video_sender_.SetVideoProtection(protection_mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000277}
278
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000279void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) {
Peter Boström7083e112015-09-22 16:28:51 +0200280 if (stats_proxy_)
281 stats_proxy_->OnSetRates(bitrate_bps, framerate);
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000282}
283
kjellander02b3d272016-04-20 05:05:54 -0700284int32_t ViEEncoder::Encoded(const EncodedImage& encoded_image,
285 const CodecSpecificInfo* codec_specific_info,
286 const RTPFragmentationHeader* fragmentation) {
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000287 {
Tommi97888bd2016-01-21 23:24:59 +0100288 rtc::CritScope lock(&data_cs_);
Niels Möllerd28db7f2016-05-10 16:31:47 +0200289 time_of_last_frame_activity_ms_ = rtc::TimeMillis();
Noah Richards099323e2015-04-15 09:14:12 -0700290 }
kjellander02b3d272016-04-20 05:05:54 -0700291 if (stats_proxy_) {
292 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info);
293 }
sprang3911c262016-04-15 01:24:14 -0700294
Peter Boström00b9d212016-05-19 16:59:03 +0200295 int success =
296 sink_->Encoded(encoded_image, codec_specific_info, fragmentation);
perkjbc75d972016-05-02 06:31:25 -0700297
298 overuse_detector_->FrameSent(encoded_image._timeStamp);
kjellander02b3d272016-04-20 05:05:54 -0700299 return success;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100300}
301
perkj376b1922016-05-02 11:35:24 -0700302void ViEEncoder::SendStatistics(uint32_t bit_rate,
303 uint32_t frame_rate,
304 const std::string& encoder_name) {
Peter Boström7083e112015-09-22 16:28:51 +0200305 if (stats_proxy_)
perkj376b1922016-05-02 11:35:24 -0700306 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate, encoder_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307}
308
perkj600246e2016-05-04 11:26:51 -0700309void ViEEncoder::OnReceivedSLI(uint8_t picture_id) {
Tommi97888bd2016-01-21 23:24:59 +0100310 rtc::CritScope lock(&data_cs_);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000311 picture_id_sli_ = picture_id;
312 has_received_sli_ = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000313}
314
perkj600246e2016-05-04 11:26:51 -0700315void ViEEncoder::OnReceivedRPSI(uint64_t picture_id) {
Tommi97888bd2016-01-21 23:24:59 +0100316 rtc::CritScope lock(&data_cs_);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000317 picture_id_rpsi_ = picture_id;
318 has_received_rpsi_ = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
perkj600246e2016-05-04 11:26:51 -0700321void ViEEncoder::OnReceivedIntraFrameRequest(size_t stream_index) {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000322 // Key frame request from remote side, signal to VCM.
justinlin@chromium.org7bfb3a32013-05-13 22:59:00 +0000323 TRACE_EVENT0("webrtc", "OnKeyFrameRequest");
perkj600246e2016-05-04 11:26:51 -0700324 video_sender_.IntraFrameRequest(stream_index);
mflodman@webrtc.orgaca26292012-10-05 16:17:41 +0000325}
326
mflodman86aabb22016-03-11 15:44:32 +0100327void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +0000328 uint8_t fraction_lost,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000329 int64_t round_trip_time_ms) {
perkjec81bcd2016-05-11 06:01:13 -0700330 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps
mflodman8602a3d2015-05-20 15:54:42 -0700331 << " packet loss " << static_cast<int>(fraction_lost)
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000332 << " rtt " << round_trip_time_ms;
Peter Boströmcd5c25c2016-04-21 16:48:08 +0200333 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost,
334 round_trip_time_ms);
335 bool video_is_suspended = video_sender_.VideoSuspended();
Peter Boströmd153a372015-11-10 15:27:12 +0000336 bool video_suspension_changed;
Peter Boströmd153a372015-11-10 15:27:12 +0000337 {
Tommi97888bd2016-01-21 23:24:59 +0100338 rtc::CritScope lock(&data_cs_);
Peter Boströmd153a372015-11-10 15:27:12 +0000339 last_observed_bitrate_bps_ = bitrate_bps;
340 video_suspension_changed = video_suspended_ != video_is_suspended;
341 video_suspended_ = video_is_suspended;
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000342 }
Peter Boströmd153a372015-11-10 15:27:12 +0000343
Peter Boströmd153a372015-11-10 15:27:12 +0000344 if (!video_suspension_changed)
345 return;
Peter Boström7083e112015-09-22 16:28:51 +0200346 // Video suspend-state changed, inform codec observer.
perkj600246e2016-05-04 11:26:51 -0700347 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended;
348
Peter Boström7083e112015-09-22 16:28:51 +0200349 if (stats_proxy_)
350 stats_proxy_->OnSuspendChange(video_is_suspended);
niklase@google.com470e71d2011-07-07 08:21:25 +0000351}
352
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000353} // namespace webrtc