Mercurial > libavcodec.hg
annotate utils.c @ 1090:8216533dd959 libavcodec
10l
author | michaelni |
---|---|
date | Fri, 28 Feb 2003 16:06:40 +0000 |
parents | b32afefe7d33 |
children | 1e39f273ecd6 |
rev | line source |
---|---|
0 | 1 /* |
2 * utils for libavcodec | |
429 | 3 * Copyright (c) 2001 Fabrice Bellard. |
0 | 4 * |
429 | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
0 | 9 * |
429 | 10 * This library is distributed in the hope that it will be useful, |
0 | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Lesser General Public License for more details. | |
0 | 14 * |
429 | 15 * You should have received a copy of the GNU Lesser General Public |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
0 | 18 */ |
394 | 19 #include "avcodec.h" |
0 | 20 #include "dsputil.h" |
341 | 21 #include "mpegvideo.h" |
0 | 22 |
862 | 23 void *av_mallocz(unsigned int size) |
394 | 24 { |
25 void *ptr; | |
908 | 26 |
394 | 27 ptr = av_malloc(size); |
28 if (!ptr) | |
29 return NULL; | |
30 memset(ptr, 0, size); | |
31 return ptr; | |
32 } | |
33 | |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
34 char *av_strdup(const char *s) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
35 { |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
36 char *ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
37 int len; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
38 len = strlen(s) + 1; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
39 ptr = av_malloc(len); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
40 if (!ptr) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
41 return NULL; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
42 memcpy(ptr, s, len); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
43 return ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
44 } |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
45 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
46 /** |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
47 * realloc which does nothing if the block is large enough |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
48 */ |
1057 | 49 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
50 { |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
51 if(min_size < *size) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
52 return ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
53 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
54 *size= min_size + 10*1024; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
55 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
56 return av_realloc(ptr, *size); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
57 } |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
58 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
59 |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
60 /* allocation of static arrays - do not use for normal allocation */ |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
61 static unsigned int last_static = 0; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
62 static char*** array_static = NULL; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
63 static const unsigned int grow_static = 64; // ^2 |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
64 void *__av_mallocz_static(void** location, unsigned int size) |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
65 { |
1057 | 66 unsigned int l = (last_static + grow_static) & ~(grow_static - 1); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
67 void *ptr = av_mallocz(size); |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
68 if (!ptr) |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
69 return NULL; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
70 |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
71 if (location) |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
72 { |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
73 if (l > last_static) |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
74 array_static = av_realloc(array_static, l); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
75 array_static[last_static++] = (char**) location; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
76 *location = ptr; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
77 } |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
78 return ptr; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
79 } |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
80 /* free all static arrays and reset pointers to 0 */ |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
81 void av_free_static() |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
82 { |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
83 if (array_static) |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
84 { |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
85 unsigned i; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
86 for (i = 0; i < last_static; i++) |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
87 { |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
88 av_free(*array_static[i]); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
89 *array_static[i] = NULL; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
90 } |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
91 av_free(array_static); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
92 array_static = 0; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
93 } |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
94 last_static = 0; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
95 } |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
96 |
400 | 97 /* cannot call it directly because of 'void **' casting is not automatic */ |
98 void __av_freep(void **ptr) | |
99 { | |
100 av_free(*ptr); | |
101 *ptr = NULL; | |
102 } | |
103 | |
0 | 104 /* encoder management */ |
105 AVCodec *first_avcodec; | |
106 | |
107 void register_avcodec(AVCodec *format) | |
108 { | |
109 AVCodec **p; | |
110 p = &first_avcodec; | |
111 while (*p != NULL) p = &(*p)->next; | |
112 *p = format; | |
113 format->next = NULL; | |
114 } | |
115 | |
903 | 116 typedef struct DefaultPicOpaque{ |
117 int last_pic_num; | |
118 uint8_t *data[4]; | |
119 }DefaultPicOpaque; | |
120 | |
925 | 121 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
903 | 122 int i; |
123 const int width = s->width; | |
124 const int height= s->height; | |
125 DefaultPicOpaque *opaque; | |
924 | 126 |
127 assert(pic->data[0]==NULL); | |
128 assert(pic->type==0 || pic->type==FF_TYPE_INTERNAL); | |
903 | 129 |
130 if(pic->opaque){ | |
131 opaque= (DefaultPicOpaque *)pic->opaque; | |
132 for(i=0; i<3; i++) | |
133 pic->data[i]= opaque->data[i]; | |
134 | |
135 // printf("get_buffer %X coded_pic_num:%d last:%d\n", pic->opaque, pic->coded_picture_number, opaque->last_pic_num); | |
136 pic->age= pic->coded_picture_number - opaque->last_pic_num; | |
137 opaque->last_pic_num= pic->coded_picture_number; | |
138 //printf("age: %d %d %d\n", pic->age, c->picture_number, pic->coded_picture_number); | |
139 }else{ | |
140 int align, h_chroma_shift, v_chroma_shift; | |
141 int w, h, pixel_size; | |
142 | |
143 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
144 | |
145 switch(s->pix_fmt){ | |
146 case PIX_FMT_YUV422: | |
147 pixel_size=2; | |
148 break; | |
149 case PIX_FMT_RGB24: | |
150 case PIX_FMT_BGR24: | |
151 pixel_size=3; | |
152 break; | |
153 case PIX_FMT_RGBA32: | |
154 pixel_size=4; | |
155 break; | |
156 default: | |
157 pixel_size=1; | |
158 } | |
159 | |
160 if(s->codec_id==CODEC_ID_SVQ1) align=63; | |
161 else align=15; | |
162 | |
163 w= (width +align)&~align; | |
164 h= (height+align)&~align; | |
165 | |
166 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | |
167 w+= EDGE_WIDTH*2; | |
168 h+= EDGE_WIDTH*2; | |
169 } | |
170 | |
171 opaque= av_mallocz(sizeof(DefaultPicOpaque)); | |
172 if(opaque==NULL) return -1; | |
173 | |
174 pic->opaque= opaque; | |
175 opaque->last_pic_num= -256*256*256*64; | |
176 | |
177 for(i=0; i<3; i++){ | |
178 int h_shift= i==0 ? 0 : h_chroma_shift; | |
179 int v_shift= i==0 ? 0 : v_chroma_shift; | |
180 | |
181 pic->linesize[i]= pixel_size*w>>h_shift; | |
182 | |
183 pic->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 | |
184 if(pic->base[i]==NULL) return -1; | |
185 | |
186 memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift); | |
187 | |
188 if(s->flags&CODEC_FLAG_EMU_EDGE) | |
924 | 189 pic->data[i] = pic->base[i] + 16; //FIXME 16 |
903 | 190 else |
924 | 191 pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift) + 16; //FIXME 16 |
903 | 192 |
193 opaque->data[i]= pic->data[i]; | |
194 } | |
195 pic->age= 256*256*256*64; | |
924 | 196 pic->type= FF_BUFFER_TYPE_INTERNAL; |
903 | 197 } |
198 | |
199 return 0; | |
200 } | |
201 | |
925 | 202 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ |
903 | 203 int i; |
204 | |
924 | 205 assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |
206 | |
903 | 207 for(i=0; i<3; i++) |
208 pic->data[i]=NULL; | |
209 //printf("R%X\n", pic->opaque); | |
210 } | |
211 | |
998 | 212 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){ |
213 return fmt[0]; | |
214 } | |
215 | |
681 | 216 void avcodec_get_context_defaults(AVCodecContext *s){ |
685 | 217 s->bit_rate= 800*1000; |
218 s->bit_rate_tolerance= s->bit_rate*10; | |
681 | 219 s->qmin= 2; |
220 s->qmax= 31; | |
932 | 221 s->mb_qmin= 2; |
222 s->mb_qmax= 31; | |
681 | 223 s->rc_eq= "tex^qComp"; |
224 s->qcompress= 0.5; | |
685 | 225 s->max_qdiff= 3; |
226 s->b_quant_factor=1.25; | |
227 s->b_quant_offset=1.25; | |
686
83d2c9d50d7d
fixing i_quant_factor, this should finally fix the bitrate bug with ffserver hopefully
michaelni
parents:
685
diff
changeset
|
228 s->i_quant_factor=-0.8; |
685 | 229 s->i_quant_offset=0.0; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
230 s->error_concealment= 3; |
762 | 231 s->error_resilience= 1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
232 s->workaround_bugs= FF_BUG_AUTODETECT; |
762 | 233 s->frame_rate = 25 * FRAME_RATE_BASE; |
234 s->gop_size= 50; | |
235 s->me_method= ME_EPZS; | |
903 | 236 s->get_buffer= avcodec_default_get_buffer; |
237 s->release_buffer= avcodec_default_release_buffer; | |
998 | 238 s->get_format= avcodec_default_get_format; |
954 | 239 s->me_subpel_quality=8; |
681 | 240 } |
241 | |
242 /** | |
243 * allocates a AVCodecContext and set it to defaults. | |
244 * this can be deallocated by simply calling free() | |
245 */ | |
703 | 246 AVCodecContext *avcodec_alloc_context(void){ |
681 | 247 AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); |
248 | |
249 if(avctx==NULL) return NULL; | |
250 | |
251 avcodec_get_context_defaults(avctx); | |
252 | |
253 return avctx; | |
254 } | |
255 | |
903 | 256 /** |
925 | 257 * allocates a AVPFrame and set it to defaults. |
903 | 258 * this can be deallocated by simply calling free() |
259 */ | |
925 | 260 AVFrame *avcodec_alloc_frame(void){ |
261 AVFrame *pic= av_mallocz(sizeof(AVFrame)); | |
903 | 262 |
263 return pic; | |
264 } | |
265 | |
0 | 266 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
267 { | |
268 int ret; | |
269 | |
270 avctx->codec = codec; | |
927 | 271 avctx->codec_id = codec->id; |
0 | 272 avctx->frame_number = 0; |
374
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
273 if (codec->priv_data_size > 0) { |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
274 avctx->priv_data = av_mallocz(codec->priv_data_size); |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
275 if (!avctx->priv_data) |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
276 return -ENOMEM; |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
277 } else { |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
278 avctx->priv_data = NULL; |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
279 } |
0 | 280 ret = avctx->codec->init(avctx); |
281 if (ret < 0) { | |
394 | 282 av_freep(&avctx->priv_data); |
0 | 283 return ret; |
284 } | |
285 return 0; | |
286 } | |
287 | |
1064 | 288 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
0 | 289 const short *samples) |
290 { | |
291 int ret; | |
292 | |
293 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); | |
294 avctx->frame_number++; | |
295 return ret; | |
296 } | |
297 | |
1064 | 298 int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
925 | 299 const AVFrame *pict) |
0 | 300 { |
301 int ret; | |
302 | |
303 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); | |
814 | 304 |
305 emms_c(); //needed to avoid a emms_c() call before every return; | |
306 | |
0 | 307 avctx->frame_number++; |
308 return ret; | |
309 } | |
310 | |
311 /* decode a frame. return -1 if error, otherwise return the number of | |
312 bytes used. If no frame could be decompressed, *got_picture_ptr is | |
313 zero. Otherwise, it is non zero */ | |
925 | 314 int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, |
0 | 315 int *got_picture_ptr, |
1064 | 316 uint8_t *buf, int buf_size) |
0 | 317 { |
318 int ret; | |
903 | 319 |
0 | 320 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
321 buf, buf_size); | |
814 | 322 |
323 emms_c(); //needed to avoid a emms_c() call before every return; | |
903 | 324 |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
325 if (*got_picture_ptr) |
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
326 avctx->frame_number++; |
0 | 327 return ret; |
328 } | |
329 | |
330 /* decode an audio frame. return -1 if error, otherwise return the | |
331 *number of bytes used. If no frame could be decompressed, | |
332 *frame_size_ptr is zero. Otherwise, it is the decompressed frame | |
333 *size in BYTES. */ | |
1064 | 334 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, |
0 | 335 int *frame_size_ptr, |
1064 | 336 uint8_t *buf, int buf_size) |
0 | 337 { |
338 int ret; | |
339 | |
340 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, | |
341 buf, buf_size); | |
342 avctx->frame_number++; | |
343 return ret; | |
344 } | |
345 | |
346 int avcodec_close(AVCodecContext *avctx) | |
347 { | |
348 if (avctx->codec->close) | |
349 avctx->codec->close(avctx); | |
394 | 350 av_freep(&avctx->priv_data); |
0 | 351 avctx->codec = NULL; |
352 return 0; | |
353 } | |
354 | |
355 AVCodec *avcodec_find_encoder(enum CodecID id) | |
356 { | |
357 AVCodec *p; | |
358 p = first_avcodec; | |
359 while (p) { | |
360 if (p->encode != NULL && p->id == id) | |
361 return p; | |
362 p = p->next; | |
363 } | |
364 return NULL; | |
365 } | |
366 | |
177 | 367 AVCodec *avcodec_find_encoder_by_name(const char *name) |
368 { | |
369 AVCodec *p; | |
370 p = first_avcodec; | |
371 while (p) { | |
372 if (p->encode != NULL && strcmp(name,p->name) == 0) | |
373 return p; | |
374 p = p->next; | |
375 } | |
376 return NULL; | |
377 } | |
378 | |
0 | 379 AVCodec *avcodec_find_decoder(enum CodecID id) |
380 { | |
381 AVCodec *p; | |
382 p = first_avcodec; | |
383 while (p) { | |
384 if (p->decode != NULL && p->id == id) | |
385 return p; | |
386 p = p->next; | |
387 } | |
388 return NULL; | |
389 } | |
390 | |
391 AVCodec *avcodec_find_decoder_by_name(const char *name) | |
392 { | |
393 AVCodec *p; | |
394 p = first_avcodec; | |
395 while (p) { | |
396 if (p->decode != NULL && strcmp(name,p->name) == 0) | |
397 return p; | |
398 p = p->next; | |
399 } | |
400 return NULL; | |
401 } | |
402 | |
403 AVCodec *avcodec_find(enum CodecID id) | |
404 { | |
405 AVCodec *p; | |
406 p = first_avcodec; | |
407 while (p) { | |
408 if (p->id == id) | |
409 return p; | |
410 p = p->next; | |
411 } | |
412 return NULL; | |
413 } | |
414 | |
415 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |
416 { | |
417 const char *codec_name; | |
418 AVCodec *p; | |
419 char buf1[32]; | |
337 | 420 char channels_str[100]; |
92 | 421 int bitrate; |
0 | 422 |
423 if (encode) | |
424 p = avcodec_find_encoder(enc->codec_id); | |
425 else | |
426 p = avcodec_find_decoder(enc->codec_id); | |
427 | |
428 if (p) { | |
429 codec_name = p->name; | |
430 } else if (enc->codec_name[0] != '\0') { | |
431 codec_name = enc->codec_name; | |
432 } else { | |
433 /* output avi tags */ | |
434 if (enc->codec_type == CODEC_TYPE_VIDEO) { | |
435 snprintf(buf1, sizeof(buf1), "%c%c%c%c", | |
436 enc->codec_tag & 0xff, | |
437 (enc->codec_tag >> 8) & 0xff, | |
438 (enc->codec_tag >> 16) & 0xff, | |
439 (enc->codec_tag >> 24) & 0xff); | |
440 } else { | |
441 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); | |
442 } | |
443 codec_name = buf1; | |
444 } | |
445 | |
446 switch(enc->codec_type) { | |
447 case CODEC_TYPE_VIDEO: | |
448 snprintf(buf, buf_size, | |
449 "Video: %s%s", | |
450 codec_name, enc->flags & CODEC_FLAG_HQ ? " (hq)" : ""); | |
55 | 451 if (enc->codec_id == CODEC_ID_RAWVIDEO) { |
452 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
453 ", %s", | |
988
001b7d3045e5
moved avcodec_get_chroma_sub_sample() to imgconvert.c
bellard
parents:
963
diff
changeset
|
454 avcodec_get_pix_fmt_name(enc->pix_fmt)); |
55 | 455 } |
0 | 456 if (enc->width) { |
457 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
458 ", %dx%d, %0.2f fps", | |
459 enc->width, enc->height, | |
460 (float)enc->frame_rate / FRAME_RATE_BASE); | |
461 } | |
741 | 462 if (encode) { |
463 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
464 ", q=%d-%d", enc->qmin, enc->qmax); | |
465 } | |
92 | 466 bitrate = enc->bit_rate; |
0 | 467 break; |
468 case CODEC_TYPE_AUDIO: | |
469 snprintf(buf, buf_size, | |
470 "Audio: %s", | |
471 codec_name); | |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
472 switch (enc->channels) { |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
473 case 1: |
337 | 474 strcpy(channels_str, "mono"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
475 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
476 case 2: |
337 | 477 strcpy(channels_str, "stereo"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
478 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
479 case 6: |
337 | 480 strcpy(channels_str, "5:1"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
481 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
482 default: |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
483 sprintf(channels_str, "%d channels", enc->channels); |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
484 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
485 } |
0 | 486 if (enc->sample_rate) { |
487 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
488 ", %d Hz, %s", | |
489 enc->sample_rate, | |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
490 channels_str); |
0 | 491 } |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
492 |
92 | 493 /* for PCM codecs, compute bitrate directly */ |
494 switch(enc->codec_id) { | |
495 case CODEC_ID_PCM_S16LE: | |
496 case CODEC_ID_PCM_S16BE: | |
497 case CODEC_ID_PCM_U16LE: | |
498 case CODEC_ID_PCM_U16BE: | |
94 | 499 bitrate = enc->sample_rate * enc->channels * 16; |
92 | 500 break; |
501 case CODEC_ID_PCM_S8: | |
502 case CODEC_ID_PCM_U8: | |
503 case CODEC_ID_PCM_ALAW: | |
504 case CODEC_ID_PCM_MULAW: | |
94 | 505 bitrate = enc->sample_rate * enc->channels * 8; |
92 | 506 break; |
507 default: | |
508 bitrate = enc->bit_rate; | |
509 break; | |
510 } | |
0 | 511 break; |
512 default: | |
583 | 513 av_abort(); |
0 | 514 } |
741 | 515 if (encode) { |
516 if (enc->flags & CODEC_FLAG_PASS1) | |
517 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
518 ", pass 1"); | |
519 if (enc->flags & CODEC_FLAG_PASS2) | |
520 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
521 ", pass 2"); | |
522 } | |
92 | 523 if (bitrate != 0) { |
0 | 524 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
92 | 525 ", %d kb/s", bitrate / 1000); |
0 | 526 } |
527 } | |
528 | |
362 | 529 unsigned avcodec_version( void ) |
530 { | |
531 return LIBAVCODEC_VERSION_INT; | |
532 } | |
55 | 533 |
379 | 534 unsigned avcodec_build( void ) |
535 { | |
536 return LIBAVCODEC_BUILD; | |
537 } | |
538 | |
0 | 539 /* must be called before any other functions */ |
540 void avcodec_init(void) | |
541 { | |
303
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
542 static int inited = 0; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
543 |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
544 if (inited != 0) |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
545 return; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
546 inited = 1; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
547 |
851 | 548 //dsputil_init(); |
0 | 549 } |
550 | |
924 | 551 /* this can be called after seeking and before trying to decode the next keyframe */ |
341 | 552 void avcodec_flush_buffers(AVCodecContext *avctx) |
553 { | |
924 | 554 int i; |
341 | 555 MpegEncContext *s = avctx->priv_data; |
924 | 556 |
557 switch(avctx->codec_id){ | |
558 case CODEC_ID_MPEG1VIDEO: | |
559 case CODEC_ID_H263: | |
560 case CODEC_ID_RV10: | |
561 case CODEC_ID_MJPEG: | |
562 case CODEC_ID_MJPEGB: | |
563 case CODEC_ID_MPEG4: | |
564 case CODEC_ID_MSMPEG4V1: | |
565 case CODEC_ID_MSMPEG4V2: | |
566 case CODEC_ID_MSMPEG4V3: | |
567 case CODEC_ID_WMV1: | |
568 case CODEC_ID_WMV2: | |
569 case CODEC_ID_H263P: | |
570 case CODEC_ID_H263I: | |
571 case CODEC_ID_SVQ1: | |
572 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
573 if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL | |
574 || s->picture[i].type == FF_BUFFER_TYPE_USER)) | |
925 | 575 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); |
963 | 576 } |
577 s->last_picture.data[0] = s->next_picture.data[0] = NULL; | |
924 | 578 break; |
579 default: | |
580 //FIXME | |
581 break; | |
582 } | |
341 | 583 } |
584 | |
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
585 static int raw_encode_init(AVCodecContext *s) |
0 | 586 { |
587 return 0; | |
588 } | |
589 | |
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
590 static int raw_decode_frame(AVCodecContext *avctx, |
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
591 void *data, int *data_size, |
1064 | 592 uint8_t *buf, int buf_size) |
0 | 593 { |
594 return -1; | |
595 } | |
596 | |
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
597 static int raw_encode_frame(AVCodecContext *avctx, |
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
598 unsigned char *frame, int buf_size, void *data) |
0 | 599 { |
600 return -1; | |
601 } | |
602 | |
603 AVCodec rawvideo_codec = { | |
604 "rawvideo", | |
605 CODEC_TYPE_VIDEO, | |
606 CODEC_ID_RAWVIDEO, | |
607 0, | |
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
608 raw_encode_init, |
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
609 raw_encode_frame, |
0 | 610 NULL, |
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
611 raw_decode_frame, |
0 | 612 }; |