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.
10 * WEBRTC VP8 wrapper interface
13 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_IMPL_H_
14 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_IMPL_H_
16 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
17 #include "webrtc/modules/video_coding/utility/quality_scaler.h"
19 // VPX forward declaration
20 typedef struct vpx_codec_ctx vpx_codec_ctx_t;
21 typedef struct vpx_codec_ctx vpx_dec_ctx_t;
22 typedef struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t;
23 typedef struct vpx_image vpx_image_t;
24 typedef struct vpx_ref_frame vpx_ref_frame_t;
25 struct vpx_codec_cx_pkt;
30 class ReferencePictureSelection;
32 class VP8EncoderImpl : public VP8Encoder {
36 virtual ~VP8EncoderImpl();
38 // Free encoder memory.
40 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
41 virtual int Release();
43 // Initialize the encoder with the information from the codecSettings
46 // - codec_settings : Codec settings
47 // - number_of_cores : Number of cores available for the encoder
48 // - max_payload_size : The maximum size each payload is allowed
49 // to have. Usually MTU - overhead.
51 // Return value : Set bit rate if OK
53 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
54 // WEBRTC_VIDEO_CODEC_ERR_SIZE
55 // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED
56 // WEBRTC_VIDEO_CODEC_MEMORY
57 // WEBRTC_VIDEO_CODEC_ERROR
58 virtual int InitEncode(const VideoCodec* codec_settings,
60 uint32_t max_payload_size);
62 // Encode an I420 image (as a part of a video stream). The encoded image
63 // will be returned to the user through the encode complete callback.
66 // - input_image : Image to be encoded
67 // - frame_types : Frame type to be generated by the encoder.
69 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
71 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
72 // WEBRTC_VIDEO_CODEC_MEMORY
73 // WEBRTC_VIDEO_CODEC_ERROR
74 // WEBRTC_VIDEO_CODEC_TIMEOUT
76 virtual int Encode(const I420VideoFrame& input_image,
77 const CodecSpecificInfo* codec_specific_info,
78 const std::vector<VideoFrameType>* frame_types);
80 // Register an encode complete callback object.
83 // - callback : Callback object which handles encoded images.
85 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
86 virtual int RegisterEncodeCompleteCallback(EncodedImageCallback* callback);
88 // Inform the encoder of the new packet loss rate and the round-trip time of
91 // - packet_loss : Fraction lost
92 // (loss rate in percent = 100 * packetLoss / 255)
93 // - rtt : Round-trip time in milliseconds
94 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
95 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
97 virtual int SetChannelParameters(uint32_t packet_loss, int rtt);
99 // Inform the encoder about the new target bit rate.
101 // - new_bitrate_kbit : New target bit rate
102 // - frame_rate : The target frame rate
104 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
105 virtual int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate);
108 // Call encoder initialize function and set control settings.
109 int InitAndSetControlSettings(const VideoCodec* inst);
111 // Update frame size for codec.
112 int UpdateCodecFrameSize(const I420VideoFrame& input_image);
114 void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
115 const vpx_codec_cx_pkt& pkt,
118 int GetEncodedPartitions(const I420VideoFrame& input_image);
120 // Determine maximum target for Intra frames
123 // - optimal_buffer_size : Optimal buffer size
124 // Return Value : Max target size for Intra frames represented as
125 // percentage of the per frame bandwidth
126 uint32_t MaxIntraTarget(uint32_t optimal_buffer_size);
128 EncodedImage encoded_image_;
129 EncodedImageCallback* encoded_complete_callback_;
133 uint16_t picture_id_;
136 uint32_t rc_max_intra_target_;
137 int token_partitions_;
138 ReferencePictureSelection* rps_;
139 TemporalLayers* temporal_layers_;
140 vpx_codec_ctx_t* encoder_;
141 vpx_codec_enc_cfg_t* config_;
143 QualityScaler quality_scaler_;
144 }; // end of VP8Encoder class
147 class VP8DecoderImpl : public VP8Decoder {
151 virtual ~VP8DecoderImpl();
153 // Initialize the decoder.
155 // Return value : WEBRTC_VIDEO_CODEC_OK.
157 // WEBRTC_VIDEO_CODEC_ERROR
158 virtual int InitDecode(const VideoCodec* inst, int number_of_cores);
160 // Decode encoded image (as a part of a video stream). The decoded image
161 // will be returned to the user through the decode complete callback.
164 // - input_image : Encoded image to be decoded
165 // - missing_frames : True if one or more frames have been lost
166 // since the previous decode call.
167 // - fragmentation : Specifies the start and length of each VP8
169 // - codec_specific_info : pointer to specific codec data
170 // - render_time_ms : Render time in Ms
172 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
174 // WEBRTC_VIDEO_CODEC_ERROR
175 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
176 virtual int Decode(const EncodedImage& input_image,
178 const RTPFragmentationHeader* fragmentation,
179 const CodecSpecificInfo* codec_specific_info,
180 int64_t /*render_time_ms*/);
182 // Register a decode complete callback object.
185 // - callback : Callback object which handles decoded images.
187 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
188 virtual int RegisterDecodeCompleteCallback(DecodedImageCallback* callback);
190 // Free decoder memory.
192 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
194 // WEBRTC_VIDEO_CODEC_ERROR
195 virtual int Release();
197 // Reset decoder state and prepare for a new call.
199 // Return value : WEBRTC_VIDEO_CODEC_OK.
201 // WEBRTC_VIDEO_CODEC_UNINITIALIZED
202 // WEBRTC_VIDEO_CODEC_ERROR
205 // Create a copy of the codec and its internal state.
207 // Return value : A copy of the instance if OK, NULL otherwise.
208 virtual VideoDecoder* Copy();
211 // Copy reference image from this _decoder to the _decoder in copyTo. Set
212 // which frame type to copy in _refFrame->frame_type before the call to
214 int CopyReference(VP8Decoder* copy);
216 int DecodePartitions(const EncodedImage& input_image,
217 const RTPFragmentationHeader* fragmentation);
219 int ReturnFrame(const vpx_image_t* img,
221 int64_t ntp_time_ms);
223 I420VideoFrame decoded_image_;
224 DecodedImageCallback* decode_complete_callback_;
227 vpx_dec_ctx_t* decoder_;
229 EncodedImage last_keyframe_;
231 vpx_ref_frame_t* ref_frame_;
232 int propagation_cnt_;
234 bool key_frame_required_;
235 }; // end of VP8Decoder class
236 } // namespace webrtc
238 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_IMPL_H_