blob: 1ef2d0ecd0424e610bf955b774f24e99a77d2b84 [file] [log] [blame]
Tommi74fc5742020-04-27 10:43:06 +02001/*
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
Evan Shrubsole09da10e2022-10-14 14:38:31 +000013#include "api/video_codecs/video_decoder.h"
Tommi74fc5742020-04-27 10:43:06 +020014#include "modules/video_coding/video_receiver2.h"
15#include "rtc_base/checks.h"
16#include "video/receive_statistics_proxy2.h"
17
18namespace webrtc {
19namespace internal {
20
21VideoStreamDecoder::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
33VideoStreamDecoder::~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
Artem Titovab30d722021-07-27 16:22:11 +020042// Do not acquire the lock of `video_receiver_` in this function. Decode
Tommi74fc5742020-04-27 10:43:06 +020043// 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.
46int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
47 absl::optional<uint8_t> qp,
Philipp Hancked970b092022-06-17 07:34:23 +020048 TimeDelta decode_time,
Tommi74fc5742020-04-27 10:43:06 +020049 VideoContentType content_type) {
Philipp Hancked970b092022-06-17 07:34:23 +020050 receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time,
Tommi74fc5742020-04-27 10:43:06 +020051 content_type);
52 incoming_video_stream_->OnFrame(video_frame);
53 return 0;
54}
55
56void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
57 receive_stats_callback_->OnDroppedFrames(frames_dropped);
58}
59
60void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
61 receive_stats_callback_->OnIncomingPayloadType(payload_type);
62}
63
Evan Shrubsole09da10e2022-10-14 14:38:31 +000064void VideoStreamDecoder::OnDecoderInfoChanged(
65 const VideoDecoder::DecoderInfo& decoder_info) {
66 receive_stats_callback_->OnDecoderInfo(decoder_info);
Tommi74fc5742020-04-27 10:43:06 +020067}
68
69} // namespace internal
70} // namespace webrtc