69 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
125 if (min_size < *size)
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;
411 w_align =
FFMAX(w_align, 8);
414 *width =
FFALIGN(*width, w_align);
415 *height =
FFALIGN(*height, h_align);
421 for (i = 0; i < 4; i++)
433 align =
FFMAX(linesize_align[0], linesize_align[3]);
434 linesize_align[1] <<= chroma_shift;
435 linesize_align[2] <<= chroma_shift;
436 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
437 *width =
FFALIGN(*width, align);
446 *xpos = (pos&1) * 128;
447 *ypos = ((pos>>1)^(pos<4)) * 128;
465 int buf_size,
int align)
467 int ch, planar, needed_size,
ret = 0;
472 if (buf_size < needed_size)
486 sample_fmt, align)) < 0) {
508 int w = frame->
width;
510 int tmpsize, unaligned;
526 for (i = 0; i < 4; i++)
535 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
536 size[i] = picture.
data[i + 1] - picture.
data[i];
537 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
539 for (i = 0; i < 4; i++) {
544 CONFIG_MEMORY_POISONING ?
547 if (!pool->
pools[i]) {
562 int planes = planar ? ch : 1;
575 if (!pool->
pools[0]) {
590 for (i = 0; i < 4; i++)
601 int planes = pool->
planes;
653 memset(pic->
data, 0,
sizeof(pic->
data));
656 for (i = 0; i < 4 && pool->
pools[i]; i++) {
690 int is_chroma = p == 1 || p == 2;
693 for (y = 0; y <
height; y++) {
695 for (x = 0; x<bytes; x++)
696 ((uint16_t*)dst)[x] = c[p];
698 memset(dst, c[p], bytes);
711 #if FF_API_GET_BUFFER
747 memcpy(frame_sd->
data, packet_sd, size);
757 memcpy(frame_sd->
data, packet_sd, size);
767 memcpy(frame_sd->
data, packet_sd, size);
833 #if FF_API_GET_BUFFER
870 int override_dimensions = 1;
883 override_dimensions = 0;
897 #if FF_API_GET_BUFFER
930 priv->
avctx = *avctx;
939 #define WRAP_PLANE(ref_out, data, data_size) \
941 AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
943 ret = AVERROR(ENOMEM); \
946 ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
949 av_frame_unref(frame); \
950 ret = AVERROR(ENOMEM); \
963 if (!desc || planes <= 0) {
968 for (i = 0; i < planes; i++) {
976 planes = planar ? avctx->
channels : 1;
1041 av_log(avctx,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1048 if (!frame->
data[0])
1080 #if FF_API_GET_BUFFER
1099 for (i = 0; i <
count; i++) {
1100 int r =
func(c, (
char *)arg + i * size);
1111 for (i = 0; i <
count; i++) {
1112 int r =
func(c, arg, i, 0);
1120 unsigned int fourcc)
1123 if (tags->
fourcc == fourcc)
1149 if (hwaccel->
id == codec_id
1150 && hwaccel->
pix_fmt == pix_fmt)
1178 "Could not find an AVHWAccel for the pixel format: %s",
1189 if (hwaccel->
init) {
1190 err = hwaccel->
init(avctx);
1202 #if FF_API_AVFRAME_LAVC
1205 #if LIBAVCODEC_VERSION_MAJOR >= 55
1212 memset(frame, 0,
sizeof(
AVFrame));
1216 AVFrame *avcodec_alloc_frame(
void)
1221 void avcodec_free_frame(
AVFrame **frame)
1231 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1235 return codec->max_lowres;
1240 memset(sub, 0,
sizeof(*sub));
1247 int bits_per_sample;
1287 if ((!codec && !avctx->
codec)) {
1291 if ((codec && avctx->
codec && codec != avctx->
codec)) {
1293 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
1297 codec = avctx->
codec;
1385 avctx->
codec = codec;
1405 "The %s '%s' is experimental but experimental codecs are not enabled, "
1406 "add '-strict %d' if you want to use it.\n",
1411 codec_string, codec2->
name);
1423 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
1425 if (CONFIG_FRAME_THREAD_ENCODER) {
1444 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
1453 "see the codecview filter instead.\n");
1472 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
1487 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1514 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1526 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1573 else if (channels != avctx->
channels) {
1577 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1578 "ignoring specified channel layout\n",
1591 "supported with subtitles codecs\n");
1596 "subtitles character encoding will be ignored\n",
1607 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
1608 if (cd == (iconv_t)-1) {
1610 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1617 "conversion needs a libavcodec built with iconv support "
1618 "for this codec\n");
1642 avctx->
codec = NULL;
1648 if (avpkt->
size < 0) {
1653 av_log(avctx,
AV_LOG_ERROR,
"Invalid minimum required packet size %"PRId64
" (max allowed is %d)\n",
1660 if (!avpkt->
data || avpkt->
size < size) {
1664 #if FF_API_DESTRUCT_PACKET
1674 #if FF_API_DESTRUCT_PACKET
1680 if (avpkt->
size < size) {
1686 #if FF_API_DESTRUCT_PACKET
1750 int *got_packet_ptr)
1752 AVFrame *extended_frame = NULL;
1756 int needs_realloc = !user_pkt.
data;
1758 *got_packet_ptr = 0;
1771 "with more than %d channels, but extended_data is not set.\n",
1778 if (!extended_frame)
1781 memcpy(extended_frame, frame,
sizeof(
AVFrame));
1783 frame = extended_frame;
1790 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1801 frame = padded_frame;
1813 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1815 if (*got_packet_ptr) {
1830 if (user_pkt.
data) {
1831 if (user_pkt.
size >= avpkt->
size) {
1838 avpkt->
buf = user_pkt.
buf;
1840 #if FF_API_DESTRUCT_PACKET
1853 if (needs_realloc && avpkt->
data) {
1862 if (ret < 0 || !*got_packet_ptr) {
1880 #if FF_API_OLD_ENCODE_AUDIO
1883 const short *samples)
1887 int ret, samples_size, got_packet;
1891 pkt.
size = buf_size;
1906 "support this codec\n");
1910 nb_samples = (int64_t)buf_size * 8 /
1913 if (nb_samples >= INT_MAX) {
1928 samples_size, 1)) < 0) {
1959 return ret ? ret : pkt.
size;
1964 #if FF_API_OLD_ENCODE_VIDEO
1969 int ret, got_packet = 0;
1978 pkt.
size = buf_size;
1995 return ret ? ret : pkt.
size;
2003 int *got_packet_ptr)
2007 int needs_realloc = !user_pkt.
data;
2009 *got_packet_ptr = 0;
2011 if(CONFIG_FRAME_THREAD_ENCODER &&
2030 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
2035 if (user_pkt.
data) {
2036 if (user_pkt.
size >= avpkt->
size) {
2043 avpkt->
buf = user_pkt.
buf;
2045 #if FF_API_DESTRUCT_PACKET
2058 if (!*got_packet_ptr)
2063 if (needs_realloc && avpkt->
data) {
2072 if (ret < 0 || !*got_packet_ptr)
2106 int64_t reordered_pts, int64_t dts)
2124 pts = reordered_pts;
2143 "changes, but PARAM_CHANGE side data was sent to it.\n");
2150 flags = bytestream_get_le32(&data);
2156 avctx->
channels = bytestream_get_le32(&data);
2174 avctx->
width = bytestream_get_le32(&data);
2175 avctx->
height = bytestream_get_le32(&data);
2247 int *got_picture_ptr,
2262 *got_picture_ptr = 0;
2282 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
2310 if (*got_picture_ptr) {
2334 #if FF_API_OLD_DECODE_AUDIO
2336 int *frame_size_ptr,
2340 int ret, got_frame = 0;
2346 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2348 "avcodec_decode_audio4()\n");
2355 if (ret >= 0 && got_frame) {
2361 if (*frame_size_ptr < data_size) {
2363 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2370 if (planar && avctx->
channels > 1) {
2372 for (ch = 1; ch < avctx->
channels; ch++) {
2377 *frame_size_ptr = data_size;
2379 *frame_size_ptr = 0;
2413 uint32_t discard_padding = 0;
2428 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
2431 if (ret >= 0 && *got_frame_ptr) {
2449 if(side && side_size>=10) {
2453 discard_padding =
AV_RL32(side + 4);
2484 if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) {
2503 avctx->internal->pkt = NULL;
2510 if (
ret >= 0 && *got_frame_ptr) {
2511 if (!avctx->refcounted_frames) {
2523 #define UTF8_MAX_BYTES 4
2528 iconv_t cd = (iconv_t)-1;
2557 outb = outpkt->
data;
2558 outl = outpkt->
size;
2560 if (iconv(cd, &inb, &inl, &outb, &outl) == (
size_t)-1 ||
2561 iconv(cd, NULL, NULL, &outb, &outl) == (
size_t)-1 ||
2562 outl >= outpkt->
size || inl != 0) {
2569 outpkt->
size -= outl;
2570 memset(outpkt->
data + outpkt->
size, 0, outl);
2573 if (cd != (iconv_t)-1)
2585 uint32_t codepoint,
min;
2589 GET_UTF8(codepoint, *(byte++),
return 0;);
2590 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2591 1 << (5 * (byte - str) - 4);
2592 if (codepoint < min || codepoint >= 0x110000 ||
2593 codepoint == 0xFFFE ||
2594 codepoint >= 0xD800 && codepoint <= 0xDFFF )
2647 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2661 "Invalid UTF-8 in decoded subtitles text; "
2662 "maybe missing -sub_charenc option\n");
2668 if (tmp.
data != pkt_recoded.
data) {
2722 if (CONFIG_FRAME_THREAD_ENCODER &&
2751 avctx->
codec = NULL;
2781 default :
return id;
2787 AVCodec *p, *experimental = NULL;
2800 return experimental;
2858 return "unknown_codec";
2865 #define TAG_PRINT(x) \
2866 (((x) >= '0' && (x) <= '9') || \
2867 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2868 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2870 for (i = 0; i < 4; i++) {
2872 TAG_PRINT(codec_tag & 0xFF) ?
"%c" :
"[%d]", codec_tag & 0xFF);
2874 buf_size = buf_size > len ? buf_size - len : 0;
2884 const char *codec_name;
2885 const char *profile = NULL;
2890 if (!buf || buf_size <= 0)
2904 snprintf(buf, buf_size,
"%s: %s", codec_type ? codec_type :
"unknown",
2906 buf[0] ^=
'a' ^
'A';
2912 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2916 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2917 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2923 char detail[256] =
"(";
2924 const char *colorspace_name;
2925 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2936 if (colorspace_name)
2937 av_strlcatf(detail,
sizeof(detail),
"%s, ", colorspace_name);
2939 if (strlen(detail) > 1) {
2940 detail[strlen(detail) - 2] = 0;
2945 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2953 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2954 " [SAR %d:%d DAR %d:%d]",
2956 display_aspect_ratio.
num, display_aspect_ratio.
den);
2960 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2966 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2967 ", q=%d-%d", enc->
qmin, enc->
qmax);
2972 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2978 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2983 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;
3370 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
3374 #if FF_API_MISSING_SAMPLE
3379 "version to the newest one from Git. If the problem still "
3380 "occurs, it means that your file has a feature which has not "
3381 "been implemented.\n", feature);
3388 va_list argument_list;
3390 va_start(argument_list, msg);
3395 "of this file to ftp://upload.ffmpeg.org/incoming/ "
3396 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
3398 va_end(argument_list);
3409 hwaccel->
next = NULL;
3412 last_hwaccel = &hwaccel->
next;
3446 entangled_thread_counter++;
3447 if (entangled_thread_counter != 1) {
3448 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
3450 av_log(log_ctx,
AV_LOG_ERROR,
"No lock manager is set, please see av_lockmgr_register()\n");
3451 ff_avcodec_locked = 1;
3456 ff_avcodec_locked = 1;
3463 ff_avcodec_locked = 0;
3464 entangled_thread_counter--;
3495 ((
unsigned)
av_toupper((x >> 24) & 0xFF) << 24);
3617 uint32_t *av_restrict
state)
3625 for (i = 0; i < 3; i++) {
3626 uint32_t tmp = *state << 8;
3627 *state = tmp + *(p++);
3628 if (tmp == 0x100 || p == end)
3633 if (p[-1] > 1 ) p += 3;
3634 else if (p[-2] ) p += 2;
3635 else if (p[-3]|(p[-1]-1)) p++;
3642 p =
FFMIN(p, end) - 4;