69 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
125 if (min_size <= *size && *p)
127 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
174 static int initialized = 0;
176 if (initialized != 0)
191 return codec && codec->
decode;
203 last_avcodec = &codec->
next;
216 #if FF_API_SET_DIMENSIONS
271 *data = matrix_encoding;
419 w_align =
FFMAX(w_align, 8);
422 *width =
FFALIGN(*width, w_align);
423 *height =
FFALIGN(*height, h_align);
429 for (i = 0; i < 4; i++)
441 align =
FFMAX(linesize_align[0], linesize_align[3]);
442 linesize_align[1] <<= chroma_shift;
443 linesize_align[2] <<= chroma_shift;
444 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
445 *width =
FFALIGN(*width, align);
454 *xpos = (pos&1) * 128;
455 *ypos = ((pos>>1)^(pos<4)) * 128;
473 int buf_size,
int align)
475 int ch, planar, needed_size,
ret = 0;
480 if (buf_size < needed_size)
494 sample_fmt, align)) < 0) {
516 int w = frame->
width;
518 int tmpsize, unaligned;
534 for (i = 0; i < 4; i++)
543 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
544 size[i] = picture.
data[i + 1] - picture.
data[i];
545 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
547 for (i = 0; i < 4; i++) {
552 CONFIG_MEMORY_POISONING ?
555 if (!pool->
pools[i]) {
570 int planes = planar ? ch : 1;
583 if (!pool->
pools[0]) {
598 for (i = 0; i < 4; i++)
609 int planes = pool->
planes;
661 memset(pic->
data, 0,
sizeof(pic->
data));
664 for (i = 0; i < 4 && pool->
pools[i]; i++) {
698 int is_chroma = p == 1 || p == 2;
701 for (y = 0; y <
height; y++) {
703 for (x = 0; x<bytes; x++)
704 ((uint16_t*)dst)[x] = c[p];
706 memset(dst, c[p], bytes);
719 #if FF_API_GET_BUFFER
739 static const struct {
764 memcpy(frame_sd->
data, packet_sd, size);
831 #if FF_API_GET_BUFFER
868 int override_dimensions = 1;
881 override_dimensions = 0;
895 #if FF_API_GET_BUFFER
928 priv->
avctx = *avctx;
937 #define WRAP_PLANE(ref_out, data, data_size) \
939 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
941 ret = AVERROR(ENOMEM); \
944 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
947 av_frame_unref(frame); \
948 ret = AVERROR(ENOMEM); \
961 if (!desc || planes <= 0) {
966 for (i = 0; i < planes; i++) {
974 planes = planar ? avctx->
channels : 1;
1039 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1046 if (!frame->
data[0])
1078 #if FF_API_GET_BUFFER
1097 for (i = 0; i <
count; i++) {
1098 int r =
func(c, (
char *)arg + i * size);
1109 for (i = 0; i <
count; i++) {
1110 int r =
func(c, arg, i, 0);
1118 unsigned int fourcc)
1121 if (tags->
fourcc == fourcc)
1147 if (hwaccel->
id == codec_id
1148 && hwaccel->
pix_fmt == pix_fmt)
1162 "Could not find an AVHWAccel for the pixel format: %s",
1174 ret = hwa->
init(avctx);
1200 memcpy(choices, fmt, (n + 1) *
sizeof(*choices));
1225 for (n = 0; choices[
n] !=
ret; n++)
1229 choices[
n] = choices[n + 1];
1237 #if FF_API_AVFRAME_LAVC
1240 #if LIBAVCODEC_VERSION_MAJOR >= 55
1247 memset(frame, 0,
sizeof(
AVFrame));
1251 AVFrame *avcodec_alloc_frame(
void)
1256 void avcodec_free_frame(
AVFrame **frame)
1266 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1270 return codec->max_lowres;
1275 memset(sub, 0,
sizeof(*sub));
1282 int bits_per_sample;
1322 if ((!codec && !avctx->
codec)) {
1326 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1328 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1332 codec = avctx->
codec;
1426 avctx->
codec = codec;
1446 "The %s '%s' is experimental but experimental codecs are not enabled, "
1447 "add '-strict %d' if you want to use it.\n",
1452 codec_string, codec2->
name);
1464 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1466 if (CONFIG_FRAME_THREAD_ENCODER) {
1485 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1494 "see the codecview filter instead.\n");
1513 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1528 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1561 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1573 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1612 #if FF_API_AUDIOENC_DELAY
1625 else if (channels != avctx->
channels) {
1629 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1630 "ignoring specified channel layout\n",
1643 "supported with subtitles codecs\n");
1648 "subtitles character encoding will be ignored\n",
1659 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1660 if (cd == (iconv_t)-1) {
1663 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1669 "conversion needs a libavcodec built with iconv support "
1670 "for this codec\n");
1678 #if FF_API_AVCTX_TIMEBASE
1693 if (codec->priv_class && codec->priv_data_size)
1696 if (avctx->internal) {
1701 avctx->codec = NULL;
1707 if (avpkt->
size < 0) {
1712 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1719 if (!avpkt->
data || avpkt->
size < size) {
1723 #if FF_API_DESTRUCT_PACKET
1733 #if FF_API_DESTRUCT_PACKET
1739 if (avpkt->
size < size) {
1745 #if FF_API_DESTRUCT_PACKET
1809 int *got_packet_ptr)
1811 AVFrame *extended_frame = NULL;
1815 int needs_realloc = !user_pkt.
data;
1817 *got_packet_ptr = 0;
1830 "with more than %d channels, but extended_data is not set.\n",
1837 if (!extended_frame)
1840 memcpy(extended_frame, frame,
sizeof(
AVFrame));
1842 frame = extended_frame;
1849 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1860 frame = padded_frame;
1872 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1874 if (*got_packet_ptr) {
1889 if (user_pkt.
data) {
1890 if (user_pkt.
size >= avpkt->
size) {
1897 avpkt->
buf = user_pkt.
buf;
1899 #if FF_API_DESTRUCT_PACKET
1912 if (needs_realloc && avpkt->
data) {
1921 if (ret < 0 || !*got_packet_ptr) {
1936 #if FF_API_AUDIOENC_DELAY
1943 #if FF_API_OLD_ENCODE_AUDIO
1946 const short *samples)
1950 int ret, samples_size, got_packet;
1954 pkt.
size = buf_size;
1969 "support this codec\n");
1973 nb_samples = (int64_t)buf_size * 8 /
1976 if (nb_samples >= INT_MAX) {
1991 samples_size, 1)) < 0) {
2022 return ret ? ret : pkt.
size;
2027 #if FF_API_OLD_ENCODE_VIDEO
2032 int ret, got_packet = 0;
2041 pkt.
size = buf_size;
2058 return ret ? ret : pkt.
size;
2066 int *got_packet_ptr)
2070 int needs_realloc = !user_pkt.
data;
2072 *got_packet_ptr = 0;
2074 if(CONFIG_FRAME_THREAD_ENCODER &&
2093 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
2098 if (user_pkt.
data) {
2099 if (user_pkt.
size >= avpkt->
size) {
2106 avpkt->
buf = user_pkt.
buf;
2108 #if FF_API_DESTRUCT_PACKET
2121 if (!*got_packet_ptr)
2126 if (needs_realloc && avpkt->
data) {
2135 if (ret < 0 || !*got_packet_ptr)
2169 int64_t reordered_pts, int64_t dts)
2187 pts = reordered_pts;
2206 "changes, but PARAM_CHANGE side data was sent to it.\n");
2213 flags = bytestream_get_le32(&data);
2219 avctx->
channels = bytestream_get_le32(&data);
2237 avctx->
width = bytestream_get_le32(&data);
2238 avctx->
height = bytestream_get_le32(&data);
2310 int *got_picture_ptr,
2325 *got_picture_ptr = 0;
2345 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2373 if (*got_picture_ptr) {
2394 #if FF_API_AVCTX_TIMEBASE
2402 #if FF_API_OLD_DECODE_AUDIO
2404 int *frame_size_ptr,
2408 int ret, got_frame = 0;
2414 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2416 "avcodec_decode_audio4()\n");
2423 if (ret >= 0 && got_frame) {
2429 if (*frame_size_ptr < data_size) {
2431 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2438 if (planar && avctx->
channels > 1) {
2440 for (ch = 1; ch < avctx->
channels; ch++) {
2445 *frame_size_ptr = data_size;
2447 *frame_size_ptr = 0;
2481 uint32_t discard_padding = 0;
2498 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2501 if (ret >= 0 && *got_frame_ptr) {
2519 if(side && side_size>=10) {
2523 discard_padding =
AV_RL32(side + 4);
2524 skip_reason =
AV_RL8(side + 8);
2525 discard_reason =
AV_RL8(side + 9);
2557 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr &&
2580 AV_WL32(fside->
data, avctx->internal->skip_samples);
2584 avctx->internal->skip_samples = 0;
2588 avctx->internal->pkt = NULL;
2595 if (
ret >= 0 && *got_frame_ptr) {
2596 if (!avctx->refcounted_frames) {
2608 #define UTF8_MAX_BYTES 4
2613 iconv_t cd = (iconv_t)-1;
2642 outb = outpkt->
data;
2643 outl = outpkt->
size;
2645 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2646 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2647 outl >= outpkt->
size || inl != 0) {
2654 outpkt->
size -= outl;
2655 memset(outpkt->
data + outpkt->
size, 0, outl);
2658 if (cd != (iconv_t)-1)
2670 uint32_t codepoint,
min;
2674 GET_UTF8(codepoint, *(byte++),
return 0;);
2675 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2676 1 << (5 * (byte - str) - 4);
2677 if (codepoint < min || codepoint >= 0x110000 ||
2678 codepoint == 0xFFFE ||
2679 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2732 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2746 "Invalid UTF-8 in decoded subtitles text; "
2747 "maybe missing -sub_charenc option\n");
2753 if (tmp.
data != pkt_recoded.
data) {
2807 if (CONFIG_FRAME_THREAD_ENCODER &&
2836 avctx->
codec = NULL;
2866 default :
return id;
2872 AVCodec *p, *experimental = NULL;
2885 return experimental;
2943 return "unknown_codec";
2950 #define TAG_PRINT(x) \
2951 (((x) >= '0' && (x) <= '9') || \
2952 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2953 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2955 for (i = 0; i < 4; i++) {
2957 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2959 buf_size = buf_size > len ? buf_size - len : 0;
2969 const char *codec_name;
2977 if (!buf || buf_size <= 0)
2991 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2993 buf[0] ^=
'a' ^
'A';
2999 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
3004 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3005 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
3011 char detail[256] =
"(";
3015 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3045 if (strlen(detail) > 1) {
3046 detail[strlen(detail) - 2] = 0;
3052 av_strlcat(buf, new_line ? separator :
", ", buf_size);
3054 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3061 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3069 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3070 " [SAR %d:%d DAR %d:%d]",
3072 display_aspect_ratio.
num, display_aspect_ratio.
den);
3076 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3082 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3083 ", q=%d-%d", enc->
qmin, enc->
qmax);
3090 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3095 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3100 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3107 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3114 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3122 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3125 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3130 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3131 ", %d kb/s", bitrate / 1000);
3133 snprintf(buf + strlen(buf), buf_size - strlen(buf),
3170 return FFMPEG_CONFIGURATION;
3175 #define LICENSE_PREFIX "libavcodec license: "
3263 if (be < 0 || be > 1)
3265 return map[
fmt][be];
3298 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
3299 return (frame_bytes * 8LL) / (bps * ch);
3326 return 256 * sr / 245;
3331 return (480 << (sr / 22050)) / ch;
3339 case 20:
return 160;
3340 case 19:
return 144;
3341 case 29:
return 288;
3342 case 37:
return 480;
3346 case 38:
return 160;
3347 case 50:
return 240;
3352 if (frame_bytes > 0) {
3355 return 240 * (frame_bytes / 32);
3357 return 256 * (frame_bytes / 64);
3359 return 160 * (frame_bytes / 20);
3361 return 240 * (frame_bytes / 24);
3366 return frame_bytes * 8 /
bps;
3373 return frame_bytes / (9 * ch) * 16;
3375 return frame_bytes / (16 * ch) * 28;
3378 return (frame_bytes - 4 * ch) * 2 / ch;
3380 return (frame_bytes - 4) * 2 / ch;
3382 return (frame_bytes - 8) * 2 / ch;
3384 return (frame_bytes / 128) * 224 / ch;
3386 return (frame_bytes - 6 - ch) / ch;
3388 return (frame_bytes - 8) / ch;
3390 return (frame_bytes - 2 * ch) / ch;
3392 return 3 * frame_bytes / ch;
3394 return 6 * frame_bytes / ch;
3396 return 2 * (frame_bytes / (5 * ch));
3399 return 4 * frame_bytes / ch;
3406 return frame_bytes / ch;
3408 return frame_bytes * 2 / ch;
3414 int blocks = frame_bytes / ba;
3417 if (bps < 2 || bps > 5)
3419 return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3421 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3423 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3425 return blocks * ((ba - 4 * ch) * 2 / ch);
3427 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3437 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3441 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
3443 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3488 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3492 #if FF_API_MISSING_SAMPLE
3497 "version to the newest one from Git. If the problem still "
3498 "occurs, it means that your file has a feature which has not "
3499 "been implemented.\n", feature);
3506 va_list argument_list;
3508 va_start(argument_list, msg);
3513 "of this file to ftp://upload.ffmpeg.org/incoming/ "
3514 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
3516 va_end(argument_list);
3527 hwaccel->
next = NULL;
3530 last_hwaccel = &hwaccel->
next;
3547 avformat_mutex = NULL;
3551 void *new_codec_mutex = NULL;
3552 void *new_avformat_mutex = NULL;
3563 codec_mutex = new_codec_mutex;
3564 avformat_mutex = new_avformat_mutex;
3576 entangled_thread_counter++;
3577 if (entangled_thread_counter != 1) {
3578 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3580 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3581 ff_avcodec_locked = 1;
3586 ff_avcodec_locked = 1;
3593 ff_avcodec_locked = 0;
3594 entangled_thread_counter--;
3626 ((
unsigned)
av_toupper((x >> 24) & 0xFF) << 24);
3753 uint32_t *av_restrict
state)
3761 for (i = 0; i < 3; i++) {
3762 uint32_t tmp = *state << 8;
3763 *state = tmp + *(p++);
3764 if (tmp == 0x100 || p == end)
3769 if (p[-1] > 1 ) p += 3;
3770 else if (p[-2] ) p += 2;
3771 else if (p[-3]|(p[-1]-1)) p++;
3778 p =
FFMIN(p, end) - 4;