69 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
83 static inline int ff_fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
88 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
139 static int initialized = 0;
141 if (initialized != 0)
156 return codec && codec->
decode;
186 #if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
187 # define STRIDE_ALIGN 16
189 # define STRIDE_ALIGN 8
312 w_align =
FFMAX(w_align, 8);
315 *width =
FFALIGN(*width, w_align);
316 *height =
FFALIGN(*height, h_align);
322 for (i = 0; i < 4; i++)
334 align =
FFMAX(linesize_align[0], linesize_align[3]);
335 linesize_align[1] <<= chroma_shift;
336 linesize_align[2] <<= chroma_shift;
337 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
338 *width =
FFALIGN(*width, align);
343 int buf_size,
int align)
345 int ch, planar, needed_size,
ret = 0;
350 if (buf_size < needed_size)
364 sample_fmt, align)) < 0) {
386 int w = frame->
width;
388 int tmpsize, unaligned;
409 for (i = 0; i < 4; i++)
418 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
419 size[i] = picture.
data[i + 1] - picture.
data[i];
420 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
422 for (i = 0; i < 4; i++) {
427 CONFIG_MEMORY_POISONING ?
430 if (!pool->
pools[i]) {
445 int planes = planar ? ch : 1;
458 if (!pool->
pools[0]) {
473 for (i = 0; i < 4; i++)
484 int planes = pool->
planes;
531 int h_chroma_shift, v_chroma_shift;
539 memset(pic->
data, 0,
sizeof(pic->
data));
544 for (i = 0; i < 4 && pool->
pools[i]; i++) {
545 const int h_shift = i == 0 ? 0 : h_chroma_shift;
546 const int v_shift = i == 0 ? 0 : v_chroma_shift;
588 int is_chroma = p == 1 || p == 2;
591 for (y = 0; y <
height; y++) {
593 for (x = 0; x<bytes; x++)
594 ((uint16_t*)dst)[x] = c[p];
596 memset(dst, c[p], bytes);
609 #if FF_API_GET_BUFFER
610 frame->
type = FF_BUFFER_TYPE_INTERNAL;
676 #if FF_API_GET_BUFFER
682 typedef struct CompatReleaseBufPriv {
685 } CompatReleaseBufPriv;
687 static void compat_free_buffer(
void *opaque,
uint8_t *
data)
689 CompatReleaseBufPriv *priv = opaque;
690 if (priv->avctx.release_buffer)
691 priv->avctx.release_buffer(&priv->avctx, &priv->frame);
695 static void compat_release_buffer(
void *opaque,
uint8_t *data)
715 #if FF_API_GET_BUFFER
723 if (avctx->get_buffer) {
724 CompatReleaseBufPriv *priv =
NULL;
731 ret = avctx->get_buffer(avctx, frame);
747 priv->avctx = *avctx;
748 priv->frame = *
frame;
756 #define WRAP_PLANE(ref_out, data, data_size) \
758 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
760 ret = AVERROR(ENOMEM); \
763 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
766 av_frame_unref(frame); \
767 ret = AVERROR(ENOMEM); \
780 if (!desc || planes <= 0) {
785 for (i = 0; i < planes; i++) {
789 WRAP_PLANE(frame->
buf[i], frame->
data[i], plane_size);
793 planes = planar ? avctx->
channels : 1;
823 avctx->release_buffer(avctx, frame);
856 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
893 #if FF_API_GET_BUFFER
912 for (i = 0; i <
count; i++) {
913 int r =
func(c, (
char *)arg + i * size);
924 for (i = 0; i <
count; i++) {
925 int r =
func(c, arg, i, 0);
947 #if LIBAVCODEC_VERSION_MAJOR >= 55
954 memset(frame, 0,
sizeof(
AVFrame));
986 if (!frame || !*frame)
997 #define MAKE_ACCESSORS(str, name, type, field) \
998 type av_##name##_get_##field(const str *s) { return s->field; } \
999 void av_##name##_set_##field(str *s, type v) { s->field = v; }
1007 memset(sub, 0,
sizeof(*sub));
1014 int bits_per_sample;
1034 #if FF_API_AVCODEC_OPEN
1061 if ((!codec && !avctx->
codec)) {
1065 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1067 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1071 codec = avctx->
codec;
1141 avctx->
codec = codec;
1161 "The %s '%s' is experimental but experimental codecs are not enabled, "
1162 "add '-strict %d' if you want to use it.\n",
1167 codec_string, codec2->
name);
1179 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1181 if (CONFIG_FRAME_THREAD_ENCODER) {
1200 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1222 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1237 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1264 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1276 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1325 else if (channels != avctx->
channels) {
1329 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1330 "ignoring specified channel layout\n",
1343 "supported with subtitles codecs\n");
1348 "subtitles character encoding will be ignored\n",
1359 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1360 if (cd == (iconv_t)-1) {
1362 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1369 "conversion needs a libavcodec built with iconv support "
1370 "for this codec\n");
1405 if (!avpkt->
data || avpkt->
size < size) {
1409 avpkt->destruct =
NULL;
1415 #if FF_API_DESTRUCT_PACKET
1416 void *destruct = avpkt->destruct;
1419 if (avpkt->
size < size) {
1425 #if FF_API_DESTRUCT_PACKET
1426 avpkt->destruct = destruct;
1493 int *got_packet_ptr)
1499 int needs_realloc = !user_pkt.
data;
1501 *got_packet_ptr = 0;
1514 "with more than %d channels, but extended_data is not set.\n",
1529 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1539 frame = padded_frame;
1551 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1553 if (*got_packet_ptr) {
1568 if (user_pkt.
data) {
1569 if (user_pkt.
size >= avpkt->
size) {
1576 avpkt->
buf = user_pkt.
buf;
1578 avpkt->destruct = user_pkt.destruct;
1587 if (needs_realloc && avpkt->
data) {
1596 if (ret < 0 || !*got_packet_ptr) {
1618 #if FF_API_OLD_ENCODE_AUDIO
1626 int ret, samples_size, got_packet;
1630 pkt.
size = buf_size;
1644 "support this codec\n");
1647 nb_samples = (int64_t)buf_size * 8 /
1650 if (nb_samples >= INT_MAX)
1663 samples_size, 1)) < 0)
1691 return ret ? ret : pkt.
size;
1696 #if FF_API_OLD_ENCODE_VIDEO
1701 int ret, got_packet = 0;
1710 pkt.
size = buf_size;
1727 return ret ? ret : pkt.
size;
1735 int *got_packet_ptr)
1739 int needs_realloc = !user_pkt.
data;
1741 *got_packet_ptr = 0;
1743 if(CONFIG_FRAME_THREAD_ENCODER &&
1762 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1767 if (user_pkt.
data) {
1768 if (user_pkt.
size >= avpkt->
size) {
1775 avpkt->
buf = user_pkt.
buf;
1777 avpkt->destruct = user_pkt.destruct;
1786 if (!*got_packet_ptr)
1791 if (needs_realloc && avpkt->
data) {
1800 if (ret < 0 || !*got_packet_ptr)
1834 int64_t reordered_pts, int64_t dts)
1848 pts = reordered_pts;
1865 if (!data || size < 4)
1867 flags = bytestream_get_le32(&data);
1872 avctx->
channels = bytestream_get_le32(&data);
1890 avctx->
width = bytestream_get_le32(&data);
1891 avctx->
height = bytestream_get_le32(&data);
1907 end = side_metadata +
size;
1908 while (side_metadata < end) {
1909 const uint8_t *key = side_metadata;
1910 const uint8_t *
val = side_metadata + strlen(key) + 1;
1914 side_metadata = val + strlen(val) + 1;
1921 int *got_picture_ptr,
1934 *got_picture_ptr = 0;
1951 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
1978 if (ret < 0 && picture->data[0])
1981 if (*got_picture_ptr) {
1985 memset(picture->
buf, 0,
sizeof(picture->
buf));
2004 #if FF_API_OLD_DECODE_AUDIO
2006 int *frame_size_ptr,
2010 int ret, got_frame = 0;
2012 if (avctx->get_buffer != avcodec_default_get_buffer) {
2014 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2016 "avcodec_decode_audio4()\n");
2017 avctx->get_buffer = avcodec_default_get_buffer;
2018 avctx->release_buffer = avcodec_default_release_buffer;
2023 if (ret >= 0 && got_frame) {
2029 if (*frame_size_ptr < data_size) {
2031 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2037 if (planar && avctx->
channels > 1) {
2039 for (ch = 1; ch < avctx->
channels; ch++) {
2044 *frame_size_ptr = data_size;
2046 *frame_size_ptr = 0;
2059 int planar, channels;
2087 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2088 if (ret >= 0 && *got_frame_ptr) {
2107 if(side && side_size>=10) {
2148 if (ret >= 0 && *got_frame_ptr) {
2152 memset(frame->
buf, 0,
sizeof(frame->
buf));
2156 }
else if (frame->
data[0])
2163 if (*got_frame_ptr) {
2175 #define UTF8_MAX_BYTES 4
2180 iconv_t cd = (iconv_t)-1;
2209 outb = outpkt->
data;
2210 outl = outpkt->
size;
2212 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2213 iconv(cd,
NULL,
NULL, &outb, &outl) == (
size_t)-1 ||
2214 outl >= outpkt->
size || inl != 0) {
2221 outpkt->
size -= outl;
2222 memset(outpkt->
data + outpkt->
size, 0, outl);
2225 if (cd != (iconv_t)-1)
2229 av_assert0(!
"requesting subtitles recoding without iconv");
2236 uint32_t codepoint,
min;
2240 GET_UTF8(codepoint, *(byte++),
return 0;);
2241 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2242 1 << (5 * (byte - str) - 4);
2243 if (codepoint < min || codepoint >= 0x110000 ||
2244 codepoint == 0xFFFE ||
2245 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2277 avctx->
pkt = &pkt_recoded;
2282 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2296 "Invalid UTF-8 in decoded subtitles text; "
2297 "maybe missing -sub_charenc option\n");
2303 if (tmp.
data != pkt_recoded.
data) {
2367 if (CONFIG_FRAME_THREAD_ENCODER &&
2410 default :
return id;
2429 return experimental;
2487 return "unknown_codec";
2492 int i,
len, ret = 0;
2494 #define TAG_PRINT(x) \
2495 (((x) >= '0' && (x) <= '9') || \
2496 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2497 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2499 for (i = 0; i < 4; i++) {
2501 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2503 buf_size = buf_size > len ? buf_size - len : 0;
2513 const char *codec_name;
2514 const char *profile =
NULL;
2519 if (!buf || buf_size <= 0)
2533 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2535 buf[0] ^=
'a' ^
'A';
2541 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2545 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2546 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2552 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2557 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2561 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2569 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2570 " [SAR %d:%d DAR %d:%d]",
2572 display_aspect_ratio.
num, display_aspect_ratio.
den);
2576 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2582 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2583 ", q=%d-%d", enc->
qmin, enc->
qmax);
2588 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2594 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2602 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2612 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2615 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2620 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2621 ", %d kb/s", bitrate / 1000);
2657 return FFMPEG_CONFIGURATION;
2662 #define LICENSE_PREFIX "libavcodec license: "
2743 if (be < 0 || be > 1)
2745 return map[
fmt][be];
2778 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2779 return (frame_bytes * 8LL) / (bps * ch);
2805 return 256 * sr / 245;
2810 return (480 << (sr / 22050)) / ch;
2818 case 20:
return 160;
2819 case 19:
return 144;
2820 case 29:
return 288;
2821 case 37:
return 480;
2825 case 38:
return 160;
2826 case 50:
return 240;
2831 if (frame_bytes > 0) {
2834 return 240 * (frame_bytes / 32);
2836 return 256 * (frame_bytes / 64);
2838 return 160 * (frame_bytes / 20);
2840 return 240 * (frame_bytes / 24);
2845 return frame_bytes * 8 /
bps;
2852 return frame_bytes / (9 * ch) * 16;
2854 return frame_bytes / (16 * ch) * 28;
2857 return (frame_bytes - 4 * ch) * 2 / ch;
2859 return (frame_bytes - 4) * 2 / ch;
2861 return (frame_bytes - 8) * 2 / ch;
2863 return (frame_bytes / 128) * 224 / ch;
2865 return (frame_bytes - 6 - ch) / ch;
2867 return (frame_bytes - 8) / ch;
2869 return (frame_bytes - 2 * ch) / ch;
2871 return 3 * frame_bytes / ch;
2873 return 6 * frame_bytes / ch;
2875 return 2 * (frame_bytes / (5 * ch));
2878 return 4 * frame_bytes / ch;
2885 return frame_bytes / ch;
2887 return frame_bytes * 2 / ch;
2893 int blocks = frame_bytes / ba;
2896 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2898 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2900 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2902 return blocks * ((ba - 4 * ch) * 2 / ch);
2904 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2914 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2918 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
2920 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2954 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
2958 #if FF_API_MISSING_SAMPLE
2959 void av_log_missing_feature(
void *avc,
const char *feature,
int want_sample)
2962 "version to the newest one from Git. If the problem still "
2963 "occurs, it means that your file has a feature which has not "
2964 "been implemented.\n", feature);
2966 av_log_ask_for_sample(avc,
NULL);
2969 void av_log_ask_for_sample(
void *avc,
const char *msg, ...)
2971 va_list argument_list;
2973 va_start(argument_list, msg);
2978 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
2979 "and contact the ffmpeg-devel mailing list.\n");
2981 va_end(argument_list);
3006 if (hwaccel->
id == codec_id
3007 && hwaccel->
pix_fmt == pix_fmt)
3040 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3197 for (i = 0; i < 3; i++) {
3198 uint32_t tmp = *state << 8;
3199 *state = tmp + *(p++);
3200 if (tmp == 0x100 || p == end)
3205 if (p[-1] > 1 ) p += 3;
3206 else if (p[-2] ) p += 2;
3207 else if (p[-3]|(p[-1]-1)) p++;
3214 p =
FFMIN(p, end) - 4;