Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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_DECODER_DATABASE_H_ |
| 12 | #define MODULES_VIDEO_CODING_DECODER_DATABASE_H_ |
| 13 | |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 14 | #include <stdint.h> |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 15 | |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 16 | #include <map> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
Erik Språng | 79c96de | 2022-08-19 11:48:10 +0200 | [diff] [blame] | 19 | #include "api/sequence_checker.h" |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 20 | #include "api/video_codecs/video_decoder.h" |
| 21 | #include "modules/video_coding/encoded_frame.h" |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 22 | #include "modules/video_coding/generic_decoder.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 26 | class VCMDecoderDataBase { |
| 27 | public: |
Erik Språng | 79c96de | 2022-08-19 11:48:10 +0200 | [diff] [blame] | 28 | VCMDecoderDataBase(); |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 29 | VCMDecoderDataBase(const VCMDecoderDataBase&) = delete; |
| 30 | VCMDecoderDataBase& operator=(const VCMDecoderDataBase&) = delete; |
| 31 | ~VCMDecoderDataBase() = default; |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 32 | |
| 33 | bool DeregisterExternalDecoder(uint8_t payload_type); |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 34 | void RegisterExternalDecoder(uint8_t payload_type, |
| 35 | VideoDecoder* external_decoder); |
Johannes Kron | 16359f6 | 2021-02-18 23:37:22 +0100 | [diff] [blame] | 36 | bool IsExternalDecoderRegistered(uint8_t payload_type) const; |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 37 | |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame] | 38 | void RegisterReceiveCodec(uint8_t payload_type, |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 39 | const VideoDecoder::Settings& settings); |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 40 | bool DeregisterReceiveCodec(uint8_t payload_type); |
| 41 | |
Åsa Persson | 6cb74fd | 2018-06-01 15:13:42 +0200 | [diff] [blame] | 42 | // Returns a decoder specified by frame.PayloadType. The decoded frame |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 43 | // callback of the decoder is set to `decoded_frame_callback`. If no such |
Åsa Persson | 6cb74fd | 2018-06-01 15:13:42 +0200 | [diff] [blame] | 44 | // decoder already exists an instance will be created and initialized. |
| 45 | // nullptr is returned if no decoder with the specified payload type was found |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 46 | // and the function failed to create one. |
| 47 | VCMGenericDecoder* GetDecoder( |
| 48 | const VCMEncodedFrame& frame, |
| 49 | VCMDecodedFrameCallback* decoded_frame_callback); |
| 50 | |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 51 | private: |
Erik Språng | 79c96de | 2022-08-19 11:48:10 +0200 | [diff] [blame] | 52 | void CreateAndInitDecoder(const VCMEncodedFrame& frame) |
| 53 | RTC_RUN_ON(decoder_sequence_checker_); |
| 54 | |
| 55 | SequenceChecker decoder_sequence_checker_; |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 56 | |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 57 | absl::optional<uint8_t> current_payload_type_; |
Erik Språng | 79c96de | 2022-08-19 11:48:10 +0200 | [diff] [blame] | 58 | absl::optional<VCMGenericDecoder> current_decoder_ |
| 59 | RTC_GUARDED_BY(decoder_sequence_checker_); |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 60 | // Initialization paramaters for decoders keyed by payload type. |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 61 | std::map<uint8_t, VideoDecoder::Settings> decoder_settings_; |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 62 | // Decoders keyed by payload type. |
Erik Språng | 79c96de | 2022-08-19 11:48:10 +0200 | [diff] [blame] | 63 | std::map<uint8_t, VideoDecoder*> decoders_ |
| 64 | RTC_GUARDED_BY(decoder_sequence_checker_); |
Niels Möller | f906378 | 2018-02-20 16:09:48 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_ |