67 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
122 if (min_size < *size)
125 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
142 if (min_size < *size)
144 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
195 static int initialized = 0;
197 if (initialized != 0)
212 return codec && codec->
decode;
242 #if HAVE_NEON || ARCH_PPC || HAVE_MMX
243 # define STRIDE_ALIGN 16
245 # define STRIDE_ALIGN 8
380 w_align =
FFMAX(w_align, 8);
383 *width =
FFALIGN(*width, w_align);
384 *height =
FFALIGN(*height, h_align);
390 for (i = 0; i < 4; i++)
402 align =
FFMAX(linesize_align[0], linesize_align[3]);
403 linesize_align[1] <<= chroma_shift;
404 linesize_align[2] <<= chroma_shift;
405 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
406 *width =
FFALIGN(*width, align);
415 *xpos = (pos&1) * 128;
416 *ypos = ((pos>>1)^(pos<4)) * 128;
434 int buf_size,
int align)
436 int ch, planar, needed_size,
ret = 0;
441 if (buf_size < needed_size)
455 sample_fmt, align)) < 0) {
477 int w = frame->
width;
479 int tmpsize, unaligned;
500 for (i = 0; i < 4; i++)
509 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
510 size[i] = picture.
data[i + 1] - picture.
data[i];
511 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
513 for (i = 0; i < 4; i++) {
518 CONFIG_MEMORY_POISONING ?
521 if (!pool->
pools[i]) {
536 int planes = planar ? ch : 1;
549 if (!pool->
pools[0]) {
564 for (i = 0; i < 4; i++)
575 int planes = pool->
planes;
622 int h_chroma_shift, v_chroma_shift;
625 if (pic->
data[0] != NULL) {
630 memset(pic->
data, 0,
sizeof(pic->
data));
635 for (i = 0; i < 4 && pool->
pools[i]; i++) {
636 const int h_shift = i == 0 ? 0 : h_chroma_shift;
637 const int v_shift = i == 0 ? 0 : v_chroma_shift;
680 int is_chroma = p == 1 || p == 2;
683 for (y = 0; y <
height; y++) {
685 for (x = 0; x<bytes; x++)
686 ((uint16_t*)dst)[x] = c[p];
688 memset(dst, c[p], bytes);
701 #if FF_API_GET_BUFFER
703 frame->
type = FF_BUFFER_TYPE_INTERNAL;
774 #if FF_API_GET_BUFFER
781 typedef struct CompatReleaseBufPriv {
784 } CompatReleaseBufPriv;
786 static void compat_free_buffer(
void *opaque,
uint8_t *
data)
788 CompatReleaseBufPriv *priv = opaque;
789 if (priv->avctx.release_buffer)
790 priv->avctx.release_buffer(&priv->avctx, &priv->frame);
794 static void compat_release_buffer(
void *opaque,
uint8_t *data)
815 #if FF_API_GET_BUFFER
824 if (avctx->get_buffer) {
825 CompatReleaseBufPriv *priv = NULL;
832 ret = avctx->get_buffer(avctx, frame);
848 priv->avctx = *avctx;
849 priv->frame = *
frame;
857 #define WRAP_PLANE(ref_out, data, data_size) \
859 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
861 ret = AVERROR(ENOMEM); \
864 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
867 av_frame_unref(frame); \
868 ret = AVERROR(ENOMEM); \
881 if (!desc || planes <= 0) {
886 for (i = 0; i < planes; i++) {
890 WRAP_PLANE(frame->
buf[i], frame->
data[i], plane_size);
894 planes = planar ? avctx->
channels : 1;
924 avctx->release_buffer(avctx, frame);
958 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
995 #if FF_API_GET_BUFFER
1014 for (i = 0; i <
count; i++) {
1015 int r =
func(c, (
char *)arg + i * size);
1026 for (i = 0; i <
count; i++) {
1027 int r =
func(c, arg, i, 0);
1049 #if LIBAVCODEC_VERSION_MAJOR >= 55
1056 memset(frame, 0,
sizeof(
AVFrame));
1081 if (!frame || !*frame)
1099 return codec->max_lowres;
1104 memset(sub, 0,
sizeof(*sub));
1111 int bits_per_sample;
1131 #if FF_API_AVCODEC_OPEN
1158 if ((!codec && !avctx->
codec)) {
1162 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1164 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1168 codec = avctx->
codec;
1238 avctx->
codec = codec;
1258 "The %s '%s' is experimental but experimental codecs are not enabled, "
1259 "add '-strict %d' if you want to use it.\n",
1264 codec_string, codec2->
name);
1276 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1278 if (CONFIG_FRAME_THREAD_ENCODER) {
1297 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1298 avctx->
codec->max_lowres);
1319 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1334 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1361 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1373 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1422 else if (channels != avctx->
channels) {
1426 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1427 "ignoring specified channel layout\n",
1440 "supported with subtitles codecs\n");
1445 "subtitles character encoding will be ignored\n",
1456 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1457 if (cd == (iconv_t)-1) {
1459 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1466 "conversion needs a libavcodec built with iconv support "
1467 "for this codec\n");
1489 avctx->
codec = NULL;
1495 if (avpkt->
size < 0) {
1500 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1507 if (!avpkt->
data || avpkt->
size < size) {
1511 avpkt->destruct = NULL;
1517 #if FF_API_DESTRUCT_PACKET
1519 void *destruct = avpkt->destruct;
1523 if (avpkt->
size < size) {
1529 #if FF_API_DESTRUCT_PACKET
1531 avpkt->destruct = destruct;
1593 int *got_packet_ptr)
1599 int needs_realloc = !user_pkt.
data;
1601 *got_packet_ptr = 0;
1614 "with more than %d channels, but extended_data is not set.\n",
1629 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1639 frame = padded_frame;
1651 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1653 if (*got_packet_ptr) {
1668 if (user_pkt.
data) {
1669 if (user_pkt.
size >= avpkt->
size) {
1676 avpkt->
buf = user_pkt.
buf;
1678 avpkt->destruct = user_pkt.destruct;
1687 if (needs_realloc && avpkt->
data) {
1696 if (ret < 0 || !*got_packet_ptr) {
1713 #if FF_API_OLD_ENCODE_AUDIO
1716 const short *samples)
1720 int ret, samples_size, got_packet;
1724 pkt.
size = buf_size;
1739 "support this codec\n");
1743 nb_samples = (int64_t)buf_size * 8 /
1746 if (nb_samples >= INT_MAX) {
1761 samples_size, 1)) < 0) {
1792 return ret ? ret : pkt.
size;
1797 #if FF_API_OLD_ENCODE_VIDEO
1802 int ret, got_packet = 0;
1811 pkt.
size = buf_size;
1828 return ret ? ret : pkt.
size;
1836 int *got_packet_ptr)
1840 int needs_realloc = !user_pkt.
data;
1842 *got_packet_ptr = 0;
1844 if(CONFIG_FRAME_THREAD_ENCODER &&
1863 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1868 if (user_pkt.
data) {
1869 if (user_pkt.
size >= avpkt->
size) {
1876 avpkt->
buf = user_pkt.
buf;
1878 avpkt->destruct = user_pkt.destruct;
1887 if (!*got_packet_ptr)
1892 if (needs_realloc && avpkt->
data) {
1901 if (ret < 0 || !*got_packet_ptr)
1935 int64_t reordered_pts, int64_t dts)
1949 pts = reordered_pts;
1966 if (!data || size < 4)
1968 flags = bytestream_get_le32(&data);
1973 avctx->
channels = bytestream_get_le32(&data);
1991 avctx->
width = bytestream_get_le32(&data);
1992 avctx->
height = bytestream_get_le32(&data);
2008 end = side_metadata +
size;
2009 if (size && end[-1])
2011 while (side_metadata < end) {
2012 const uint8_t *key = side_metadata;
2013 const uint8_t *
val = side_metadata + strlen(key) + 1;
2022 side_metadata = val + strlen(val) + 1;
2029 int *got_picture_ptr,
2044 *got_picture_ptr = 0;
2061 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2088 if (ret < 0 && picture->data[0])
2091 if (*got_picture_ptr) {
2095 memset(picture->
buf, 0,
sizeof(picture->
buf));
2114 #if FF_API_OLD_DECODE_AUDIO
2116 int *frame_size_ptr,
2120 int ret, got_frame = 0;
2124 if (avctx->get_buffer != avcodec_default_get_buffer) {
2126 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2128 "avcodec_decode_audio4()\n");
2129 avctx->get_buffer = avcodec_default_get_buffer;
2130 avctx->release_buffer = avcodec_default_release_buffer;
2135 if (ret >= 0 && got_frame) {
2141 if (*frame_size_ptr < data_size) {
2143 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2150 if (planar && avctx->
channels > 1) {
2152 for (ch = 1; ch < avctx->
channels; ch++) {
2157 *frame_size_ptr = data_size;
2159 *frame_size_ptr = 0;
2173 int planar, channels;
2197 uint32_t discard_padding = 0;
2207 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2210 if (ret >= 0 && *got_frame_ptr) {
2228 if(side && side_size>=10) {
2232 discard_padding =
AV_RL32(side + 4);
2263 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) {
2289 if (ret >= 0 && *got_frame_ptr) {
2291 avci->to_free = *
frame;
2293 memset(frame->
buf, 0,
sizeof(frame->
buf));
2297 }
else if (frame->
data[0])
2304 if (*got_frame_ptr) {
2316 #define UTF8_MAX_BYTES 4
2321 iconv_t cd = (iconv_t)-1;
2350 outb = outpkt->
data;
2351 outl = outpkt->
size;
2353 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2354 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2355 outl >= outpkt->
size || inl != 0) {
2362 outpkt->
size -= outl;
2363 memset(outpkt->
data + outpkt->
size, 0, outl);
2366 if (cd != (iconv_t)-1)
2370 av_assert0(!
"requesting subtitles recoding without iconv");
2377 uint32_t codepoint,
min;
2381 GET_UTF8(codepoint, *(byte++),
return 0;);
2382 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2383 1 << (5 * (byte - str) - 4);
2384 if (codepoint < min || codepoint >= 0x110000 ||
2385 codepoint == 0xFFFE ||
2386 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2434 avctx->
pkt = &pkt_recoded;
2439 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2453 "Invalid UTF-8 in decoded subtitles text; "
2454 "maybe missing -sub_charenc option\n");
2460 if (tmp.
data != pkt_recoded.
data) {
2532 if (CONFIG_FRAME_THREAD_ENCODER &&
2559 avctx->
codec = NULL;
2579 default :
return id;
2585 AVCodec *p, *experimental = NULL;
2598 return experimental;
2656 return "unknown_codec";
2661 int i,
len, ret = 0;
2663 #define TAG_PRINT(x) \
2664 (((x) >= '0' && (x) <= '9') || \
2665 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2666 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2668 for (i = 0; i < 4; i++) {
2670 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2672 buf_size = buf_size > len ? buf_size - len : 0;
2682 const char *codec_name;
2683 const char *profile = NULL;
2688 if (!buf || buf_size <= 0)
2702 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2704 buf[0] ^=
'a' ^
'A';
2710 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2714 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2715 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2721 char detail[256] =
"(";
2722 const char *colorspace_name;
2723 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2734 if (colorspace_name)
2735 av_strlcatf(detail,
sizeof(detail),
"%s, ", colorspace_name);
2737 if (strlen(detail) > 1) {
2738 detail[strlen(detail) - 2] = 0;
2743 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2751 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2752 " [SAR %d:%d DAR %d:%d]",
2754 display_aspect_ratio.
num, display_aspect_ratio.
den);
2758 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2764 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2765 ", q=%d-%d", enc->
qmin, enc->
qmax);
2770 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2776 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2784 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2791 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2799 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2802 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2807 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2808 ", %d kb/s", bitrate / 1000);
2810 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2847 return FFMPEG_CONFIGURATION;
2852 #define LICENSE_PREFIX "libavcodec license: "
2936 if (be < 0 || be > 1)
2938 return map[
fmt][be];
2971 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2972 return (frame_bytes * 8LL) / (bps * ch);
2998 return 256 * sr / 245;
3003 return (480 << (sr / 22050)) / ch;
3011 case 20:
return 160;
3012 case 19:
return 144;
3013 case 29:
return 288;
3014 case 37:
return 480;
3018 case 38:
return 160;
3019 case 50:
return 240;
3024 if (frame_bytes > 0) {
3027 return 240 * (frame_bytes / 32);
3029 return 256 * (frame_bytes / 64);
3031 return 160 * (frame_bytes / 20);
3033 return 240 * (frame_bytes / 24);
3038 return frame_bytes * 8 /
bps;
3045 return frame_bytes / (9 * ch) * 16;
3047 return frame_bytes / (16 * ch) * 28;
3050 return (frame_bytes - 4 * ch) * 2 / ch;
3052 return (frame_bytes - 4) * 2 / ch;
3054 return (frame_bytes - 8) * 2 / ch;
3056 return (frame_bytes / 128) * 224 / ch;
3058 return (frame_bytes - 6 - ch) / ch;
3060 return (frame_bytes - 8) / ch;
3062 return (frame_bytes - 2 * ch) / ch;
3064 return 3 * frame_bytes / ch;
3066 return 6 * frame_bytes / ch;
3068 return 2 * (frame_bytes / (5 * ch));
3071 return 4 * frame_bytes / ch;
3078 return frame_bytes / ch;
3080 return frame_bytes * 2 / ch;
3086 int blocks = frame_bytes / ba;
3089 if (bps < 2 || bps > 5)
3091 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3093 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3095 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3097 return blocks * ((ba - 4 * ch) * 2 / ch);
3099 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3109 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3113 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
3115 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3149 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3153 #if FF_API_MISSING_SAMPLE
3155 void av_log_missing_feature(
void *avc,
const char *feature,
int want_sample)
3158 "version to the newest one from Git. If the problem still "
3159 "occurs, it means that your file has a feature which has not "
3160 "been implemented.\n", feature);
3162 av_log_ask_for_sample(avc, NULL);
3165 void av_log_ask_for_sample(
void *avc,
const char *msg, ...)
3167 va_list argument_list;
3169 va_start(argument_list, msg);
3174 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
3175 "and contact the ffmpeg-devel mailing list.\n");
3177 va_end(argument_list);
3187 hwaccel->
next = NULL;
3202 if (hwaccel->
id == codec_id
3203 && hwaccel->
pix_fmt == pix_fmt)
3234 entangled_thread_counter++;
3235 if (entangled_thread_counter != 1) {
3236 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3238 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3239 ff_avcodec_locked = 1;
3244 ff_avcodec_locked = 1;
3251 ff_avcodec_locked = 0;
3252 entangled_thread_counter--;
3404 uint32_t *av_restrict
state)
3412 for (i = 0; i < 3; i++) {
3413 uint32_t tmp = *state << 8;
3414 *state = tmp + *(p++);
3415 if (tmp == 0x100 || p == end)
3420 if (p[-1] > 1 ) p += 3;
3421 else if (p[-2] ) p += 2;
3422 else if (p[-3]|(p[-1]-1)) p++;
3429 p =
FFMIN(p, end) - 4;