00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "libavutil/avstring.h"
00029 #include "libavutil/integer.h"
00030 #include "libavutil/crc.h"
00031 #include "libavutil/pixdesc.h"
00032 #include "libavutil/audioconvert.h"
00033 #include "libavutil/imgutils.h"
00034 #include "libavutil/samplefmt.h"
00035 #include "libavutil/dict.h"
00036 #include "avcodec.h"
00037 #include "dsputil.h"
00038 #include "libavutil/opt.h"
00039 #include "imgconvert.h"
00040 #include "thread.h"
00041 #include "audioconvert.h"
00042 #include "internal.h"
00043 #include <stdlib.h>
00044 #include <stdarg.h>
00045 #include <limits.h>
00046 #include <float.h>
00047
00048 static int volatile entangled_thread_counter=0;
00049 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
00050 static void *codec_mutex;
00051
00052 void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size)
00053 {
00054 if(min_size < *size)
00055 return ptr;
00056
00057 min_size= FFMAX(17*min_size/16 + 32, min_size);
00058
00059 ptr= av_realloc(ptr, min_size);
00060 if(!ptr)
00061 min_size= 0;
00062
00063 *size= min_size;
00064
00065 return ptr;
00066 }
00067
00068 void av_fast_malloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size)
00069 {
00070 void **p = ptr;
00071 if (min_size < *size)
00072 return;
00073 min_size= FFMAX(17*min_size/16 + 32, min_size);
00074 av_free(*p);
00075 *p = av_malloc(min_size);
00076 if (!*p) min_size = 0;
00077 *size= min_size;
00078 }
00079
00080
00081 static AVCodec *first_avcodec = NULL;
00082
00083 AVCodec *av_codec_next(AVCodec *c){
00084 if(c) return c->next;
00085 else return first_avcodec;
00086 }
00087
00088 void avcodec_register(AVCodec *codec)
00089 {
00090 AVCodec **p;
00091 avcodec_init();
00092 p = &first_avcodec;
00093 while (*p != NULL) p = &(*p)->next;
00094 *p = codec;
00095 codec->next = NULL;
00096 }
00097
00098 #if LIBAVCODEC_VERSION_MAJOR < 53
00099 void register_avcodec(AVCodec *codec)
00100 {
00101 avcodec_register(codec);
00102 }
00103 #endif
00104
00105 unsigned avcodec_get_edge_width(void)
00106 {
00107 return EDGE_WIDTH;
00108 }
00109
00110 void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
00111 s->coded_width = width;
00112 s->coded_height= height;
00113 s->width = -((-width )>>s->lowres);
00114 s->height= -((-height)>>s->lowres);
00115 }
00116
00117 typedef struct InternalBuffer{
00118 int last_pic_num;
00119 uint8_t *base[4];
00120 uint8_t *data[4];
00121 int linesize[4];
00122 int width, height;
00123 enum PixelFormat pix_fmt;
00124 }InternalBuffer;
00125
00126 #define INTERNAL_BUFFER_SIZE (32+1)
00127
00128 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
00129 int w_align= 1;
00130 int h_align= 1;
00131
00132 switch(s->pix_fmt){
00133 case PIX_FMT_YUV420P:
00134 case PIX_FMT_YUYV422:
00135 case PIX_FMT_UYVY422:
00136 case PIX_FMT_YUV422P:
00137 case PIX_FMT_YUV440P:
00138 case PIX_FMT_YUV444P:
00139 case PIX_FMT_GRAY8:
00140 case PIX_FMT_GRAY16BE:
00141 case PIX_FMT_GRAY16LE:
00142 case PIX_FMT_YUVJ420P:
00143 case PIX_FMT_YUVJ422P:
00144 case PIX_FMT_YUVJ440P:
00145 case PIX_FMT_YUVJ444P:
00146 case PIX_FMT_YUVA420P:
00147 case PIX_FMT_YUV420P9LE:
00148 case PIX_FMT_YUV420P9BE:
00149 case PIX_FMT_YUV420P10LE:
00150 case PIX_FMT_YUV420P10BE:
00151 case PIX_FMT_YUV422P10LE:
00152 case PIX_FMT_YUV422P10BE:
00153 case PIX_FMT_YUV444P9LE:
00154 case PIX_FMT_YUV444P9BE:
00155 case PIX_FMT_YUV444P10LE:
00156 case PIX_FMT_YUV444P10BE:
00157 w_align= 16;
00158 h_align= 16;
00159 if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264)
00160 h_align= 32;
00161 break;
00162 case PIX_FMT_YUV411P:
00163 case PIX_FMT_UYYVYY411:
00164 w_align=32;
00165 h_align=8;
00166 break;
00167 case PIX_FMT_YUV410P:
00168 if(s->codec_id == CODEC_ID_SVQ1){
00169 w_align=64;
00170 h_align=64;
00171 }
00172 case PIX_FMT_RGB555:
00173 if(s->codec_id == CODEC_ID_RPZA){
00174 w_align=4;
00175 h_align=4;
00176 }
00177 case PIX_FMT_PAL8:
00178 case PIX_FMT_BGR8:
00179 case PIX_FMT_RGB8:
00180 if(s->codec_id == CODEC_ID_SMC){
00181 w_align=4;
00182 h_align=4;
00183 }
00184 break;
00185 case PIX_FMT_BGR24:
00186 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
00187 w_align=4;
00188 h_align=4;
00189 }
00190 break;
00191 default:
00192 w_align= 1;
00193 h_align= 1;
00194 break;
00195 }
00196
00197 *width = FFALIGN(*width , w_align);
00198 *height= FFALIGN(*height, h_align);
00199 if(s->codec_id == CODEC_ID_H264 || s->lowres)
00200 *height+=2;
00201
00202
00203 linesize_align[0] =
00204 linesize_align[1] =
00205 linesize_align[2] =
00206 linesize_align[3] = STRIDE_ALIGN;
00207
00208
00209
00210
00211 #if HAVE_MMX
00212 if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
00213 s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
00214 s->codec_id == CODEC_ID_VP6A) {
00215 linesize_align[0] =
00216 linesize_align[1] =
00217 linesize_align[2] = 16;
00218 }
00219 #endif
00220 }
00221
00222 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
00223 int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
00224 int linesize_align[4];
00225 int align;
00226 avcodec_align_dimensions2(s, width, height, linesize_align);
00227 align = FFMAX(linesize_align[0], linesize_align[3]);
00228 linesize_align[1] <<= chroma_shift;
00229 linesize_align[2] <<= chroma_shift;
00230 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
00231 *width=FFALIGN(*width, align);
00232 }
00233
00234 #if LIBAVCODEC_VERSION_MAJOR < 53
00235 int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
00236 return av_image_check_size(w, h, 0, av_log_ctx);
00237 }
00238 #endif
00239
00240 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
00241 int i;
00242 int w= s->width;
00243 int h= s->height;
00244 InternalBuffer *buf;
00245 int *picture_number;
00246
00247 if(pic->data[0]!=NULL) {
00248 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
00249 return -1;
00250 }
00251 if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
00252 av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
00253 return -1;
00254 }
00255
00256 if(av_image_check_size(w, h, 0, s))
00257 return -1;
00258
00259 if(s->internal_buffer==NULL){
00260 s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
00261 }
00262 #if 0
00263 s->internal_buffer= av_fast_realloc(
00264 s->internal_buffer,
00265 &s->internal_buffer_size,
00266 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)
00267 );
00268 #endif
00269
00270 buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
00271 picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num;
00272 (*picture_number)++;
00273
00274 if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
00275 if(s->active_thread_type&FF_THREAD_FRAME) {
00276 av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
00277 return -1;
00278 }
00279
00280 for(i=0; i<4; i++){
00281 av_freep(&buf->base[i]);
00282 buf->data[i]= NULL;
00283 }
00284 }
00285
00286 if(buf->base[0]){
00287 pic->age= *picture_number - buf->last_pic_num;
00288 buf->last_pic_num= *picture_number;
00289 }else{
00290 int h_chroma_shift, v_chroma_shift;
00291 int size[4] = {0};
00292 int tmpsize;
00293 int unaligned;
00294 AVPicture picture;
00295 int stride_align[4];
00296 const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;
00297
00298 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
00299
00300 avcodec_align_dimensions2(s, &w, &h, stride_align);
00301
00302 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
00303 w+= EDGE_WIDTH*2;
00304 h+= EDGE_WIDTH*2;
00305 }
00306
00307 do {
00308
00309
00310 av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
00311
00312 w += w & ~(w-1);
00313
00314 unaligned = 0;
00315 for (i=0; i<4; i++){
00316 unaligned |= picture.linesize[i] % stride_align[i];
00317 }
00318 } while (unaligned);
00319
00320 tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
00321 if (tmpsize < 0)
00322 return -1;
00323
00324 for (i=0; i<3 && picture.data[i+1]; i++)
00325 size[i] = picture.data[i+1] - picture.data[i];
00326 size[i] = tmpsize - (picture.data[i] - picture.data[0]);
00327
00328 buf->last_pic_num= -256*256*256*64;
00329 memset(buf->base, 0, sizeof(buf->base));
00330 memset(buf->data, 0, sizeof(buf->data));
00331
00332 for(i=0; i<4 && size[i]; i++){
00333 const int h_shift= i==0 ? 0 : h_chroma_shift;
00334 const int v_shift= i==0 ? 0 : v_chroma_shift;
00335
00336 buf->linesize[i]= picture.linesize[i];
00337
00338 buf->base[i]= av_malloc(size[i]+16);
00339 if(buf->base[i]==NULL) return -1;
00340 memset(buf->base[i], 128, size[i]);
00341
00342
00343 if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
00344 buf->data[i] = buf->base[i];
00345 else
00346 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]);
00347 }
00348 if(size[1] && !size[2])
00349 ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
00350 buf->width = s->width;
00351 buf->height = s->height;
00352 buf->pix_fmt= s->pix_fmt;
00353 pic->age= 256*256*256*64;
00354 }
00355 pic->type= FF_BUFFER_TYPE_INTERNAL;
00356
00357 for(i=0; i<4; i++){
00358 pic->base[i]= buf->base[i];
00359 pic->data[i]= buf->data[i];
00360 pic->linesize[i]= buf->linesize[i];
00361 }
00362 s->internal_buffer_count++;
00363
00364 if (s->pkt) {
00365 pic->pkt_pts = s->pkt->pts;
00366 pic->pkt_pos = s->pkt->pos;
00367 } else {
00368 pic->pkt_pts = AV_NOPTS_VALUE;
00369 pic->pkt_pos = -1;
00370 }
00371 pic->reordered_opaque= s->reordered_opaque;
00372 pic->sample_aspect_ratio = s->sample_aspect_ratio;
00373 pic->width = s->width;
00374 pic->height = s->height;
00375 pic->format = s->pix_fmt;
00376
00377 if(s->debug&FF_DEBUG_BUFFERS)
00378 av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
00379
00380 return 0;
00381 }
00382
00383 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
00384 int i;
00385 InternalBuffer *buf, *last;
00386
00387 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
00388 assert(s->internal_buffer_count);
00389
00390 if(s->internal_buffer){
00391 buf = NULL;
00392 for(i=0; i<s->internal_buffer_count; i++){
00393 buf= &((InternalBuffer*)s->internal_buffer)[i];
00394 if(buf->data[0] == pic->data[0])
00395 break;
00396 }
00397 assert(i < s->internal_buffer_count);
00398 s->internal_buffer_count--;
00399 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
00400
00401 FFSWAP(InternalBuffer, *buf, *last);
00402 }
00403
00404 for(i=0; i<4; i++){
00405 pic->data[i]=NULL;
00406
00407 }
00408
00409
00410 if(s->debug&FF_DEBUG_BUFFERS)
00411 av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
00412 }
00413
00414 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
00415 AVFrame temp_pic;
00416 int i;
00417
00418
00419 if(pic->data[0] == NULL) {
00420
00421 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
00422 return s->get_buffer(s, pic);
00423 }
00424
00425
00426 if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
00427 if(s->pkt) pic->pkt_pts= s->pkt->pts;
00428 else pic->pkt_pts= AV_NOPTS_VALUE;
00429 pic->reordered_opaque= s->reordered_opaque;
00430 return 0;
00431 }
00432
00433
00434
00435
00436 temp_pic = *pic;
00437 for(i = 0; i < 4; i++)
00438 pic->data[i] = pic->base[i] = NULL;
00439 pic->opaque = NULL;
00440
00441 if (s->get_buffer(s, pic))
00442 return -1;
00443
00444 av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
00445 s->height);
00446 s->release_buffer(s, &temp_pic);
00447 return 0;
00448 }
00449
00450 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
00451 int i;
00452
00453 for(i=0; i<count; i++){
00454 int r= func(c, (char*)arg + i*size);
00455 if(ret) ret[i]= r;
00456 }
00457 return 0;
00458 }
00459
00460 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
00461 int i;
00462
00463 for(i=0; i<count; i++){
00464 int r= func(c, arg, i, 0);
00465 if(ret) ret[i]= r;
00466 }
00467 return 0;
00468 }
00469
00470 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
00471 while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
00472 ++fmt;
00473 return fmt[0];
00474 }
00475
00476 void avcodec_get_frame_defaults(AVFrame *pic){
00477 memset(pic, 0, sizeof(AVFrame));
00478
00479 pic->pts = pic->best_effort_timestamp = AV_NOPTS_VALUE;
00480 pic->pkt_pos = -1;
00481 pic->key_frame= 1;
00482 pic->sample_aspect_ratio = (AVRational){0, 1};
00483 pic->format = -1;
00484 }
00485
00486 AVFrame *avcodec_alloc_frame(void){
00487 AVFrame *pic= av_malloc(sizeof(AVFrame));
00488
00489 if(pic==NULL) return NULL;
00490
00491 avcodec_get_frame_defaults(pic);
00492
00493 return pic;
00494 }
00495
00496 static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
00497 {
00498 memset(sub, 0, sizeof(*sub));
00499 sub->pts = AV_NOPTS_VALUE;
00500 }
00501
00502 #if FF_API_AVCODEC_OPEN
00503 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
00504 {
00505 return avcodec_open2(avctx, codec, NULL);
00506 }
00507 #endif
00508
00509 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
00510 {
00511 int ret = 0;
00512 AVDictionary *tmp = NULL;
00513
00514 if (options)
00515 av_dict_copy(&tmp, *options, 0);
00516
00517
00518 if (ff_lockmgr_cb) {
00519 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
00520 return -1;
00521 }
00522
00523 entangled_thread_counter++;
00524 if(entangled_thread_counter != 1){
00525 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
00526 ret = -1;
00527 goto end;
00528 }
00529
00530 if(avctx->codec || !codec) {
00531 ret = AVERROR(EINVAL);
00532 goto end;
00533 }
00534
00535 if (codec->priv_data_size > 0) {
00536 if(!avctx->priv_data){
00537 avctx->priv_data = av_mallocz(codec->priv_data_size);
00538 if (!avctx->priv_data) {
00539 ret = AVERROR(ENOMEM);
00540 goto end;
00541 }
00542 if (codec->priv_class) {
00543 *(AVClass**)avctx->priv_data= codec->priv_class;
00544 av_opt_set_defaults(avctx->priv_data);
00545 }
00546 }
00547 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
00548 goto free_and_end;
00549 } else {
00550 avctx->priv_data = NULL;
00551 }
00552 if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
00553 goto free_and_end;
00554
00555 if(avctx->coded_width && avctx->coded_height)
00556 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
00557 else if(avctx->width && avctx->height)
00558 avcodec_set_dimensions(avctx, avctx->width, avctx->height);
00559
00560 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
00561 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
00562 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
00563 av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
00564 avcodec_set_dimensions(avctx, 0, 0);
00565 }
00566
00567
00568
00569 if (codec->decode)
00570 av_freep(&avctx->subtitle_header);
00571
00572 #define SANE_NB_CHANNELS 128U
00573 if (avctx->channels > SANE_NB_CHANNELS) {
00574 ret = AVERROR(EINVAL);
00575 goto free_and_end;
00576 }
00577
00578 avctx->codec = codec;
00579 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
00580 avctx->codec_id == CODEC_ID_NONE) {
00581 avctx->codec_type = codec->type;
00582 avctx->codec_id = codec->id;
00583 }
00584 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
00585 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
00586 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
00587 ret = AVERROR(EINVAL);
00588 goto free_and_end;
00589 }
00590 avctx->frame_number = 0;
00591
00592 if (HAVE_THREADS && !avctx->thread_opaque) {
00593 ret = ff_thread_init(avctx);
00594 if (ret < 0) {
00595 goto free_and_end;
00596 }
00597 }
00598
00599 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
00600 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
00601 avctx->codec->max_lowres);
00602 ret = AVERROR(EINVAL);
00603 goto free_and_end;
00604 }
00605 if (avctx->codec->encode) {
00606 int i;
00607 if (avctx->codec->sample_fmts) {
00608 if (avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
00609 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
00610 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
00611 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
00612 break;
00613 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
00614 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
00615 ret = AVERROR(EINVAL);
00616 goto free_and_end;
00617 }
00618 }
00619 if (avctx->codec->supported_samplerates) {
00620 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
00621 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
00622 break;
00623 if (avctx->codec->supported_samplerates[i] == 0) {
00624 av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
00625 ret = AVERROR(EINVAL);
00626 goto free_and_end;
00627 }
00628 }
00629 if (avctx->codec->channel_layouts) {
00630 if (!avctx->channel_layout) {
00631 av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
00632 } else {
00633 for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
00634 if (avctx->channel_layout == avctx->codec->channel_layouts[i])
00635 break;
00636 if (avctx->codec->channel_layouts[i] == 0) {
00637 av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
00638 ret = AVERROR(EINVAL);
00639 goto free_and_end;
00640 }
00641 }
00642 }
00643 if (avctx->channel_layout && avctx->channels) {
00644 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
00645 av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
00646 ret = AVERROR(EINVAL);
00647 goto free_and_end;
00648 }
00649 } else if (avctx->channel_layout) {
00650 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
00651 }
00652 }
00653
00654 avctx->pts_correction_num_faulty_pts =
00655 avctx->pts_correction_num_faulty_dts = 0;
00656 avctx->pts_correction_last_pts =
00657 avctx->pts_correction_last_dts = INT64_MIN;
00658
00659 if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
00660 ret = avctx->codec->init(avctx);
00661 if (ret < 0) {
00662 goto free_and_end;
00663 }
00664 }
00665
00666 ret=0;
00667 end:
00668 entangled_thread_counter--;
00669
00670
00671 if (ff_lockmgr_cb) {
00672 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
00673 }
00674 if (options) {
00675 av_dict_free(options);
00676 *options = tmp;
00677 }
00678
00679 return ret;
00680 free_and_end:
00681 av_dict_free(&tmp);
00682 av_freep(&avctx->priv_data);
00683 avctx->codec= NULL;
00684 goto end;
00685 }
00686
00687 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
00688 const short *samples)
00689 {
00690 if(buf_size < FF_MIN_BUFFER_SIZE && 0){
00691 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
00692 return -1;
00693 }
00694 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
00695 int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
00696 avctx->frame_number++;
00697 return ret;
00698 }else
00699 return 0;
00700 }
00701
00702 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
00703 const AVFrame *pict)
00704 {
00705 if(buf_size < FF_MIN_BUFFER_SIZE){
00706 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
00707 return -1;
00708 }
00709 if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
00710 return -1;
00711 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
00712 int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
00713 avctx->frame_number++;
00714 emms_c();
00715
00716 return ret;
00717 }else
00718 return 0;
00719 }
00720
00721 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
00722 const AVSubtitle *sub)
00723 {
00724 int ret;
00725 if(sub->start_display_time) {
00726 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
00727 return -1;
00728 }
00729
00730 ret = avctx->codec->encode(avctx, buf, buf_size, sub);
00731 avctx->frame_number++;
00732 return ret;
00733 }
00734
00745 static int64_t guess_correct_pts(AVCodecContext *ctx,
00746 int64_t reordered_pts, int64_t dts)
00747 {
00748 int64_t pts = AV_NOPTS_VALUE;
00749
00750 if (dts != AV_NOPTS_VALUE) {
00751 ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
00752 ctx->pts_correction_last_dts = dts;
00753 }
00754 if (reordered_pts != AV_NOPTS_VALUE) {
00755 ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
00756 ctx->pts_correction_last_pts = reordered_pts;
00757 }
00758 if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
00759 && reordered_pts != AV_NOPTS_VALUE)
00760 pts = reordered_pts;
00761 else
00762 pts = dts;
00763
00764 return pts;
00765 }
00766
00767 #if FF_API_VIDEO_OLD
00768 int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
00769 int *got_picture_ptr,
00770 const uint8_t *buf, int buf_size)
00771 {
00772 AVPacket avpkt;
00773 av_init_packet(&avpkt);
00774 avpkt.data = buf;
00775 avpkt.size = buf_size;
00776
00777 avpkt.flags = AV_PKT_FLAG_KEY;
00778
00779 return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
00780 }
00781 #endif
00782
00783 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
00784 int *got_picture_ptr,
00785 AVPacket *avpkt)
00786 {
00787 int ret;
00788
00789 *got_picture_ptr= 0;
00790 if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
00791 return -1;
00792
00793 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
00794 avctx->pkt = avpkt;
00795 if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
00796 ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
00797 avpkt);
00798 else {
00799 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
00800 avpkt);
00801 picture->pkt_dts= avpkt->dts;
00802
00803 if(!avctx->has_b_frames){
00804 picture->pkt_pos= avpkt->pos;
00805 }
00806
00807 if (!picture->sample_aspect_ratio.num)
00808 picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
00809 if (!picture->width)
00810 picture->width = avctx->width;
00811 if (!picture->height)
00812 picture->height = avctx->height;
00813 if (picture->format == PIX_FMT_NONE)
00814 picture->format = avctx->pix_fmt;
00815 }
00816
00817 emms_c();
00818
00819
00820 if (*got_picture_ptr){
00821 avctx->frame_number++;
00822 picture->best_effort_timestamp = guess_correct_pts(avctx,
00823 picture->pkt_pts,
00824 picture->pkt_dts);
00825 }
00826 }else
00827 ret= 0;
00828
00829 return ret;
00830 }
00831
00832 #if FF_API_AUDIO_OLD
00833 int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
00834 int *frame_size_ptr,
00835 const uint8_t *buf, int buf_size)
00836 {
00837 AVPacket avpkt;
00838 av_init_packet(&avpkt);
00839 avpkt.data = buf;
00840 avpkt.size = buf_size;
00841
00842 return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
00843 }
00844 #endif
00845
00846 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
00847 int *frame_size_ptr,
00848 AVPacket *avpkt)
00849 {
00850 int ret;
00851
00852 avctx->pkt = avpkt;
00853
00854 if (!avpkt->data && avpkt->size) {
00855 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
00856 return AVERROR(EINVAL);
00857 }
00858
00859 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
00860
00861 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
00862 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
00863 return -1;
00864 }
00865 if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
00866 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
00867 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
00868 return -1;
00869 }
00870
00871 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
00872 avctx->frame_number++;
00873 }else{
00874 ret= 0;
00875 *frame_size_ptr=0;
00876 }
00877 return ret;
00878 }
00879
00880 #if FF_API_SUBTITLE_OLD
00881 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
00882 int *got_sub_ptr,
00883 const uint8_t *buf, int buf_size)
00884 {
00885 AVPacket avpkt;
00886 av_init_packet(&avpkt);
00887 avpkt.data = buf;
00888 avpkt.size = buf_size;
00889
00890 return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
00891 }
00892 #endif
00893
00894 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
00895 int *got_sub_ptr,
00896 AVPacket *avpkt)
00897 {
00898 int ret;
00899
00900 avctx->pkt = avpkt;
00901 *got_sub_ptr = 0;
00902 avcodec_get_subtitle_defaults(sub);
00903 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
00904 if (*got_sub_ptr)
00905 avctx->frame_number++;
00906 return ret;
00907 }
00908
00909 void avsubtitle_free(AVSubtitle *sub)
00910 {
00911 int i;
00912
00913 for (i = 0; i < sub->num_rects; i++)
00914 {
00915 av_freep(&sub->rects[i]->pict.data[0]);
00916 av_freep(&sub->rects[i]->pict.data[1]);
00917 av_freep(&sub->rects[i]->pict.data[2]);
00918 av_freep(&sub->rects[i]->pict.data[3]);
00919 av_freep(&sub->rects[i]->text);
00920 av_freep(&sub->rects[i]->ass);
00921 av_freep(&sub->rects[i]);
00922 }
00923
00924 av_freep(&sub->rects);
00925
00926 memset(sub, 0, sizeof(AVSubtitle));
00927 }
00928
00929 av_cold int avcodec_close(AVCodecContext *avctx)
00930 {
00931
00932 if (ff_lockmgr_cb) {
00933 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
00934 return -1;
00935 }
00936
00937 entangled_thread_counter++;
00938 if(entangled_thread_counter != 1){
00939 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
00940 entangled_thread_counter--;
00941 return -1;
00942 }
00943
00944 if (HAVE_THREADS && avctx->thread_opaque)
00945 ff_thread_free(avctx);
00946 if (avctx->codec && avctx->codec->close)
00947 avctx->codec->close(avctx);
00948 avcodec_default_free_buffers(avctx);
00949 avctx->coded_frame = NULL;
00950 if (avctx->codec && avctx->codec->priv_class)
00951 av_opt_free(avctx->priv_data);
00952 av_opt_free(avctx);
00953 av_freep(&avctx->priv_data);
00954 if(avctx->codec && avctx->codec->encode)
00955 av_freep(&avctx->extradata);
00956 avctx->codec = NULL;
00957 avctx->active_thread_type = 0;
00958 entangled_thread_counter--;
00959
00960
00961 if (ff_lockmgr_cb) {
00962 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
00963 }
00964 return 0;
00965 }
00966
00967 AVCodec *avcodec_find_encoder(enum CodecID id)
00968 {
00969 AVCodec *p, *experimental=NULL;
00970 p = first_avcodec;
00971 while (p) {
00972 if (p->encode != NULL && p->id == id) {
00973 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
00974 experimental = p;
00975 } else
00976 return p;
00977 }
00978 p = p->next;
00979 }
00980 return experimental;
00981 }
00982
00983 AVCodec *avcodec_find_encoder_by_name(const char *name)
00984 {
00985 AVCodec *p;
00986 if (!name)
00987 return NULL;
00988 p = first_avcodec;
00989 while (p) {
00990 if (p->encode != NULL && strcmp(name,p->name) == 0)
00991 return p;
00992 p = p->next;
00993 }
00994 return NULL;
00995 }
00996
00997 AVCodec *avcodec_find_decoder(enum CodecID id)
00998 {
00999 AVCodec *p, *experimental=NULL;
01000 p = first_avcodec;
01001 while (p) {
01002 if (p->decode != NULL && p->id == id) {
01003 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
01004 experimental = p;
01005 } else
01006 return p;
01007 }
01008 p = p->next;
01009 }
01010 return experimental;
01011 }
01012
01013 AVCodec *avcodec_find_decoder_by_name(const char *name)
01014 {
01015 AVCodec *p;
01016 if (!name)
01017 return NULL;
01018 p = first_avcodec;
01019 while (p) {
01020 if (p->decode != NULL && strcmp(name,p->name) == 0)
01021 return p;
01022 p = p->next;
01023 }
01024 return NULL;
01025 }
01026
01027 static int get_bit_rate(AVCodecContext *ctx)
01028 {
01029 int bit_rate;
01030 int bits_per_sample;
01031
01032 switch(ctx->codec_type) {
01033 case AVMEDIA_TYPE_VIDEO:
01034 case AVMEDIA_TYPE_DATA:
01035 case AVMEDIA_TYPE_SUBTITLE:
01036 case AVMEDIA_TYPE_ATTACHMENT:
01037 bit_rate = ctx->bit_rate;
01038 break;
01039 case AVMEDIA_TYPE_AUDIO:
01040 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
01041 bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
01042 break;
01043 default:
01044 bit_rate = 0;
01045 break;
01046 }
01047 return bit_rate;
01048 }
01049
01050 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
01051 {
01052 int i, len, ret = 0;
01053
01054 for (i = 0; i < 4; i++) {
01055 len = snprintf(buf, buf_size,
01056 isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
01057 buf += len;
01058 buf_size = buf_size > len ? buf_size - len : 0;
01059 ret += len;
01060 codec_tag>>=8;
01061 }
01062 return ret;
01063 }
01064
01065 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
01066 {
01067 const char *codec_name;
01068 const char *profile = NULL;
01069 AVCodec *p;
01070 char buf1[32];
01071 int bitrate;
01072 AVRational display_aspect_ratio;
01073
01074 if (encode)
01075 p = avcodec_find_encoder(enc->codec_id);
01076 else
01077 p = avcodec_find_decoder(enc->codec_id);
01078
01079 if (p) {
01080 codec_name = p->name;
01081 profile = av_get_profile_name(p, enc->profile);
01082 } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
01083
01084
01085 codec_name = "mpeg2ts";
01086 } else if (enc->codec_name[0] != '\0') {
01087 codec_name = enc->codec_name;
01088 } else {
01089
01090 char tag_buf[32];
01091 av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
01092 snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
01093 codec_name = buf1;
01094 }
01095
01096 switch(enc->codec_type) {
01097 case AVMEDIA_TYPE_VIDEO:
01098 snprintf(buf, buf_size,
01099 "Video: %s%s",
01100 codec_name, enc->mb_decision ? " (hq)" : "");
01101 if (profile)
01102 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01103 " (%s)", profile);
01104 if (enc->pix_fmt != PIX_FMT_NONE) {
01105 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01106 ", %s",
01107 av_get_pix_fmt_name(enc->pix_fmt));
01108 }
01109 if (enc->width) {
01110 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01111 ", %dx%d",
01112 enc->width, enc->height);
01113 if (enc->sample_aspect_ratio.num) {
01114 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
01115 enc->width*enc->sample_aspect_ratio.num,
01116 enc->height*enc->sample_aspect_ratio.den,
01117 1024*1024);
01118 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01119 " [PAR %d:%d DAR %d:%d]",
01120 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
01121 display_aspect_ratio.num, display_aspect_ratio.den);
01122 }
01123 if(av_log_get_level() >= AV_LOG_DEBUG){
01124 int g= av_gcd(enc->time_base.num, enc->time_base.den);
01125 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01126 ", %d/%d",
01127 enc->time_base.num/g, enc->time_base.den/g);
01128 }
01129 }
01130 if (encode) {
01131 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01132 ", q=%d-%d", enc->qmin, enc->qmax);
01133 }
01134 break;
01135 case AVMEDIA_TYPE_AUDIO:
01136 snprintf(buf, buf_size,
01137 "Audio: %s",
01138 codec_name);
01139 if (profile)
01140 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01141 " (%s)", profile);
01142 if (enc->sample_rate) {
01143 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01144 ", %d Hz", enc->sample_rate);
01145 }
01146 av_strlcat(buf, ", ", buf_size);
01147 av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
01148 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
01149 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01150 ", %s", av_get_sample_fmt_name(enc->sample_fmt));
01151 }
01152 break;
01153 case AVMEDIA_TYPE_DATA:
01154 snprintf(buf, buf_size, "Data: %s", codec_name);
01155 break;
01156 case AVMEDIA_TYPE_SUBTITLE:
01157 snprintf(buf, buf_size, "Subtitle: %s", codec_name);
01158 break;
01159 case AVMEDIA_TYPE_ATTACHMENT:
01160 snprintf(buf, buf_size, "Attachment: %s", codec_name);
01161 break;
01162 default:
01163 snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
01164 return;
01165 }
01166 if (encode) {
01167 if (enc->flags & CODEC_FLAG_PASS1)
01168 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01169 ", pass 1");
01170 if (enc->flags & CODEC_FLAG_PASS2)
01171 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01172 ", pass 2");
01173 }
01174 bitrate = get_bit_rate(enc);
01175 if (bitrate != 0) {
01176 snprintf(buf + strlen(buf), buf_size - strlen(buf),
01177 ", %d kb/s", bitrate / 1000);
01178 }
01179 }
01180
01181 const char *av_get_profile_name(const AVCodec *codec, int profile)
01182 {
01183 const AVProfile *p;
01184 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
01185 return NULL;
01186
01187 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
01188 if (p->profile == profile)
01189 return p->name;
01190
01191 return NULL;
01192 }
01193
01194 unsigned avcodec_version( void )
01195 {
01196 return LIBAVCODEC_VERSION_INT;
01197 }
01198
01199 const char *avcodec_configuration(void)
01200 {
01201 return FFMPEG_CONFIGURATION;
01202 }
01203
01204 const char *avcodec_license(void)
01205 {
01206 #define LICENSE_PREFIX "libavcodec license: "
01207 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
01208 }
01209
01210 void avcodec_init(void)
01211 {
01212 static int initialized = 0;
01213
01214 if (initialized != 0)
01215 return;
01216 initialized = 1;
01217
01218 dsputil_static_init();
01219 }
01220
01221 void avcodec_flush_buffers(AVCodecContext *avctx)
01222 {
01223 if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
01224 ff_thread_flush(avctx);
01225 else if(avctx->codec->flush)
01226 avctx->codec->flush(avctx);
01227 }
01228
01229 void avcodec_default_free_buffers(AVCodecContext *s){
01230 int i, j;
01231
01232 if(s->internal_buffer==NULL) return;
01233
01234 if (s->internal_buffer_count)
01235 av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
01236 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
01237 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
01238 for(j=0; j<4; j++){
01239 av_freep(&buf->base[j]);
01240 buf->data[j]= NULL;
01241 }
01242 }
01243 av_freep(&s->internal_buffer);
01244
01245 s->internal_buffer_count=0;
01246 }
01247
01248 #if FF_API_OLD_FF_PICT_TYPES
01249 char av_get_pict_type_char(int pict_type){
01250 return av_get_picture_type_char(pict_type);
01251 }
01252 #endif
01253
01254 int av_get_bits_per_sample(enum CodecID codec_id){
01255 switch(codec_id){
01256 case CODEC_ID_ADPCM_SBPRO_2:
01257 return 2;
01258 case CODEC_ID_ADPCM_SBPRO_3:
01259 return 3;
01260 case CODEC_ID_ADPCM_SBPRO_4:
01261 case CODEC_ID_ADPCM_CT:
01262 case CODEC_ID_ADPCM_IMA_WAV:
01263 case CODEC_ID_ADPCM_MS:
01264 case CODEC_ID_ADPCM_YAMAHA:
01265 return 4;
01266 case CODEC_ID_ADPCM_G722:
01267 case CODEC_ID_PCM_ALAW:
01268 case CODEC_ID_PCM_MULAW:
01269 case CODEC_ID_PCM_S8:
01270 case CODEC_ID_PCM_U8:
01271 case CODEC_ID_PCM_ZORK:
01272 return 8;
01273 case CODEC_ID_PCM_S16BE:
01274 case CODEC_ID_PCM_S16LE:
01275 case CODEC_ID_PCM_S16LE_PLANAR:
01276 case CODEC_ID_PCM_U16BE:
01277 case CODEC_ID_PCM_U16LE:
01278 return 16;
01279 case CODEC_ID_PCM_S24DAUD:
01280 case CODEC_ID_PCM_S24BE:
01281 case CODEC_ID_PCM_S24LE:
01282 case CODEC_ID_PCM_U24BE:
01283 case CODEC_ID_PCM_U24LE:
01284 return 24;
01285 case CODEC_ID_PCM_S32BE:
01286 case CODEC_ID_PCM_S32LE:
01287 case CODEC_ID_PCM_U32BE:
01288 case CODEC_ID_PCM_U32LE:
01289 case CODEC_ID_PCM_F32BE:
01290 case CODEC_ID_PCM_F32LE:
01291 return 32;
01292 case CODEC_ID_PCM_F64BE:
01293 case CODEC_ID_PCM_F64LE:
01294 return 64;
01295 default:
01296 return 0;
01297 }
01298 }
01299
01300 #if FF_API_OLD_SAMPLE_FMT
01301 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
01302 return av_get_bytes_per_sample(sample_fmt) << 3;
01303 }
01304 #endif
01305
01306 #if !HAVE_THREADS
01307 int ff_thread_init(AVCodecContext *s){
01308 return -1;
01309 }
01310 #endif
01311
01312 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
01313 {
01314 unsigned int n = 0;
01315
01316 while(v >= 0xff) {
01317 *s++ = 0xff;
01318 v -= 0xff;
01319 n++;
01320 }
01321 *s = v;
01322 n++;
01323 return n;
01324 }
01325
01326 #if LIBAVCODEC_VERSION_MAJOR < 53
01327 #include "libavutil/parseutils.h"
01328
01329 int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
01330 {
01331 return av_parse_video_size(width_ptr, height_ptr, str);
01332 }
01333
01334 int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
01335 {
01336 return av_parse_video_rate(frame_rate, arg);
01337 }
01338 #endif
01339
01340 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
01341 int i;
01342 for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
01343 return i;
01344 }
01345
01346 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
01347 {
01348 av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
01349 "version to the newest one from Git. If the problem still "
01350 "occurs, it means that your file has a feature which has not "
01351 "been implemented.\n", feature);
01352 if(want_sample)
01353 av_log_ask_for_sample(avc, NULL);
01354 }
01355
01356 void av_log_ask_for_sample(void *avc, const char *msg, ...)
01357 {
01358 va_list argument_list;
01359
01360 va_start(argument_list, msg);
01361
01362 if (msg)
01363 av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
01364 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
01365 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
01366 "and contact the ffmpeg-devel mailing list.\n");
01367
01368 va_end(argument_list);
01369 }
01370
01371 static AVHWAccel *first_hwaccel = NULL;
01372
01373 void av_register_hwaccel(AVHWAccel *hwaccel)
01374 {
01375 AVHWAccel **p = &first_hwaccel;
01376 while (*p)
01377 p = &(*p)->next;
01378 *p = hwaccel;
01379 hwaccel->next = NULL;
01380 }
01381
01382 AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
01383 {
01384 return hwaccel ? hwaccel->next : first_hwaccel;
01385 }
01386
01387 AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
01388 {
01389 AVHWAccel *hwaccel=NULL;
01390
01391 while((hwaccel= av_hwaccel_next(hwaccel))){
01392 if ( hwaccel->id == codec_id
01393 && hwaccel->pix_fmt == pix_fmt)
01394 return hwaccel;
01395 }
01396 return NULL;
01397 }
01398
01399 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
01400 {
01401 if (ff_lockmgr_cb) {
01402 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
01403 return -1;
01404 }
01405
01406 ff_lockmgr_cb = cb;
01407
01408 if (ff_lockmgr_cb) {
01409 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
01410 return -1;
01411 }
01412 return 0;
01413 }
01414
01415 unsigned int ff_toupper4(unsigned int x)
01416 {
01417 return toupper( x &0xFF)
01418 + (toupper((x>>8 )&0xFF)<<8 )
01419 + (toupper((x>>16)&0xFF)<<16)
01420 + (toupper((x>>24)&0xFF)<<24);
01421 }
01422
01423 #if !HAVE_PTHREADS
01424
01425 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
01426 {
01427 f->owner = avctx;
01428 return avctx->get_buffer(avctx, f);
01429 }
01430
01431 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
01432 {
01433 f->owner->release_buffer(f->owner, f);
01434 }
01435
01436 void ff_thread_finish_setup(AVCodecContext *avctx)
01437 {
01438 }
01439
01440 void ff_thread_report_progress(AVFrame *f, int progress, int field)
01441 {
01442 }
01443
01444 void ff_thread_await_progress(AVFrame *f, int progress, int field)
01445 {
01446 }
01447
01448 #endif
01449
01450 #if FF_API_THREAD_INIT
01451 int avcodec_thread_init(AVCodecContext *s, int thread_count)
01452 {
01453 s->thread_count = thread_count;
01454 return ff_thread_init(s);
01455 }
01456
01457 void avcodec_thread_free(AVCodecContext *s)
01458 {
01459 #if HAVE_THREADS
01460 ff_thread_free(s);
01461 #endif
01462 }
01463
01464 #endif