1 /*
2 * utils for libavcodec
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * utils.
26 */
27
28 #include "config.h"
47 #include <stdlib.h>
48 #include <stdarg.h>
49 #include <limits.h>
50 #include <float.h>
51 #if CONFIG_ICONV
52 # include <iconv.h>
53 #endif
54
60
62 {
63 if (min_size < *size)
64 return ptr;
65
66 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
67
69 /* we could set this to the unmodified min_size but this is safer
70 * if the user lost the ptr and uses NULL now
71 */
72 if (!ptr)
73 min_size = 0;
74
75 *size = min_size;
76
77 return ptr;
78 }
79
80 static inline int ff_fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
81 {
82 void **p = ptr;
83 if (min_size < *size)
84 return 0;
85 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
88 if (!*p)
89 min_size = 0;
90 *size = min_size;
91 return 1;
92 }
93
95 {
97 }
98
100 {
104 *size = 0;
105 return;
106 }
109 }
110
112 {
116 *size = 0;
117 return;
118 }
121 }
122
123 /* encoder management */
125
127 {
128 if (c)
130 else
132 }
133
135 {
136 static int initialized = 0;
137
138 if (initialized != 0)
139 return;
140 initialized = 1;
141
143 }
144
146 {
148 }
149
151 {
152 return codec && codec->
decode;
153 }
154
156 {
162 *p = codec;
164
167 }
168
170 {
172 }
173
175 {
180 }
181
182 #define INTERNAL_BUFFER_SIZE (32 + 1)
183
184 #if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
185 # define STRIDE_ALIGN 16
186 #else
187 # define STRIDE_ALIGN 8
188 #endif
189
192 {
193 int i;
194 int w_align = 1;
195 int h_align = 1;
196
247 w_align = 16; //FIXME assume 16 pixel per macroblock
248 h_align = 16 * 2; // interlaced needs 2 macroblocks height
249 break;
252 w_align = 32;
253 h_align = 8;
254 break;
257 w_align = 64;
258 h_align = 64;
259 }
260 break;
263 w_align = 4;
264 h_align = 4;
265 }
266 break;
272 w_align = 4;
273 h_align = 4;
274 }
275 break;
279 w_align = 4;
280 h_align = 4;
281 }
282 break;
285 w_align = 4;
286 h_align = 4;
287 }
288 break;
289 default:
290 w_align = 1;
291 h_align = 1;
292 break;
293 }
294
296 w_align =
FFMAX(w_align, 8);
297 }
298
299 *width =
FFALIGN(*width, w_align);
300 *height =
FFALIGN(*height, h_align);
302 // some of the optimized chroma MC reads one line too much
303 // which is also done in mpeg decoders with lowres > 0
304 *height += 2;
305
306 for (i = 0; i < 4; i++)
308 }
309
311 {
315 int align;
316
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);
323 }
324
327 int buf_size, int align)
328 {
329 int ch, planar, needed_size, ret = 0;
330
333 align);
334 if (buf_size < needed_size)
336
342 } else {
344 }
345
348 sample_fmt, align)) < 0) {
351 return ret;
352 }
356 }
357
358 return ret;
359 }
360
362 {
364 int buf_size, ret;
365
369 0);
370 if (buf_size < 0)
372
376
378 frame->
data[0], buf_size, 0);
379 if (ret < 0) {
381 return ret;
382 }
383
387 "internal audio buffer used\n", frame);
388
389 return 0;
390 }
391
393 {
394 int i;
399
402 return -1;
403 }
406 return -1;
407 }
408
411 return -1;
412 }
413
417 }
418
420
425 }
426 }
427
429 int h_chroma_shift, v_chroma_shift;
431 int tmpsize;
432 int unaligned;
437
439 &v_chroma_shift);
440
442
446 }
447
448 do {
449 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
450 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
452 // increase alignment of w for next try (rhs gives the lowest bit set in w)
453 w += w & ~(w - 1);
454
455 unaligned = 0;
456 for (i = 0; i < 4; i++)
457 unaligned |= picture.
linesize[i] % stride_align[i];
458 } while (unaligned);
459
461 if (tmpsize < 0)
462 return -1;
463
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]);
467
468 memset(buf->
base, 0,
sizeof(buf->
base));
469 memset(buf->
data, 0,
sizeof(buf->
data));
470
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;
474
476
480
481 // no edge if EDGE EMU or not planar YUV
484 else
486 }
490 }
491 if (size[1] && !size[2])
496 }
497
502 }
505
509
510 return 0;
511 }
512
514 {
517
519
522 int is_chroma = p == 1 || p == 2;
526 for (x = 0; x<bytes; x++)
527 ((uint16_t*)
dst)[x] = c[p];
528 }else
529 memset(dst, c[p], bytes);
531 }
532 }
533 }
534
536 {
543 default:
544 return -1;
545 }
546 }
547
549 {
555 } else {
560 }
562
569 break;
575 break;
576 }
577 }
578
580 {
582
584 }
585
587 {
588 int i;
591
593
596
598 buf =
NULL;
/* avoids warning */
599 for (i = 0; i < avci->
buffer_count; i++) {
//just 3-5 checks so is not worth to optimize
602 break;
603 }
607
608 if (buf != last)
610 }
611
614 // pic->base[i]=NULL;
615
619 }
620
622 {
624 int i, ret;
625
627
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",
632 }
633
635
636 /* If no picture return a new buffer */
638 /* We will copy from buffer, so must be readable */
641 }
642
644
645 /* If internal buffer type return the same buffer */
647 return 0;
648 }
649
650 /*
651 * Not internal type and reget_buffer not overridden, emulate cr buffer
652 */
653 temp_pic = *pic;
657 /* Allocate new frame */
659 return ret;
660 /* Copy image data from old buffer to new buffer */
664 return 0;
665 }
666
668 {
669 int i;
670
671 for (i = 0; i < count; i++) {
672 int r =
func(c, (
char *)arg + i * size);
673 if (ret)
675 }
676 return 0;
677 }
678
680 {
681 int i;
682
683 for (i = 0; i < count; i++) {
684 int r =
func(c, arg, i, 0);
685 if (ret)
687 }
688 return 0;
689 }
690
692 {
695 }
696
698 {
701 return fmt[0];
702 }
703
705 {
706 #if LIBAVCODEC_VERSION_MAJOR >= 55
707 // extended_data should explicitly be freed when needed, this code is unsafe currently
708 // also this is not compatible to the <55 ABI/API
711 #endif
712
713 memset(frame, 0,
sizeof(
AVFrame));
714
724 frame->
format = -1;
/* unknown */
726 }
727
729 {
731
734
737
739 }
740
742 {
744
745 if (!frame || !*frame)
746 return;
747
749
752
754 }
755
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; }
759
769
771
774
776 {
777 memset(sub, 0, sizeof(*sub));
779 }
780
782 {
783 int bit_rate;
784 int bits_per_sample;
785
792 break;
796 break;
797 default:
798 bit_rate = 0;
799 break;
800 }
801 return bit_rate;
802 }
803
804 #if FF_API_AVCODEC_OPEN
806 {
808 }
809 #endif
810
812 {
813 int ret = 0;
814
816
818
820 return ret;
821 }
822
824 {
825 int ret = 0;
827
829 return 0;
830
831 if ((!codec && !avctx->
codec)) {
834 }
835 if ((codec && avctx->
codec && codec != avctx->
codec)) {
837 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
839 }
840 if (!codec)
841 codec = avctx->
codec;
842
845
846 if (options)
848
850 if (ret < 0)
851 return ret;
852
857 }
858
865 }
869 }
870 }
872 goto free_and_end;
873 } else {
875 }
877 goto free_and_end;
878
879 //We only call avcodec_set_dimensions() for non h264 codecs so as not to overwrite previously setup dimensions
881
886 }
887
893 }
894
895 /* if the decoder init function was already called previously,
896 * free the already allocated subtitle_header before overwriting it */
899
902 goto free_and_end;
903 }
904
905 avctx->
codec = codec;
910 }
915 goto free_and_end;
916 }
919
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);
933 goto free_and_end;
934 }
935
940 }
941
942 if (!HAVE_THREADS)
943 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
944
945 if (HAVE_THREADS) {
946 ff_unlock_avcodec();
//we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
949 if (ret < 0)
950 goto free_and_end;
951 }
952
956 if (ret < 0) {
957 goto free_and_end;
958 }
959 }
962
964 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
967 goto free_and_end;
968 }
969
971 int i;
975 break;
980 break;
981 }
982 }
984 char buf[128];
986 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
989 goto free_and_end;
990 }
991 }
995 break;
999 char buf[128];
1001 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1004 goto free_and_end;
1005 }
1006 }
1010 break;
1015 goto free_and_end;
1016 }
1017 }
1021 } else {
1024 break;
1026 char buf[512];
1028 av_log(avctx,
AV_LOG_ERROR,
"Specified channel layout '%s' is not supported\n", buf);
1030 goto free_and_end;
1031 }
1032 }
1033 }
1037 char buf[512];
1040 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1043 goto free_and_end;
1044 }
1047 }
1050 ) {
1054 goto free_and_end;
1055 }
1056 }
1060 }
1061
1064 }
1065
1070
1074 if (ret < 0) {
1075 goto free_and_end;
1076 }
1077 }
1078
1079 ret=0;
1080
1084 /* validate channel layout from the decoder */
1089 else if (channels != avctx->
channels) {
1090 char buf[512];
1093 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1094 "ignoring specified channel layout\n",
1097 }
1098 }
1102 goto free_and_end;
1103 }
1107 "supported with subtitles codecs\n");
1109 goto free_and_end;
1112 "subtitles character encoding will be ignored\n",
1115 } else {
1116 /* input character encoding is set for a text based subtitle
1117 * codec at this point */
1120
1123 "conversion needs a libavcodec built with iconv support "
1124 "for this codec\n");
1126 goto free_and_end;
1127 }
1128 }
1129 }
1130 }
1133 if (options) {
1135 *options = tmp;
1136 }
1137
1138 return ret;
1139 free_and_end:
1145 }
1146
1148 {
1152 }
1153
1154 if (avctx) {
1156 if (!avpkt->
data || avpkt->
size < size) {
1161 }
1162 }
1163
1166
1167 if (avpkt->
size < size) {
1170 }
1171
1175 return 0;
1176 } else {
1178 if (ret < 0)
1180 return ret;
1181 }
1182 }
1183
1185 {
1187 }
1188
1189 /**
1190 * Pad last frame with silence.
1191 */
1193 {
1196 int ret;
1197
1200 *frame = *src;
1201
1204 goto fail;
1205
1208 goto fail;
1209 }
1210
1213 buf, ret, 0)) < 0)
1214 goto fail;
1217 goto fail;
1221 goto fail;
1222
1224
1225 return 0;
1226
1227 fail:
1232 return ret;
1233 }
1234
1238 int *got_packet_ptr)
1239 {
1242 int ret;
1244 int needs_realloc = !user_pkt.
data;
1245
1246 *got_packet_ptr = 0;
1247
1251 return 0;
1252 }
1253
1254 /* ensure that extended_data is properly set */
1259 "with more than %d channels, but extended_data is not set.\n",
1262 }
1264
1267 frame = &tmp;
1268 }
1269
1270 /* check for valid frame size */
1271 if (frame) {
1274 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1276 }
1281 if (ret < 0)
1282 return ret;
1283
1284 frame = padded_frame;
1286 }
1287
1292 }
1293 }
1294 }
1295
1296 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1297 if (!ret) {
1298 if (*got_packet_ptr) {
1305 }
1307 } else {
1309 }
1310 }
1312 needs_realloc = 0;
1313 if (user_pkt.
data) {
1314 if (user_pkt.
size >= avpkt->
size) {
1316 } else {
1319 ret = -1;
1320 }
1323 } else {
1326 }
1327 }
1328 }
1329
1330 if (!ret) {
1331 if (needs_realloc && avpkt->
data) {
1333 if (new_data)
1334 avpkt->
data = new_data;
1335 }
1336
1338 }
1339
1340 if (ret < 0 || !*got_packet_ptr) {
1344 }
1345
1346 /* NOTE: if we add any audio encoders which output non-keyframe packets,
1347 * this needs to be moved to the encoders, but for now we can do it
1348 * here to simplify things */
1350
1352 if (padded_frame) {
1357 }
1358
1359 return ret;
1360 }
1361
1362 #if FF_API_OLD_ENCODE_AUDIO
1366 {
1370 int ret, samples_size, got_packet;
1371
1374 pkt.
size = buf_size;
1375
1376 if (samples) {
1377 frame = &frame0;
1379
1382 } else {
1383 /* if frame_size is not set, the number of samples must be
1384 * calculated from the buffer size */
1388 "support this codec\n");
1390 }
1391 nb_samples = (int64_t)buf_size * 8 /
1394 if (nb_samples >= INT_MAX)
1397 }
1398
1399 /* it is assumed that the samples buffer is large enough based on the
1400 * relevant parameters */
1407 samples_size, 1)) < 0)
1408 return ret;
1409
1410 /* fabricate frame pts from sample count.
1411 * this is needed because the avcodec_encode_audio() API does not have
1412 * a way for the user to provide pts */
1416 else
1419 } else {
1421 }
1422
1423 got_packet = 0;
1428 }
1429 /* free any side data since we cannot return it */
1431
1434
1435 return ret ? ret : pkt.
size;
1436 }
1437
1438 #endif
1439
1440 #if FF_API_OLD_ENCODE_VIDEO
1443 {
1445 int ret, got_packet = 0;
1446
1449 return -1;
1450 }
1451
1454 pkt.
size = buf_size;
1455
1460 }
1461
1462 /* free any side data since we cannot return it */
1464 int i;
1469 }
1470
1471 return ret ? ret : pkt.
size;
1472 }
1473
1474 #endif
1475
1479 int *got_packet_ptr)
1480 {
1481 int ret;
1483 int needs_realloc = !user_pkt.
data;
1484
1485 *got_packet_ptr = 0;
1486
1489
1492
1497 return 0;
1498 }
1499
1502
1504
1505 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1507
1509 needs_realloc = 0;
1510 if (user_pkt.
data) {
1511 if (user_pkt.
size >= avpkt->
size) {
1513 } else {
1516 ret = -1;
1517 }
1520 } else {
1523 }
1524 }
1525 }
1526
1527 if (!ret) {
1528 if (!*got_packet_ptr)
1532
1533 if (needs_realloc && avpkt->
data &&
1536 if (new_data)
1537 avpkt->
data = new_data;
1538 }
1539
1541 }
1542
1543 if (ret < 0 || !*got_packet_ptr)
1545
1547 return ret;
1548 }
1549
1552 {
1553 int ret;
1556 return -1;
1557 }
1558
1561 return ret;
1562 }
1563
1564 /**
1565 * Attempt to guess proper monotonic timestamps for decoded video frames
1566 * which might have incorrect times. Input timestamps may wrap around, in
1567 * which case the output will as well.
1568 *
1569 * @param pts the pts field of the decoded AVPacket, as passed through
1570 * AVFrame.pkt_pts
1571 * @param dts the dts field of the decoded AVPacket
1572 * @return one of the input values, may be AV_NOPTS_VALUE
1573 */
1575 int64_t reordered_pts, int64_t dts)
1576 {
1578
1582 }
1586 }
1589 pts = reordered_pts;
1590 else
1591 pts = dts;
1592
1593 return pts;
1594 }
1595
1597 {
1601
1603 return;
1604
1606 if (!data || size < 4)
1607 return;
1608 flags = bytestream_get_le32(&data);
1609 size -= 4;
1610 if (size < 4) /* Required for any of the changes */
1611 return;
1613 avctx->
channels = bytestream_get_le32(&data);
1614 size -= 4;
1615 }
1617 if (size < 8)
1618 return;
1620 size -= 8;
1621 }
1622 if (size < 4)
1623 return;
1626 size -= 4;
1627 }
1629 if (size < 8)
1630 return;
1631 avctx->
width = bytestream_get_le32(&data);
1632 avctx->
height = bytestream_get_le32(&data);
1634 size -= 8;
1635 }
1636 }
1637
1639 {
1643
1647 if (!side_metadata)
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;
1654 if (ret < 0)
1655 break;
1656 side_metadata = val + strlen(val) + 1;
1657 }
1658 end:
1660 return ret;
1661 }
1662
1664 int *got_picture_ptr,
1666 {
1667 int ret;
1668 // copy to ensure we do not change avpkt
1670
1674 }
1675
1676 *got_picture_ptr = 0;
1679
1681
1688 &tmp);
1689 else {
1690 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
1691 &tmp);
1693
1696 }
1697 //FIXME these should be under if(!avctx->has_b_frames)
1698 /* get_buffer is supposed to set frame parameters */
1704 }
1705 }
1707
1708 emms_c();
//needed to avoid an emms_c() call before every return;
1709
1711 if (did_split) {
1715 }
1716
1717 if (*got_picture_ptr){
1723 }
1724 } else
1725 ret = 0;
1726
1727 /* many decoders assign whole AVFrames, thus overwriting extended_data;
1728 * make sure it's set correctly */
1730
1731 return ret;
1732 }
1733
1734 #if FF_API_OLD_DECODE_AUDIO
1736 int *frame_size_ptr,
1738 {
1740 int ret, got_frame = 0;
1741
1744 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1746 "avcodec_decode_audio4()\n");
1749 }
1750
1752
1753 if (ret >= 0 && got_frame) {
1754 int ch, plane_size;
1759 if (*frame_size_ptr < data_size) {
1761 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1763 }
1764
1766
1767 if (planar && avctx->
channels > 1) {
1769 for (ch = 1; ch < avctx->
channels; ch++) {
1771 out += plane_size;
1772 }
1773 }
1774 *frame_size_ptr = data_size;
1775 } else {
1776 *frame_size_ptr = 0;
1777 }
1778 return ret;
1779 }
1780
1781 #endif
1782
1785 int *got_frame_ptr,
1787 {
1788 int planar, channels;
1789 int ret = 0;
1790
1791 *got_frame_ptr = 0;
1792
1796 }
1800 }
1801
1803
1806 int side_size;
1807 // copy to ensure we do not change avpkt
1811
1813 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
1814 if (ret >= 0 && *got_frame_ptr) {
1829 }
1831
1833 if(side && side_size>=10) {
1837 }
1840 *got_frame_ptr = 0;
1844 } else {
1857 } else {
1859 }
1864 }
1865 }
1866
1868 if (did_split) {
1870 if(ret == tmp.size)
1872 }
1873 }
1874
1875 /* many decoders assign whole AVFrames, thus overwriting extended_data;
1876 * make sure it's set correctly; assume decoders that actually use
1877 * extended_data are doing it correctly */
1878 if (*got_frame_ptr) {
1883 } else {
1885 }
1886
1887 return ret;
1888 }
1889
1890 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
1893 {
1894 #if CONFIG_ICONV
1895 iconv_t cd = (iconv_t)-1;
1896 int ret = 0;
1897 char *inb, *outb;
1898 size_t inl, outl;
1900 #endif
1901
1903 return 0;
1904
1905 #if CONFIG_ICONV
1907 if (cd == (iconv_t)-1) {
1909 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
1912 }
1913
1916
1921 }
1922
1924 if (ret < 0)
1928 outb = outpkt->
data;
1929 outl = outpkt->
size;
1930
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) {
1939 }
1940 outpkt->
size -= outl;
1941 memset(outpkt->
data + outpkt->
size, 0, outl);
1942
1944 if (cd != (iconv_t)-1)
1945 iconv_close(cd);
1946 return ret;
1947 #else
1948 av_assert0(!
"requesting subtitles recoding without iconv");
1949 #endif
1950 }
1951
1953 int *got_sub_ptr,
1955 {
1956 int ret = 0;
1957
1961 }
1962
1963 *got_sub_ptr = 0;
1965
1970 //apply_param_change(avctx, &tmp);
1971
1972 pkt_recoded = tmp;
1974 if (ret < 0) {
1975 *got_sub_ptr = 0;
1976 } else {
1977 avctx->
pkt = &pkt_recoded;
1978
1982 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &pkt_recoded);
1989 }
1990
1991 if (did_split) {
1995 }
1996
1997 if (*got_sub_ptr)
1999 }
2000
2001 return ret;
2002 }
2003
2005 {
2006 int i;
2007
2016 }
2017
2019
2021 }
2022
2024 {
2025 int ret = 0;
2026
2028
2030
2032 return ret;
2033 }
2034
2036 {
2038 if (ret < 0)
2039 return ret;
2040
2046 }
2057 }
2058
2067
2069 return 0;
2070 }
2071
2073 {
2074 switch(id){
2075 //This is for future deprecatec codec ids, its empty since
2076 //last major bump but will fill up again over time, please don't remove it
2077 // case AV_CODEC_ID_UTVIDEO_DEPRECATED: return AV_CODEC_ID_UTVIDEO;
2080 default :
return id;
2081 }
2082 }
2083
2085 {
2089 while (p) {
2093 experimental = p;
2094 } else
2095 return p;
2096 }
2098 }
2099 return experimental;
2100 }
2101
2103 {
2105 }
2106
2108 {
2110 if (!name)
2113 while (p) {
2115 return p;
2117 }
2119 }
2120
2122 {
2124 }
2125
2127 {
2129 if (!name)
2132 while (p) {
2134 return p;
2136 }
2138 }
2139
2141 {
2144
2146 return "none";
2148 if (cd)
2152 if (codec)
2155 if (codec)
2157 return "unknown_codec";
2158 }
2159
2161 {
2162 int i,
len, ret = 0;
2163
2164 #define TAG_PRINT(x) \
2165 (((x) >= '0' && (x) <= '9') || \
2166 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2167 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2168
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;
2175 codec_tag >>= 8;
2176 }
2177 return ret;
2178 }
2179
2181 {
2183 const char *codec_name;
2184 const char *profile =
NULL;
2186 int bitrate;
2188
2189 if (!buf || buf_size <= 0)
2190 return;
2196 else
2199 if (p)
2201 }
2202
2203 snprintf(buf, buf_size,
"%s: %s%s", codec_type ? codec_type :
"unknown",
2205 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
2206 if (profile)
2207 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2209 char tag_buf[32];
2211 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2212 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2213 }
2214
2218 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2219 ", %s",
2223 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2225 }
2227 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2228 ", %dx%d",
2234 1024 * 1024);
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);
2239 }
2242 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2243 ", %d/%d",
2245 }
2246 }
2247 if (encode) {
2248 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2249 ", q=%d-%d", enc->
qmin, enc->
qmax);
2250 }
2251 break;
2254 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2256 }
2260 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2262 }
2263 break;
2267 if (g)
2268 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2269 ", %d/%d",
2271 }
2272 break;
2273 default:
2274 return;
2275 }
2276 if (encode) {
2278 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2279 ", pass 1");
2281 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2282 ", pass 2");
2283 }
2285 if (bitrate != 0) {
2286 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2287 ", %d kb/s", bitrate / 1000);
2288 }
2289 }
2290
2292 {
2296
2300
2302 }
2303
2305 {
2306 // av_assert0(AV_CODEC_ID_V410==164);
2309 // av_assert0(AV_CODEC_ID_BMV_AUDIO==86071);
2312
2314 }
2315
2317 {
2318 return FFMPEG_CONFIGURATION;
2319 }
2320
2322 {
2323 #define LICENSE_PREFIX "libavcodec license: "
2325 }
2326
2328 {
2333
2336 }
2337
2339 {
2341 int i, j;
2342
2344 return;
2345
2351 for (j = 0; j < 4; j++) {
2354 }
2355 }
2357
2359 }
2360
2362 {
2365 }
2366
2368 {
2372 break;
2375 break;
2376 default:
2377 break;
2378 }
2379 }
2380
2382 {
2383 switch (codec_id) {
2393 return 4;
2400 return 8;
2407 return 16;
2414 return 24;
2422 return 32;
2425 return 64;
2426 default:
2427 return 0;
2428 }
2429 }
2430
2432 {
2444 };
2447 if (be < 0 || be > 1)
2449 return map[
fmt][be];
2450 }
2451
2453 {
2454 switch (codec_id) {
2456 return 2;
2458 return 3;
2464 return 4;
2465 default:
2467 }
2468 }
2469
2471 {
2473
2480
2481 /* codecs with an exact constant bits per sample */
2482 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2483 return (frame_bytes * 8LL) / (bps * ch);
2485
2486 /* codecs with a fixed packet duration */
2487 switch (id) {
2504 }
2505
2506 if (sr > 0) {
2507 /* calc from sample rate */
2509 return 256 * sr / 245;
2510
2511 if (ch > 0) {
2512 /* calc from sample rate and channels */
2514 return (480 << (sr / 22050)) / ch;
2515 }
2516 }
2517
2518 if (ba > 0) {
2519 /* calc from block_align */
2521 switch (ba) {
2522 case 20: return 160;
2523 case 19: return 144;
2524 case 29: return 288;
2525 case 37: return 480;
2526 }
2528 switch (ba) {
2529 case 38: return 160;
2530 case 50: return 240;
2531 }
2532 }
2533 }
2534
2535 if (frame_bytes > 0) {
2536 /* calc from frame_bytes only */
2538 return 240 * (frame_bytes / 32);
2540 return 256 * (frame_bytes / 64);
2542 return 160 * (frame_bytes / 20);
2544 return 240 * (frame_bytes / 24);
2545
2546 if (bps > 0) {
2547 /* calc from frame_bytes and bits_per_coded_sample */
2549 return frame_bytes * 8 /
bps;
2550 }
2551
2552 if (ch > 0) {
2553 /* calc from frame_bytes and channels */
2554 switch (id) {
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;
2581 }
2582
2583 if (tag) {
2584 /* calc from frame_bytes, channels, and codec_tag */
2586 if (tag == 3)
2587 return frame_bytes / ch;
2588 else
2589 return frame_bytes * 2 / ch;
2590 }
2591 }
2592
2593 if (ba > 0) {
2594 /* calc from frame_bytes, channels, and block_align */
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);
2605 }
2606 }
2607
2608 if (bps > 0) {
2609 /* calc from frame_bytes, channels, and bits_per_coded_sample */
2612 if(bps<4)
2613 return 0;
2614 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2616 if(bps<4)
2617 return 0;
2618 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
2620 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2621 }
2622 }
2623 }
2624 }
2625
2626 return 0;
2627 }
2628
2629 #if !HAVE_THREADS
2631 {
2632 return -1;
2633 }
2634
2635 #endif
2636
2638 {
2639 unsigned int n = 0;
2640
2641 while (v >= 0xff) {
2642 *s++ = 0xff;
2643 v -= 0xff;
2644 n++;
2645 }
2647 n++;
2648 return n;
2649 }
2650
2652 {
2653 int i;
2654 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
2655 return i;
2656 }
2657
2659 {
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);
2664 if(want_sample)
2666 }
2667
2669 {
2670 va_list argument_list;
2671
2672 va_start(argument_list, msg);
2673
2674 if (msg)
2677 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
2678 "and contact the ffmpeg-devel mailing list.\n");
2679
2680 va_end(argument_list);
2681 }
2682
2684
2686 {
2688 while (*p)
2690 *p = hwaccel;
2692 }
2693
2695 {
2697 }
2698
2700 {
2702
2704 if (hwaccel->
id == codec_id
2705 && hwaccel->
pix_fmt == pix_fmt)
2706 return hwaccel;
2708 }
2709
2711 {
2714 return -1;
2716 return -1;
2717 }
2718
2720
2723 return -1;
2725 return -1;
2726 }
2727 return 0;
2728 }
2729
2731 {
2734 return -1;
2735 }
2738 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
2742 }
2745 return 0;
2746 }
2747
2749 {
2755 return -1;
2756 }
2757 return 0;
2758 }
2759
2761 {
2764 return -1;
2765 }
2766 return 0;
2767 }
2768
2770 {
2773 return -1;
2774 }
2775 return 0;
2776 }
2777
2779 {
2784 }
2785
2786 #if !HAVE_THREADS
2787
2789 {
2791
2793 }
2794
2796 {
2798 }
2799
2801 {
2802 }
2803
2805 {
2806 }
2807
2809 {
2810 }
2811
2813 {
2814 return 1;
2815 }
2816
2817 #endif
2818
2820 {
2822 if(!c)
2824 if(c)
2826
2835
2837 }
2838
2840 {
2842 }
2843
2845 {
2846 int ret;
2847 char *str;
2848
2850 if (ret < 0)
2851 return ret;
2853 /* Note: the string is NUL terminated (so extradata can be read as a
2854 * string), but the ending character is not accounted in the size (in
2855 * binary formats you are likely not supposed to mux that character). When
2856 * extradata is copied, it is also padded with FF_INPUT_BUFFER_PADDING_SIZE
2857 * zeros. */
2859 return 0;
2860 }