mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/video_stream_decoder.h" |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 12 | |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 13 | #include "modules/video_coding/video_receiver2.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "video/receive_statistics_proxy.h" |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | VideoStreamDecoder::VideoStreamDecoder( |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 20 | VideoReceiver2* video_receiver, |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 21 | ReceiveStatisticsProxy* receive_statistics_proxy, |
nisse | 76bc8e8 | 2017-02-07 09:37:41 -0800 | [diff] [blame] | 22 | rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream) |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 23 | : video_receiver_(video_receiver), |
| 24 | receive_stats_callback_(receive_statistics_proxy), |
Tommi | 6b28e20 | 2018-03-25 19:52:46 +0200 | [diff] [blame] | 25 | incoming_video_stream_(incoming_video_stream) { |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 26 | RTC_DCHECK(video_receiver_); |
| 27 | |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 28 | video_receiver_->RegisterReceiveCallback(this); |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 29 | } |
| 30 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 31 | VideoStreamDecoder::~VideoStreamDecoder() { |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 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 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 36 | // Unset all the callback pointers that we set in the ctor. |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 37 | video_receiver_->RegisterReceiveCallback(nullptr); |
| 38 | } |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 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. |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 44 | int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame, |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 45 | absl::optional<uint8_t> qp, |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 46 | int32_t decode_time_ms, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 47 | VideoContentType content_type) { |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 48 | receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time_ms, |
| 49 | content_type); |
sakal | 55d932b | 2016-09-30 06:19:08 -0700 | [diff] [blame] | 50 | incoming_video_stream_->OnFrame(video_frame); |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
Johannes Kron | 0c141c5 | 2019-08-26 15:04:43 +0200 | [diff] [blame] | 54 | void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) { |
| 55 | receive_stats_callback_->OnDroppedFrames(frames_dropped); |
| 56 | } |
| 57 | |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 58 | void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) { |
| 59 | receive_stats_callback_->OnIncomingPayloadType(payload_type); |
| 60 | } |
| 61 | |
| 62 | void VideoStreamDecoder::OnDecoderImplementationName( |
| 63 | const char* implementation_name) { |
| 64 | receive_stats_callback_->OnDecoderImplementationName(implementation_name); |
| 65 | } |
| 66 | |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 67 | } // namespace webrtc |