68 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
121 #if CONFIG_RAISE_MAJOR
122 # define LIBNAME "LIBAVCODEC_155"
124 # define LIBNAME "LIBAVCODEC_55"
127 #if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
142 if (min_size < *size)
144 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
191 static int initialized = 0;
193 if (initialized != 0)
208 return codec && codec->
decode;
220 last_avcodec = &codec->
next;
233 #if FF_API_SET_DIMENSIONS
273 *data = matrix_encoding;
410 w_align =
FFMAX(w_align, 8);
413 *width =
FFALIGN(*width, w_align);
414 *height =
FFALIGN(*height, h_align);
420 for (i = 0; i < 4; i++)
432 align =
FFMAX(linesize_align[0], linesize_align[3]);
433 linesize_align[1] <<= chroma_shift;
434 linesize_align[2] <<= chroma_shift;
435 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
436 *width =
FFALIGN(*width, align);
445 *xpos = (pos&1) * 128;
446 *ypos = ((pos>>1)^(pos<4)) * 128;
464 int buf_size,
int align)
466 int ch, planar, needed_size,
ret = 0;
471 if (buf_size < needed_size)
485 sample_fmt, align)) < 0) {
507 int w = frame->
width;
509 int tmpsize, unaligned;
530 for (i = 0; i < 4; i++)
539 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
540 size[i] = picture.
data[i + 1] - picture.
data[i];
541 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
543 for (i = 0; i < 4; i++) {
548 CONFIG_MEMORY_POISONING ?
551 if (!pool->
pools[i]) {
566 int planes = planar ? ch : 1;
579 if (!pool->
pools[0]) {
594 for (i = 0; i < 4; i++)
605 int planes = pool->
planes;
652 int h_chroma_shift, v_chroma_shift;
655 if (pic->
data[0] != NULL) {
660 memset(pic->
data, 0,
sizeof(pic->
data));
665 for (i = 0; i < 4 && pool->
pools[i]; i++) {
666 const int h_shift = i == 0 ? 0 : h_chroma_shift;
667 const int v_shift = i == 0 ? 0 : v_chroma_shift;
710 int is_chroma = p == 1 || p == 2;
713 for (y = 0; y <
height; y++) {
715 for (x = 0; x<bytes; x++)
716 ((uint16_t*)dst)[x] = c[p];
718 memset(dst, c[p], bytes);
731 #if FF_API_GET_BUFFER
801 #if FF_API_GET_BUFFER
832 int override_dimensions = 1;
845 override_dimensions = 0;
851 #if FF_API_GET_BUFFER
884 priv->
avctx = *avctx;
893 #define WRAP_PLANE(ref_out, data, data_size) \
895 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
897 ret = AVERROR(ENOMEM); \
900 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
903 av_frame_unref(frame); \
904 ret = AVERROR(ENOMEM); \
917 if (!desc || planes <= 0) {
922 for (i = 0; i < planes; i++) {
930 planes = planar ? avctx->
channels : 1;
994 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1001 if (!frame->
data[0])
1036 #if FF_API_GET_BUFFER
1055 for (i = 0; i <
count; i++) {
1056 int r =
func(c, (
char *)arg + i * size);
1067 for (i = 0; i <
count; i++) {
1068 int r =
func(c, arg, i, 0);
1076 unsigned int fourcc)
1079 if (tags->
fourcc == fourcc)
1099 #if FF_API_AVFRAME_LAVC
1102 #if LIBAVCODEC_VERSION_MAJOR >= 55
1109 memset(frame, 0,
sizeof(
AVFrame));
1128 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1132 return codec->max_lowres;
1137 memset(sub, 0,
sizeof(*sub));
1144 int bits_per_sample;
1184 if ((!codec && !avctx->
codec)) {
1188 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1190 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1194 codec = avctx->
codec;
1272 avctx->
codec = codec;
1292 "The %s '%s' is experimental but experimental codecs are not enabled, "
1293 "add '-strict %d' if you want to use it.\n",
1298 codec_string, codec2->
name);
1310 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1312 if (CONFIG_FRAME_THREAD_ENCODER) {
1331 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1353 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1368 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1395 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1407 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1456 else if (channels != avctx->
channels) {
1460 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1461 "ignoring specified channel layout\n",
1474 "supported with subtitles codecs\n");
1479 "subtitles character encoding will be ignored\n",
1490 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1491 if (cd == (iconv_t)-1) {
1493 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1500 "conversion needs a libavcodec built with iconv support "
1501 "for this codec\n");
1525 avctx->
codec = NULL;
1531 if (avpkt->
size < 0) {
1536 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1543 if (!avpkt->
data || avpkt->
size < size) {
1553 #if FF_API_DESTRUCT_PACKET
1559 if (avpkt->
size < size) {
1565 #if FF_API_DESTRUCT_PACKET
1629 int *got_packet_ptr)
1631 AVFrame *extended_frame = NULL;
1635 int needs_realloc = !user_pkt.
data;
1637 *got_packet_ptr = 0;
1650 "with more than %d channels, but extended_data is not set.\n",
1657 if (!extended_frame)
1660 memcpy(extended_frame, frame,
sizeof(
AVFrame));
1662 frame = extended_frame;
1669 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1680 frame = padded_frame;
1692 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1694 if (*got_packet_ptr) {
1709 if (user_pkt.
data) {
1710 if (user_pkt.
size >= avpkt->
size) {
1717 avpkt->
buf = user_pkt.
buf;
1728 if (needs_realloc && avpkt->
data) {
1737 if (ret < 0 || !*got_packet_ptr) {
1755 #if FF_API_OLD_ENCODE_AUDIO
1758 const short *samples)
1762 int ret, samples_size, got_packet;
1766 pkt.
size = buf_size;
1781 "support this codec\n");
1785 nb_samples = (int64_t)buf_size * 8 /
1788 if (nb_samples >= INT_MAX) {
1803 samples_size, 1)) < 0) {
1834 return ret ? ret : pkt.
size;
1839 #if FF_API_OLD_ENCODE_VIDEO
1844 int ret, got_packet = 0;
1853 pkt.
size = buf_size;
1870 return ret ? ret : pkt.
size;
1878 int *got_packet_ptr)
1882 int needs_realloc = !user_pkt.
data;
1884 *got_packet_ptr = 0;
1886 if(CONFIG_FRAME_THREAD_ENCODER &&
1905 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1910 if (user_pkt.
data) {
1911 if (user_pkt.
size >= avpkt->
size) {
1918 avpkt->
buf = user_pkt.
buf;
1929 if (!*got_packet_ptr)
1934 if (needs_realloc && avpkt->
data) {
1943 if (ret < 0 || !*got_packet_ptr)
1977 int64_t reordered_pts, int64_t dts)
1995 pts = reordered_pts;
2014 "changes, but PARAM_CHANGE side data was sent to it.\n");
2021 flags = bytestream_get_le32(&data);
2027 avctx->
channels = bytestream_get_le32(&data);
2045 avctx->
width = bytestream_get_le32(&data);
2046 avctx->
height = bytestream_get_le32(&data);
2118 int *got_picture_ptr,
2133 *got_picture_ptr = 0;
2153 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2181 if (*got_picture_ptr) {
2205 #if FF_API_OLD_DECODE_AUDIO
2207 int *frame_size_ptr,
2211 int ret, got_frame = 0;
2217 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2219 "avcodec_decode_audio4()\n");
2226 if (ret >= 0 && got_frame) {
2232 if (*frame_size_ptr < data_size) {
2234 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2241 if (planar && avctx->
channels > 1) {
2243 for (ch = 1; ch < avctx->
channels; ch++) {
2250 *frame_size_ptr = 0;
2284 uint32_t discard_padding = 0;
2299 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2302 if (ret >= 0 && *got_frame_ptr) {
2320 if(side && side_size>=10) {
2324 discard_padding =
AV_RL32(side + 4);
2355 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) {
2374 avctx->internal->pkt = NULL;
2381 if (
ret >= 0 && *got_frame_ptr) {
2382 if (!avctx->refcounted_frames) {
2394 #define UTF8_MAX_BYTES 4
2399 iconv_t cd = (iconv_t)-1;
2428 outb = outpkt->
data;
2429 outl = outpkt->
size;
2431 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2432 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2433 outl >= outpkt->
size || inl != 0) {
2440 outpkt->
size -= outl;
2441 memset(outpkt->
data + outpkt->
size, 0, outl);
2444 if (cd != (iconv_t)-1)
2448 av_assert0(!
"requesting subtitles recoding without iconv");
2455 uint32_t codepoint,
min;
2459 GET_UTF8(codepoint, *(byte++),
return 0;);
2460 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2461 1 << (5 * (byte - str) - 4);
2462 if (codepoint < min || codepoint >= 0x110000 ||
2463 codepoint == 0xFFFE ||
2464 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2517 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2531 "Invalid UTF-8 in decoded subtitles text; "
2532 "maybe missing -sub_charenc option\n");
2538 if (tmp.
data != pkt_recoded.
data) {
2610 if (CONFIG_FRAME_THREAD_ENCODER &&
2636 avctx->
codec = NULL;
2657 default :
return id;
2663 AVCodec *p, *experimental = NULL;
2676 return experimental;
2734 return "unknown_codec";
2741 #define TAG_PRINT(x) \
2742 (((x) >= '0' && (x) <= '9') || \
2743 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2744 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2746 for (i = 0; i < 4; i++) {
2748 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2750 buf_size = buf_size > len ? buf_size - len : 0;
2760 const char *codec_name;
2761 const char *profile = NULL;
2766 if (!buf || buf_size <= 0)
2780 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2782 buf[0] ^=
'a' ^
'A';
2788 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2792 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2793 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2799 char detail[256] =
"(";
2800 const char *colorspace_name;
2801 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2812 if (colorspace_name)
2813 av_strlcatf(detail,
sizeof(detail),
"%s, ", colorspace_name);
2815 if (strlen(detail) > 1) {
2816 detail[strlen(detail) - 2] = 0;
2821 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2829 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2830 " [SAR %d:%d DAR %d:%d]",
2832 display_aspect_ratio.
num, display_aspect_ratio.
den);
2836 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2842 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2843 ", q=%d-%d", enc->
qmin, enc->
qmax);
2848 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2854 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2862 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2869 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2877 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2880 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2885 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2886 ", %d kb/s", bitrate / 1000);
2888 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2925 return FFMPEG_CONFIGURATION;
2930 #define LICENSE_PREFIX "libavcodec license: "
3014 if (be < 0 || be > 1)
3016 return map[
fmt][be];
3049 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
3050 return (frame_bytes * 8LL) / (bps * ch);
3076 return 256 * sr / 245;
3081 return (480 << (sr / 22050)) / ch;
3089 case 20:
return 160;
3090 case 19:
return 144;
3091 case 29:
return 288;
3092 case 37:
return 480;
3096 case 38:
return 160;
3097 case 50:
return 240;
3102 if (frame_bytes > 0) {
3105 return 240 * (frame_bytes / 32);
3107 return 256 * (frame_bytes / 64);
3109 return 160 * (frame_bytes / 20);
3111 return 240 * (frame_bytes / 24);
3116 return frame_bytes * 8 /
bps;
3123 return frame_bytes / (9 * ch) * 16;
3125 return frame_bytes / (16 * ch) * 28;
3128 return (frame_bytes - 4 * ch) * 2 / ch;
3130 return (frame_bytes - 4) * 2 / ch;
3132 return (frame_bytes - 8) * 2 / ch;
3134 return (frame_bytes / 128) * 224 / ch;
3136 return (frame_bytes - 6 - ch) / ch;
3138 return (frame_bytes - 8) / ch;
3140 return (frame_bytes - 2 * ch) / ch;
3142 return 3 * frame_bytes / ch;
3144 return 6 * frame_bytes / ch;
3146 return 2 * (frame_bytes / (5 * ch));
3149 return 4 * frame_bytes / ch;
3156 return frame_bytes / ch;
3158 return frame_bytes * 2 / ch;
3164 int blocks = frame_bytes / ba;
3167 if (bps < 2 || bps > 5)
3169 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3171 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3173 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3175 return blocks * ((ba - 4 * ch) * 2 / ch);
3177 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3187 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3191 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
3193 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3227 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3231 #if FF_API_MISSING_SAMPLE
3236 "version to the newest one from Git. If the problem still "
3237 "occurs, it means that your file has a feature which has not "
3238 "been implemented.\n", feature);
3245 va_list argument_list;
3247 va_start(argument_list, msg);
3252 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
3253 "and contact the ffmpeg-devel mailing list.\n");
3255 va_end(argument_list);
3266 hwaccel->
next = NULL;
3269 last_hwaccel = &hwaccel->
next;
3285 if (hwaccel->
id == codec_id
3286 && hwaccel->
pix_fmt == pix_fmt)
3317 entangled_thread_counter++;
3318 if (entangled_thread_counter != 1) {
3319 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3321 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3322 ff_avcodec_locked = 1;
3327 ff_avcodec_locked = 1;
3334 ff_avcodec_locked = 0;
3335 entangled_thread_counter--;
3487 uint32_t *av_restrict
state)
3495 for (i = 0; i < 3; i++) {
3496 uint32_t tmp = *state << 8;
3497 *state = tmp + *(p++);
3498 if (tmp == 0x100 || p == end)
3503 if (p[-1] > 1 ) p += 3;
3504 else if (p[-2] ) p += 2;
3505 else if (p[-3]|(p[-1]-1)) p++;
3512 p =
FFMIN(p, end) - 4;