blob: c39474f6a2d18e5a44e4e78ff3cffcbc40cabd97 [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
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000054 // Returns the default settings for the codec with type |codec_type|.
Peter Boström92f8dbd2015-11-24 13:55:55 +010055 static void Codec(VideoCodecType codec_type, VideoCodec* settings);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000057 // Sets the sender side codec and initiates the desired codec given the
58 // VideoCodec struct.
59 // Returns true if the codec was successfully registered, false otherwise.
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000060 bool SetSendCodec(const VideoCodec* send_codec,
61 int number_of_cores,
Peter Boström4f5db112015-10-29 16:53:59 +010062 size_t max_payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000064 // Gets the current send codec. Relevant for internal codecs only.
65 // Returns true if there is a send codec, false otherwise.
66 bool SendCodec(VideoCodec* current_send_codec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000067
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000068 // Gets current send side codec type. Relevant for internal codecs only.
69 // Returns kVideoCodecUnknown if there is no send codec.
70 VideoCodecType SendCodec() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000072 // Registers and initializes an external encoder object.
73 // |internal_source| should be set to true if the codec has an internal
74 // video source and doesn't need the user to provide it with frames via
75 // the Encode() method.
76 void RegisterExternalEncoder(VideoEncoder* external_encoder,
77 uint8_t payload_type,
78 bool internal_source);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000080 // Deregisters an external encoder. Returns true if the encoder was
81 // found and deregistered, false otherwise. |was_send_codec| is set to true
82 // if the external encoder was the send codec before being deregistered.
83 bool DeregisterExternalEncoder(uint8_t payload_type, bool* was_send_codec);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000085 VCMGenericEncoder* GetEncoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000086
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000087 bool SetPeriodicKeyFrames(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000088
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000089 // Deregisters an external decoder object specified by |payload_type|.
90 bool DeregisterExternalDecoder(uint8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000092 // Registers an external decoder object to the payload type |payload_type|.
93 // |internal_render_timing| is set to true if the |external_decoder| has
94 // built in rendering which is able to obey the render timestamps of the
95 // encoded frames.
Peter Boström795dbe42015-11-27 14:09:07 +010096 void RegisterExternalDecoder(VideoDecoder* external_decoder,
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +000097 uint8_t payload_type,
98 bool internal_render_timing);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000100 bool DecoderRegistered() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000102 bool RegisterReceiveCodec(const VideoCodec* receive_codec,
103 int number_of_cores,
104 bool require_key_frame);
105
106 bool DeregisterReceiveCodec(uint8_t payload_type);
107
108 // Get current receive side codec. Relevant for internal codecs only.
109 bool ReceiveCodec(VideoCodec* current_receive_codec) const;
110
111 // Get current receive side codec type. Relevant for internal codecs only.
112 VideoCodecType ReceiveCodec() const;
113
114 // Returns a decoder specified by |payload_type|. The decoded frame callback
115 // of the encoder is set to |decoded_frame_callback|. If no such decoder
116 // already exists an instance will be created and initialized.
117 // NULL is returned if no encoder with the specified payload type was found
118 // and the function failed to create one.
119 VCMGenericDecoder* GetDecoder(
Peter Boströme997a7d2015-11-27 14:23:21 +0100120 const VCMEncodedFrame& frame,
121 VCMDecodedFrameCallback* decoded_frame_callback);
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000122
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000123 // Deletes the memory of the decoder instance |decoder|. Used to delete
124 // deep copies returned by CreateDecoderCopy().
125 void ReleaseDecoder(VCMGenericDecoder* decoder) const;
126
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000127 // Returns true if the currently active decoder supports render scheduling,
128 // that is, it is able to render frames according to the render timestamp of
129 // the encoded frames.
130 bool SupportsRenderScheduling() const;
131
pbos@webrtc.org67a9e402015-03-05 13:57:37 +0000132 bool MatchesCurrentResolution(int width, int height) const;
133
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000134 private:
135 typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
136 typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
137
Peter Boströme997a7d2015-11-27 14:23:21 +0100138 VCMGenericDecoder* CreateAndInitDecoder(const VCMEncodedFrame& frame,
Stefan Holmer79064e52015-03-25 15:20:32 +0100139 VideoCodec* new_codec) const;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000140
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000141 // Determines whether a new codec has to be created or not.
142 // Checks every setting apart from maxFramerate and startBitrate.
143 bool RequiresEncoderReset(const VideoCodec& send_codec);
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000144
145 void DeleteEncoder();
146
147 // Create an internal Decoder given a codec type
148 VCMGenericDecoder* CreateDecoder(VideoCodecType type) const;
149
150 const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
151
152 const VCMExtDecoderMapItem* FindExternalDecoderItem(
153 uint8_t payload_type) const;
154
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000155 int number_of_cores_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000156 size_t max_payload_size_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000157 bool periodic_key_frames_;
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000158 bool pending_encoder_reset_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000159 VideoCodec send_codec_;
160 VideoCodec receive_codec_;
Peter Boströmab73d132015-10-15 12:01:38 +0200161 uint8_t encoder_payload_type_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000162 VideoEncoder* external_encoder_;
163 bool internal_source_;
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000164 VideoEncoderRateObserver* const encoder_rate_observer_;
Peter Boström4f5db112015-10-29 16:53:59 +0100165 VCMEncodedFrameCallback* const encoded_frame_callback_;
Peter Boströmab73d132015-10-15 12:01:38 +0200166 rtc::scoped_ptr<VCMGenericEncoder> ptr_encoder_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000167 VCMGenericDecoder* ptr_decoder_;
stefan@webrtc.orgfa7e8682012-10-11 11:21:38 +0000168 DecoderMap dec_map_;
169 ExternalDecoderMap dec_external_map_;
170}; // VCMCodecDataBase
171
172} // namespace webrtc
173
Henrik Kjellander2557b862015-11-18 22:00:21 +0100174#endif // WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_