Mercurial > libavcodec.hg
annotate utils.c @ 903:22ee74da2cd3 libavcodec
cleanup
adding AVVideoFrame
moving quality, pict_type, key_frame, qscale_table, ... to AVVideoFrame
removing obsolete variables in AVCodecContext
skiping of MBs in b frames
correctly initalizing AVCodecContext
picture buffer cleanup
| author | michaelni |
|---|---|
| date | Wed, 04 Dec 2002 10:04:03 +0000 |
| parents | 6acc8394960d |
| children | 2ac4caad5ca6 |
| 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; | |
| 26 ptr = av_malloc(size); | |
| 27 if (!ptr) | |
| 28 return NULL; | |
| 29 memset(ptr, 0, size); | |
| 30 return ptr; | |
| 31 } | |
| 32 | |
|
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
33 /* 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
|
34 static unsigned int last_static = 0; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
35 static char*** array_static = NULL; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
36 static const unsigned int grow_static = 64; // ^2 |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
37 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
|
38 { |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
39 int l = (last_static + grow_static) & ~(grow_static - 1); |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
40 void *ptr = av_mallocz(size); |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
41 if (!ptr) |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
42 return NULL; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
43 |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
44 if (location) |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
45 { |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
46 if (l > last_static) |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
47 array_static = realloc(array_static, l); |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
48 array_static[last_static++] = (char**) location; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
49 *location = ptr; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
50 } |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
51 return ptr; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
52 } |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
53 /* 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
|
54 void av_free_static() |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
55 { |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
56 if (array_static) |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
57 { |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
58 unsigned i; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
59 for (i = 0; i < last_static; i++) |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
60 { |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
61 free(*array_static[i]); |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
62 *array_static[i] = NULL; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
63 } |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
64 free(array_static); |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
65 array_static = 0; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
66 } |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
67 last_static = 0; |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
68 } |
|
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
69 |
| 400 | 70 /* cannot call it directly because of 'void **' casting is not automatic */ |
| 71 void __av_freep(void **ptr) | |
| 72 { | |
| 73 av_free(*ptr); | |
| 74 *ptr = NULL; | |
| 75 } | |
| 76 | |
| 0 | 77 /* encoder management */ |
| 78 AVCodec *first_avcodec; | |
| 79 | |
| 80 void register_avcodec(AVCodec *format) | |
| 81 { | |
| 82 AVCodec **p; | |
| 83 p = &first_avcodec; | |
| 84 while (*p != NULL) p = &(*p)->next; | |
| 85 *p = format; | |
| 86 format->next = NULL; | |
| 87 } | |
| 88 | |
| 903 | 89 void avcodec_get_chroma_sub_sample(int fmt, int *h_shift, int *v_shift){ |
| 90 switch(fmt){ | |
| 91 case PIX_FMT_YUV410P: | |
| 92 *h_shift=2; | |
| 93 *v_shift=2; | |
| 94 break; | |
| 95 case PIX_FMT_YUV420P: | |
| 96 *h_shift=1; | |
| 97 *v_shift=1; | |
| 98 break; | |
| 99 case PIX_FMT_YUV411P: | |
| 100 *h_shift=2; | |
| 101 *v_shift=0; | |
| 102 break; | |
| 103 case PIX_FMT_YUV422P: | |
| 104 case PIX_FMT_YUV422: | |
| 105 *h_shift=1; | |
| 106 *v_shift=0; | |
| 107 break; | |
| 108 default: //RGB/... | |
| 109 *h_shift=0; | |
| 110 *v_shift=0; | |
| 111 break; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 typedef struct DefaultPicOpaque{ | |
| 116 int last_pic_num; | |
| 117 uint8_t *data[4]; | |
| 118 }DefaultPicOpaque; | |
| 119 | |
| 120 int avcodec_default_get_buffer(AVCodecContext *s, AVVideoFrame *pic){ | |
| 121 int i; | |
| 122 const int width = s->width; | |
| 123 const int height= s->height; | |
| 124 DefaultPicOpaque *opaque; | |
| 125 | |
| 126 if(pic->opaque){ | |
| 127 opaque= (DefaultPicOpaque *)pic->opaque; | |
| 128 for(i=0; i<3; i++) | |
| 129 pic->data[i]= opaque->data[i]; | |
| 130 | |
| 131 // printf("get_buffer %X coded_pic_num:%d last:%d\n", pic->opaque, pic->coded_picture_number, opaque->last_pic_num); | |
| 132 pic->age= pic->coded_picture_number - opaque->last_pic_num; | |
| 133 opaque->last_pic_num= pic->coded_picture_number; | |
| 134 //printf("age: %d %d %d\n", pic->age, c->picture_number, pic->coded_picture_number); | |
| 135 }else{ | |
| 136 int align, h_chroma_shift, v_chroma_shift; | |
| 137 int w, h, pixel_size; | |
| 138 | |
| 139 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
| 140 | |
| 141 switch(s->pix_fmt){ | |
| 142 case PIX_FMT_YUV422: | |
| 143 pixel_size=2; | |
| 144 break; | |
| 145 case PIX_FMT_RGB24: | |
| 146 case PIX_FMT_BGR24: | |
| 147 pixel_size=3; | |
| 148 break; | |
| 149 case PIX_FMT_BGRA32: | |
| 150 case PIX_FMT_RGBA32: | |
| 151 pixel_size=4; | |
| 152 break; | |
| 153 default: | |
| 154 pixel_size=1; | |
| 155 } | |
| 156 | |
| 157 if(s->codec_id==CODEC_ID_SVQ1) align=63; | |
| 158 else align=15; | |
| 159 | |
| 160 w= (width +align)&~align; | |
| 161 h= (height+align)&~align; | |
| 162 | |
| 163 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | |
| 164 w+= EDGE_WIDTH*2; | |
| 165 h+= EDGE_WIDTH*2; | |
| 166 } | |
| 167 | |
| 168 opaque= av_mallocz(sizeof(DefaultPicOpaque)); | |
| 169 if(opaque==NULL) return -1; | |
| 170 | |
| 171 pic->opaque= opaque; | |
| 172 opaque->last_pic_num= -256*256*256*64; | |
| 173 | |
| 174 for(i=0; i<3; i++){ | |
| 175 int h_shift= i==0 ? 0 : h_chroma_shift; | |
| 176 int v_shift= i==0 ? 0 : v_chroma_shift; | |
| 177 | |
| 178 pic->linesize[i]= pixel_size*w>>h_shift; | |
| 179 | |
| 180 pic->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 | |
| 181 if(pic->base[i]==NULL) return -1; | |
| 182 | |
| 183 memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift); | |
| 184 | |
| 185 if(s->flags&CODEC_FLAG_EMU_EDGE) | |
| 186 pic->data[i] = pic->base[i]; | |
| 187 else | |
| 188 pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift); | |
| 189 | |
| 190 opaque->data[i]= pic->data[i]; | |
| 191 } | |
| 192 pic->age= 256*256*256*64; | |
| 193 } | |
| 194 | |
| 195 return 0; | |
| 196 } | |
| 197 | |
| 198 void avcodec_default_release_buffer(AVCodecContext *s, AVVideoFrame *pic){ | |
| 199 int i; | |
| 200 | |
| 201 for(i=0; i<3; i++) | |
| 202 pic->data[i]=NULL; | |
| 203 //printf("R%X\n", pic->opaque); | |
| 204 } | |
| 205 | |
| 681 | 206 void avcodec_get_context_defaults(AVCodecContext *s){ |
| 685 | 207 s->bit_rate= 800*1000; |
| 208 s->bit_rate_tolerance= s->bit_rate*10; | |
| 681 | 209 s->qmin= 2; |
| 210 s->qmax= 31; | |
| 211 s->rc_eq= "tex^qComp"; | |
| 212 s->qcompress= 0.5; | |
| 685 | 213 s->max_qdiff= 3; |
| 214 s->b_quant_factor=1.25; | |
| 215 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
|
216 s->i_quant_factor=-0.8; |
| 685 | 217 s->i_quant_offset=0.0; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
218 s->error_concealment= 3; |
| 762 | 219 s->error_resilience= 1; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
220 s->workaround_bugs= FF_BUG_AUTODETECT; |
| 762 | 221 s->frame_rate = 25 * FRAME_RATE_BASE; |
| 222 s->gop_size= 50; | |
| 223 s->me_method= ME_EPZS; | |
| 903 | 224 s->get_buffer= avcodec_default_get_buffer; |
| 225 s->release_buffer= avcodec_default_release_buffer; | |
| 681 | 226 } |
| 227 | |
| 228 /** | |
| 229 * allocates a AVCodecContext and set it to defaults. | |
| 230 * this can be deallocated by simply calling free() | |
| 231 */ | |
| 703 | 232 AVCodecContext *avcodec_alloc_context(void){ |
| 681 | 233 AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); |
| 234 | |
| 235 if(avctx==NULL) return NULL; | |
| 236 | |
| 237 avcodec_get_context_defaults(avctx); | |
| 238 | |
| 239 return avctx; | |
| 240 } | |
| 241 | |
| 903 | 242 /** |
| 243 * allocates a AVPicture and set it to defaults. | |
| 244 * this can be deallocated by simply calling free() | |
| 245 */ | |
| 246 AVVideoFrame *avcodec_alloc_picture(void){ | |
| 247 AVVideoFrame *pic= av_mallocz(sizeof(AVVideoFrame)); | |
| 248 | |
| 249 return pic; | |
| 250 } | |
| 251 | |
| 0 | 252 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
| 253 { | |
| 254 int ret; | |
| 255 | |
| 256 avctx->codec = codec; | |
| 257 avctx->frame_number = 0; | |
|
374
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
258 if (codec->priv_data_size > 0) { |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
259 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
|
260 if (!avctx->priv_data) |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
261 return -ENOMEM; |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
262 } else { |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
263 avctx->priv_data = NULL; |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
264 } |
| 0 | 265 ret = avctx->codec->init(avctx); |
| 266 if (ret < 0) { | |
| 394 | 267 av_freep(&avctx->priv_data); |
| 0 | 268 return ret; |
| 269 } | |
| 270 return 0; | |
| 271 } | |
| 272 | |
| 273 int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size, | |
| 274 const short *samples) | |
| 275 { | |
| 276 int ret; | |
| 277 | |
| 278 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); | |
| 279 avctx->frame_number++; | |
| 280 return ret; | |
| 281 } | |
| 282 | |
| 283 int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size, | |
| 903 | 284 const AVVideoFrame *pict) |
| 0 | 285 { |
| 286 int ret; | |
| 287 | |
| 288 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); | |
| 814 | 289 |
| 290 emms_c(); //needed to avoid a emms_c() call before every return; | |
| 291 | |
| 0 | 292 avctx->frame_number++; |
| 293 return ret; | |
| 294 } | |
| 295 | |
| 296 /* decode a frame. return -1 if error, otherwise return the number of | |
| 297 bytes used. If no frame could be decompressed, *got_picture_ptr is | |
| 298 zero. Otherwise, it is non zero */ | |
| 903 | 299 int avcodec_decode_video(AVCodecContext *avctx, AVVideoFrame *picture, |
| 0 | 300 int *got_picture_ptr, |
| 301 UINT8 *buf, int buf_size) | |
| 302 { | |
| 303 int ret; | |
| 903 | 304 |
| 0 | 305 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
| 306 buf, buf_size); | |
| 814 | 307 |
| 308 emms_c(); //needed to avoid a emms_c() call before every return; | |
| 903 | 309 |
|
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
310 if (*got_picture_ptr) |
|
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
311 avctx->frame_number++; |
| 0 | 312 return ret; |
| 313 } | |
| 314 | |
| 315 /* decode an audio frame. return -1 if error, otherwise return the | |
| 316 *number of bytes used. If no frame could be decompressed, | |
| 317 *frame_size_ptr is zero. Otherwise, it is the decompressed frame | |
| 318 *size in BYTES. */ | |
| 319 int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples, | |
| 320 int *frame_size_ptr, | |
| 321 UINT8 *buf, int buf_size) | |
| 322 { | |
| 323 int ret; | |
| 324 | |
| 325 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, | |
| 326 buf, buf_size); | |
| 327 avctx->frame_number++; | |
| 328 return ret; | |
| 329 } | |
| 330 | |
| 331 int avcodec_close(AVCodecContext *avctx) | |
| 332 { | |
| 333 if (avctx->codec->close) | |
| 334 avctx->codec->close(avctx); | |
| 394 | 335 av_freep(&avctx->priv_data); |
| 0 | 336 avctx->codec = NULL; |
| 337 return 0; | |
| 338 } | |
| 339 | |
| 340 AVCodec *avcodec_find_encoder(enum CodecID id) | |
| 341 { | |
| 342 AVCodec *p; | |
| 343 p = first_avcodec; | |
| 344 while (p) { | |
| 345 if (p->encode != NULL && p->id == id) | |
| 346 return p; | |
| 347 p = p->next; | |
| 348 } | |
| 349 return NULL; | |
| 350 } | |
| 351 | |
| 177 | 352 AVCodec *avcodec_find_encoder_by_name(const char *name) |
| 353 { | |
| 354 AVCodec *p; | |
| 355 p = first_avcodec; | |
| 356 while (p) { | |
| 357 if (p->encode != NULL && strcmp(name,p->name) == 0) | |
| 358 return p; | |
| 359 p = p->next; | |
| 360 } | |
| 361 return NULL; | |
| 362 } | |
| 363 | |
| 0 | 364 AVCodec *avcodec_find_decoder(enum CodecID id) |
| 365 { | |
| 366 AVCodec *p; | |
| 367 p = first_avcodec; | |
| 368 while (p) { | |
| 369 if (p->decode != NULL && p->id == id) | |
| 370 return p; | |
| 371 p = p->next; | |
| 372 } | |
| 373 return NULL; | |
| 374 } | |
| 375 | |
| 376 AVCodec *avcodec_find_decoder_by_name(const char *name) | |
| 377 { | |
| 378 AVCodec *p; | |
| 379 p = first_avcodec; | |
| 380 while (p) { | |
| 381 if (p->decode != NULL && strcmp(name,p->name) == 0) | |
| 382 return p; | |
| 383 p = p->next; | |
| 384 } | |
| 385 return NULL; | |
| 386 } | |
| 387 | |
| 388 AVCodec *avcodec_find(enum CodecID id) | |
| 389 { | |
| 390 AVCodec *p; | |
| 391 p = first_avcodec; | |
| 392 while (p) { | |
| 393 if (p->id == id) | |
| 394 return p; | |
| 395 p = p->next; | |
| 396 } | |
| 397 return NULL; | |
| 398 } | |
| 399 | |
| 55 | 400 const char *pix_fmt_str[] = { |
| 401 "yuv420p", | |
| 402 "yuv422", | |
| 403 "rgb24", | |
| 404 "bgr24", | |
| 405 "yuv422p", | |
| 406 "yuv444p", | |
| 583 | 407 "rgba32", |
| 408 "bgra32", | |
| 742 | 409 "yuv410p", |
| 410 "yuv411p", | |
| 55 | 411 }; |
| 742 | 412 |
| 0 | 413 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) |
| 414 { | |
| 415 const char *codec_name; | |
| 416 AVCodec *p; | |
| 417 char buf1[32]; | |
| 337 | 418 char channels_str[100]; |
| 92 | 419 int bitrate; |
| 0 | 420 |
| 421 if (encode) | |
| 422 p = avcodec_find_encoder(enc->codec_id); | |
| 423 else | |
| 424 p = avcodec_find_decoder(enc->codec_id); | |
| 425 | |
| 426 if (p) { | |
| 427 codec_name = p->name; | |
| 428 } else if (enc->codec_name[0] != '\0') { | |
| 429 codec_name = enc->codec_name; | |
| 430 } else { | |
| 431 /* output avi tags */ | |
| 432 if (enc->codec_type == CODEC_TYPE_VIDEO) { | |
| 433 snprintf(buf1, sizeof(buf1), "%c%c%c%c", | |
| 434 enc->codec_tag & 0xff, | |
| 435 (enc->codec_tag >> 8) & 0xff, | |
| 436 (enc->codec_tag >> 16) & 0xff, | |
| 437 (enc->codec_tag >> 24) & 0xff); | |
| 438 } else { | |
| 439 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); | |
| 440 } | |
| 441 codec_name = buf1; | |
| 442 } | |
| 443 | |
| 444 switch(enc->codec_type) { | |
| 445 case CODEC_TYPE_VIDEO: | |
| 446 snprintf(buf, buf_size, | |
| 447 "Video: %s%s", | |
| 448 codec_name, enc->flags & CODEC_FLAG_HQ ? " (hq)" : ""); | |
| 55 | 449 if (enc->codec_id == CODEC_ID_RAWVIDEO) { |
| 450 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 451 ", %s", | |
| 452 pix_fmt_str[enc->pix_fmt]); | |
| 453 } | |
| 0 | 454 if (enc->width) { |
| 455 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 456 ", %dx%d, %0.2f fps", | |
| 457 enc->width, enc->height, | |
| 458 (float)enc->frame_rate / FRAME_RATE_BASE); | |
| 459 } | |
| 741 | 460 if (encode) { |
| 461 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 462 ", q=%d-%d", enc->qmin, enc->qmax); | |
| 463 } | |
| 92 | 464 bitrate = enc->bit_rate; |
| 0 | 465 break; |
| 466 case CODEC_TYPE_AUDIO: | |
| 467 snprintf(buf, buf_size, | |
| 468 "Audio: %s", | |
| 469 codec_name); | |
|
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
470 switch (enc->channels) { |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
471 case 1: |
| 337 | 472 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
|
473 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
474 case 2: |
| 337 | 475 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
|
476 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
477 case 6: |
| 337 | 478 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
|
479 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
480 default: |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
481 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
|
482 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
483 } |
| 0 | 484 if (enc->sample_rate) { |
| 485 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 486 ", %d Hz, %s", | |
| 487 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
|
488 channels_str); |
| 0 | 489 } |
|
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
490 |
| 92 | 491 /* for PCM codecs, compute bitrate directly */ |
| 492 switch(enc->codec_id) { | |
| 493 case CODEC_ID_PCM_S16LE: | |
| 494 case CODEC_ID_PCM_S16BE: | |
| 495 case CODEC_ID_PCM_U16LE: | |
| 496 case CODEC_ID_PCM_U16BE: | |
| 94 | 497 bitrate = enc->sample_rate * enc->channels * 16; |
| 92 | 498 break; |
| 499 case CODEC_ID_PCM_S8: | |
| 500 case CODEC_ID_PCM_U8: | |
| 501 case CODEC_ID_PCM_ALAW: | |
| 502 case CODEC_ID_PCM_MULAW: | |
| 94 | 503 bitrate = enc->sample_rate * enc->channels * 8; |
| 92 | 504 break; |
| 505 default: | |
| 506 bitrate = enc->bit_rate; | |
| 507 break; | |
| 508 } | |
| 0 | 509 break; |
| 510 default: | |
| 583 | 511 av_abort(); |
| 0 | 512 } |
| 741 | 513 if (encode) { |
| 514 if (enc->flags & CODEC_FLAG_PASS1) | |
| 515 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 516 ", pass 1"); | |
| 517 if (enc->flags & CODEC_FLAG_PASS2) | |
| 518 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 519 ", pass 2"); | |
| 520 } | |
| 92 | 521 if (bitrate != 0) { |
| 0 | 522 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 92 | 523 ", %d kb/s", bitrate / 1000); |
| 0 | 524 } |
| 525 } | |
| 526 | |
| 55 | 527 /* Picture field are filled with 'ptr' addresses */ |
| 528 void avpicture_fill(AVPicture *picture, UINT8 *ptr, | |
| 529 int pix_fmt, int width, int height) | |
| 530 { | |
| 531 int size; | |
| 532 | |
| 533 size = width * height; | |
| 534 switch(pix_fmt) { | |
| 535 case PIX_FMT_YUV420P: | |
| 536 picture->data[0] = ptr; | |
| 537 picture->data[1] = picture->data[0] + size; | |
| 538 picture->data[2] = picture->data[1] + size / 4; | |
| 539 picture->linesize[0] = width; | |
| 540 picture->linesize[1] = width / 2; | |
| 541 picture->linesize[2] = width / 2; | |
| 542 break; | |
| 543 case PIX_FMT_YUV422P: | |
| 544 picture->data[0] = ptr; | |
| 545 picture->data[1] = picture->data[0] + size; | |
| 546 picture->data[2] = picture->data[1] + size / 2; | |
| 547 picture->linesize[0] = width; | |
| 548 picture->linesize[1] = width / 2; | |
| 549 picture->linesize[2] = width / 2; | |
| 550 break; | |
| 551 case PIX_FMT_YUV444P: | |
| 552 picture->data[0] = ptr; | |
| 553 picture->data[1] = picture->data[0] + size; | |
| 554 picture->data[2] = picture->data[1] + size; | |
| 555 picture->linesize[0] = width; | |
| 556 picture->linesize[1] = width; | |
| 557 picture->linesize[2] = width; | |
| 558 break; | |
| 559 case PIX_FMT_RGB24: | |
| 560 case PIX_FMT_BGR24: | |
| 561 picture->data[0] = ptr; | |
| 562 picture->data[1] = NULL; | |
| 563 picture->data[2] = NULL; | |
| 564 picture->linesize[0] = width * 3; | |
| 565 break; | |
| 583 | 566 case PIX_FMT_RGBA32: |
| 567 case PIX_FMT_BGRA32: | |
| 568 picture->data[0] = ptr; | |
| 569 picture->data[1] = NULL; | |
| 570 picture->data[2] = NULL; | |
| 571 picture->linesize[0] = width * 4; | |
| 572 break; | |
| 55 | 573 case PIX_FMT_YUV422: |
| 574 picture->data[0] = ptr; | |
| 575 picture->data[1] = NULL; | |
| 576 picture->data[2] = NULL; | |
| 577 picture->linesize[0] = width * 2; | |
| 578 break; | |
| 579 default: | |
| 580 picture->data[0] = NULL; | |
| 581 picture->data[1] = NULL; | |
| 582 picture->data[2] = NULL; | |
| 583 break; | |
| 584 } | |
| 585 } | |
| 586 | |
| 587 int avpicture_get_size(int pix_fmt, int width, int height) | |
| 588 { | |
| 589 int size; | |
| 590 | |
| 591 size = width * height; | |
| 592 switch(pix_fmt) { | |
| 593 case PIX_FMT_YUV420P: | |
| 594 size = (size * 3) / 2; | |
| 595 break; | |
| 596 case PIX_FMT_YUV422P: | |
| 597 size = (size * 2); | |
| 598 break; | |
| 599 case PIX_FMT_YUV444P: | |
| 600 size = (size * 3); | |
| 601 break; | |
| 602 case PIX_FMT_RGB24: | |
| 603 case PIX_FMT_BGR24: | |
| 604 size = (size * 3); | |
| 605 break; | |
| 583 | 606 case PIX_FMT_RGBA32: |
| 607 case PIX_FMT_BGRA32: | |
| 608 size = (size * 4); | |
| 609 break; | |
| 55 | 610 case PIX_FMT_YUV422: |
| 611 size = (size * 2); | |
| 612 break; | |
| 613 default: | |
| 614 size = -1; | |
| 615 break; | |
| 616 } | |
| 617 return size; | |
| 618 } | |
| 619 | |
| 362 | 620 unsigned avcodec_version( void ) |
| 621 { | |
| 622 return LIBAVCODEC_VERSION_INT; | |
| 623 } | |
| 55 | 624 |
| 379 | 625 unsigned avcodec_build( void ) |
| 626 { | |
| 627 return LIBAVCODEC_BUILD; | |
| 628 } | |
| 629 | |
| 0 | 630 /* must be called before any other functions */ |
| 631 void avcodec_init(void) | |
| 632 { | |
|
303
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
633 static int inited = 0; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
634 |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
635 if (inited != 0) |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
636 return; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
637 inited = 1; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
638 |
| 851 | 639 //dsputil_init(); |
| 0 | 640 } |
| 641 | |
| 341 | 642 /* this should be called after seeking and before trying to decode the next frame */ |
| 643 void avcodec_flush_buffers(AVCodecContext *avctx) | |
| 644 { | |
| 645 MpegEncContext *s = avctx->priv_data; | |
| 646 s->num_available_buffers=0; | |
| 647 } | |
| 648 | |
| 649 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
650 static int raw_encode_init(AVCodecContext *s) |
| 0 | 651 { |
| 652 return 0; | |
| 653 } | |
| 654 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
655 static int raw_decode_frame(AVCodecContext *avctx, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
656 void *data, int *data_size, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
657 UINT8 *buf, int buf_size) |
| 0 | 658 { |
| 659 return -1; | |
| 660 } | |
| 661 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
662 static int raw_encode_frame(AVCodecContext *avctx, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
663 unsigned char *frame, int buf_size, void *data) |
| 0 | 664 { |
| 665 return -1; | |
| 666 } | |
| 667 | |
| 668 AVCodec rawvideo_codec = { | |
| 669 "rawvideo", | |
| 670 CODEC_TYPE_VIDEO, | |
| 671 CODEC_ID_RAWVIDEO, | |
| 672 0, | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
673 raw_encode_init, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
674 raw_encode_frame, |
| 0 | 675 NULL, |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
676 raw_decode_frame, |
| 0 | 677 }; |
