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"
36 #include "libavutil/avassert.h"
39 #include "libavutil/opt.h"
40 #include "imgconvert.h"
42 #include "audioconvert.h"
44 #include "bytestream.h"
50 static int volatile entangled_thread_counter=0;
51 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
52 static void *codec_mutex;
53 static void *avformat_mutex;
55 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
60 min_size= FFMAX(17*min_size/16 + 32, min_size);
62 ptr= av_realloc(ptr, min_size);
63 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
71 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
76 min_size= FFMAX(17*min_size/16 + 32, min_size);
78 *p = av_malloc(min_size);
79 if (!*p) min_size = 0;
83 /* encoder management */
84 static AVCodec *first_avcodec = NULL;
86 AVCodec *av_codec_next(AVCodec *c){
88 else return first_avcodec;
91 #if !FF_API_AVCODEC_INIT
94 void avcodec_init(void)
96 static int initialized = 0;
102 dsputil_static_init();
105 void avcodec_register(AVCodec *codec)
110 while (*p != NULL) p = &(*p)->next;
114 if (codec->init_static_data)
115 codec->init_static_data(codec);
118 unsigned avcodec_get_edge_width(void)
123 void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
124 s->coded_width = width;
125 s->coded_height= height;
126 s->width = -((-width )>>s->lowres);
127 s->height= -((-height)>>s->lowres);
130 #define INTERNAL_BUFFER_SIZE (32+1)
132 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
133 int linesize_align[AV_NUM_DATA_POINTERS])
140 case PIX_FMT_YUV420P:
141 case PIX_FMT_YUYV422:
142 case PIX_FMT_UYVY422:
143 case PIX_FMT_YUV422P:
144 case PIX_FMT_YUV440P:
145 case PIX_FMT_YUV444P:
148 case PIX_FMT_GRAY16BE:
149 case PIX_FMT_GRAY16LE:
150 case PIX_FMT_YUVJ420P:
151 case PIX_FMT_YUVJ422P:
152 case PIX_FMT_YUVJ440P:
153 case PIX_FMT_YUVJ444P:
154 case PIX_FMT_YUVA420P:
155 case PIX_FMT_YUV420P9LE:
156 case PIX_FMT_YUV420P9BE:
157 case PIX_FMT_YUV420P10LE:
158 case PIX_FMT_YUV420P10BE:
159 case PIX_FMT_YUV422P9LE:
160 case PIX_FMT_YUV422P9BE:
161 case PIX_FMT_YUV422P10LE:
162 case PIX_FMT_YUV422P10BE:
163 case PIX_FMT_YUV444P9LE:
164 case PIX_FMT_YUV444P9BE:
165 case PIX_FMT_YUV444P10LE:
166 case PIX_FMT_YUV444P10BE:
167 case PIX_FMT_GBRP9LE:
168 case PIX_FMT_GBRP9BE:
169 case PIX_FMT_GBRP10LE:
170 case PIX_FMT_GBRP10BE:
171 w_align = 16; //FIXME assume 16 pixel per macroblock
172 h_align = 16 * 2; // interlaced needs 2 macroblocks height
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)
375 AVCodecInternal *avci = s->internal;
377 if(pic->data[0]!=NULL) {
378 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
381 if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) {
382 av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n");
386 if(av_image_check_size(w, h, 0, s))
390 avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE+1) *
391 sizeof(InternalBuffer));
394 buf = &avci->buffer[avci->buffer_count];
396 if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
397 if(s->active_thread_type&FF_THREAD_FRAME) {
398 av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
402 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
403 av_freep(&buf->base[i]);
409 int h_chroma_shift, v_chroma_shift;
414 int stride_align[AV_NUM_DATA_POINTERS];
415 const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;
417 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
419 avcodec_align_dimensions2(s, &w, &h, stride_align);
421 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
427 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
428 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
429 av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
430 // increase alignment of w for next try (rhs gives the lowest bit set in w)
435 unaligned |= picture.linesize[i] % stride_align[i];
439 tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
443 for (i=0; i<3 && picture.data[i+1]; i++)
444 size[i] = picture.data[i+1] - picture.data[i];
445 size[i] = tmpsize - (picture.data[i] - picture.data[0]);
447 memset(buf->base, 0, sizeof(buf->base));
448 memset(buf->data, 0, sizeof(buf->data));
450 for(i=0; i<4 && size[i]; i++){
451 const int h_shift= i==0 ? 0 : h_chroma_shift;
452 const int v_shift= i==0 ? 0 : v_chroma_shift;
454 buf->linesize[i]= picture.linesize[i];
456 buf->base[i]= av_malloc(size[i]+16); //FIXME 16
457 if(buf->base[i]==NULL) return -1;
458 memset(buf->base[i], 128, size[i]);
460 // no edge if EDGE EMU or not planar YUV
461 if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
462 buf->data[i] = buf->base[i];
464 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]);
466 for (; i < AV_NUM_DATA_POINTERS; i++) {
467 buf->base[i] = buf->data[i] = NULL;
468 buf->linesize[i] = 0;
470 if(size[1] && !size[2])
471 ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
472 buf->width = s->width;
473 buf->height = s->height;
474 buf->pix_fmt= s->pix_fmt;
476 pic->type= FF_BUFFER_TYPE_INTERNAL;
478 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
479 pic->base[i]= buf->base[i];
480 pic->data[i]= buf->data[i];
481 pic->linesize[i]= buf->linesize[i];
483 pic->extended_data = pic->data;
484 avci->buffer_count++;
487 pic->pkt_pts = s->pkt->pts;
488 pic->pkt_pos = s->pkt->pos;
490 pic->pkt_pts = AV_NOPTS_VALUE;
493 pic->reordered_opaque= s->reordered_opaque;
494 pic->sample_aspect_ratio = s->sample_aspect_ratio;
495 pic->width = s->width;
496 pic->height = s->height;
497 pic->format = s->pix_fmt;
499 if(s->debug&FF_DEBUG_BUFFERS)
500 av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
501 "buffers used\n", pic, avci->buffer_count);
506 int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
508 switch (avctx->codec_type) {
509 case AVMEDIA_TYPE_VIDEO:
510 return video_get_buffer(avctx, frame);
511 case AVMEDIA_TYPE_AUDIO:
512 return audio_get_buffer(avctx, frame);
518 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
520 InternalBuffer *buf, *last;
521 AVCodecInternal *avci = s->internal;
523 assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
525 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
526 assert(avci->buffer_count);
529 buf = NULL; /* avoids warning */
530 for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize
531 buf = &avci->buffer[i];
532 if (buf->data[0] == pic->data[0])
535 assert(i < avci->buffer_count);
536 avci->buffer_count--;
537 last = &avci->buffer[avci->buffer_count];
540 FFSWAP(InternalBuffer, *buf, *last);
543 for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
545 // pic->base[i]=NULL;
547 //printf("R%X\n", pic->opaque);
549 if(s->debug&FF_DEBUG_BUFFERS)
550 av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
551 "buffers used\n", pic, avci->buffer_count);
554 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
558 assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
560 /* If no picture return a new buffer */
561 if(pic->data[0] == NULL) {
562 /* We will copy from buffer, so must be readable */
563 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
564 return s->get_buffer(s, pic);
567 /* If internal buffer type return the same buffer */
568 if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
569 if(s->pkt) pic->pkt_pts= s->pkt->pts;
570 else pic->pkt_pts= AV_NOPTS_VALUE;
571 pic->reordered_opaque= s->reordered_opaque;
576 * Not internal type and reget_buffer not overridden, emulate cr buffer
579 for(i = 0; i < AV_NUM_DATA_POINTERS; i++)
580 pic->data[i] = pic->base[i] = NULL;
582 /* Allocate new frame */
583 if (s->get_buffer(s, pic))
585 /* Copy image data from old buffer to new buffer */
586 av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
588 s->release_buffer(s, &temp_pic); // Release old frame
592 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
595 for(i=0; i<count; i++){
596 int r= func(c, (char*)arg + i*size);
602 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
605 for(i=0; i<count; i++){
606 int r= func(c, arg, i, 0);
612 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
613 while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
618 void avcodec_get_frame_defaults(AVFrame *pic){
619 memset(pic, 0, sizeof(AVFrame));
621 pic->pts = pic->pkt_dts = pic->pkt_pts = pic->best_effort_timestamp = AV_NOPTS_VALUE;
624 pic->sample_aspect_ratio = (AVRational){0, 1};
625 pic->format = -1; /* unknown */
628 AVFrame *avcodec_alloc_frame(void){
629 AVFrame *pic= av_malloc(sizeof(AVFrame));
631 if(pic==NULL) return NULL;
633 avcodec_get_frame_defaults(pic);
638 static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
640 memset(sub, 0, sizeof(*sub));
641 sub->pts = AV_NOPTS_VALUE;
644 #if FF_API_AVCODEC_OPEN
645 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
647 return avcodec_open2(avctx, codec, NULL);
651 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
654 AVDictionary *tmp = NULL;
657 av_dict_copy(&tmp, *options, 0);
659 /* If there is a user-supplied mutex locking routine, call it. */
661 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
665 entangled_thread_counter++;
666 if(entangled_thread_counter != 1){
667 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
672 if(avctx->codec || !codec) {
673 ret = AVERROR(EINVAL);
677 avctx->internal = av_mallocz(sizeof(AVCodecInternal));
678 if (!avctx->internal) {
679 ret = AVERROR(ENOMEM);
683 if (codec->priv_data_size > 0) {
684 if(!avctx->priv_data){
685 avctx->priv_data = av_mallocz(codec->priv_data_size);
686 if (!avctx->priv_data) {
687 ret = AVERROR(ENOMEM);
690 if (codec->priv_class) {
691 *(AVClass**)avctx->priv_data= codec->priv_class;
692 av_opt_set_defaults(avctx->priv_data);
695 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
698 avctx->priv_data = NULL;
700 if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
703 //We only call avcodec_set_dimensions() for non h264 codecs so as not to overwrite previously setup dimensions
704 if(!( avctx->coded_width && avctx->coded_height && avctx->width && avctx->height && avctx->codec_id == CODEC_ID_H264)){
705 if(avctx->coded_width && avctx->coded_height)
706 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
707 else if(avctx->width && avctx->height)
708 avcodec_set_dimensions(avctx, avctx->width, avctx->height);
711 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
712 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
713 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
714 av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
715 avcodec_set_dimensions(avctx, 0, 0);
718 /* if the decoder init function was already called previously,
719 free the already allocated subtitle_header before overwriting it */
721 av_freep(&avctx->subtitle_header);
723 #define SANE_NB_CHANNELS 128U
724 if (avctx->channels > SANE_NB_CHANNELS) {
725 ret = AVERROR(EINVAL);
729 avctx->codec = codec;
730 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
731 avctx->codec_id == CODEC_ID_NONE) {
732 avctx->codec_type = codec->type;
733 avctx->codec_id = codec->id;
735 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
736 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
737 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
738 ret = AVERROR(EINVAL);
741 avctx->frame_number = 0;
744 av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition separate: %d; %X\n",
745 avctx->error_recognition, avctx->err_recognition);
746 switch(avctx->error_recognition){
747 case FF_ER_EXPLODE : avctx->err_recognition |= AV_EF_EXPLODE | AV_EF_COMPLIANT | AV_EF_CAREFUL;
749 case FF_ER_VERY_AGGRESSIVE:
750 case FF_ER_AGGRESSIVE : avctx->err_recognition |= AV_EF_AGGRESSIVE;
751 case FF_ER_COMPLIANT : avctx->err_recognition |= AV_EF_COMPLIANT;
752 case FF_ER_CAREFUL : avctx->err_recognition |= AV_EF_CAREFUL;
755 av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition combined: %d; %X\n",
756 avctx->error_recognition, avctx->err_recognition);
760 av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
762 if (HAVE_THREADS && !avctx->thread_opaque) {
763 ret = ff_thread_init(avctx);
769 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
770 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
771 avctx->codec->max_lowres);
772 ret = AVERROR(EINVAL);
775 if (avctx->codec->encode) {
777 if (avctx->codec->sample_fmts) {
778 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
779 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
781 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
782 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
783 ret = AVERROR(EINVAL);
787 if (avctx->codec->supported_samplerates) {
788 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
789 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
791 if (avctx->codec->supported_samplerates[i] == 0) {
792 av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
793 ret = AVERROR(EINVAL);
797 if (avctx->codec->channel_layouts) {
798 if (!avctx->channel_layout) {
799 av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
801 for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
802 if (avctx->channel_layout == avctx->codec->channel_layouts[i])
804 if (avctx->codec->channel_layouts[i] == 0) {
805 av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
806 ret = AVERROR(EINVAL);
811 if (avctx->channel_layout && avctx->channels) {
812 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
813 av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
814 ret = AVERROR(EINVAL);
817 } else if (avctx->channel_layout) {
818 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
822 avctx->pts_correction_num_faulty_pts =
823 avctx->pts_correction_num_faulty_dts = 0;
824 avctx->pts_correction_last_pts =
825 avctx->pts_correction_last_dts = INT64_MIN;
827 if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
828 ret = avctx->codec->init(avctx);
836 entangled_thread_counter--;
838 /* Release any user-supplied mutex. */
840 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
843 av_dict_free(options);
850 av_freep(&avctx->priv_data);
851 av_freep(&avctx->internal);
856 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
857 const short *samples)
859 if(buf_size < FF_MIN_BUFFER_SIZE && 0){
860 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
863 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
864 int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
865 avctx->frame_number++;
871 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
874 if(buf_size < FF_MIN_BUFFER_SIZE){
875 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
878 if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
880 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
881 int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
882 avctx->frame_number++;
883 emms_c(); //needed to avoid an emms_c() call before every return;
890 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
891 const AVSubtitle *sub)
894 if(sub->start_display_time) {
895 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
899 ret = avctx->codec->encode(avctx, buf, buf_size, sub);
900 avctx->frame_number++;
905 * Attempt to guess proper monotonic timestamps for decoded video frames
906 * which might have incorrect times. Input timestamps may wrap around, in
907 * which case the output will as well.
909 * @param pts the pts field of the decoded AVPacket, as passed through
911 * @param dts the dts field of the decoded AVPacket
912 * @return one of the input values, may be AV_NOPTS_VALUE
914 static int64_t guess_correct_pts(AVCodecContext *ctx,
915 int64_t reordered_pts, int64_t dts)
917 int64_t pts = AV_NOPTS_VALUE;
919 if (dts != AV_NOPTS_VALUE) {
920 ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
921 ctx->pts_correction_last_dts = dts;
923 if (reordered_pts != AV_NOPTS_VALUE) {
924 ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
925 ctx->pts_correction_last_pts = reordered_pts;
927 if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
928 && reordered_pts != AV_NOPTS_VALUE)
936 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
937 int *got_picture_ptr,
943 if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
946 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
947 av_packet_split_side_data(avpkt);
949 if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
950 ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
953 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
955 picture->pkt_dts= avpkt->dts;
957 if(!avctx->has_b_frames){
958 picture->pkt_pos= avpkt->pos;
960 //FIXME these should be under if(!avctx->has_b_frames)
961 if (!picture->sample_aspect_ratio.num)
962 picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
964 picture->width = avctx->width;
965 if (!picture->height)
966 picture->height = avctx->height;
967 if (picture->format == PIX_FMT_NONE)
968 picture->format = avctx->pix_fmt;
971 emms_c(); //needed to avoid an emms_c() call before every return;
974 if (*got_picture_ptr){
975 avctx->frame_number++;
976 picture->best_effort_timestamp = guess_correct_pts(avctx,
986 #if FF_API_OLD_DECODE_AUDIO
987 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
992 int ret, got_frame = 0;
994 if (avctx->get_buffer != avcodec_default_get_buffer) {
995 av_log(avctx, AV_LOG_ERROR, "Overriding custom get_buffer() for "
996 "avcodec_decode_audio3()\n");
997 avctx->get_buffer = avcodec_default_get_buffer;
998 avctx->release_buffer = avcodec_default_release_buffer;
1001 ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
1003 if (ret >= 0 && got_frame) {
1005 int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
1006 int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
1008 avctx->sample_fmt, 1);
1009 if (*frame_size_ptr < data_size) {
1010 av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
1011 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1012 return AVERROR(EINVAL);
1015 memcpy(samples, frame.extended_data[0], plane_size);
1017 if (planar && avctx->channels > 1) {
1018 uint8_t *out = ((uint8_t *)samples) + plane_size;
1019 for (ch = 1; ch < avctx->channels; ch++) {
1020 memcpy(out, frame.extended_data[ch], plane_size);
1024 *frame_size_ptr = data_size;
1026 *frame_size_ptr = 0;
1032 static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1035 const uint8_t *data;
1038 if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
1041 data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1042 if (!data || size < 4)
1044 flags = bytestream_get_le32(&data);
1046 if (size < 4) /* Required for any of the changes */
1048 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
1049 avctx->channels = bytestream_get_le32(&data);
1052 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
1055 avctx->channel_layout = bytestream_get_le64(&data);
1060 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
1061 avctx->sample_rate = bytestream_get_le32(&data);
1064 if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
1067 avctx->width = bytestream_get_le32(&data);
1068 avctx->height = bytestream_get_le32(&data);
1073 int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
1082 if (!avpkt->data && avpkt->size) {
1083 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1084 return AVERROR(EINVAL);
1087 if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1088 av_packet_split_side_data(avpkt);
1089 apply_param_change(avctx, avpkt);
1092 ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1093 if (ret >= 0 && *got_frame_ptr) {
1094 avctx->frame_number++;
1095 frame->pkt_dts = avpkt->dts;
1096 if (frame->format == AV_SAMPLE_FMT_NONE)
1097 frame->format = avctx->sample_fmt;
1103 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
1111 avcodec_get_subtitle_defaults(sub);
1112 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1114 avctx->frame_number++;
1118 void avsubtitle_free(AVSubtitle *sub)
1122 for (i = 0; i < sub->num_rects; i++)
1124 av_freep(&sub->rects[i]->pict.data[0]);
1125 av_freep(&sub->rects[i]->pict.data[1]);
1126 av_freep(&sub->rects[i]->pict.data[2]);
1127 av_freep(&sub->rects[i]->pict.data[3]);
1128 av_freep(&sub->rects[i]->text);
1129 av_freep(&sub->rects[i]->ass);
1130 av_freep(&sub->rects[i]);
1133 av_freep(&sub->rects);
1135 memset(sub, 0, sizeof(AVSubtitle));
1138 av_cold int avcodec_close(AVCodecContext *avctx)
1140 /* If there is a user-supplied mutex locking routine, call it. */
1141 if (ff_lockmgr_cb) {
1142 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
1146 entangled_thread_counter++;
1147 if(entangled_thread_counter != 1){
1148 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1149 entangled_thread_counter--;
1153 if (HAVE_THREADS && avctx->thread_opaque)
1154 ff_thread_free(avctx);
1155 if (avctx->codec && avctx->codec->close)
1156 avctx->codec->close(avctx);
1157 avcodec_default_free_buffers(avctx);
1158 avctx->coded_frame = NULL;
1159 av_freep(&avctx->internal);
1160 if (avctx->codec && avctx->codec->priv_class)
1161 av_opt_free(avctx->priv_data);
1163 av_freep(&avctx->priv_data);
1164 if(avctx->codec && avctx->codec->encode)
1165 av_freep(&avctx->extradata);
1166 avctx->codec = NULL;
1167 avctx->active_thread_type = 0;
1168 entangled_thread_counter--;
1170 /* Release any user-supplied mutex. */
1171 if (ff_lockmgr_cb) {
1172 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1177 static enum CodecID remap_deprecated_codec_id(enum CodecID id)
1180 case CODEC_ID_G723_1_DEPRECATED : return CODEC_ID_G723_1;
1181 case CODEC_ID_G729_DEPRECATED : return CODEC_ID_G729;
1182 case CODEC_ID_UTVIDEO_DEPRECATED: return CODEC_ID_UTVIDEO;
1183 default : return id;
1187 AVCodec *avcodec_find_encoder(enum CodecID id)
1189 AVCodec *p, *experimental=NULL;
1191 id= remap_deprecated_codec_id(id);
1193 if (p->encode != NULL && p->id == id) {
1194 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1201 return experimental;
1204 AVCodec *avcodec_find_encoder_by_name(const char *name)
1211 if (p->encode != NULL && strcmp(name,p->name) == 0)
1218 AVCodec *avcodec_find_decoder(enum CodecID id)
1220 AVCodec *p, *experimental=NULL;
1222 id= remap_deprecated_codec_id(id);
1224 if (p->decode != NULL && p->id == id) {
1225 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1232 return experimental;
1235 AVCodec *avcodec_find_decoder_by_name(const char *name)
1242 if (p->decode != NULL && strcmp(name,p->name) == 0)
1249 static int get_bit_rate(AVCodecContext *ctx)
1252 int bits_per_sample;
1254 switch(ctx->codec_type) {
1255 case AVMEDIA_TYPE_VIDEO:
1256 case AVMEDIA_TYPE_DATA:
1257 case AVMEDIA_TYPE_SUBTITLE:
1258 case AVMEDIA_TYPE_ATTACHMENT:
1259 bit_rate = ctx->bit_rate;
1261 case AVMEDIA_TYPE_AUDIO:
1262 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1263 bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1272 const char *avcodec_get_name(enum CodecID id)
1278 #include "libavcodec/codec_names.h"
1280 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
1282 codec = avcodec_find_decoder(id);
1285 codec = avcodec_find_encoder(id);
1288 return "unknown_codec";
1291 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1293 int i, len, ret = 0;
1295 for (i = 0; i < 4; i++) {
1296 len = snprintf(buf, buf_size,
1297 isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
1299 buf_size = buf_size > len ? buf_size - len : 0;
1306 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1308 const char *codec_type;
1309 const char *codec_name;
1310 const char *profile = NULL;
1313 AVRational display_aspect_ratio;
1315 if (!buf || buf_size <= 0)
1317 codec_type = av_get_media_type_string(enc->codec_type);
1318 codec_name = avcodec_get_name(enc->codec_id);
1319 if (enc->profile != FF_PROFILE_UNKNOWN) {
1320 p = encode ? avcodec_find_encoder(enc->codec_id) :
1321 avcodec_find_decoder(enc->codec_id);
1323 profile = av_get_profile_name(p, enc->profile);
1326 snprintf(buf, buf_size, "%s: %s%s", codec_type ? codec_type : "unknown",
1327 codec_name, enc->mb_decision ? " (hq)" : "");
1328 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
1330 snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
1331 if (enc->codec_tag) {
1333 av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1334 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1335 " (%s / 0x%04X)", tag_buf, enc->codec_tag);
1337 switch(enc->codec_type) {
1338 case AVMEDIA_TYPE_VIDEO:
1339 if (enc->pix_fmt != PIX_FMT_NONE) {
1340 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1342 av_get_pix_fmt_name(enc->pix_fmt));
1345 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1347 enc->width, enc->height);
1348 if (enc->sample_aspect_ratio.num) {
1349 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1350 enc->width*enc->sample_aspect_ratio.num,
1351 enc->height*enc->sample_aspect_ratio.den,
1353 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1354 " [SAR %d:%d DAR %d:%d]",
1355 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
1356 display_aspect_ratio.num, display_aspect_ratio.den);
1358 if(av_log_get_level() >= AV_LOG_DEBUG){
1359 int g= av_gcd(enc->time_base.num, enc->time_base.den);
1360 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1362 enc->time_base.num/g, enc->time_base.den/g);
1366 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1367 ", q=%d-%d", enc->qmin, enc->qmax);
1370 case AVMEDIA_TYPE_AUDIO:
1371 if (enc->sample_rate) {
1372 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1373 ", %d Hz", enc->sample_rate);
1375 av_strlcat(buf, ", ", buf_size);
1376 av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1377 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1378 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1379 ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1386 if (enc->flags & CODEC_FLAG_PASS1)
1387 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1389 if (enc->flags & CODEC_FLAG_PASS2)
1390 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1393 bitrate = get_bit_rate(enc);
1395 snprintf(buf + strlen(buf), buf_size - strlen(buf),
1396 ", %d kb/s", bitrate / 1000);
1400 const char *av_get_profile_name(const AVCodec *codec, int profile)
1403 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1406 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1407 if (p->profile == profile)
1413 unsigned avcodec_version( void )
1415 av_assert0(CODEC_ID_V410==164);
1416 av_assert0(CODEC_ID_PCM_S8_PLANAR==65563);
1417 av_assert0(CODEC_ID_ADPCM_G722==69660);
1418 av_assert0(CODEC_ID_BMV_AUDIO==86071);
1419 av_assert0(CODEC_ID_SRT==94216);
1420 av_assert0(LIBAVCODEC_VERSION_MICRO >= 100);
1422 return LIBAVCODEC_VERSION_INT;
1425 const char *avcodec_configuration(void)
1427 return FFMPEG_CONFIGURATION;
1430 const char *avcodec_license(void)
1432 #define LICENSE_PREFIX "libavcodec license: "
1433 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1436 void avcodec_flush_buffers(AVCodecContext *avctx)
1438 if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
1439 ff_thread_flush(avctx);
1440 else if(avctx->codec->flush)
1441 avctx->codec->flush(avctx);
1444 static void video_free_buffers(AVCodecContext *s)
1446 AVCodecInternal *avci = s->internal;
1452 if (avci->buffer_count)
1453 av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n",
1454 avci->buffer_count);
1455 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
1456 InternalBuffer *buf = &avci->buffer[i];
1458 av_freep(&buf->base[j]);
1462 av_freep(&avci->buffer);
1464 avci->buffer_count=0;
1467 static void audio_free_buffers(AVCodecContext *avctx)
1469 AVCodecInternal *avci = avctx->internal;
1470 InternalBuffer *buf;
1476 if (buf->extended_data) {
1477 av_free(buf->extended_data[0]);
1478 if (buf->extended_data != buf->data)
1479 av_free(buf->extended_data);
1481 av_freep(&avci->buffer);
1484 void avcodec_default_free_buffers(AVCodecContext *avctx)
1486 switch (avctx->codec_type) {
1487 case AVMEDIA_TYPE_VIDEO:
1488 video_free_buffers(avctx);
1490 case AVMEDIA_TYPE_AUDIO:
1491 audio_free_buffers(avctx);
1498 #if FF_API_OLD_FF_PICT_TYPES
1499 char av_get_pict_type_char(int pict_type){
1500 return av_get_picture_type_char(pict_type);
1504 int av_get_bits_per_sample(enum CodecID codec_id){
1506 case CODEC_ID_ADPCM_SBPRO_2:
1508 case CODEC_ID_ADPCM_SBPRO_3:
1510 case CODEC_ID_ADPCM_SBPRO_4:
1511 case CODEC_ID_ADPCM_CT:
1512 case CODEC_ID_ADPCM_IMA_WAV:
1513 case CODEC_ID_ADPCM_IMA_QT:
1514 case CODEC_ID_ADPCM_SWF:
1515 case CODEC_ID_ADPCM_MS:
1516 case CODEC_ID_ADPCM_YAMAHA:
1517 case CODEC_ID_ADPCM_G722:
1519 case CODEC_ID_PCM_ALAW:
1520 case CODEC_ID_PCM_MULAW:
1521 case CODEC_ID_PCM_S8:
1522 case CODEC_ID_PCM_U8:
1523 case CODEC_ID_PCM_ZORK:
1525 case CODEC_ID_PCM_S16BE:
1526 case CODEC_ID_PCM_S16LE:
1527 case CODEC_ID_PCM_S16LE_PLANAR:
1528 case CODEC_ID_PCM_U16BE:
1529 case CODEC_ID_PCM_U16LE:
1531 case CODEC_ID_PCM_S24DAUD:
1532 case CODEC_ID_PCM_S24BE:
1533 case CODEC_ID_PCM_S24LE:
1534 case CODEC_ID_PCM_U24BE:
1535 case CODEC_ID_PCM_U24LE:
1537 case CODEC_ID_PCM_S32BE:
1538 case CODEC_ID_PCM_S32LE:
1539 case CODEC_ID_PCM_U32BE:
1540 case CODEC_ID_PCM_U32LE:
1541 case CODEC_ID_PCM_F32BE:
1542 case CODEC_ID_PCM_F32LE:
1544 case CODEC_ID_PCM_F64BE:
1545 case CODEC_ID_PCM_F64LE:
1552 #if FF_API_OLD_SAMPLE_FMT
1553 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
1554 return av_get_bytes_per_sample(sample_fmt) << 3;
1559 int ff_thread_init(AVCodecContext *s){
1564 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1578 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
1580 for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
1584 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1586 av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
1587 "version to the newest one from Git. If the problem still "
1588 "occurs, it means that your file has a feature which has not "
1589 "been implemented.\n", feature);
1591 av_log_ask_for_sample(avc, NULL);
1594 void av_log_ask_for_sample(void *avc, const char *msg, ...)
1596 va_list argument_list;
1598 va_start(argument_list, msg);
1601 av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
1602 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1603 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
1604 "and contact the ffmpeg-devel mailing list.\n");
1606 va_end(argument_list);
1609 static AVHWAccel *first_hwaccel = NULL;
1611 void av_register_hwaccel(AVHWAccel *hwaccel)
1613 AVHWAccel **p = &first_hwaccel;
1617 hwaccel->next = NULL;
1620 AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
1622 return hwaccel ? hwaccel->next : first_hwaccel;
1625 AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
1627 AVHWAccel *hwaccel=NULL;
1629 while((hwaccel= av_hwaccel_next(hwaccel))){
1630 if ( hwaccel->id == codec_id
1631 && hwaccel->pix_fmt == pix_fmt)
1637 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1639 if (ff_lockmgr_cb) {
1640 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
1642 if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
1648 if (ff_lockmgr_cb) {
1649 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
1651 if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
1657 int avpriv_lock_avformat(void)
1659 if (ff_lockmgr_cb) {
1660 if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_OBTAIN))
1666 int avpriv_unlock_avformat(void)
1668 if (ff_lockmgr_cb) {
1669 if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_RELEASE))
1675 unsigned int avpriv_toupper4(unsigned int x)
1677 return toupper( x &0xFF)
1678 + (toupper((x>>8 )&0xFF)<<8 )
1679 + (toupper((x>>16)&0xFF)<<16)
1680 + (toupper((x>>24)&0xFF)<<24);
1685 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
1689 ff_init_buffer_info(avctx, f);
1691 return avctx->get_buffer(avctx, f);
1694 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
1696 f->owner->release_buffer(f->owner, f);
1699 void ff_thread_finish_setup(AVCodecContext *avctx)
1703 void ff_thread_report_progress(AVFrame *f, int progress, int field)
1707 void ff_thread_await_progress(AVFrame *f, int progress, int field)
1713 #if FF_API_THREAD_INIT
1714 int avcodec_thread_init(AVCodecContext *s, int thread_count)
1716 s->thread_count = thread_count;
1717 return ff_thread_init(s);
1721 enum AVMediaType avcodec_get_type(enum CodecID codec_id)
1723 AVCodec *c= avcodec_find_decoder(codec_id);
1725 c= avcodec_find_encoder(codec_id);
1729 if (codec_id <= CODEC_ID_NONE)
1730 return AVMEDIA_TYPE_UNKNOWN;
1731 else if (codec_id < CODEC_ID_FIRST_AUDIO)
1732 return AVMEDIA_TYPE_VIDEO;
1733 else if (codec_id < CODEC_ID_FIRST_SUBTITLE)
1734 return AVMEDIA_TYPE_AUDIO;
1735 else if (codec_id < CODEC_ID_FIRST_UNKNOWN)
1736 return AVMEDIA_TYPE_SUBTITLE;
1738 return AVMEDIA_TYPE_UNKNOWN;