1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450
|
/*
Copyright (C) 2018, Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2000, 2004-2005 Herbert Valerio Riedel <hvr@gnu.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define _VCD_INFO_PRIVATE_H
/* We don't want to pull in cdio's config */
#define __CDIO_CONFIG_H__
#include <cdio/cdio.h>
#include <cdio/util.h>
#include <cdio/iso9660.h>
/* public headers */
#include <libvcd/types.h>
#include <libvcd/info.h>
#include <libvcd/files.h>
#include <libvcd/sector.h>
#include <libvcd/logging.h>
/* Private headers */
#include "assert.h"
#include "dict.h"
#include "directory.h"
#include "obj.h"
#include "pbc.h"
#include "salloc.h"
#include "util.h"
#include "vcd.h"
static const char zero[CDIO_CD_FRAMESIZE_RAW] = { 0, };
#define DEFAULT_ISO_PREPARER_ID "GNU VCDImager " VERSION " " HOST_ARCH
static void sequence_free(mpeg_sequence_t *data)
{
if (data != NULL) free(data);
}
static void dict_free(struct _dict_t *data)
{
if (data != NULL) free(data);
}
static void cue_data_free(vcd_cue_t *data)
{
if (data != NULL) free(data);
}
/* exported private functions
*/
mpeg_sequence_t *
_vcd_obj_get_sequence_by_id (VcdObj_t *p_obj, const char sequence_id[])
{
CdioListNode_t *node;
vcd_assert (sequence_id != NULL);
vcd_assert (p_obj != NULL);
_CDIO_LIST_FOREACH (node, p_obj->mpeg_sequence_list)
{
mpeg_sequence_t *_sequence = _cdio_list_node_data (node);
if (_sequence->id && !strcmp (sequence_id, _sequence->id))
return _sequence;
}
return NULL;
}
mpeg_sequence_t *
_vcd_obj_get_sequence_by_entry_id (VcdObj_t *p_obj, const char entry_id[])
{
CdioListNode_t *node;
vcd_assert (entry_id != NULL);
vcd_assert (p_obj != NULL);
_CDIO_LIST_FOREACH (node, p_obj->mpeg_sequence_list)
{
mpeg_sequence_t *_sequence = _cdio_list_node_data (node);
CdioListNode_t *node2;
/* default entry point */
if (_sequence->default_entry_id
&& !strcmp (entry_id, _sequence->default_entry_id))
return _sequence;
/* additional entry points */
_CDIO_LIST_FOREACH (node2, _sequence->entry_list)
{
entry_t *_entry = _cdio_list_node_data (node2);
if (_entry->id
&& !strcmp (entry_id, _entry->id))
return _sequence;
}
}
/* not found */
return NULL;
}
mpeg_segment_t *
_vcd_obj_get_segment_by_id (VcdObj_t *p_obj, const char segment_id[])
{
CdioListNode_t *node;
vcd_assert (segment_id != NULL);
vcd_assert (p_obj != NULL);
_CDIO_LIST_FOREACH (node, p_obj->mpeg_segment_list)
{
mpeg_segment_t *_segment = _cdio_list_node_data (node);
if (_segment->id && !strcmp (segment_id, _segment->id))
return _segment;
}
return NULL;
}
bool
_vcd_obj_has_cap_p (const VcdObj_t *p_obj, enum vcd_capability_t capability)
{
switch (capability)
{
case _CAP_VALID:
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_VCD2:
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
return true;
break;
case VCD_TYPE_INVALID:
return false;
break;
}
break;
case _CAP_MPEG2:
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_VCD2:
case VCD_TYPE_INVALID:
return false;
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
return true;
break;
}
break;
case _CAP_PBC:
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_INVALID:
return false;
break;
case VCD_TYPE_VCD2:
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
return true;
break;
}
break;
case _CAP_PBC_X:
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_INVALID:
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
return false;
break;
case VCD_TYPE_VCD2:
return true;
break;
}
break;
case _CAP_4C_SVCD:
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_INVALID:
case VCD_TYPE_VCD2:
return false;
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
return true;
break;
}
break;
case _CAP_PAL_BITS:
return _vcd_obj_has_cap_p (p_obj, _CAP_PBC); /* for now */
break;
case _CAP_MPEG1:
return !_vcd_obj_has_cap_p (p_obj, _CAP_MPEG2); /* for now */
break;
case _CAP_TRACK_MARGINS:
return !_vcd_obj_has_cap_p (p_obj, _CAP_MPEG2); /* for now */
break;
}
vcd_assert_not_reached ();
return false;
}
/*
* public methods
*/
VcdObj_t *
vcd_obj_new (vcd_type_t vcd_type)
{
VcdObj_t *p_new_obj = NULL;
static bool _first = true;
if (_first)
{
#if defined(_DEVELOPMENT_)
vcd_warn ("initializing libvcd %s [%s]", VERSION, HOST_ARCH);
vcd_warn (" ");
vcd_warn (" this is the Beta development branch!");
vcd_warn (" use only if you know what you are doing");
vcd_warn (" see http://www.hvrlab.org/~hvr/vcdimager/ for more information");
vcd_warn (" ");
#else
vcd_debug ("initializing libvcd %s [%s]", VERSION, HOST_ARCH);
#endif
_first = false;
}
p_new_obj = calloc(1, sizeof (VcdObj_t));
p_new_obj->type = vcd_type;
if (!_vcd_obj_has_cap_p (p_new_obj, _CAP_VALID))
{
vcd_error ("VCD type not supported");
free (p_new_obj);
return NULL;
}
if (vcd_type == VCD_TYPE_VCD)
vcd_warn ("VCD 1.0 support is experimental -- user feedback needed!");
p_new_obj->iso_volume_label = strdup ("");
p_new_obj->iso_publisher_id = strdup ("");
p_new_obj->iso_application_id = strdup ("");
p_new_obj->iso_preparer_id = _vcd_strdup_upper (DEFAULT_ISO_PREPARER_ID);
p_new_obj->info_album_id = strdup ("");
p_new_obj->info_volume_count = 1;
p_new_obj->info_volume_number = 1;
p_new_obj->custom_file_list = _cdio_list_new ();
p_new_obj->custom_dir_list = _cdio_list_new ();
p_new_obj->mpeg_sequence_list = _cdio_list_new ();
p_new_obj->mpeg_segment_list = _cdio_list_new ();
p_new_obj->pbc_list = _cdio_list_new ();
/* gap's defined by IEC-10149 / ECMA-130 */
/* pre-gap's for tracks but the first one */
p_new_obj->track_pregap = CDIO_PREGAP_SECTORS;
/* post-gap after last track */
p_new_obj->leadout_pregap = CDIO_POSTGAP_SECTORS;
if (_vcd_obj_has_cap_p (p_new_obj, _CAP_TRACK_MARGINS))
{
p_new_obj->track_front_margin = 30;
p_new_obj->track_rear_margin = 45;
}
else
{
p_new_obj->track_front_margin = 0;
p_new_obj->track_rear_margin = 0;
}
return p_new_obj;
}
int
vcd_obj_remove_item (VcdObj_t *p_vcdobj, const char id[])
{
vcd_warn ("vcd_obj_remove_item('%s') not implemented yet!", id);
return -1;
}
static void
_vcd_obj_remove_mpeg_track (VcdObj_t *p_vcdobj, int track_id)
{
int length;
mpeg_sequence_t *track = NULL;
CdioListNode_t *node = NULL;
vcd_assert (track_id >= 0);
node = _vcd_list_at (p_vcdobj->mpeg_sequence_list, track_id);
vcd_assert (node != NULL);
track = (mpeg_sequence_t *) _cdio_list_node_data (node);
vcd_mpeg_source_destroy (track->source, true);
length = track->info ? track->info->packets : 0;
length += p_vcdobj->track_pregap + p_vcdobj->track_front_margin
+ 0 + p_vcdobj->track_rear_margin;
/* fixup offsets */
{
CdioListNode_t *node2 = node;
while ((node2 = _cdio_list_node_next (node2)) != NULL)
((mpeg_sequence_t *) _cdio_list_node_data (node))->relative_start_extent
-= length;
}
p_vcdobj->relative_end_extent -= length;
/* shift up */
_cdio_list_node_free (node, true, NULL);
}
int
vcd_obj_append_segment_play_item (VcdObj_t *p_vcdobj,
VcdMpegSource_t *p_mpeg_source,
const char item_id[])
{
mpeg_segment_t *segment = NULL;
vcd_assert (p_vcdobj != NULL);
vcd_assert (p_mpeg_source != NULL);
if (!_vcd_obj_has_cap_p (p_vcdobj, _CAP_PBC))
{
vcd_error ("segment play items not supported for this vcd type");
return -1;
}
if (!item_id)
{
vcd_error ("no id given for segment play item");
return -1;
}
if (_vcd_pbc_lookup (p_vcdobj, item_id))
{
vcd_error ("item id (%s) exists already", item_id);
return -1;
}
vcd_info ("scanning mpeg segment item #%d for scanpoints...",
_cdio_list_length (p_vcdobj->mpeg_segment_list));
vcd_mpeg_source_scan (p_mpeg_source, !p_vcdobj->relaxed_aps,
p_vcdobj->update_scan_offsets, NULL, NULL);
if (vcd_mpeg_source_get_info (p_mpeg_source)->packets == 0)
{
vcd_error ("mpeg is empty?");
return -1;
}
/* create list node */
segment = calloc(1, sizeof (mpeg_sequence_t));
segment->source = p_mpeg_source;
segment->id = strdup (item_id);
segment->info = vcd_mpeg_source_get_info (p_mpeg_source);
segment->segment_count = _vcd_len2blocks (segment->info->packets, 150);
segment->pause_list = _cdio_list_new ();
vcd_debug ("SPI length is %d sector(s), allocated %d segment(s)",
segment->info->packets,
segment->segment_count);
_cdio_list_append (p_vcdobj->mpeg_segment_list, segment);
return 0;
}
int
vcd_obj_append_sequence_play_item (VcdObj_t *p_vcdobj,
VcdMpegSource_t *p_mpeg_source,
const char item_id[],
const char default_entry_id[])
{
unsigned length;
mpeg_sequence_t *sequence = NULL;
int track_no = _cdio_list_length (p_vcdobj->mpeg_sequence_list);
vcd_assert (p_vcdobj != NULL);
vcd_assert (p_mpeg_source != NULL);
if (item_id && _vcd_pbc_lookup (p_vcdobj, item_id))
{
vcd_error ("item id (%s) exist already", item_id);
return -1;
}
if (default_entry_id && _vcd_pbc_lookup (p_vcdobj, default_entry_id))
{
vcd_error ("default entry id (%s) exist already", default_entry_id);
return -1;
}
if (default_entry_id && item_id && !strcmp (item_id, default_entry_id))
{
vcd_error ("default entry id == item id (%s)", item_id);
return -1;
}
vcd_info ("scanning mpeg sequence item #%d for scanpoints...", track_no);
vcd_mpeg_source_scan (p_mpeg_source, !p_vcdobj->relaxed_aps,
p_vcdobj->update_scan_offsets, NULL, NULL);
sequence = calloc(1, sizeof (mpeg_sequence_t));
sequence->source = p_mpeg_source;
if (item_id)
sequence->id = strdup (item_id);
if (default_entry_id)
sequence->default_entry_id = strdup (default_entry_id);
sequence->info = vcd_mpeg_source_get_info (p_mpeg_source);
length = sequence->info->packets;
sequence->entry_list = _cdio_list_new ();
sequence->pause_list = _cdio_list_new ();
p_vcdobj->relative_end_extent += p_vcdobj->track_pregap;
sequence->relative_start_extent = p_vcdobj->relative_end_extent;
p_vcdobj->relative_end_extent += p_vcdobj->track_front_margin + length
+ p_vcdobj->track_rear_margin;
/* sanity checks */
if (length < 75)
vcd_warn ("mpeg stream shorter than 75 sectors");
if (!_vcd_obj_has_cap_p (p_vcdobj, _CAP_PAL_BITS)
&& vcd_mpeg_get_norm (&sequence->info->shdr[0]) != MPEG_NORM_FILM
&& vcd_mpeg_get_norm (&sequence->info->shdr[0]) != MPEG_NORM_NTSC)
vcd_warn ("VCD 1.x should contain only NTSC/FILM video (may work with PAL nevertheless)");
if (!_vcd_obj_has_cap_p (p_vcdobj, _CAP_MPEG1)
&& sequence->info->version == MPEG_VERS_MPEG1)
vcd_warn ("this VCD type should not contain MPEG1 streams");
if (!_vcd_obj_has_cap_p (p_vcdobj, _CAP_MPEG2)
&& sequence->info->version == MPEG_VERS_MPEG2)
vcd_warn ("this VCD type should not contain MPEG2 streams");
if (!sequence->info->shdr[0].seen
|| sequence->info->shdr[1].seen
|| sequence->info->shdr[2].seen)
vcd_warn ("sequence items should contain a motion video stream!");
{
int i;
for (i = 0; i < 3; i++)
{
if (sequence->info->ahdr[i].seen)
{
if (i && !_vcd_obj_has_cap_p (p_vcdobj, _CAP_MPEG2))
vcd_warn ("audio stream #%d not supported by this VCD type", i);
if (sequence->info->ahdr[i].sampfreq != 44100)
vcd_warn ("audio stream #%d has sampling frequency %d Hz (should be 44100 Hz)",
i, sequence->info->ahdr[i].sampfreq);
if (sequence->info->ahdr[i].layer != 2)
vcd_warn ("audio stream #%d is not layer II", i);
if (_vcd_obj_has_cap_p (p_vcdobj, _CAP_MPEG1)
&& sequence->info->ahdr[i].bitrate != 224*1024)
vcd_warn ("audio stream #%d has bitrate %d kbps (should be 224 kbps for this vcd type)",
i, sequence->info->ahdr[i].bitrate);
}
else if (!i && !_vcd_obj_has_cap_p (p_vcdobj, _CAP_MPEG2))
{
vcd_warn ("this VCD type requires an audio stream to be present");
}
}
}
/* vcd_debug ("track# %d's detected playing time: %.2f seconds", */
/* track_no, sequence->info->playing_time); */
_cdio_list_append (p_vcdobj->mpeg_sequence_list, sequence);
return track_no;
}
static int
_pause_cmp (pause_t *ent1, pause_t *ent2)
{
if (ent1->time < ent2->time)
return -1;
if (ent1->time > ent2->time)
return 1;
return 0;
}
int
vcd_obj_add_sequence_pause (VcdObj_t *obj, const char sequence_id[],
double pause_time, const char pause_id[])
{
mpeg_sequence_t *p_sequence;
vcd_assert (obj != NULL);
if (sequence_id)
p_sequence = _vcd_obj_get_sequence_by_id (obj, sequence_id);
else
p_sequence =
_cdio_list_node_data (_cdio_list_end (obj->mpeg_sequence_list));
if (!p_sequence)
{
vcd_error ("sequence id `%s' not found", sequence_id);
return -1;
}
if (pause_id)
vcd_warn ("pause id ignored...");
{
pause_t *_pause = calloc(1, sizeof (pause_t));
if (pause_id)
_pause->id = strdup (pause_id);
_pause->time = pause_time;
_cdio_list_append (p_sequence->pause_list, _pause);
}
_vcd_list_sort (p_sequence->pause_list,
(_cdio_list_cmp_func_t) _pause_cmp);
vcd_debug ("added autopause point at %f", pause_time);
return 0;
}
int
vcd_obj_add_segment_pause (VcdObj_t *p_obj, const char segment_id[],
double pause_time, const char pause_id[])
{
mpeg_segment_t *_segment;
vcd_assert (p_obj != NULL);
if (segment_id)
_segment = _vcd_obj_get_segment_by_id (p_obj, segment_id);
else
_segment = _cdio_list_node_data (_cdio_list_end (p_obj->mpeg_segment_list));
if (!_segment)
{
vcd_error ("segment id `%s' not found", segment_id);
return -1;
}
if (pause_id)
vcd_warn ("pause id ignored...");
{
pause_t *_pause = calloc(1, sizeof (pause_t));
if (pause_id)
_pause->id = strdup (pause_id);
_pause->time = pause_time;
_cdio_list_append (_segment->pause_list, _pause);
}
_vcd_list_sort (_segment->pause_list,
(_cdio_list_cmp_func_t) _pause_cmp);
vcd_debug ("added autopause point at %f", pause_time);
return 0;
}
static int
_entry_cmp (entry_t *p_ent1, entry_t *p_ent2)
{
if (p_ent1->time < p_ent2->time)
return -1;
if (p_ent1->time > p_ent2->time)
return 1;
return 0;
}
int
vcd_obj_add_sequence_entry (VcdObj_t *p_obj, const char sequence_id[],
double entry_time, const char entry_id[])
{
mpeg_sequence_t *p_sequence;
vcd_assert (p_obj != NULL);
if (sequence_id)
p_sequence = _vcd_obj_get_sequence_by_id (p_obj, sequence_id);
else
p_sequence =
_cdio_list_node_data (_cdio_list_end (p_obj->mpeg_sequence_list));
if (!p_sequence)
{
vcd_error ("sequence id `%s' not found", sequence_id);
return -1;
}
if (_cdio_list_length (p_sequence->entry_list) >= MAX_SEQ_ENTRIES)
{
vcd_error ("only %d entries per sequence allowed!", MAX_SEQ_ENTRIES);
return -1;
}
if (entry_id && _vcd_pbc_lookup (p_obj, entry_id))
{
vcd_error ("item id (%s) exists already", entry_id);
return -1;
}
{
entry_t *_entry = calloc(1, sizeof (entry_t));
if (entry_id)
_entry->id = strdup (entry_id);
_entry->time = entry_time;
_cdio_list_append (p_sequence->entry_list, _entry);
}
_vcd_list_sort (p_sequence->entry_list,
(_cdio_list_cmp_func_t) _entry_cmp);
return 0;
}
void
vcd_obj_destroy (VcdObj_t *p_obj)
{
CdioListNode_t *p_node;
vcd_assert (p_obj != NULL);
vcd_assert (!p_obj->in_output);
free (p_obj->iso_volume_label);
free (p_obj->iso_application_id);
_CDIO_LIST_FOREACH (p_node, p_obj->custom_file_list)
{
custom_file_t *p = _cdio_list_node_data (p_node);
free (p->iso_pathname);
}
_cdio_list_free (p_obj->custom_file_list, true, NULL);
_cdio_list_free (p_obj->custom_dir_list, true, NULL);
while (_cdio_list_length (p_obj->mpeg_sequence_list))
_vcd_obj_remove_mpeg_track (p_obj, 0);
_cdio_list_free (p_obj->mpeg_sequence_list, true, (CdioDataFree_t) &sequence_free);
free (p_obj);
}
int
vcd_obj_set_param_uint (VcdObj_t *p_obj, vcd_parm_t param, unsigned arg)
{
vcd_assert (p_obj != NULL);
switch (param)
{
case VCD_PARM_VOLUME_COUNT:
p_obj->info_volume_count = arg;
if (!IN (p_obj->info_volume_count, 1, 65535))
{
p_obj->info_volume_count =
CLAMP (p_obj->info_volume_count, 1, 65535);
vcd_warn ("volume count out of range, clamping to range");
}
vcd_debug ("changed volume count to %u", p_obj->info_volume_count);
break;
case VCD_PARM_VOLUME_NUMBER:
p_obj->info_volume_number = arg;
if (!IN (p_obj->info_volume_number, 0, 65534))
{
p_obj->info_volume_number =
CLAMP (p_obj->info_volume_number, 0, 65534);
vcd_warn ("volume number out of range, clamping to range");
}
vcd_debug ("changed volume number to %u", p_obj->info_volume_number);
break;
case VCD_PARM_RESTRICTION:
p_obj->info_restriction = arg;
if (!IN (p_obj->info_restriction, 0, 3))
{
p_obj->info_restriction = CLAMP (p_obj->info_restriction, 0, 65534);
vcd_warn ("restriction out of range, clamping to range");
}
vcd_debug ("changed restriction number to %u", p_obj->info_restriction);
break;
case VCD_PARM_LEADOUT_PREGAP:
p_obj->leadout_pregap = arg;
if (!IN (p_obj->leadout_pregap, 0, 300))
{
p_obj->leadout_pregap = CLAMP (p_obj->leadout_pregap, 0, 300);
vcd_warn ("ledout pregap out of range, clamping to allowed range");
}
if (p_obj->leadout_pregap < CDIO_PREGAP_SECTORS)
vcd_warn ("track leadout pregap set below %d sectors; "
"created (S)VCD may be non-working",
CDIO_PREGAP_SECTORS);
vcd_debug ("changed leadout pregap to %u", p_obj->leadout_pregap);
break;
case VCD_PARM_TRACK_PREGAP:
p_obj->track_pregap = arg;
if (!IN (p_obj->track_pregap, 1, 300))
{
p_obj->track_pregap = CLAMP (p_obj->track_pregap, 1, 300);
vcd_warn ("track pregap out of range, clamping to allowed range");
}
if (p_obj->track_pregap < CDIO_PREGAP_SECTORS)
vcd_warn ("track pre gap set below %d sectors; "
"created (S)VCD may be non-working",
CDIO_PREGAP_SECTORS);
vcd_debug ("changed track pregap to %u", p_obj->track_pregap);
break;
case VCD_PARM_TRACK_FRONT_MARGIN:
p_obj->track_front_margin = arg;
if (!IN (p_obj->track_front_margin, 0, CDIO_PREGAP_SECTORS))
{
p_obj->track_front_margin = CLAMP (p_obj->track_front_margin, 0,
CDIO_PREGAP_SECTORS);
vcd_warn ("front margin out of range, clamping to allowed range");
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_TRACK_MARGINS)
&& p_obj->track_front_margin < 15)
vcd_warn ("front margin set smaller than recommended (%d < 15 sectors) for disc type used",
p_obj->track_front_margin);
vcd_debug ("changed front margin to %u", p_obj->track_front_margin);
break;
case VCD_PARM_TRACK_REAR_MARGIN:
p_obj->track_rear_margin = arg;
if (!IN (p_obj->track_rear_margin, 0, CDIO_POSTGAP_SECTORS))
{
p_obj->track_rear_margin = CLAMP (p_obj->track_rear_margin, 0,
CDIO_POSTGAP_SECTORS);
vcd_warn ("rear margin out of range, clamping to allowed range");
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_TRACK_MARGINS)
&& p_obj->track_rear_margin < 15)
vcd_warn ("rear margin set smaller than recommended (%d < 15 sectors) for disc type used",
p_obj->track_rear_margin);
vcd_debug ("changed rear margin to %u", p_obj->track_rear_margin);
break;
default:
vcd_assert_not_reached ();
break;
}
return 0;
}
int
vcd_obj_set_param_str (VcdObj_t *p_obj, vcd_parm_t param, const char *arg)
{
vcd_assert (p_obj != NULL);
vcd_assert (arg != NULL);
switch (param)
{
case VCD_PARM_VOLUME_ID:
free (p_obj->iso_volume_label);
p_obj->iso_volume_label = strdup (arg);
if (strlen (p_obj->iso_volume_label) > ISO_MAX_VOLUME_ID)
{
p_obj->iso_volume_label[ISO_MAX_VOLUME_ID] = '\0';
vcd_warn ("Volume label too long, will be truncated");
}
vcd_debug ("changed volume label to `%s'", p_obj->iso_volume_label);
break;
case VCD_PARM_PUBLISHER_ID:
free (p_obj->iso_publisher_id);
p_obj->iso_publisher_id = strdup (arg);
if (strlen (p_obj->iso_publisher_id) > ISO_MAX_PUBLISHER_ID)
{
p_obj->iso_publisher_id[ISO_MAX_PUBLISHER_ID] = '\0';
vcd_warn ("Publisher ID too long, will be truncated");
}
vcd_debug ("changed publisher id to `%s'", p_obj->iso_publisher_id);
break;
case VCD_PARM_PREPARER_ID:
free (p_obj->iso_preparer_id);
p_obj->iso_preparer_id = strdup (arg);
if (strlen (p_obj->iso_preparer_id) > ISO_MAX_PREPARER_ID)
{
p_obj->iso_preparer_id[ISO_MAX_PREPARER_ID] = '\0';
vcd_warn ("Preparer ID too long, will be truncated");
}
vcd_debug ("changed preparer id to `%s'", p_obj->iso_preparer_id);
break;
case VCD_PARM_APPLICATION_ID:
free (p_obj->iso_application_id);
p_obj->iso_application_id = strdup (arg);
if (strlen (p_obj->iso_application_id) > ISO_MAX_APPLICATION_ID)
{
p_obj->iso_application_id[ISO_MAX_APPLICATION_ID] = '\0';
vcd_warn ("Application ID too long, will be truncated");
}
vcd_debug ("changed application id to `%s'", p_obj->iso_application_id);
break;
case VCD_PARM_ALBUM_ID:
free (p_obj->info_album_id);
p_obj->info_album_id = strdup (arg);
if (strlen (p_obj->info_album_id) > 16)
{
p_obj->info_album_id[16] = '\0';
vcd_warn ("Album ID too long, will be truncated");
}
vcd_debug ("changed album id to `%s'", p_obj->info_album_id);
break;
default:
vcd_assert_not_reached ();
break;
}
return 0;
}
int
vcd_obj_set_param_bool (VcdObj_t *p_obj, vcd_parm_t param, bool arg)
{
vcd_assert (p_obj != NULL);
switch (param)
{
case VCD_PARM_RELAXED_APS:
p_obj->relaxed_aps = arg ? true : false;
vcd_debug ("changing 'relaxed aps' to %d", p_obj->relaxed_aps);
break;
case VCD_PARM_NEXT_VOL_LID2:
p_obj->info_use_lid2 = arg ? true : false;
vcd_debug ("changing 'next volume use lid 2' to %d",
p_obj->info_use_lid2);
break;
case VCD_PARM_NEXT_VOL_SEQ2:
p_obj->info_use_seq2 = arg ? true : false;
vcd_debug ("changing 'next volume use sequence 2' to %d",
p_obj->info_use_seq2);
break;
case VCD_PARM_SVCD_VCD3_MPEGAV:
if (p_obj->type == VCD_TYPE_SVCD)
{
if ((p_obj->svcd_vcd3_mpegav = arg ? true : false))
vcd_warn ("!! enabling deprecated VCD3.0 MPEGAV folder --"
" SVCD will not be IEC62107 compliant !!");
}
else
vcd_error ("parameter not applicable for vcd type");
break;
case VCD_PARM_SVCD_VCD3_ENTRYSVD:
if (p_obj->type == VCD_TYPE_SVCD)
{
if ((p_obj->svcd_vcd3_entrysvd = arg ? true : false))
vcd_warn ("!! enabling deprecated VCD3.0 ENTRYSVD signature --"
" SVCD will not be IEC62107 compliant !!");
}
else
vcd_error ("parameter not applicable for vcd type");
break;
case VCD_PARM_SVCD_VCD3_TRACKSVD:
if (p_obj->type == VCD_TYPE_SVCD)
{
if ((p_obj->svcd_vcd3_tracksvd = arg ? true : false))
vcd_warn ("!! enabling deprecated VCD3.0 TRACK.SVD format --"
" SVCD will not be IEC62107 compliant !!");
}
else
vcd_error ("parameter not applicable for vcd type");
break;
case VCD_PARM_UPDATE_SCAN_OFFSETS:
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
p_obj->update_scan_offsets = arg ? true : false;
vcd_debug ("changing 'update scan offsets' to %d",
p_obj->update_scan_offsets);
}
else
vcd_error ("parameter not applicable for vcd type");
break;
case VCD_PARM_LEADOUT_PAUSE:
vcd_warn ("use of 'leadout pause' is deprecated and may be removed in later releases;"
" use 'leadout pregap' instead");
vcd_obj_set_param_uint (p_obj, VCD_PARM_LEADOUT_PREGAP,
(arg ? CDIO_PREGAP_SECTORS : 0));
break;
default:
vcd_assert_not_reached ();
break;
}
return 0;
}
int
vcd_obj_add_dir (VcdObj_t *p_obj, const char iso_pathname[])
{
char *_iso_pathname;
vcd_assert (p_obj != NULL);
vcd_assert (iso_pathname != NULL);
_iso_pathname = _vcd_strdup_upper (iso_pathname);
if (!iso9660_dirname_valid_p (_iso_pathname))
{
vcd_error("pathname `%s' is not a valid iso pathname",
_iso_pathname);
free (_iso_pathname);
return 1;
}
_cdio_list_append (p_obj->custom_dir_list, _iso_pathname);
_vcd_list_sort (p_obj->custom_dir_list,
(_cdio_list_cmp_func_t) strcmp);
return 0;
}
int
vcd_obj_add_file (VcdObj_t *p_obj, const char iso_pathname[],
VcdDataSource_t *file, bool raw_flag)
{
uint32_t size = 0, sectors = 0;
vcd_assert (p_obj != NULL);
vcd_assert (file != NULL);
vcd_assert (iso_pathname != NULL);
vcd_assert (strlen (iso_pathname) > 0);
vcd_assert (file != NULL);
size = vcd_data_source_stat (file);
/* close file to save file descriptors */
vcd_data_source_close (file);
if (raw_flag)
{
if (!size)
{
vcd_error("raw mode2 file must not be empty\n");
return 1;
}
sectors = size / M2RAW_SECTOR_SIZE;
if (size % M2RAW_SECTOR_SIZE)
{
vcd_error("raw mode2 file must have size multiple of %d \n",
M2RAW_SECTOR_SIZE);
return 1;
}
}
else
sectors = _vcd_len2blocks (size, CDIO_CD_FRAMESIZE);
{
custom_file_t *p;
char *_iso_pathname = _vcd_strdup_upper (iso_pathname);
if (!iso9660_pathname_valid_p (_iso_pathname))
{
vcd_error("pathname `%s' is not a valid iso pathname",
_iso_pathname);
free (_iso_pathname);
return 1;
}
p = calloc(1, sizeof (custom_file_t));
p->file = file;
p->iso_pathname = _iso_pathname;
p->raw_flag = raw_flag;
p->size = size;
p->start_extent = 0;
p->sectors = sectors;
_cdio_list_append (p_obj->custom_file_list, p);
}
return 0;
}
static void
_finalize_vcd_iso_track_allocation (VcdObj_t *p_obj)
{
int n;
CdioListNode_t *p_node;
_dict_clean (p_obj);
/* pre-alloc 16 blocks of ISO9660 required silence */
if (_vcd_salloc (p_obj->iso_bitmap, 0, 16) == SECTOR_NIL)
vcd_assert_not_reached ();
/* keep karaoke sectors blank -- well... guess I'm too paranoid :) */
if (_vcd_salloc (p_obj->iso_bitmap, 75, 75) == SECTOR_NIL)
vcd_assert_not_reached ();
/* pre-alloc descriptors, PVD */
_dict_insert (p_obj, "pvd", ISO_PVD_SECTOR, 1, SM_EOR); /* EOR */
/* EVD */
_dict_insert (p_obj, "evd", ISO_EVD_SECTOR, 1, SM_EOR|SM_EOF); /* EOR+EOF */
/* reserve for iso directory */
_vcd_salloc (p_obj->iso_bitmap, 18, 75-18);
/* VCD information area */
_dict_insert (p_obj, "info", INFO_VCD_SECTOR, 1, SM_EOF); /* INFO.VCD */ /* EOF */
_dict_insert (p_obj, "entries", ENTRIES_VCD_SECTOR, 1, SM_EOF); /* ENTRIES.VCD */ /* EOF */
/* PBC */
if (_vcd_pbc_available (p_obj))
{
_dict_insert (p_obj, "lot", LOT_VCD_SECTOR, LOT_VCD_SIZE, SM_EOF); /* LOT.VCD */ /* EOF */
_dict_insert (p_obj, "psd", PSD_VCD_SECTOR,
_vcd_len2blocks (get_psd_size (p_obj, false), ISO_BLOCKSIZE), SM_EOF); /* PSD.VCD */ /* EOF */
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
_dict_insert (p_obj, "tracks", SECTOR_NIL, 1, SM_EOF); /* TRACKS.SVD */
_dict_insert (p_obj, "search", SECTOR_NIL,
_vcd_len2blocks (get_search_dat_size (p_obj), ISO_BLOCKSIZE), SM_EOF); /* SEARCH.DAT */
vcd_assert (_dict_get_bykey (p_obj, "tracks")->sector > INFO_VCD_SECTOR);
vcd_assert (_dict_get_bykey (p_obj, "search")->sector > INFO_VCD_SECTOR);
}
/* done with primary information area */
p_obj->mpeg_segment_start_extent =
_vcd_len2blocks (_vcd_salloc_get_highest (p_obj->iso_bitmap) + 1, 75) * 75;
/* salloc up to end of vcd sector */
for(n = 0;n < p_obj->mpeg_segment_start_extent;n++)
_vcd_salloc (p_obj->iso_bitmap, n, 1);
vcd_assert (_vcd_salloc_get_highest (p_obj->iso_bitmap) + 1 == p_obj->mpeg_segment_start_extent);
/* insert segments */
_CDIO_LIST_FOREACH (p_node, p_obj->mpeg_segment_list)
{
mpeg_segment_t *_segment = _cdio_list_node_data (p_node);
_segment->start_extent =
_vcd_salloc (p_obj->iso_bitmap, SECTOR_NIL,
_segment->segment_count * VCDINFO_SEGMENT_SECTOR_SIZE);
vcd_assert (_segment->start_extent % 75 == 0);
vcd_assert (_vcd_salloc_get_highest (p_obj->iso_bitmap) + 1
== _segment->start_extent
+ _segment->segment_count * VCDINFO_SEGMENT_SECTOR_SIZE);
}
p_obj->ext_file_start_extent = _vcd_salloc_get_highest (p_obj->iso_bitmap) + 1;
vcd_assert (p_obj->ext_file_start_extent % 75 == 0);
/* go on with EXT area */
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
_dict_insert (p_obj, "scandata", SECTOR_NIL,
_vcd_len2blocks (get_scandata_dat_size (p_obj),
ISO_BLOCKSIZE),
SM_EOF);
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_PBC_X)
&&_vcd_pbc_available (p_obj))
{
_dict_insert (p_obj, "lot_x", SECTOR_NIL, LOT_VCD_SIZE, SM_EOF);
_dict_insert (p_obj, "psd_x", SECTOR_NIL,
_vcd_len2blocks (get_psd_size (p_obj, true),
ISO_BLOCKSIZE), SM_EOF);
}
p_obj->custom_file_start_extent =
_vcd_salloc_get_highest (p_obj->iso_bitmap) + 1;
/* now for the custom files */
_CDIO_LIST_FOREACH (p_node, p_obj->custom_file_list)
{
custom_file_t *p = _cdio_list_node_data (p_node);
if (p->sectors)
{
p->start_extent =
_vcd_salloc(p_obj->iso_bitmap, SECTOR_NIL, p->sectors);
vcd_assert (p->start_extent != SECTOR_NIL);
}
else /* zero sized files -- set dummy extent */
p->start_extent = p_obj->custom_file_start_extent;
}
/* calculate iso size -- after this point no sector shall be
allocated anymore */
p_obj->iso_size =
MAX (MIN_ISO_SIZE, _vcd_salloc_get_highest (p_obj->iso_bitmap) + 1);
vcd_debug ("iso9660: highest alloced sector is %lu (using %d as isosize)",
(unsigned long int) _vcd_salloc_get_highest (p_obj->iso_bitmap),
p_obj->iso_size);
/* after this point the ISO9660's size is frozen */
}
static void
_finalize_vcd_iso_track_filesystem (VcdObj_t *p_obj)
{
int n;
CdioListNode_t *p_node;
/* create filesystem entries */
switch (p_obj->type) {
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_VCD2:
/* add only necessary directories! */
/* _vcd_directory_mkdir (p_obj->dir, "CDDA"); */
/* _vcd_directory_mkdir (p_obj->dir, "CDI"); */
_vcd_directory_mkdir (p_obj->dir, "EXT");
/* _vcd_directory_mkdir (p_obj->dir, "KARAOKE"); */
_vcd_directory_mkdir (p_obj->dir, "MPEGAV");
_vcd_directory_mkdir (p_obj->dir, "VCD");
/* add segment dir only when there are actually segment play items */
if (_cdio_list_length (p_obj->mpeg_segment_list))
_vcd_directory_mkdir (p_obj->dir, "SEGMENT");
_vcd_directory_mkfile (p_obj->dir, "VCD/ENTRIES.VCD",
_dict_get_bykey (p_obj, "entries")->sector,
ISO_BLOCKSIZE, false, 0);
_vcd_directory_mkfile (p_obj->dir, "VCD/INFO.VCD",
_dict_get_bykey (p_obj, "info")->sector,
ISO_BLOCKSIZE, false, 0);
/* only for vcd2.0 */
if (_vcd_pbc_available (p_obj))
{
_vcd_directory_mkfile (p_obj->dir, "VCD/LOT.VCD",
_dict_get_bykey (p_obj, "lot")->sector,
ISO_BLOCKSIZE*LOT_VCD_SIZE, false, 0);
_vcd_directory_mkfile (p_obj->dir, "VCD/PSD.VCD",
_dict_get_bykey (p_obj, "psd")->sector,
get_psd_size (p_obj, false), false, 0);
}
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
_vcd_directory_mkdir (p_obj->dir, "EXT");
if (!p_obj->svcd_vcd3_mpegav)
_vcd_directory_mkdir (p_obj->dir, "MPEG2");
else
{
vcd_warn ("adding MPEGAV dir for *DEPRECATED* SVCD VCD30 mode");
_vcd_directory_mkdir (p_obj->dir, "MPEGAV");
}
/* add segment dir only when there are actually segment play items */
if (_cdio_list_length (p_obj->mpeg_segment_list))
_vcd_directory_mkdir (p_obj->dir, "SEGMENT");
_vcd_directory_mkdir (p_obj->dir, "SVCD");
_vcd_directory_mkfile (p_obj->dir, "SVCD/ENTRIES.SVD",
_dict_get_bykey (p_obj, "entries")->sector,
ISO_BLOCKSIZE, false, 0);
_vcd_directory_mkfile (p_obj->dir, "SVCD/INFO.SVD",
_dict_get_bykey (p_obj, "info")->sector,
ISO_BLOCKSIZE, false, 0);
if (_vcd_pbc_available (p_obj))
{
_vcd_directory_mkfile (p_obj->dir, "SVCD/LOT.SVD",
_dict_get_bykey (p_obj, "lot")->sector,
ISO_BLOCKSIZE*LOT_VCD_SIZE, false, 0);
_vcd_directory_mkfile (p_obj->dir, "SVCD/PSD.SVD",
_dict_get_bykey (p_obj, "psd")->sector,
get_psd_size (p_obj, false), false, 0);
}
_vcd_directory_mkfile (p_obj->dir, "SVCD/SEARCH.DAT",
_dict_get_bykey (p_obj, "search")->sector,
get_search_dat_size (p_obj), false, 0);
_vcd_directory_mkfile (p_obj->dir, "SVCD/TRACKS.SVD",
_dict_get_bykey (p_obj, "tracks")->sector,
ISO_BLOCKSIZE, false, 0);
break;
default:
vcd_assert_not_reached ();
break;
}
/* SEGMENTS */
n = 1;
_CDIO_LIST_FOREACH (p_node, p_obj->mpeg_segment_list)
{
mpeg_segment_t *segment = _cdio_list_node_data (p_node);
char segment_pathname[128] = { 0, };
const char *fmt = NULL;
uint8_t fnum = 0;
switch (p_obj->type)
{
case VCD_TYPE_VCD2:
fmt = "SEGMENT/ITEM%4.4d.DAT";
fnum = 1;
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
fmt = "SEGMENT/ITEM%4.4d.MPG";
fnum = 0;
break;
default:
vcd_assert_not_reached ();
}
snprintf (segment_pathname, sizeof (segment_pathname), fmt, n);
_vcd_directory_mkfile (p_obj->dir, segment_pathname,
segment->start_extent,
segment->info->packets * ISO_BLOCKSIZE,
true, fnum);
vcd_assert (n <= MAX_SEGMENTS);
n += segment->segment_count;
}
/* EXT files */
if (_vcd_obj_has_cap_p (p_obj, _CAP_PBC_X)
&&_vcd_pbc_available (p_obj))
{
/* psd_x -- extended PSD */
_vcd_directory_mkfile (p_obj->dir, "EXT/PSD_X.VCD",
_dict_get_bykey (p_obj, "psd_x")->sector,
get_psd_size (p_obj, true), false, 1);
/* lot_x -- extended LOT */
_vcd_directory_mkfile (p_obj->dir, "EXT/LOT_X.VCD",
_dict_get_bykey (p_obj, "lot_x")->sector,
ISO_BLOCKSIZE*LOT_VCD_SIZE, false, 1);
vcd_assert (p_obj->type == VCD_TYPE_VCD2);
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
/* scandata.dat -- scanpoints */
_vcd_directory_mkfile (p_obj->dir, "EXT/SCANDATA.DAT",
_dict_get_bykey (p_obj, "scandata")->sector,
get_scandata_dat_size (p_obj), false, 0);
}
/* custom files/dirs */
_CDIO_LIST_FOREACH (p_node, p_obj->custom_dir_list)
{
char *p = _cdio_list_node_data (p_node);
_vcd_directory_mkdir (p_obj->dir, p);
}
_CDIO_LIST_FOREACH (p_node, p_obj->custom_file_list)
{
custom_file_t *p = _cdio_list_node_data (p_node);
_vcd_directory_mkfile (p_obj->dir, p->iso_pathname, p->start_extent,
(p->raw_flag
? (ISO_BLOCKSIZE * (p->size / M2RAW_SECTOR_SIZE))
: p->size),
p->raw_flag, 1);
}
n = 0;
_CDIO_LIST_FOREACH (p_node, p_obj->mpeg_sequence_list)
{
char avseq_pathname[128] = { 0, };
const char *fmt = NULL;
mpeg_sequence_t *p_sequence = _cdio_list_node_data (p_node);
uint32_t extent = p_sequence->relative_start_extent;
uint8_t file_num = 0;
extent += p_obj->iso_size;
switch (p_obj->type)
{
case VCD_TYPE_VCD:
fmt = "MPEGAV/MUSIC%2.2d.DAT";
file_num = n + 1;
break;
case VCD_TYPE_VCD11:
case VCD_TYPE_VCD2:
fmt = "MPEGAV/AVSEQ%2.2d.DAT";
file_num = n + 1;
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
fmt = "MPEG2/AVSEQ%2.2d.MPG";
file_num = 0;
/* if vcd3 compat mode, override */
if (p_obj->svcd_vcd3_mpegav)
{
fmt = "MPEGAV/AVSEQ%2.2d.MPG";
file_num = n + 1;
}
break;
default:
vcd_assert_not_reached ();
}
vcd_assert (n < 98);
snprintf (avseq_pathname, sizeof (avseq_pathname), fmt, n + 1);
/* file entry contains front margin, mpeg stream and rear margin */
_vcd_directory_mkfile (p_obj->dir, avseq_pathname, extent,
(p_obj->track_front_margin
+ p_sequence->info->packets
+ p_obj->track_rear_margin) * ISO_BLOCKSIZE,
true, file_num);
n++;
}
/* register isofs dir structures */
{
uint32_t dirs_size = _vcd_directory_get_size (p_obj->dir);
/* be sure to stay out of information areas */
switch (p_obj->type)
{
case VCD_TYPE_VCD:
case VCD_TYPE_VCD11:
case VCD_TYPE_VCD2:
/* karaoke area starts at 03:00 */
if (16 + 2 + dirs_size + 2 >= 75)
vcd_error ("directory section to big for a VCD");
break;
case VCD_TYPE_SVCD:
case VCD_TYPE_HQVCD:
/* since no karaoke exists the next fixed area starts at 04:00 */
if (16 + 2 + dirs_size + 2 >= 150)
vcd_error ("directory section to big for a SVCD");
break;
default:
vcd_assert_not_reached ();
}
/* un-alloc small area */
_vcd_salloc_free (p_obj->iso_bitmap, 18, dirs_size + 2);
/* alloc it again! */
_dict_insert (p_obj, "dir", 18, dirs_size, SM_EOR|SM_EOF);
_dict_insert (p_obj, "ptl", 18 + dirs_size, 1, SM_EOR|SM_EOF);
_dict_insert (p_obj, "ptm", 18 + dirs_size + 1, 1, SM_EOR|SM_EOF);
}
}
static void
_finalize_vcd_iso_track (VcdObj_t *p_obj)
{
_vcd_pbc_finalize (p_obj);
_finalize_vcd_iso_track_allocation (p_obj);
_finalize_vcd_iso_track_filesystem (p_obj);
}
static int
_callback_wrapper (VcdObj_t *p_obj, int force)
{
const int cb_frequency = 75;
if (p_obj->last_cb_call + cb_frequency > p_obj->sectors_written && !force)
return 0;
p_obj->last_cb_call = p_obj->sectors_written;
if (p_obj->progress_callback) {
progress_info_t _pi;
_pi.sectors_written = p_obj->sectors_written;
_pi.total_sectors = p_obj->relative_end_extent + p_obj->iso_size;
_pi.in_track = p_obj->in_track;
_pi.total_tracks = _cdio_list_length (p_obj->mpeg_sequence_list) + 1;
return p_obj->progress_callback (&_pi, p_obj->callback_user_data);
}
else
return 0;
}
static int
_write_m2_image_sector (VcdObj_t *obj, const void *data, uint32_t extent,
uint8_t fnum, uint8_t cnum, uint8_t sm, uint8_t ci)
{
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
vcd_assert (extent == obj->sectors_written);
_vcd_make_mode2(buf, data, extent, fnum, cnum, sm, ci);
vcd_image_sink_write (obj->image_sink, buf, extent);
obj->sectors_written++;
return _callback_wrapper (obj, false);
}
static int
_write_m2_raw_image_sector (VcdObj_t *obj, const void *data, uint32_t extent)
{
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
vcd_assert (extent == obj->sectors_written);
_vcd_make_raw_mode2(buf, data, extent);
vcd_image_sink_write (obj->image_sink, buf, extent);
obj->sectors_written++;
return _callback_wrapper (obj, false);
}
static void
_write_source_mode2_raw (VcdObj_t *obj, VcdDataSource_t *source,
uint32_t extent)
{
int n;
uint32_t sectors;
sectors = vcd_data_source_stat (source) / M2RAW_SECTOR_SIZE;
vcd_data_source_seek (source, 0);
for (n = 0;n < sectors;n++) {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
vcd_data_source_read (source, buf, M2RAW_SECTOR_SIZE, 1);
if (_write_m2_raw_image_sector (obj, buf, extent+n))
break;
}
vcd_data_source_close (source);
}
static void
_write_source_mode2_form1 (VcdObj_t *obj, VcdDataSource_t *source,
uint32_t extent)
{
int n;
uint32_t sectors, size, last_block_size;
size = vcd_data_source_stat (source);
sectors = _vcd_len2blocks (size, CDIO_CD_FRAMESIZE);
last_block_size = size % CDIO_CD_FRAMESIZE;
if (!last_block_size)
last_block_size = CDIO_CD_FRAMESIZE;
vcd_data_source_seek (source, 0);
for (n = 0;n < sectors;n++) {
char buf[CDIO_CD_FRAMESIZE] = { 0, };
vcd_data_source_read (source, buf,
((n + 1 == sectors)
? last_block_size
: CDIO_CD_FRAMESIZE), 1);
if (_write_m2_image_sector (obj, buf, extent+n, 1, 0,
((n+1 < sectors)
? SM_DATA
: SM_DATA |SM_EOF),
0))
break;
}
vcd_data_source_close (source);
}
static int
_write_sequence (VcdObj_t *p_obj, int track_idx)
{
mpeg_sequence_t *track =
_cdio_list_node_data (_vcd_list_at (p_obj->mpeg_sequence_list, track_idx));
CdioListNode_t *pause_node;
int n, lastsect = p_obj->sectors_written;
char buf[2324];
struct {
int audio;
int video;
int zero;
int ogt;
int unknown;
} mpeg_packets = {0, };
{
char *norm_str = NULL;
const struct vcd_mpeg_stream_vid_info *_info = &track->info->shdr[0];
switch (vcd_mpeg_get_norm (_info)) {
case MPEG_NORM_PAL:
norm_str = strdup ("PAL SIF (352x288/25fps)");
break;
case MPEG_NORM_NTSC:
norm_str = strdup ("NTSC SIF (352x240/29.97fps)");
break;
case MPEG_NORM_FILM:
norm_str = strdup ("FILM SIF (352x240/24fps)");
break;
case MPEG_NORM_PAL_S:
norm_str = strdup ("PAL 2/3 D1 (480x576/25fps)");
break;
case MPEG_NORM_NTSC_S:
norm_str = strdup ("NTSC 2/3 D1 (480x480/29.97fps)");
break;
case MPEG_NORM_OTHER:
{
char buf[1024] = { 0, };
switch (_info->vsize)
{
case 480:
case 240:
snprintf (buf, sizeof (buf), "NTSC UNKNOWN (%dx%d/%2.2ffps)",
_info->hsize, _info->vsize, _info->frate);
break;
case 288:
case 576:
snprintf (buf, sizeof (buf), "PAL UNKNOWN (%dx%d/%2.2ffps)",
_info->hsize, _info->vsize, _info->frate);
break;
default:
snprintf (buf, sizeof (buf), "UNKNOWN (%dx%d/%2.2ffps)",
_info->hsize, _info->vsize, _info->frate);
break;
}
norm_str = strdup (buf);
}
break;
}
{
char buf[1024] = { 0, }, buf2[1024] = { 0, };
int i;
int i_buf2 = 0;
for (i = 0; i < 3; i++)
if (track->info->ahdr[i].seen)
{
const char *_mode_str[] = {
0,
"stereo",
"jstereo",
"dual",
"single",
0
};
int i_buf = snprintf (buf, sizeof (buf),
"audio[%d]: l%d/%2.1fkHz/%dkbps/%s ",
i,
track->info->ahdr[i].layer,
track->info->ahdr[i].sampfreq / 1000.0,
track->info->ahdr[i].bitrate / 1024,
_mode_str[track->info->ahdr[i].mode]);
strncat (buf2, buf, sizeof(buf2)-strlen(buf2)-i_buf2-1);
i_buf2 += i_buf;
}
vcd_info ("writing track %d, %s, %s, %s...", track_idx + 2,
(track->info->version == MPEG_VERS_MPEG1 ? "MPEG1" : "MPEG2"),
norm_str, buf2);
}
free (norm_str);
}
for (n = 0; n < p_obj->track_pregap; n++)
_write_m2_image_sector (p_obj, zero, lastsect++, 0, 0, SM_FORM2, 0);
for (n = 0; n < p_obj->track_front_margin;n++)
_write_m2_image_sector (p_obj, zero, lastsect++, track_idx + 1,
0, SM_FORM2|SM_REALT, 0);
pause_node = _cdio_list_begin (track->pause_list);
for (n = 0; n < track->info->packets; n++) {
int ci = 0, sm = 0, cnum = 0, fnum = 0;
struct vcd_mpeg_packet_info pkt_flags;
bool set_trigger = false;
vcd_mpeg_source_get_packet (track->source, n, buf, &pkt_flags,
p_obj->update_scan_offsets);
while (pause_node)
{
pause_t *_pause = _cdio_list_node_data (pause_node);
if (!pkt_flags.has_pts)
break; /* no pts */
if (pkt_flags.pts < _pause->time)
break; /* our time has not come yet */
/* seems it's time to trigger! */
set_trigger = true;
vcd_debug ("setting auto pause trigger for time %f (pts %f) @%d",
_pause->time, pkt_flags.pts, n);
pause_node = _cdio_list_node_next (pause_node);
}
switch (vcd_mpeg_packet_get_type (&pkt_flags))
{
case PKT_TYPE_VIDEO:
mpeg_packets.video++;
sm = SM_FORM2|SM_REALT|SM_VIDEO;
ci = CI_VIDEO;
cnum = CN_VIDEO;
break;
case PKT_TYPE_OGT:
mpeg_packets.ogt++;
sm = SM_FORM2|SM_REALT|SM_VIDEO;
ci = CI_OGT;
cnum = CN_OGT;
break;
case PKT_TYPE_AUDIO:
mpeg_packets.audio++;
sm = SM_FORM2|SM_REALT|SM_AUDIO;
ci = CI_AUDIO;
cnum = CN_AUDIO;
if (pkt_flags.audio[1] || pkt_flags.audio[2])
{
ci = CI_AUDIO2;
cnum = CN_AUDIO2;
}
break;
case PKT_TYPE_ZERO:
mpeg_packets.zero++;
mpeg_packets.unknown--;
case PKT_TYPE_EMPTY:
mpeg_packets.unknown++;
sm = SM_FORM2|SM_REALT;
ci = CI_EMPTY;
cnum = CN_EMPTY;
break;
case PKT_TYPE_INVALID:
vcd_error ("invalid mpeg packet found at packet# %d"
" -- please fix this mpeg file!", n);
vcd_mpeg_source_close (track->source);
return 1;
break;
default:
vcd_assert_not_reached ();
}
if (n == track->info->packets - 1)
{
sm |= SM_EOR;
if (!p_obj->track_rear_margin) /* if no rear margin... */
sm |= SM_EOF;
}
if (set_trigger)
sm |= SM_TRIG;
fnum = track_idx + 1;
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD)
&& !p_obj->svcd_vcd3_mpegav) /* IEC62107 SVCDs have a
simplified subheader */
{
fnum = 1;
ci = CI_MPEG2;
}
if (_write_m2_image_sector (p_obj, buf, lastsect++, fnum, cnum, sm, ci))
break;
}
vcd_mpeg_source_close (track->source);
for (n = 0; n < p_obj->track_rear_margin; n++)
{
const uint8_t ci = 0, cnum = 0;
uint8_t fnum = track_idx + 1;
uint8_t sm = SM_FORM2 | SM_REALT;
if (n + 1 == p_obj->track_rear_margin)
sm |= SM_EOF;
_write_m2_image_sector (p_obj, zero, lastsect++, fnum, cnum, sm, ci);
}
vcd_debug ("MPEG packet statistics: %d video, %d audio, %d zero, %d ogt, %d unknown",
mpeg_packets.video, mpeg_packets.audio, mpeg_packets.zero, mpeg_packets.ogt,
mpeg_packets.unknown);
return 0;
}
static int
_write_segment (VcdObj_t *p_obj, mpeg_segment_t *p_segment)
{
CdioListNode_t *pause_node;
unsigned int packet_no;
int n = p_obj->sectors_written;
vcd_assert (p_segment->start_extent == n);
pause_node = _cdio_list_begin (p_segment->pause_list);
for (packet_no = 0;
packet_no < (p_segment->segment_count * VCDINFO_SEGMENT_SECTOR_SIZE);
packet_no++)
{
uint8_t buf[M2F2_SECTOR_SIZE] = { 0, };
uint8_t fn, cn, sm, ci;
if (packet_no < p_segment->info->packets)
{
struct vcd_mpeg_packet_info pkt_flags;
bool set_trigger = false;
bool _need_eor = false;
vcd_mpeg_source_get_packet (p_segment->source, packet_no,
buf, &pkt_flags,
p_obj->update_scan_offsets);
fn = 1;
cn = CN_EMPTY;
sm = SM_FORM2 | SM_REALT;
ci = CI_EMPTY;
while (pause_node)
{
pause_t *_pause = _cdio_list_node_data (pause_node);
if (!pkt_flags.has_pts)
break; /* no pts */
if (pkt_flags.pts < _pause->time)
break; /* our time has not come yet */
/* seems it's time to trigger! */
set_trigger = true;
vcd_debug ("setting auto pause trigger for time %f (pts %f) @%d",
_pause->time, pkt_flags.pts, n);
pause_node = _cdio_list_node_next (pause_node);
}
switch (vcd_mpeg_packet_get_type (&pkt_flags))
{
case PKT_TYPE_VIDEO:
sm = SM_FORM2 | SM_REALT | SM_VIDEO;
ci = CI_VIDEO;
cn = CN_VIDEO;
if (pkt_flags.video[1])
ci = CI_STILL, cn = CN_STILL;
else if (pkt_flags.video[2])
ci = CI_STILL2, cn = CN_STILL2;
if (pkt_flags.video[1] || pkt_flags.video[2])
{ /* search for endcode -- hack */
int idx;
for (idx = 0; idx <= 2320; idx++)
if (buf[idx] == 0x00
&& buf[idx + 1] == 0x00
&& buf[idx + 2] == 0x01
&& buf[idx + 3] == 0xb7)
{
_need_eor = true;
break;
}
}
break;
case PKT_TYPE_AUDIO:
sm = SM_FORM2 | SM_REALT | SM_AUDIO;
ci = CI_AUDIO;
cn = CN_AUDIO;
break;
case PKT_TYPE_EMPTY:
ci = CI_EMPTY;
cn = CN_EMPTY;
break;
default:
/* fixme -- check.... */
break;
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
cn = 1;
sm = SM_FORM2 | SM_REALT | SM_VIDEO;
ci = CI_MPEG2;
}
if (packet_no + 1 == p_segment->info->packets)
sm |= SM_EOF;
if (set_trigger)
sm |= SM_TRIG;
if (_need_eor)
{
vcd_debug ("setting EOR for SeqEnd at packet# %d ('%s')",
packet_no, p_segment->id);
sm |= SM_EOR;
}
}
else
{
fn = 1;
cn = CN_EMPTY;
sm = SM_FORM2 | SM_REALT;
ci = CI_EMPTY;
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
fn = 0;
sm = SM_FORM2;
}
}
_write_m2_image_sector (p_obj, buf, n, fn, cn, sm, ci);
n++;
}
vcd_mpeg_source_close (p_segment->source);
return 0;
}
static uint32_t
_get_closest_aps (const struct vcd_mpeg_stream_info *_mpeg_info, double t,
struct aps_data *_best_aps)
{
CdioListNode_t *p_node;
struct aps_data best_aps;
bool first = true;
best_aps.packet_no = 0xFFFF; /* A number which will be caught as an error*/
best_aps.timestamp = -1; /* A number which will be caught as an error*/
vcd_assert (_mpeg_info != NULL);
vcd_assert (_mpeg_info->shdr[0].aps_list != NULL);
_CDIO_LIST_FOREACH (p_node, _mpeg_info->shdr[0].aps_list)
{
struct aps_data *_aps = _cdio_list_node_data (p_node);
if (first)
{
best_aps = *_aps;
first = false;
}
else if (fabs (_aps->timestamp - t) < fabs (best_aps.timestamp - t))
best_aps = *_aps;
else
break;
}
if (_best_aps)
*_best_aps = best_aps;
return best_aps.packet_no;
}
static void
_update_entry_points (VcdObj_t *p_obj)
{
CdioListNode_t *sequence_node;
_CDIO_LIST_FOREACH (sequence_node, p_obj->mpeg_sequence_list)
{
mpeg_sequence_t *_sequence = _cdio_list_node_data (sequence_node);
CdioListNode_t *entry_node;
unsigned int last_packet_no = 0;
_CDIO_LIST_FOREACH (entry_node, _sequence->entry_list)
{
entry_t *_entry = _cdio_list_node_data (entry_node);
_get_closest_aps (_sequence->info, _entry->time, &_entry->aps);
vcd_log ((fabs (_entry->aps.timestamp - _entry->time) > 1
? VCD_LOG_WARN
: VCD_LOG_DEBUG),
"requested entry point (id=%s) at %f, "
"closest possible entry point at %f",
_entry->id, _entry->time, _entry->aps.timestamp);
if (last_packet_no == _entry->aps.packet_no)
vcd_warn ("entry point '%s' falls into same sector as previous one!",
_entry->id);
last_packet_no = _entry->aps.packet_no;
}
}
}
static int
_write_vcd_iso_track (VcdObj_t *p_obj, const time_t *p_create_time)
{
CdioListNode_t *node;
int n;
/* generate dir sectors */
_vcd_directory_dump_entries (p_obj->dir,
_dict_get_bykey (p_obj, "dir")->buf,
_dict_get_bykey (p_obj, "dir")->sector);
_vcd_directory_dump_pathtables (p_obj->dir,
_dict_get_bykey (p_obj, "ptl")->buf,
_dict_get_bykey (p_obj, "ptm")->buf);
/* generate PVD and EVD at last... */
iso9660_set_pvd (_dict_get_bykey (p_obj, "pvd")->buf,
p_obj->iso_volume_label,
p_obj->iso_publisher_id,
p_obj->iso_preparer_id,
p_obj->iso_application_id,
p_obj->iso_size,
_dict_get_bykey (p_obj, "dir")->buf,
_dict_get_bykey (p_obj, "ptl")->sector,
_dict_get_bykey (p_obj, "ptm")->sector,
iso9660_pathtable_get_size (_dict_get_bykey (p_obj, "ptm")->buf),
p_create_time
);
iso9660_set_evd (_dict_get_bykey (p_obj, "evd")->buf);
/* fill VCD relevant files with data */
set_info_vcd (p_obj, _dict_get_bykey (p_obj, "info")->buf);
set_entries_vcd (p_obj, _dict_get_bykey (p_obj, "entries")->buf);
if (_vcd_pbc_available (p_obj))
{
if (_vcd_obj_has_cap_p (p_obj, _CAP_PBC_X))
{
set_lot_vcd (p_obj, _dict_get_bykey (p_obj, "lot_x")->buf, true);
set_psd_vcd (p_obj, _dict_get_bykey (p_obj, "psd_x")->buf, true);
}
_vcd_pbc_check_unreferenced (p_obj);
set_lot_vcd (p_obj, _dict_get_bykey (p_obj, "lot")->buf, false);
set_psd_vcd (p_obj, _dict_get_bykey (p_obj, "psd")->buf, false);
}
if (_vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD))
{
set_tracks_svd (p_obj, _dict_get_bykey (p_obj, "tracks")->buf);
set_search_dat (p_obj, _dict_get_bykey (p_obj, "search")->buf);
set_scandata_dat (p_obj, _dict_get_bykey (p_obj, "scandata")->buf);
}
/* start actually writing stuff */
vcd_info ("writing track 1 (ISO9660)...");
/* 00:02:00 -> 00:04:74 */
for (n = 0; n < p_obj->mpeg_segment_start_extent; n++)
{
const void *content = NULL;
uint8_t flags = SM_DATA;
content = _dict_get_sector (p_obj, n);
flags |= _dict_get_sector_flags (p_obj, n);
if (content == NULL)
content = zero;
_write_m2_image_sector (p_obj, content, n, 0, 0, flags, 0);
}
/* SEGMENTS */
vcd_assert (n == p_obj->mpeg_segment_start_extent);
_CDIO_LIST_FOREACH (node, p_obj->mpeg_segment_list)
{
mpeg_segment_t *p_segment = _cdio_list_node_data (node);
_write_segment (p_obj, p_segment);
}
n = p_obj->sectors_written;
/* EXT stuff */
vcd_assert (n == p_obj->ext_file_start_extent);
for (;n < p_obj->custom_file_start_extent; n++)
{
const void *content = NULL;
uint8_t flags = SM_DATA;
uint8_t fileno = _vcd_obj_has_cap_p (p_obj, _CAP_4C_SVCD) ? 0 : 1;
content = _dict_get_sector (p_obj, n);
flags |= _dict_get_sector_flags (p_obj, n);
if (content == NULL)
{
vcd_debug ("unexpected empty EXT sector");
content = zero;
}
_write_m2_image_sector (p_obj, content, n, fileno, 0, flags, 0);
}
/* write custom files */
vcd_assert (n == p_obj->custom_file_start_extent);
_CDIO_LIST_FOREACH (node, p_obj->custom_file_list)
{
custom_file_t *p = _cdio_list_node_data (node);
vcd_info ("writing file `%s' (%lu bytes%s)",
p->iso_pathname, (unsigned long) p->size,
p->raw_flag ? ", raw sectors file": "");
if (p->raw_flag)
_write_source_mode2_raw (p_obj, p->file, p->start_extent);
else
_write_source_mode2_form1 (p_obj, p->file, p->start_extent);
}
/* blank unalloced tracks */
while ((n = _vcd_salloc (p_obj->iso_bitmap, SECTOR_NIL, 1)) < p_obj->iso_size)
_write_m2_image_sector (p_obj, zero, n, 0, 0, SM_DATA, 0);
return 0;
}
long
vcd_obj_get_image_size (VcdObj_t *p_obj)
{
long size_sectors = -1;
vcd_assert (!p_obj->in_output);
if (_cdio_list_length (p_obj->mpeg_sequence_list) > 0)
{
/* fixme -- make this efficient */
size_sectors = vcd_obj_begin_output (p_obj);
vcd_obj_end_output (p_obj);
}
return size_sectors;
}
long
vcd_obj_begin_output (VcdObj_t *p_obj)
{
uint32_t image_size;
vcd_assert (p_obj != NULL);
vcd_assert (_cdio_list_length (p_obj->mpeg_sequence_list) > 0);
vcd_assert (!p_obj->in_output);
p_obj->in_output = true;
p_obj->in_track = 1;
p_obj->sectors_written = 0;
p_obj->iso_bitmap = _vcd_salloc_new ();
p_obj->dir = _vcd_directory_new ();
p_obj->buffer_dict_list = _cdio_list_new ();
_finalize_vcd_iso_track (p_obj);
_update_entry_points (p_obj);
image_size = p_obj->relative_end_extent + p_obj->iso_size;
image_size += p_obj->leadout_pregap;
if (image_size > CDIO_CD_MAX_SECTORS)
vcd_error ("image too big (%d sectors > %d sectors)",
(unsigned) image_size, (unsigned) CDIO_CD_MAX_SECTORS);
{
char *_tmp = cdio_lba_to_msf_str (image_size);
if (image_size > CDIO_CD_74MIN_SECTORS)
vcd_warn ("generated image (%d sectors [%s]) may not fit "
"on 74min CDRs (%d sectors)",
(unsigned) image_size, _tmp, (unsigned) CDIO_CD_74MIN_SECTORS);
free (_tmp);
}
return image_size;
}
void
vcd_obj_end_output (VcdObj_t *p_obj)
{
vcd_assert (p_obj != NULL);
vcd_assert (p_obj->in_output);
p_obj->in_output = false;
_vcd_directory_destroy (p_obj->dir);
_vcd_salloc_destroy (p_obj->iso_bitmap);
_dict_clean (p_obj);
_cdio_list_free (p_obj->buffer_dict_list, true, (CdioDataFree_t) &dict_free);
}
int
vcd_obj_append_pbc_node (VcdObj_t *p_obj, struct _pbc_t *p_pbc)
{
vcd_assert (p_obj != NULL);
vcd_assert (p_pbc != NULL);
if (!_vcd_obj_has_cap_p (p_obj, _CAP_PBC))
{
vcd_error ("PBC not supported for current VCD type");
return -1;
}
if (p_pbc->item_id && _vcd_pbc_lookup (p_obj, p_pbc->item_id))
{
vcd_error ("item id (%s) exists already", p_pbc->item_id);
return -1;
}
_cdio_list_append (p_obj->pbc_list, p_pbc);
return 0;
}
int
vcd_obj_write_image (VcdObj_t *p_obj, VcdImageSink_t *p_image_sink,
progress_callback_t callback, void *user_data,
const time_t *p_create_time)
{
CdioListNode_t *node;
vcd_assert (p_obj != NULL);
vcd_assert (p_obj->in_output);
if (!p_image_sink)
return -1;
/* start with meta info */
{
CdioList_t *p_cue_list;
vcd_cue_t *p_cue;
p_cue_list = _cdio_list_new ();
_cdio_list_append (p_cue_list, (p_cue = calloc(1, sizeof (vcd_cue_t))));
p_cue->lsn = 0;
p_cue->type = VCD_CUE_TRACK_START;
_CDIO_LIST_FOREACH (node, p_obj->mpeg_sequence_list)
{
mpeg_sequence_t *p_track = _cdio_list_node_data (node);
CdioListNode_t *p_entry_node;
_cdio_list_append (p_cue_list,
(p_cue = calloc(1, sizeof (vcd_cue_t))));
p_cue->lsn = p_track->relative_start_extent + p_obj->iso_size;
p_cue->lsn -= p_obj->track_pregap;
p_cue->type = VCD_CUE_PREGAP_START;
_cdio_list_append (p_cue_list,
(p_cue = calloc(1, sizeof (vcd_cue_t))));
p_cue->lsn = p_track->relative_start_extent + p_obj->iso_size;
p_cue->type = VCD_CUE_TRACK_START;
_CDIO_LIST_FOREACH (p_entry_node, p_track->entry_list)
{
entry_t *_entry = _cdio_list_node_data (p_entry_node);
_cdio_list_append (p_cue_list,
(p_cue = calloc(1, sizeof (vcd_cue_t))));
p_cue->lsn = p_obj->iso_size;
p_cue->lsn += p_track->relative_start_extent;
p_cue->lsn += p_obj->track_front_margin;
p_cue->lsn += _entry->aps.packet_no;
p_cue->type = VCD_CUE_SUBINDEX;
}
}
/* add last one... */
_cdio_list_append (p_cue_list, (p_cue = calloc(1, sizeof (vcd_cue_t))));
p_cue->lsn = p_obj->relative_end_extent + p_obj->iso_size;
p_cue->lsn += p_obj->leadout_pregap;
p_cue->type = VCD_CUE_END;
/* send it to image object */
vcd_image_sink_set_cuesheet (p_image_sink, p_cue_list);
_cdio_list_free (p_cue_list, true, (CdioDataFree_t) &cue_data_free);
}
/* and now for the pay load */
{
unsigned int track;
vcd_assert (p_obj != NULL);
vcd_assert (p_obj->sectors_written == 0);
vcd_assert (p_obj->in_output);
p_obj->progress_callback = callback;
p_obj->callback_user_data = user_data;
p_obj->image_sink = p_image_sink;
if (_callback_wrapper (p_obj, true))
return 1;
if (_write_vcd_iso_track (p_obj, p_create_time))
return 1;
if (p_obj->update_scan_offsets)
vcd_info ("'update scan offsets' option enabled for "
"the following tracks!");
for (track = 0;
track < _cdio_list_length (p_obj->mpeg_sequence_list);
track++)
{
p_obj->in_track++;
if (_callback_wrapper (p_obj, true))
return 1;
if (_write_sequence (p_obj, track))
return 1;
}
if (p_obj->leadout_pregap)
{
int n, lastsect = p_obj->sectors_written;
vcd_debug ("writting post-gap ('leadout pregap')...");
for (n = 0; n < p_obj->leadout_pregap; n++)
_write_m2_image_sector (p_obj, zero, lastsect++, 0, 0, SM_FORM2, 0);
}
if (_callback_wrapper (p_obj, true))
return 1;
p_obj->image_sink = NULL;
vcd_image_sink_destroy (p_image_sink);
return 0; /* ok */
}
}
const char *
vcd_version_string (bool full_text)
{
if (!full_text)
return ("GNU VCDImager " VERSION " [" HOST_ARCH "]");
return ("%s (GNU VCDImager) " VERSION "\n"
"Written by Herbert Valerio Riedel and Rocky Bernstein.\n"
"\n"
"http://www.gnu.org/software/vcdimager/\n"
"\n"
"Copyright (C) 2000-2003 Herbert Valerio Riedel <hvr@gnu.org>\n"
" 2003 Rocky Bernstein <rocky@gnu.org>\n"
"\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}
/*
* Local variables:
* c-file-style: "gnu"
* tab-width: 8
* indent-tabs-mode: nil
* End:
*/
|