2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_CODEC_DATABASE_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_CODEC_DATABASE_H_
16 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
17 #include "webrtc/modules/video_coding/main/interface/video_coding.h"
18 #include "webrtc/modules/video_coding/main/source/generic_decoder.h"
19 #include "webrtc/modules/video_coding/main/source/generic_encoder.h"
20 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
21 #include "webrtc/typedefs.h"
25 enum VCMCodecDBProperties {
26 kDefaultPayloadSize = 1440
29 struct VCMDecoderMapItem {
31 VCMDecoderMapItem(VideoCodec* settings,
33 bool require_key_frame);
35 scoped_ptr<VideoCodec> settings;
37 bool require_key_frame;
40 struct VCMExtDecoderMapItem {
42 VCMExtDecoderMapItem(VideoDecoder* external_decoder_instance,
44 bool internal_render_timing);
47 VideoDecoder* external_decoder_instance;
48 bool internal_render_timing;
51 class VCMCodecDataBase {
57 // Returns the number of supported codecs (or -1 in case of error).
58 static int NumberOfCodecs();
60 // Returns the default settings for the codec with id |list_id|.
61 static bool Codec(int list_id, VideoCodec* settings);
63 // Returns the default settings for the codec with type |codec_type|.
64 static bool Codec(VideoCodecType codec_type, VideoCodec* settings);
68 // Sets the sender side codec and initiates the desired codec given the
70 // Returns true if the codec was successfully registered, false otherwise.
71 bool SetSendCodec(const VideoCodec* send_codec,
74 VCMEncodedFrameCallback* encoded_frame_callback);
76 // Gets the current send codec. Relevant for internal codecs only.
77 // Returns true if there is a send codec, false otherwise.
78 bool SendCodec(VideoCodec* current_send_codec) const;
80 // Gets current send side codec type. Relevant for internal codecs only.
81 // Returns kVideoCodecUnknown if there is no send codec.
82 VideoCodecType SendCodec() const;
84 // Registers and initializes an external encoder object.
85 // |internal_source| should be set to true if the codec has an internal
86 // video source and doesn't need the user to provide it with frames via
87 // the Encode() method.
88 void RegisterExternalEncoder(VideoEncoder* external_encoder,
90 bool internal_source);
92 // Deregisters an external encoder. Returns true if the encoder was
93 // found and deregistered, false otherwise. |was_send_codec| is set to true
94 // if the external encoder was the send codec before being deregistered.
95 bool DeregisterExternalEncoder(uint8_t payload_type, bool* was_send_codec);
97 VCMGenericEncoder* GetEncoder();
99 bool SetPeriodicKeyFrames(bool enable);
102 void ResetReceiver();
104 // Deregisters an external decoder object specified by |payload_type|.
105 bool DeregisterExternalDecoder(uint8_t payload_type);
107 // Registers an external decoder object to the payload type |payload_type|.
108 // |internal_render_timing| is set to true if the |external_decoder| has
109 // built in rendering which is able to obey the render timestamps of the
111 bool RegisterExternalDecoder(VideoDecoder* external_decoder,
112 uint8_t payload_type,
113 bool internal_render_timing);
115 bool DecoderRegistered() const;
117 bool RegisterReceiveCodec(const VideoCodec* receive_codec,
119 bool require_key_frame);
121 bool DeregisterReceiveCodec(uint8_t payload_type);
123 // Get current receive side codec. Relevant for internal codecs only.
124 bool ReceiveCodec(VideoCodec* current_receive_codec) const;
126 // Get current receive side codec type. Relevant for internal codecs only.
127 VideoCodecType ReceiveCodec() const;
129 // Returns a decoder specified by |payload_type|. The decoded frame callback
130 // of the encoder is set to |decoded_frame_callback|. If no such decoder
131 // already exists an instance will be created and initialized.
132 // NULL is returned if no encoder with the specified payload type was found
133 // and the function failed to create one.
134 VCMGenericDecoder* GetDecoder(
135 uint8_t payload_type, VCMDecodedFrameCallback* decoded_frame_callback);
137 // Returns a deep copy of the currently active decoder.
138 VCMGenericDecoder* CreateDecoderCopy() const;
140 // Deletes the memory of the decoder instance |decoder|. Used to delete
141 // deep copies returned by CreateDecoderCopy().
142 void ReleaseDecoder(VCMGenericDecoder* decoder) const;
144 // Creates a deep copy of |decoder| and replaces the currently used decoder
146 void CopyDecoder(const VCMGenericDecoder& decoder);
148 // Returns true if the currently active decoder supports render scheduling,
149 // that is, it is able to render frames according to the render timestamp of
150 // the encoded frames.
151 bool SupportsRenderScheduling() const;
154 typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
155 typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
157 VCMGenericDecoder* CreateAndInitDecoder(uint8_t payload_type,
158 VideoCodec* new_codec,
159 bool* external) const;
161 // Determines whether a new codec has to be created or not.
162 // Checks every setting apart from maxFramerate and startBitrate.
163 bool RequiresEncoderReset(const VideoCodec& send_codec);
164 // Create an internal encoder given a codec type.
165 VCMGenericEncoder* CreateEncoder(const VideoCodecType type) const;
167 void DeleteEncoder();
169 // Create an internal Decoder given a codec type
170 VCMGenericDecoder* CreateDecoder(VideoCodecType type) const;
172 const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
174 const VCMExtDecoderMapItem* FindExternalDecoderItem(
175 uint8_t payload_type) const;
177 int number_of_cores_;
178 int max_payload_size_;
179 bool periodic_key_frames_;
180 bool pending_encoder_reset_;
181 bool current_enc_is_external_;
182 VideoCodec send_codec_;
183 VideoCodec receive_codec_;
184 uint8_t external_payload_type_;
185 VideoEncoder* external_encoder_;
186 bool internal_source_;
187 VCMGenericEncoder* ptr_encoder_;
188 VCMGenericDecoder* ptr_decoder_;
189 bool current_dec_is_external_;
191 ExternalDecoderMap dec_external_map_;
192 }; // VCMCodecDataBase
194 } // namespace webrtc
196 #endif // WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_CODEC_DATABASE_H_