blob: 72a004b443c388d23faa09af60aacaf063f9148b [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>
12#include <cstdint>
13#include <vector>
14
15#include "api/rtp_headers.h"
16#include "api/video_codecs/video_codec.h"
17#include "api/video_codecs/video_decoder.h"
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "modules/include/module_common_types.h"
Tommifbf3bce2018-02-21 15:56:05 +010019#include "modules/utility/include/process_thread.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "modules/video_coding/decoder_database.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/video_coding/encoded_frame.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "modules/video_coding/generic_decoder.h"
23#include "modules/video_coding/include/video_coding.h"
24#include "modules/video_coding/include/video_coding_defines.h"
25#include "modules/video_coding/internal_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "modules/video_coding/jitter_buffer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "modules/video_coding/media_opt_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "modules/video_coding/packet.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "modules/video_coding/receiver.h"
30#include "modules/video_coding/timing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "modules/video_coding/video_coding_impl.h"
32#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "rtc_base/critical_section.h"
Tommifbf3bce2018-02-21 15:56:05 +010034#include "rtc_base/location.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "rtc_base/one_time_event.h"
Yves Gerey3e707812018-11-28 16:47:49 +010037#include "rtc_base/thread_checker.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "rtc_base/trace_event.h"
39#include "system_wrappers/include/clock.h"
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000040
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000041namespace webrtc {
42namespace vcm {
43
Niels Möllerdb64d992019-03-29 14:30:53 +010044VideoReceiver::VideoReceiver(Clock* clock, VCMTiming* timing)
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000045 : clock_(clock),
philipel721d4022016-12-15 07:10:57 -080046 _timing(timing),
Niels Möllerdb64d992019-03-29 14:30:53 +010047 _receiver(_timing, clock_),
philipel721d4022016-12-15 07:10:57 -080048 _decodedFrameCallback(_timing, clock_),
sprang3911c262016-04-15 01:24:14 -070049 _frameTypeCallback(nullptr),
sprang3911c262016-04-15 01:24:14 -070050 _packetRequestCallback(nullptr),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000051 _scheduleKeyRequest(false),
Peter Boströmed3277b2016-02-02 15:40:04 +010052 drop_frames_until_keyframe_(false),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000053 max_nack_list_size_(0),
Niels Möllerf9063782018-02-20 16:09:48 +010054 _codecDataBase(),
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000055 _receiveStatsTimer(1000, clock_),
56 _retransmissionTimer(10, clock_),
Tommifbf3bce2018-02-21 15:56:05 +010057 _keyRequestTimer(500, clock_) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020058 decoder_thread_checker_.Detach();
59 module_thread_checker_.Detach();
Tommifbf3bce2018-02-21 15:56:05 +010060}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000061
Tommifbf3bce2018-02-21 15:56:05 +010062VideoReceiver::~VideoReceiver() {
63 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
64}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000065
pbosa26ac922016-02-25 04:50:01 -080066void VideoReceiver::Process() {
Tommifbf3bce2018-02-21 15:56:05 +010067 RTC_DCHECK_RUN_ON(&module_thread_checker_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000068 // Receive-side statistics
philipela45102f2017-02-22 05:30:39 -080069
70 // TODO(philipel): Remove this if block when we know what to do with
71 // ReceiveStatisticsProxy::QualitySample.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000072 if (_receiveStatsTimer.TimeUntilProcess() == 0) {
73 _receiveStatsTimer.Processed();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000074 }
75
76 // Key frame requests
77 if (_keyRequestTimer.TimeUntilProcess() == 0) {
78 _keyRequestTimer.Processed();
Tommifbf3bce2018-02-21 15:56:05 +010079 bool request_key_frame = _frameTypeCallback != nullptr;
80 if (request_key_frame) {
sprang3911c262016-04-15 01:24:14 -070081 rtc::CritScope cs(&process_crit_);
Tommifbf3bce2018-02-21 15:56:05 +010082 request_key_frame = _scheduleKeyRequest;
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +000083 }
pbosa26ac922016-02-25 04:50:01 -080084 if (request_key_frame)
85 RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000086 }
87
88 // Packet retransmission requests
89 // TODO(holmer): Add API for changing Process interval and make sure it's
90 // disabled when NACK is off.
91 if (_retransmissionTimer.TimeUntilProcess() == 0) {
92 _retransmissionTimer.Processed();
Tommifbf3bce2018-02-21 15:56:05 +010093 bool callback_registered = _packetRequestCallback != nullptr;
94 uint16_t length = max_nack_list_size_;
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +000095 if (callback_registered && length > 0) {
Wan-Teh Changb1825a42015-06-03 15:03:35 -070096 // Collect sequence numbers from the default receiver.
97 bool request_key_frame = false;
98 std::vector<uint16_t> nackList = _receiver.NackList(&request_key_frame);
99 int32_t ret = VCM_OK;
100 if (request_key_frame) {
101 ret = RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000102 }
Wan-Teh Changb1825a42015-06-03 15:03:35 -0700103 if (ret == VCM_OK && !nackList.empty()) {
guidouc3372582017-04-04 07:16:21 -0700104 rtc::CritScope cs(&process_crit_);
sprang3911c262016-04-15 01:24:14 -0700105 if (_packetRequestCallback != nullptr) {
Wan-Teh Changb1825a42015-06-03 15:03:35 -0700106 _packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
stefan@webrtc.orgf7c6e742014-01-29 10:27:51 +0000107 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000108 }
109 }
110 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000111}
112
Tommifbf3bce2018-02-21 15:56:05 +0100113void VideoReceiver::ProcessThreadAttached(ProcessThread* process_thread) {
114 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
115 if (process_thread) {
116 is_attached_to_process_thread_ = true;
117 RTC_DCHECK(!process_thread_ || process_thread_ == process_thread);
118 process_thread_ = process_thread;
119 } else {
120 is_attached_to_process_thread_ = false;
121 }
122}
123
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000124int64_t VideoReceiver::TimeUntilNextProcess() {
Tommifbf3bce2018-02-21 15:56:05 +0100125 RTC_DCHECK_RUN_ON(&module_thread_checker_);
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000126 int64_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
Niels Möller691f62c2019-04-11 15:27:17 +0200127 // We need a Process call more often if we are relying on
128 // retransmissions
129 timeUntilNextProcess =
130 VCM_MIN(timeUntilNextProcess, _retransmissionTimer.TimeUntilProcess());
131
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000132 timeUntilNextProcess =
133 VCM_MIN(timeUntilNextProcess, _keyRequestTimer.TimeUntilProcess());
134
135 return timeUntilNextProcess;
136}
137
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000138int32_t VideoReceiver::SetReceiveChannelParameters(int64_t rtt) {
Tommifbf3bce2018-02-21 15:56:05 +0100139 RTC_DCHECK_RUN_ON(&module_thread_checker_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000140 _receiver.UpdateRtt(rtt);
141 return 0;
142}
143
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000144// Register a receive callback. Will be called whenever there is a new frame
145// ready for rendering.
146int32_t VideoReceiver::RegisterReceiveCallback(
147 VCMReceiveCallback* receiveCallback) {
Tommifbf3bce2018-02-21 15:56:05 +0100148 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
149 RTC_DCHECK(!IsDecoderThreadRunning());
150 // This value is set before the decoder thread starts and unset after
151 // the decoder thread has been stopped.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000152 _decodedFrameCallback.SetUserReceiveCallback(receiveCallback);
153 return VCM_OK;
154}
155
perkj796cfaf2015-12-10 09:27:38 -0800156// Register an externally defined decoder object.
Peter Boström795dbe42015-11-27 14:09:07 +0100157void VideoReceiver::RegisterExternalDecoder(VideoDecoder* externalDecoder,
perkj796cfaf2015-12-10 09:27:38 -0800158 uint8_t payloadType) {
Tommifbf3bce2018-02-21 15:56:05 +0100159 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
160 RTC_DCHECK(!IsDecoderThreadRunning());
sprang3911c262016-04-15 01:24:14 -0700161 if (externalDecoder == nullptr) {
Peter Boström795dbe42015-11-27 14:09:07 +0100162 RTC_CHECK(_codecDataBase.DeregisterExternalDecoder(payloadType));
Peter Boström395c7c62015-11-27 15:23:12 +0100163 return;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000164 }
perkj796cfaf2015-12-10 09:27:38 -0800165 _codecDataBase.RegisterExternalDecoder(externalDecoder, payloadType);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000166}
167
168// Register a frame type request callback.
169int32_t VideoReceiver::RegisterFrameTypeCallback(
170 VCMFrameTypeCallback* frameTypeCallback) {
Tommifbf3bce2018-02-21 15:56:05 +0100171 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
172 RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
173 // This callback is used on the module thread, but since we don't get
174 // callbacks on the module thread while the decoder thread isn't running
175 // (and this function must not be called when the decoder is running),
176 // we don't need a lock here.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000177 _frameTypeCallback = frameTypeCallback;
178 return VCM_OK;
179}
180
181int32_t VideoReceiver::RegisterPacketRequestCallback(
182 VCMPacketRequestCallback* callback) {
Tommifbf3bce2018-02-21 15:56:05 +0100183 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
184 RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
185 // This callback is used on the module thread, but since we don't get
186 // callbacks on the module thread while the decoder thread isn't running
187 // (and this function must not be called when the decoder is running),
188 // we don't need a lock here.
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000189 _packetRequestCallback = callback;
190 return VCM_OK;
191}
192
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +0000193void VideoReceiver::TriggerDecoderShutdown() {
Tommifbf3bce2018-02-21 15:56:05 +0100194 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
195 RTC_DCHECK(IsDecoderThreadRunning());
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +0000196 _receiver.TriggerDecoderShutdown();
197}
198
Tommifbf3bce2018-02-21 15:56:05 +0100199void VideoReceiver::DecoderThreadStarting() {
200 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
201 RTC_DCHECK(!IsDecoderThreadRunning());
202 if (process_thread_ && !is_attached_to_process_thread_) {
203 process_thread_->RegisterModule(this, RTC_FROM_HERE);
204 }
205#if RTC_DCHECK_IS_ON
206 decoder_thread_is_running_ = true;
207#endif
208}
209
210void VideoReceiver::DecoderThreadStopped() {
211 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
212 RTC_DCHECK(IsDecoderThreadRunning());
213 if (process_thread_ && is_attached_to_process_thread_) {
214 process_thread_->DeRegisterModule(this);
215 }
216#if RTC_DCHECK_IS_ON
217 decoder_thread_is_running_ = false;
Sebastian Janssonc01367d2019-04-08 15:20:44 +0200218 decoder_thread_checker_.Detach();
Tommifbf3bce2018-02-21 15:56:05 +0100219#endif
220}
221
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000222// Decode next frame, blocking.
223// Should be called as often as possible to get the most out of the decoder.
224int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
Tommifbf3bce2018-02-21 15:56:05 +0100225 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
226 VCMEncodedFrame* frame = _receiver.FrameForDecoding(
227 maxWaitTimeMs, _codecDataBase.PrefersLateDecoding());
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000228
Peter Boströmb7d9a972015-12-18 16:01:11 +0100229 if (!frame)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000230 return VCM_FRAME_NOT_READY;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000231
Tommifbf3bce2018-02-21 15:56:05 +0100232 bool drop_frame = false;
Peter Boströmed3277b2016-02-02 15:40:04 +0100233 {
sprang3911c262016-04-15 01:24:14 -0700234 rtc::CritScope cs(&process_crit_);
Peter Boströmed3277b2016-02-02 15:40:04 +0100235 if (drop_frames_until_keyframe_) {
236 // Still getting delta frames, schedule another keyframe request as if
237 // decode failed.
Niels Möller8f7ce222019-03-21 15:43:58 +0100238 if (frame->FrameType() != VideoFrameType::kVideoFrameKey) {
Tommifbf3bce2018-02-21 15:56:05 +0100239 drop_frame = true;
Peter Boströmed3277b2016-02-02 15:40:04 +0100240 _scheduleKeyRequest = true;
Tommifbf3bce2018-02-21 15:56:05 +0100241 // TODO(tommi): Consider if we could instead post a task to the module
242 // thread and call RequestKeyFrame directly. Here we call WakeUp so that
243 // TimeUntilNextProcess() gets called straight away.
244 process_thread_->WakeUp(this);
245 } else {
246 drop_frames_until_keyframe_ = false;
Peter Boströmed3277b2016-02-02 15:40:04 +0100247 }
Peter Boströmed3277b2016-02-02 15:40:04 +0100248 }
249 }
Peter Boströmb7d9a972015-12-18 16:01:11 +0100250
Tommifbf3bce2018-02-21 15:56:05 +0100251 if (drop_frame) {
252 _receiver.ReleaseFrame(frame);
253 return VCM_FRAME_NOT_READY;
254 }
255
sprang3911c262016-04-15 01:24:14 -0700256 // If this frame was too late, we should adjust the delay accordingly
philipel721d4022016-12-15 07:10:57 -0800257 _timing->UpdateCurrentDelay(frame->RenderTimeMs(),
258 clock_->TimeInMilliseconds());
skvlad98bb6642016-04-07 15:36:45 -0700259
260 if (first_frame_received_()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100261 RTC_LOG(LS_INFO) << "Received first "
262 << (frame->Complete() ? "complete" : "incomplete")
263 << " decodable video frame";
skvlad98bb6642016-04-07 15:36:45 -0700264 }
265
Peter Boströmb7d9a972015-12-18 16:01:11 +0100266 const int32_t ret = Decode(*frame);
267 _receiver.ReleaseFrame(frame);
268 return ret;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000269}
270
philipela45102f2017-02-22 05:30:39 -0800271// Used for the new jitter buffer.
philipelfd5a20f2016-11-15 00:57:57 -0800272// TODO(philipel): Clean up among the Decode functions as we replace
273// VCMEncodedFrame with FrameObject.
274int32_t VideoReceiver::Decode(const webrtc::VCMEncodedFrame* frame) {
Tommifbf3bce2018-02-21 15:56:05 +0100275 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
philipelfd5a20f2016-11-15 00:57:57 -0800276 return Decode(*frame);
277}
278
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000279int32_t VideoReceiver::RequestKeyFrame() {
Tommifbf3bce2018-02-21 15:56:05 +0100280 RTC_DCHECK_RUN_ON(&module_thread_checker_);
281
282 // Since we deregister from the module thread when the decoder thread isn't
283 // running, we should get no calls here if decoding isn't being done.
284 RTC_DCHECK(IsDecoderThreadRunning());
285
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000286 TRACE_EVENT0("webrtc", "RequestKeyFrame");
sprang3911c262016-04-15 01:24:14 -0700287 if (_frameTypeCallback != nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000288 const int32_t ret = _frameTypeCallback->RequestKeyFrame();
289 if (ret < 0) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000290 return ret;
291 }
Tommifbf3bce2018-02-21 15:56:05 +0100292 rtc::CritScope cs(&process_crit_);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000293 _scheduleKeyRequest = false;
294 } else {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000295 return VCM_MISSING_CALLBACK;
296 }
297 return VCM_OK;
298}
299
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000300// Must be called from inside the receive side critical section.
301int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) {
Tommifbf3bce2018-02-21 15:56:05 +0100302 RTC_DCHECK_RUN_ON(&decoder_thread_checker_);
tommidb23ea62017-03-03 07:21:18 -0800303 TRACE_EVENT0("webrtc", "VideoReceiver::Decode");
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000304 // Change decoder if payload type has changed
tommid0a71ba2017-03-14 04:16:20 -0700305 VCMGenericDecoder* decoder =
306 _codecDataBase.GetDecoder(frame, &_decodedFrameCallback);
307 if (decoder == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000308 return VCM_NO_CODEC_REGISTERED;
309 }
philipel3042c2d2017-08-18 04:55:02 -0700310 return decoder->Decode(frame, clock_->TimeInMilliseconds());
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000311}
312
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000313// Register possible receive codecs, can be called multiple times
314int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec,
315 int32_t numberOfCores,
316 bool requireKeyFrame) {
Tommifbf3bce2018-02-21 15:56:05 +0100317 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
318 RTC_DCHECK(!IsDecoderThreadRunning());
sprang3911c262016-04-15 01:24:14 -0700319 if (receiveCodec == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000320 return VCM_PARAMETER_ERROR;
321 }
philipel9d3ab612015-12-21 04:12:39 -0800322 if (!_codecDataBase.RegisterReceiveCodec(receiveCodec, numberOfCores,
323 requireKeyFrame)) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000324 return -1;
325 }
326 return 0;
327}
328
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000329// Incoming packet from network parsed and ready for decode, non blocking.
330int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000331 size_t payloadLength,
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000332 const WebRtcRTPHeader& rtpInfo) {
Tommifbf3bce2018-02-21 15:56:05 +0100333 RTC_DCHECK_RUN_ON(&module_thread_checker_);
Niels Möller8f7ce222019-03-21 15:43:58 +0100334 if (rtpInfo.frameType == VideoFrameType::kVideoFrameKey) {
philipel9d3ab612015-12-21 04:12:39 -0800335 TRACE_EVENT1("webrtc", "VCM::PacketKeyFrame", "seqnum",
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000336 rtpInfo.header.sequenceNumber);
337 }
sprang3911c262016-04-15 01:24:14 -0700338 if (incomingPayload == nullptr) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000339 // The jitter buffer doesn't handle non-zero payload lengths for packets
340 // without payload.
341 // TODO(holmer): We should fix this in the jitter buffer.
342 payloadLength = 0;
343 }
Niels Möller075e7fd2019-03-12 12:29:22 +0100344 const VCMPacket packet(incomingPayload, payloadLength, rtpInfo.header,
345 rtpInfo.video_header(), rtpInfo.frameType,
346 rtpInfo.ntp_time_ms);
Johan Ahlers95348f72016-06-28 11:11:28 +0200347 int32_t ret = _receiver.InsertPacket(packet);
sprang3911c262016-04-15 01:24:14 -0700348
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000349 // TODO(holmer): Investigate if this somehow should use the key frame
350 // request scheduling to throttle the requests.
351 if (ret == VCM_FLUSH_INDICATOR) {
Peter Boströmed3277b2016-02-02 15:40:04 +0100352 {
sprang3911c262016-04-15 01:24:14 -0700353 rtc::CritScope cs(&process_crit_);
Peter Boströmed3277b2016-02-02 15:40:04 +0100354 drop_frames_until_keyframe_ = true;
355 }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000356 RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000357 } else if (ret < 0) {
358 return ret;
359 }
360 return VCM_OK;
361}
362
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000363// The estimated delay caused by rendering, defaults to
364// kDefaultRenderDelayMs = 10 ms
365int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) {
Tommifbf3bce2018-02-21 15:56:05 +0100366 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
367 RTC_DCHECK(!IsDecoderThreadRunning());
philipel721d4022016-12-15 07:10:57 -0800368 _timing->set_render_delay(timeMS);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000369 return VCM_OK;
370}
371
372// Current video delay
philipel9d3ab612015-12-21 04:12:39 -0800373int32_t VideoReceiver::Delay() const {
Tommifbf3bce2018-02-21 15:56:05 +0100374 RTC_DCHECK_RUN_ON(&module_thread_checker_);
philipel721d4022016-12-15 07:10:57 -0800375 return _timing->TargetVideoDelay();
philipel9d3ab612015-12-21 04:12:39 -0800376}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000377
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000378void VideoReceiver::SetNackSettings(size_t max_nack_list_size,
379 int max_packet_age_to_nack,
380 int max_incomplete_time_ms) {
Tommifbf3bce2018-02-21 15:56:05 +0100381 RTC_DCHECK_RUN_ON(&construction_thread_checker_);
382 RTC_DCHECK(!IsDecoderThreadRunning());
guidouc3372582017-04-04 07:16:21 -0700383 if (max_nack_list_size != 0) {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000384 max_nack_list_size_ = max_nack_list_size;
guidouc3372582017-04-04 07:16:21 -0700385 }
philipel9d3ab612015-12-21 04:12:39 -0800386 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
387 max_incomplete_time_ms);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000388}
389
Tommifbf3bce2018-02-21 15:56:05 +0100390bool VideoReceiver::IsDecoderThreadRunning() {
391#if RTC_DCHECK_IS_ON
392 return decoder_thread_is_running_;
393#else
394 return true;
395#endif
396}
397
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000398} // namespace vcm
399} // namespace webrtc