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_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
16 #include "webrtc/common_types.h"
17 #include "webrtc/common_video/interface/i420_video_frame.h"
18 #include "webrtc/common_video/interface/video_image.h"
19 #include "webrtc/modules/interface/module_common_types.h"
20 #include "webrtc/modules/video_coding/codecs/interface/video_error_codes.h"
22 #include "webrtc/typedefs.h"
27 class RTPFragmentationHeader; // forward declaration
29 // Note: if any pointers are added to this struct, it must be fitted
30 // with a copy-constructor. See below.
31 struct CodecSpecificInfoVP8 {
35 uint64_t pictureIdRPSI;
36 int16_t pictureId; // Negative value to skip pictureId.
41 int tl0PicIdx; // Negative value to skip tl0PicIdx.
42 int8_t keyIdx; // Negative value to skip keyIdx.
45 struct CodecSpecificInfoGeneric {
46 uint8_t simulcast_idx;
49 struct CodecSpecificInfoH264 {};
51 union CodecSpecificInfoUnion {
52 CodecSpecificInfoGeneric generic;
53 CodecSpecificInfoVP8 VP8;
54 CodecSpecificInfoH264 H264;
57 // Note: if any pointers are added to this struct or its sub-structs, it
58 // must be fitted with a copy-constructor. This is because it is copied
59 // in the copy-constructor of VCMEncodedFrame.
60 struct CodecSpecificInfo
62 VideoCodecType codecType;
63 CodecSpecificInfoUnion codecSpecific;
66 class EncodedImageCallback
69 virtual ~EncodedImageCallback() {};
71 // Callback function which is called when an image has been encoded.
74 // - encodedImage : The encoded image
76 // Return value : > 0, signals to the caller that one or more future frames
77 // should be dropped to keep bit rate or frame rate.
81 Encoded(EncodedImage& encodedImage,
82 const CodecSpecificInfo* codecSpecificInfo = NULL,
83 const RTPFragmentationHeader* fragmentation = NULL) = 0;
89 virtual ~VideoEncoder() {};
91 // Initialize the encoder with the information from the VideoCodec.
94 // - codecSettings : Codec settings
95 // - numberOfCores : Number of cores available for the encoder
96 // - maxPayloadSize : The maximum size each payload is allowed
97 // to have. Usually MTU - overhead.
99 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
100 virtual int32_t InitEncode(const VideoCodec* codecSettings, int32_t numberOfCores, uint32_t maxPayloadSize) = 0;
102 // Encode an I420 image (as a part of a video stream). The encoded image
103 // will be returned to the user through the encode complete callback.
106 // - inputImage : Image to be encoded
107 // - codecSpecificInfo : Pointer to codec specific data
108 // - frame_types : The frame type to encode
110 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0
112 virtual int32_t Encode(
113 const I420VideoFrame& inputImage,
114 const CodecSpecificInfo* codecSpecificInfo,
115 const std::vector<VideoFrameType>* frame_types) = 0;
117 // Register an encode complete callback object.
120 // - callback : Callback object which handles encoded images.
122 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
123 virtual int32_t RegisterEncodeCompleteCallback(EncodedImageCallback* callback) = 0;
125 // Free encoder memory.
127 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
128 virtual int32_t Release() = 0;
130 // Inform the encoder about the packet loss and round trip time on the
131 // network used to decide the best pattern and signaling.
133 // - packetLoss : Fraction lost (loss rate in percent =
134 // 100 * packetLoss / 255)
135 // - rtt : Round-trip time in milliseconds
137 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
138 virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) = 0;
140 // Inform the encoder about the new target bit rate.
142 // - newBitRate : New target bit rate
143 // - frameRate : The target frame rate
145 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
146 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) = 0;
148 // Use this function to enable or disable periodic key frames. Can be useful for codecs
149 // which have other ways of stopping error propagation.
151 // - enable : Enable or disable periodic key frames
153 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
154 virtual int32_t SetPeriodicKeyFrames(bool enable) { return WEBRTC_VIDEO_CODEC_ERROR; }
156 // Codec configuration data to send out-of-band, i.e. in SIP call setup
158 // - buffer : Buffer pointer to where the configuration data
160 // - size : The size of the buffer in bytes
162 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
163 virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) { return WEBRTC_VIDEO_CODEC_ERROR; }
166 class DecodedImageCallback
169 virtual ~DecodedImageCallback() {};
171 // Callback function which is called when an image has been decoded.
174 // - decodedImage : The decoded image.
176 // Return value : 0 if OK, < 0 otherwise.
177 virtual int32_t Decoded(I420VideoFrame& decodedImage) = 0;
179 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {return -1;}
181 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) {return -1;}
187 virtual ~VideoDecoder() {};
189 // Initialize the decoder with the information from the VideoCodec.
192 // - inst : Codec settings
193 // - numberOfCores : Number of cores available for the decoder
195 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
196 virtual int32_t InitDecode(const VideoCodec* codecSettings, int32_t numberOfCores) = 0;
198 // Decode encoded image (as a part of a video stream). The decoded image
199 // will be returned to the user through the decode complete callback.
202 // - inputImage : Encoded image to be decoded
203 // - missingFrames : True if one or more frames have been lost
204 // since the previous decode call.
205 // - fragmentation : Specifies where the encoded frame can be
206 // split into separate fragments. The meaning
207 // of fragment is codec specific, but often
208 // means that each fragment is decodable by
210 // - codecSpecificInfo : Pointer to codec specific data
211 // - renderTimeMs : System time to render in milliseconds. Only
212 // used by decoders with internal rendering.
214 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
216 Decode(const EncodedImage& inputImage,
218 const RTPFragmentationHeader* fragmentation,
219 const CodecSpecificInfo* codecSpecificInfo = NULL,
220 int64_t renderTimeMs = -1) = 0;
222 // Register an decode complete callback object.
225 // - callback : Callback object which handles decoded images.
227 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
228 virtual int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback) = 0;
230 // Free decoder memory.
232 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
233 virtual int32_t Release() = 0;
235 // Reset decoder state and prepare for a new call.
237 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
238 virtual int32_t Reset() = 0;
240 // Codec configuration data sent out-of-band, i.e. in SIP call setup
243 // - buffer : Buffer pointer to the configuration data
244 // - size : The size of the configuration data in
247 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
248 virtual int32_t SetCodecConfigParameters(const uint8_t* /*buffer*/, int32_t /*size*/) { return WEBRTC_VIDEO_CODEC_ERROR; }
250 // Create a copy of the codec and its internal state.
252 // Return value : A copy of the instance if OK, NULL otherwise.
253 virtual VideoDecoder* Copy() { return NULL; }
256 } // namespace webrtc
258 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H