Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 1 | /* |
| 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 Titov | d15a575 | 2021-02-10 14:31:24 +0100 | [diff] [blame] | 14 | #include "api/sequence_checker.h" |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 15 | #include "api/video_codecs/video_decoder.h" |
Jonas Oreland | e02f9ee | 2022-03-25 12:43:14 +0100 | [diff] [blame^] | 16 | #include "api/webrtc_key_value_config.h" |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 17 | #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öller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 21 | #include "system_wrappers/include/clock.h" |
| 22 | |
| 23 | namespace 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. |
| 30 | class VideoReceiver2 { |
| 31 | public: |
Jonas Oreland | e02f9ee | 2022-03-25 12:43:14 +0100 | [diff] [blame^] | 32 | VideoReceiver2(Clock* clock, |
| 33 | VCMTiming* timing, |
| 34 | const WebRtcKeyValueConfig& field_trials); |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 35 | ~VideoReceiver2(); |
| 36 | |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame] | 37 | void RegisterReceiveCodec(uint8_t payload_type, |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 38 | const VideoDecoder::Settings& decoder_settings); |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 39 | |
| 40 | void RegisterExternalDecoder(VideoDecoder* externalDecoder, |
| 41 | uint8_t payloadType); |
Johannes Kron | 16359f6 | 2021-02-18 23:37:22 +0100 | [diff] [blame] | 42 | bool IsExternalDecoderRegistered(uint8_t payloadType) const; |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 43 | int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback); |
| 44 | |
| 45 | int32_t Decode(const webrtc::VCMEncodedFrame* frame); |
| 46 | |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 47 | // Notification methods that are used to check our internal state and validate |
| 48 | // threading assumptions. These are called by VideoReceiveStream. |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 49 | // See `IsDecoderThreadRunning()` for more details. |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 50 | 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 Kron | 16359f6 | 2021-02-18 23:37:22 +0100 | [diff] [blame] | 61 | SequenceChecker construction_sequence_checker_; |
| 62 | SequenceChecker decoder_sequence_checker_; |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 63 | Clock* const clock_; |
| 64 | VCMTiming* timing_; |
| 65 | VCMDecodedFrameCallback decodedFrameCallback_; |
| 66 | |
| 67 | // Callbacks are set before the decoder thread starts. |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 68 | // Once the decoder thread has been started, usage of `_codecDataBase` moves |
Niels Möller | ee3d995 | 2019-09-09 12:51:55 +0200 | [diff] [blame] | 69 | // 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_ |