blob: 45d774b1ba21086d8fce82ac177e0c0a943e426b [file] [log] [blame]
Niels Mölleree3d9952019-09-09 12:51:55 +02001/*
2 * Copyright (c) 2019 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#ifndef MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_
12#define MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_
13
Artem Titovd15a5752021-02-10 14:31:24 +010014#include "api/sequence_checker.h"
Danil Chapovalov355b8d22021-08-13 16:50:37 +020015#include "api/video_codecs/video_decoder.h"
Jonas Orelande02f9ee2022-03-25 12:43:14 +010016#include "api/webrtc_key_value_config.h"
Niels Mölleree3d9952019-09-09 12:51:55 +020017#include "modules/video_coding/decoder_database.h"
18#include "modules/video_coding/encoded_frame.h"
19#include "modules/video_coding/generic_decoder.h"
20#include "modules/video_coding/timing.h"
Niels Mölleree3d9952019-09-09 12:51:55 +020021#include "system_wrappers/include/clock.h"
22
23namespace webrtc {
24
25// This class is a copy of vcm::VideoReceiver, trimmed down to what's used by
26// VideoReceive stream, with the aim to incrementally trim it down further and
27// ultimately delete it. It's difficult to do this incrementally with the
28// original VideoReceiver class, since it is used by the legacy
29// VideoCodingModule api.
30class VideoReceiver2 {
31 public:
Jonas Orelande02f9ee2022-03-25 12:43:14 +010032 VideoReceiver2(Clock* clock,
33 VCMTiming* timing,
34 const WebRtcKeyValueConfig& field_trials);
Niels Mölleree3d9952019-09-09 12:51:55 +020035 ~VideoReceiver2();
36
Danil Chapovalovba0a3062021-08-13 18:15:55 +020037 void RegisterReceiveCodec(uint8_t payload_type,
Danil Chapovalov355b8d22021-08-13 16:50:37 +020038 const VideoDecoder::Settings& decoder_settings);
Niels Mölleree3d9952019-09-09 12:51:55 +020039
40 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
41 uint8_t payloadType);
Johannes Kron16359f62021-02-18 23:37:22 +010042 bool IsExternalDecoderRegistered(uint8_t payloadType) const;
Niels Mölleree3d9952019-09-09 12:51:55 +020043 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
44
45 int32_t Decode(const webrtc::VCMEncodedFrame* frame);
46
Niels Mölleree3d9952019-09-09 12:51:55 +020047 // Notification methods that are used to check our internal state and validate
48 // threading assumptions. These are called by VideoReceiveStream.
Artem Titovdcd7fc72021-08-09 13:02:57 +020049 // See `IsDecoderThreadRunning()` for more details.
Niels Mölleree3d9952019-09-09 12:51:55 +020050 void DecoderThreadStarting();
51 void DecoderThreadStopped();
52
53 private:
54 // Used for DCHECKing thread correctness.
55 // In build where DCHECKs are enabled, will return false before
56 // DecoderThreadStarting is called, then true until DecoderThreadStopped
57 // is called.
58 // In builds where DCHECKs aren't enabled, it will return true.
59 bool IsDecoderThreadRunning();
60
Johannes Kron16359f62021-02-18 23:37:22 +010061 SequenceChecker construction_sequence_checker_;
62 SequenceChecker decoder_sequence_checker_;
Niels Mölleree3d9952019-09-09 12:51:55 +020063 Clock* const clock_;
64 VCMTiming* timing_;
65 VCMDecodedFrameCallback decodedFrameCallback_;
66
67 // Callbacks are set before the decoder thread starts.
Artem Titovdcd7fc72021-08-09 13:02:57 +020068 // Once the decoder thread has been started, usage of `_codecDataBase` moves
Niels Mölleree3d9952019-09-09 12:51:55 +020069 // over to the decoder thread.
70 VCMDecoderDataBase codecDataBase_;
71
72#if RTC_DCHECK_IS_ON
73 bool decoder_thread_is_running_ = false;
74#endif
75};
76
77} // namespace webrtc
78
79#endif // MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_