blob: 49021bc06f3c59c3f0f635d841fffce55f88462c [file] [log] [blame]
mflodmancfc8e3b2016-05-03 21:22:04 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "video/video_stream_decoder.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070012
Niels Mölleree3d9952019-09-09 12:51:55 +020013#include "modules/video_coding/video_receiver2.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "video/receive_statistics_proxy.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070016
17namespace webrtc {
18
19VideoStreamDecoder::VideoStreamDecoder(
Niels Mölleree3d9952019-09-09 12:51:55 +020020 VideoReceiver2* video_receiver,
mflodmancfc8e3b2016-05-03 21:22:04 -070021 ReceiveStatisticsProxy* receive_statistics_proxy,
nisse76bc8e82017-02-07 09:37:41 -080022 rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
mflodmancfc8e3b2016-05-03 21:22:04 -070023 : video_receiver_(video_receiver),
24 receive_stats_callback_(receive_statistics_proxy),
Tommi6b28e202018-03-25 19:52:46 +020025 incoming_video_stream_(incoming_video_stream) {
mflodmancfc8e3b2016-05-03 21:22:04 -070026 RTC_DCHECK(video_receiver_);
27
mflodmancfc8e3b2016-05-03 21:22:04 -070028 video_receiver_->RegisterReceiveCallback(this);
mflodmancfc8e3b2016-05-03 21:22:04 -070029}
30
tommi2e82f382016-06-21 00:26:43 -070031VideoStreamDecoder::~VideoStreamDecoder() {
tommid0a71ba2017-03-14 04:16:20 -070032 // 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
tommi2e82f382016-06-21 00:26:43 -070036 // Unset all the callback pointers that we set in the ctor.
tommi2e82f382016-06-21 00:26:43 -070037 video_receiver_->RegisterReceiveCallback(nullptr);
38}
mflodmancfc8e3b2016-05-03 21:22:04 -070039
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.
sakalcc452e12017-02-09 04:53:45 -080044int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020045 absl::optional<uint8_t> qp,
Johannes Kronbfd343b2019-07-01 10:07:50 +020046 int32_t decode_time_ms,
ilnik00d802b2017-04-11 10:34:31 -070047 VideoContentType content_type) {
Johannes Kronbfd343b2019-07-01 10:07:50 +020048 receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time_ms,
49 content_type);
sakal55d932b2016-09-30 06:19:08 -070050 incoming_video_stream_->OnFrame(video_frame);
mflodmancfc8e3b2016-05-03 21:22:04 -070051 return 0;
52}
53
Johannes Kron0c141c52019-08-26 15:04:43 +020054void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
55 receive_stats_callback_->OnDroppedFrames(frames_dropped);
56}
57
mflodmancfc8e3b2016-05-03 21:22:04 -070058void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
59 receive_stats_callback_->OnIncomingPayloadType(payload_type);
60}
61
62void VideoStreamDecoder::OnDecoderImplementationName(
63 const char* implementation_name) {
64 receive_stats_callback_->OnDecoderImplementationName(implementation_name);
65}
66
mflodmancfc8e3b2016-05-03 21:22:04 -070067} // namespace webrtc