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