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 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | |
| 17 | #include "modules/video_coding/generic_decoder.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | struct VCMDecoderMapItem { |
| 22 | public: |
| 23 | VCMDecoderMapItem(VideoCodec* settings, |
| 24 | int number_of_cores, |
| 25 | bool require_key_frame); |
| 26 | |
| 27 | std::unique_ptr<VideoCodec> settings; |
| 28 | int number_of_cores; |
| 29 | bool require_key_frame; |
| 30 | }; |
| 31 | |
| 32 | struct VCMExtDecoderMapItem { |
| 33 | public: |
| 34 | VCMExtDecoderMapItem(VideoDecoder* external_decoder_instance, |
| 35 | uint8_t payload_type); |
| 36 | |
| 37 | uint8_t payload_type; |
| 38 | VideoDecoder* external_decoder_instance; |
| 39 | }; |
| 40 | |
| 41 | class VCMDecoderDataBase { |
| 42 | public: |
| 43 | VCMDecoderDataBase(); |
| 44 | ~VCMDecoderDataBase(); |
| 45 | |
| 46 | bool DeregisterExternalDecoder(uint8_t payload_type); |
| 47 | void RegisterExternalDecoder(VideoDecoder* external_decoder, |
| 48 | uint8_t payload_type); |
| 49 | |
| 50 | bool DecoderRegistered() const; |
| 51 | |
| 52 | bool RegisterReceiveCodec(const VideoCodec* receive_codec, |
| 53 | int number_of_cores, |
| 54 | bool require_key_frame); |
| 55 | |
| 56 | bool DeregisterReceiveCodec(uint8_t payload_type); |
| 57 | |
| 58 | // Returns a decoder specified by |payload_type|. The decoded frame callback |
| 59 | // of the encoder is set to |decoded_frame_callback|. If no such decoder |
| 60 | // already exists an instance will be created and initialized. |
| 61 | // NULL is returned if no encoder with the specified payload type was found |
| 62 | // and the function failed to create one. |
| 63 | VCMGenericDecoder* GetDecoder( |
| 64 | const VCMEncodedFrame& frame, |
| 65 | VCMDecodedFrameCallback* decoded_frame_callback); |
| 66 | |
| 67 | // Returns the current decoder (i.e. the same value as was last returned from |
| 68 | // GetDecoder(); |
| 69 | VCMGenericDecoder* GetCurrentDecoder(); |
| 70 | |
| 71 | // Returns true if the currently active decoder prefer to decode frames late. |
| 72 | // That means that frames must be decoded near the render times stamp. |
| 73 | bool PrefersLateDecoding() const; |
| 74 | |
| 75 | private: |
| 76 | typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap; |
| 77 | typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap; |
| 78 | |
| 79 | std::unique_ptr<VCMGenericDecoder> CreateAndInitDecoder( |
| 80 | const VCMEncodedFrame& frame, |
| 81 | VideoCodec* new_codec) const; |
| 82 | |
| 83 | const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const; |
| 84 | |
| 85 | const VCMExtDecoderMapItem* FindExternalDecoderItem( |
| 86 | uint8_t payload_type) const; |
| 87 | |
| 88 | VideoCodec receive_codec_; |
| 89 | std::unique_ptr<VCMGenericDecoder> ptr_decoder_; |
| 90 | DecoderMap dec_map_; |
| 91 | ExternalDecoderMap dec_external_map_; |
| 92 | }; |
| 93 | |
| 94 | } // namespace webrtc |
| 95 | |
| 96 | #endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_ |