blob: 6ef60024a91c63874ac3532a167e108dda7ba1d4 [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
13#include "modules/video_coding/video_receiver2.h"
14#include "rtc_base/checks.h"
15#include "video/receive_statistics_proxy2.h"
16
17namespace webrtc {
18namespace internal {
19
20VideoStreamDecoder::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
32VideoStreamDecoder::~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 Titovab30d722021-07-27 14:22:1141// Do not acquire the lock of `video_receiver_` in this function. Decode
Tommi74fc5742020-04-27 08:43:0642// 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.
45int32_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
55void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
56 receive_stats_callback_->OnDroppedFrames(frames_dropped);
57}
58
59void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
60 receive_stats_callback_->OnIncomingPayloadType(payload_type);
61}
62
63void VideoStreamDecoder::OnDecoderImplementationName(
64 const char* implementation_name) {
65 receive_stats_callback_->OnDecoderImplementationName(implementation_name);
66}
67
68} // namespace internal
69} // namespace webrtc