Mercurial > libavcodec.hg
annotate utils.c @ 902:6acc8394960d libavcodec
* two functions to handle allocation of static data more simple
av_mallocz_static - called for every static data table
av_free_static - called when ffmpeg is no longer needed and should free
all static resources
* simple usage shown in mpegaudiodec.c
| author | kabi |
|---|---|
| date | Tue, 03 Dec 2002 19:40:35 +0000 |
| parents | 058194d7ade6 |
| children | 22ee74da2cd3 |
| 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 | |
| 681 | 89 void avcodec_get_context_defaults(AVCodecContext *s){ |
| 685 | 90 s->bit_rate= 800*1000; |
| 91 s->bit_rate_tolerance= s->bit_rate*10; | |
| 681 | 92 s->qmin= 2; |
| 93 s->qmax= 31; | |
| 94 s->rc_eq= "tex^qComp"; | |
| 95 s->qcompress= 0.5; | |
| 685 | 96 s->max_qdiff= 3; |
| 97 s->b_quant_factor=1.25; | |
| 98 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
|
99 s->i_quant_factor=-0.8; |
| 685 | 100 s->i_quant_offset=0.0; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
101 s->error_concealment= 3; |
| 762 | 102 s->error_resilience= 1; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
103 s->workaround_bugs= FF_BUG_AUTODETECT; |
| 762 | 104 s->frame_rate = 25 * FRAME_RATE_BASE; |
| 105 s->gop_size= 50; | |
| 106 s->me_method= ME_EPZS; | |
| 681 | 107 } |
| 108 | |
| 109 /** | |
| 110 * allocates a AVCodecContext and set it to defaults. | |
| 111 * this can be deallocated by simply calling free() | |
| 112 */ | |
| 703 | 113 AVCodecContext *avcodec_alloc_context(void){ |
| 681 | 114 AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); |
| 115 | |
| 116 if(avctx==NULL) return NULL; | |
| 117 | |
| 118 avcodec_get_context_defaults(avctx); | |
| 119 | |
| 120 return avctx; | |
| 121 } | |
| 122 | |
| 0 | 123 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
| 124 { | |
| 125 int ret; | |
| 126 | |
| 127 avctx->codec = codec; | |
| 128 avctx->frame_number = 0; | |
|
374
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
129 if (codec->priv_data_size > 0) { |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
130 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
|
131 if (!avctx->priv_data) |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
132 return -ENOMEM; |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
133 } else { |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
134 avctx->priv_data = NULL; |
|
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
135 } |
| 0 | 136 ret = avctx->codec->init(avctx); |
| 137 if (ret < 0) { | |
| 394 | 138 av_freep(&avctx->priv_data); |
| 0 | 139 return ret; |
| 140 } | |
| 141 return 0; | |
| 142 } | |
| 143 | |
| 144 int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size, | |
| 145 const short *samples) | |
| 146 { | |
| 147 int ret; | |
| 148 | |
| 149 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); | |
| 150 avctx->frame_number++; | |
| 151 return ret; | |
| 152 } | |
| 153 | |
| 154 int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size, | |
| 155 const AVPicture *pict) | |
| 156 { | |
| 157 int ret; | |
| 158 | |
| 159 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); | |
| 814 | 160 |
| 161 emms_c(); //needed to avoid a emms_c() call before every return; | |
| 162 | |
| 0 | 163 avctx->frame_number++; |
| 164 return ret; | |
| 165 } | |
| 166 | |
| 167 /* decode a frame. return -1 if error, otherwise return the number of | |
| 168 bytes used. If no frame could be decompressed, *got_picture_ptr is | |
| 169 zero. Otherwise, it is non zero */ | |
| 170 int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture, | |
| 171 int *got_picture_ptr, | |
| 172 UINT8 *buf, int buf_size) | |
| 173 { | |
| 174 int ret; | |
| 175 | |
| 176 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | |
| 177 buf, buf_size); | |
| 814 | 178 |
| 179 emms_c(); //needed to avoid a emms_c() call before every return; | |
| 180 | |
|
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
181 if (*got_picture_ptr) |
|
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
260
diff
changeset
|
182 avctx->frame_number++; |
| 0 | 183 return ret; |
| 184 } | |
| 185 | |
| 186 /* decode an audio frame. return -1 if error, otherwise return the | |
| 187 *number of bytes used. If no frame could be decompressed, | |
| 188 *frame_size_ptr is zero. Otherwise, it is the decompressed frame | |
| 189 *size in BYTES. */ | |
| 190 int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples, | |
| 191 int *frame_size_ptr, | |
| 192 UINT8 *buf, int buf_size) | |
| 193 { | |
| 194 int ret; | |
| 195 | |
| 196 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, | |
| 197 buf, buf_size); | |
| 198 avctx->frame_number++; | |
| 199 return ret; | |
| 200 } | |
| 201 | |
| 202 int avcodec_close(AVCodecContext *avctx) | |
| 203 { | |
| 204 if (avctx->codec->close) | |
| 205 avctx->codec->close(avctx); | |
| 394 | 206 av_freep(&avctx->priv_data); |
| 0 | 207 avctx->codec = NULL; |
| 208 return 0; | |
| 209 } | |
| 210 | |
| 211 AVCodec *avcodec_find_encoder(enum CodecID id) | |
| 212 { | |
| 213 AVCodec *p; | |
| 214 p = first_avcodec; | |
| 215 while (p) { | |
| 216 if (p->encode != NULL && p->id == id) | |
| 217 return p; | |
| 218 p = p->next; | |
| 219 } | |
| 220 return NULL; | |
| 221 } | |
| 222 | |
| 177 | 223 AVCodec *avcodec_find_encoder_by_name(const char *name) |
| 224 { | |
| 225 AVCodec *p; | |
| 226 p = first_avcodec; | |
| 227 while (p) { | |
| 228 if (p->encode != NULL && strcmp(name,p->name) == 0) | |
| 229 return p; | |
| 230 p = p->next; | |
| 231 } | |
| 232 return NULL; | |
| 233 } | |
| 234 | |
| 0 | 235 AVCodec *avcodec_find_decoder(enum CodecID id) |
| 236 { | |
| 237 AVCodec *p; | |
| 238 p = first_avcodec; | |
| 239 while (p) { | |
| 240 if (p->decode != NULL && p->id == id) | |
| 241 return p; | |
| 242 p = p->next; | |
| 243 } | |
| 244 return NULL; | |
| 245 } | |
| 246 | |
| 247 AVCodec *avcodec_find_decoder_by_name(const char *name) | |
| 248 { | |
| 249 AVCodec *p; | |
| 250 p = first_avcodec; | |
| 251 while (p) { | |
| 252 if (p->decode != NULL && strcmp(name,p->name) == 0) | |
| 253 return p; | |
| 254 p = p->next; | |
| 255 } | |
| 256 return NULL; | |
| 257 } | |
| 258 | |
| 259 AVCodec *avcodec_find(enum CodecID id) | |
| 260 { | |
| 261 AVCodec *p; | |
| 262 p = first_avcodec; | |
| 263 while (p) { | |
| 264 if (p->id == id) | |
| 265 return p; | |
| 266 p = p->next; | |
| 267 } | |
| 268 return NULL; | |
| 269 } | |
| 270 | |
| 55 | 271 const char *pix_fmt_str[] = { |
| 272 "yuv420p", | |
| 273 "yuv422", | |
| 274 "rgb24", | |
| 275 "bgr24", | |
| 276 "yuv422p", | |
| 277 "yuv444p", | |
| 583 | 278 "rgba32", |
| 279 "bgra32", | |
| 742 | 280 "yuv410p", |
| 281 "yuv411p", | |
| 55 | 282 }; |
| 742 | 283 |
| 0 | 284 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) |
| 285 { | |
| 286 const char *codec_name; | |
| 287 AVCodec *p; | |
| 288 char buf1[32]; | |
| 337 | 289 char channels_str[100]; |
| 92 | 290 int bitrate; |
| 0 | 291 |
| 292 if (encode) | |
| 293 p = avcodec_find_encoder(enc->codec_id); | |
| 294 else | |
| 295 p = avcodec_find_decoder(enc->codec_id); | |
| 296 | |
| 297 if (p) { | |
| 298 codec_name = p->name; | |
| 299 } else if (enc->codec_name[0] != '\0') { | |
| 300 codec_name = enc->codec_name; | |
| 301 } else { | |
| 302 /* output avi tags */ | |
| 303 if (enc->codec_type == CODEC_TYPE_VIDEO) { | |
| 304 snprintf(buf1, sizeof(buf1), "%c%c%c%c", | |
| 305 enc->codec_tag & 0xff, | |
| 306 (enc->codec_tag >> 8) & 0xff, | |
| 307 (enc->codec_tag >> 16) & 0xff, | |
| 308 (enc->codec_tag >> 24) & 0xff); | |
| 309 } else { | |
| 310 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); | |
| 311 } | |
| 312 codec_name = buf1; | |
| 313 } | |
| 314 | |
| 315 switch(enc->codec_type) { | |
| 316 case CODEC_TYPE_VIDEO: | |
| 317 snprintf(buf, buf_size, | |
| 318 "Video: %s%s", | |
| 319 codec_name, enc->flags & CODEC_FLAG_HQ ? " (hq)" : ""); | |
| 55 | 320 if (enc->codec_id == CODEC_ID_RAWVIDEO) { |
| 321 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 322 ", %s", | |
| 323 pix_fmt_str[enc->pix_fmt]); | |
| 324 } | |
| 0 | 325 if (enc->width) { |
| 326 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 327 ", %dx%d, %0.2f fps", | |
| 328 enc->width, enc->height, | |
| 329 (float)enc->frame_rate / FRAME_RATE_BASE); | |
| 330 } | |
| 741 | 331 if (encode) { |
| 332 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 333 ", q=%d-%d", enc->qmin, enc->qmax); | |
| 334 } | |
| 92 | 335 bitrate = enc->bit_rate; |
| 0 | 336 break; |
| 337 case CODEC_TYPE_AUDIO: | |
| 338 snprintf(buf, buf_size, | |
| 339 "Audio: %s", | |
| 340 codec_name); | |
|
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
341 switch (enc->channels) { |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
342 case 1: |
| 337 | 343 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
|
344 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
345 case 2: |
| 337 | 346 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
|
347 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
348 case 6: |
| 337 | 349 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
|
350 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
351 default: |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
352 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
|
353 break; |
|
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
354 } |
| 0 | 355 if (enc->sample_rate) { |
| 356 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 357 ", %d Hz, %s", | |
| 358 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
|
359 channels_str); |
| 0 | 360 } |
|
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
361 |
| 92 | 362 /* for PCM codecs, compute bitrate directly */ |
| 363 switch(enc->codec_id) { | |
| 364 case CODEC_ID_PCM_S16LE: | |
| 365 case CODEC_ID_PCM_S16BE: | |
| 366 case CODEC_ID_PCM_U16LE: | |
| 367 case CODEC_ID_PCM_U16BE: | |
| 94 | 368 bitrate = enc->sample_rate * enc->channels * 16; |
| 92 | 369 break; |
| 370 case CODEC_ID_PCM_S8: | |
| 371 case CODEC_ID_PCM_U8: | |
| 372 case CODEC_ID_PCM_ALAW: | |
| 373 case CODEC_ID_PCM_MULAW: | |
| 94 | 374 bitrate = enc->sample_rate * enc->channels * 8; |
| 92 | 375 break; |
| 376 default: | |
| 377 bitrate = enc->bit_rate; | |
| 378 break; | |
| 379 } | |
| 0 | 380 break; |
| 381 default: | |
| 583 | 382 av_abort(); |
| 0 | 383 } |
| 741 | 384 if (encode) { |
| 385 if (enc->flags & CODEC_FLAG_PASS1) | |
| 386 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 387 ", pass 1"); | |
| 388 if (enc->flags & CODEC_FLAG_PASS2) | |
| 389 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
| 390 ", pass 2"); | |
| 391 } | |
| 92 | 392 if (bitrate != 0) { |
| 0 | 393 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 92 | 394 ", %d kb/s", bitrate / 1000); |
| 0 | 395 } |
| 396 } | |
| 397 | |
| 55 | 398 /* Picture field are filled with 'ptr' addresses */ |
| 399 void avpicture_fill(AVPicture *picture, UINT8 *ptr, | |
| 400 int pix_fmt, int width, int height) | |
| 401 { | |
| 402 int size; | |
| 403 | |
| 404 size = width * height; | |
| 405 switch(pix_fmt) { | |
| 406 case PIX_FMT_YUV420P: | |
| 407 picture->data[0] = ptr; | |
| 408 picture->data[1] = picture->data[0] + size; | |
| 409 picture->data[2] = picture->data[1] + size / 4; | |
| 410 picture->linesize[0] = width; | |
| 411 picture->linesize[1] = width / 2; | |
| 412 picture->linesize[2] = width / 2; | |
| 413 break; | |
| 414 case PIX_FMT_YUV422P: | |
| 415 picture->data[0] = ptr; | |
| 416 picture->data[1] = picture->data[0] + size; | |
| 417 picture->data[2] = picture->data[1] + size / 2; | |
| 418 picture->linesize[0] = width; | |
| 419 picture->linesize[1] = width / 2; | |
| 420 picture->linesize[2] = width / 2; | |
| 421 break; | |
| 422 case PIX_FMT_YUV444P: | |
| 423 picture->data[0] = ptr; | |
| 424 picture->data[1] = picture->data[0] + size; | |
| 425 picture->data[2] = picture->data[1] + size; | |
| 426 picture->linesize[0] = width; | |
| 427 picture->linesize[1] = width; | |
| 428 picture->linesize[2] = width; | |
| 429 break; | |
| 430 case PIX_FMT_RGB24: | |
| 431 case PIX_FMT_BGR24: | |
| 432 picture->data[0] = ptr; | |
| 433 picture->data[1] = NULL; | |
| 434 picture->data[2] = NULL; | |
| 435 picture->linesize[0] = width * 3; | |
| 436 break; | |
| 583 | 437 case PIX_FMT_RGBA32: |
| 438 case PIX_FMT_BGRA32: | |
| 439 picture->data[0] = ptr; | |
| 440 picture->data[1] = NULL; | |
| 441 picture->data[2] = NULL; | |
| 442 picture->linesize[0] = width * 4; | |
| 443 break; | |
| 55 | 444 case PIX_FMT_YUV422: |
| 445 picture->data[0] = ptr; | |
| 446 picture->data[1] = NULL; | |
| 447 picture->data[2] = NULL; | |
| 448 picture->linesize[0] = width * 2; | |
| 449 break; | |
| 450 default: | |
| 451 picture->data[0] = NULL; | |
| 452 picture->data[1] = NULL; | |
| 453 picture->data[2] = NULL; | |
| 454 break; | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 int avpicture_get_size(int pix_fmt, int width, int height) | |
| 459 { | |
| 460 int size; | |
| 461 | |
| 462 size = width * height; | |
| 463 switch(pix_fmt) { | |
| 464 case PIX_FMT_YUV420P: | |
| 465 size = (size * 3) / 2; | |
| 466 break; | |
| 467 case PIX_FMT_YUV422P: | |
| 468 size = (size * 2); | |
| 469 break; | |
| 470 case PIX_FMT_YUV444P: | |
| 471 size = (size * 3); | |
| 472 break; | |
| 473 case PIX_FMT_RGB24: | |
| 474 case PIX_FMT_BGR24: | |
| 475 size = (size * 3); | |
| 476 break; | |
| 583 | 477 case PIX_FMT_RGBA32: |
| 478 case PIX_FMT_BGRA32: | |
| 479 size = (size * 4); | |
| 480 break; | |
| 55 | 481 case PIX_FMT_YUV422: |
| 482 size = (size * 2); | |
| 483 break; | |
| 484 default: | |
| 485 size = -1; | |
| 486 break; | |
| 487 } | |
| 488 return size; | |
| 489 } | |
| 490 | |
| 362 | 491 unsigned avcodec_version( void ) |
| 492 { | |
| 493 return LIBAVCODEC_VERSION_INT; | |
| 494 } | |
| 55 | 495 |
| 379 | 496 unsigned avcodec_build( void ) |
| 497 { | |
| 498 return LIBAVCODEC_BUILD; | |
| 499 } | |
| 500 | |
| 0 | 501 /* must be called before any other functions */ |
| 502 void avcodec_init(void) | |
| 503 { | |
|
303
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
504 static int inited = 0; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
505 |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
506 if (inited != 0) |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
507 return; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
508 inited = 1; |
|
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
509 |
| 851 | 510 //dsputil_init(); |
| 0 | 511 } |
| 512 | |
| 341 | 513 /* this should be called after seeking and before trying to decode the next frame */ |
| 514 void avcodec_flush_buffers(AVCodecContext *avctx) | |
| 515 { | |
| 516 MpegEncContext *s = avctx->priv_data; | |
| 517 s->num_available_buffers=0; | |
| 518 } | |
| 519 | |
| 520 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
521 static int raw_encode_init(AVCodecContext *s) |
| 0 | 522 { |
| 523 return 0; | |
| 524 } | |
| 525 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
526 static int raw_decode_frame(AVCodecContext *avctx, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
527 void *data, int *data_size, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
528 UINT8 *buf, int buf_size) |
| 0 | 529 { |
| 530 return -1; | |
| 531 } | |
| 532 | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
533 static int raw_encode_frame(AVCodecContext *avctx, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
534 unsigned char *frame, int buf_size, void *data) |
| 0 | 535 { |
| 536 return -1; | |
| 537 } | |
| 538 | |
| 539 AVCodec rawvideo_codec = { | |
| 540 "rawvideo", | |
| 541 CODEC_TYPE_VIDEO, | |
| 542 CODEC_ID_RAWVIDEO, | |
| 543 0, | |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
544 raw_encode_init, |
|
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
545 raw_encode_frame, |
| 0 | 546 NULL, |
|
440
000aeeac27a2
* started to cleanup name clashes for onetime compilation
kabi
parents:
429
diff
changeset
|
547 raw_decode_frame, |
| 0 | 548 }; |
