• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/minidlna/ffmpeg-2.3.4/libavcodec/

Lines Matching refs:avctx

261 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
263 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
266 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
268 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
271 avctx->sample_aspect_ratio = sar;
519 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
521 FramePool *pool = avctx->internal->pool;
524 switch (avctx->codec_type) {
536 avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
541 av_image_fill_linesizes(picture.linesize, avctx->pix_fmt, w);
550 tmpsize = av_image_fill_pointers(picture.data, avctx->pix_fmt, h,
618 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
620 FramePool *pool = avctx->internal->pool;
654 if (avctx->debug & FF_DEBUG_BUFFERS)
655 av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
724 int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
728 if ((ret = update_frame_pool(avctx, frame)) < 0)
737 switch (avctx->codec_type) {
739 return video_get_buffer(avctx, frame);
741 return audio_get_buffer(avctx, frame);
747 int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
749 AVPacket *pkt = avctx->internal->pkt;
785 frame->reordered_opaque = avctx->reordered_opaque;
789 frame->color_primaries = avctx->color_primaries;
791 frame->color_trc = avctx->color_trc;
793 av_frame_set_colorspace(frame, avctx->colorspace);
795 av_frame_set_color_range(frame, avctx->color_range);
797 frame->chroma_location = avctx->chroma_sample_location;
800 switch (avctx->codec->type) {
802 frame->format = avctx->pix_fmt;
804 frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
809 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
818 frame->sample_rate = avctx->sample_rate;
820 frame->format = avctx->sample_fmt;
822 if (avctx->channel_layout) {
823 if (av_get_channel_layout_nb_channels(avctx->channel_layout) !=
824 avctx->channels) {
825 av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
830 frame->channel_layout = avctx->channel_layout;
832 if (avctx->channels > FF_SANE_NB_CHANNELS) {
833 av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
834 avctx->channels);
839 av_frame_set_channels(frame, avctx->channels);
847 int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
849 return avcodec_default_get_buffer2(avctx, frame, 0);
853 AVCodecContext avctx;
861 if (priv->avctx.release_buffer)
862 priv->avctx.release_buffer(&priv->avctx, &priv->frame);
874 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
876 return ff_init_buffer_info(avctx, frame);
879 static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
881 const AVHWAccel *hwaccel = avctx->hwaccel;
885 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
886 if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0 || avctx->pix_fmt<0) {
887 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
891 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
893 frame->width = FFMAX(avctx->width, FF_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
894 frame->height = FFMAX(avctx->height, FF_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
898 ret = ff_decode_frame_props(avctx, frame);
901 if ((ret = ff_init_buffer_info(avctx, frame)) < 0)
905 ret = hwaccel->alloc_frame(avctx, frame);
918 if (avctx->get_buffer) {
926 ret = avctx->get_buffer(avctx, frame);
942 priv->avctx = *avctx;
967 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
988 planes = planar ? avctx->channels : 1;
1012 frame->width = avctx->width;
1013 frame->height = avctx->height;
1018 avctx->release_buffer(avctx, frame);
1026 ret = avctx->get_buffer2(avctx, frame, flags);
1029 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) {
1030 frame->width = avctx->width;
1031 frame->height = avctx->height;
1037 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
1039 int ret = get_buffer_internal(avctx, frame, flags);
1041 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1045 static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
1050 av_assert0(avctx->codec_type == AVMEDIA_TYPE_VIDEO);
1052 if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1053 av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1054 frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1058 ff_init_buffer_info(avctx, frame);
1061 return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1064 return ff_decode_frame_props(avctx, frame);
1072 ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1084 int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
1086 int ret = reget_buffer_internal(avctx, frame);
1088 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1168 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1171 enum AVPixelFormat ret = avctx->get_format(avctx, fmt);
1177 if (avctx->hwaccel && avctx->hwaccel->uninit)
1178 avctx->hwaccel->uninit(avctx);
1179 av_freep(&avctx->internal->hwaccel_priv_data);
1180 avctx->hwaccel = NULL;
1183 !(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)) {
1187 hwaccel = find_hwaccel(avctx->codec_id, ret);
1189 av_log(avctx, AV_LOG_ERROR,
1196 avctx->internal->hwaccel_priv_data = av_mallocz(hwaccel->priv_data_size);
1197 if (!avctx->internal->hwaccel_priv_data)
1202 err = hwaccel->init(avctx);
1204 av_freep(&avctx->internal->hwaccel_priv_data);
1208 avctx->hwaccel = hwaccel;
1279 int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
1285 ret = avcodec_open2(avctx, codec, options);
1287 ff_lock_avcodec(avctx);
1291 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
1296 if (avcodec_is_open(avctx))
1299 if ((!codec && !avctx->codec)) {
1300 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
1303 if ((codec && avctx->codec && codec != avctx->codec)) {
1304 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
1305 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
1309 codec = avctx->codec;
1311 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
1317 ret = ff_lock_avcodec(avctx);
1321 avctx->internal = av_mallocz(sizeof(AVCodecInternal));
1322 if (!avctx->internal) {
1327 avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
1328 if (!avctx->internal->pool) {
1333 avctx->internal->to_free = av_frame_alloc();
1334 if (!avctx->internal->to_free) {
1340 if (!avctx->priv_data) {
1341 avctx->priv_data = av_mallocz(codec->priv_data_size);
1342 if (!avctx->priv_data) {
1347 *(const AVClass **)avctx->priv_data = codec->priv_class;
1348 av_opt_set_defaults(avctx->priv_data);
1351 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
1354 avctx->priv_data = NULL;
1356 if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
1360 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
1361 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F))) {
1362 if (avctx->coded_width && avctx->coded_height)
1363 ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
1364 else if (avctx->width && avctx->height)
1365 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1370 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
1371 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
1372 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
1373 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
1374 ff_set_dimensions(avctx, 0, 0);
1377 if (avctx->width > 0 && avctx->height > 0) {
1378 if (av_image_check_sar(avctx->width, avctx->height,
1379 avctx->sample_aspect_ratio) < 0) {
1380 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1381 avctx->sample_aspect_ratio.num,
1382 avctx->sample_aspect_ratio.den);
1383 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
1390 av_freep(&avctx->subtitle_header);
1392 if (avctx->channels > FF_SANE_NB_CHANNELS) {
1397 avctx->codec = codec;
1398 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
1399 avctx->codec_id == AV_CODEC_ID_NONE) {
1400 avctx->codec_type = codec->type;
1401 avctx->codec_id = codec->id;
1403 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
1404 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
1405 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
1409 avctx->frame_number = 0;
1410 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
1412 if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
1413 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
1416 av_log(avctx, AV_LOG_ERROR,
1422 av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
1428 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1429 (!avctx->time_base.num || !avctx->time_base.den)) {
1430 avctx->time_base.num = 1;
1431 avctx->time_base.den = avctx->sample_rate;
1435 av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
1439 ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
1440 ff_lock_avcodec(avctx);
1446 && !(avctx->internal->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
1447 ret = ff_thread_init(avctx);
1453 avctx->thread_count = 1;
1455 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1456 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
1457 avctx->codec->max_lowres);
1462 if (av_codec_is_encoder(avctx->codec)) {
1464 if (avctx->codec->sample_fmts) {
1465 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1466 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1468 if (avctx->channels == 1 &&
1469 av_get_planar_sample_fmt(avctx->sample_fmt) ==
1470 av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) {
1471 avctx->sample_fmt = avctx->codec->sample_fmts[i];
1475 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1477 snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
1478 av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
1479 (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
1484 if (avctx->codec->pix_fmts) {
1485 for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1486 if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1488 if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
1489 && !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
1490 && avctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL)) {
1492 snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
1493 av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
1494 (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
1499 if (avctx->codec->supported_samplerates) {
1500 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1501 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1503 if (avctx->codec->supported_samplerates[i] == 0) {
1504 av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
1505 avctx->sample_rate);
1510 if (avctx->codec->channel_layouts) {
1511 if (!avctx->channel_layout) {
1512 av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
1514 for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1515 if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1517 if (avctx->codec->channel_layouts[i] == 0) {
1519 av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1520 av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
1526 if (avctx->channel_layout && avctx->channels) {
1527 int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1528 if (channels != avctx->channels) {
1530 av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1531 av_log(avctx, AV_LOG_ERROR,
1533 buf, channels, avctx->channels);
1537 } else if (avctx->channel_layout) {
1538 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1540 if(avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
1541 avctx->codec_id != AV_CODEC_ID_PNG // For mplayer
1543 if (avctx->width <= 0 || avctx->height <= 0) {
1544 av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
1549 if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
1550 && avctx->bit_rate>0 && avctx->bit_rate<1000) {
1551 av_log(avctx, AV_LOG_WARNING, "Bitrate %d is extremely low, maybe you mean %dk\n", avctx->bit_rate, avctx->bit_rate);
1554 if (!avctx->rc_initial_buffer_occupancy)
1555 avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
1558 avctx->pts_correction_num_faulty_pts =
1559 avctx->pts_correction_num_faulty_dts = 0;
1560 avctx->pts_correction_last_pts =
1561 avctx->pts_correction_last_dts = INT64_MIN;
1563 if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
1564 || avctx->internal->frame_thread_encoder)) {
1565 ret = avctx->codec->init(avctx);
1573 if (av_codec_is_decoder(avctx->codec)) {
1574 if (!avctx->bit_rate)
1575 avctx->bit_rate = get_bit_rate(avctx);
1577 if (avctx->channel_layout) {
1578 int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1579 if (!avctx->channels)
1580 avctx->channels = channels;
1581 else if (channels != avctx->channels) {
1583 av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1584 av_log(avctx, AV_LOG_WARNING,
1587 buf, channels, avctx->channels);
1588 avctx->channel_layout = 0;
1591 if (avctx->channels && avctx->channels < 0 ||
1592 avctx->channels > FF_SANE_NB_CHANNELS) {
1596 if (avctx->sub_charenc) {
1597 if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1598 av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1602 } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1603 av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1605 avctx->codec_descriptor->name);
1606 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING;
1610 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC)
1611 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER;
1613 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) {
1615 iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1617 av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1618 "with input character encoding \"%s\"\n", avctx->sub_charenc);
1624 av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1644 av_freep(&avctx->priv_data);
1645 if (avctx->internal) {
1646 av_frame_free(&avctx->internal->to_free);
1647 av_freep(&avctx->internal->pool);
1649 av_freep(&avctx->internal);
1650 avctx->codec = NULL;
1654 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
1657 av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
1661 av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
1666 if (avctx) {
1667 av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
1669 av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);
1670 avpkt->data = avctx->internal->byte_buffer;
1671 avpkt->size = avctx->internal->byte_buffer_size;
1689 av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
1705 av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
1755 int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
1768 if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1776 if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1777 avctx->channels > AV_NUM_DATA_POINTERS) {
1778 av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1783 av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1796 if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
1797 if (frame->nb_samples > avctx->frame_size) {
1798 av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
1802 } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1803 if (frame->nb_samples < avctx->frame_size &&
1804 !avctx->internal->last_audio_frame) {
1805 ret = pad_last_frame(avctx, &padded_frame, frame);
1810 avctx->internal->last_audio_frame = 1;
1813 if (frame->nb_samples != avctx->frame_size) {
1814 av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
1821 ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1824 if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1828 avpkt->duration = ff_samples_to_time_base(avctx,
1836 if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
1842 av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
1867 avctx->frame_number++;
1889 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
1906 if (avctx->frame_size) {
1907 frame->nb_samples = avctx->frame_size;
1912 if (!av_get_bits_per_sample(avctx->codec_id)) {
1913 av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not "
1919 (av_get_bits_per_sample(avctx->codec_id) *
1920 avctx->channels);
1930 samples_size = av_samples_get_buffer_size(NULL, avctx->channels,
1932 avctx->sample_fmt, 1);
1933 if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
1934 avctx->sample_fmt,
1944 if (avctx->sample_rate && avctx->time_base.num)
1945 frame->pts = ff_samples_to_time_base(avctx,
1946 avctx->internal->sample_count);
1949 avctx->internal->sample_count += frame->nb_samples;
1955 ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
1956 if (!ret && got_packet && avctx->coded_frame) {
1957 avctx->coded_frame->pts = pkt.pts;
1958 avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1973 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1980 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
1988 ret = avcodec_encode_video2(avctx, &pkt, pict, &got_packet);
1989 if (!ret && got_packet && avctx->coded_frame) {
1990 avctx->coded_frame->pts = pkt.pts;
1991 avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
2008 int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
2020 avctx->internal->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))
2021 return ff_thread_video_encode_frame(avctx, avpkt, frame, got_packet_ptr);
2023 if ((avctx->flags&CODEC_FLAG_PASS1) && avctx->stats_out)
2024 avctx->stats_out[0] = '\0';
2026 if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
2033 if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
2036 av_assert0(avctx->codec->encode2);
2038 ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
2041 if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
2047 av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
2068 else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
2077 avctx->frame_number++;
2089 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
2094 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
2098 ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
2099 avctx->frame_number++;
2139 static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
2149 if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) {
2150 av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
2164 avctx->channels = bytestream_get_le32(&data);
2170 avctx->channel_layout = bytestream_get_le64(&data);
2176 avctx->sample_rate = bytestream_get_le32(&data);
2182 avctx->width = bytestream_get_le32(&data);
2183 avctx->height = bytestream_get_le32(&data);
2185 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
2192 av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
2196 static int add_metadata_from_side_data(AVCodecContext *avctx, AVFrame *frame)
2203 side_metadata = av_packet_get_side_data(avctx->internal->pkt,
2254 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
2258 AVCodecInternal *avci = avctx->internal;
2263 if (!avctx->codec)
2265 if (avctx->codec->type != AVMEDIA_TYPE_VIDEO) {
2266 av_log(avctx, AV_LOG_ERROR, "Invalid media type for video\n");
2271 if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
2276 if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
2278 ret = apply_param_change(avctx, &tmp);
2280 av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
2281 if (avctx->err_recognition & AV_EF_EXPLODE)
2285 avctx->internal->pkt = &tmp;
2286 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
2287 ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
2290 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
2294 if(!avctx->has_b_frames){
2297 //FIXME these should be under if(!avctx->has_b_frames)
2299 if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
2300 if (!picture->sample_aspect_ratio.num) picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
2301 if (!picture->width) picture->width = avctx->width;
2302 if (!picture->height) picture->height = avctx->height;
2303 if (picture->format == AV_PIX_FMT_NONE) picture->format = avctx->pix_fmt;
2306 add_metadata_from_side_data(avctx, picture);
2311 avctx->internal->pkt = NULL;
2319 if (!avctx->refcounted_frames) {
2325 avctx->frame_number++;
2327 guess_correct_pts(avctx,
2343 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
2352 if (avctx->get_buffer != avcodec_default_get_buffer) {
2353 av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
2355 av_log(avctx, AV_LOG_ERROR, "Please port your application to "
2357 avctx->get_buffer = avcodec_default_get_buffer;
2358 avctx->release_buffer = avcodec_default_release_buffer;
2361 ret = avcodec_decode_audio4(avctx, frame, &got_frame, avpkt);
2365 int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
2366 int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
2368 avctx->sample_fmt, 1);
2370 av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
2378 if (planar && avctx->channels > 1) {
2380 for (ch = 1; ch < avctx->channels; ch++) {
2395 int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
2400 AVCodecInternal *avci = avctx->internal;
2406 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2409 if (!avctx->codec)
2411 if (avctx->codec->type != AVMEDIA_TYPE_AUDIO) {
2412 av_log(avctx, AV_LOG_ERROR, "Invalid media type for audio\n");
2418 if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
2425 ret = apply_param_change(avctx, &tmp);
2427 av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
2428 if (avctx->err_recognition & AV_EF_EXPLODE)
2432 avctx->internal->pkt = &tmp;
2433 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
2434 ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp);
2436 ret = avctx->codec->decode(avctx, frame, got_frame_ptr, &tmp);
2440 add_metadata_from_side_data(avctx, frame);
2441 avctx->frame_number++;
2443 guess_correct_pts(avctx,
2447 frame->format = avctx->sample_fmt;
2449 frame->channel_layout = avctx->channel_layout;
2451 av_frame_set_channels(frame, avctx->channels);
2453 frame->sample_rate = avctx->sample_rate;
2456 side= av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
2458 avctx->internal->skip_samples = AV_RL32(side);
2459 av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n",
2460 avctx->internal->skip_samples);
2463 if (avctx->internal->skip_samples && *got_frame_ptr) {
2464 if(frame->nb_samples <= avctx->internal->skip_samples){
2466 avctx->internal->skip_samples -= frame->nb_samples;
2467 av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
2468 avctx->internal->skip_samples);
2470 av_samples_copy(frame->extended_data, frame->extended_data, 0, avctx->internal->skip_samples,
2471 frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
2472 if(avctx->pkt_timebase.num && avctx->sample_rate) {
2473 int64_t diff_ts = av_rescale_q(avctx->internal->skip_samples,
2474 (AVRational){1, avctx->sample_rate},
2475 avctx->pkt_timebase);
2483 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
2485 av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
2486 avctx->internal->skip_samples, frame->nb_samples);
2487 frame->nb_samples -= avctx->internal->skip_samples;
2488 avctx->internal->skip_samples = 0;
2496 if(avctx->pkt_timebase.num && avctx->sample_rate) {
2498 (AVRational){1, avctx->sample_rate},
2499 avctx->pkt_timebase);
2503 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
2505 av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
2511 avctx->internal->pkt = NULL;
2519 if (!avctx->refcounted_frames) {
2532 static int recode_subtitle(AVCodecContext *avctx,
2543 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0)
2547 cd = iconv_open("UTF-8", avctx->sub_charenc);
2554 av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
2571 av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
2572 "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
2585 av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
2609 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
2616 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2619 if (!avctx->codec)
2621 if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
2622 av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
2629 if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
2633 //apply_param_change(avctx, &tmp);
2646 ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
2650 avctx->internal->pkt = &pkt_recoded;
2652 if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
2654 avctx->pkt_timebase, AV_TIME_BASE_Q);
2655 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2660 avctx->pkt_timebase.num) {
2663 avctx->pkt_timebase, ms);
2668 av_log(avctx, AV_LOG_ERROR,
2683 if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
2685 else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
2687 avctx->internal->pkt = NULL;
2697 avctx->frame_number++;
2722 av_cold int avcodec_close(AVCodecContext *avctx)
2724 if (!avctx)
2727 if (avcodec_is_open(avctx)) {
2728 FramePool *pool = avctx->internal->pool;
2731 avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
2732 ff_frame_thread_encoder_free(avctx);
2734 if (HAVE_THREADS && avctx->internal->thread_ctx)
2735 ff_thread_free(avctx);
2736 if (avctx->codec && avctx->codec->close)
2737 avctx->codec->close(avctx);
2738 avctx->coded_frame = NULL;
2739 avctx->internal->byte_buffer_size = 0;
2740 av_freep(&avctx->internal->byte_buffer);
2741 av_frame_free(&avctx->internal->to_free);
2744 av_freep(&avctx->internal->pool);
2746 if (avctx->hwaccel && avctx->hwaccel->uninit)
2747 avctx->hwaccel->uninit(avctx);
2748 av_freep(&avctx->internal->hwaccel_priv_data);
2750 av_freep(&avctx->internal);
2753 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
2754 av_opt_free(avctx->priv_data);
2755 av_opt_free(avctx);
2756 av_freep(&avctx->priv_data);
2757 if (av_codec_is_encoder(avctx->codec))
2758 av_freep(&avctx->extradata);
2759 avctx->codec = NULL;
2760 avctx->active_thread_type = 0;
3066 void avcodec_flush_buffers(AVCodecContext *avctx)
3068 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
3069 ff_thread_flush(avctx);
3070 else if (avctx->codec->flush)
3071 avctx->codec->flush(avctx);
3073 avctx->pts_correction_last_pts =
3074 avctx->pts_correction_last_dts = INT64_MIN;
3076 if (!avctx->refcounted_frames)
3077 av_frame_unref(avctx->internal->to_free);
3173 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
3177 id = avctx->codec_id;
3178 sr = avctx->sample_rate;
3179 ch = avctx->channels;
3180 ba = avctx->block_align;
3181 tag = avctx->codec_tag;
3182 bps = av_get_exact_bits_per_sample(avctx->codec_id);
3187 bps = avctx->bits_per_coded_sample;
3301 switch (avctx->codec_id) {
3319 switch (avctx->codec_id) {
3512 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
3514 return ff_get_format(avctx, fmt);
3517 int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
3519 f->owner = avctx;
3520 return ff_get_buffer(avctx, f->f, flags);
3523 void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
3529 void ff_thread_finish_setup(AVCodecContext *avctx)
3541 int ff_thread_can_start_frame(AVCodecContext *avctx)
3546 int ff_alloc_entries(AVCodecContext *avctx, int count)
3551 void ff_reset_entries(AVCodecContext *avctx)
3555 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
3559 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
3590 int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
3598 avctx->extradata = str;
3604 avctx->extradata_size = buf->len;