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 14 #include <stdint.h> 15 16 #include <map> 17 #include <memory> 18 19 #include "absl/types/optional.h" 20 #include "api/sequence_checker.h" 21 #include "api/video_codecs/video_decoder.h" 22 #include "modules/video_coding/encoded_frame.h" 23 #include "modules/video_coding/generic_decoder.h" 24 25 namespace webrtc { 26 27 class VCMDecoderDatabase { 28 public: 29 VCMDecoderDatabase(); 30 VCMDecoderDatabase(const VCMDecoderDatabase&) = delete; 31 VCMDecoderDatabase& operator=(const VCMDecoderDatabase&) = delete; 32 ~VCMDecoderDatabase() = default; 33 34 // Returns a pointer to the previously registered decoder or nullptr if none 35 // was registered for the `payload_type`. 36 void DeregisterExternalDecoder(uint8_t payload_type); 37 void RegisterExternalDecoder(uint8_t payload_type, 38 std::unique_ptr<VideoDecoder> external_decoder); 39 bool IsExternalDecoderRegistered(uint8_t payload_type) const; 40 41 void RegisterReceiveCodec(uint8_t payload_type, 42 const VideoDecoder::Settings& settings); 43 bool DeregisterReceiveCodec(uint8_t payload_type); 44 void DeregisterReceiveCodecs(); 45 46 // Returns a decoder specified by frame.PayloadType. The decoded frame 47 // callback of the decoder is set to `decoded_frame_callback`. If no such 48 // decoder already exists an instance will be created and initialized. 49 // nullptr is returned if no decoder with the specified payload type was found 50 // and the function failed to create one. 51 VCMGenericDecoder* GetDecoder( 52 const VCMEncodedFrame& frame, 53 VCMDecodedFrameCallback* decoded_frame_callback); 54 55 private: 56 void CreateAndInitDecoder(const VCMEncodedFrame& frame) 57 RTC_RUN_ON(decoder_sequence_checker_); 58 59 SequenceChecker decoder_sequence_checker_; 60 61 absl::optional<uint8_t> current_payload_type_; 62 absl::optional<VCMGenericDecoder> current_decoder_ 63 RTC_GUARDED_BY(decoder_sequence_checker_); 64 // Initialization paramaters for decoders keyed by payload type. 65 std::map<uint8_t, VideoDecoder::Settings> decoder_settings_; 66 // Decoders keyed by payload type. 67 std::map<uint8_t, std::unique_ptr<VideoDecoder>> decoders_ 68 RTC_GUARDED_BY(decoder_sequence_checker_); 69 }; 70 71 } // namespace webrtc 72 73 #endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_ 74