blob: 132e30f3b199698766ac2d2fb6aa5047c7cdf83c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.orgf27916a2012-01-20 14:04:13 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Henrik Kjellander2557b862015-11-18 22:00:21 +010011#ifndef WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_
12#define WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
stefan@webrtc.orgf27916a2012-01-20 14:04:13 +000014#include <map>
15
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000016#include "webrtc/base/scoped_ptr.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010017#include "webrtc/modules/video_coding/include/video_codec_interface.h"
18#include "webrtc/modules/video_coding/include/video_coding.h"
19#include "webrtc/modules/video_coding/generic_decoder.h"
20#include "webrtc/modules/video_coding/generic_encoder.h"
pbos@webrtc.orga4407322013-07-16 12:32:05 +000021#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000025struct VCMDecoderMapItem {
26 public:
27 VCMDecoderMapItem(VideoCodec* settings,
28 int number_of_cores,
29 bool require_key_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000030
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000031 rtc::scoped_ptr<VideoCodec> settings;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000032 int number_of_cores;
33 bool require_key_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +000034};
35
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000036struct VCMExtDecoderMapItem {
37 public:
38 VCMExtDecoderMapItem(VideoDecoder* external_decoder_instance,
39 uint8_t payload_type,
40 bool internal_render_timing);
niklase@google.com470e71d2011-07-07 08:21:25 +000041
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000042 uint8_t payload_type;
43 VideoDecoder* external_decoder_instance;
44 bool internal_render_timing;
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
46
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000047class VCMCodecDataBase {
48 public:
Peter Boström4f5db112015-10-29 16:53:59 +010049 VCMCodecDataBase(VideoEncoderRateObserver* encoder_rate_observer,
50 VCMEncodedFrameCallback* encoded_frame_callback);
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000051 ~VCMCodecDataBase();
niklase@google.com470e71d2011-07-07 08:21:25 +000052
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000053 // Sender Side
54 // Returns the number of supported codecs (or -1 in case of error).
55 static int NumberOfCodecs();
niklase@google.com470e71d2011-07-07 08:21:25 +000056
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000057 // Returns the default settings for the codec with id |list_id|.
58 static bool Codec(int list_id, VideoCodec* settings);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000060 // Returns the default settings for the codec with type |codec_type|.
61 static bool Codec(VideoCodecType codec_type, VideoCodec* settings);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000063 void ResetSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000064
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000065 // Sets the sender side codec and initiates the desired codec given the
66 // VideoCodec struct.
67 // Returns true if the codec was successfully registered, false otherwise.
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000068 bool SetSendCodec(const VideoCodec* send_codec,
69 int number_of_cores,
Peter Boström4f5db112015-10-29 16:53:59 +010070 size_t max_payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000071
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000072 // Gets the current send codec. Relevant for internal codecs only.
73 // Returns true if there is a send codec, false otherwise.
74 bool SendCodec(VideoCodec* current_send_codec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000076 // Gets current send side codec type. Relevant for internal codecs only.
77 // Returns kVideoCodecUnknown if there is no send codec.
78 VideoCodecType SendCodec() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000080 // Registers and initializes an external encoder object.
81 // |internal_source| should be set to true if the codec has an internal
82 // video source and doesn't need the user to provide it with frames via
83 // the Encode() method.
84 void RegisterExternalEncoder(VideoEncoder* external_encoder,
85 uint8_t payload_type,
86 bool internal_source);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000088 // Deregisters an external encoder. Returns true if the encoder was
89 // found and deregistered, false otherwise. |was_send_codec| is set to true
90 // if the external encoder was the send codec before being deregistered.
91 bool DeregisterExternalEncoder(uint8_t payload_type, bool* was_send_codec);
niklase@google.com470e71d2011-07-07 08:21:25 +000092
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000093 VCMGenericEncoder* GetEncoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000094
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000095 bool SetPeriodicKeyFrames(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000097 // Receiver Side
98 void ResetReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000099
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000100 // Deregisters an external decoder object specified by |payload_type|.
101 bool DeregisterExternalDecoder(uint8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000103 // Registers an external decoder object to the payload type |payload_type|.
104 // |internal_render_timing| is set to true if the |external_decoder| has
105 // built in rendering which is able to obey the render timestamps of the
106 // encoded frames.
107 bool RegisterExternalDecoder(VideoDecoder* external_decoder,
108 uint8_t payload_type,
109 bool internal_render_timing);
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000111 bool DecoderRegistered() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000113 bool RegisterReceiveCodec(const VideoCodec* receive_codec,
114 int number_of_cores,
115 bool require_key_frame);
116
117 bool DeregisterReceiveCodec(uint8_t payload_type);
118
119 // Get current receive side codec. Relevant for internal codecs only.
120 bool ReceiveCodec(VideoCodec* current_receive_codec) const;
121
122 // Get current receive side codec type. Relevant for internal codecs only.
123 VideoCodecType ReceiveCodec() const;
124
125 // Returns a decoder specified by |payload_type|. The decoded frame callback
126 // of the encoder is set to |decoded_frame_callback|. If no such decoder
127 // already exists an instance will be created and initialized.
128 // NULL is returned if no encoder with the specified payload type was found
129 // and the function failed to create one.
130 VCMGenericDecoder* GetDecoder(
131 uint8_t payload_type, VCMDecodedFrameCallback* decoded_frame_callback);
132
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000133 // Deletes the memory of the decoder instance |decoder|. Used to delete
134 // deep copies returned by CreateDecoderCopy().
135 void ReleaseDecoder(VCMGenericDecoder* decoder) const;
136
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000137 // Returns true if the currently active decoder supports render scheduling,
138 // that is, it is able to render frames according to the render timestamp of
139 // the encoded frames.
140 bool SupportsRenderScheduling() const;
141
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000142 bool MatchesCurrentResolution(int width, int height) const;
143
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000144 private:
145 typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
146 typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
147
148 VCMGenericDecoder* CreateAndInitDecoder(uint8_t payload_type,
Stefan Holmer79064e52015-03-25 15:20:32 +0100149 VideoCodec* new_codec) const;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000150
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000151 // Determines whether a new codec has to be created or not.
152 // Checks every setting apart from maxFramerate and startBitrate.
153 bool RequiresEncoderReset(const VideoCodec& send_codec);
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000154
155 void DeleteEncoder();
156
157 // Create an internal Decoder given a codec type
158 VCMGenericDecoder* CreateDecoder(VideoCodecType type) const;
159
160 const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
161
162 const VCMExtDecoderMapItem* FindExternalDecoderItem(
163 uint8_t payload_type) const;
164
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000165 int number_of_cores_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000166 size_t max_payload_size_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000167 bool periodic_key_frames_;
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000168 bool pending_encoder_reset_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000169 VideoCodec send_codec_;
170 VideoCodec receive_codec_;
Peter Boströmab73d132015-10-15 12:01:38 +0200171 uint8_t encoder_payload_type_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000172 VideoEncoder* external_encoder_;
173 bool internal_source_;
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000174 VideoEncoderRateObserver* const encoder_rate_observer_;
Peter Boström4f5db112015-10-29 16:53:59 +0100175 VCMEncodedFrameCallback* const encoded_frame_callback_;
Peter Boströmab73d132015-10-15 12:01:38 +0200176 rtc::scoped_ptr<VCMGenericEncoder> ptr_encoder_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000177 VCMGenericDecoder* ptr_decoder_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000178 DecoderMap dec_map_;
179 ExternalDecoderMap dec_external_map_;
180}; // VCMCodecDataBase
181
182} // namespace webrtc
183
Henrik Kjellander2557b862015-11-18 22:00:21 +0100184#endif // WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_