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