Lines Matching refs:avctx
52 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
64 if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
65 av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
84 av_log(avctx, AV_LOG_ERROR, "Invalid channel count");
88 avctx->channels = val;
94 avctx->channel_layout = bytestream_get_le64(&data);
104 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
108 avctx->sample_rate = val;
114 avctx->width = bytestream_get_le32(&data);
115 avctx->height = bytestream_get_le32(&data);
117 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
124 av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
128 av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
129 if (avctx->err_recognition & AV_EF_EXPLODE)
170 static int decode_bsfs_init(AVCodecContext *avctx)
172 AVCodecInternal *avci = avctx->internal;
173 const FFCodec *const codec = ffcodec(avctx->codec);
181 av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
191 ret = avcodec_parameters_from_context(avci->bsf->par_in, avctx);
205 int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
207 AVCodecInternal *avci = avctx->internal;
219 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
220 ret = extract_packet_props(avctx->internal, pkt);
225 ret = apply_param_change(avctx, pkt);
277 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
279 AVCodecInternal *avci = avctx->internal;
281 const FFCodec *const codec = ffcodec(avctx->codec);
287 ret = ff_decode_get_packet(avctx, pkt);
298 !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
299 avctx->active_thread_type & FF_THREAD_FRAME))
304 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
305 ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
307 ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
311 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
312 if(!avctx->has_b_frames)
314 //FIXME these should be under if(!avctx->has_b_frames)
316 if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
317 if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
318 if (!frame->width) frame->width = avctx->width;
319 if (!frame->height) frame->height = avctx->height;
320 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
327 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
330 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
339 frame->format = avctx->sample_fmt;
341 int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
350 frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
351 avctx->ch_layout.u.mask : 0;
353 frame->channels = avctx->ch_layout.nb_channels;
357 frame->sample_rate = avctx->sample_rate;
365 av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
372 !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
379 !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
384 av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
388 frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
389 if(avctx->pkt_timebase.num && avctx->sample_rate) {
391 (AVRational){1, avctx->sample_rate},
392 avctx->pkt_timebase);
400 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
402 av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
411 !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
416 if(avctx->pkt_timebase.num && avctx->sample_rate) {
418 (AVRational){1, avctx->sample_rate},
419 avctx->pkt_timebase);
422 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
424 av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
430 if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL) && got_frame) {
442 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO &&
444 ret >= 0 && ret != pkt->size && !(avctx->codec->capabilities & AV_CODEC_CAP_SUBFRAMES)) {
445 av_log(avctx, AV_LOG_WARNING, "Multiple frames in a packet.\n");
453 if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
455 if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
460 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
461 avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
470 int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
471 avctx->thread_count : 1);
474 av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
507 static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
513 if (discarded_samples > avctx->max_samples)
515 ret = decode_simple_internal(avctx, frame, &discarded_samples);
523 static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
525 AVCodecInternal *avci = avctx->internal;
526 const FFCodec *const codec = ffcodec(avctx->codec);
532 ret = codec->cb.receive_frame(avctx, frame);
536 ret = decode_simple_receive_frame(avctx, frame);
548 frame->best_effort_timestamp = guess_correct_pts(avctx,
555 !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
561 ret = fdd->post_process(avctx, frame);
576 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
578 AVCodecInternal *avci = avctx->internal;
581 if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
584 if (avctx->internal->draining)
604 ret = decode_receive_frame_internal(avctx, avci->buffer_frame);
612 static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
619 av_log(avctx, AV_LOG_WARNING,
632 if (!avctx->apply_cropping)
635 return av_frame_apply_cropping(frame, avctx->flags & AV_CODEC_FLAG_UNALIGNED ?
639 int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
641 AVCodecInternal *avci = avctx->internal;
646 if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
652 ret = decode_receive_frame_internal(avctx, frame);
657 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
658 ret = apply_cropping(avctx, frame);
665 avctx->frame_number++;
667 if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
669 if (avctx->frame_number == 1) {
671 switch(avctx->codec_type) {
678 avctx->sample_rate;
694 if (avctx->frame_number > 1) {
697 switch(avctx->codec_type) {
705 avci->initial_sample_rate != avctx->sample_rate ||
717 av_log(avctx, AV_LOG_INFO, "dropped changed frame #%d pts %"PRId64
719 avctx->frame_number, frame->pts,
736 static int recode_subtitle(AVCodecContext *avctx, AVPacket **outpkt,
746 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
756 av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
760 cd = iconv_open("UTF-8", avctx->sub_charenc);
776 av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
777 "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
792 av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
816 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
823 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
826 if (!avctx->codec)
828 if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
829 av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
836 if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
837 AVCodecInternal *avci = avctx->internal;
840 ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
844 if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
846 avctx->pkt_timebase, AV_TIME_BASE_Q);
847 ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
858 avctx->pkt_timebase.num) {
861 avctx->pkt_timebase, ms);
864 if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
866 else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
870 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
872 av_log(avctx, AV_LOG_ERROR,
882 avctx->frame_number++;
888 enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx,
897 if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
899 (AVHWDeviceContext*)avctx->hw_device_ctx->data;
901 config = &ffcodec(avctx->codec)->hw_configs[i]->public;
930 config = avcodec_get_hw_config(avctx->codec, i);
951 int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,
958 if (!avctx->hwaccel)
961 if (avctx->hw_frames_ctx)
963 if (!avctx->hw_device_ctx) {
964 av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
969 device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
971 av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
977 ret = avcodec_get_hw_frames_parameters(avctx,
978 avctx->hw_device_ctx,
979 avctx->hwaccel->pix_fmt,
980 &avctx->hw_frames_ctx);
984 frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
993 ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
995 av_buffer_unref(&avctx->hw_frames_ctx);
1002 int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
1013 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1028 ret = hwa->frame_params(avctx, frames_ref);
1035 if (avctx->extra_hw_frames > 0)
1036 frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1040 if (avctx->active_thread_type & FF_THREAD_FRAME)
1041 frames_ctx->initial_pool_size += avctx->thread_count;
1051 static int hwaccel_init(AVCodecContext *avctx,
1059 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
1060 av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1066 avctx->internal->hwaccel_priv_data =
1068 if (!avctx->internal->hwaccel_priv_data)
1072 avctx->hwaccel = hwaccel;
1074 err = hwaccel->init(avctx);
1076 av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1079 av_freep(&avctx->internal->hwaccel_priv_data);
1080 avctx->hwaccel = NULL;
1088 static void hwaccel_uninit(AVCodecContext *avctx)
1090 if (avctx->hwaccel && avctx->hwaccel->uninit)
1091 avctx->hwaccel->uninit(avctx);
1093 av_freep(&avctx->internal->hwaccel_priv_data);
1095 avctx->hwaccel = NULL;
1097 av_buffer_unref(&avctx->hw_frames_ctx);
1100 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1118 avctx->sw_pix_fmt = fmt[n - 1];
1127 hwaccel_uninit(avctx);
1129 user_choice = avctx->get_format(avctx, choices);
1138 av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1143 av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1151 av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1157 if (ffcodec(avctx->codec)->hw_configs) {
1159 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1178 avctx->hw_frames_ctx) {
1180 (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1182 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1189 avctx->hw_device_ctx) {
1191 (AVHWDeviceContext*)avctx->hw_device_ctx->data;
1193 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1205 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1210 av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
1212 err = hwaccel_init(avctx, hw_config);
1220 av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1247 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
1249 AVPacket *pkt = avctx->internal->last_pkt_props;
1267 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
1294 frame->reordered_opaque = avctx->reordered_opaque;
1297 frame->color_primaries = avctx->color_primaries;
1299 frame->color_trc = avctx->color_trc;
1301 frame->colorspace = avctx->colorspace;
1303 frame->color_range = avctx->color_range;
1305 frame->chroma_location = avctx->chroma_sample_location;
1307 switch (avctx->codec->type) {
1309 frame->format = avctx->pix_fmt;
1311 frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
1316 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1325 frame->sample_rate = avctx->sample_rate;
1327 frame->format = avctx->sample_fmt;
1329 int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
1345 static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
1347 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1360 av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1403 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
1405 const AVHWAccel *hwaccel = avctx->hwaccel;
1409 av_assert0(av_codec_is_decoder(avctx->codec));
1411 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1412 if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1413 (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
1414 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1420 frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1421 frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1426 av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1430 } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1434 avctx->channels = avctx->ch_layout.nb_channels;
1435 avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
1436 avctx->ch_layout.u.mask : 0;
1440 if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1441 av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1446 ret = ff_decode_frame_props(avctx, frame);
1452 ret = hwaccel->alloc_frame(avctx, frame);
1456 avctx->sw_pix_fmt = avctx->pix_fmt;
1458 ret = avctx->get_buffer2(avctx, frame, flags);
1462 validate_avframe_allocation(avctx, frame);
1469 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1470 !(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)) {
1471 frame->width = avctx->width;
1472 frame->height = avctx->height;
1477 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1484 static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
1489 av_assert0(avctx->codec_type == AVMEDIA_TYPE_VIDEO);
1491 if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1492 av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1493 frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1498 return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1501 return ff_decode_frame_props(avctx, frame);
1509 ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1521 int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
1523 int ret = reget_buffer_internal(avctx, frame, flags);
1525 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1529 int ff_decode_preinit(AVCodecContext *avctx)
1531 AVCodecInternal *avci = avctx->internal;
1536 av_freep(&avctx->subtitle_header);
1540 if ((avctx->thread_type & FF_THREAD_FRAME) &&
1541 avctx->get_buffer2 != avcodec_default_get_buffer2 &&
1542 !avctx->thread_safe_callbacks) {
1543 av_log(avctx, AV_LOG_WARNING, "Requested frame threading with a "
1551 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->ch_layout.nb_channels == 0 &&
1552 !(avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
1553 av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
1556 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1557 av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1558 avctx->codec->max_lowres);
1559 avctx->lowres = avctx->codec->max_lowres;
1561 if (avctx->sub_charenc) {
1562 if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1563 av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1566 } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1567 av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1569 avctx->codec_descriptor->name);
1570 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING;
1574 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC)
1575 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER;
1577 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) {
1579 iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1582 av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1583 "with input character encoding \"%s\"\n", avctx->sub_charenc);
1588 av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1597 avctx->pts_correction_num_faulty_pts =
1598 avctx->pts_correction_num_faulty_dts = 0;
1599 avctx->pts_correction_last_pts =
1600 avctx->pts_correction_last_dts = INT64_MIN;
1602 if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1603 && avctx->codec_descriptor->type == AVMEDIA_TYPE_VIDEO)
1604 av_log(avctx, AV_LOG_WARNING,
1606 if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1607 avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS;
1617 ret = decode_bsfs_init(avctx);