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->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
|
|
117 return -1;
|
|
118 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
|
|
119 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
|
|
120 buf, buf_size);
|
|
121
|
|
122 emms_c(); //needed to avoid an emms_c() call before every return;
|
|
123
|
|
124 if (*got_picture_ptr)
|
|
125 avctx->frame_number++;
|
|
126 }else
|
|
127 ret= 0;
|
|
128
|
|
129 return ret;
|
|
130 }
|
|
131
|
|
132 /* decode an audio frame. return -1 if error, otherwise return the
|
|
133 *number of bytes used. If no frame could be decompressed,
|
|
134 *frame_size_ptr is zero. Otherwise, it is the decompressed frame
|
|
135 *size in BYTES. */
|
|
136 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
|
|
137 int *frame_size_ptr,
|
|
138 uint8_t *buf, int buf_size)
|
|
139 {
|
|
140 int ret;
|
|
141
|
|
142 *frame_size_ptr= 0;
|
|
143 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
|
|
144 ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
|
|
145 buf, buf_size);
|
|
146 avctx->frame_number++;
|
|
147 }else
|
|
148 ret= 0;
|
|
149 return ret;
|
|
150 }
|
|
151
|
|
152 /* decode a subtitle message. return -1 if error, otherwise return the
|
|
153 *number of bytes used. If no subtitle could be decompressed,
|
|
154 *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
|
|
155 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
|
|
156 int *got_sub_ptr,
|
|
157 const uint8_t *buf, int buf_size)
|
|
158 {
|
|
159 int ret;
|
|
160
|
|
161 *got_sub_ptr = 0;
|
|
162 ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
|
|
163 (uint8_t *)buf, buf_size);
|
|
164 if (*got_sub_ptr)
|
|
165 avctx->frame_number++;
|
|
166 return ret;
|
|
167 }
|
818
|
168
|
808
|
169 #define INTERNAL_BUFFER_SIZE 32
|
|
170
|
815
|
171 #undef ALIGN
|
808
|
172 #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
|
|
173
|
|
174 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
|
815
|
175 int w_align= 1;
|
|
176 int h_align= 1;
|
|
177
|
808
|
178 switch(s->pix_fmt){
|
|
179 case PIX_FMT_YUV420P:
|
|
180 case PIX_FMT_YUV422:
|
|
181 case PIX_FMT_YUV422P:
|
|
182 case PIX_FMT_YUV444P:
|
|
183 case PIX_FMT_GRAY8:
|
|
184 case PIX_FMT_YUVJ420P:
|
|
185 case PIX_FMT_YUVJ422P:
|
|
186 case PIX_FMT_YUVJ444P:
|
|
187 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
|
|
188 h_align= 16;
|
|
189 break;
|
|
190 case PIX_FMT_YUV411P:
|
|
191 w_align=32;
|
|
192 h_align=8;
|
|
193 break;
|
|
194 case PIX_FMT_YUV410P:
|
|
195 default:
|
|
196 w_align= 1;
|
|
197 h_align= 1;
|
|
198 break;
|
|
199 }
|
|
200
|
|
201 *width = ALIGN(*width , w_align);
|
|
202 *height= ALIGN(*height, h_align);
|
|
203 }
|
|
204
|
818
|
205 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
|
|
206 return fmt[0];
|
|
207 }
|
|
208
|
808
|
209 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
|
|
210 int i;
|
|
211 InternalBuffer *buf, *last, temp;
|
|
212
|
|
213 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
|
|
214 assert(s->internal_buffer_count);
|
|
215
|
|
216 buf = NULL; /* avoids warning */
|
|
217 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
|
|
218 buf= &((InternalBuffer*)s->internal_buffer)[i];
|
|
219 if(buf->data[0] == pic->data[0])
|
|
220 break;
|
|
221 }
|
|
222 assert(i < s->internal_buffer_count);
|
|
223 s->internal_buffer_count--;
|
|
224 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
|
|
225
|
|
226 temp= *buf;
|
|
227 *buf= *last;
|
|
228 *last= temp;
|
|
229
|
|
230 for(i=0; i<3; i++){
|
|
231 pic->data[i]=NULL;
|
|
232 // pic->base[i]=NULL;
|
|
233 }
|
|
234 }
|
|
235
|
|
236
|
|
237 void avcodec_get_context_defaults(AVCodecContext *s){
|
815
|
238 s->bit_rate= 800*1000;
|
|
239 s->bit_rate_tolerance= s->bit_rate*10;
|
|
240 s->qmin= 2;
|
|
241 s->qmax= 31;
|
|
242 s->mb_qmin= 2;
|
|
243 s->mb_qmax= 31;
|
808
|
244 s->rc_eq= "tex^qComp";
|
815
|
245 s->qcompress= 0.5;
|
|
246 s->max_qdiff= 3;
|
|
247 s->b_quant_factor=1.25;
|
|
248 s->b_quant_offset=1.25;
|
|
249 s->i_quant_factor=-0.8;
|
|
250 s->i_quant_offset=0.0;
|
|
251 s->error_concealment= 3;
|
|
252 s->error_resilience= 1;
|
|
253 s->workaround_bugs= FF_BUG_AUTODETECT;
|
|
254 s->gop_size= 50;
|
|
255 s->me_method= ME_EPZS;
|
|
256 //s->get_buffer= avcodec_default_get_buffer;
|
808
|
257 s->release_buffer= avcodec_default_release_buffer;
|
|
258 s->get_format= avcodec_default_get_format;
|
815
|
259 s->me_subpel_quality=8;
|
|
260 s->lmin= FF_QP2LAMBDA * s->qmin;
|
|
261 s->lmax= FF_QP2LAMBDA * s->qmax;
|
|
262 //s->sample_aspect_ratio= (AVRational){0,1};
|
|
263 s->ildct_cmp= FF_CMP_VSAD;
|
|
264
|
|
265 s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
|
|
266 s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
|
808
|
267 s->palctrl = NULL;
|
815
|
268 //s->reget_buffer= avcodec_default_reget_buffer;
|
808
|
269 }
|
|
270
|
|
271 /**
|
|
272 * allocates a AVCodecContext and set it to defaults.
|
815
|
273 * this can be deallocated by simply calling free()
|
808
|
274 */
|
|
275 AVCodecContext *avcodec_alloc_context(void){
|
815
|
276 AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext));
|
|
277
|
808
|
278 if(avctx==NULL) return NULL;
|
815
|
279
|
808
|
280 avcodec_get_context_defaults(avctx);
|
815
|
281
|
808
|
282 return avctx;
|
|
283 }
|
|
284
|
|
285 /**
|
|
286 * allocates a AVPFrame and set it to defaults.
|
815
|
287 * this can be deallocated by simply calling free()
|
808
|
288 */
|
|
289 AVFrame *avcodec_alloc_frame(void){
|
815
|
290 AVFrame *pic= av_mallocz(sizeof(AVFrame));
|
|
291
|
808
|
292 return pic;
|
|
293 }
|
|
294
|
|
295 int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
|
|
296 {
|
815
|
297 int ret;
|
808
|
298
|
|
299 if(avctx->codec)
|
815
|
300 return -1;
|
808
|
301
|
|
302 avctx->codec = codec;
|
|
303 avctx->codec_id = codec->id;
|
|
304 avctx->frame_number = 0;
|
815
|
305 if (codec->priv_data_size > 0) {
|
|
306 avctx->priv_data = av_mallocz(codec->priv_data_size);
|
|
307 if (!avctx->priv_data)
|
|
308 return -ENOMEM;
|
|
309 } else {
|
|
310 avctx->priv_data = NULL;
|
|
311 }
|
808
|
312 ret = avctx->codec->init(avctx);
|
|
313 if (ret < 0) {
|
|
314 av_freep(&avctx->priv_data);
|
815
|
315 return ret;
|
808
|
316 }
|
815
|
317 return 0;
|
808
|
318 }
|
|
319
|
815
|
320 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
|
|
321 const short *samples)
|
808
|
322 {
|
|
323 int ret;
|
|
324
|
815
|
325 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
|
|
326 avctx->frame_number++;
|
808
|
327 return ret;
|
|
328 }
|
|
329
|
|
330 int avcodec_close(AVCodecContext *avctx)
|
|
331 {
|
|
332 if (avctx->codec->close)
|
|
333 avctx->codec->close(avctx);
|
|
334 av_freep(&avctx->priv_data);
|
|
335 avctx->codec = NULL;
|
|
336 return 0;
|
|
337 }
|
|
338
|
|
339 AVCodec *avcodec_find_encoder(enum CodecID id)
|
|
340 {
|
|
341 AVCodec *p;
|
|
342 p = first_avcodec;
|
|
343 while (p) {
|
815
|
344 if (p->encode != NULL && (enum CodecID)p->id == id)
|
808
|
345 return p;
|
|
346 p = p->next;
|
|
347 }
|
|
348 return NULL;
|
|
349 }
|
|
350
|
|
351 AVCodec *avcodec_find_encoder_by_name(const char *name)
|
|
352 {
|
|
353 AVCodec *p;
|
|
354 p = first_avcodec;
|
|
355 while (p) {
|
|
356 if (p->encode != NULL && strcmp(name,p->name) == 0)
|
|
357 return p;
|
|
358 p = p->next;
|
|
359 }
|
|
360 return NULL;
|
|
361 }
|
|
362
|
|
363 AVCodec *avcodec_find_decoder(enum CodecID id)
|
|
364 {
|
|
365 AVCodec *p;
|
|
366 p = first_avcodec;
|
|
367 while (p) {
|
815
|
368 if (p->decode != NULL && (enum CodecID)p->id == id)
|
808
|
369 return p;
|
|
370 p = p->next;
|
|
371 }
|
|
372 return NULL;
|
|
373 }
|
|
374
|
|
375 AVCodec *avcodec_find_decoder_by_name(const char *name)
|
|
376 {
|
|
377 AVCodec *p;
|
|
378 p = first_avcodec;
|
|
379 while (p) {
|
|
380 if (p->decode != NULL && strcmp(name,p->name) == 0)
|
|
381 return p;
|
|
382 p = p->next;
|
|
383 }
|
|
384 return NULL;
|
|
385 }
|
|
386
|
815
|
387 AVCodec *avcodec_find(enum CodecID id)
|
|
388 {
|
|
389 AVCodec *p;
|
|
390 p = first_avcodec;
|
|
391 while (p) {
|
|
392 if ((enum CodecID)p->id == id)
|
|
393 return p;
|
|
394 p = p->next;
|
|
395 }
|
|
396 return NULL;
|
|
397 }
|
|
398
|
808
|
399 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
|
|
400 {
|
|
401 const char *codec_name;
|
|
402 AVCodec *p;
|
|
403 char buf1[32];
|
|
404 char channels_str[100];
|
|
405 int bitrate;
|
|
406
|
|
407 if (encode)
|
|
408 p = avcodec_find_encoder(enc->codec_id);
|
|
409 else
|
|
410 p = avcodec_find_decoder(enc->codec_id);
|
|
411
|
|
412 if (p) {
|
|
413 codec_name = p->name;
|
|
414 } else if (enc->codec_name[0] != '\0') {
|
|
415 codec_name = enc->codec_name;
|
|
416 } else {
|
|
417 /* output avi tags */
|
815
|
418 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
|
808
|
419 codec_name = buf1;
|
|
420 }
|
|
421
|
|
422 switch(enc->codec_type) {
|
|
423 case CODEC_TYPE_AUDIO:
|
|
424 snprintf(buf, buf_size,
|
|
425 "Audio: %s",
|
|
426 codec_name);
|
|
427 switch (enc->channels) {
|
|
428 case 1:
|
|
429 strcpy(channels_str, "mono");
|
|
430 break;
|
|
431 case 2:
|
|
432 strcpy(channels_str, "stereo");
|
|
433 break;
|
|
434 case 6:
|
|
435 strcpy(channels_str, "5:1");
|
|
436 break;
|
|
437 default:
|
818
|
438 snprintf(channels_str, 100, "%d channels", enc->channels);
|
808
|
439 break;
|
|
440 }
|
|
441 if (enc->sample_rate) {
|
|
442 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
443 ", %d Hz, %s",
|
|
444 enc->sample_rate,
|
|
445 channels_str);
|
|
446 }
|
815
|
447
|
808
|
448 /* for PCM codecs, compute bitrate directly */
|
|
449 switch(enc->codec_id) {
|
|
450 case CODEC_ID_PCM_S16LE:
|
|
451 case CODEC_ID_PCM_S16BE:
|
|
452 case CODEC_ID_PCM_U16LE:
|
|
453 case CODEC_ID_PCM_U16BE:
|
|
454 bitrate = enc->sample_rate * enc->channels * 16;
|
|
455 break;
|
|
456 case CODEC_ID_PCM_S8:
|
|
457 case CODEC_ID_PCM_U8:
|
|
458 case CODEC_ID_PCM_ALAW:
|
|
459 case CODEC_ID_PCM_MULAW:
|
|
460 bitrate = enc->sample_rate * enc->channels * 8;
|
|
461 break;
|
|
462 default:
|
|
463 bitrate = enc->bit_rate;
|
|
464 break;
|
|
465 }
|
|
466 break;
|
|
467 case CODEC_TYPE_DATA:
|
|
468 snprintf(buf, buf_size, "Data: %s", codec_name);
|
|
469 bitrate = enc->bit_rate;
|
|
470 break;
|
|
471 default:
|
815
|
472 av_abort();
|
808
|
473 }
|
|
474 if (encode) {
|
|
475 if (enc->flags & CODEC_FLAG_PASS1)
|
|
476 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
477 ", pass 1");
|
|
478 if (enc->flags & CODEC_FLAG_PASS2)
|
|
479 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
|
480 ", pass 2");
|
|
481 }
|
|
482 if (bitrate != 0) {
|
815
|
483 snprintf(buf + strlen(buf), buf_size - strlen(buf),
|
808
|
484 ", %d kb/s", bitrate / 1000);
|
|
485 }
|
|
486 }
|
|
487
|
|
488 unsigned avcodec_version( void )
|
|
489 {
|
|
490 return LIBAVCODEC_VERSION_INT;
|
|
491 }
|
|
492
|
|
493 unsigned avcodec_build( void )
|
|
494 {
|
|
495 return LIBAVCODEC_BUILD;
|
|
496 }
|
|
497
|
|
498 /* must be called before any other functions */
|
|
499 void avcodec_init(void)
|
|
500 {
|
|
501 static int inited = 0;
|
|
502
|
|
503 if (inited != 0)
|
815
|
504 return;
|
808
|
505 inited = 1;
|
|
506
|
|
507 dsputil_static_init();
|
|
508 }
|
|
509
|
|
510 /**
|
|
511 * Flush buffers, should be called when seeking or when swicthing to a different stream.
|
|
512 */
|
|
513 void avcodec_flush_buffers(AVCodecContext *avctx)
|
|
514 {
|
|
515 if(avctx->codec->flush)
|
|
516 avctx->codec->flush(avctx);
|
|
517 }
|
|
518
|
|
519 void avcodec_default_free_buffers(AVCodecContext *s){
|
|
520 int i, j;
|
|
521
|
|
522 if(s->internal_buffer==NULL) return;
|
815
|
523
|
808
|
524 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
|
|
525 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
|
|
526 for(j=0; j<4; j++){
|
|
527 av_freep(&buf->base[j]);
|
|
528 buf->data[j]= NULL;
|
|
529 }
|
|
530 }
|
|
531 av_freep(&s->internal_buffer);
|
815
|
532
|
808
|
533 s->internal_buffer_count=0;
|
|
534 }
|
815
|
535 #if 0
|
808
|
536 char av_get_pict_type_char(int pict_type){
|
|
537 switch(pict_type){
|
815
|
538 case I_TYPE: return 'I';
|
|
539 case P_TYPE: return 'P';
|
|
540 case B_TYPE: return 'B';
|
|
541 case S_TYPE: return 'S';
|
|
542 case SI_TYPE:return 'i';
|
|
543 case SP_TYPE:return 'p';
|
808
|
544 default: return '?';
|
|
545 }
|
|
546 }
|
|
547
|
815
|
548 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
|
549 int exact=1, sign=0;
|
|
550 int64_t gcd;
|
|
551
|
|
552 assert(den != 0);
|
|
553
|
|
554 if(den < 0){
|
|
555 den= -den;
|
|
556 nom= -nom;
|
|
557 }
|
|
558
|
|
559 if(nom < 0){
|
|
560 nom= -nom;
|
|
561 sign= 1;
|
808
|
562 }
|
815
|
563
|
|
564 gcd = ff_gcd(nom, den);
|
|
565 nom /= gcd;
|
|
566 den /= gcd;
|
|
567
|
|
568 if(nom > max || den > max){
|
|
569 AVRational a0={0,1}, a1={1,0};
|
|
570 exact=0;
|
|
571
|
|
572 for(;;){
|
|
573 int64_t x= nom / den;
|
|
574 int64_t a2n= x*a1.num + a0.num;
|
|
575 int64_t a2d= x*a1.den + a0.den;
|
|
576
|
|
577 if(a2n > max || a2d > max) break;
|
|
578
|
|
579 nom %= den;
|
|
580
|
|
581 a0= a1;
|
|
582 a1= (AVRational){a2n, a2d};
|
|
583 if(nom==0) break;
|
|
584 x= nom; nom=den; den=x;
|
|
585 }
|
|
586 nom= a1.num;
|
|
587 den= a1.den;
|
|
588 }
|
|
589
|
|
590 assert(ff_gcd(nom, den) == 1);
|
|
591
|
|
592 if(sign) nom= -nom;
|
|
593
|
|
594 *dst_nom = nom;
|
|
595 *dst_den = den;
|
|
596
|
|
597 return exact;
|
|
598 }
|
|
599 #endif
|