70 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
84 static inline int ff_fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
89 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
140 static int initialized = 0;
142 if (initialized != 0)
157 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;
534 if (pic->
data[0] != NULL) {
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");
1392 avctx->
codec = NULL;
1398 if (avpkt->
size < 0) {
1403 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %d (max allowed is %d)\n",
1410 if (!avpkt->
data || avpkt->
size < size) {
1414 avpkt->destruct = NULL;
1420 #if FF_API_DESTRUCT_PACKET
1421 void *destruct = avpkt->destruct;
1424 if (avpkt->
size < size) {
1430 #if FF_API_DESTRUCT_PACKET
1431 avpkt->destruct = destruct;
1492 int *got_packet_ptr)
1498 int needs_realloc = !user_pkt.
data;
1500 *got_packet_ptr = 0;
1513 "with more than %d channels, but extended_data is not set.\n",
1528 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1538 frame = padded_frame;
1550 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1552 if (*got_packet_ptr) {
1567 if (user_pkt.
data) {
1568 if (user_pkt.
size >= avpkt->
size) {
1575 avpkt->
buf = user_pkt.
buf;
1577 avpkt->destruct = user_pkt.destruct;
1586 if (needs_realloc && avpkt->
data) {
1595 if (ret < 0 || !*got_packet_ptr) {
1612 #if FF_API_OLD_ENCODE_AUDIO
1615 const short *samples)
1620 int ret, samples_size, got_packet;
1624 pkt.
size = buf_size;
1638 "support this codec\n");
1641 nb_samples = (int64_t)buf_size * 8 /
1644 if (nb_samples >= INT_MAX)
1657 samples_size, 1)) < 0)
1685 return ret ? ret : pkt.
size;
1690 #if FF_API_OLD_ENCODE_VIDEO
1695 int ret, got_packet = 0;
1704 pkt.
size = buf_size;
1721 return ret ? ret : pkt.
size;
1729 int *got_packet_ptr)
1733 int needs_realloc = !user_pkt.
data;
1735 *got_packet_ptr = 0;
1737 if(CONFIG_FRAME_THREAD_ENCODER &&
1756 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1761 if (user_pkt.
data) {
1762 if (user_pkt.
size >= avpkt->
size) {
1769 avpkt->
buf = user_pkt.
buf;
1771 avpkt->destruct = user_pkt.destruct;
1780 if (!*got_packet_ptr)
1785 if (needs_realloc && avpkt->
data) {
1794 if (ret < 0 || !*got_packet_ptr)
1828 int64_t reordered_pts, int64_t dts)
1842 pts = reordered_pts;
1859 if (!data || size < 4)
1861 flags = bytestream_get_le32(&data);
1866 avctx->
channels = bytestream_get_le32(&data);
1884 avctx->
width = bytestream_get_le32(&data);
1885 avctx->
height = bytestream_get_le32(&data);
1901 end = side_metadata +
size;
1902 while (side_metadata < end) {
1903 const uint8_t *key = side_metadata;
1904 const uint8_t *
val = side_metadata + strlen(key) + 1;
1908 side_metadata = val + strlen(val) + 1;
1915 int *got_picture_ptr,
1930 *got_picture_ptr = 0;
1947 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
1974 if (ret < 0 && picture->data[0])
1977 if (*got_picture_ptr) {
1981 memset(picture->
buf, 0,
sizeof(picture->
buf));
2000 #if FF_API_OLD_DECODE_AUDIO
2002 int *frame_size_ptr,
2006 int ret, got_frame = 0;
2008 if (avctx->get_buffer != avcodec_default_get_buffer) {
2010 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2012 "avcodec_decode_audio4()\n");
2013 avctx->get_buffer = avcodec_default_get_buffer;
2014 avctx->release_buffer = avcodec_default_release_buffer;
2019 if (ret >= 0 && got_frame) {
2025 if (*frame_size_ptr < data_size) {
2027 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2033 if (planar && avctx->
channels > 1) {
2035 for (ch = 1; ch < avctx->
channels; ch++) {
2040 *frame_size_ptr = data_size;
2042 *frame_size_ptr = 0;
2055 int planar, channels;
2088 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2091 if (ret >= 0 && *got_frame_ptr) {
2109 if(side && side_size>=10) {
2150 if (ret >= 0 && *got_frame_ptr) {
2154 memset(frame->
buf, 0,
sizeof(frame->
buf));
2158 }
else if (frame->
data[0])
2165 if (*got_frame_ptr) {
2177 #define UTF8_MAX_BYTES 4
2182 iconv_t cd = (iconv_t)-1;
2211 outb = outpkt->
data;
2212 outl = outpkt->
size;
2214 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2215 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2216 outl >= outpkt->
size || inl != 0) {
2223 outpkt->
size -= outl;
2224 memset(outpkt->
data + outpkt->
size, 0, outl);
2227 if (cd != (iconv_t)-1)
2231 av_assert0(!
"requesting subtitles recoding without iconv");
2238 uint32_t codepoint,
min;
2242 GET_UTF8(codepoint, *(byte++),
return 0;);
2243 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2244 1 << (5 * (byte - str) - 4);
2245 if (codepoint < min || codepoint >= 0x110000 ||
2246 codepoint == 0xFFFE ||
2247 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2279 avctx->
pkt = &pkt_recoded;
2284 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2298 "Invalid UTF-8 in decoded subtitles text; "
2299 "maybe missing -sub_charenc option\n");
2305 if (tmp.
data != pkt_recoded.
data) {
2369 if (CONFIG_FRAME_THREAD_ENCODER &&
2396 avctx->
codec = NULL;
2413 default :
return id;
2419 AVCodec *p, *experimental = NULL;
2432 return experimental;
2490 return "unknown_codec";
2495 int i,
len, ret = 0;
2497 #define TAG_PRINT(x) \
2498 (((x) >= '0' && (x) <= '9') || \
2499 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2500 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2502 for (i = 0; i < 4; i++) {
2504 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2506 buf_size = buf_size > len ? buf_size - len : 0;
2516 const char *codec_name;
2517 const char *profile = NULL;
2522 if (!buf || buf_size <= 0)
2536 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2538 buf[0] ^=
'a' ^
'A';
2544 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2548 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2549 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2555 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2560 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2564 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2572 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2573 " [SAR %d:%d DAR %d:%d]",
2575 display_aspect_ratio.
num, display_aspect_ratio.
den);
2579 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2585 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2586 ", q=%d-%d", enc->
qmin, enc->
qmax);
2591 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2597 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2605 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2615 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2618 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2623 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2624 ", %d kb/s", bitrate / 1000);
2660 return FFMPEG_CONFIGURATION;
2665 #define LICENSE_PREFIX "libavcodec license: "
2749 if (be < 0 || be > 1)
2751 return map[
fmt][be];
2784 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2785 return (frame_bytes * 8LL) / (bps * ch);
2811 return 256 * sr / 245;
2816 return (480 << (sr / 22050)) / ch;
2824 case 20:
return 160;
2825 case 19:
return 144;
2826 case 29:
return 288;
2827 case 37:
return 480;
2831 case 38:
return 160;
2832 case 50:
return 240;
2837 if (frame_bytes > 0) {
2840 return 240 * (frame_bytes / 32);
2842 return 256 * (frame_bytes / 64);
2844 return 160 * (frame_bytes / 20);
2846 return 240 * (frame_bytes / 24);
2851 return frame_bytes * 8 /
bps;
2858 return frame_bytes / (9 * ch) * 16;
2860 return frame_bytes / (16 * ch) * 28;
2863 return (frame_bytes - 4 * ch) * 2 / ch;
2865 return (frame_bytes - 4) * 2 / ch;
2867 return (frame_bytes - 8) * 2 / ch;
2869 return (frame_bytes / 128) * 224 / ch;
2871 return (frame_bytes - 6 - ch) / ch;
2873 return (frame_bytes - 8) / ch;
2875 return (frame_bytes - 2 * ch) / ch;
2877 return 3 * frame_bytes / ch;
2879 return 6 * frame_bytes / ch;
2881 return 2 * (frame_bytes / (5 * ch));
2884 return 4 * frame_bytes / ch;
2891 return frame_bytes / ch;
2893 return frame_bytes * 2 / ch;
2899 int blocks = frame_bytes / ba;
2902 if (bps < 2 || bps > 5)
2904 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
2906 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2908 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2910 return blocks * ((ba - 4 * ch) * 2 / ch);
2912 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2922 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2926 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
2928 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2962 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
2966 #if FF_API_MISSING_SAMPLE
2967 void av_log_missing_feature(
void *avc,
const char *feature,
int want_sample)
2970 "version to the newest one from Git. If the problem still "
2971 "occurs, it means that your file has a feature which has not "
2972 "been implemented.\n", feature);
2974 av_log_ask_for_sample(avc, NULL);
2977 void av_log_ask_for_sample(
void *avc,
const char *msg, ...)
2979 va_list argument_list;
2981 va_start(argument_list, msg);
2986 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
2987 "and contact the ffmpeg-devel mailing list.\n");
2989 va_end(argument_list);
2998 hwaccel->
next = NULL;
3013 if (hwaccel->
id == codec_id
3014 && hwaccel->
pix_fmt == pix_fmt)
3047 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3204 for (i = 0; i < 3; i++) {
3205 uint32_t tmp = *state << 8;
3206 *state = tmp + *(p++);
3207 if (tmp == 0x100 || p == end)
3212 if (p[-1] > 1 ) p += 3;
3213 else if (p[-2] ) p += 2;
3214 else if (p[-3]|(p[-1]-1)) p++;
3221 p =
FFMIN(p, end) - 4;