|
808
|
1 /*
|
|
|
2 * utils for libavcodec
|
|
|
3 * Copyright (c) 2001 Fabrice Bellard.
|
|
815
|
4 * Copyright (c) 2003 Michel Bardiaux for the av_log API
|
|
808
|
5 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
|
815
|
6 * Copyright (c) 2004 Roman Bogorodskiy (bmp-wma specific stuff)
|
|
808
|
7 *
|
|
815
|
8 * This library is free software; you can redistribute it and/or
|
|
808
|
9 * modify it under the terms of the GNU Lesser General Public
|
|
|
10 * License as published by the Free Software Foundation; either
|
|
815
|
11 * version 2 of the License, or (at your option) any later version.
|
|
808
|
12 *
|
|
815
|
13 * This library is distributed in the hope that it will be useful,
|
|
808
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
16 * Lesser General Public License for more details.
|
|
|
17 *
|
|
|
18 * You should have received a copy of the GNU Lesser General Public
|
|
815
|
19 * License along with this library; if not, write to the Free Software
|
|
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
808
|
21 */
|
|
815
|
22
|
|
808
|
23 #include "avcodec.h"
|
|
|
24 #include "dsputil.h"
|
|
|
25 #include <stdarg.h>
|
|
|
26
|
|
|
27 /* encoder management */
|
|
815
|
28 AVCodec *first_avcodec;
|
|
808
|
29
|
|
|
30 void register_avcodec(AVCodec *format)
|
|
|
31 {
|
|
|
32 AVCodec **p;
|
|
|
33 p = &first_avcodec;
|
|
|
34 while (*p != NULL) p = &(*p)->next;
|
|
|
35 *p = format;
|
|
|
36 format->next = NULL;
|
|
|
37 }
|
|
|
38
|
|
|
39 typedef struct InternalBuffer{
|
|
|
40 int last_pic_num;
|
|
|
41 uint8_t *base[4];
|
|
|
42 uint8_t *data[4];
|
|
|
43 int linesize[4];
|
|
|
44 }InternalBuffer;
|
|
|
45
|
|
818
|
46 const uint8_t ff_reverse[256]={
|
|
|
47 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
|
|
|
48 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
|
|
|
49 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
|
|
|
50 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
|
|
|
51 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
|
|
|
52 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
|
|
|
53 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
|
|
|
54 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
|
|
|
55 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
|
|
|
56 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
|
|
|
57 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
|
|
|
58 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
|
|
|
59 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
|
|
|
60 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
|
|
|
61 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
|
|
|
62 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
|
|
|
63 };
|
|
|
64
|
|
820
|
65 int av_get_bits_per_sample(enum CodecID codec_id){
|
|
|
66 switch(codec_id){
|
|
|
67 case CODEC_ID_ADPCM_SBPRO_2:
|
|
|
68 return 2;
|
|
|
69 case CODEC_ID_ADPCM_SBPRO_3:
|
|
|
70 return 3;
|
|
|
71 case CODEC_ID_ADPCM_SBPRO_4:
|
|
|
72 case CODEC_ID_ADPCM_CT:
|
|
|
73 return 4;
|
|
|
74 case CODEC_ID_PCM_ALAW:
|
|
|
75 case CODEC_ID_PCM_MULAW:
|
|
|
76 case CODEC_ID_PCM_S8:
|
|
|
77 case CODEC_ID_PCM_U8:
|
|
|
78 return 8;
|
|
|
79 case CODEC_ID_PCM_S16BE:
|
|
|
80 case CODEC_ID_PCM_S16LE:
|
|
|
81 case CODEC_ID_PCM_U16BE:
|
|
|
82 case CODEC_ID_PCM_U16LE:
|
|
|
83 return 16;
|
|
|
84 case CODEC_ID_PCM_S24DAUD:
|
|
|
85 case CODEC_ID_PCM_S24BE:
|
|
|
86 case CODEC_ID_PCM_S24LE:
|
|
|
87 case CODEC_ID_PCM_U24BE:
|
|
|
88 case CODEC_ID_PCM_U24LE:
|
|
|
89 return 24;
|
|
|
90 case CODEC_ID_PCM_S32BE:
|
|
|
91 case CODEC_ID_PCM_S32LE:
|
|
|
92 case CODEC_ID_PCM_U32BE:
|
|
|
93 case CODEC_ID_PCM_U32LE:
|
|
|
94 return 32;
|
|
|
95 default:
|
|
|
96 return 0;
|
|
|
97 }
|
|
|
98 }
|
|
|
99
|
|
|
100 /**
|
|
|
101 * decode a frame.
|
|
|
102 * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
|
|
|
103 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
|
|
|
104 * @param buf_size the size of the buffer in bytes
|
|
|
105 * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
|
|
|
106 * @return -1 if error, otherwise return the number of
|
|
|
107 * bytes used.
|
|
|
108 */
|
|
|
109 int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
|
|
|
110 int *got_picture_ptr,
|
|
|
111 uint8_t *buf, int buf_size)
|
|
|
112 {
|
|
|
113 int ret;
|
|
|
114
|
|
|
115 *got_picture_ptr= 0;
|
|
|
116 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
|
|
|
117 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
|
|
|
118 buf, buf_size);
|
|
|
119
|
|
|
120 emms_c(); //needed to avoid an emms_c() call before every return;
|
|
|
121
|
|
|
122 if (*got_picture_ptr)
|
|
|
123 avctx->frame_number++;
|
|
|
124 }else
|
|
|
125 ret= 0;
|
|
|
126
|
|
|
127 return ret;
|
|
|
128 }
|
|
|
129
|
|
|
130 /* decode an audio frame. return -1 if error, otherwise return the
|
|
|
131 *number of bytes used. If no frame could be decompressed,
|
|
|
132 *frame_size_ptr is zero. Otherwise, it is the decompressed frame
|
|
|
133 *size in BYTES. */
|
|
|
134 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
|
|
|
135 int *frame_size_ptr,
|
|
|
136 uint8_t *buf, int buf_size)
|
|
|
137 {
|
|
|
138 int ret;
|
|
|
139
|
|
|
140 *frame_size_ptr= 0;
|
|
|
141 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
|
|
|
142 ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
|
|
|
143 buf, buf_size);
|
|
|
144 avctx->frame_number++;
|
|
|
145 }else
|
|
|
146 ret= 0;
|
|
|
147 return ret;
|
|
|
148 }
|
|
|
149
|
|
|
150 /* decode a subtitle message. return -1 if error, otherwise return the
|
|
|
151 *number of bytes used. If no subtitle could be decompressed,
|
|
|
152 *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
|
|
|
153 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
|
|
|
154 int *got_sub_ptr,
|
|
|
155 const uint8_t *buf, int buf_size)
|
|
|
156 {
|
|
|
157 int ret;
|
|
|
158
|
|
|
159 *got_sub_ptr = 0;
|
|
|
160 ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
|
|
|
161 (uint8_t *)buf, buf_size);
|
|
|
162 if (*got_sub_ptr)
|
|
|
163 avctx->frame_number++;
|
|
|
164 return ret;
|
|
|
165 }
|
|
818
|
166
|
|
808
|
167 #define INTERNAL_BUFFER_SIZE 32
|
|
|
168
|
|
815
|
169 #undef ALIGN
|
|
808
|
170 #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
|
|
|
171
|
|
|
172 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
|
|
815
|
173 int w_align= 1;
|
|
|
174 int h_align= 1;
|
|
|
175
|
|
808
|
176 switch(s->pix_fmt){
|
|
|
177 case PIX_FMT_YUV420P:
|
|
|
178 case PIX_FMT_YUV422:
|
|
|
179 case PIX_FMT_YUV422P:
|
|
|
180 case PIX_FMT_YUV444P:
|
|
|
181 case PIX_FMT_GRAY8:
|
|
|
182 case PIX_FMT_YUVJ420P:
|
|
|
183 case PIX_FMT_YUVJ422P:
|
|
|
184 case PIX_FMT_YUVJ444P:
|
|
|
185 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
|
|
|
186 h_align= 16;
|
|
|
187 break;
|
|
|
188 case PIX_FMT_YUV411P:
|
|
|
189 w_align=32;
|
|
|
190 h_align=8;
|
|
|
191 break;
|
|
|
192 case PIX_FMT_YUV410P:
|
|
|
193 default:
|
|
|
194 w_align= 1;
|
|
|
195 h_align= 1;
|
|
|
196 break;
|
|
|
197 }
|
|
|
198
|
|
|
199 *width = ALIGN(*width , w_align);
|
|
|
200 *height= ALIGN(*height, h_align);
|
|
|
201 }
|
|
|
202
|
|
818
|
203 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
|
|
|
204 return fmt[0];
|
|
|
205 }
|
|
|
206
|
|
808
|
207 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
|
|
|
208 int i;
|
|
|
209 InternalBuffer *buf, *last, temp;
|
|
|
210
|
|
|
211 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
|
|
|
212 assert(s->internal_buffer_count);
|
|
|
213
|
|
|
214 buf = NULL; /* avoids warning */
|
|
|
215 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
|
|
|
216 buf= &((InternalBuffer*)s->internal_buffer)[i];
|
|
|
217 if(buf->data[0] == pic->data[0])
|
|
|
218 break;
|
|
|
219 }
|
|
|
220 assert(i < s->internal_buffer_count);
|
|
|
221 s->internal_buffer_count--;
|
|
|
222 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
|
|
|
223
|
|
|
224 temp= *buf;
|
|
|
225 *buf= *last;
|
|
|
226 *last= temp;
|
|
|
227
|
|
|
228 for(i=0; i<3; i++){
|
|
|
229 pic->data[i]=NULL;
|
|
|
230 // pic->base[i]=NULL;
|
|
|
231 }
|
|
|
232 }
|
|
|
233
|
|
|
234
|
|
|
235 void avcodec_get_context_defaults(AVCodecContext *s){
|
|
815
|
236 s->bit_rate= 800*1000;
|
|
|
237 s->bit_rate_tolerance= s->bit_rate*10;
|
|
|
238 s->qmin= 2;
|
|
|
239 s->qmax= 31;
|
|
|
240 s->mb_qmin= 2;
|
|
|
241 s->mb_qmax= 31;
|
|
808
|
242 s->rc_eq= "tex^qComp";
|
|
815
|
243 s->qcompress= 0.5;
|
|
|
244 s->max_qdiff= 3;
|
|
|
245 s->b_quant_factor=1.25;
|
|
|
246 s->b_quant_offset=1.25;
|
|
|
247 s->i_quant_factor=-0.8;
|
|
|
248 s->i_quant_offset=0.0;
|
|
|
249 s->error_concealment= 3;
|
|
|
250 s->error_resilience= 1;
|
|
|
251 s->workaround_bugs= FF_BUG_AUTODETECT;
|
|
|
252 s->gop_size= 50;
|
|
|
253 s->me_method= ME_EPZS;
|
|
|
254 //s->get_buffer= avcodec_default_get_buffer;
|
|
808
|
255 s->release_buffer= avcodec_default_release_buffer;
|
|
|
256 s->get_format= avcodec_default_get_format;
|
|
815
|
257 s->me_subpel_quality=8;
|
|
|
258 s->lmin= FF_QP2LAMBDA * s->qmin;
|
|
|
259 s->lmax= FF_QP2LAMBDA * s->qmax;
|
|
|
260 //s->sample_aspect_ratio= (AVRational){0,1};
|
|
|
261 s->ildct_cmp= FF_CMP_VSAD;
|
|
|
262
|
|
|
263 s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
|
|
|
264 s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
|
|
808
|
265 s->palctrl = NULL;
|
|
815
|
266 //s->reget_buffer= avcodec_default_reget_buffer;
|
|
808
|
267 }
|
|
|
268
|
|
|
269 /**
|
|
|
270 * allocates a AVCodecContext and set it to defaults.
|
|
815
|
271 * this can be deallocated by simply calling free()
|
|
808
|
272 */
|
|
|
273 AVCodecContext *avcodec_alloc_context(void){
|
|
815
|
274 AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext));
|
|
|
275
|
|
808
|
276 if(avctx==NULL) return NULL;
|
|
815
|
277
|
|
808
|
278 avcodec_get_context_defaults(avctx);
|
|
815
|
279
|
|
808
|
280 return avctx;
|
|
|
281 }
|
|
|
282
|
|
|
283 /**
|
|
|
284 * allocates a AVPFrame and set it to defaults.
|
|
815
|
285 * this can be deallocated by simply calling free()
|
|
808
|
286 */
|
|
|
287 AVFrame *avcodec_alloc_frame(void){
|
|
815
|
288 AVFrame *pic= av_mallocz(sizeof(AVFrame));
|
|
|
289
|
|
808
|
290 return pic;
|
|
|
291 }
|
|
|
292
|
|
|
293 int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
|
|
|
294 {
|
|
815
|
295 int ret;
|
|
808
|
296
|
|
|
297 if(avctx->codec)
|
|
815
|
298 return -1;
|
|
808
|
299
|
|
|
300 avctx->codec = codec;
|
|
|
301 avctx->codec_id = codec->id;
|
|
|
302 avctx->frame_number = 0;
|
|
815
|
303 if (codec->priv_data_size > 0) {
|
|
|
304 avctx->priv_data = av_mallocz(codec->priv_data_size);
|
|
|
305 if (!avctx->priv_data)
|
|
|
306 return -ENOMEM;
|
|
|
307 } else {
|
|
|
308 avctx->priv_data = NULL;
|
|
|
309 }
|
|
808
|
310 ret = avctx->codec->init(avctx);
|
|
|
311 if (ret < 0) {
|
|
|
312 av_freep(&avctx->priv_data);
|
|
815
|
313 return ret;
|
|
808
|
314 }
|
|
815
|
315 return 0;
|
|
808
|
316 }
|
|
|
317
|
|
815
|
318 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
|
|
|
319 const short *samples)
|
|
808
|
320 {
|
|
|
321 int ret;
|
|
|
322
|
|
815
|
323 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
|
|
|
324 avctx->frame_number++;
|
|
808
|
325 return ret;
|
|
|
326 }
|
|
|
327
|
|
|
328 int avcodec_close(AVCodecContext *avctx)
|
|
|
329 {
|
|
|
330 if (avctx->codec->close)
|
|
|
331 avctx->codec->close(avctx);
|
|
|
332 av_freep(&avctx->priv_data);
|
|
|
333 avctx->codec = NULL;
|
|
|
334 return 0;
|
|
|
335 }
|
|
|
336
|
|
|
337 AVCodec *avcodec_find_encoder(enum CodecID id)
|
|
|
338 {
|
|
|
339 AVCodec *p;
|
|
|
340 p = first_avcodec;
|
|
|
341 while (p) {
|
|
815
|
342 if (p->encode != NULL && (enum CodecID)p->id == id)
|
|
808
|
343 return p;
|
|
|
344 p = p->next;
|
|
|
345 }
|
|
|
346 return NULL;
|
|
|
347 }
|
|
|
348
|
|
|
349 AVCodec *avcodec_find_encoder_by_name(const char *name)
|
|
|
350 {
|
|
|
351 AVCodec *p;
|
|
|
352 p = first_avcodec;
|
|
|
353 while (p) {
|
|
|
354 if (p->encode != NULL && strcmp(name,p->name) == 0)
|
|
|
355 return p;
|
|
|
356 p = p->next;
|
|
|
357 }
|
|
|
358 return NULL;
|
|
|
359 }
|
|
|
360
|
|
|
361 AVCodec *avcodec_find_decoder(enum CodecID id)
|
|
|
362 {
|
|
|
363 AVCodec *p;
|
|
|
364 p = first_avcodec;
|
|
|
365 while (p) {
|
|
815
|
366 if (p->decode != NULL && (enum CodecID)p->id == id)
|
|
808
|
367 return p;
|
|
|
368 p = p->next;
|
|
|
369 }
|
|
|
370 return NULL;
|
|
|
371 }
|
|
|
372
|
|
|
373 AVCodec *avcodec_find_decoder_by_name(const char *name)
|
|
|
374 {
|
|
|
375 AVCodec *p;
|
|
|
376 p = first_avcodec;
|
|
|
377 while (p) {
|
|
|
378 if (p->decode != NULL && strcmp(name,p->name) == 0)
|
|
|
379 return p;
|
|
|
380 p = p->next;
|
|
|
381 }
|
|
|
382 return NULL;
|
|
|
383 }
|
|
|
384
|
|
815
|
385 AVCodec *avcodec_find(enum CodecID id)
|
|
|
386 {
|
|
|
387 AVCodec *p;
|
|
|
388 p = first_avcodec;
|
|
|
389 while (p) {
|
|
|
390 if ((enum CodecID)p->id == id)
|
|
|
391 return p;
|
|
|
392 p = p->next;
|
|
|
393 }
|
|
|
394 return NULL;
|
|
|
395 }
|
|
|
396
|
|
808
|
397 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
|
|
|
398 {
|
|
|
399 const char *codec_name;
|
|
|
400 AVCodec *p;
|
|
|
401 char buf1[32];
|
|
|
402 char channels_str[100];
|
|
|
403 int bitrate;
|
|
|
404
|
|
|
405 if (encode)
|
|
|
406 p = avcodec_find_encoder(enc->codec_id);
|
|
|
407 else
|
|
|
408 p = avcodec_find_decoder(enc->codec_id);
|
|
|
409
|
|
|
410 if (p) {
|
|
|
411 codec_name = p->name;
|
|
|
412 } else if (enc->codec_name[0] != '\0') {
|
|
|
413 codec_name = enc->codec_name;
|
|
|
414 } else {
|
|
|
415 /* output avi tags */
|
|
815
|
416 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
|
|
808
|
417 codec_name = buf1;
|
|
|
418 }
|
|
|
419
|
|
|
420 switch(enc->codec_type) {
|
|
|
421 case CODEC_TYPE_AUDIO:
|
|
|
422 snprintf(buf, buf_size,
|
|
|
423 "Audio: %s",
|
|
|
424 codec_name);
|
|
|
425 switch (enc->channels) {
|
|
|
426 case 1:
|
|
|
427 strcpy(channels_str, "mono");
|
|
|
428 break;
|
|
|
429 case 2:
|
|
|
430 strcpy(channels_str, "stereo");
|
|
|
431 break;
|
|
|
432 case 6:
|
|
|
433 strcpy(channels_str, "5:1");
|
|
|
434 break;
|
|
|
435 default:
|
|
818
|
436 snprintf(channels_str, 100, "%d channels", enc->channels);
|
|
808
|
437 break;
|
|
|
438 }
|
|
|
439 if (enc->sample_rate) {
|
|
|
440 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
|
441 ", %d Hz, %s",
|
|
|
442 enc->sample_rate,
|
|
|
443 channels_str);
|
|
|
444 }
|
|
815
|
445
|
|
808
|
446 /* for PCM codecs, compute bitrate directly */
|
|
|
447 switch(enc->codec_id) {
|
|
|
448 case CODEC_ID_PCM_S16LE:
|
|
|
449 case CODEC_ID_PCM_S16BE:
|
|
|
450 case CODEC_ID_PCM_U16LE:
|
|
|
451 case CODEC_ID_PCM_U16BE:
|
|
|
452 bitrate = enc->sample_rate * enc->channels * 16;
|
|
|
453 break;
|
|
|
454 case CODEC_ID_PCM_S8:
|
|
|
455 case CODEC_ID_PCM_U8:
|
|
|
456 case CODEC_ID_PCM_ALAW:
|
|
|
457 case CODEC_ID_PCM_MULAW:
|
|
|
458 bitrate = enc->sample_rate * enc->channels * 8;
|
|
|
459 break;
|
|
|
460 default:
|
|
|
461 bitrate = enc->bit_rate;
|
|
|
462 break;
|
|
|
463 }
|
|
|
464 break;
|
|
|
465 case CODEC_TYPE_DATA:
|
|
|
466 snprintf(buf, buf_size, "Data: %s", codec_name);
|
|
|
467 bitrate = enc->bit_rate;
|
|
|
468 break;
|
|
|
469 default:
|
|
815
|
470 av_abort();
|
|
808
|
471 }
|
|
|
472 if (encode) {
|
|
|
473 if (enc->flags & CODEC_FLAG_PASS1)
|
|
|
474 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
|
475 ", pass 1");
|
|
|
476 if (enc->flags & CODEC_FLAG_PASS2)
|
|
|
477 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
|
478 ", pass 2");
|
|
|
479 }
|
|
|
480 if (bitrate != 0) {
|
|
815
|
481 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
808
|
482 ", %d kb/s", bitrate / 1000);
|
|
|
483 }
|
|
|
484 }
|
|
|
485
|
|
|
486 unsigned avcodec_version( void )
|
|
|
487 {
|
|
|
488 return LIBAVCODEC_VERSION_INT;
|
|
|
489 }
|
|
|
490
|
|
|
491 unsigned avcodec_build( void )
|
|
|
492 {
|
|
|
493 return LIBAVCODEC_BUILD;
|
|
|
494 }
|
|
|
495
|
|
|
496 /* must be called before any other functions */
|
|
|
497 void avcodec_init(void)
|
|
|
498 {
|
|
|
499 static int inited = 0;
|
|
|
500
|
|
|
501 if (inited != 0)
|
|
815
|
502 return;
|
|
808
|
503 inited = 1;
|
|
|
504
|
|
|
505 dsputil_static_init();
|
|
|
506 }
|
|
|
507
|
|
|
508 /**
|
|
|
509 * Flush buffers, should be called when seeking or when swicthing to a different stream.
|
|
|
510 */
|
|
|
511 void avcodec_flush_buffers(AVCodecContext *avctx)
|
|
|
512 {
|
|
|
513 if(avctx->codec->flush)
|
|
|
514 avctx->codec->flush(avctx);
|
|
|
515 }
|
|
|
516
|
|
|
517 void avcodec_default_free_buffers(AVCodecContext *s){
|
|
|
518 int i, j;
|
|
|
519
|
|
|
520 if(s->internal_buffer==NULL) return;
|
|
815
|
521
|
|
808
|
522 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
|
|
|
523 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
|
|
|
524 for(j=0; j<4; j++){
|
|
|
525 av_freep(&buf->base[j]);
|
|
|
526 buf->data[j]= NULL;
|
|
|
527 }
|
|
|
528 }
|
|
|
529 av_freep(&s->internal_buffer);
|
|
815
|
530
|
|
808
|
531 s->internal_buffer_count=0;
|
|
|
532 }
|
|
815
|
533 #if 0
|
|
808
|
534 char av_get_pict_type_char(int pict_type){
|
|
|
535 switch(pict_type){
|
|
815
|
536 case I_TYPE: return 'I';
|
|
|
537 case P_TYPE: return 'P';
|
|
|
538 case B_TYPE: return 'B';
|
|
|
539 case S_TYPE: return 'S';
|
|
|
540 case SI_TYPE:return 'i';
|
|
|
541 case SP_TYPE:return 'p';
|
|
808
|
542 default: return '?';
|
|
|
543 }
|
|
|
544 }
|
|
|
545
|
|
815
|
546 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
|
|
547 int exact=1, sign=0;
|
|
|
548 int64_t gcd;
|
|
|
549
|
|
|
550 assert(den != 0);
|
|
|
551
|
|
|
552 if(den < 0){
|
|
|
553 den= -den;
|
|
|
554 nom= -nom;
|
|
|
555 }
|
|
|
556
|
|
|
557 if(nom < 0){
|
|
|
558 nom= -nom;
|
|
|
559 sign= 1;
|
|
808
|
560 }
|
|
815
|
561
|
|
|
562 gcd = ff_gcd(nom, den);
|
|
|
563 nom /= gcd;
|
|
|
564 den /= gcd;
|
|
|
565
|
|
|
566 if(nom > max || den > max){
|
|
|
567 AVRational a0={0,1}, a1={1,0};
|
|
|
568 exact=0;
|
|
|
569
|
|
|
570 for(;;){
|
|
|
571 int64_t x= nom / den;
|
|
|
572 int64_t a2n= x*a1.num + a0.num;
|
|
|
573 int64_t a2d= x*a1.den + a0.den;
|
|
|
574
|
|
|
575 if(a2n > max || a2d > max) break;
|
|
|
576
|
|
|
577 nom %= den;
|
|
|
578
|
|
|
579 a0= a1;
|
|
|
580 a1= (AVRational){a2n, a2d};
|
|
|
581 if(nom==0) break;
|
|
|
582 x= nom; nom=den; den=x;
|
|
|
583 }
|
|
|
584 nom= a1.num;
|
|
|
585 den= a1.den;
|
|
|
586 }
|
|
|
587
|
|
|
588 assert(ff_gcd(nom, den) == 1);
|
|
|
589
|
|
|
590 if(sign) nom= -nom;
|
|
|
591
|
|
|
592 *dst_nom = nom;
|
|
|
593 *dst_den = den;
|
|
|
594
|
|
|
595 return exact;
|
|
|
596 }
|
|
|
597 #endif
|