69 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
122 #if CONFIG_RAISE_MAJOR
123 # define LIBNAME "LIBAVCODEC_155"
125 # define LIBNAME "LIBAVCODEC_55"
128 #if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
143 if (min_size < *size)
145 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
192 static int initialized = 0;
194 if (initialized != 0)
209 return codec && codec->
decode;
221 last_avcodec = &codec->
next;
234 #if FF_API_SET_DIMENSIONS
289 *data = matrix_encoding;
427 w_align =
FFMAX(w_align, 8);
430 *width =
FFALIGN(*width, w_align);
431 *height =
FFALIGN(*height, h_align);
437 for (i = 0; i < 4; i++)
449 align =
FFMAX(linesize_align[0], linesize_align[3]);
450 linesize_align[1] <<= chroma_shift;
451 linesize_align[2] <<= chroma_shift;
452 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
453 *width =
FFALIGN(*width, align);
462 *xpos = (pos&1) * 128;
463 *ypos = ((pos>>1)^(pos<4)) * 128;
481 int buf_size,
int align)
483 int ch, planar, needed_size,
ret = 0;
488 if (buf_size < needed_size)
502 sample_fmt, align)) < 0) {
524 int w = frame->
width;
526 int tmpsize, unaligned;
542 for (i = 0; i < 4; i++)
551 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
552 size[i] = picture.
data[i + 1] - picture.
data[i];
553 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
555 for (i = 0; i < 4; i++) {
560 CONFIG_MEMORY_POISONING ?
563 if (!pool->
pools[i]) {
578 int planes = planar ? ch : 1;
591 if (!pool->
pools[0]) {
606 for (i = 0; i < 4; i++)
617 int planes = pool->
planes;
664 if (pic->
data[0] != NULL) {
669 memset(pic->
data, 0,
sizeof(pic->
data));
672 for (i = 0; i < 4 && pool->
pools[i]; i++) {
706 int is_chroma = p == 1 || p == 2;
709 for (y = 0; y <
height; y++) {
711 for (x = 0; x<bytes; x++)
712 ((uint16_t*)dst)[x] = c[p];
714 memset(dst, c[p], bytes);
727 #if FF_API_GET_BUFFER
763 memcpy(frame_sd->
data, packet_sd, size);
773 memcpy(frame_sd->
data, packet_sd, size);
783 #if FF_API_AVFRAME_COLORSPACE
841 #if FF_API_GET_BUFFER
878 int override_dimensions = 1;
891 override_dimensions = 0;
905 #if FF_API_GET_BUFFER
938 priv->
avctx = *avctx;
947 #define WRAP_PLANE(ref_out, data, data_size) \
949 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
951 ret = AVERROR(ENOMEM); \
954 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
957 av_frame_unref(frame); \
958 ret = AVERROR(ENOMEM); \
971 if (!desc || planes <= 0) {
976 for (i = 0; i < planes; i++) {
984 planes = planar ? avctx->
channels : 1;
1049 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1056 if (!frame->
data[0])
1088 #if FF_API_GET_BUFFER
1107 for (i = 0; i <
count; i++) {
1108 int r =
func(c, (
char *)arg + i * size);
1119 for (i = 0; i <
count; i++) {
1120 int r =
func(c, arg, i, 0);
1128 unsigned int fourcc)
1131 if (tags->
fourcc == fourcc)
1157 if (hwaccel->
id == codec_id
1158 && hwaccel->
pix_fmt == pix_fmt)
1186 "Could not find an AVHWAccel for the pixel format: %s",
1197 if (hwaccel->
init) {
1198 err = hwaccel->
init(avctx);
1210 #if FF_API_AVFRAME_LAVC
1213 #if LIBAVCODEC_VERSION_MAJOR >= 55
1220 memset(frame, 0,
sizeof(
AVFrame));
1224 AVFrame *avcodec_alloc_frame(
void)
1229 void avcodec_free_frame(
AVFrame **frame)
1239 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1243 return codec->max_lowres;
1248 memset(sub, 0,
sizeof(*sub));
1255 int bits_per_sample;
1295 if ((!codec && !avctx->
codec)) {
1299 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1301 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1305 codec = avctx->
codec;
1393 avctx->
codec = codec;
1413 "The %s '%s' is experimental but experimental codecs are not enabled, "
1414 "add '-strict %d' if you want to use it.\n",
1419 codec_string, codec2->
name);
1431 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1433 if (CONFIG_FRAME_THREAD_ENCODER) {
1452 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1474 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1489 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1516 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1528 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1577 else if (channels != avctx->
channels) {
1581 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1582 "ignoring specified channel layout\n",
1595 "supported with subtitles codecs\n");
1600 "subtitles character encoding will be ignored\n",
1611 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1612 if (cd == (iconv_t)-1) {
1614 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1621 "conversion needs a libavcodec built with iconv support "
1622 "for this codec\n");
1646 avctx->
codec = NULL;
1652 if (avpkt->
size < 0) {
1657 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1664 if (!avpkt->
data || avpkt->
size < size) {
1668 #if FF_API_DESTRUCT_PACKET
1678 #if FF_API_DESTRUCT_PACKET
1684 if (avpkt->
size < size) {
1690 #if FF_API_DESTRUCT_PACKET
1754 int *got_packet_ptr)
1756 AVFrame *extended_frame = NULL;
1760 int needs_realloc = !user_pkt.
data;
1762 *got_packet_ptr = 0;
1775 "with more than %d channels, but extended_data is not set.\n",
1782 if (!extended_frame)
1785 memcpy(extended_frame, frame,
sizeof(
AVFrame));
1787 frame = extended_frame;
1794 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1805 frame = padded_frame;
1817 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1819 if (*got_packet_ptr) {
1834 if (user_pkt.
data) {
1835 if (user_pkt.
size >= avpkt->
size) {
1842 avpkt->
buf = user_pkt.
buf;
1844 #if FF_API_DESTRUCT_PACKET
1857 if (needs_realloc && avpkt->
data) {
1866 if (ret < 0 || !*got_packet_ptr) {
1884 #if FF_API_OLD_ENCODE_AUDIO
1887 const short *samples)
1891 int ret, samples_size, got_packet;
1895 pkt.
size = buf_size;
1910 "support this codec\n");
1914 nb_samples = (int64_t)buf_size * 8 /
1917 if (nb_samples >= INT_MAX) {
1932 samples_size, 1)) < 0) {
1963 return ret ? ret : pkt.
size;
1968 #if FF_API_OLD_ENCODE_VIDEO
1973 int ret, got_packet = 0;
1982 pkt.
size = buf_size;
1999 return ret ? ret : pkt.
size;
2007 int *got_packet_ptr)
2011 int needs_realloc = !user_pkt.
data;
2013 *got_packet_ptr = 0;
2015 if(CONFIG_FRAME_THREAD_ENCODER &&
2034 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
2039 if (user_pkt.
data) {
2040 if (user_pkt.
size >= avpkt->
size) {
2047 avpkt->
buf = user_pkt.
buf;
2049 #if FF_API_DESTRUCT_PACKET
2062 if (!*got_packet_ptr)
2067 if (needs_realloc && avpkt->
data) {
2076 if (ret < 0 || !*got_packet_ptr)
2110 int64_t reordered_pts, int64_t dts)
2128 pts = reordered_pts;
2147 "changes, but PARAM_CHANGE side data was sent to it.\n");
2154 flags = bytestream_get_le32(&data);
2160 avctx->
channels = bytestream_get_le32(&data);
2178 avctx->
width = bytestream_get_le32(&data);
2179 avctx->
height = bytestream_get_le32(&data);
2251 int *got_picture_ptr,
2266 *got_picture_ptr = 0;
2286 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2314 if (*got_picture_ptr) {
2338 #if FF_API_OLD_DECODE_AUDIO
2340 int *frame_size_ptr,
2344 int ret, got_frame = 0;
2350 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2352 "avcodec_decode_audio4()\n");
2359 if (ret >= 0 && got_frame) {
2365 if (*frame_size_ptr < data_size) {
2367 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2374 if (planar && avctx->
channels > 1) {
2376 for (ch = 1; ch < avctx->
channels; ch++) {
2381 *frame_size_ptr = data_size;
2383 *frame_size_ptr = 0;
2417 uint32_t discard_padding = 0;
2432 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2435 if (ret >= 0 && *got_frame_ptr) {
2453 if(side && side_size>=10) {
2457 discard_padding =
AV_RL32(side + 4);
2488 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) {
2507 avctx->internal->pkt = NULL;
2514 if (
ret >= 0 && *got_frame_ptr) {
2515 if (!avctx->refcounted_frames) {
2527 #define UTF8_MAX_BYTES 4
2532 iconv_t cd = (iconv_t)-1;
2561 outb = outpkt->
data;
2562 outl = outpkt->
size;
2564 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2565 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2566 outl >= outpkt->
size || inl != 0) {
2573 outpkt->
size -= outl;
2574 memset(outpkt->
data + outpkt->
size, 0, outl);
2577 if (cd != (iconv_t)-1)
2589 uint32_t codepoint,
min;
2593 GET_UTF8(codepoint, *(byte++),
return 0;);
2594 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2595 1 << (5 * (byte - str) - 4);
2596 if (codepoint < min || codepoint >= 0x110000 ||
2597 codepoint == 0xFFFE ||
2598 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2651 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2665 "Invalid UTF-8 in decoded subtitles text; "
2666 "maybe missing -sub_charenc option\n");
2672 if (tmp.
data != pkt_recoded.
data) {
2726 if (CONFIG_FRAME_THREAD_ENCODER &&
2755 avctx->
codec = NULL;
2785 default :
return id;
2791 AVCodec *p, *experimental = NULL;
2804 return experimental;
2862 return "unknown_codec";
2869 #define TAG_PRINT(x) \
2870 (((x) >= '0' && (x) <= '9') || \
2871 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2872 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2874 for (i = 0; i < 4; i++) {
2876 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2878 buf_size = buf_size > len ? buf_size - len : 0;
2888 const char *codec_name;
2889 const char *profile = NULL;
2894 if (!buf || buf_size <= 0)
2908 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2910 buf[0] ^=
'a' ^
'A';
2916 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2920 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2921 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2927 char detail[256] =
"(";
2928 const char *colorspace_name;
2929 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2940 if (colorspace_name)
2941 av_strlcatf(detail,
sizeof(detail),
"%s, ", colorspace_name);
2943 if (strlen(detail) > 1) {
2944 detail[strlen(detail) - 2] = 0;
2949 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2957 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2958 " [SAR %d:%d DAR %d:%d]",
2960 display_aspect_ratio.
num, display_aspect_ratio.
den);
2964 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2970 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2971 ", q=%d-%d", enc->
qmin, enc->
qmax);
2976 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2982 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2990 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2997 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3005 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3008 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3013 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3014 ", %d kb/s", bitrate / 1000);
3016 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3053 return FFMPEG_CONFIGURATION;
3058 #define LICENSE_PREFIX "libavcodec license: "
3146 if (be < 0 || be > 1)
3148 return map[
fmt][be];
3181 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
3182 return (frame_bytes * 8LL) / (bps * ch);
3208 return 256 * sr / 245;
3213 return (480 << (sr / 22050)) / ch;
3221 case 20:
return 160;
3222 case 19:
return 144;
3223 case 29:
return 288;
3224 case 37:
return 480;
3228 case 38:
return 160;
3229 case 50:
return 240;
3234 if (frame_bytes > 0) {
3237 return 240 * (frame_bytes / 32);
3239 return 256 * (frame_bytes / 64);
3241 return 160 * (frame_bytes / 20);
3243 return 240 * (frame_bytes / 24);
3248 return frame_bytes * 8 /
bps;
3255 return frame_bytes / (9 * ch) * 16;
3257 return frame_bytes / (16 * ch) * 28;
3260 return (frame_bytes - 4 * ch) * 2 / ch;
3262 return (frame_bytes - 4) * 2 / ch;
3264 return (frame_bytes - 8) * 2 / ch;
3266 return (frame_bytes / 128) * 224 / ch;
3268 return (frame_bytes - 6 - ch) / ch;
3270 return (frame_bytes - 8) / ch;
3272 return (frame_bytes - 2 * ch) / ch;
3274 return 3 * frame_bytes / ch;
3276 return 6 * frame_bytes / ch;
3278 return 2 * (frame_bytes / (5 * ch));
3281 return 4 * frame_bytes / ch;
3288 return frame_bytes / ch;
3290 return frame_bytes * 2 / ch;
3296 int blocks = frame_bytes / ba;
3299 if (bps < 2 || bps > 5)
3301 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3303 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3305 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3307 return blocks * ((ba - 4 * ch) * 2 / ch);
3309 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3319 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3323 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
3325 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3359 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3363 #if FF_API_MISSING_SAMPLE
3368 "version to the newest one from Git. If the problem still "
3369 "occurs, it means that your file has a feature which has not "
3370 "been implemented.\n", feature);
3377 va_list argument_list;
3379 va_start(argument_list, msg);
3384 "of this file to ftp://upload.ffmpeg.org/incoming/ "
3385 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
3387 va_end(argument_list);
3398 hwaccel->
next = NULL;
3401 last_hwaccel = &hwaccel->
next;
3435 entangled_thread_counter++;
3436 if (entangled_thread_counter != 1) {
3437 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3439 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3440 ff_avcodec_locked = 1;
3445 ff_avcodec_locked = 1;
3452 ff_avcodec_locked = 0;
3453 entangled_thread_counter--;
3484 ((
unsigned)
av_toupper((x >> 24) & 0xFF) << 24);
3606 uint32_t *av_restrict
state)
3614 for (i = 0; i < 3; i++) {
3615 uint32_t tmp = *state << 8;
3616 *state = tmp + *(p++);
3617 if (tmp == 0x100 || p == end)
3622 if (p[-1] > 1 ) p += 3;
3623 else if (p[-2] ) p += 2;
3624 else if (p[-3]|(p[-1]-1)) p++;
3631 p =
FFMIN(p, end) - 4;