3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "libavutil/avstring.h"
29 #include "libavutil/crc.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/audioconvert.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/samplefmt.h"
35 #include "libavutil/dict.h"
38 #include "libavutil/opt.h"
39 #include "imgconvert.h"
41 #include "audioconvert.h"
48 static int volatile entangled_thread_counter=0;
49 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
50 static void *codec_mutex;
51 static void *avformat_mutex;
53 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
58 min_size= FFMAX(17*min_size/16 + 32, min_size);
60 ptr= av_realloc(ptr, min_size);
61 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
69 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
74 min_size= FFMAX(17*min_size/16 + 32, min_size);
76 *p = av_malloc(min_size);
77 if (!*p) min_size = 0;
81 /* encoder management */
82 static AVCodec *first_avcodec = NULL;
84 AVCodec *av_codec_next(AVCodec *c){
86 else return first_avcodec;
89 #if !FF_API_AVCODEC_INIT
92 void avcodec_init(void)
94 static int initialized = 0;
100 dsputil_static_init();
103 void avcodec_register(AVCodec *codec)
108 while (*p != NULL) p = &(*p)->next;
112 if (codec->init_static_data)
113 codec->init_static_data(codec);
116 unsigned avcodec_get_edge_width(void)
121 void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
122 s->coded_width = width;
123 s->coded_height= height;
124 s->width = -((-width )>>s->lowres);
125 s->height= -((-height)>>s->lowres);
128 #define INTERNAL_BUFFER_SIZE (32+1)
130 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
131 int linesize_align[AV_NUM_DATA_POINTERS])
138 case PIX_FMT_YUV420P:
139 case PIX_FMT_YUYV422:
140 case PIX_FMT_UYVY422:
141 case PIX_FMT_YUV422P:
142 case PIX_FMT_YUV440P:
143 case PIX_FMT_YUV444P:
146 case PIX_FMT_GRAY16BE:
147 case PIX_FMT_GRAY16LE:
148 case PIX_FMT_YUVJ420P:
149 case PIX_FMT_YUVJ422P:
150 case PIX_FMT_YUVJ440P:
151 case PIX_FMT_YUVJ444P:
152 case PIX_FMT_YUVA420P:
153 case PIX_FMT_YUV420P9LE:
154 case PIX_FMT_YUV420P9BE:
155 case PIX_FMT_YUV420P10LE:
156 case PIX_FMT_YUV420P10BE:
157 case PIX_FMT_YUV422P9LE:
158 case PIX_FMT_YUV422P9BE:
159 case PIX_FMT_YUV422P10LE:
160 case PIX_FMT_YUV422P10BE:
161 case PIX_FMT_YUV444P9LE:
162 case PIX_FMT_YUV444P9BE:
163 case PIX_FMT_YUV444P10LE:
164 case PIX_FMT_YUV444P10BE:
165 case PIX_FMT_GBRP9LE:
166 case PIX_FMT_GBRP9BE:
167 case PIX_FMT_GBRP10LE:
168 case PIX_FMT_GBRP10BE:
169 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
171 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 || s->codec_id == CODEC_ID_PRORES)
172 h_align= 32; // interlaced is rounded up to 2 MBs
174 case PIX_FMT_YUV411P:
175 case PIX_FMT_UYYVYY411:
179 case PIX_FMT_YUV410P:
180 if(s->codec_id == CODEC_ID_SVQ1){
185 if(s->codec_id == CODEC_ID_RPZA){
192 if(s->codec_id == CODEC_ID_SMC){
198 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
209 if(s->codec_id == CODEC_ID_IFF_ILBM || s->codec_id == CODEC_ID_IFF_BYTERUN1){
210 w_align= FFMAX(w_align, 8);
213 *width = FFALIGN(*width , w_align);
214 *height= FFALIGN(*height, h_align);
215 if(s->codec_id == CODEC_ID_H264 || s->lowres)
216 *height+=2; // some of the optimized chroma MC reads one line too much
217 // which is also done in mpeg decoders with lowres > 0
219 for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
220 linesize_align[i] = STRIDE_ALIGN;
221 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
222 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
223 //picture size unneccessarily in some cases. The solution here is not
224 //pretty and better ideas are welcome!
226 if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
227 s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
228 s->codec_id == CODEC_ID_VP6A || s->codec_id == CODEC_ID_DIRAC) {
229 for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
230 linesize_align[i] = 16;
235 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
236 int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
237 int linesize_align[AV_NUM_DATA_POINTERS];
239 avcodec_align_dimensions2(s, width, height, linesize_align);
240 align = FFMAX(linesize_align[0], linesize_align[3]);
241 linesize_align[1] <<= chroma_shift;
242 linesize_align[2] <<= chroma_shift;
243 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
244 *width=FFALIGN(*width, align);
247 void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic)
250 pic->pkt_pts = s->pkt->pts;
251 pic->pkt_pos = s->pkt->pos;
253 pic->pkt_pts = AV_NOPTS_VALUE;
256 pic->reordered_opaque= s->reordered_opaque;
257 pic->sample_aspect_ratio = s->sample_aspect_ratio;
258 pic->width = s->width;
259 pic->height = s->height;
260 pic->format = s->pix_fmt;
263 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
265 AVCodecInternal *avci = avctx->internal;
267 int buf_size, ret, i, needs_extended_data;
269 buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
270 frame->nb_samples, avctx->sample_fmt,
273 return AVERROR(EINVAL);
275 needs_extended_data = av_sample_fmt_is_planar(avctx->sample_fmt) &&
276 avctx->channels > AV_NUM_DATA_POINTERS;
278 /* allocate InternalBuffer if needed */
280 avci->buffer = av_mallocz(sizeof(InternalBuffer));
282 return AVERROR(ENOMEM);
286 /* if there is a previously-used internal buffer, check its size and
287 channel count to see if we can reuse it */
288 if (buf->extended_data) {
289 /* if current buffer is too small, free it */
290 if (buf->extended_data[0] && buf_size > buf->audio_data_size) {
291 av_free(buf->extended_data[0]);
292 if (buf->extended_data != buf->data)
293 av_free(&buf->extended_data);
294 buf->extended_data = NULL;
297 /* if number of channels has changed, reset and/or free extended data
298 pointers but leave data buffer in buf->data[0] for reuse */
299 if (buf->nb_channels != avctx->channels) {
300 if (buf->extended_data != buf->data)
301 av_free(buf->extended_data);
302 buf->extended_data = NULL;
306 /* if there is no previous buffer or the previous buffer cannot be used
307 as-is, allocate a new buffer and/or rearrange the channel pointers */
308 if (!buf->extended_data) {
309 /* if the channel pointers will fit, just set extended_data to data,
310 otherwise allocate the extended_data channel pointers */
311 if (needs_extended_data) {
312 buf->extended_data = av_mallocz(avctx->channels *
313 sizeof(*buf->extended_data));
314 if (!buf->extended_data)
315 return AVERROR(ENOMEM);
317 buf->extended_data = buf->data;
320 /* if there is a previous buffer and it is large enough, reuse it and
321 just fill-in new channel pointers and linesize, otherwise allocate
323 if (buf->extended_data[0]) {
324 ret = av_samples_fill_arrays(buf->extended_data, &buf->linesize[0],
325 buf->extended_data[0], avctx->channels,
326 frame->nb_samples, avctx->sample_fmt,
329 ret = av_samples_alloc(buf->extended_data, &buf->linesize[0],
330 avctx->channels, frame->nb_samples,
331 avctx->sample_fmt, 32);
336 /* if data was not used for extended_data, we need to copy as many of
337 the extended_data channel pointers as will fit */
338 if (needs_extended_data) {
339 for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
340 buf->data[i] = buf->extended_data[i];
342 buf->audio_data_size = buf_size;
343 buf->nb_channels = avctx->channels;
346 /* copy InternalBuffer info to the AVFrame */
347 frame->type = FF_BUFFER_TYPE_INTERNAL;
348 frame->extended_data = buf->extended_data;
349 frame->linesize[0] = buf->linesize[0];
350 memcpy(frame->data, buf->data, sizeof(frame->data));
353 frame->pkt_pts = avctx->pkt->pts;
354 frame->pkt_pos = avctx->pkt->pos;
356 frame->pkt_pts = AV_NOPTS_VALUE;
360 frame->reordered_opaque = avctx->reordered_opaque;
362 if (avctx->debug & FF_DEBUG_BUFFERS)
363 av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
364 "internal audio buffer used\n", frame);
369 static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
376 AVCodecInternal *avci = s->internal;
378 if(pic->data[0]!=NULL) {
379 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
382 if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) {
383 av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n");
387 if(av_image_check_size(w, h, 0, s))
391 avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE+1) *
392 sizeof(InternalBuffer));
395 buf = &avci->buffer[avci->buffer_count];
396 picture_number = &(avci->buffer[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
399 if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
400 if(s->active_thread_type&FF_THREAD_FRAME) {
401 av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
405 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
406 av_freep(&buf->base[i]);
412 pic->age= *picture_number - buf->last_pic_num;
413 buf->last_pic_num= *picture_number;
415 int h_chroma_shift, v_chroma_shift;
420 int stride_align[AV_NUM_DATA_POINTERS];
421 const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;
423 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
425 avcodec_align_dimensions2(s, &w, &h, stride_align);
427 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
433 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
434 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
435 av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
436 // increase alignment of w for next try (rhs gives the lowest bit set in w)
441 unaligned |= picture.linesize[i] % stride_align[i];
445 tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
449 for (i=0; i<3 && picture.data[i+1]; i++)
450 size[i] = picture.data[i+1] - picture.data[i];
451 size[i] = tmpsize - (picture.data[i] - picture.data[0]);
453 buf->last_pic_num= -256*256*256*64;
454 memset(buf->base, 0, sizeof(buf->base));
455 memset(buf->data, 0, sizeof(buf->data));
457 for(i=0; i<4 && size[i]; i++){
458 const int h_shift= i==0 ? 0 : h_chroma_shift;
459 const int v_shift= i==0 ? 0 : v_chroma_shift;
461 buf->linesize[i]= picture.linesize[i];
463 buf->base[i]= av_malloc(size[i]+16); //FIXME 16
464 if(buf->base[i]==NULL) return -1;
465 memset(buf->base[i], 128, size[i]);
467 // no edge if EDGE EMU or not planar YUV
468 if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
469 buf->data[i] = buf->base[i];
471 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]);
473 for (; i < AV_NUM_DATA_POINTERS; i++) {
474 buf->base[i] = buf->data[i] = NULL;
475 buf->linesize[i] = 0;
477 if(size[1] && !size[2])
478 ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
479 buf->width = s->width;
480 buf->height = s->height;
481 buf->pix_fmt= s->pix_fmt;
482 pic->age= 256*256*256*64;
484 pic->type= FF_BUFFER_TYPE_INTERNAL;
486 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
487 pic->base[i]= buf->base[i];
488 pic->data[i]= buf->data[i];
489 pic->linesize[i]= buf->linesize[i];
491 pic->extended_data = pic->data;
492 avci->buffer_count++;
495 pic->pkt_pts = s->pkt->pts;
496 pic->pkt_pos = s->pkt->pos;
498 pic->pkt_pts = AV_NOPTS_VALUE;
501 pic->reordered_opaque= s->reordered_opaque;
502 pic->sample_aspect_ratio = s->sample_aspect_ratio;
503 pic->width = s->width;
504 pic->height = s->height;
505 pic->format = s->pix_fmt;
507 if(s->debug&FF_DEBUG_BUFFERS)
508 av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
509 "buffers used\n", pic, avci->buffer_count);
514 int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
516 switch (avctx->codec_type) {
517 case AVMEDIA_TYPE_VIDEO:
518 return video_get_buffer(avctx, frame);
519 case AVMEDIA_TYPE_AUDIO:
520 return audio_get_buffer(avctx, frame);
526 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
528 InternalBuffer *buf, *last;
529 AVCodecInternal *avci = s->internal;
531 assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
533 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
534 assert(avci->buffer_count);
537 buf = NULL; /* avoids warning */
538 for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize
539 buf = &avci->buffer[i];
540 if (buf->data[0] == pic->data[0])
543 assert(i < avci->buffer_count);
544 avci->buffer_count--;
545 last = &avci->buffer[avci->buffer_count];
548 FFSWAP(InternalBuffer, *buf, *last);
551 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
553 // pic->base[i]=NULL;
555 //printf("R%X\n", pic->opaque);
557 if(s->debug&FF_DEBUG_BUFFERS)
558 av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
559 "buffers used\n", pic, avci->buffer_count);
562 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
566 assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
568 /* If no picture return a new buffer */
569 if(pic->data[0] == NULL) {
570 /* We will copy from buffer, so must be readable */
571 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
572 return s->get_buffer(s, pic);
575 /* If internal buffer type return the same buffer */
576 if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
577 if(s->pkt) pic->pkt_pts= s->pkt->pts;
578 else pic->pkt_pts= AV_NOPTS_VALUE;
579 pic->reordered_opaque= s->reordered_opaque;
584 * Not internal type and reget_buffer not overridden, emulate cr buffer
587 for(i = 0; i < AV_NUM_DATA_POINTERS; i++)
588 pic->data[i] = pic->base[i] = NULL;
590 /* Allocate new frame */
591 if (s->get_buffer(s, pic))
593 /* Copy image data from old buffer to new buffer */
594 av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
596 s->release_buffer(s, &temp_pic); // Release old frame
600 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
603 for(i=0; i<count; i++){
604 int r= func(c, (char*)arg + i*size);
610 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
613 for(i=0; i<count; i++){
614 int r= func(c, arg, i, 0);
620 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
621 while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
626 void avcodec_get_frame_defaults(AVFrame *pic){
627 memset(pic, 0, sizeof(AVFrame));
629 pic->pts = pic->pkt_dts = pic->pkt_pts = pic->best_effort_timestamp = AV_NOPTS_VALUE;
632 pic->sample_aspect_ratio = (AVRational){0, 1};
633 pic->format = -1; /* unknown */
636 AVFrame *avcodec_alloc_frame(void){
637 AVFrame *pic= av_malloc(sizeof(AVFrame));
639 if(pic==NULL) return NULL;
641 avcodec_get_frame_defaults(pic);
646 static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
648 memset(sub, 0, sizeof(*sub));
649 sub->pts = AV_NOPTS_VALUE;
652 #if FF_API_AVCODEC_OPEN
653 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
655 return avcodec_open2(avctx, codec, NULL);
659 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
662 AVDictionary *tmp = NULL;
665 av_dict_copy(&tmp, *options, 0);
667 /* If there is a user-supplied mutex locking routine, call it. */
669 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
673 entangled_thread_counter++;
674 if(entangled_thread_counter != 1){
675 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
680 if(avctx->codec || !codec) {
681 ret = AVERROR(EINVAL);
685 avctx->internal = av_mallocz(sizeof(AVCodecInternal));
686 if (!avctx->internal) {
687 ret = AVERROR(ENOMEM);
691 if (codec->priv_data_size > 0) {
692 if(!avctx->priv_data){
693 avctx->priv_data = av_mallocz(codec->priv_data_size);
694 if (!avctx->priv_data) {
695 ret = AVERROR(ENOMEM);
698 if (codec->priv_class) {
699 *(AVClass**)avctx->priv_data= codec->priv_class;
700 av_opt_set_defaults(avctx->priv_data);
703 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
706 avctx->priv_data = NULL;
708 if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
711 //We only call avcodec_set_dimensions() for non h264 codecs so as not to overwrite previously setup dimensions
712 if(!( avctx->coded_width && avctx->coded_height && avctx->width && avctx->height && avctx->codec_id == CODEC_ID_H264)){
713 if(avctx->coded_width && avctx->coded_height)
714 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
715 else if(avctx->width && avctx->height)
716 avcodec_set_dimensions(avctx, avctx->width, avctx->height);
719 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
720 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
721 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
722 av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
723 avcodec_set_dimensions(avctx, 0, 0);
726 /* if the decoder init function was already called previously,
727 free the already allocated subtitle_header before overwriting it */
729 av_freep(&avctx->subtitle_header);
731 #define SANE_NB_CHANNELS 128U
732 if (avctx->channels > SANE_NB_CHANNELS) {
733 ret = AVERROR(EINVAL);
737 avctx->codec = codec;
738 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
739 avctx->codec_id == CODEC_ID_NONE) {
740 avctx->codec_type = codec->type;
741 avctx->codec_id = codec->id;
743 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
744 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
745 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
746 ret = AVERROR(EINVAL);
749 avctx->frame_number = 0;
752 av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition separate: %d; %X\n",
753 avctx->error_recognition, avctx->err_recognition);
754 switch(avctx->error_recognition){
755 case FF_ER_EXPLODE : avctx->err_recognition |= AV_EF_EXPLODE | AV_EF_COMPLIANT | AV_EF_CAREFUL;
757 case FF_ER_VERY_AGGRESSIVE:
758 case FF_ER_AGGRESSIVE : avctx->err_recognition |= AV_EF_AGGRESSIVE;
759 case FF_ER_COMPLIANT : avctx->err_recognition |= AV_EF_COMPLIANT;
760 case FF_ER_CAREFUL : avctx->err_recognition |= AV_EF_CAREFUL;
763 av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition combined: %d; %X\n",
764 avctx->error_recognition, avctx->err_recognition);
768 av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
770 if (HAVE_THREADS && !avctx->thread_opaque) {
771 ret = ff_thread_init(avctx);
777 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
778 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
779 avctx->codec->max_lowres);
780 ret = AVERROR(EINVAL);
783 if (avctx->codec->encode) {
785 if (avctx->codec->sample_fmts) {
786 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
787 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
789 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
790 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
791 ret = AVERROR(EINVAL);
795 if (avctx->codec->supported_samplerates) {
796 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
797 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
799 if (avctx->codec->supported_samplerates[i] == 0) {
800 av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
801 ret = AVERROR(EINVAL);
805 if (avctx->codec->channel_layouts) {
806 if (!avctx->channel_layout) {
807 av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
809 for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
810 if (avctx->channel_layout == avctx->codec->channel_layouts[i])
812 if (avctx->codec->channel_layouts[i] == 0) {
813 av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
814 ret = AVERROR(EINVAL);
819 if (avctx->channel_layout && avctx->channels) {
820 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
821 av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
822 ret = AVERROR(EINVAL);
825 } else if (avctx->channel_layout) {
826 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
830 avctx->pts_correction_num_faulty_pts =
831 avctx->pts_correction_num_faulty_dts = 0;
832 avctx->pts_correction_last_pts =
833 avctx->pts_correction_last_dts = INT64_MIN;
835 if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
836 ret = avctx->codec->init(avctx);
844 entangled_thread_counter--;
846 /* Release any user-supplied mutex. */
848 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
851 av_dict_free(options);
858 av_freep(&avctx->priv_data);
859 av_freep(&avctx->internal);
864 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
865 const short *samples)
867 if(buf_size < FF_MIN_BUFFER_SIZE && 0){
868 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
871 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
872 int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
873 avctx->frame_number++;
879 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
882 if(buf_size < FF_MIN_BUFFER_SIZE){
883 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
886 if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
888 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
889 int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
890 avctx->frame_number++;
891 emms_c(); //needed to avoid an emms_c() call before every return;
898 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
899 const AVSubtitle *sub)
902 if(sub->start_display_time) {
903 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
907 ret = avctx->codec->encode(avctx, buf, buf_size, sub);
908 avctx->frame_number++;
913 * Attempt to guess proper monotonic timestamps for decoded video frames
914 * which might have incorrect times. Input timestamps may wrap around, in
915 * which case the output will as well.
917 * @param pts the pts field of the decoded AVPacket, as passed through
919 * @param dts the dts field of the decoded AVPacket
920 * @return one of the input values, may be AV_NOPTS_VALUE
922 static int64_t guess_correct_pts(AVCodecContext *ctx,
923 int64_t reordered_pts, int64_t dts)
925 int64_t pts = AV_NOPTS_VALUE;
927 if (dts != AV_NOPTS_VALUE) {
928 ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
929 ctx->pts_correction_last_dts = dts;
931 if (reordered_pts != AV_NOPTS_VALUE) {
932 ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
933 ctx->pts_correction_last_pts = reordered_pts;
935 if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
936 && reordered_pts != AV_NOPTS_VALUE)
944 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
945 int *got_picture_ptr,
951 if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
954 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
955 av_packet_split_side_data(avpkt);
957 if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
958 ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
961 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
963 picture->pkt_dts= avpkt->dts;
965 if(!avctx->has_b_frames){
966 picture->pkt_pos= avpkt->pos;
968 //FIXME these should be under if(!avctx->has_b_frames)
969 if (!picture->sample_aspect_ratio.num)
970 picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
972 picture->width = avctx->width;
973 if (!picture->height)
974 picture->height = avctx->height;
975 if (picture->format == PIX_FMT_NONE)
976 picture->format = avctx->pix_fmt;
979 emms_c(); //needed to avoid an emms_c() call before every return;
982 if (*got_picture_ptr){
983 avctx->frame_number++;
984 picture->best_effort_timestamp = guess_correct_pts(avctx,
994 #if FF_API_OLD_DECODE_AUDIO
995 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
1000 int ret, got_frame = 0;
1002 if (avctx->get_buffer != avcodec_default_get_buffer) {
1003 av_log(avctx, AV_LOG_ERROR, "A custom get_buffer() cannot be used with "
1004 "avcodec_decode_audio3()\n");
1005 return AVERROR(EINVAL);
1008 ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
1010 if (ret >= 0 && got_frame) {
1012 int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
1013 int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
1015 avctx->sample_fmt, 1);
1016 if (*frame_size_ptr < data_size) {
1017 av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
1018 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1019 return AVERROR(EINVAL);
1022 memcpy(samples, frame.extended_data[0], plane_size);
1024 if (planar && avctx->channels > 1) {
1025 uint8_t *out = ((uint8_t *)samples) + plane_size;
1026 for (ch = 1; ch < avctx->channels; ch++) {
1027 memcpy(out, frame.extended_data[ch], plane_size);
1031 *frame_size_ptr = data_size;
1033 *frame_size_ptr = 0;
1039 int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
1048 if (!avpkt->data && avpkt->size) {
1049 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1050 return AVERROR(EINVAL);
1053 if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1054 av_packet_split_side_data(avpkt);
1056 ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1057 if (ret >= 0 && *got_frame_ptr) {
1058 avctx->frame_number++;
1059 frame->pkt_dts = avpkt->dts;
1065 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
1073 avcodec_get_subtitle_defaults(sub);
1074 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1076 avctx->frame_number++;
1080 void avsubtitle_free(AVSubtitle *sub)
1084 for (i = 0; i < sub->num_rects; i++)
1086 av_freep(&sub->rects[i]->pict.data[0]);
1087 av_freep(&sub->rects[i]->pict.data[1]);
1088 av_freep(&sub->rects[i]->pict.data[2]);
1089 av_freep(&sub->rects[i]->pict.data[3]);
1090 av_freep(&sub->rects[i]->text);
1091 av_freep(&sub->rects[i]->ass);
1092 av_freep(&sub->rects[i]);
1095 av_freep(&sub->rects);
1097 memset(sub, 0, sizeof(AVSubtitle));
1100 av_cold int avcodec_close(AVCodecContext *avctx)
1102 /* If there is a user-supplied mutex locking routine, call it. */
1103 if (ff_lockmgr_cb) {
1104 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
1108 entangled_thread_counter++;
1109 if(entangled_thread_counter != 1){
1110 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1111 entangled_thread_counter--;
1115 if (HAVE_THREADS && avctx->thread_opaque)
1116 ff_thread_free(avctx);
1117 if (avctx->codec && avctx->codec->close)
1118 avctx->codec->close(avctx);
1119 avcodec_default_free_buffers(avctx);
1120 avctx->coded_frame = NULL;
1121 av_freep(&avctx->internal);
1122 if (avctx->codec && avctx->codec->priv_class)
1123 av_opt_free(avctx->priv_data);
1125 av_freep(&avctx->priv_data);
1126 if(avctx->codec && avctx->codec->encode)
1127 av_freep(&avctx->extradata);
1128 avctx->codec = NULL;
1129 avctx->active_thread_type = 0;
1130 entangled_thread_counter--;
1132 /* Release any user-supplied mutex. */
1133 if (ff_lockmgr_cb) {
1134 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1139 static enum CodecID remap_deprecated_codec_id(enum CodecID id)
1142 case CODEC_ID_G723_1_DEPRECATED : return CODEC_ID_G723_1;
1143 case CODEC_ID_G729_DEPRECATED : return CODEC_ID_G729;
1144 case CODEC_ID_UTVIDEO_DEPRECATED: return CODEC_ID_UTVIDEO;
1145 default : return id;
1149 AVCodec *avcodec_find_encoder(enum CodecID id)
1151 AVCodec *p, *experimental=NULL;
1153 id= remap_deprecated_codec_id(id);
1155 if (p->encode != NULL && p->id == id) {
1156 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1163 return experimental;
1166 AVCodec *avcodec_find_encoder_by_name(const char *name)
1173 if (p->encode != NULL && strcmp(name,p->name) == 0)
1180 AVCodec *avcodec_find_decoder(enum CodecID id)
1182 AVCodec *p, *experimental=NULL;
1184 id= remap_deprecated_codec_id(id);
1186 if (p->decode != NULL && p->id == id) {
1187 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1194 return experimental;
1197 AVCodec *avcodec_find_decoder_by_name(const char *name)
1204 if (p->decode != NULL && strcmp(name,p->name) == 0)
1211 static int get_bit_rate(AVCodecContext *ctx)
1214 int bits_per_sample;
1216 switch(ctx->codec_type) {
1217 case AVMEDIA_TYPE_VIDEO:
1218 case AVMEDIA_TYPE_DATA:
1219 case AVMEDIA_TYPE_SUBTITLE:
1220 case AVMEDIA_TYPE_ATTACHMENT:
1221 bit_rate = ctx->bit_rate;
1223 case AVMEDIA_TYPE_AUDIO:
1224 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1225 bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1234 const char *avcodec_get_name(enum CodecID id)
1240 #include "libavcodec/codec_names.h"
1242 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
1244 codec = avcodec_find_decoder(id);
1247 codec = avcodec_find_encoder(id);
1250 return "unknown_codec";
1253 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1255 int i, len, ret = 0;
1257 for (i = 0; i < 4; i++) {
1258 len = snprintf(buf, buf_size,
1259 isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
1261 buf_size = buf_size > len ? buf_size - len : 0;
1268 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1270 const char *codec_type;
1271 const char *codec_name;
1272 const char *profile = NULL;
1275 AVRational display_aspect_ratio;
1277 if (!buf || buf_size <= 0)
1279 codec_type = av_get_media_type_string(enc->codec_type);
1280 codec_name = avcodec_get_name(enc->codec_id);
1281 if (enc->profile != FF_PROFILE_UNKNOWN) {
1282 p = encode ? avcodec_find_encoder(enc->codec_id) :
1283 avcodec_find_decoder(enc->codec_id);
1285 profile = av_get_profile_name(p, enc->profile);
1288 snprintf(buf, buf_size, "%s: %s%s", codec_type ? codec_type : "unknown",
1289 codec_name, enc->mb_decision ? " (hq)" : "");
1290 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
1292 snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
1293 if (enc->codec_tag) {
1295 av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1296 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1297 " (%s / 0x%04X)", tag_buf, enc->codec_tag);
1299 switch(enc->codec_type) {
1300 case AVMEDIA_TYPE_VIDEO:
1301 if (enc->pix_fmt != PIX_FMT_NONE) {
1302 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1304 av_get_pix_fmt_name(enc->pix_fmt));
1307 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1309 enc->width, enc->height);
1310 if (enc->sample_aspect_ratio.num) {
1311 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1312 enc->width*enc->sample_aspect_ratio.num,
1313 enc->height*enc->sample_aspect_ratio.den,
1315 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1316 " [SAR %d:%d DAR %d:%d]",
1317 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
1318 display_aspect_ratio.num, display_aspect_ratio.den);
1320 if(av_log_get_level() >= AV_LOG_DEBUG){
1321 int g= av_gcd(enc->time_base.num, enc->time_base.den);
1322 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1324 enc->time_base.num/g, enc->time_base.den/g);
1328 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1329 ", q=%d-%d", enc->qmin, enc->qmax);
1332 case AVMEDIA_TYPE_AUDIO:
1333 if (enc->sample_rate) {
1334 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1335 ", %d Hz", enc->sample_rate);
1337 av_strlcat(buf, ", ", buf_size);
1338 av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1339 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1340 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1341 ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1348 if (enc->flags & CODEC_FLAG_PASS1)
1349 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1351 if (enc->flags & CODEC_FLAG_PASS2)
1352 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1355 bitrate = get_bit_rate(enc);
1357 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1358 ", %d kb/s", bitrate / 1000);
1362 const char *av_get_profile_name(const AVCodec *codec, int profile)
1365 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1368 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1369 if (p->profile == profile)
1375 unsigned avcodec_version( void )
1377 return LIBAVCODEC_VERSION_INT;
1380 const char *avcodec_configuration(void)
1382 return FFMPEG_CONFIGURATION;
1385 const char *avcodec_license(void)
1387 #define LICENSE_PREFIX "libavcodec license: "
1388 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1391 void avcodec_flush_buffers(AVCodecContext *avctx)
1393 if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
1394 ff_thread_flush(avctx);
1395 else if(avctx->codec->flush)
1396 avctx->codec->flush(avctx);
1399 static void video_free_buffers(AVCodecContext *s)
1401 AVCodecInternal *avci = s->internal;
1407 if (avci->buffer_count)
1408 av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n",
1409 avci->buffer_count);
1410 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
1411 InternalBuffer *buf = &avci->buffer[i];
1413 av_freep(&buf->base[j]);
1417 av_freep(&avci->buffer);
1419 avci->buffer_count=0;
1422 static void audio_free_buffers(AVCodecContext *avctx)
1424 AVCodecInternal *avci = avctx->internal;
1425 InternalBuffer *buf;
1431 if (buf->extended_data) {
1432 av_free(buf->extended_data[0]);
1433 if (buf->extended_data != buf->data)
1434 av_free(buf->extended_data);
1436 av_freep(&avci->buffer);
1439 void avcodec_default_free_buffers(AVCodecContext *avctx)
1441 switch (avctx->codec_type) {
1442 case AVMEDIA_TYPE_VIDEO:
1443 video_free_buffers(avctx);
1445 case AVMEDIA_TYPE_AUDIO:
1446 audio_free_buffers(avctx);
1453 #if FF_API_OLD_FF_PICT_TYPES
1454 char av_get_pict_type_char(int pict_type){
1455 return av_get_picture_type_char(pict_type);
1459 int av_get_bits_per_sample(enum CodecID codec_id){
1461 case CODEC_ID_ADPCM_SBPRO_2:
1463 case CODEC_ID_ADPCM_SBPRO_3:
1465 case CODEC_ID_ADPCM_SBPRO_4:
1466 case CODEC_ID_ADPCM_CT:
1467 case CODEC_ID_ADPCM_IMA_WAV:
1468 case CODEC_ID_ADPCM_IMA_QT:
1469 case CODEC_ID_ADPCM_SWF:
1470 case CODEC_ID_ADPCM_MS:
1471 case CODEC_ID_ADPCM_YAMAHA:
1472 case CODEC_ID_ADPCM_G722:
1474 case CODEC_ID_PCM_ALAW:
1475 case CODEC_ID_PCM_MULAW:
1476 case CODEC_ID_PCM_S8:
1477 case CODEC_ID_PCM_U8:
1478 case CODEC_ID_PCM_ZORK:
1480 case CODEC_ID_PCM_S16BE:
1481 case CODEC_ID_PCM_S16LE:
1482 case CODEC_ID_PCM_S16LE_PLANAR:
1483 case CODEC_ID_PCM_U16BE:
1484 case CODEC_ID_PCM_U16LE:
1486 case CODEC_ID_PCM_S24DAUD:
1487 case CODEC_ID_PCM_S24BE:
1488 case CODEC_ID_PCM_S24LE:
1489 case CODEC_ID_PCM_U24BE:
1490 case CODEC_ID_PCM_U24LE:
1492 case CODEC_ID_PCM_S32BE:
1493 case CODEC_ID_PCM_S32LE:
1494 case CODEC_ID_PCM_U32BE:
1495 case CODEC_ID_PCM_U32LE:
1496 case CODEC_ID_PCM_F32BE:
1497 case CODEC_ID_PCM_F32LE:
1499 case CODEC_ID_PCM_F64BE:
1500 case CODEC_ID_PCM_F64LE:
1507 #if FF_API_OLD_SAMPLE_FMT
1508 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
1509 return av_get_bytes_per_sample(sample_fmt) << 3;
1514 int ff_thread_init(AVCodecContext *s){
1519 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1533 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
1535 for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
1539 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1541 av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
1542 "version to the newest one from Git. If the problem still "
1543 "occurs, it means that your file has a feature which has not "
1544 "been implemented.\n", feature);
1546 av_log_ask_for_sample(avc, NULL);
1549 void av_log_ask_for_sample(void *avc, const char *msg, ...)
1551 va_list argument_list;
1553 va_start(argument_list, msg);
1556 av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
1557 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1558 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
1559 "and contact the ffmpeg-devel mailing list.\n");
1561 va_end(argument_list);
1564 static AVHWAccel *first_hwaccel = NULL;
1566 void av_register_hwaccel(AVHWAccel *hwaccel)
1568 AVHWAccel **p = &first_hwaccel;
1572 hwaccel->next = NULL;
1575 AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
1577 return hwaccel ? hwaccel->next : first_hwaccel;
1580 AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
1582 AVHWAccel *hwaccel=NULL;
1584 while((hwaccel= av_hwaccel_next(hwaccel))){
1585 if ( hwaccel->id == codec_id
1586 && hwaccel->pix_fmt == pix_fmt)
1592 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1594 if (ff_lockmgr_cb) {
1595 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
1597 if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
1603 if (ff_lockmgr_cb) {
1604 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
1606 if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
1612 int avpriv_lock_avformat(void)
1614 if (ff_lockmgr_cb) {
1615 if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_OBTAIN))
1621 int avpriv_unlock_avformat(void)
1623 if (ff_lockmgr_cb) {
1624 if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_RELEASE))
1630 unsigned int avpriv_toupper4(unsigned int x)
1632 return toupper( x &0xFF)
1633 + (toupper((x>>8 )&0xFF)<<8 )
1634 + (toupper((x>>16)&0xFF)<<16)
1635 + (toupper((x>>24)&0xFF)<<24);
1640 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
1644 ff_init_buffer_info(avctx, f);
1646 return avctx->get_buffer(avctx, f);
1649 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
1651 f->owner->release_buffer(f->owner, f);
1654 void ff_thread_finish_setup(AVCodecContext *avctx)
1658 void ff_thread_report_progress(AVFrame *f, int progress, int field)
1662 void ff_thread_await_progress(AVFrame *f, int progress, int field)
1668 #if FF_API_THREAD_INIT
1669 int avcodec_thread_init(AVCodecContext *s, int thread_count)
1671 s->thread_count = thread_count;
1672 return ff_thread_init(s);
1676 enum AVMediaType avcodec_get_type(enum CodecID codec_id)
1678 AVCodec *c= avcodec_find_decoder(codec_id);
1680 c= avcodec_find_encoder(codec_id);
1684 if (codec_id <= CODEC_ID_NONE)
1685 return AVMEDIA_TYPE_UNKNOWN;
1686 else if (codec_id < CODEC_ID_FIRST_AUDIO)
1687 return AVMEDIA_TYPE_VIDEO;
1688 else if (codec_id < CODEC_ID_FIRST_SUBTITLE)
1689 return AVMEDIA_TYPE_AUDIO;
1690 else if (codec_id < CODEC_ID_FIRST_UNKNOWN)
1691 return AVMEDIA_TYPE_SUBTITLE;
1693 return AVMEDIA_TYPE_UNKNOWN;