66 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
80 static inline int ff_fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
85 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
136 static int initialized = 0;
138 if (initialized != 0)
152 return codec && codec->
decode;
182 #define INTERNAL_BUFFER_SIZE (32 + 1)
184 #if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
185 # define STRIDE_ALIGN 16
187 # define STRIDE_ALIGN 8
296 w_align =
FFMAX(w_align, 8);
299 *width =
FFALIGN(*width, w_align);
300 *height =
FFALIGN(*height, h_align);
306 for (i = 0; i < 4; i++)
318 align =
FFMAX(linesize_align[0], linesize_align[3]);
319 linesize_align[1] <<= chroma_shift;
320 linesize_align[2] <<= chroma_shift;
321 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
322 *width =
FFALIGN(*width, align);
327 int buf_size,
int align)
329 int ch, planar, needed_size, ret = 0;
334 if (buf_size < needed_size)
348 sample_fmt, align)) < 0) {
378 frame->
data[0], buf_size, 0);
387 "internal audio buffer used\n", frame);
429 int h_chroma_shift, v_chroma_shift;
456 for (i = 0; i < 4; i++)
457 unaligned |= picture.
linesize[i] % stride_align[i];
464 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
465 size[i] = picture.
data[i + 1] - picture.
data[i];
466 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
468 memset(buf->
base, 0,
sizeof(buf->
base));
469 memset(buf->
data, 0,
sizeof(buf->
data));
471 for (i = 0; i < 4 && size[i]; i++) {
472 const int h_shift = i == 0 ? 0 : h_chroma_shift;
473 const int v_shift = i == 0 ? 0 : v_chroma_shift;
491 if (size[1] && !size[2])
522 int is_chroma = p == 1 || p == 2;
526 for (x = 0; x<bytes; x++)
527 ((uint16_t*)
dst)[x] = c[p];
529 memset(dst, c[p], bytes);
629 av_log(s,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
671 for (i = 0; i < count; i++) {
672 int r =
func(c, (
char *)arg + i * size);
683 for (i = 0; i < count; i++) {
684 int r =
func(c, arg, i, 0);
706 #if LIBAVCODEC_VERSION_MAJOR >= 55
713 memset(frame, 0,
sizeof(
AVFrame));
745 if (!frame || !*frame)
756 #define MAKE_ACCESSORS(str, name, type, field) \
757 type av_##name##_get_##field(const str *s) { return s->field; } \
758 void av_##name##_set_##field(str *s, type v) { s->field = v; }
777 memset(sub, 0,
sizeof(*sub));
804 #if FF_API_AVCODEC_OPEN
831 if ((!codec && !avctx->
codec)) {
835 if ((codec && avctx->
codec && codec != avctx->
codec)) {
837 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
841 codec = avctx->
codec;
905 avctx->
codec = codec;
925 "The %s '%s' is experimental but experimental codecs are not enabled, "
926 "add '-strict %d' if you want to use it.\n",
931 codec_string, codec2->
name);
943 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
964 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
986 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1001 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1028 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1040 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1089 else if (channels != avctx->
channels) {
1093 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1094 "ignoring specified channel layout\n",
1107 "supported with subtitles codecs\n");
1112 "subtitles character encoding will be ignored\n",
1123 "conversion needs a libavcodec built with iconv support "
1124 "for this codec\n");
1156 if (!avpkt->
data || avpkt->
size < size) {
1167 if (avpkt->
size < size) {
1238 int *got_packet_ptr)
1244 int needs_realloc = !user_pkt.
data;
1246 *got_packet_ptr = 0;
1259 "with more than %d channels, but extended_data is not set.\n",
1274 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1284 frame = padded_frame;
1296 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1298 if (*got_packet_ptr) {
1313 if (user_pkt.
data) {
1314 if (user_pkt.
size >= avpkt->
size) {
1331 if (needs_realloc && avpkt->
data) {
1334 avpkt->
data = new_data;
1340 if (ret < 0 || !*got_packet_ptr) {
1362 #if FF_API_OLD_ENCODE_AUDIO
1370 int ret, samples_size, got_packet;
1374 pkt.
size = buf_size;
1388 "support this codec\n");
1391 nb_samples = (int64_t)buf_size * 8 /
1394 if (nb_samples >= INT_MAX)
1407 samples_size, 1)) < 0)
1435 return ret ? ret : pkt.
size;
1440 #if FF_API_OLD_ENCODE_VIDEO
1445 int ret, got_packet = 0;
1454 pkt.
size = buf_size;
1471 return ret ? ret : pkt.
size;
1479 int *got_packet_ptr)
1483 int needs_realloc = !user_pkt.
data;
1485 *got_packet_ptr = 0;
1505 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1510 if (user_pkt.
data) {
1511 if (user_pkt.
size >= avpkt->
size) {
1528 if (!*got_packet_ptr)
1533 if (needs_realloc && avpkt->
data &&
1537 avpkt->
data = new_data;
1543 if (ret < 0 || !*got_packet_ptr)
1575 int64_t reordered_pts, int64_t dts)
1589 pts = reordered_pts;
1606 if (!data || size < 4)
1608 flags = bytestream_get_le32(&data);
1613 avctx->
channels = bytestream_get_le32(&data);
1631 avctx->
width = bytestream_get_le32(&data);
1632 avctx->
height = bytestream_get_le32(&data);
1649 end = side_metadata +
size;
1650 while (side_metadata < end) {
1651 const uint8_t *key = side_metadata;
1652 const uint8_t *val = side_metadata + strlen(key) + 1;
1656 side_metadata = val + strlen(val) + 1;
1664 int *got_picture_ptr,
1676 *got_picture_ptr = 0;
1690 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
1717 if (*got_picture_ptr){
1734 #if FF_API_OLD_DECODE_AUDIO
1736 int *frame_size_ptr,
1740 int ret, got_frame = 0;
1744 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1746 "avcodec_decode_audio4()\n");
1753 if (ret >= 0 && got_frame) {
1759 if (*frame_size_ptr < data_size) {
1761 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1767 if (planar && avctx->
channels > 1) {
1769 for (ch = 1; ch < avctx->
channels; ch++) {
1774 *frame_size_ptr = data_size;
1776 *frame_size_ptr = 0;
1788 int planar, channels;
1813 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
1814 if (ret >= 0 && *got_frame_ptr) {
1833 if(side && side_size>=10) {
1878 if (*got_frame_ptr) {
1890 #define UTF8_MAX_BYTES 4
1895 iconv_t cd = (iconv_t)-1;
1907 if (cd == (iconv_t)-1) {
1909 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1928 outb = outpkt->
data;
1929 outl = outpkt->
size;
1931 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
1932 iconv(cd,
NULL,
NULL, &outb, &outl) == (
size_t)-1 ||
1933 outl >= outpkt->
size || inl != 0) {
1940 outpkt->
size -= outl;
1941 memset(outpkt->
data + outpkt->
size, 0, outl);
1944 if (cd != (iconv_t)-1)
1948 av_assert0(!
"requesting subtitles recoding without iconv");
1977 avctx->
pkt = &pkt_recoded;
1982 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2080 default :
return id;
2099 return experimental;
2157 return "unknown_codec";
2162 int i,
len, ret = 0;
2164 #define TAG_PRINT(x) \
2165 (((x) >= '0' && (x) <= '9') || \
2166 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2167 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2169 for (i = 0; i < 4; i++) {
2171 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2173 buf_size = buf_size > len ? buf_size - len : 0;
2183 const char *codec_name;
2184 const char *profile =
NULL;
2189 if (!buf || buf_size <= 0)
2203 snprintf(buf, buf_size,
"%s: %s%s", codec_type ? codec_type :
"unknown",
2205 buf[0] ^=
'a' ^
'A';
2207 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2211 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2212 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2218 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2223 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2227 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2235 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2236 " [SAR %d:%d DAR %d:%d]",
2238 display_aspect_ratio.
num, display_aspect_ratio.
den);
2242 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2248 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2249 ", q=%d-%d", enc->
qmin, enc->
qmax);
2254 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2260 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2268 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2278 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2281 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2286 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2287 ", %d kb/s", bitrate / 1000);
2318 return FFMPEG_CONFIGURATION;
2323 #define LICENSE_PREFIX "libavcodec license: "
2351 for (j = 0; j < 4; j++) {
2447 if (be < 0 || be > 1)
2449 return map[
fmt][be];
2482 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2483 return (frame_bytes * 8LL) / (bps * ch);
2509 return 256 * sr / 245;
2514 return (480 << (sr / 22050)) / ch;
2522 case 20:
return 160;
2523 case 19:
return 144;
2524 case 29:
return 288;
2525 case 37:
return 480;
2529 case 38:
return 160;
2530 case 50:
return 240;
2535 if (frame_bytes > 0) {
2538 return 240 * (frame_bytes / 32);
2540 return 256 * (frame_bytes / 64);
2542 return 160 * (frame_bytes / 20);
2544 return 240 * (frame_bytes / 24);
2549 return frame_bytes * 8 /
bps;
2556 return frame_bytes / (9 * ch) * 16;
2559 return (frame_bytes - 4 * ch) * 2 / ch;
2561 return (frame_bytes - 4) * 2 / ch;
2563 return (frame_bytes - 8) * 2 / ch;
2565 return (frame_bytes / 128) * 224 / ch;
2567 return (frame_bytes - 6 - ch) / ch;
2569 return (frame_bytes - 8) / ch;
2571 return (frame_bytes - 2 * ch) / ch;
2573 return 3 * frame_bytes / ch;
2575 return 6 * frame_bytes / ch;
2577 return 2 * (frame_bytes / (5 * ch));
2580 return 4 * frame_bytes / ch;
2587 return frame_bytes / ch;
2589 return frame_bytes * 2 / ch;
2595 int blocks = frame_bytes / ba;
2598 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2600 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2602 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2604 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2614 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2618 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
2620 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2654 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
2661 "version to the newest one from Git. If the problem still "
2662 "occurs, it means that your file has a feature which has not "
2663 "been implemented.\n", feature);
2670 va_list argument_list;
2672 va_start(argument_list, msg);
2677 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
2678 "and contact the ffmpeg-devel mailing list.\n");
2680 va_end(argument_list);
2704 if (hwaccel->
id == codec_id
2705 && hwaccel->
pix_fmt == pix_fmt)
2738 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");