blob: 444a5b9f67f3c7e43b01163b4e4ecdb4d825201a [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <cstdint>
14#include <vector>
15
16#include "api/rtp_headers.h"
17#include "api/video_codecs/video_codec.h"
18#include "api/video_codecs/video_decoder.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "modules/include/module_common_types.h"
Tommifbf3bce2018-02-21 15:56:05 +010020#include "modules/utility/include/process_thread.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "modules/video_coding/decoder_database.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/video_coding/encoded_frame.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "modules/video_coding/generic_decoder.h"
24#include "modules/video_coding/include/video_coding.h"
25#include "modules/video_coding/include/video_coding_defines.h"
26#include "modules/video_coding/internal_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/video_coding/jitter_buffer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "modules/video_coding/media_opt_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "modules/video_coding/packet.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "modules/video_coding/receiver.h"
31#include "modules/video_coding/timing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "modules/video_coding/video_coding_impl.h"
33#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "rtc_base/critical_section.h"
Tommifbf3bce2018-02-21 15:56:05 +010035#include "rtc_base/location.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080037#include "rtc_base/one_time_event.h"
Yves Gerey3e707812018-11-28 16:47:49 +010038#include "rtc_base/thread_checker.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "rtc_base/trace_event.h"
40#include "system_wrappers/include/clock.h"
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000041
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000042namespace webrtc {
43namespace vcm {
44
Niels Möllerdb64d992019-03-29 14:30:53 +010045VideoReceiver::VideoReceiver(Clock* clock, VCMTiming* timing)
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000046 : clock_(clock),
philipel721d4022016-12-15 07:10:57 -080047 _timing(timing),
Niels Möllerdb64d992019-03-29 14:30:53 +010048 _receiver(_timing, clock_),
philipel721d4022016-12-15 07:10:57 -080049 _decodedFrameCallback(_timing, clock_),
sprang3911c262016-04-15 01:24:14 -070050 _frameTypeCallback(nullptr),
sprang3911c262016-04-15 01:24:14 -070051 _packetRequestCallback(nullptr),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000052 _scheduleKeyRequest(false),
Peter Boströmed3277b2016-02-02 15:40:04 +010053 drop_frames_until_keyframe_(false),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000054 max_nack_list_size_(0),
Niels Möllerf9063782018-02-20 16:09:48 +010055 _codecDataBase(),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000056 _receiveStatsTimer(1000, clock_),
57 _retransmissionTimer(10, clock_),
Tommifbf3bce2018-02-21 15:56:05 +010058 _keyRequestTimer(500, clock_) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020059 decoder_thread_checker_.Detach();
60 module_thread_checker_.Detach();
Tommifbf3bce2018-02-21 15:56:05 +010061}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000062
Tommifbf3bce2018-02-21 15:56:05 +010063VideoReceiver::~VideoReceiver() {
64 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
65}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000066
pbosa26ac922016-02-25 04:50:01 -080067void VideoReceiver::Process() {
Tommifbf3bce2018-02-21 15:56:05 +010068 RTC_DCHECK_RUN_ON(&module_thread_checker_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000069 // Receive-side statistics
philipela45102f2017-02-22 05:30:39 -080070
71 // TODO(philipel): Remove this if block when we know what to do with
72 // ReceiveStatisticsProxy::QualitySample.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000073 if (_receiveStatsTimer.TimeUntilProcess() == 0) {
74 _receiveStatsTimer.Processed();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000075 }
76
77 // Key frame requests
78 if (_keyRequestTimer.TimeUntilProcess() == 0) {
79 _keyRequestTimer.Processed();
Tommifbf3bce2018-02-21 15:56:05 +010080 bool request_key_frame = _frameTypeCallback != nullptr;
81 if (request_key_frame) {
sprang3911c262016-04-15 01:24:14 -070082 rtc::CritScope cs(&process_crit_);
Tommifbf3bce2018-02-21 15:56:05 +010083 request_key_frame = _scheduleKeyRequest;
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +000084 }
pbosa26ac922016-02-25 04:50:01 -080085 if (request_key_frame)
86 RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000087 }
88
89 // Packet retransmission requests
90 // TODO(holmer): Add API for changing Process interval and make sure it's
91 // disabled when NACK is off.
92 if (_retransmissionTimer.TimeUntilProcess() == 0) {
93 _retransmissionTimer.Processed();
Tommifbf3bce2018-02-21 15:56:05 +010094 bool callback_registered = _packetRequestCallback != nullptr;
95 uint16_t length = max_nack_list_size_;
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +000096 if (callback_registered && length > 0) {
Wan-Teh Changb1825a42015-06-03 15:03:35 -070097 // Collect sequence numbers from the default receiver.
98 bool request_key_frame = false;
99 std::vector<uint16_t> nackList = _receiver.NackList(&request_key_frame);
100 int32_t ret = VCM_OK;
101 if (request_key_frame) {
102 ret = RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000103 }
Wan-Teh Changb1825a42015-06-03 15:03:35 -0700104 if (ret == VCM_OK && !nackList.empty()) {
guidouc3372582017-04-04 07:16:21 -0700105 rtc::CritScope cs(&process_crit_);
sprang3911c262016-04-15 01:24:14 -0700106 if (_packetRequestCallback != nullptr) {
Wan-Teh Changb1825a42015-06-03 15:03:35 -0700107 _packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +0000108 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000109 }
110 }
111 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000112}
113
Tommifbf3bce2018-02-21 15:56:05 +0100114void VideoReceiver::ProcessThreadAttached(ProcessThread* process_thread) {
115 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
116 if (process_thread) {
117 is_attached_to_process_thread_ = true;
118 RTC_DCHECK(!process_thread_ || process_thread_ == process_thread);
119 process_thread_ = process_thread;
120 } else {
121 is_attached_to_process_thread_ = false;
122 }
123}
124
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000125int64_t VideoReceiver::TimeUntilNextProcess() {
Tommifbf3bce2018-02-21 15:56:05 +0100126 RTC_DCHECK_RUN_ON(&module_thread_checker_);
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000127 int64_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
Niels Möller691f62c2019-04-11 15:27:17 +0200128 // We need a Process call more often if we are relying on
129 // retransmissions
130 timeUntilNextProcess =
131 VCM_MIN(timeUntilNextProcess, _retransmissionTimer.TimeUntilProcess());
132
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000133 timeUntilNextProcess =
134 VCM_MIN(timeUntilNextProcess, _keyRequestTimer.TimeUntilProcess());
135
136 return timeUntilNextProcess;
137}
138
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000139// Register a receive callback. Will be called whenever there is a new frame
140// ready for rendering.
141int32_t VideoReceiver::RegisterReceiveCallback(
142 VCMReceiveCallback* receiveCallback) {
Tommifbf3bce2018-02-21 15:56:05 +0100143 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
144 RTC_DCHECK(!IsDecoderThreadRunning());
145 // This value is set before the decoder thread starts and unset after
146 // the decoder thread has been stopped.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000147 _decodedFrameCallback.SetUserReceiveCallback(receiveCallback);
148 return VCM_OK;
149}
150
perkj796cfaf2015-12-10 09:27:38 -0800151// Register an externally defined decoder object.
Peter Boström795dbe42015-11-27 14:09:07 +0100152void VideoReceiver::RegisterExternalDecoder(VideoDecoder* externalDecoder,
perkj796cfaf2015-12-10 09:27:38 -0800153 uint8_t payloadType) {
Tommifbf3bce2018-02-21 15:56:05 +0100154 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
155 RTC_DCHECK(!IsDecoderThreadRunning());
sprang3911c262016-04-15 01:24:14 -0700156 if (externalDecoder == nullptr) {
Peter Boström795dbe42015-11-27 14:09:07 +0100157 RTC_CHECK(_codecDataBase.DeregisterExternalDecoder(payloadType));
Peter Boström395c7c62015-11-27 15:23:12 +0100158 return;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000159 }
perkj796cfaf2015-12-10 09:27:38 -0800160 _codecDataBase.RegisterExternalDecoder(externalDecoder, payloadType);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000161}
162
163// Register a frame type request callback.
164int32_t VideoReceiver::RegisterFrameTypeCallback(
165 VCMFrameTypeCallback* frameTypeCallback) {
Tommifbf3bce2018-02-21 15:56:05 +0100166 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
167 RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
168 // This callback is used on the module thread, but since we don't get
169 // callbacks on the module thread while the decoder thread isn't running
170 // (and this function must not be called when the decoder is running),
171 // we don't need a lock here.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000172 _frameTypeCallback = frameTypeCallback;
173 return VCM_OK;
174}
175
176int32_t VideoReceiver::RegisterPacketRequestCallback(
177 VCMPacketRequestCallback* callback) {
Tommifbf3bce2018-02-21 15:56:05 +0100178 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
179 RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
180 // This callback is used on the module thread, but since we don't get
181 // callbacks on the module thread while the decoder thread isn't running
182 // (and this function must not be called when the decoder is running),
183 // we don't need a lock here.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000184 _packetRequestCallback = callback;
185 return VCM_OK;
186}
187
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +0000188void VideoReceiver::TriggerDecoderShutdown() {
Tommifbf3bce2018-02-21 15:56:05 +0100189 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
190 RTC_DCHECK(IsDecoderThreadRunning());
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +0000191 _receiver.TriggerDecoderShutdown();
192}
193
Tommifbf3bce2018-02-21 15:56:05 +0100194void VideoReceiver::DecoderThreadStarting() {
195 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
196 RTC_DCHECK(!IsDecoderThreadRunning());
197 if (process_thread_ && !is_attached_to_process_thread_) {
198 process_thread_->RegisterModule(this, RTC_FROM_HERE);
199 }
200#if RTC_DCHECK_IS_ON
201 decoder_thread_is_running_ = true;
202#endif
203}
204
205void VideoReceiver::DecoderThreadStopped() {
206 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
207 RTC_DCHECK(IsDecoderThreadRunning());
208 if (process_thread_ && is_attached_to_process_thread_) {
209 process_thread_->DeRegisterModule(this);
210 }
211#if RTC_DCHECK_IS_ON
212 decoder_thread_is_running_ = false;
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200213 decoder_thread_checker_.Detach();
Tommifbf3bce2018-02-21 15:56:05 +0100214#endif
215}
216
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000217// Decode next frame, blocking.
218// Should be called as often as possible to get the most out of the decoder.
219int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
Tommifbf3bce2018-02-21 15:56:05 +0100220 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
221 VCMEncodedFrame* frame = _receiver.FrameForDecoding(
222 maxWaitTimeMs, _codecDataBase.PrefersLateDecoding());
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000223
Peter Boströmb7d9a972015-12-18 16:01:11 +0100224 if (!frame)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000225 return VCM_FRAME_NOT_READY;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000226
Tommifbf3bce2018-02-21 15:56:05 +0100227 bool drop_frame = false;
Peter Boströmed3277b2016-02-02 15:40:04 +0100228 {
sprang3911c262016-04-15 01:24:14 -0700229 rtc::CritScope cs(&process_crit_);
Peter Boströmed3277b2016-02-02 15:40:04 +0100230 if (drop_frames_until_keyframe_) {
231 // Still getting delta frames, schedule another keyframe request as if
232 // decode failed.
Niels Möller8f7ce222019-03-21 15:43:58 +0100233 if (frame->FrameType() != VideoFrameType::kVideoFrameKey) {
Tommifbf3bce2018-02-21 15:56:05 +0100234 drop_frame = true;
Peter Boströmed3277b2016-02-02 15:40:04 +0100235 _scheduleKeyRequest = true;
Tommifbf3bce2018-02-21 15:56:05 +0100236 // TODO(tommi): Consider if we could instead post a task to the module
237 // thread and call RequestKeyFrame directly. Here we call WakeUp so that
238 // TimeUntilNextProcess() gets called straight away.
239 process_thread_->WakeUp(this);
240 } else {
241 drop_frames_until_keyframe_ = false;
Peter Boströmed3277b2016-02-02 15:40:04 +0100242 }
Peter Boströmed3277b2016-02-02 15:40:04 +0100243 }
244 }
Peter Boströmb7d9a972015-12-18 16:01:11 +0100245
Tommifbf3bce2018-02-21 15:56:05 +0100246 if (drop_frame) {
247 _receiver.ReleaseFrame(frame);
248 return VCM_FRAME_NOT_READY;
249 }
250
sprang3911c262016-04-15 01:24:14 -0700251 // If this frame was too late, we should adjust the delay accordingly
philipel721d4022016-12-15 07:10:57 -0800252 _timing->UpdateCurrentDelay(frame->RenderTimeMs(),
253 clock_->TimeInMilliseconds());
skvlad98bb6642016-04-07 15:36:45 -0700254
255 if (first_frame_received_()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100256 RTC_LOG(LS_INFO) << "Received first "
257 << (frame->Complete() ? "complete" : "incomplete")
258 << " decodable video frame";
skvlad98bb6642016-04-07 15:36:45 -0700259 }
260
Peter Boströmb7d9a972015-12-18 16:01:11 +0100261 const int32_t ret = Decode(*frame);
262 _receiver.ReleaseFrame(frame);
263 return ret;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000264}
265
philipela45102f2017-02-22 05:30:39 -0800266// Used for the new jitter buffer.
philipelfd5a20f2016-11-15 00:57:57 -0800267// TODO(philipel): Clean up among the Decode functions as we replace
268// VCMEncodedFrame with FrameObject.
269int32_t VideoReceiver::Decode(const webrtc::VCMEncodedFrame* frame) {
Tommifbf3bce2018-02-21 15:56:05 +0100270 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
philipelfd5a20f2016-11-15 00:57:57 -0800271 return Decode(*frame);
272}
273
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000274int32_t VideoReceiver::RequestKeyFrame() {
Tommifbf3bce2018-02-21 15:56:05 +0100275 RTC_DCHECK_RUN_ON(&module_thread_checker_);
276
277 // Since we deregister from the module thread when the decoder thread isn't
278 // running, we should get no calls here if decoding isn't being done.
279 RTC_DCHECK(IsDecoderThreadRunning());
280
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000281 TRACE_EVENT0("webrtc", "RequestKeyFrame");
sprang3911c262016-04-15 01:24:14 -0700282 if (_frameTypeCallback != nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000283 const int32_t ret = _frameTypeCallback->RequestKeyFrame();
284 if (ret < 0) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000285 return ret;
286 }
Tommifbf3bce2018-02-21 15:56:05 +0100287 rtc::CritScope cs(&process_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000288 _scheduleKeyRequest = false;
289 } else {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000290 return VCM_MISSING_CALLBACK;
291 }
292 return VCM_OK;
293}
294
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000295// Must be called from inside the receive side critical section.
296int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) {
Tommifbf3bce2018-02-21 15:56:05 +0100297 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
tommidb23ea62017-03-03 07:21:18 -0800298 TRACE_EVENT0("webrtc", "VideoReceiver::Decode");
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000299 // Change decoder if payload type has changed
tommid0a71ba2017-03-14 04:16:20 -0700300 VCMGenericDecoder* decoder =
301 _codecDataBase.GetDecoder(frame, &_decodedFrameCallback);
302 if (decoder == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000303 return VCM_NO_CODEC_REGISTERED;
304 }
philipel3042c2d2017-08-18 04:55:02 -0700305 return decoder->Decode(frame, clock_->TimeInMilliseconds());
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000306}
307
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000308// Register possible receive codecs, can be called multiple times
309int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec,
310 int32_t numberOfCores,
311 bool requireKeyFrame) {
Tommifbf3bce2018-02-21 15:56:05 +0100312 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
313 RTC_DCHECK(!IsDecoderThreadRunning());
sprang3911c262016-04-15 01:24:14 -0700314 if (receiveCodec == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000315 return VCM_PARAMETER_ERROR;
316 }
philipel9d3ab612015-12-21 04:12:39 -0800317 if (!_codecDataBase.RegisterReceiveCodec(receiveCodec, numberOfCores,
318 requireKeyFrame)) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000319 return -1;
320 }
321 return 0;
322}
323
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000324// Incoming packet from network parsed and ready for decode, non blocking.
325int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000326 size_t payloadLength,
Niels Möllerbe7a0ec2019-04-25 10:02:52 +0200327 const RTPHeader& rtp_header,
328 const RTPVideoHeader& video_header) {
Tommifbf3bce2018-02-21 15:56:05 +0100329 RTC_DCHECK_RUN_ON(&module_thread_checker_);
Niels Möllerbe7a0ec2019-04-25 10:02:52 +0200330 if (video_header.frame_type == VideoFrameType::kVideoFrameKey) {
philipel9d3ab612015-12-21 04:12:39 -0800331 TRACE_EVENT1("webrtc", "VCM::PacketKeyFrame", "seqnum",
Niels Möllerbe7a0ec2019-04-25 10:02:52 +0200332 rtp_header.sequenceNumber);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000333 }
sprang3911c262016-04-15 01:24:14 -0700334 if (incomingPayload == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000335 // The jitter buffer doesn't handle non-zero payload lengths for packets
336 // without payload.
337 // TODO(holmer): We should fix this in the jitter buffer.
338 payloadLength = 0;
339 }
Niels Möllerbe7a0ec2019-04-25 10:02:52 +0200340 // Callers don't provide any ntp time.
341 const VCMPacket packet(incomingPayload, payloadLength, rtp_header,
Chen Xingf00bf422019-06-20 10:05:55 +0200342 video_header, /*ntp_time_ms=*/0,
343 clock_->TimeInMilliseconds());
Johan Ahlers95348f72016-06-28 11:11:28 +0200344 int32_t ret = _receiver.InsertPacket(packet);
sprang3911c262016-04-15 01:24:14 -0700345
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000346 // TODO(holmer): Investigate if this somehow should use the key frame
347 // request scheduling to throttle the requests.
348 if (ret == VCM_FLUSH_INDICATOR) {
Peter Boströmed3277b2016-02-02 15:40:04 +0100349 {
sprang3911c262016-04-15 01:24:14 -0700350 rtc::CritScope cs(&process_crit_);
Peter Boströmed3277b2016-02-02 15:40:04 +0100351 drop_frames_until_keyframe_ = true;
352 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000353 RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000354 } else if (ret < 0) {
355 return ret;
356 }
357 return VCM_OK;
358}
359
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000360void VideoReceiver::SetNackSettings(size_t max_nack_list_size,
361 int max_packet_age_to_nack,
362 int max_incomplete_time_ms) {
Tommifbf3bce2018-02-21 15:56:05 +0100363 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
364 RTC_DCHECK(!IsDecoderThreadRunning());
guidouc3372582017-04-04 07:16:21 -0700365 if (max_nack_list_size != 0) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000366 max_nack_list_size_ = max_nack_list_size;
guidouc3372582017-04-04 07:16:21 -0700367 }
philipel9d3ab612015-12-21 04:12:39 -0800368 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
369 max_incomplete_time_ms);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000370}
371
Tommifbf3bce2018-02-21 15:56:05 +0100372bool VideoReceiver::IsDecoderThreadRunning() {
373#if RTC_DCHECK_IS_ON
374 return decoder_thread_is_running_;
375#else
376 return true;
377#endif
378}
379
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000380} // namespace vcm
381} // namespace webrtc