1 /*
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
11 #include "video/video_stream_decoder2.h"
12
13 #include "api/video_codecs/video_decoder.h"
14 #include "modules/video_coding/video_receiver2.h"
15 #include "rtc_base/checks.h"
16 #include "video/receive_statistics_proxy2.h"
17
18 namespace webrtc {
19 namespace internal {
20
VideoStreamDecoder(VideoReceiver2 * video_receiver,ReceiveStatisticsProxy * receive_statistics_proxy,rtc::VideoSinkInterface<VideoFrame> * incoming_video_stream)21 VideoStreamDecoder::VideoStreamDecoder(
22 VideoReceiver2* video_receiver,
23 ReceiveStatisticsProxy* receive_statistics_proxy,
24 rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
25 : video_receiver_(video_receiver),
26 receive_stats_callback_(receive_statistics_proxy),
27 incoming_video_stream_(incoming_video_stream) {
28 RTC_DCHECK(video_receiver_);
29
30 video_receiver_->RegisterReceiveCallback(this);
31 }
32
~VideoStreamDecoder()33 VideoStreamDecoder::~VideoStreamDecoder() {
34 // Note: There's an assumption at this point that the decoder thread is
35 // *not* running. If it was, then there could be a race for each of these
36 // callbacks.
37
38 // Unset all the callback pointers that we set in the ctor.
39 video_receiver_->RegisterReceiveCallback(nullptr);
40 }
41
42 // Do not acquire the lock of `video_receiver_` in this function. Decode
43 // callback won't necessarily be called from the decoding thread. The decoding
44 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or
45 // 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 int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
47 absl::optional<uint8_t> qp,
48 TimeDelta decode_time,
49 VideoContentType content_type) {
50 receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time,
51 content_type);
52 incoming_video_stream_->OnFrame(video_frame);
53 return 0;
54 }
55
OnDroppedFrames(uint32_t frames_dropped)56 void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
57 receive_stats_callback_->OnDroppedFrames(frames_dropped);
58 }
59
OnIncomingPayloadType(int payload_type)60 void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
61 receive_stats_callback_->OnIncomingPayloadType(payload_type);
62 }
63
OnDecoderInfoChanged(const VideoDecoder::DecoderInfo & decoder_info)64 void VideoStreamDecoder::OnDecoderInfoChanged(
65 const VideoDecoder::DecoderInfo& decoder_info) {
66 receive_stats_callback_->OnDecoderInfo(decoder_info);
67 }
68
69 } // namespace internal
70 } // namespace webrtc
71