72 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
128 if (min_size <= *size && *p)
130 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
177 static int initialized = 0;
179 if (initialized != 0)
194 return codec && codec->
decode;
206 last_avcodec = &codec->
next;
219 #if FF_API_SET_DIMENSIONS
274 *data = matrix_encoding;
422 w_align =
FFMAX(w_align, 8);
425 *width =
FFALIGN(*width, w_align);
426 *height =
FFALIGN(*height, h_align);
431 *width =
FFMAX(*width, 32);
434 for (i = 0; i < 4; i++)
446 align =
FFMAX(linesize_align[0], linesize_align[3]);
447 linesize_align[1] <<= chroma_shift;
448 linesize_align[2] <<= chroma_shift;
449 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
450 *width =
FFALIGN(*width, align);
459 *xpos = (pos&1) * 128;
460 *ypos = ((pos>>1)^(pos<4)) * 128;
478 int buf_size,
int align)
480 int ch, planar, needed_size,
ret = 0;
485 if (buf_size < needed_size)
499 sample_fmt, align)) < 0) {
521 int w = frame->
width;
523 int tmpsize, unaligned;
539 for (i = 0; i < 4; i++)
548 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
549 size[i] = picture.
data[i + 1] - picture.
data[i];
550 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
552 for (i = 0; i < 4; i++) {
560 if (!pool->
pools[i]) {
575 int planes = planar ? ch : 1;
588 if (!pool->
pools[0]) {
603 for (i = 0; i < 4; i++)
614 int planes = pool->
planes;
666 memset(pic->
data, 0,
sizeof(pic->
data));
669 for (i = 0; i < 4 && pool->
pools[i]; i++) {
703 int is_chroma = p == 1 || p == 2;
706 for (y = 0; y <
height; y++) {
708 for (x = 0; x<bytes; x++)
709 ((uint16_t*)dst)[x] = c[p];
711 memset(dst, c[p], bytes);
724 #if FF_API_GET_BUFFER
744 static const struct {
770 memcpy(frame_sd->
data, packet_sd, size);
837 #if FF_API_GET_BUFFER
874 int override_dimensions = 1;
887 override_dimensions = 0;
904 #if FF_API_GET_BUFFER
937 priv->
avctx = *avctx;
946 #define WRAP_PLANE(ref_out, data, data_size) \
948 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
950 ret = AVERROR(ENOMEM); \
953 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
956 av_frame_unref(frame); \
957 ret = AVERROR(ENOMEM); \
970 if (!desc || planes <= 0) {
975 for (i = 0; i < planes; i++) {
983 planes = planar ? avctx->
channels : 1;
1050 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1057 if (!frame->
data[0])
1089 #if FF_API_GET_BUFFER
1108 for (i = 0; i <
count; i++) {
1109 int r =
func(c, (
char *)arg + i * size);
1120 for (i = 0; i <
count; i++) {
1121 int r =
func(c, arg, i, 0);
1129 unsigned int fourcc)
1132 if (tags->
fourcc == fourcc)
1158 if (hwaccel->
id == codec_id
1159 && hwaccel->
pix_fmt == pix_fmt)
1173 "Could not find an AVHWAccel for the pixel format: %s",
1185 ret = hwa->
init(avctx);
1215 memcpy(choices, fmt, (n + 1) *
sizeof(*choices));
1240 for (n = 0; choices[
n] !=
ret; n++)
1244 choices[
n] = choices[n + 1];
1252 #if FF_API_AVFRAME_LAVC
1255 #if LIBAVCODEC_VERSION_MAJOR >= 55
1262 memset(frame, 0,
sizeof(
AVFrame));
1266 AVFrame *avcodec_alloc_frame(
void)
1271 void avcodec_free_frame(
AVFrame **frame)
1281 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1285 return codec->max_lowres;
1290 memset(sub, 0,
sizeof(*sub));
1297 int bits_per_sample;
1337 if ((!codec && !avctx->
codec)) {
1341 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1343 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1347 codec = avctx->
codec;
1441 avctx->
codec = codec;
1461 "The %s '%s' is experimental but experimental codecs are not enabled, "
1462 "add '-strict %d' if you want to use it.\n",
1467 codec_string, codec2->
name);
1479 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1500 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1509 "see the codecview filter instead.\n");
1528 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1543 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1576 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1588 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1627 #if FF_API_AUDIOENC_DELAY
1640 else if (channels != avctx->
channels) {
1644 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1645 "ignoring specified channel layout\n",
1658 "supported with subtitles codecs\n");
1663 "subtitles character encoding will be ignored\n",
1674 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1675 if (cd == (iconv_t)-1) {
1678 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1684 "conversion needs a libavcodec built with iconv support "
1685 "for this codec\n");
1693 #if FF_API_AVCTX_TIMEBASE
1698 if (codec->priv_data_size > 0 && avctx->priv_data && codec->priv_class) {
1712 if (codec->priv_class && codec->priv_data_size)
1715 if (avctx->internal) {
1720 avctx->codec =
NULL;
1726 if (avpkt->
size < 0) {
1731 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1738 if (!avpkt->
data || avpkt->
size < size) {
1742 #if FF_API_DESTRUCT_PACKET
1752 #if FF_API_DESTRUCT_PACKET
1758 if (avpkt->
size < size) {
1764 #if FF_API_DESTRUCT_PACKET
1828 int *got_packet_ptr)
1834 int needs_realloc = !user_pkt.
data;
1836 *got_packet_ptr = 0;
1849 "with more than %d channels, but extended_data is not set.\n",
1856 if (!extended_frame)
1859 memcpy(extended_frame, frame,
sizeof(
AVFrame));
1861 frame = extended_frame;
1875 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1886 frame = padded_frame;
1898 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1900 if (*got_packet_ptr) {
1915 if (user_pkt.
data) {
1916 if (user_pkt.
size >= avpkt->
size) {
1923 avpkt->
buf = user_pkt.
buf;
1925 #if FF_API_DESTRUCT_PACKET
1938 if (needs_realloc && avpkt->
data) {
1947 if (ret < 0 || !*got_packet_ptr) {
1962 #if FF_API_AUDIOENC_DELAY
1969 #if FF_API_OLD_ENCODE_AUDIO
1972 const short *samples)
1976 int ret, samples_size, got_packet;
1980 pkt.
size = buf_size;
1995 "support this codec\n");
1999 nb_samples = (int64_t)buf_size * 8 /
2002 if (nb_samples >= INT_MAX) {
2017 samples_size, 1)) < 0) {
2048 return ret ? ret : pkt.
size;
2053 #if FF_API_OLD_ENCODE_VIDEO
2058 int ret, got_packet = 0;
2067 pkt.
size = buf_size;
2084 return ret ? ret : pkt.
size;
2092 int *got_packet_ptr)
2096 int needs_realloc = !user_pkt.
data;
2098 *got_packet_ptr = 0;
2119 if (frame && (frame->
width == 0 || frame->
height == 0))
2124 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
2129 if (user_pkt.
data) {
2130 if (user_pkt.
size >= avpkt->
size) {
2137 avpkt->
buf = user_pkt.
buf;
2139 #if FF_API_DESTRUCT_PACKET
2152 if (!*got_packet_ptr)
2157 if (needs_realloc && avpkt->
data) {
2166 if (ret < 0 || !*got_packet_ptr)
2200 int64_t reordered_pts, int64_t dts)
2218 pts = reordered_pts;
2237 "changes, but PARAM_CHANGE side data was sent to it.\n");
2244 flags = bytestream_get_le32(&data);
2250 avctx->
channels = bytestream_get_le32(&data);
2268 avctx->
width = bytestream_get_le32(&data);
2269 avctx->
height = bytestream_get_le32(&data);
2341 int *got_picture_ptr,
2356 *got_picture_ptr = 0;
2376 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2404 if (*got_picture_ptr) {
2425 #if FF_API_AVCTX_TIMEBASE
2433 #if FF_API_OLD_DECODE_AUDIO
2435 int *frame_size_ptr,
2439 int ret, got_frame = 0;
2445 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2447 "avcodec_decode_audio4()\n");
2454 if (ret >= 0 && got_frame) {
2460 if (*frame_size_ptr < data_size) {
2462 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2469 if (planar && avctx->
channels > 1) {
2471 for (ch = 1; ch < avctx->
channels; ch++) {
2476 *frame_size_ptr = data_size;
2478 *frame_size_ptr = 0;
2512 uint32_t discard_padding = 0;
2529 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2532 if (ret >= 0 && *got_frame_ptr) {
2550 if(side && side_size>=10) {
2554 discard_padding =
AV_RL32(side + 4);
2555 skip_reason =
AV_RL8(side + 8);
2556 discard_reason =
AV_RL8(side + 9);
2588 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr &&
2611 AV_WL32(fside->
data, avctx->internal->skip_samples);
2615 avctx->internal->skip_samples = 0;
2619 avctx->internal->pkt =
NULL;
2626 if (
ret >= 0 && *got_frame_ptr) {
2627 if (!avctx->refcounted_frames) {
2639 #define UTF8_MAX_BYTES 4
2644 iconv_t cd = (iconv_t)-1;
2673 outb = outpkt->
data;
2674 outl = outpkt->
size;
2676 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2677 iconv(cd,
NULL,
NULL, &outb, &outl) == (
size_t)-1 ||
2678 outl >= outpkt->
size || inl != 0) {
2685 outpkt->
size -= outl;
2686 memset(outpkt->
data + outpkt->
size, 0, outl);
2689 if (cd != (iconv_t)-1)
2701 uint32_t codepoint,
min;
2705 GET_UTF8(codepoint, *(byte++),
return 0;);
2706 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2707 1 << (5 * (byte - str) - 4);
2708 if (codepoint < min || codepoint >= 0x110000 ||
2709 codepoint == 0xFFFE ||
2710 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2763 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2777 "Invalid UTF-8 in decoded subtitles text; "
2778 "maybe missing -sub_charenc option\n");
2784 if (tmp.
data != pkt_recoded.
data) {
2897 default :
return id;
2916 return experimental;
2974 return "unknown_codec";
2981 #define TAG_PRINT(x) \
2982 (((x) >= '0' && (x) <= '9') || \
2983 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2984 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2986 for (i = 0; i < 4; i++) {
2988 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2990 buf_size = buf_size > len ? buf_size - len : 0;
3000 const char *codec_name;
3008 if (!buf || buf_size <= 0)
3022 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
3024 buf[0] ^=
'a' ^
'A';
3030 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
3035 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3036 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
3042 char detail[256] =
"(";
3046 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3076 if (strlen(detail) > 1) {
3077 detail[strlen(detail) - 2] = 0;
3083 av_strlcat(buf, new_line ? separator :
", ", buf_size);
3085 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3092 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3100 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3101 " [SAR %d:%d DAR %d:%d]",
3103 display_aspect_ratio.
num, display_aspect_ratio.
den);
3107 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3113 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3114 ", q=%d-%d", enc->
qmin, enc->
qmax);
3121 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3126 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3131 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3138 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3145 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3153 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3156 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3161 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3162 ", %d kb/s", bitrate / 1000);
3164 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3206 #define LICENSE_PREFIX "libavcodec license: "
3294 if (be < 0 || be > 1)
3296 return map[
fmt][be];
3329 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
3330 return (frame_bytes * 8LL) / (bps * ch);
3357 return 256 * sr / 245;
3362 return (480 << (sr / 22050)) / ch;
3370 case 20:
return 160;
3371 case 19:
return 144;
3372 case 29:
return 288;
3373 case 37:
return 480;
3377 case 38:
return 160;
3378 case 50:
return 240;
3383 if (frame_bytes > 0) {
3386 return 240 * (frame_bytes / 32);
3388 return 256 * (frame_bytes / 64);
3390 return 160 * (frame_bytes / 20);
3392 return 240 * (frame_bytes / 24);
3397 return frame_bytes * 8 /
bps;
3400 if (ch > 0 && ch < INT_MAX/16) {
3404 return frame_bytes / (9 * ch) * 16;
3406 return frame_bytes / (16 * ch) * 28;
3409 return (frame_bytes - 4 * ch) * 2 / ch;
3411 return (frame_bytes - 4) * 2 / ch;
3413 return (frame_bytes - 8) * 2 / ch;
3415 return (frame_bytes / 128) * 224 / ch;
3417 return (frame_bytes - 6 - ch) / ch;
3419 return (frame_bytes - 8) / ch;
3421 return (frame_bytes - 2 * ch) / ch;
3423 return 3 * frame_bytes / ch;
3425 return 6 * frame_bytes / ch;
3427 return 2 * (frame_bytes / (5 * ch));
3430 return 4 * frame_bytes / ch;
3437 return frame_bytes / ch;
3439 return frame_bytes * 2 / ch;
3445 int blocks = frame_bytes / ba;
3448 if (bps < 2 || bps > 5)
3450 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3452 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3454 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3456 return blocks * ((ba - 4 * ch) * 2 / ch);
3458 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3468 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3472 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
3474 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3519 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3523 #if FF_API_MISSING_SAMPLE
3528 "version to the newest one from Git. If the problem still "
3529 "occurs, it means that your file has a feature which has not "
3530 "been implemented.\n", feature);
3537 va_list argument_list;
3539 va_start(argument_list, msg);
3544 "of this file to ftp://upload.ffmpeg.org/incoming/ "
3545 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
3547 va_end(argument_list);
3561 last_hwaccel = &hwaccel->
next;
3582 void *new_codec_mutex =
NULL;
3583 void *new_avformat_mutex =
NULL;
3609 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3611 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3657 ((
unsigned)
av_toupper((x >> 24) & 0xFF) << 24);
3794 for (i = 0; i < 3; i++) {
3795 uint32_t tmp = *state << 8;
3796 *state = tmp + *(p++);
3797 if (tmp == 0x100 || p == end)
3802 if (p[-1] > 1 ) p += 3;
3803 else if (p[-2] ) p += 2;
3804 else if (p[-3]|(p[-1]-1)) p++;
3811 p =
FFMIN(p, end) - 4;