1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker *
4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker */
10*d9f75844SAndroid Build Coastguard Worker
11*d9f75844SAndroid Build Coastguard Worker #include "video/video_stream_decoder2.h"
12*d9f75844SAndroid Build Coastguard Worker
13*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_decoder.h"
14*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/video_receiver2.h"
15*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h"
16*d9f75844SAndroid Build Coastguard Worker #include "video/receive_statistics_proxy2.h"
17*d9f75844SAndroid Build Coastguard Worker
18*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
19*d9f75844SAndroid Build Coastguard Worker namespace internal {
20*d9f75844SAndroid Build Coastguard Worker
VideoStreamDecoder(VideoReceiver2 * video_receiver,ReceiveStatisticsProxy * receive_statistics_proxy,rtc::VideoSinkInterface<VideoFrame> * incoming_video_stream)21*d9f75844SAndroid Build Coastguard Worker VideoStreamDecoder::VideoStreamDecoder(
22*d9f75844SAndroid Build Coastguard Worker VideoReceiver2* video_receiver,
23*d9f75844SAndroid Build Coastguard Worker ReceiveStatisticsProxy* receive_statistics_proxy,
24*d9f75844SAndroid Build Coastguard Worker rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
25*d9f75844SAndroid Build Coastguard Worker : video_receiver_(video_receiver),
26*d9f75844SAndroid Build Coastguard Worker receive_stats_callback_(receive_statistics_proxy),
27*d9f75844SAndroid Build Coastguard Worker incoming_video_stream_(incoming_video_stream) {
28*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK(video_receiver_);
29*d9f75844SAndroid Build Coastguard Worker
30*d9f75844SAndroid Build Coastguard Worker video_receiver_->RegisterReceiveCallback(this);
31*d9f75844SAndroid Build Coastguard Worker }
32*d9f75844SAndroid Build Coastguard Worker
~VideoStreamDecoder()33*d9f75844SAndroid Build Coastguard Worker VideoStreamDecoder::~VideoStreamDecoder() {
34*d9f75844SAndroid Build Coastguard Worker // Note: There's an assumption at this point that the decoder thread is
35*d9f75844SAndroid Build Coastguard Worker // *not* running. If it was, then there could be a race for each of these
36*d9f75844SAndroid Build Coastguard Worker // callbacks.
37*d9f75844SAndroid Build Coastguard Worker
38*d9f75844SAndroid Build Coastguard Worker // Unset all the callback pointers that we set in the ctor.
39*d9f75844SAndroid Build Coastguard Worker video_receiver_->RegisterReceiveCallback(nullptr);
40*d9f75844SAndroid Build Coastguard Worker }
41*d9f75844SAndroid Build Coastguard Worker
42*d9f75844SAndroid Build Coastguard Worker // Do not acquire the lock of `video_receiver_` in this function. Decode
43*d9f75844SAndroid Build Coastguard Worker // callback won't necessarily be called from the decoding thread. The decoding
44*d9f75844SAndroid Build Coastguard Worker // thread may have held the lock when calling VideoDecoder::Decode, Reset, or
45*d9f75844SAndroid Build Coastguard Worker // Release. Acquiring the same lock in the path of decode callback can deadlock.
FrameToRender(VideoFrame & video_frame,absl::optional<uint8_t> qp,TimeDelta decode_time,VideoContentType content_type)46*d9f75844SAndroid Build Coastguard Worker int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
47*d9f75844SAndroid Build Coastguard Worker absl::optional<uint8_t> qp,
48*d9f75844SAndroid Build Coastguard Worker TimeDelta decode_time,
49*d9f75844SAndroid Build Coastguard Worker VideoContentType content_type) {
50*d9f75844SAndroid Build Coastguard Worker receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time,
51*d9f75844SAndroid Build Coastguard Worker content_type);
52*d9f75844SAndroid Build Coastguard Worker incoming_video_stream_->OnFrame(video_frame);
53*d9f75844SAndroid Build Coastguard Worker return 0;
54*d9f75844SAndroid Build Coastguard Worker }
55*d9f75844SAndroid Build Coastguard Worker
OnDroppedFrames(uint32_t frames_dropped)56*d9f75844SAndroid Build Coastguard Worker void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
57*d9f75844SAndroid Build Coastguard Worker receive_stats_callback_->OnDroppedFrames(frames_dropped);
58*d9f75844SAndroid Build Coastguard Worker }
59*d9f75844SAndroid Build Coastguard Worker
OnIncomingPayloadType(int payload_type)60*d9f75844SAndroid Build Coastguard Worker void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
61*d9f75844SAndroid Build Coastguard Worker receive_stats_callback_->OnIncomingPayloadType(payload_type);
62*d9f75844SAndroid Build Coastguard Worker }
63*d9f75844SAndroid Build Coastguard Worker
OnDecoderInfoChanged(const VideoDecoder::DecoderInfo & decoder_info)64*d9f75844SAndroid Build Coastguard Worker void VideoStreamDecoder::OnDecoderInfoChanged(
65*d9f75844SAndroid Build Coastguard Worker const VideoDecoder::DecoderInfo& decoder_info) {
66*d9f75844SAndroid Build Coastguard Worker receive_stats_callback_->OnDecoderInfo(decoder_info);
67*d9f75844SAndroid Build Coastguard Worker }
68*d9f75844SAndroid Build Coastguard Worker
69*d9f75844SAndroid Build Coastguard Worker } // namespace internal
70*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc
71