blob: 7fe0adef100bc1af1d607c96ab6ef273b20684e8 [file] [log] [blame]
mflodmancfc8e3b2016-05-04 04:22:041/*
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 04:47:3111#include "video/video_stream_decoder.h"
mflodmancfc8e3b2016-05-04 04:22:0412
Niels Mölleree3d9952019-09-09 10:51:5513#include "modules/video_coding/video_receiver2.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "video/receive_statistics_proxy.h"
mflodmancfc8e3b2016-05-04 04:22:0416
17namespace webrtc {
18
19VideoStreamDecoder::VideoStreamDecoder(
Niels Mölleree3d9952019-09-09 10:51:5520 VideoReceiver2* video_receiver,
mflodmancfc8e3b2016-05-04 04:22:0421 ReceiveStatisticsProxy* receive_statistics_proxy,
nisse76bc8e82017-02-07 17:37:4122 rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
mflodmancfc8e3b2016-05-04 04:22:0423 : video_receiver_(video_receiver),
24 receive_stats_callback_(receive_statistics_proxy),
Tommi6b28e202018-03-25 17:52:4625 incoming_video_stream_(incoming_video_stream) {
mflodmancfc8e3b2016-05-04 04:22:0426 RTC_DCHECK(video_receiver_);
27
mflodmancfc8e3b2016-05-04 04:22:0428 video_receiver_->RegisterReceiveCallback(this);
mflodmancfc8e3b2016-05-04 04:22:0429}
30
tommi2e82f382016-06-21 07:26:4331VideoStreamDecoder::~VideoStreamDecoder() {
tommid0a71ba2017-03-14 11:16:2032 // 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 07:26:4336 // Unset all the callback pointers that we set in the ctor.
tommi2e82f382016-06-21 07:26:4337 video_receiver_->RegisterReceiveCallback(nullptr);
38}
mflodmancfc8e3b2016-05-04 04:22:0439
Artem Titovab30d722021-07-27 14:22:1140// Do not acquire the lock of `video_receiver_` in this function. Decode
mflodmancfc8e3b2016-05-04 04:22:0441// 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 12:53:4544int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
Danil Chapovalovb9b146c2018-06-15 10:28:0745 absl::optional<uint8_t> qp,
Johannes Kronbfd343b2019-07-01 08:07:5046 int32_t decode_time_ms,
ilnik00d802b2017-04-11 17:34:3147 VideoContentType content_type) {
Johannes Kronbfd343b2019-07-01 08:07:5048 receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time_ms,
49 content_type);
sakal55d932b2016-09-30 13:19:0850 incoming_video_stream_->OnFrame(video_frame);
mflodmancfc8e3b2016-05-04 04:22:0451 return 0;
52}
53
Johannes Kron0c141c52019-08-26 13:04:4354void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
55 receive_stats_callback_->OnDroppedFrames(frames_dropped);
56}
57
mflodmancfc8e3b2016-05-04 04:22:0458void 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-04 04:22:0467} // namespace webrtc