blob: e766767cd078941514807612f2851de093c90c3b [file] [log] [blame]
mflodmancfc8e3b2016-05-03 21:22:04 -07001/*
2 * 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 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "video/video_stream_decoder.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070012
13#include <algorithm>
14#include <map>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "common_video/include/frame_callback.h"
18#include "modules/video_coding/video_coding_impl.h"
19#include "rtc_base/checks.h"
20#include "rtc_base/logging.h"
21#include "system_wrappers/include/metrics.h"
22#include "video/call_stats.h"
23#include "video/payload_router.h"
24#include "video/receive_statistics_proxy.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070025
26namespace webrtc {
27
28VideoStreamDecoder::VideoStreamDecoder(
29 vcm::VideoReceiver* video_receiver,
30 VCMFrameTypeCallback* vcm_frame_type_callback,
31 VCMPacketRequestCallback* vcm_packet_request_callback,
32 bool enable_nack,
tommi2e82f382016-06-21 00:26:43 -070033 bool enable_fec,
mflodmancfc8e3b2016-05-03 21:22:04 -070034 ReceiveStatisticsProxy* receive_statistics_proxy,
nisse76bc8e82017-02-07 09:37:41 -080035 rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
mflodmancfc8e3b2016-05-03 21:22:04 -070036 : video_receiver_(video_receiver),
37 receive_stats_callback_(receive_statistics_proxy),
Tommi6b28e202018-03-25 19:52:46 +020038 incoming_video_stream_(incoming_video_stream) {
mflodmancfc8e3b2016-05-03 21:22:04 -070039 RTC_DCHECK(video_receiver_);
40
41 static const int kMaxPacketAgeToNack = 450;
42 static const int kMaxNackListSize = 250;
43 video_receiver_->SetNackSettings(kMaxNackListSize,
44 kMaxPacketAgeToNack, 0);
45 video_receiver_->RegisterReceiveCallback(this);
46 video_receiver_->RegisterFrameTypeCallback(vcm_frame_type_callback);
47 video_receiver_->RegisterReceiveStatisticsCallback(this);
mflodmancfc8e3b2016-05-03 21:22:04 -070048
tommi2e82f382016-06-21 00:26:43 -070049 VCMVideoProtection video_protection =
50 enable_nack ? (enable_fec ? kProtectionNackFEC : kProtectionNack)
51 : kProtectionNone;
philipelae284082016-05-09 12:14:29 +020052
mflodmancfc8e3b2016-05-03 21:22:04 -070053 VCMDecodeErrorMode decode_error_mode = enable_nack ? kNoErrors : kWithErrors;
54 video_receiver_->SetVideoProtection(video_protection, true);
55 video_receiver_->SetDecodeErrorMode(decode_error_mode);
56 VCMPacketRequestCallback* packet_request_callback =
57 enable_nack ? vcm_packet_request_callback : nullptr;
58 video_receiver_->RegisterPacketRequestCallback(packet_request_callback);
59}
60
tommi2e82f382016-06-21 00:26:43 -070061VideoStreamDecoder::~VideoStreamDecoder() {
tommid0a71ba2017-03-14 04:16:20 -070062 // Note: There's an assumption at this point that the decoder thread is
63 // *not* running. If it was, then there could be a race for each of these
64 // callbacks.
65
tommi2e82f382016-06-21 00:26:43 -070066 // Unset all the callback pointers that we set in the ctor.
67 video_receiver_->RegisterPacketRequestCallback(nullptr);
tommi2e82f382016-06-21 00:26:43 -070068 video_receiver_->RegisterReceiveStatisticsCallback(nullptr);
69 video_receiver_->RegisterFrameTypeCallback(nullptr);
70 video_receiver_->RegisterReceiveCallback(nullptr);
71}
mflodmancfc8e3b2016-05-03 21:22:04 -070072
73// Do not acquire the lock of |video_receiver_| in this function. Decode
74// callback won't necessarily be called from the decoding thread. The decoding
75// thread may have held the lock when calling VideoDecoder::Decode, Reset, or
76// Release. Acquiring the same lock in the path of decode callback can deadlock.
sakalcc452e12017-02-09 04:53:45 -080077int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
ilnik00d802b2017-04-11 10:34:31 -070078 rtc::Optional<uint8_t> qp,
79 VideoContentType content_type) {
80 receive_stats_callback_->OnDecodedFrame(qp, content_type);
sakal55d932b2016-09-30 06:19:08 -070081 incoming_video_stream_->OnFrame(video_frame);
mflodmancfc8e3b2016-05-03 21:22:04 -070082 return 0;
83}
84
85int32_t VideoStreamDecoder::ReceivedDecodedReferenceFrame(
86 const uint64_t picture_id) {
87 RTC_NOTREACHED();
88 return 0;
89}
90
91void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
92 receive_stats_callback_->OnIncomingPayloadType(payload_type);
93}
94
95void VideoStreamDecoder::OnDecoderImplementationName(
96 const char* implementation_name) {
97 receive_stats_callback_->OnDecoderImplementationName(implementation_name);
98}
99
100void VideoStreamDecoder::OnReceiveRatesUpdated(uint32_t bit_rate,
101 uint32_t frame_rate) {
102 receive_stats_callback_->OnIncomingRate(frame_rate, bit_rate);
103}
104
105void VideoStreamDecoder::OnDiscardedPacketsUpdated(int discarded_packets) {
106 receive_stats_callback_->OnDiscardedPacketsUpdated(discarded_packets);
107}
108
109void VideoStreamDecoder::OnFrameCountsUpdated(const FrameCounts& frame_counts) {
110 receive_stats_callback_->OnFrameCountsUpdated(frame_counts);
111}
112
philipela45102f2017-02-22 05:30:39 -0800113void VideoStreamDecoder::OnFrameBufferTimingsUpdated(int decode_ms,
114 int max_decode_ms,
115 int current_delay_ms,
116 int target_delay_ms,
117 int jitter_buffer_ms,
118 int min_playout_delay_ms,
119 int render_delay_ms) {}
120
ilnik2edc6842017-07-06 03:06:50 -0700121void VideoStreamDecoder::OnTimingFrameInfoUpdated(const TimingFrameInfo& info) {
122}
123
ilnik6d5b4d62017-08-30 03:32:14 -0700124void VideoStreamDecoder::OnCompleteFrame(bool is_keyframe,
125 size_t size_bytes,
126 VideoContentType content_type) {}
mflodmancfc8e3b2016-05-03 21:22:04 -0700127
Tommi81de14f2018-03-25 22:19:25 +0200128void VideoStreamDecoder::UpdateRtt(int64_t max_rtt_ms) {
mflodmancfc8e3b2016-05-03 21:22:04 -0700129 video_receiver_->SetReceiveChannelParameters(max_rtt_ms);
mflodmancfc8e3b2016-05-03 21:22:04 -0700130}
131} // namespace webrtc