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/modules/interface/module_common_types.h"
19 #include "webrtc/modules/video_coding/codecs/interface/video_error_codes.h"
20 #include "webrtc/typedefs.h"
21 #include "webrtc/video_encoder.h"
26 class RTPFragmentationHeader; // forward declaration
28 // Note: if any pointers are added to this struct, it must be fitted
29 // with a copy-constructor. See below.
30 struct CodecSpecificInfoVP8 {
34 uint64_t pictureIdRPSI;
35 int16_t pictureId; // Negative value to skip pictureId.
40 int tl0PicIdx; // Negative value to skip tl0PicIdx.
41 int8_t keyIdx; // Negative value to skip keyIdx.
44 struct CodecSpecificInfoGeneric {
45 uint8_t simulcast_idx;
48 struct CodecSpecificInfoH264 {};
50 union CodecSpecificInfoUnion {
51 CodecSpecificInfoGeneric generic;
52 CodecSpecificInfoVP8 VP8;
53 CodecSpecificInfoH264 H264;
56 // Note: if any pointers are added to this struct or its sub-structs, it
57 // must be fitted with a copy-constructor. This is because it is copied
58 // in the copy-constructor of VCMEncodedFrame.
59 struct CodecSpecificInfo
61 VideoCodecType codecType;
62 CodecSpecificInfoUnion codecSpecific;
65 class DecodedImageCallback
68 virtual ~DecodedImageCallback() {};
70 // Callback function which is called when an image has been decoded.
73 // - decodedImage : The decoded image.
75 // Return value : 0 if OK, < 0 otherwise.
76 virtual int32_t Decoded(I420VideoFrame& decodedImage) = 0;
78 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {return -1;}
80 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) {return -1;}
86 virtual ~VideoDecoder() {};
88 // Initialize the decoder with the information from the VideoCodec.
91 // - inst : Codec settings
92 // - numberOfCores : Number of cores available for the decoder
94 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
95 virtual int32_t InitDecode(const VideoCodec* codecSettings, int32_t numberOfCores) = 0;
97 // Decode encoded image (as a part of a video stream). The decoded image
98 // will be returned to the user through the decode complete callback.
101 // - inputImage : Encoded image to be decoded
102 // - missingFrames : True if one or more frames have been lost
103 // since the previous decode call.
104 // - fragmentation : Specifies where the encoded frame can be
105 // split into separate fragments. The meaning
106 // of fragment is codec specific, but often
107 // means that each fragment is decodable by
109 // - codecSpecificInfo : Pointer to codec specific data
110 // - renderTimeMs : System time to render in milliseconds. Only
111 // used by decoders with internal rendering.
113 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
115 Decode(const EncodedImage& inputImage,
117 const RTPFragmentationHeader* fragmentation,
118 const CodecSpecificInfo* codecSpecificInfo = NULL,
119 int64_t renderTimeMs = -1) = 0;
121 // Register an decode complete callback object.
124 // - callback : Callback object which handles decoded images.
126 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
127 virtual int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback) = 0;
129 // Free decoder memory.
131 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
132 virtual int32_t Release() = 0;
134 // Reset decoder state and prepare for a new call.
136 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
137 virtual int32_t Reset() = 0;
139 // Codec configuration data sent out-of-band, i.e. in SIP call setup
142 // - buffer : Buffer pointer to the configuration data
143 // - size : The size of the configuration data in
146 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
147 virtual int32_t SetCodecConfigParameters(const uint8_t* /*buffer*/, int32_t /*size*/) { return WEBRTC_VIDEO_CODEC_ERROR; }
149 // Create a copy of the codec and its internal state.
151 // Return value : A copy of the instance if OK, NULL otherwise.
152 virtual VideoDecoder* Copy() { return NULL; }
155 } // namespace webrtc
157 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H