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