3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of Libav.
8 * Libav 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 * Libav 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 Libav; 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 assume 16 pixel per macroblock
170 h_align
= 16 * 2; // interlaced needs 2 macroblocks height
172 case PIX_FMT_YUV411P
:
173 case PIX_FMT_UYYVYY411
:
177 case PIX_FMT_YUV410P
:
178 if(s
->codec_id
== CODEC_ID_SVQ1
){
183 if(s
->codec_id
== CODEC_ID_RPZA
){
190 if(s
->codec_id
== CODEC_ID_SMC
){
196 if((s
->codec_id
== CODEC_ID_MSZH
) || (s
->codec_id
== CODEC_ID_ZLIB
)){
207 *width
= FFALIGN(*width
, w_align
);
208 *height
= FFALIGN(*height
, h_align
);
209 if(s
->codec_id
== CODEC_ID_H264
|| s
->lowres
)
210 *height
+=2; // some of the optimized chroma MC reads one line too much
211 // which is also done in mpeg decoders with lowres > 0
213 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++)
214 linesize_align
[i
] = STRIDE_ALIGN
;
215 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
216 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
217 //picture size unneccessarily in some cases. The solution here is not
218 //pretty and better ideas are welcome!
220 if(s
->codec_id
== CODEC_ID_SVQ1
|| s
->codec_id
== CODEC_ID_VP5
||
221 s
->codec_id
== CODEC_ID_VP6
|| s
->codec_id
== CODEC_ID_VP6F
||
222 s
->codec_id
== CODEC_ID_VP6A
) {
223 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++)
224 linesize_align
[i
] = 16;
229 void avcodec_align_dimensions(AVCodecContext
*s
, int *width
, int *height
){
230 int chroma_shift
= av_pix_fmt_descriptors
[s
->pix_fmt
].log2_chroma_w
;
231 int linesize_align
[AV_NUM_DATA_POINTERS
];
233 avcodec_align_dimensions2(s
, width
, height
, linesize_align
);
234 align
= FFMAX(linesize_align
[0], linesize_align
[3]);
235 linesize_align
[1] <<= chroma_shift
;
236 linesize_align
[2] <<= chroma_shift
;
237 align
= FFMAX3(align
, linesize_align
[1], linesize_align
[2]);
238 *width
=FFALIGN(*width
, align
);
241 static int audio_get_buffer(AVCodecContext
*avctx
, AVFrame
*frame
)
243 AVCodecInternal
*avci
= avctx
->internal
;
245 int buf_size
, ret
, i
, needs_extended_data
;
247 buf_size
= av_samples_get_buffer_size(NULL
, avctx
->channels
,
248 frame
->nb_samples
, avctx
->sample_fmt
,
251 return AVERROR(EINVAL
);
253 needs_extended_data
= av_sample_fmt_is_planar(avctx
->sample_fmt
) &&
254 avctx
->channels
> AV_NUM_DATA_POINTERS
;
256 /* allocate InternalBuffer if needed */
258 avci
->buffer
= av_mallocz(sizeof(InternalBuffer
));
260 return AVERROR(ENOMEM
);
264 /* if there is a previously-used internal buffer, check its size and
265 channel count to see if we can reuse it */
266 if (buf
->extended_data
) {
267 /* if current buffer is too small, free it */
268 if (buf
->extended_data
[0] && buf_size
> buf
->audio_data_size
) {
269 av_free(buf
->extended_data
[0]);
270 if (buf
->extended_data
!= buf
->data
)
271 av_free(&buf
->extended_data
);
272 buf
->extended_data
= NULL
;
275 /* if number of channels has changed, reset and/or free extended data
276 pointers but leave data buffer in buf->data[0] for reuse */
277 if (buf
->nb_channels
!= avctx
->channels
) {
278 if (buf
->extended_data
!= buf
->data
)
279 av_free(buf
->extended_data
);
280 buf
->extended_data
= NULL
;
284 /* if there is no previous buffer or the previous buffer cannot be used
285 as-is, allocate a new buffer and/or rearrange the channel pointers */
286 if (!buf
->extended_data
) {
287 /* if the channel pointers will fit, just set extended_data to data,
288 otherwise allocate the extended_data channel pointers */
289 if (needs_extended_data
) {
290 buf
->extended_data
= av_mallocz(avctx
->channels
*
291 sizeof(*buf
->extended_data
));
292 if (!buf
->extended_data
)
293 return AVERROR(ENOMEM
);
295 buf
->extended_data
= buf
->data
;
298 /* if there is a previous buffer and it is large enough, reuse it and
299 just fill-in new channel pointers and linesize, otherwise allocate
301 if (buf
->extended_data
[0]) {
302 ret
= av_samples_fill_arrays(buf
->extended_data
, &buf
->linesize
[0],
303 buf
->extended_data
[0], avctx
->channels
,
304 frame
->nb_samples
, avctx
->sample_fmt
,
307 ret
= av_samples_alloc(buf
->extended_data
, &buf
->linesize
[0],
308 avctx
->channels
, frame
->nb_samples
,
309 avctx
->sample_fmt
, 32);
314 /* if data was not used for extended_data, we need to copy as many of
315 the extended_data channel pointers as will fit */
316 if (needs_extended_data
) {
317 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++)
318 buf
->data
[i
] = buf
->extended_data
[i
];
320 buf
->audio_data_size
= buf_size
;
321 buf
->nb_channels
= avctx
->channels
;
324 /* copy InternalBuffer info to the AVFrame */
325 frame
->type
= FF_BUFFER_TYPE_INTERNAL
;
326 frame
->extended_data
= buf
->extended_data
;
327 frame
->linesize
[0] = buf
->linesize
[0];
328 memcpy(frame
->data
, buf
->data
, sizeof(frame
->data
));
330 if (avctx
->pkt
) frame
->pkt_pts
= avctx
->pkt
->pts
;
331 else frame
->pkt_pts
= AV_NOPTS_VALUE
;
332 frame
->reordered_opaque
= avctx
->reordered_opaque
;
334 if (avctx
->debug
& FF_DEBUG_BUFFERS
)
335 av_log(avctx
, AV_LOG_DEBUG
, "default_get_buffer called on frame %p, "
336 "internal audio buffer used\n", frame
);
341 static int video_get_buffer(AVCodecContext
*s
, AVFrame
*pic
)
347 AVCodecInternal
*avci
= s
->internal
;
349 if(pic
->data
[0]!=NULL
) {
350 av_log(s
, AV_LOG_ERROR
, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
353 if(avci
->buffer_count
>= INTERNAL_BUFFER_SIZE
) {
354 av_log(s
, AV_LOG_ERROR
, "buffer_count overflow (missing release_buffer?)\n");
358 if(av_image_check_size(w
, h
, 0, s
))
362 avci
->buffer
= av_mallocz((INTERNAL_BUFFER_SIZE
+1) *
363 sizeof(InternalBuffer
));
366 buf
= &avci
->buffer
[avci
->buffer_count
];
368 if(buf
->base
[0] && (buf
->width
!= w
|| buf
->height
!= h
|| buf
->pix_fmt
!= s
->pix_fmt
)){
369 if(s
->active_thread_type
&FF_THREAD_FRAME
) {
370 av_log_missing_feature(s
, "Width/height changing with frame threads is", 0);
374 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++) {
375 av_freep(&buf
->base
[i
]);
381 int h_chroma_shift
, v_chroma_shift
;
386 int stride_align
[AV_NUM_DATA_POINTERS
];
387 const int pixel_size
= av_pix_fmt_descriptors
[s
->pix_fmt
].comp
[0].step_minus1
+1;
389 avcodec_get_chroma_sub_sample(s
->pix_fmt
, &h_chroma_shift
, &v_chroma_shift
);
391 avcodec_align_dimensions2(s
, &w
, &h
, stride_align
);
393 if(!(s
->flags
&CODEC_FLAG_EMU_EDGE
)){
399 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
400 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
401 av_image_fill_linesizes(picture
.linesize
, s
->pix_fmt
, w
);
402 // increase alignment of w for next try (rhs gives the lowest bit set in w)
407 unaligned
|= picture
.linesize
[i
] % stride_align
[i
];
411 tmpsize
= av_image_fill_pointers(picture
.data
, s
->pix_fmt
, h
, NULL
, picture
.linesize
);
415 for (i
=0; i
<3 && picture
.data
[i
+1]; i
++)
416 size
[i
] = picture
.data
[i
+1] - picture
.data
[i
];
417 size
[i
] = tmpsize
- (picture
.data
[i
] - picture
.data
[0]);
419 memset(buf
->base
, 0, sizeof(buf
->base
));
420 memset(buf
->data
, 0, sizeof(buf
->data
));
422 for(i
=0; i
<4 && size
[i
]; i
++){
423 const int h_shift
= i
==0 ?
0 : h_chroma_shift
;
424 const int v_shift
= i
==0 ?
0 : v_chroma_shift
;
426 buf
->linesize
[i
]= picture
.linesize
[i
];
428 buf
->base
[i
]= av_malloc(size
[i
]+16); //FIXME 16
429 if(buf
->base
[i
]==NULL
) return -1;
430 memset(buf
->base
[i
], 128, size
[i
]);
432 // no edge if EDGE EMU or not planar YUV
433 if((s
->flags
&CODEC_FLAG_EMU_EDGE
) || !size
[2])
434 buf
->data
[i
] = buf
->base
[i
];
436 buf
->data
[i
] = buf
->base
[i
] + FFALIGN((buf
->linesize
[i
]*EDGE_WIDTH
>>v_shift
) + (pixel_size
*EDGE_WIDTH
>>h_shift
), stride_align
[i
]);
438 for (; i
< AV_NUM_DATA_POINTERS
; i
++) {
439 buf
->base
[i
] = buf
->data
[i
] = NULL
;
440 buf
->linesize
[i
] = 0;
442 if(size
[1] && !size
[2])
443 ff_set_systematic_pal2((uint32_t*)buf
->data
[1], s
->pix_fmt
);
444 buf
->width
= s
->width
;
445 buf
->height
= s
->height
;
446 buf
->pix_fmt
= s
->pix_fmt
;
448 pic
->type
= FF_BUFFER_TYPE_INTERNAL
;
450 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++) {
451 pic
->base
[i
]= buf
->base
[i
];
452 pic
->data
[i
]= buf
->data
[i
];
453 pic
->linesize
[i
]= buf
->linesize
[i
];
455 pic
->extended_data
= pic
->data
;
456 avci
->buffer_count
++;
458 if(s
->pkt
) pic
->pkt_pts
= s
->pkt
->pts
;
459 else pic
->pkt_pts
= AV_NOPTS_VALUE
;
460 pic
->reordered_opaque
= s
->reordered_opaque
;
462 if(s
->debug
&FF_DEBUG_BUFFERS
)
463 av_log(s
, AV_LOG_DEBUG
, "default_get_buffer called on pic %p, %d "
464 "buffers used\n", pic
, avci
->buffer_count
);
469 int avcodec_default_get_buffer(AVCodecContext
*avctx
, AVFrame
*frame
)
471 switch (avctx
->codec_type
) {
472 case AVMEDIA_TYPE_VIDEO
:
473 return video_get_buffer(avctx
, frame
);
474 case AVMEDIA_TYPE_AUDIO
:
475 return audio_get_buffer(avctx
, frame
);
481 void avcodec_default_release_buffer(AVCodecContext
*s
, AVFrame
*pic
){
483 InternalBuffer
*buf
, *last
;
484 AVCodecInternal
*avci
= s
->internal
;
486 assert(s
->codec_type
== AVMEDIA_TYPE_VIDEO
);
488 assert(pic
->type
==FF_BUFFER_TYPE_INTERNAL
);
489 assert(avci
->buffer_count
);
492 buf
= NULL
; /* avoids warning */
493 for (i
= 0; i
< avci
->buffer_count
; i
++) { //just 3-5 checks so is not worth to optimize
494 buf
= &avci
->buffer
[i
];
495 if (buf
->data
[0] == pic
->data
[0])
498 assert(i
< avci
->buffer_count
);
499 avci
->buffer_count
--;
500 last
= &avci
->buffer
[avci
->buffer_count
];
503 FFSWAP(InternalBuffer
, *buf
, *last
);
506 for (i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++) {
508 // pic->base[i]=NULL;
510 //printf("R%X\n", pic->opaque);
512 if(s
->debug
&FF_DEBUG_BUFFERS
)
513 av_log(s
, AV_LOG_DEBUG
, "default_release_buffer called on pic %p, %d "
514 "buffers used\n", pic
, avci
->buffer_count
);
517 int avcodec_default_reget_buffer(AVCodecContext
*s
, AVFrame
*pic
){
521 assert(s
->codec_type
== AVMEDIA_TYPE_VIDEO
);
523 /* If no picture return a new buffer */
524 if(pic
->data
[0] == NULL
) {
525 /* We will copy from buffer, so must be readable */
526 pic
->buffer_hints
|= FF_BUFFER_HINTS_READABLE
;
527 return s
->get_buffer(s
, pic
);
530 /* If internal buffer type return the same buffer */
531 if(pic
->type
== FF_BUFFER_TYPE_INTERNAL
) {
532 if(s
->pkt
) pic
->pkt_pts
= s
->pkt
->pts
;
533 else pic
->pkt_pts
= AV_NOPTS_VALUE
;
534 pic
->reordered_opaque
= s
->reordered_opaque
;
539 * Not internal type and reget_buffer not overridden, emulate cr buffer
542 for(i
= 0; i
< AV_NUM_DATA_POINTERS
; i
++)
543 pic
->data
[i
] = pic
->base
[i
] = NULL
;
545 /* Allocate new frame */
546 if (s
->get_buffer(s
, pic
))
548 /* Copy image data from old buffer to new buffer */
549 av_picture_copy((AVPicture
*)pic
, (AVPicture
*)&temp_pic
, s
->pix_fmt
, s
->width
,
551 s
->release_buffer(s
, &temp_pic
); // Release old frame
555 int avcodec_default_execute(AVCodecContext
*c
, int (*func
)(AVCodecContext
*c2
, void *arg2
),void *arg
, int *ret
, int count
, int size
){
558 for(i
=0; i
<count
; i
++){
559 int r
= func(c
, (char*)arg
+ i
*size
);
565 int avcodec_default_execute2(AVCodecContext
*c
, int (*func
)(AVCodecContext
*c2
, void *arg2
, int jobnr
, int threadnr
),void *arg
, int *ret
, int count
){
568 for(i
=0; i
<count
; i
++){
569 int r
= func(c
, arg
, i
, 0);
575 enum PixelFormat
avcodec_default_get_format(struct AVCodecContext
*s
, const enum PixelFormat
*fmt
){
576 while (*fmt
!= PIX_FMT_NONE
&& ff_is_hwaccel_pix_fmt(*fmt
))
581 void avcodec_get_frame_defaults(AVFrame
*pic
){
582 memset(pic
, 0, sizeof(AVFrame
));
584 pic
->pts
= AV_NOPTS_VALUE
;
588 AVFrame
*avcodec_alloc_frame(void){
589 AVFrame
*pic
= av_malloc(sizeof(AVFrame
));
591 if(pic
==NULL
) return NULL
;
593 avcodec_get_frame_defaults(pic
);
598 #if FF_API_AVCODEC_OPEN
599 int attribute_align_arg
avcodec_open(AVCodecContext
*avctx
, AVCodec
*codec
)
601 return avcodec_open2(avctx
, codec
, NULL
);
605 int attribute_align_arg
avcodec_open2(AVCodecContext
*avctx
, AVCodec
*codec
, AVDictionary
**options
)
608 AVDictionary
*tmp
= NULL
;
611 av_dict_copy(&tmp
, *options
, 0);
613 /* If there is a user-supplied mutex locking routine, call it. */
615 if ((*ff_lockmgr_cb
)(&codec_mutex
, AV_LOCK_OBTAIN
))
619 entangled_thread_counter
++;
620 if(entangled_thread_counter
!= 1){
621 av_log(avctx
, AV_LOG_ERROR
, "insufficient thread locking around avcodec_open/close()\n");
626 if(avctx
->codec
|| !codec
) {
627 ret
= AVERROR(EINVAL
);
631 avctx
->internal
= av_mallocz(sizeof(AVCodecInternal
));
632 if (!avctx
->internal
) {
633 ret
= AVERROR(ENOMEM
);
637 if (codec
->priv_data_size
> 0) {
638 if(!avctx
->priv_data
){
639 avctx
->priv_data
= av_mallocz(codec
->priv_data_size
);
640 if (!avctx
->priv_data
) {
641 ret
= AVERROR(ENOMEM
);
644 if (codec
->priv_class
) {
645 *(AVClass
**)avctx
->priv_data
= codec
->priv_class
;
646 av_opt_set_defaults(avctx
->priv_data
);
649 if (codec
->priv_class
&& (ret
= av_opt_set_dict(avctx
->priv_data
, &tmp
)) < 0)
652 avctx
->priv_data
= NULL
;
654 if ((ret
= av_opt_set_dict(avctx
, &tmp
)) < 0)
657 if(avctx
->coded_width
&& avctx
->coded_height
)
658 avcodec_set_dimensions(avctx
, avctx
->coded_width
, avctx
->coded_height
);
659 else if(avctx
->width
&& avctx
->height
)
660 avcodec_set_dimensions(avctx
, avctx
->width
, avctx
->height
);
662 if ((avctx
->coded_width
|| avctx
->coded_height
|| avctx
->width
|| avctx
->height
)
663 && ( av_image_check_size(avctx
->coded_width
, avctx
->coded_height
, 0, avctx
) < 0
664 || av_image_check_size(avctx
->width
, avctx
->height
, 0, avctx
) < 0)) {
665 av_log(avctx
, AV_LOG_WARNING
, "ignoring invalid width/height values\n");
666 avcodec_set_dimensions(avctx
, 0, 0);
669 /* if the decoder init function was already called previously,
670 free the already allocated subtitle_header before overwriting it */
672 av_freep(&avctx
->subtitle_header
);
674 #define SANE_NB_CHANNELS 128U
675 if (avctx
->channels
> SANE_NB_CHANNELS
) {
676 ret
= AVERROR(EINVAL
);
680 avctx
->codec
= codec
;
681 if ((avctx
->codec_type
== AVMEDIA_TYPE_UNKNOWN
|| avctx
->codec_type
== codec
->type
) &&
682 avctx
->codec_id
== CODEC_ID_NONE
) {
683 avctx
->codec_type
= codec
->type
;
684 avctx
->codec_id
= codec
->id
;
686 if (avctx
->codec_id
!= codec
->id
|| (avctx
->codec_type
!= codec
->type
687 && avctx
->codec_type
!= AVMEDIA_TYPE_ATTACHMENT
)) {
688 av_log(avctx
, AV_LOG_ERROR
, "codec type or id mismatches\n");
689 ret
= AVERROR(EINVAL
);
692 avctx
->frame_number
= 0;
695 av_log(avctx
, AV_LOG_DEBUG
, "err{or,}_recognition separate: %d; %d\n",
696 avctx
->error_recognition
, avctx
->err_recognition
);
697 /* FF_ER_CAREFUL (==1) implies AV_EF_CRCCHECK (== 1<<1 - 1),
698 FF_ER_COMPLIANT (==2) implies AV_EF_{CRCCHECK,BITSTREAM} (== 1<<2 - 1), et cetera} */
699 avctx
->err_recognition
|= (1<<(avctx
->error_recognition
-(avctx
->error_recognition
>=FF_ER_VERY_AGGRESSIVE
))) - 1;
700 av_log(avctx
, AV_LOG_DEBUG
, "err{or,}_recognition combined: %d; %d\n",
701 avctx
->error_recognition
, avctx
->err_recognition
);
704 if (HAVE_THREADS
&& !avctx
->thread_opaque
) {
705 ret
= ff_thread_init(avctx
);
711 if (avctx
->codec
->max_lowres
< avctx
->lowres
) {
712 av_log(avctx
, AV_LOG_ERROR
, "The maximum value for lowres supported by the decoder is %d\n",
713 avctx
->codec
->max_lowres
);
714 ret
= AVERROR(EINVAL
);
717 if (avctx
->codec
->encode
) {
719 if (avctx
->codec
->sample_fmts
) {
720 for (i
= 0; avctx
->codec
->sample_fmts
[i
] != AV_SAMPLE_FMT_NONE
; i
++)
721 if (avctx
->sample_fmt
== avctx
->codec
->sample_fmts
[i
])
723 if (avctx
->codec
->sample_fmts
[i
] == AV_SAMPLE_FMT_NONE
) {
724 av_log(avctx
, AV_LOG_ERROR
, "Specified sample_fmt is not supported.\n");
725 ret
= AVERROR(EINVAL
);
729 if (avctx
->codec
->supported_samplerates
) {
730 for (i
= 0; avctx
->codec
->supported_samplerates
[i
] != 0; i
++)
731 if (avctx
->sample_rate
== avctx
->codec
->supported_samplerates
[i
])
733 if (avctx
->codec
->supported_samplerates
[i
] == 0) {
734 av_log(avctx
, AV_LOG_ERROR
, "Specified sample_rate is not supported\n");
735 ret
= AVERROR(EINVAL
);
739 if (avctx
->codec
->channel_layouts
) {
740 if (!avctx
->channel_layout
) {
741 av_log(avctx
, AV_LOG_WARNING
, "channel_layout not specified\n");
743 for (i
= 0; avctx
->codec
->channel_layouts
[i
] != 0; i
++)
744 if (avctx
->channel_layout
== avctx
->codec
->channel_layouts
[i
])
746 if (avctx
->codec
->channel_layouts
[i
] == 0) {
747 av_log(avctx
, AV_LOG_ERROR
, "Specified channel_layout is not supported\n");
748 ret
= AVERROR(EINVAL
);
753 if (avctx
->channel_layout
&& avctx
->channels
) {
754 if (av_get_channel_layout_nb_channels(avctx
->channel_layout
) != avctx
->channels
) {
755 av_log(avctx
, AV_LOG_ERROR
, "channel layout does not match number of channels\n");
756 ret
= AVERROR(EINVAL
);
759 } else if (avctx
->channel_layout
) {
760 avctx
->channels
= av_get_channel_layout_nb_channels(avctx
->channel_layout
);
764 if(avctx
->codec
->init
&& !(avctx
->active_thread_type
&FF_THREAD_FRAME
)){
765 ret
= avctx
->codec
->init(avctx
);
771 entangled_thread_counter
--;
773 /* Release any user-supplied mutex. */
775 (*ff_lockmgr_cb
)(&codec_mutex
, AV_LOCK_RELEASE
);
778 av_dict_free(options
);
785 av_freep(&avctx
->priv_data
);
786 av_freep(&avctx
->internal
);
791 int attribute_align_arg
avcodec_encode_audio(AVCodecContext
*avctx
, uint8_t *buf
, int buf_size
,
792 const short *samples
)
794 if(buf_size
< FF_MIN_BUFFER_SIZE
&& 0){
795 av_log(avctx
, AV_LOG_ERROR
, "buffer smaller than minimum size\n");
798 if((avctx
->codec
->capabilities
& CODEC_CAP_DELAY
) || samples
){
799 int ret
= avctx
->codec
->encode(avctx
, buf
, buf_size
, samples
);
800 avctx
->frame_number
++;
806 int attribute_align_arg
avcodec_encode_video(AVCodecContext
*avctx
, uint8_t *buf
, int buf_size
,
809 if(buf_size
< FF_MIN_BUFFER_SIZE
){
810 av_log(avctx
, AV_LOG_ERROR
, "buffer smaller than minimum size\n");
813 if(av_image_check_size(avctx
->width
, avctx
->height
, 0, avctx
))
815 if((avctx
->codec
->capabilities
& CODEC_CAP_DELAY
) || pict
){
816 int ret
= avctx
->codec
->encode(avctx
, buf
, buf_size
, pict
);
817 avctx
->frame_number
++;
818 emms_c(); //needed to avoid an emms_c() call before every return;
825 int avcodec_encode_subtitle(AVCodecContext
*avctx
, uint8_t *buf
, int buf_size
,
826 const AVSubtitle
*sub
)
829 if(sub
->start_display_time
) {
830 av_log(avctx
, AV_LOG_ERROR
, "start_display_time must be 0.\n");
833 if(sub
->num_rects
== 0 || !sub
->rects
)
835 ret
= avctx
->codec
->encode(avctx
, buf
, buf_size
, sub
);
836 avctx
->frame_number
++;
840 int attribute_align_arg
avcodec_decode_video2(AVCodecContext
*avctx
, AVFrame
*picture
,
841 int *got_picture_ptr
,
847 if((avctx
->coded_width
||avctx
->coded_height
) && av_image_check_size(avctx
->coded_width
, avctx
->coded_height
, 0, avctx
))
852 if((avctx
->codec
->capabilities
& CODEC_CAP_DELAY
) || avpkt
->size
|| (avctx
->active_thread_type
&FF_THREAD_FRAME
)){
853 if (HAVE_THREADS
&& avctx
->active_thread_type
&FF_THREAD_FRAME
)
854 ret
= ff_thread_decode_frame(avctx
, picture
, got_picture_ptr
,
857 ret
= avctx
->codec
->decode(avctx
, picture
, got_picture_ptr
,
859 picture
->pkt_dts
= avpkt
->dts
;
862 emms_c(); //needed to avoid an emms_c() call before every return;
864 if (*got_picture_ptr
)
865 avctx
->frame_number
++;
872 #if FF_API_OLD_DECODE_AUDIO
873 int attribute_align_arg
avcodec_decode_audio3(AVCodecContext
*avctx
, int16_t *samples
,
878 int ret
, got_frame
= 0;
880 if (avctx
->get_buffer
!= avcodec_default_get_buffer
) {
881 av_log(avctx
, AV_LOG_ERROR
, "A custom get_buffer() cannot be used with "
882 "avcodec_decode_audio3()\n");
883 return AVERROR(EINVAL
);
886 ret
= avcodec_decode_audio4(avctx
, &frame
, &got_frame
, avpkt
);
888 if (ret
>= 0 && got_frame
) {
890 int planar
= av_sample_fmt_is_planar(avctx
->sample_fmt
);
891 int data_size
= av_samples_get_buffer_size(&plane_size
, avctx
->channels
,
893 avctx
->sample_fmt
, 1);
894 if (*frame_size_ptr
< data_size
) {
895 av_log(avctx
, AV_LOG_ERROR
, "output buffer size is too small for "
896 "the current frame (%d < %d)\n", *frame_size_ptr
, data_size
);
897 return AVERROR(EINVAL
);
900 memcpy(samples
, frame
.extended_data
[0], plane_size
);
902 if (planar
&& avctx
->channels
> 1) {
903 uint8_t *out
= ((uint8_t *)samples
) + plane_size
;
904 for (ch
= 1; ch
< avctx
->channels
; ch
++) {
905 memcpy(out
, frame
.extended_data
[ch
], plane_size
);
909 *frame_size_ptr
= data_size
;
917 int attribute_align_arg
avcodec_decode_audio4(AVCodecContext
*avctx
,
928 if (!avpkt
->data
&& avpkt
->size
) {
929 av_log(avctx
, AV_LOG_ERROR
, "invalid packet: NULL data, size != 0\n");
930 return AVERROR(EINVAL
);
933 if ((avctx
->codec
->capabilities
& CODEC_CAP_DELAY
) || avpkt
->size
) {
934 ret
= avctx
->codec
->decode(avctx
, frame
, got_frame_ptr
, avpkt
);
935 if (ret
>= 0 && *got_frame_ptr
) {
936 avctx
->frame_number
++;
937 frame
->pkt_dts
= avpkt
->dts
;
943 int avcodec_decode_subtitle2(AVCodecContext
*avctx
, AVSubtitle
*sub
,
951 ret
= avctx
->codec
->decode(avctx
, sub
, got_sub_ptr
, avpkt
);
953 avctx
->frame_number
++;
957 void avsubtitle_free(AVSubtitle
*sub
)
961 for (i
= 0; i
< sub
->num_rects
; i
++)
963 av_freep(&sub
->rects
[i
]->pict
.data
[0]);
964 av_freep(&sub
->rects
[i
]->pict
.data
[1]);
965 av_freep(&sub
->rects
[i
]->pict
.data
[2]);
966 av_freep(&sub
->rects
[i
]->pict
.data
[3]);
967 av_freep(&sub
->rects
[i
]->text
);
968 av_freep(&sub
->rects
[i
]->ass
);
969 av_freep(&sub
->rects
[i
]);
972 av_freep(&sub
->rects
);
974 memset(sub
, 0, sizeof(AVSubtitle
));
977 av_cold
int avcodec_close(AVCodecContext
*avctx
)
979 /* If there is a user-supplied mutex locking routine, call it. */
981 if ((*ff_lockmgr_cb
)(&codec_mutex
, AV_LOCK_OBTAIN
))
985 entangled_thread_counter
++;
986 if(entangled_thread_counter
!= 1){
987 av_log(avctx
, AV_LOG_ERROR
, "insufficient thread locking around avcodec_open/close()\n");
988 entangled_thread_counter
--;
992 if (HAVE_THREADS
&& avctx
->thread_opaque
)
993 ff_thread_free(avctx
);
994 if (avctx
->codec
&& avctx
->codec
->close
)
995 avctx
->codec
->close(avctx
);
996 avcodec_default_free_buffers(avctx
);
997 avctx
->coded_frame
= NULL
;
998 av_freep(&avctx
->internal
);
999 if (avctx
->codec
&& avctx
->codec
->priv_class
)
1000 av_opt_free(avctx
->priv_data
);
1002 av_freep(&avctx
->priv_data
);
1003 if(avctx
->codec
&& avctx
->codec
->encode
)
1004 av_freep(&avctx
->extradata
);
1005 avctx
->codec
= NULL
;
1006 avctx
->active_thread_type
= 0;
1007 entangled_thread_counter
--;
1009 /* Release any user-supplied mutex. */
1010 if (ff_lockmgr_cb
) {
1011 (*ff_lockmgr_cb
)(&codec_mutex
, AV_LOCK_RELEASE
);
1016 AVCodec
*avcodec_find_encoder(enum CodecID id
)
1018 AVCodec
*p
, *experimental
=NULL
;
1021 if (p
->encode
!= NULL
&& p
->id
== id
) {
1022 if (p
->capabilities
& CODEC_CAP_EXPERIMENTAL
&& !experimental
) {
1029 return experimental
;
1032 AVCodec
*avcodec_find_encoder_by_name(const char *name
)
1039 if (p
->encode
!= NULL
&& strcmp(name
,p
->name
) == 0)
1046 AVCodec
*avcodec_find_decoder(enum CodecID id
)
1051 if (p
->decode
!= NULL
&& p
->id
== id
)
1058 AVCodec
*avcodec_find_decoder_by_name(const char *name
)
1065 if (p
->decode
!= NULL
&& strcmp(name
,p
->name
) == 0)
1072 static int get_bit_rate(AVCodecContext
*ctx
)
1075 int bits_per_sample
;
1077 switch(ctx
->codec_type
) {
1078 case AVMEDIA_TYPE_VIDEO
:
1079 case AVMEDIA_TYPE_DATA
:
1080 case AVMEDIA_TYPE_SUBTITLE
:
1081 case AVMEDIA_TYPE_ATTACHMENT
:
1082 bit_rate
= ctx
->bit_rate
;
1084 case AVMEDIA_TYPE_AUDIO
:
1085 bits_per_sample
= av_get_bits_per_sample(ctx
->codec_id
);
1086 bit_rate
= bits_per_sample ? ctx
->sample_rate
* ctx
->channels
* bits_per_sample
: ctx
->bit_rate
;
1095 size_t av_get_codec_tag_string(char *buf
, size_t buf_size
, unsigned int codec_tag
)
1097 int i
, len
, ret
= 0;
1099 for (i
= 0; i
< 4; i
++) {
1100 len
= snprintf(buf
, buf_size
,
1101 isprint(codec_tag
&0xFF) ?
"%c" : "[%d]", codec_tag
&0xFF);
1103 buf_size
= buf_size
> len ? buf_size
- len
: 0;
1110 void avcodec_string(char *buf
, int buf_size
, AVCodecContext
*enc
, int encode
)
1112 const char *codec_name
;
1113 const char *profile
= NULL
;
1117 AVRational display_aspect_ratio
;
1120 p
= avcodec_find_encoder(enc
->codec_id
);
1122 p
= avcodec_find_decoder(enc
->codec_id
);
1125 codec_name
= p
->name
;
1126 profile
= av_get_profile_name(p
, enc
->profile
);
1127 } else if (enc
->codec_id
== CODEC_ID_MPEG2TS
) {
1128 /* fake mpeg2 transport stream codec (currently not
1130 codec_name
= "mpeg2ts";
1131 } else if (enc
->codec_name
[0] != '\0') {
1132 codec_name
= enc
->codec_name
;
1134 /* output avi tags */
1136 av_get_codec_tag_string(tag_buf
, sizeof(tag_buf
), enc
->codec_tag
);
1137 snprintf(buf1
, sizeof(buf1
), "%s / 0x%04X", tag_buf
, enc
->codec_tag
);
1141 switch(enc
->codec_type
) {
1142 case AVMEDIA_TYPE_VIDEO
:
1143 snprintf(buf
, buf_size
,
1145 codec_name
, enc
->mb_decision ?
" (hq)" : "");
1147 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1149 if (enc
->pix_fmt
!= PIX_FMT_NONE
) {
1150 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1152 av_get_pix_fmt_name(enc
->pix_fmt
));
1155 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1157 enc
->width
, enc
->height
);
1158 if (enc
->sample_aspect_ratio
.num
) {
1159 av_reduce(&display_aspect_ratio
.num
, &display_aspect_ratio
.den
,
1160 enc
->width
*enc
->sample_aspect_ratio
.num
,
1161 enc
->height
*enc
->sample_aspect_ratio
.den
,
1163 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1164 " [PAR %d:%d DAR %d:%d]",
1165 enc
->sample_aspect_ratio
.num
, enc
->sample_aspect_ratio
.den
,
1166 display_aspect_ratio
.num
, display_aspect_ratio
.den
);
1168 if(av_log_get_level() >= AV_LOG_DEBUG
){
1169 int g
= av_gcd(enc
->time_base
.num
, enc
->time_base
.den
);
1170 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1172 enc
->time_base
.num
/g
, enc
->time_base
.den
/g
);
1176 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1177 ", q=%d-%d", enc
->qmin
, enc
->qmax
);
1180 case AVMEDIA_TYPE_AUDIO
:
1181 snprintf(buf
, buf_size
,
1185 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1187 if (enc
->sample_rate
) {
1188 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1189 ", %d Hz", enc
->sample_rate
);
1191 av_strlcat(buf
, ", ", buf_size
);
1192 av_get_channel_layout_string(buf
+ strlen(buf
), buf_size
- strlen(buf
), enc
->channels
, enc
->channel_layout
);
1193 if (enc
->sample_fmt
!= AV_SAMPLE_FMT_NONE
) {
1194 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1195 ", %s", av_get_sample_fmt_name(enc
->sample_fmt
));
1198 case AVMEDIA_TYPE_DATA
:
1199 snprintf(buf
, buf_size
, "Data: %s", codec_name
);
1201 case AVMEDIA_TYPE_SUBTITLE
:
1202 snprintf(buf
, buf_size
, "Subtitle: %s", codec_name
);
1204 case AVMEDIA_TYPE_ATTACHMENT
:
1205 snprintf(buf
, buf_size
, "Attachment: %s", codec_name
);
1208 snprintf(buf
, buf_size
, "Invalid Codec type %d", enc
->codec_type
);
1212 if (enc
->flags
& CODEC_FLAG_PASS1
)
1213 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1215 if (enc
->flags
& CODEC_FLAG_PASS2
)
1216 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1219 bitrate
= get_bit_rate(enc
);
1221 snprintf(buf
+ strlen(buf
), buf_size
- strlen(buf
),
1222 ", %d kb/s", bitrate
/ 1000);
1226 const char *av_get_profile_name(const AVCodec
*codec
, int profile
)
1229 if (profile
== FF_PROFILE_UNKNOWN
|| !codec
->profiles
)
1232 for (p
= codec
->profiles
; p
->profile
!= FF_PROFILE_UNKNOWN
; p
++)
1233 if (p
->profile
== profile
)
1239 unsigned avcodec_version( void )
1241 return LIBAVCODEC_VERSION_INT
;
1244 const char *avcodec_configuration(void)
1246 return LIBAV_CONFIGURATION
;
1249 const char *avcodec_license(void)
1251 #define LICENSE_PREFIX "libavcodec license: "
1252 return LICENSE_PREFIX LIBAV_LICENSE
+ sizeof(LICENSE_PREFIX
) - 1;
1255 void avcodec_flush_buffers(AVCodecContext
*avctx
)
1257 if(HAVE_THREADS
&& avctx
->active_thread_type
&FF_THREAD_FRAME
)
1258 ff_thread_flush(avctx
);
1259 else if(avctx
->codec
->flush
)
1260 avctx
->codec
->flush(avctx
);
1263 static void video_free_buffers(AVCodecContext
*s
)
1265 AVCodecInternal
*avci
= s
->internal
;
1271 if (avci
->buffer_count
)
1272 av_log(s
, AV_LOG_WARNING
, "Found %i unreleased buffers!\n",
1273 avci
->buffer_count
);
1274 for(i
=0; i
<INTERNAL_BUFFER_SIZE
; i
++){
1275 InternalBuffer
*buf
= &avci
->buffer
[i
];
1277 av_freep(&buf
->base
[j
]);
1281 av_freep(&avci
->buffer
);
1283 avci
->buffer_count
=0;
1286 static void audio_free_buffers(AVCodecContext
*avctx
)
1288 AVCodecInternal
*avci
= avctx
->internal
;
1289 InternalBuffer
*buf
;
1295 if (buf
->extended_data
) {
1296 av_free(buf
->extended_data
[0]);
1297 if (buf
->extended_data
!= buf
->data
)
1298 av_free(buf
->extended_data
);
1300 av_freep(&avci
->buffer
);
1303 void avcodec_default_free_buffers(AVCodecContext
*avctx
)
1305 switch (avctx
->codec_type
) {
1306 case AVMEDIA_TYPE_VIDEO
:
1307 video_free_buffers(avctx
);
1309 case AVMEDIA_TYPE_AUDIO
:
1310 audio_free_buffers(avctx
);
1317 #if FF_API_OLD_FF_PICT_TYPES
1318 char av_get_pict_type_char(int pict_type
){
1319 return av_get_picture_type_char(pict_type
);
1323 int av_get_bits_per_sample(enum CodecID codec_id
){
1325 case CODEC_ID_ADPCM_SBPRO_2
:
1327 case CODEC_ID_ADPCM_SBPRO_3
:
1329 case CODEC_ID_ADPCM_SBPRO_4
:
1330 case CODEC_ID_ADPCM_CT
:
1331 case CODEC_ID_ADPCM_IMA_WAV
:
1332 case CODEC_ID_ADPCM_IMA_QT
:
1333 case CODEC_ID_ADPCM_SWF
:
1334 case CODEC_ID_ADPCM_MS
:
1335 case CODEC_ID_ADPCM_YAMAHA
:
1336 case CODEC_ID_ADPCM_G722
:
1338 case CODEC_ID_PCM_ALAW
:
1339 case CODEC_ID_PCM_MULAW
:
1340 case CODEC_ID_PCM_S8
:
1341 case CODEC_ID_PCM_U8
:
1342 case CODEC_ID_PCM_ZORK
:
1344 case CODEC_ID_PCM_S16BE
:
1345 case CODEC_ID_PCM_S16LE
:
1346 case CODEC_ID_PCM_S16LE_PLANAR
:
1347 case CODEC_ID_PCM_U16BE
:
1348 case CODEC_ID_PCM_U16LE
:
1350 case CODEC_ID_PCM_S24DAUD
:
1351 case CODEC_ID_PCM_S24BE
:
1352 case CODEC_ID_PCM_S24LE
:
1353 case CODEC_ID_PCM_U24BE
:
1354 case CODEC_ID_PCM_U24LE
:
1356 case CODEC_ID_PCM_S32BE
:
1357 case CODEC_ID_PCM_S32LE
:
1358 case CODEC_ID_PCM_U32BE
:
1359 case CODEC_ID_PCM_U32LE
:
1360 case CODEC_ID_PCM_F32BE
:
1361 case CODEC_ID_PCM_F32LE
:
1363 case CODEC_ID_PCM_F64BE
:
1364 case CODEC_ID_PCM_F64LE
:
1371 #if FF_API_OLD_SAMPLE_FMT
1372 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt
) {
1373 return av_get_bytes_per_sample(sample_fmt
) << 3;
1378 int ff_thread_init(AVCodecContext
*s
){
1383 unsigned int av_xiphlacing(unsigned char *s
, unsigned int v
)
1397 int ff_match_2uint16(const uint16_t (*tab
)[2], int size
, int a
, int b
){
1399 for(i
=0; i
<size
&& !(tab
[i
][0]==a
&& tab
[i
][1]==b
); i
++);
1403 void av_log_missing_feature(void *avc
, const char *feature
, int want_sample
)
1405 av_log(avc
, AV_LOG_WARNING
, "%s not implemented. Update your Libav "
1406 "version to the newest one from Git. If the problem still "
1407 "occurs, it means that your file has a feature which has not "
1408 "been implemented.\n", feature
);
1410 av_log_ask_for_sample(avc
, NULL
);
1413 void av_log_ask_for_sample(void *avc
, const char *msg
, ...)
1415 va_list argument_list
;
1417 va_start(argument_list
, msg
);
1420 av_vlog(avc
, AV_LOG_WARNING
, msg
, argument_list
);
1421 av_log(avc
, AV_LOG_WARNING
, "If you want to help, upload a sample "
1422 "of this file to ftp://upload.libav.org/incoming/ "
1423 "and contact the libav-devel mailing list.\n");
1425 va_end(argument_list
);
1428 static AVHWAccel
*first_hwaccel
= NULL
;
1430 void av_register_hwaccel(AVHWAccel
*hwaccel
)
1432 AVHWAccel
**p
= &first_hwaccel
;
1436 hwaccel
->next
= NULL
;
1439 AVHWAccel
*av_hwaccel_next(AVHWAccel
*hwaccel
)
1441 return hwaccel ? hwaccel
->next
: first_hwaccel
;
1444 AVHWAccel
*ff_find_hwaccel(enum CodecID codec_id
, enum PixelFormat pix_fmt
)
1446 AVHWAccel
*hwaccel
=NULL
;
1448 while((hwaccel
= av_hwaccel_next(hwaccel
))){
1449 if ( hwaccel
->id
== codec_id
1450 && hwaccel
->pix_fmt
== pix_fmt
)
1456 int av_lockmgr_register(int (*cb
)(void **mutex
, enum AVLockOp op
))
1458 if (ff_lockmgr_cb
) {
1459 if (ff_lockmgr_cb(&codec_mutex
, AV_LOCK_DESTROY
))
1461 if (ff_lockmgr_cb(&avformat_mutex
, AV_LOCK_DESTROY
))
1467 if (ff_lockmgr_cb
) {
1468 if (ff_lockmgr_cb(&codec_mutex
, AV_LOCK_CREATE
))
1470 if (ff_lockmgr_cb(&avformat_mutex
, AV_LOCK_CREATE
))
1476 int avpriv_lock_avformat(void)
1478 if (ff_lockmgr_cb
) {
1479 if ((*ff_lockmgr_cb
)(&avformat_mutex
, AV_LOCK_OBTAIN
))
1485 int avpriv_unlock_avformat(void)
1487 if (ff_lockmgr_cb
) {
1488 if ((*ff_lockmgr_cb
)(&avformat_mutex
, AV_LOCK_RELEASE
))
1494 unsigned int avpriv_toupper4(unsigned int x
)
1496 return toupper( x
&0xFF)
1497 + (toupper((x
>>8 )&0xFF)<<8 )
1498 + (toupper((x
>>16)&0xFF)<<16)
1499 + (toupper((x
>>24)&0xFF)<<24);
1504 int ff_thread_get_buffer(AVCodecContext
*avctx
, AVFrame
*f
)
1507 return avctx
->get_buffer(avctx
, f
);
1510 void ff_thread_release_buffer(AVCodecContext
*avctx
, AVFrame
*f
)
1512 f
->owner
->release_buffer(f
->owner
, f
);
1515 void ff_thread_finish_setup(AVCodecContext
*avctx
)
1519 void ff_thread_report_progress(AVFrame
*f
, int progress
, int field
)
1523 void ff_thread_await_progress(AVFrame
*f
, int progress
, int field
)
1529 #if FF_API_THREAD_INIT
1530 int avcodec_thread_init(AVCodecContext
*s
, int thread_count
)
1532 s
->thread_count
= thread_count
;
1533 return ff_thread_init(s
);
1537 enum AVMediaType
avcodec_get_type(enum CodecID codec_id
)
1539 if (codec_id
<= CODEC_ID_NONE
)
1540 return AVMEDIA_TYPE_UNKNOWN
;
1541 else if (codec_id
< CODEC_ID_FIRST_AUDIO
)
1542 return AVMEDIA_TYPE_VIDEO
;
1543 else if (codec_id
< CODEC_ID_FIRST_SUBTITLE
)
1544 return AVMEDIA_TYPE_AUDIO
;
1545 else if (codec_id
< CODEC_ID_FIRST_UNKNOWN
)
1546 return AVMEDIA_TYPE_SUBTITLE
;
1548 return AVMEDIA_TYPE_UNKNOWN
;