blob: 5640835c16e931cebb2db6f4ded92e0bce420fda [file] [log] [blame]
Tommi74fc5742020-04-27 08:43:061/*
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:3113#include "api/video_codecs/video_decoder.h"
Tommi74fc5742020-04-27 08:43:0614#include "modules/video_coding/video_receiver2.h"
15#include "rtc_base/checks.h"
Rasmus Brandt090fe082023-05-09 10:53:0116#include "video/receive_statistics_proxy.h"
Tommi74fc5742020-04-27 08:43:0617
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 14:22:1142// Do not acquire the lock of `video_receiver_` in this function. Decode
Tommi74fc5742020-04-27 08:43:0643// 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 05:34:2348 TimeDelta decode_time,
Philipp Hancke51657432023-08-15 08:20:5049 VideoContentType content_type,
50 VideoFrameType frame_type) {
Philipp Hancked970b092022-06-17 05:34:2351 receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time,
Philipp Hancke51657432023-08-15 08:20:5052 content_type, frame_type);
Tommi74fc5742020-04-27 08:43:0653 incoming_video_stream_->OnFrame(video_frame);
54 return 0;
55}
56
57void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
58 receive_stats_callback_->OnDroppedFrames(frames_dropped);
59}
60
61void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
62 receive_stats_callback_->OnIncomingPayloadType(payload_type);
63}
64
Evan Shrubsole09da10e2022-10-14 14:38:3165void VideoStreamDecoder::OnDecoderInfoChanged(
66 const VideoDecoder::DecoderInfo& decoder_info) {
67 receive_stats_callback_->OnDecoderInfo(decoder_info);
Tommi74fc5742020-04-27 08:43:0668}
69
70} // namespace internal
71} // namespace webrtc