2 * AVCodecContext functions for libavcodec
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * AVCodecContext functions for libavcodec
27 #include "libavutil/avassert.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/emms.h"
32 #include "libavutil/fifo.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/thread.h"
38 #include "avcodec_internal.h"
40 #include "codec_desc.h"
41 #include "codec_internal.h"
44 #include "frame_thread_encoder.h"
47 #include "refstruct.h"
51 * Maximum size in bytes of extradata.
52 * This value was chosen such that every bit of the buffer is
53 * addressable by a 32-bit signed integer as used by get_bits.
55 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
57 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
61 for (i = 0; i < count; i++) {
62 size_t offset = i * size;
63 int r = func(c, FF_PTR_ADD((char *)arg, offset));
71 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
75 for (i = 0; i < count; i++) {
76 int r = func(c, arg, i, 0);
84 static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
86 static void lock_avcodec(const FFCodec *codec)
88 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
89 ff_mutex_lock(&codec_mutex);
92 static void unlock_avcodec(const FFCodec *codec)
94 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
95 ff_mutex_unlock(&codec_mutex);
98 static int64_t get_bit_rate(AVCodecContext *ctx)
103 switch (ctx->codec_type) {
104 case AVMEDIA_TYPE_VIDEO:
105 case AVMEDIA_TYPE_DATA:
106 case AVMEDIA_TYPE_SUBTITLE:
107 case AVMEDIA_TYPE_ATTACHMENT:
108 bit_rate = ctx->bit_rate;
110 case AVMEDIA_TYPE_AUDIO:
111 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
112 if (bits_per_sample) {
113 bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels;
114 if (bit_rate > INT64_MAX / bits_per_sample) {
117 bit_rate *= bits_per_sample;
119 bit_rate = ctx->bit_rate;
128 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
131 AVCodecInternal *avci;
132 const FFCodec *codec2;
134 if (avcodec_is_open(avctx))
137 if (!codec && !avctx->codec) {
138 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
139 return AVERROR(EINVAL);
141 if (codec && avctx->codec && codec != avctx->codec) {
142 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
143 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
144 return AVERROR(EINVAL);
147 codec = avctx->codec;
148 codec2 = ffcodec(codec);
150 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
151 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
152 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
153 return AVERROR(EINVAL);
156 avctx->codec_type = codec->type;
157 avctx->codec_id = codec->id;
158 avctx->codec = codec;
160 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
161 return AVERROR(EINVAL);
163 avci = av_codec_is_decoder(codec) ?
164 ff_decode_internal_alloc() :
165 ff_encode_internal_alloc();
167 ret = AVERROR(ENOMEM);
170 avctx->internal = avci;
172 avci->buffer_frame = av_frame_alloc();
173 avci->buffer_pkt = av_packet_alloc();
174 if (!avci->buffer_frame || !avci->buffer_pkt) {
175 ret = AVERROR(ENOMEM);
179 if (codec2->priv_data_size > 0) {
180 if (!avctx->priv_data) {
181 avctx->priv_data = av_mallocz(codec2->priv_data_size);
182 if (!avctx->priv_data) {
183 ret = AVERROR(ENOMEM);
186 if (codec->priv_class) {
187 *(const AVClass **)avctx->priv_data = codec->priv_class;
188 av_opt_set_defaults(avctx->priv_data);
191 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, options)) < 0)
194 avctx->priv_data = NULL;
196 if ((ret = av_opt_set_dict(avctx, options)) < 0)
199 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
200 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
201 ret = AVERROR(EINVAL);
205 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
206 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
207 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
208 if (avctx->coded_width && avctx->coded_height)
209 ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
210 else if (avctx->width && avctx->height)
211 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
216 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
217 && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
218 || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
219 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
220 ff_set_dimensions(avctx, 0, 0);
223 if (avctx->width > 0 && avctx->height > 0) {
224 if (av_image_check_sar(avctx->width, avctx->height,
225 avctx->sample_aspect_ratio) < 0) {
226 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
227 avctx->sample_aspect_ratio.num,
228 avctx->sample_aspect_ratio.den);
229 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
233 if (avctx->sample_rate < 0) {
234 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
235 ret = AVERROR(EINVAL);
238 if (avctx->block_align < 0) {
239 av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align);
240 ret = AVERROR(EINVAL);
244 #if FF_API_OLD_CHANNEL_LAYOUT
245 FF_DISABLE_DEPRECATION_WARNINGS
246 /* compat wrapper for old-style callers */
247 if (avctx->channel_layout && !avctx->channels)
248 avctx->channels = av_popcount64(avctx->channel_layout);
250 if ((avctx->channels && avctx->ch_layout.nb_channels != avctx->channels) ||
251 (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
252 avctx->ch_layout.u.mask != avctx->channel_layout))) {
253 av_channel_layout_uninit(&avctx->ch_layout);
254 if (avctx->channel_layout) {
255 av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
257 avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
259 avctx->ch_layout.nb_channels = avctx->channels;
261 FF_ENABLE_DEPRECATION_WARNINGS
264 /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
265 * in particular checks that nb_channels is set for all audio encoders. */
266 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
267 && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
268 av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n",
269 av_codec_is_decoder(codec) ? "Decoder" : "Encoder");
270 ret = AVERROR(EINVAL);
273 if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
274 av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
275 ret = AVERROR(EINVAL);
278 if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
279 av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
280 ret = AVERROR(EINVAL);
284 avctx->frame_num = 0;
285 #if FF_API_AVCTX_FRAME_NUMBER
286 FF_DISABLE_DEPRECATION_WARNINGS
287 avctx->frame_number = avctx->frame_num;
288 FF_ENABLE_DEPRECATION_WARNINGS
290 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
292 if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
293 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
294 const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
295 const AVCodec *codec2;
296 av_log(avctx, AV_LOG_ERROR,
297 "The %s '%s' is experimental but experimental codecs are not enabled, "
298 "add '-strict %d' if you want to use it.\n",
299 codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
300 codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
301 if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
302 av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
303 codec_string, codec2->name);
304 ret = AVERROR_EXPERIMENTAL;
308 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
309 (!avctx->time_base.num || !avctx->time_base.den)) {
310 avctx->time_base.num = 1;
311 avctx->time_base.den = avctx->sample_rate;
314 if (av_codec_is_encoder(avctx->codec))
315 ret = ff_encode_preinit(avctx);
317 ret = ff_decode_preinit(avctx);
321 if (HAVE_THREADS && !avci->frame_thread_encoder) {
322 /* Frame-threaded decoders call FFCodec.init for their child contexts. */
323 lock_avcodec(codec2);
324 ret = ff_thread_init(avctx);
325 unlock_avcodec(codec2);
330 if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
331 avctx->thread_count = 1;
333 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
334 avci->frame_thread_encoder) {
336 lock_avcodec(codec2);
337 ret = codec2->init(avctx);
338 unlock_avcodec(codec2);
340 avci->needs_close = codec2->caps_internal & FF_CODEC_CAP_INIT_CLEANUP;
344 avci->needs_close = 1;
349 if (av_codec_is_decoder(avctx->codec)) {
350 if (!avctx->bit_rate)
351 avctx->bit_rate = get_bit_rate(avctx);
353 #if FF_API_OLD_CHANNEL_LAYOUT
354 FF_DISABLE_DEPRECATION_WARNINGS
355 /* update the deprecated fields for old-style callers */
356 avctx->channels = avctx->ch_layout.nb_channels;
357 avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
358 avctx->ch_layout.u.mask : 0;
359 FF_ENABLE_DEPRECATION_WARNINGS
362 /* validate channel layout from the decoder */
363 if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) ||
364 avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
365 ret = AVERROR(EINVAL);
368 if (avctx->bits_per_coded_sample < 0) {
369 ret = AVERROR(EINVAL);
373 if (codec->priv_class)
374 av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
380 avcodec_close(avctx);
384 void avcodec_flush_buffers(AVCodecContext *avctx)
386 AVCodecInternal *avci = avctx->internal;
388 if (av_codec_is_encoder(avctx->codec)) {
389 int caps = avctx->codec->capabilities;
391 if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) {
392 // Only encoders that explicitly declare support for it can be
393 // flushed. Otherwise, this is a no-op.
394 av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder "
395 "that doesn't support it\n");
398 ff_encode_flush_buffers(avctx);
400 ff_decode_flush_buffers(avctx);
403 avci->draining_done = 0;
404 av_frame_unref(avci->buffer_frame);
405 av_packet_unref(avci->buffer_pkt);
407 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
408 ff_thread_flush(avctx);
409 else if (ffcodec(avctx->codec)->flush)
410 ffcodec(avctx->codec)->flush(avctx);
413 void avsubtitle_free(AVSubtitle *sub)
417 for (i = 0; i < sub->num_rects; i++) {
418 AVSubtitleRect *const rect = sub->rects[i];
420 av_freep(&rect->data[0]);
421 av_freep(&rect->data[1]);
422 av_freep(&rect->data[2]);
423 av_freep(&rect->data[3]);
424 av_freep(&rect->text);
425 av_freep(&rect->ass);
427 av_freep(&sub->rects[i]);
430 av_freep(&sub->rects);
432 memset(sub, 0, sizeof(*sub));
435 av_cold int avcodec_close(AVCodecContext *avctx)
442 if (avcodec_is_open(avctx)) {
443 AVCodecInternal *avci = avctx->internal;
445 if (CONFIG_FRAME_THREAD_ENCODER &&
446 avci->frame_thread_encoder && avctx->thread_count > 1) {
447 ff_frame_thread_encoder_free(avctx);
449 if (HAVE_THREADS && avci->thread_ctx)
450 ff_thread_free(avctx);
451 if (avci->needs_close && ffcodec(avctx->codec)->close)
452 ffcodec(avctx->codec)->close(avctx);
453 avci->byte_buffer_size = 0;
454 av_freep(&avci->byte_buffer);
455 av_frame_free(&avci->buffer_frame);
456 av_packet_free(&avci->buffer_pkt);
457 av_packet_free(&avci->last_pkt_props);
459 av_packet_free(&avci->in_pkt);
460 av_frame_free(&avci->in_frame);
461 av_frame_free(&avci->recon_frame);
463 ff_refstruct_unref(&avci->pool);
465 ff_hwaccel_uninit(avctx);
467 av_bsf_free(&avci->bsf);
469 #if FF_API_DROPCHANGED
470 av_channel_layout_uninit(&avci->initial_ch_layout);
474 ff_icc_context_uninit(&avci->icc);
477 av_freep(&avctx->internal);
480 for (i = 0; i < avctx->nb_coded_side_data; i++)
481 av_freep(&avctx->coded_side_data[i].data);
482 av_freep(&avctx->coded_side_data);
483 avctx->nb_coded_side_data = 0;
485 av_buffer_unref(&avctx->hw_frames_ctx);
486 av_buffer_unref(&avctx->hw_device_ctx);
488 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
489 av_opt_free(avctx->priv_data);
491 av_freep(&avctx->priv_data);
492 if (av_codec_is_encoder(avctx->codec)) {
493 av_freep(&avctx->extradata);
494 avctx->extradata_size = 0;
495 } else if (av_codec_is_decoder(avctx->codec))
496 av_freep(&avctx->subtitle_header);
499 avctx->active_thread_type = 0;
504 static const char *unknown_if_null(const char *str)
506 return str ? str : "unknown";
509 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
511 const char *codec_type;
512 const char *codec_name;
513 const char *profile = NULL;
517 AVRational display_aspect_ratio;
518 const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
521 if (!buf || buf_size <= 0)
523 av_bprint_init_for_buffer(&bprint, buf, buf_size);
524 codec_type = av_get_media_type_string(enc->codec_type);
525 codec_name = avcodec_get_name(enc->codec_id);
526 profile = avcodec_profile_name(enc->codec_id, enc->profile);
528 av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown",
530 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
532 if (enc->codec && strcmp(enc->codec->name, codec_name))
533 av_bprintf(&bprint, " (%s)", enc->codec->name);
536 av_bprintf(&bprint, " (%s)", profile);
537 if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
538 && av_log_get_level() >= AV_LOG_VERBOSE
540 av_bprintf(&bprint, ", %d reference frame%s",
541 enc->refs, enc->refs > 1 ? "s" : "");
544 av_bprintf(&bprint, " (%s / 0x%04X)",
545 av_fourcc2str(enc->codec_tag), enc->codec_tag);
547 switch (enc->codec_type) {
548 case AVMEDIA_TYPE_VIDEO:
552 av_bprintf(&bprint, "%s%s", separator,
553 enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
554 unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt)));
556 av_bprint_chars(&bprint, '(', 1);
559 /* The following check ensures that '(' has been written
560 * and therefore allows us to erase it if it turns out
561 * to be unnecessary. */
562 if (!av_bprint_is_complete(&bprint))
565 if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
566 enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth)
567 av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample);
568 if (enc->color_range != AVCOL_RANGE_UNSPECIFIED &&
569 (str = av_color_range_name(enc->color_range)))
570 av_bprintf(&bprint, "%s, ", str);
572 if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
573 enc->color_primaries != AVCOL_PRI_UNSPECIFIED ||
574 enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
575 const char *col = unknown_if_null(av_color_space_name(enc->colorspace));
576 const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries));
577 const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc));
578 if (strcmp(col, pri) || strcmp(col, trc)) {
580 av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc);
582 av_bprintf(&bprint, "%s, ", col);
585 if (enc->field_order != AV_FIELD_UNKNOWN) {
586 const char *field_order = "progressive";
587 if (enc->field_order == AV_FIELD_TT)
588 field_order = "top first";
589 else if (enc->field_order == AV_FIELD_BB)
590 field_order = "bottom first";
591 else if (enc->field_order == AV_FIELD_TB)
592 field_order = "top coded first (swapped)";
593 else if (enc->field_order == AV_FIELD_BT)
594 field_order = "bottom coded first (swapped)";
596 av_bprintf(&bprint, "%s, ", field_order);
599 if (av_log_get_level() >= AV_LOG_VERBOSE &&
600 enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
601 (str = av_chroma_location_name(enc->chroma_sample_location)))
602 av_bprintf(&bprint, "%s, ", str);
604 if (len == bprint.len) {
605 bprint.str[len - 1] = '\0';
608 if (bprint.len - 2 < bprint.size) {
609 /* Erase the last ", " */
611 bprint.str[bprint.len] = '\0';
613 av_bprint_chars(&bprint, ')', 1);
618 av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ",
619 enc->width, enc->height);
621 if (av_log_get_level() >= AV_LOG_VERBOSE &&
622 (enc->width != enc->coded_width ||
623 enc->height != enc->coded_height))
624 av_bprintf(&bprint, " (%dx%d)",
625 enc->coded_width, enc->coded_height);
627 if (enc->sample_aspect_ratio.num) {
628 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
629 enc->width * (int64_t)enc->sample_aspect_ratio.num,
630 enc->height * (int64_t)enc->sample_aspect_ratio.den,
632 av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]",
633 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
634 display_aspect_ratio.num, display_aspect_ratio.den);
636 if (av_log_get_level() >= AV_LOG_DEBUG) {
637 int g = av_gcd(enc->time_base.num, enc->time_base.den);
638 av_bprintf(&bprint, ", %d/%d",
639 enc->time_base.num / g, enc->time_base.den / g);
643 av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax);
645 if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS)
646 av_bprintf(&bprint, ", Closed Captions");
647 if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN)
648 av_bprintf(&bprint, ", Film Grain");
649 if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS)
650 av_bprintf(&bprint, ", lossless");
653 case AVMEDIA_TYPE_AUDIO:
654 av_bprintf(&bprint, "%s", separator);
656 if (enc->sample_rate) {
657 av_bprintf(&bprint, "%d Hz, ", enc->sample_rate);
661 int ret = av_channel_layout_describe(&enc->ch_layout, buf, sizeof(buf));
663 av_bprintf(&bprint, "%s", buf);
665 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE &&
666 (str = av_get_sample_fmt_name(enc->sample_fmt))) {
667 av_bprintf(&bprint, ", %s", str);
669 if ( enc->bits_per_raw_sample > 0
670 && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8)
671 av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample);
672 if (av_log_get_level() >= AV_LOG_VERBOSE) {
673 if (enc->initial_padding)
674 av_bprintf(&bprint, ", delay %d", enc->initial_padding);
675 if (enc->trailing_padding)
676 av_bprintf(&bprint, ", padding %d", enc->trailing_padding);
679 case AVMEDIA_TYPE_DATA:
680 if (av_log_get_level() >= AV_LOG_DEBUG) {
681 int g = av_gcd(enc->time_base.num, enc->time_base.den);
683 av_bprintf(&bprint, ", %d/%d",
684 enc->time_base.num / g, enc->time_base.den / g);
687 case AVMEDIA_TYPE_SUBTITLE:
689 av_bprintf(&bprint, ", %dx%d", enc->width, enc->height);
695 if (enc->flags & AV_CODEC_FLAG_PASS1)
696 av_bprintf(&bprint, ", pass 1");
697 if (enc->flags & AV_CODEC_FLAG_PASS2)
698 av_bprintf(&bprint, ", pass 2");
700 bitrate = get_bit_rate(enc);
702 av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000);
703 } else if (enc->rc_max_rate > 0) {
704 av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
708 int avcodec_is_open(AVCodecContext *s)
710 return !!s->internal;
713 int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
715 av_frame_unref(frame);
717 if (av_codec_is_decoder(avctx->codec))
718 return ff_decode_receive_frame(avctx, frame);
719 return ff_encode_receive_frame(avctx, frame);