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
|
/*
* xine_frontend.c:
*
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
* $Id$
*
*/
#include "features.h"
#ifndef _GNU_SOURCE
# define _GNU_SOURCE // asprintf
#endif
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
#ifdef HAVE_LIBJPEG
# ifdef boolean
# define HAVE_BOOLEAN
# endif
# define INT32 jpegINT32
# include <jpeglib.h>
# undef INT32
# undef boolean
#endif
#include <xine.h>
#include <xine/xine_internal.h>
#define LOG_MODULENAME "[vdr-fe] "
#include "logdefs.h"
#include "xine_frontend_internal.h"
#include "xine/post.h"
#include "xine/vo_post.h"
#include "xine/vo_osdscaler.h"
#include "xine/vo_osdreorder.h"
#include "xine/vo_lastpts.h"
#include "xine/vo_frameoutput.h"
#ifdef __WIN32__
# define mkdir(a,b) mkdir(a)
#endif
#undef MIN
#define MIN(a,b) ( (a) < (b) ? (a) : (b))
#undef MAX
#define MAX(a,b) ( (a) > (b) ? (a) : (b))
static void intercept_video_driver(xine_video_port_t *video_port)
{
vo_driver_t *osdscaler = osdscaler_init();
if (osdscaler && !wire_video_driver(video_port, osdscaler)) {
LOGMSG("wire_video_driver() for osdscaler failed");
osdscaler->dispose(osdscaler);
}
vo_driver_t *osdreorder = osd_reorder_init();
if (osdreorder && !wire_video_driver(video_port, osdreorder)) {
LOGMSG("wire_video_driver() for osdreorder failed");
osdreorder->dispose(osdreorder);
}
vo_driver_t *lastpts = vo_lastpts_init();
if (lastpts && !wire_video_driver(video_port, lastpts)) {
LOGMSG("wire_video_driver() for vo_lastpts failed");
lastpts->dispose(lastpts);
}
}
char *strn0cpy(char *dest, const char *src, int n)
{
char *s = dest;
for ( ; --n && (*dest = *src) != 0; dest++, src++) ;
*dest = 0;
return s;
}
static int guess_cpu_count(void)
{
static int cores = -1;
FILE *f;
if(cores >= 0)
return cores;
cores = 0;
if(NULL != (f = fopen("/proc/cpuinfo", "r"))) {
char buf[256];
while (NULL != fgets(buf, 255, f))
sscanf(buf, "processor : %d", &cores);
fclose(f);
}
cores++;
if(cores > 1)
LOGMSG("Detected %d CPUs", cores);
else
LOGDBG("Detected single CPU. Multithreaded decoding and post processing disabled.");
return cores;
}
static void shutdown_system(char *cmd, int user_requested)
{
const char *reason = user_requested ? "User requested system shutdown" : "Inactivity timer elapsed";
if (cmd) {
LOGMSG("%s. Executing '%s'", reason, cmd);
if (-1 == system(cmd))
LOGERR("Can't execute %s", cmd);
} else {
LOGMSG("%s, power off comand undefined!", reason);
}
}
static int _ensure_dir(const char *path)
{
struct stat st;
int saved_errno;
if (mkdir(path, ACCESSPERMS) == 0) {
LOGDBG("Created directory %s", path);
return 0;
}
saved_errno = errno;
if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) {
errno = saved_errno;
LOGERR("Can't create %s", path);
return -1;
}
/* directory exist */
return 0;
}
static void make_dirs(const char *file)
{
char *s = strdup(file);
char *p = s;
if (*p == '/') {
p++;
while ((p = strchr(p, '/')) != NULL) {
*p = 0;
if (_ensure_dir(s) < 0)
break;
*p++ = '/';
}
}
free(s);
}
/*
* list available plugins
*/
static int plugins_check(xine_t *xine)
{
const char *const *list;
int basic = 0, advanced = 0;
list = xine_list_video_decoder_plugins(xine);
while (list && *list) {
if (!strcmp(*list, "ffmpegvideo") ||
!strncmp(*list, "vdpau_", 6) ||
!strcmp(*list, "libmmal")) {
advanced = 1;
break;
}
if (!strcmp(*list, "mpeg2")) {
basic = 1;
}
list++;
}
if (!advanced) {
if (!basic) {
LOGERR("FATAL: Required xine video decoder plugins are missing! Please install plugins.");
return -1;
} else {
LOGMSG("WARNING: Essential xine video decoder plugins not found! Please install plugins to display H.264 video.");
}
}
return 0;
}
#define LIST_FUNC __typeof__(xine_list_audio_output_plugins)
static void list_plugins_type(xine_t *xine, const char *msg, LIST_FUNC list_func)
{
const char *const *list = list_func(xine);
printf("%s", msg);
while(list && *list)
printf(" %s", *list++);
printf("\n");
}
void list_xine_plugins(frontend_t *fe, int verbose)
{
fe_t *this = (fe_t *)fe;
xine_t *tmp_xine = NULL;
xine_t *xine = this ? this->xine : NULL;
if (!xine)
xine_init(xine = tmp_xine = xine_new());
list_plugins_type (xine, "Available video drivers:", xine_list_video_output_plugins);
list_plugins_type (xine, "Available audio drivers:", xine_list_audio_output_plugins);
if (verbose) {
list_plugins_type (xine, "Available post plugins: ", xine_list_post_plugins);
list_plugins_type (xine, "Available input plugins:", xine_list_input_plugins);
list_plugins_type (xine, "Available demux plugins:", xine_list_demuxer_plugins);
list_plugins_type (xine, "Available audio decoder plugins:", xine_list_audio_decoder_plugins);
list_plugins_type (xine, "Available video decoder plugins:", xine_list_video_decoder_plugins);
list_plugins_type (xine, "Available SPU decoder plugins: ", xine_list_spu_plugins);
}
if (tmp_xine)
xine_exit(tmp_xine);
}
/*
* detect input plugin
*/
static int find_input_plugin(fe_t *this)
{
if(!this->input_plugin) {
if(!this->stream || !this->stream->input_plugin ||
!this->stream->input_plugin->input_class || _xl_atomic_load(&this->playback_finished)) {
LOGMSG("find_input_plugin: stream not initialized or playback finished !");
usleep(100*1000);
return 0;
}
#if XINE_VERSION_CODE < 10190
if(strcmp(this->stream->input_plugin->input_class->get_identifier(
this->stream->input_plugin->input_class),
MRL_ID)) {
#else
if(strcmp(this->stream->input_plugin->input_class->identifier,
MRL_ID)) {
#endif
LOGMSG("find_input_plugin: current xine input plugin is not " MRL_ID " !");
return 0;
}
this->input_plugin = (vdr_input_plugin_if_t*)this->stream->input_plugin;
}
return 1;
}
static void *fe_control(frontend_t *this_gen, const char *cmd);
/*
* xine callbacks
*/
static double fe_dest_pixel_aspect(const fe_t *this, double video_pixel_aspect,
int video_width, int video_height)
{
/*int new_cropping = 0;*/
double result = 1.0;
if(!this->scale_video) {
/*#warning what to do if scaling disabled ???*/
/*return video_pixel_aspect;*/
}
switch(this->aspect) {
/* Auto */
default: {
double correction =
((double)video_width/(double)video_height) /
((double)this->width/(double)this->height);
result = video_pixel_aspect * correction;
if(result > (16.9/9.0 * (double)this->height/
(double)this->width))
result = (16.0/9.0 * (double)this->height/
(double)this->width);
break;
}
/* Default */
case 1: result = this->display_ratio; break;
/* 4:3 */
case 2: result = (4.0/3.0 * (double)this->height/(double)this->width); break;
/* 16:9 */
case 3: result = (16.0/9.0 * (double)this->height/(double)this->width); break;
/* 16:10 */
case 4: result = (16.0/10.0 * (double)this->height/(double)this->width); break;
/* Pan&Scan */
case 5: {
double aspect_diff /*= video_pixel_aspect - 1.0*/;
/* TODO */
/* does not work (?) */
aspect_diff=(video_pixel_aspect*(double)video_width/(double)video_height) - 4.0 / 3.0;
if ((aspect_diff < 0.05) && (aspect_diff > -0.05)) {
result = (4.0/3.0 * (double)this->height/(double)this->width);
/*LOGDBG("diff: %f", aspect_diff);*/
/*new_cropping = 1;*/
} else {
result = (16.0/9.0 * (double)this->height/(double)this->width);
}
/*result = (4.0/3.0 * (double)this->height/(double)this->width);*/
break;
}
/* center cut-out */
case 6: {
/*#warning center cut-out mode not implemented*/
break;
}
}
#if 0
if(this->cropping && !new_cropping) {
LOGDBG("pan&scan CROP OFF");
xine_set_param(this->stream, XINE_PARAM_VO_CROP_LEFT, 0);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_TOP, 72);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_RIGHT, 0);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_BOTTOM, 72);
this->cropping = 0;
}
if(!this->cropping && new_cropping) {
LOGDBG("pan&scan CROP ON");
/*** Should set unscaled osd (or top & bottom will be cropped off) */
xine_set_param(this->stream, XINE_PARAM_VO_CROP_LEFT, 0);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_TOP, 0);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_RIGHT, 0);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_BOTTOM, 0);
this->cropping = 1;
}
#endif
return result;
}
static void fe_frame_output_cb (void *data,
int video_width, int video_height,
double video_pixel_aspect,
int *dest_x, int *dest_y,
int *dest_width, int *dest_height,
double *dest_pixel_aspect,
int *win_x, int *win_y)
{
fe_t *this = (fe_t *)data;
if (!this)
return;
pthread_mutex_lock(&this->geom_mutex);
*dest_width = this->width;
*dest_height = this->height;
*dest_x = 0;
*dest_y = 0;
#if 1
if(!this->scale_video) {
if(video_height < this->height) {
*dest_height = video_height;
*dest_y = (this->height - video_height) / 2;
}
if(video_width < this->width) {
*dest_width = video_width;
*dest_x = (this->width - video_width) / 2;
}
}
#endif
*win_x = this->xpos;
*win_y = this->ypos;
*dest_pixel_aspect = this->dest_pixel_aspect(this, video_pixel_aspect,
video_width, video_height);
#if 0
if(this->cropping) {
*dest_pixel_aspect = *dest_pixel_aspect * (16.0/9.0)/(4.0/3.0);
*dest_y = *dest_y - 72;
*dest_height = *dest_height + 144;
}
#endif
#if 0
/* video_out cropping works better */
if(this->overscan) {
int crop_x = this->overscan * this->width / 100 / 2;
int crop_y = this->overscan * this->height / 100 / 2;
*dest_x -= crop_x;
*dest_y -= crop_y;
*dest_width += crop_x;
*dest_height += crop_y;
}
#endif
if (!this->stream) {
pthread_mutex_unlock(&this->geom_mutex);
return;
}
_x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO,
(int)(10000.0*video_pixel_aspect *
((double)video_width)/((double)video_height)));
if(this->video_width != video_width ||
this->video_height != video_height) {
xine_format_change_data_t framedata = {
.width = video_width,
.height = video_height,
.aspect = 0, /* TODO */
.pan_scan = 0,
};
const xine_event_t event = {
.type = XINE_EVENT_FRAME_FORMAT_CHANGE,
.stream = this->stream,
.data = &framedata,
.data_length = sizeof(framedata),
};
xine_event_send(this->stream, &event);
this->video_width = video_width;
this->video_height = video_height;
#if 0
/* trigger forced redraw to make cropping changes effective */
if(this->cropping)
xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, 100);
#endif
}
if(this->aspect_controller) {
double video_aspect = (video_pixel_aspect * (double)video_width / (double)video_height);
double aspect_diff = video_aspect - this->video_aspect;
if ((aspect_diff > 0.05) || (aspect_diff < -0.05)) {
char cmd[4096];
if(snprintf(cmd, sizeof(cmd), "%s %d",
this->aspect_controller, (int)(video_aspect * 10000.0))
< (int)sizeof(cmd)) {
LOGDBG("Aspect ratio changed, executing %s", cmd);
if(system(cmd) == -1)
LOGERR("Executing /bin/sh -c %s failed", cmd);
this->video_aspect = video_aspect;
}
}
}
pthread_mutex_unlock(&this->geom_mutex);
}
static void xine_event_cb (void *user_data, const xine_event_t *event)
{
fe_t *this = (fe_t *)user_data;
switch (event->type) {
/* in local mode: vdr stream / slave stream ; in remote mode: vdr stream only */
case XINE_EVENT_UI_PLAYBACK_FINISHED:
LOGDBG("XINE_EVENT_UI_PLAYBACK_FINISHED");
if(this) {
if(event->stream == this->stream)
_xl_atomic_store(&this->playback_finished, 1);
} else {
LOGMSG("xine_event_cb: NO USER DATA !");
}
break;
default: break;
}
}
/*
* fe_xine_init
*
* initialize xine engine, initialize audio and video ports, setup stream
*/
#define MONO 0
#define STEREO 1
#define HEADPHONES 2
#define SURROUND21 3
#define SURROUND3 4
#define SURROUND4 5
#define SURROUND41 6
#define SURROUND5 7
#define SURROUND51 8
#define SURROUND6 9
#define SURROUND61 10
#define SURROUND71 11
#define A52_PASSTHRU 12
#define x_reg_num(x...) xine_config_register_num(this->xine, x)
#define x_reg_str(x...) xine_config_register_string(this->xine, x)
#define x_reg_enum(x...) xine_config_register_enum(this->xine, x)
#define x_reg_bool(x...) xine_config_register_bool(this->xine, x)
#define x_upd_num(x...) this->xine->config->update_num(this->xine->config, x)
#define x_upd_str(x...) this->xine->config->update_string(this->xine->config, x)
static void configure_audio_out(const fe_t *this, const char *audio_driver, const char *audio_port)
{
/*
* alsa
*/
if(audio_driver && audio_port && !strcmp("alsa", audio_driver) && strlen(audio_port) > 0) {
/* define possible speaker arrangements */
/* From xine audio_alsa_out.c ; must be synchronized ! */
static const char * const speaker_arrangement[] =
{"Mono 1.0", "Stereo 2.0", "Headphones 2.0", "Stereo 2.1",
"Surround 3.0", "Surround 4.0", "Surround 4.1",
"Surround 5.0", "Surround 5.1", "Surround 6.0",
"Surround 6.1", "Surround 7.1", "Pass Through", NULL};
x_reg_enum("audio.output.speaker_arrangement",
STEREO,
(char**)(intptr_t)speaker_arrangement,
_("speaker arrangement"),
_("Select how your speakers are arranged, "
"this determines which speakers xine uses for sound output. "
"The individual values are:\n\n"
"Mono 1.0: You have only one speaker.\n"
"Stereo 2.0: You have two speakers for left and right channel.\n"
"Headphones 2.0: You use headphones.\n"
"Stereo 2.1: You have two speakers for left and right channel, and one "
"subwoofer for the low frequencies.\n"
"Surround 3.0: You have three speakers for left, right and rear channel.\n"
"Surround 4.0: You have four speakers for front left and right and rear "
"left and right channels.\n"
"Surround 4.1: You have four speakers for front left and right and rear "
"left and right channels, and one subwoofer for the low frequencies.\n"
"Surround 5.0: You have five speakers for front left, center and right and "
"rear left and right channels.\n"
"Surround 5.1: You have five speakers for front left, center and right and "
"rear left and right channels, and one subwoofer for the low frequencies.\n"
"Surround 6.0: You have six speakers for front left, center and right and "
"rear left, center and right channels.\n"
"Surround 6.1: You have six speakers for front left, center and right and "
"rear left, center and right channels, and one subwoofer for the low frequencies.\n"
"Surround 7.1: You have seven speakers for front left, center and right, "
"left and right and rear left and right channels, and one subwoofer for the "
"low frequencies.\n"
"Pass Through: Your sound system will receive undecoded digital sound from xine. "
"You need to connect a digital surround decoder capable of decoding the "
"formats you want to play to your sound card's digital output."),
10, NULL, NULL);
x_reg_str("audio.device.alsa_default_device",
"default",
_("device used for mono output"),
_("xine will use this alsa device "
"to output mono sound.\n"
"See the alsa documentation "
"for information on alsa devices."),
10, NULL, NULL);
x_reg_str("audio.device.alsa_front_device",
"plug:front:default",
_("device used for stereo output"),
_("xine will use this alsa device "
"to output stereo sound.\n"
"See the alsa documentation "
"for information on alsa devices."),
10, NULL, NULL);
x_reg_str("audio.device.alsa_surround51_device",
"plug:surround51:0",
_("device used for 5.1-channel output"),
_("xine will use this alsa device to output "
"5 channel plus LFE (5.1) surround sound.\n"
"See the alsa documentation for information "
"on alsa devices."),
10, NULL, NULL);
x_reg_str("audio.device.alsa_passthrough_device",
"iec958:AES0=0x6,AES1=0x82,AES2=0x0,AES3=0x2",
_("device used for 5.1-channel output"),
_("xine will use this alsa device to output "
"undecoded digital surround sound. This can "
"be used be external surround decoders.\nSee the "
"alsa documentation for information on alsa "
"devices."),
10, NULL, NULL);
x_upd_str("audio.device.alsa_front_device", audio_port);
x_upd_str("audio.device.alsa_default_device", audio_port);
x_upd_str("audio.device.alsa_surround51_device", audio_port);
if(strstr(audio_port, "iec") ||
strstr(audio_port, "spdif")) {
x_upd_str("audio.device.alsa_passthrough_device", audio_port);
x_upd_num("audio.output.speaker_arrangement", A52_PASSTHRU);
} else {
#if 0
x_upd_num("audio.output.speaker_arrangement",
strstr(audio_port, "surround") ? SURROUND51 : STEREO);
#endif
}
}
/*
* OSS
*/
if(audio_driver && !strcmp("oss", audio_driver) && audio_port) {
int devnum = -2;
if(!strcmp("default", audio_port))
devnum = -1;
if(!strncmp("/dev/dsp", audio_port, 8) &&
sscanf(audio_port+8, "%d", &devnum) < 1)
devnum = -1;
if(!strncmp("/dev/sound/dsp", audio_port, 14) &&
sscanf(audio_port+14, "%d", &devnum) < 1)
devnum = -1;
if(devnum > -2) {
x_reg_num("audio.device.oss_device_number", -1,
_("OSS audio device number, -1 for none"),
_("The full audio device name is created by concatenating the "
"OSS device name and the audio device number.\n"
"If you do not need a number because you are happy with "
"your system's default audio device, set this to -1.\n"
"The range of this value is -1 or 0-15. This setting is "
"ignored, when the OSS audio device name is set to \"auto\"."),
10, NULL, NULL);
x_upd_num("audio.device.oss_device_num", devnum);
}
}
}
static int fe_xine_init(frontend_t *this_gen, const char *audio_driver,
const char *audio_port,
const char *video_driver,
int pes_buffers,
int ffmpeg_threads,
const char *static_post_plugins,
const char *config_file)
{
fe_t *this = (fe_t*)this_gen;
post_plugins_t *posts = NULL;
int old_pes_buffers;
if(!this)
return 0;
/* check xine-lib version */
if(!xine_check_version(1, 1, 0)) {
LOGERR("xine-lib is too old, require at least xine library version 1.1.0\n");
return FE_ERROR;
}
/*
* init xine engine
*/
if(this->xine)
this->fe.xine_exit(this_gen);
this->stream = NULL;
this->video_port = NULL;
this->audio_port = NULL;
this->input_plugin = NULL;
/* Set log level for input plugin.
* Also inform input plugin we're not running in xine-ui etc.
*/
#ifndef _WIN32
static char log_level[16];
sprintf(log_level, "%d", SysLogLevel);
setenv("VDR_FE_LOG_LEVEL", log_level, 1);
if (LogToSysLog) {
setenv("VDR_FE_SYSLOG", "1", 1);
}
#endif
/* create a new xine and load config file */
this->xine = xine_new();
if(!this->xine)
return 0;
/* Set xine engine logging verbosity */
this->xine->verbosity = (SysLogLevel>2) ? (SysLogLevel - 1) : 0;
/*xine_register_log_cb(this->xine, xine_log_cb, this);*/
free(this->configfile);
this->configfile = NULL;
if (config_file)
this->configfile = strdup(config_file);
else if(asprintf(&this->configfile, "%s%s", xine_get_homedir(),
"/.xine/config_xineliboutput") < 0)
return 0;
LOGDBG("Using xine-lib config file %s", this->configfile);
make_dirs(this->configfile);
xine_config_load (this->xine, this->configfile);
old_pes_buffers =
x_reg_num ("engine.buffers.video_num_buffers",
500,
_("number of video buffers"),
_("The number of video buffers "
"(each is 8k in size) "
"xine uses in its internal queue. "
"Higher values "
"mean smoother playback for unreliable "
"inputs, but "
"also increased latency and memory "
"consumption."),
20, NULL, NULL);
if (old_pes_buffers < 50 || old_pes_buffers > 10000) {
LOGMSG("Fixing invalid buffer size (%d) in config", old_pes_buffers);
x_upd_num("engine.buffers.video_num_buffers", 250);
old_pes_buffers = 250;
}
x_reg_num ("engine.buffers.audio_num_buffers",
500,
_("number of audio buffers"),
_("The number of audio buffers (each is 8k in size) "
"xine uses in its internal queue. Higher values "
"mean smoother playback for unreliable inputs, but "
"also increased latency and memory consumption."),
20, NULL, NULL);
x_reg_bool("gui.osd_use_unscaled",
0,
_("Use unscaled OSD"),
_("Use unscaled (full screen resolution) OSD if possible"),
10, NULL, NULL);
xine_init (this->xine);
if (plugins_check(this->xine) < 0)
return 0;
x_upd_num("video.device.xv_double_buffer", 1);
if (pes_buffers >= 50)
x_upd_num("engine.buffers.video_num_buffers", pes_buffers);
else
pes_buffers = old_pes_buffers;
if(this->video_port_name) {
if(video_driver && !strcmp(video_driver, "fb"))
x_upd_str("video.device.fb_device", this->video_port_name);
}
_xl_atomic_store(&this->playback_finished, 0);
/* check X11 video driver type */
if (this->xine_visual_type == XINE_VISUAL_TYPE_X11) {
if (video_driver &&
( !strcasecmp(video_driver, "xshm") ||
!strcasecmp(video_driver, "xv") ||
!strcasecmp(video_driver, "xcbshm") ||
!strcasecmp(video_driver, "xcbxv") ||
!strcasecmp(video_driver, "opengl") ||
!strcasecmp(video_driver, "xvmc") ||
!strcasecmp(video_driver, "xxmc"))) {
LOGMSG("WARNING: Using inefficient legacy video driver %s\n", video_driver);
}
if (!video_driver) {
LOGMSG("WARNING: no video driver given. Trying OpenGL2.\n");
this->video_port = xine_open_video_driver(this->xine,
"opengl2",
this->xine_visual_type,
(void *) &(this->vis));
if (!this->video_port)
LOGMSG("Failed initializing OpenGL2 video output.\n");
}
}
/* create video port */
if (!this->video_port) {
if (video_driver && !strcmp(video_driver, "none"))
this->video_port = xine_open_video_driver(this->xine,
video_driver,
XINE_VISUAL_TYPE_NONE,
NULL);
else if (video_driver && !strcmp(video_driver, "dxr3"))
this->video_port = xine_open_video_driver(this->xine,
video_driver,
XINE_VISUAL_TYPE_X11,
NULL);
else if(video_driver && !strcmp(video_driver, "aadxr3"))
this->video_port = xine_open_video_driver(this->xine,
video_driver,
XINE_VISUAL_TYPE_AA,
NULL);
else
this->video_port = xine_open_video_driver(this->xine,
video_driver,
this->xine_visual_type,
(void *) &(this->vis));
}
if(!this->video_port) {
LOGMSG("fe_xine_init: xine_open_video_driver(\"%s\") failed",
video_driver?video_driver:"(NULL)");
this->fe.xine_exit(this_gen);
return 0;
}
intercept_video_driver(this->video_port);
if (this->frame_draw_cb) {
vo_driver_t *frameoutput = vo_frameoutput_init(this, this->frame_draw_cb);
if (frameoutput && !wire_video_driver(this->video_port, frameoutput)) {
LOGMSG("wire_video_driver() for frame output handler failed");
frameoutput->dispose(frameoutput);
}
}
this->video_port_none = NULL;
/* re-configure display size (DirectFB driver changes display mode in init) */
if(this->update_display_size_cb)
this->update_display_size_cb(this);
/* create audio port */
if(audio_driver && audio_port)
configure_audio_out(this, audio_driver, audio_port);
if(audio_driver && !strcmp(audio_driver, "auto")) {
this->audio_port = xine_open_audio_driver (this->xine, NULL, NULL);
#if XINE_VERSION_CODE < 10190
} else if(audio_driver && !strcmp(audio_driver, "none")) {
this->audio_port = _x_ao_new_port (this->xine, NULL, 1);
this->audio_port->set_property(this->audio_port, AO_PROP_DISCARD_BUFFERS, 1);
#endif
} else {
this->audio_port = xine_open_audio_driver (this->xine, audio_driver, NULL);
}
if(!this->audio_port && (audio_driver && !!strcmp(audio_driver, "none"))) {
LOGMSG("fe_xine_init: xine_open_audio_driver(\"%s%s%s\") failed",
audio_driver?audio_driver:"(NULL)",
audio_port?":":"", audio_port?audio_port:"");
}
this->audio_port_none = NULL;
/* create stream */
this->stream = xine_stream_new(this->xine, this->audio_port, this->video_port);
this->slave_stream = NULL;
if(!this->stream) {
LOGMSG("fe_xine_init: xine_stream_new failed");
this->fe.xine_exit(this_gen);
return 0;
}
/* event handling */
this->event_queue = xine_event_new_queue (this->stream);
xine_event_create_listener_thread (this->event_queue, xine_event_cb, this);
if(!this->event_queue)
LOGMSG("fe_xine_init: xine_event_new_queue failed");
/* misc. config */
this->pes_buffers = pes_buffers;
posts = this->postplugins = calloc(1, sizeof(post_plugins_t));
posts->xine = this->xine;
posts->audio_port = this->audio_port;
posts->video_port = this->video_port;
posts->video_source = posts->audio_source = this->stream;
/* multithreaded decoding / post processing */
if (!ffmpeg_threads)
ffmpeg_threads = guess_cpu_count();
if (ffmpeg_threads) {
if (ffmpeg_threads == 1)
LOGMSG("Disabling FFmpeg multithreaded video decoding");
else if (!xine_check_version(1,1,9))
LOGMSG("FFmpeg multithreaded video decoding is not supported in xine-lib < 1.1.9");
else
LOGMSG("Enabling FFmpeg multithreaded video decoding");
/* try to enable anyway, maybe someone is using patched 1.1.8 ... */
x_upd_num("video.processing.ffmpeg_thread_count", ffmpeg_threads);
#if 0
LOGMSG("Enabling multithreaded post processing");
vpplugin_parse_and_store_post(posts, "thread");
#endif
}
/* static post plugins from command-line */
if(static_post_plugins && *static_post_plugins) {
int i;
LOGDBG("static post plugins (from command line): %s", static_post_plugins);
posts->static_post_plugins = strdup(static_post_plugins);
vpplugin_parse_and_store_post(posts, posts->static_post_plugins);
applugin_parse_and_store_post(posts, posts->static_post_plugins);
for(i=0; i<posts->post_audio_elements_num; i++)
if(posts->post_audio_elements[i])
posts->post_audio_elements[i]->enable = 2;
for(i=0; i<posts->post_video_elements_num; i++)
if(posts->post_video_elements[i])
posts->post_video_elements[i]->enable = 2;
posts->post_video_enable = 1;
posts->post_audio_enable = 1;
}
this->video_width = this->video_height = 0;
return 1;
}
static void fe_shutdown_init(frontend_t *this_gen, const char *cmd, int timeout)
{
fe_t *this = (fe_t*)this_gen;
free(this->shutdown_cmd);
this->shutdown_cmd = cmd ? strdup(cmd) : NULL;
this->shutdown_timeout = timeout;
this->shutdown_time = (timeout <= 0) ? (time_t)-1 : time(NULL) + timeout;
}
/*
* fe_xine_open
*
* open xine stream
*/
static int fe_xine_open(frontend_t *this_gen, const char *mrl)
{
fe_t *this = (fe_t*)this_gen;
int result = 0;
char *url = NULL;
if(!this)
return 0;
this->input_plugin = NULL;
_xl_atomic_store(&this->playback_finished, 1);
_xl_atomic_store(&this->terminate_key_pressed, 0);
if (asprintf(&url, "%s#nocache", mrl ? : MRL_ID "://") < 0)
return 0;
result = xine_open(this->stream, url);
if(!result) {
LOGMSG("fe_xine_open: xine_open(\"%s\") failed", url);
free(url);
return 0;
}
free(url);
#if 0
this->xine->config->update_num(this->xine->config,
"video.output.xv_double_buffer",
1);
#endif
if (this->pes_buffers > 50)
x_upd_num("engine.buffers.video_num_buffers", this->pes_buffers);
return result;
}
/*
* post plugin handling
*
*/
#define POST_AUDIO_VIS 0
#define POST_AUDIO 1
#define POST_VIDEO 2
#define POST_VIDEO_PIP 3
static void init_dummy_ports(fe_t *this, int on)
{
if(!on) {
if(this->slave_stream)
LOGMSG("ERROR: init_dummy_ports(false) called while port is still in use !");
if(this->audio_port_none)
xine_close_audio_driver(this->xine, this->audio_port_none);
this->audio_port_none = NULL;
if(this->video_port_none)
xine_close_video_driver(this->xine, this->video_port_none);
this->video_port_none = NULL;
} else {
if(! this->audio_port_none)
#if XINE_VERSION_CODE < 10190
this->audio_port_none = _x_ao_new_port (this->xine, NULL, 1);
#else
this->audio_port_none = NULL;/*xine_new_framegrab_audio_port(this->xine);*/
#endif
if(this->audio_port_none)
this->audio_port_none->set_property(this->audio_port_none, AO_PROP_DISCARD_BUFFERS, 1);
/*LOGMSG("initialized dummy audio port %x", this->audio_port_none);*/
#if 0
if(! this->video_port_none)
this->video_port_none =
_x_vo_new_port(this->xine,
_x_load_video_output_plugin(this->xine, "none",
XINE_VISUAL_TYPE_NONE, NULL),
1);
this->video_port_none->set_property(this->video_port_none, VO_PROP_DISCARD_FRAMES, 1);
#endif
}
}
static void fe_post_unwire(fe_t *this)
{
if (!this || !this->stream)
return;
xine_post_out_t *vo_source = xine_get_video_source(this->stream);
xine_post_out_t *ao_source = xine_get_audio_source(this->stream);
if(this->slave_stream &&
this->slave_stream == this->postplugins->audio_source) {
LOGDBG("unwiring slave stream audio post plugins");
init_dummy_ports(this, 1);
if(ao_source && this->audio_port_none)
(void) xine_post_wire_audio_port(ao_source, this->audio_port_none);
ao_source = xine_get_audio_source(this->slave_stream);
if(ao_source && this->audio_port)
(void) xine_post_wire_audio_port(ao_source, this->audio_port);
} else {
LOGDBG("unwiring audio post plugins");
init_dummy_ports(this, 0);
if(ao_source && this->audio_port)
(void) xine_post_wire_audio_port(ao_source, this->audio_port);
}
if(this->slave_stream &&
this->slave_stream == this->postplugins->video_source) {
LOGDBG("unwiring slave stream video post plugins");
/*init_dummy_ports(this, 1);*/
/*(void) xine_post_wire_video_port(vo_source, this->video_port_none);*/
vo_source = xine_get_video_source(this->slave_stream);
if(vo_source && this->video_port)
(void) xine_post_wire_video_port(vo_source, this->video_port);
} else {
LOGDBG("unwiring video post plugins");
/*init_dummy_ports(this, 0);*/
if(vo_source && this->video_port)
(void) xine_post_wire_video_port(vo_source, this->video_port);
}
}
static void fe_post_rewire(const fe_t *this)
{
LOGDBG("re-wiring post plugins");
vpplugin_rewire_posts(this->postplugins);
applugin_rewire_posts(this->postplugins);
}
static void fe_post_unload(const fe_t *this)
{
if (this->postplugins) {
LOGDBG("unloading post plugins");
vpplugin_unload_post(this->postplugins, NULL);
applugin_unload_post(this->postplugins, NULL);
}
}
static void fe_post_close(const fe_t *this, const char *name, int which)
{
if(!this)
return;
post_plugins_t *posts = this->postplugins;
if(name && !strcmp(name, "AudioVisualization")) {
name = NULL;
which = POST_AUDIO_VIS;
}
if(name && !strcmp(name, "Pip")) {
name = NULL;
which = POST_VIDEO_PIP;
}
/* by name */
if(name) {
LOGDBG("closing post plugin: %s", name);
if(applugin_unload_post(posts, name)) {
/*LOGDBG(" * rewiring audio");*/
applugin_rewire_posts(posts);
return;
}
if(vpplugin_unload_post(posts, name)) {
/*LOGDBG(" * rewiring video");*/
vpplugin_rewire_posts(posts);
return;
}
return;
}
/* by type */
if(which == POST_AUDIO_VIS || which < 0) { /* audio visualization */
if(posts->post_vis_elements_num &&
posts->post_vis_elements &&
posts->post_vis_elements[0]) {
LOGDBG("Closing audio visualization post plugins");
if(applugin_unload_post(posts, posts->post_vis_elements[0]->name)) {
/*LOGDBG(" * rewiring audio");*/
applugin_rewire_posts(posts);
}
}
}
if(which == POST_AUDIO || which < 0) { /* audio effect(s) */
LOGDBG("Closing audio post plugins");
if(applugin_disable_post(posts, NULL)) {
/*LOGDBG(" * rewiring audio");*/
applugin_rewire_posts(posts);
}
}
if(which == POST_VIDEO || which < 0) { /* video effect(s) */
LOGDBG("Closing video post plugins");
if(vpplugin_unload_post(posts, NULL)) {
/*LOGDBG(" * rewiring video");*/
vpplugin_rewire_posts(posts);
}
}
if(which == POST_VIDEO_PIP || which < 0) { /* Picture-In-Picture */
if(posts->post_pip_elements_num &&
posts->post_pip_elements &&
posts->post_pip_elements[0]) {
LOGDBG("Closing PIP (mosaico) post plugins");
if(vpplugin_unload_post(posts, "mosaico")) {
/*LOGDBG(" * rewiring video");*/
vpplugin_rewire_posts(posts);
}
}
}
}
static int get_opt_val(const char *s, const char *opt)
{
int val = -1;
const char *pt = strstr(s, opt);
if(pt)
if(1 == sscanf(pt+strlen(opt)+1, "%d", &val))
return val;
return -1;
}
static void fe_post_open(const fe_t *this, const char *name, const char *args)
{
if(!this || !this->xine || !this->stream || !name)
return;
post_plugins_t *posts = this->postplugins;
char initstr[1024];
int found = 0;
/* pip */
if(!strcmp(name, "Pip")) {
posts->post_pip_enable = 1;
name = "mosaico";
if(!posts->post_pip_elements ||
!posts->post_vis_elements[0] ||
!posts->post_vis_elements[0]->enable)
LOGMSG("enabling picture-in-picture (\"%s:%s\") post plugin", name, args);
}
if(args) {
snprintf(initstr, sizeof(initstr), "%s:%s", name, args);
initstr[sizeof(initstr)-1] = 0;
} else
strn0cpy(initstr, name, sizeof(initstr));
/* swscale aspect ratio */
if (!strcmp(name, "swscale")) {
char *pt = strstr(initstr, "output_aspect=auto");
if (pt) {
char tmp[16];
double r = 0.0;
pt += 14;
switch(this->aspect) {
case 0:
case 1: /* */ r = this->display_ratio * (double)this->width / (double)this->height; break;
case 2: /* 4:3 */ r = 4.0/3.0; break;
case 3: /* 16:9 */ r = 16.0/9.0; break;
case 4: /* 16:10 */ r = 16.0/10.0; break;
default: LOGDBG("%s(%d): unknown aspect: %d", __FUNCTION__, __LINE__, this->aspect);
}
/* in finnish locale decimal separator is "," - same as post plugin parameter separator :( */
sprintf(tmp, "%04d", (int)(r*1000.0));
memcpy(pt, tmp, 4);
}
}
LOGDBG("opening post plugin: %s", initstr);
/* close old audio visualization plugin */
if(!strcmp(name,"goom") ||
!strcmp(name,"oscope") ||
!strcmp(name,"fftscope") ||
!strcmp(name,"fftgraph") ||
!strcmp(name,"fooviz")) {
/* close if changed */
if(posts->post_vis_elements_num &&
posts->post_vis_elements &&
posts->post_vis_elements[0] &&
strcmp(name, posts->post_vis_elements[0]->name)) {
fe_post_close(this, NULL, POST_AUDIO_VIS);
}
if(!found && applugin_enable_post(posts, initstr, &found)) {
posts->post_vis_enable = 1;
applugin_rewire_posts(posts);
// goom wants options thru config ...
if(args && !strcmp(name,"goom")) {
int val;
if((val = get_opt_val(initstr, "fps")) > 0)
x_upd_num ("effects.goom.fps", val );
if((val = get_opt_val(initstr, "width")) > 0)
x_upd_num ("effects.goom.width", val);
if((val = get_opt_val(initstr, "height")) > 0)
x_upd_num ("effects.goom.height", val);
//if((val = get_opt_val(initstr, "csc_method"))>0)
// this->xine->config->update_enum (this->xine->config, "effects.goom.csc_method", val);
}
}
} else {
/* video filters */
if(strcmp(name, "audiochannel") &&
strcmp(name, "volnorm") &&
strcmp(name, "stretch") &&
strcmp(name, "upmix_mono") &&
strcmp(name, "upmix") &&
vpplugin_enable_post(posts, initstr, &found)) {
posts->post_video_enable = 1;
vpplugin_rewire_posts(posts);
}
/* audio filters */
if(!found && applugin_enable_post(posts, initstr, &found)) {
posts->post_audio_enable = 1;
applugin_rewire_posts(posts);
}
}
if(!found)
LOGMSG("Can't load post plugin %s", name);
else
LOGDBG("Post plugin %s loaded and wired", name);
}
static void input_event_cb(frontend_t *this_gen, const char *keymap, const char *key)
{
fe_t *this = (fe_t*)this_gen;
if (this->fe.fe_message_cb) {
this->fe.fe_message_cb(this->fe.fe_message_h, keymap, key);
}
}
static int fe_xine_play(frontend_t *this_gen)
{
fe_t *this = (fe_t*)this_gen;
int status;
if(!this)
return 0;
fe_post_rewire(this);
this->input_plugin = NULL;
status = xine_play(this->stream, 0, 0) ? 0 : 1;
_xl_atomic_store(&this->playback_finished, status);
if(!find_input_plugin(this))
return -1;
this->input_plugin->f.xine_input_event = this->fe.fe_message_cb ? input_event_cb : NULL;
this->input_plugin->f.fe_control = fe_control;
this->input_plugin->f.fe_handle = this_gen;
if (_xl_atomic_load(&this->playback_finished))
LOGMSG("Error playing " MRL_ID ":// !");
char str[128];
snprintf(str, sizeof(str), "INFO WINDOW %dx%d", this->width, this->height);
this->fe.send_event(&this->fe, str);
return !_xl_atomic_load(&this->playback_finished);
}
static int fe_xine_stop(frontend_t *this_gen)
{
fe_t *this = (fe_t*)this_gen;
if(!this)
return 0;
this->input_plugin = NULL;
_xl_atomic_store(&this->playback_finished, 1);
if (!this->stream)
return 0;
xine_stop(this->stream);
fe_post_unwire(this);
return 1;
}
static void fe_xine_close(frontend_t *this_gen)
{
fe_t *this = (fe_t*)this_gen;
if(!this)
return;
if (this && this->xine) {
if(this->input_plugin) {
this->input_plugin->f.xine_input_event = NULL;
this->input_plugin->f.fe_control = NULL;
}
if (!this->stream)
return;
fe_xine_stop(this_gen);
xine_close(this->stream);
if (this->postplugins->pip_stream)
xine_close(this->postplugins->pip_stream);
}
}
static void fe_xine_exit(frontend_t *this_gen)
{
fe_t *this = (fe_t*)this_gen;
if (this && this->xine) {
if(this->input_plugin || !_xl_atomic_load(&this->playback_finished))
fe_xine_close(this_gen);
fe_post_unload(this);
if(this->configfile) {
xine_config_save (this->xine, this->configfile);
free(this->configfile);
this->configfile = NULL;
}
if(this->event_queue)
xine_event_dispose_queue(this->event_queue);
this->event_queue = NULL;
if(this->stream)
xine_dispose(this->stream);
this->stream = NULL;
if (this->postplugins) {
if (this->postplugins->pip_stream)
xine_dispose(this->postplugins->pip_stream);
this->postplugins->pip_stream = NULL;
free(this->postplugins->static_post_plugins);
}
free(this->postplugins);
this->postplugins = NULL;
if(this->slave_stream)
xine_dispose(this->slave_stream);
this->slave_stream = NULL;
if(this->audio_port)
xine_close_audio_driver(this->xine, this->audio_port);
this->audio_port = NULL;
init_dummy_ports(this, 0);
if(this->video_port)
xine_close_video_driver(this->xine, this->video_port);
this->video_port = NULL;
xine_exit(this->xine);
this->xine = NULL;
}
}
static void fe_free(frontend_t *this_gen)
{
if (this_gen) {
fe_t *this = (fe_t*)this_gen;
this->fe.fe_display_close(this_gen);
pthread_mutex_destroy(&this->geom_mutex);
free(this->configfile);
free(this->shutdown_cmd);
free(this);
}
}
static int fe_is_finished(frontend_t *this_gen, int slave_stream)
{
fe_t *this = (fe_t*)this_gen;
if (!this)
return FE_XINE_ERROR;
if (_xl_atomic_load(&this->terminate_key_pressed))
return FE_XINE_EXIT;
if (_xl_atomic_load(&this->playback_finished))
return FE_XINE_ERROR;
if (slave_stream) {
if (!this->slave_stream || this->slave_playback_finished)
return FE_XINE_EXIT;
}
/* check inactivity timer */
if (this->shutdown_timeout > 0) {
if (this->shutdown_time < time(NULL)) {
shutdown_system(this->shutdown_cmd, 0);
return FE_XINE_EXIT;
}
}
return FE_XINE_RUNNING;
}
/************************** hooks to input plugin ****************************/
/*
* data/control from VDR
*/
static int xine_control(frontend_t *this_gen, const char *cmd)
{
fe_t *this = (fe_t*)this_gen;
if(!find_input_plugin(this))
return -1;
return this->input_plugin->f.push_input_control(this->input_plugin, cmd);
}
static int xine_osd_command(frontend_t *this_gen, struct osd_command_s *cmd) {
fe_t *this = (fe_t*)this_gen;
if(!find_input_plugin(this))
return -1;
return this->input_plugin->f.push_input_osd(this->input_plugin, cmd);
}
static int xine_queue_pes_packet(frontend_t *this_gen, int stream, uint64_t pos, const char *data, int len)
{
fe_t *this = (fe_t*)this_gen;
if(!find_input_plugin(this))
return 0/*-1*/;
return this->input_plugin->f.push_input_write(this->input_plugin, stream, pos, data, len);
}
/*
* control from frontend to xine/vdr
*/
static int fe_send_input_event(frontend_t *this_gen, const char *map,
const char *key, int repeat, int release)
{
fe_t *this = (fe_t*)this_gen;
LOGDBG("Keypress: %s %s %s %s",
map, key, repeat?"Repeat":"", release?"Release":"");
/* reset inactivity timer */
if (this->shutdown_timeout > 0)
this->shutdown_time = time(NULL) + this->shutdown_timeout;
/* local mode: --> vdr callback */
if (this->fe.fe_message_cb) {
this->fe.fe_message_cb(this->fe.fe_message_h, map, key);
return FE_OK;
}
/* remote mode: --> input plugin --> vdr */
if (find_input_plugin(this)) {
char *msg = NULL;
if (map) {
if (asprintf(&msg, "KEY %s %s %s %s\r\n", map, key,
repeat?"Repeat":"", release?"Release":"") < 0)
msg = NULL;
} else {
if (asprintf(&msg, "KEY %s\r\n", key) < 0)
msg = NULL;
}
if (msg) {
const xine_event_t event = {
.type = XINE_EVENT_XVDR_EVENT,
.stream = this->stream,
.data = msg,
.data_length = strlen(msg) + 1,
};
xine_event_send(this->stream, &event);
free(msg);
return FE_OK;
}
}
LOGMSG("fe_send_input_event: message KEY %s lost (no input plugin)", key);
return FE_ERROR;
}
static int fe_send_event(frontend_t *this_gen, const char *data)
{
fe_t *this = (fe_t*)this_gen;
if (!data)
return FE_ERROR;
if (!strcmp(data, "TOGGLE_FULLSCREEN")) {
if(this->toggle_fullscreen_cb)
this->toggle_fullscreen_cb(this, -1);
} else if (!strncasecmp(data, "FULLSCREEN ", 11)) {
if(this->toggle_fullscreen_cb)
this->toggle_fullscreen_cb(this, atoi(data+11) ? 1: 0);
} else if (!strcmp(data, "QUIT")) {
_xl_atomic_store(&this->terminate_key_pressed, 1);
} else if(!strcmp(data, "TOGGLE_DEINTERLACE")) {
xine_set_param(this->stream, XINE_PARAM_VO_DEINTERLACE,
xine_get_param(this->stream, XINE_PARAM_VO_DEINTERLACE) ? 0 : 1);
} else if(!strncasecmp(data, "DEINTERLACE ", 12)) {
xine_set_param(this->stream, XINE_PARAM_VO_DEINTERLACE, atoi(data+12) ? 1 : 0);
} else if (!strcmp(data, "POWER_OFF")) {
shutdown_system(this->shutdown_cmd, 1);
} else {
LOGDBG("Event: %s", data);
/* local mode: --> vdr callback */
if (this->fe.fe_message_cb) {
this->fe.fe_message_cb(this->fe.fe_message_h, data, NULL);
return FE_OK;
}
/* remote mode: --> input plugin --> vdr */
if (find_input_plugin(this)) {
char *msg = NULL;
if (asprintf(&msg, "%s\r\n", data) < 1)
msg = NULL;
if (msg) {
const xine_event_t event = {
.type = XINE_EVENT_XVDR_EVENT,
.stream = this->stream,
.data = msg,
.data_length = strlen(msg) + 1,
};
xine_event_send(this->stream, &event);
}
free(msg);
return FE_OK;
}
LOGMSG("EVENT %s Lost (no input plugin)", data);
return FE_ERROR;
}
return FE_OK;
}
/*
* Control messages from input plugin
*/
static void *fe_control(frontend_t *this_gen, const char *cmd)
{
fe_t *this = (fe_t*)this_gen;
post_plugins_t *posts;
/*LOGDBG("fe_control(\"%s\")", cmd);*/
if(!cmd || !this) {
LOGMSG("fe_control(%p,%p) : invalid argument",
(const void *)this_gen, (const void *)cmd);
return NULL;
}
posts = this->postplugins;
if(!posts) {
LOGMSG("fe_control : this->posts == NULL");
return NULL;
}
if(!strncmp(cmd, "SLAVE CLOSED", 12)) {
/*LOGMSG("fe_control : slave closed");*/
if(this->slave_stream)
fe_control(this_gen, "SLAVE 0x0\r\n");
init_dummy_ports(this, 0);
this->video_width = this->video_height = 0;
} else if(!strncmp(cmd, "SLAVE ", 6)) {
void *pt;
if(1 == sscanf(cmd+6, "%p", &pt)) {
xine_stream_t *slave_stream = (xine_stream_t*)pt;
if(this->slave_stream != slave_stream) {
fe_post_unwire(this);
if(this->slave_stream) {
/*xine_post_out_t *vo_source = xine_get_video_source(posts->slave_stream);*/
if(this->slave_stream == this->postplugins->audio_source) {
xine_post_out_t *ao_source = xine_get_audio_source(this->slave_stream);
LOGMSG("unwiring slave stream from output");
/*(void) xine_post_wire_video_port(vo_source, this->video_port_none);*/
(void) xine_post_wire_audio_port(ao_source, this->audio_port_none);
}
}
this->slave_stream = slave_stream;
this->postplugins->video_source = this->postplugins->audio_source =
this->slave_stream ?: this->stream;
if(strstr(cmd, "Video")) /* video only, audio from VDR */
this->postplugins->audio_source = this->stream;
if(strstr(cmd, "Audio")) /* audio only, video from VDR */
this->postplugins->video_source = this->stream;
if(this->slave_stream)
fe_post_unwire(this);
fe_post_rewire(this);
}
this->slave_playback_finished = !slave_stream;
this->video_width = this->video_height = 0;
}
} else if(!strncmp(cmd, "ENDOFSTREAM", 11)) {
if(this->slave_stream)
this->slave_playback_finished = 1;
} else if(!strncmp(cmd, "SUBSTREAM ", 10)) {
unsigned int pid;
int x, y, w, h;
if(5 == sscanf(cmd+10, "0x%x %d %d %d %d", &pid, &x, &y, &w, &h)) {
char mrl[256];
if(!posts->pip_stream)
posts->pip_stream = xine_stream_new(this->xine,
this->audio_port,
this->video_port);
LOGMSG(" PIP %d: %dx%d @ (%d,%d)", pid & 0x0f, w, h, x, y);
LOGMSG("create pip stream done");
sprintf(mrl, MRL_ID "+slave://%p#nocache",
(void *)this);
if(!xine_open(posts->pip_stream, mrl) ||
!xine_play(posts->pip_stream, 0, 0)) {
LOGERR(" pip stream open/play failed");
} else {
char params[64];
sprintf(params, "pip_num=1,x=%d,y=%d,w=%d,h=%d", x,y,w,h);
fe_post_open(this, "Pip", params);
return posts->pip_stream;
}
}
fe_post_close(this, NULL, POST_VIDEO_PIP);
if(posts->pip_stream) {
xine_close(posts->pip_stream);
xine_dispose(posts->pip_stream);
posts->pip_stream = NULL;
}
return NULL;
} else if(!strncmp(cmd, "POST ", 5)) {
char *name = strdup(cmd+5), *args = name, *pt;
if(NULL != (pt=strchr(name, '\r')))
*pt = 0;
if(NULL != (pt=strchr(name, '\n')))
*pt = 0;
while(*args && *args != ' ') /* skip name */
args++;
if(*args /*== ' '*/)
*args++ = 0;
while(*args && *args == ' ') /* skip whitespace between name and args */
args++;
/*this->stream->xine->port_ticket->acquire(this->stream->xine->port_ticket, 0);*/
/* - locks local frontend at startup */
if(!strncmp(args, "On", 2)) {
args += 2;
while(*args == ' ')
args++;
/*LOGDBG(" POST: %s On \"%s\"", name, args);*/
fe_post_open(this, name, args);
} else if(!strncmp(args, "Off", 3)) {
/*LOGDBG(" POST: %s Off (name len=%d), name => int = %d", name, strlen(name), atoi(name));*/
if(strlen(name) == 1)
fe_post_close(this, NULL, atoi(name));
else
fe_post_close(this, name, -1);
} else {
LOGMSG("fe_control: POST: unknown command %s", cmd);
}
/*this->stream->xine->port_ticket->release(this->stream->xine->port_ticket, 0);*/
/* - locks local frontend at startup */
free(name);
return NULL;
} else if(!strncmp(cmd, "GRAB ", 5)) {
int quality, width, height, jpeg, size=0;
jpeg = !strncmp(cmd+5,"JPEG",4);
if(3 == sscanf(cmd+5+4, "%d %d %d", &quality, &width, &height)) {
grab_data_t *result = (grab_data_t*)malloc(sizeof(grab_data_t));
if (result) {
result->data = this->fe.grab((frontend_t*)this, &size,
jpeg, quality, width, height);
if(result->data && (result->size=size)>0)
return result;
free(result->data);
free(result);
}
}
} else if(!strncmp(cmd, "OVERSCAN ", 9)) {
int overscan;
if(1 == sscanf(cmd+9, "%d", &overscan)) {
int crop_x = overscan * this->width / 100 / 2;
int crop_y = overscan * this->height / 100 / 2;
/*this->overscan = overscan;*/
xine_set_param(this->stream, XINE_PARAM_VO_CROP_LEFT, crop_x);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_TOP, crop_y);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_RIGHT, crop_x);
xine_set_param(this->stream, XINE_PARAM_VO_CROP_BOTTOM, crop_y);
/* trigger forced redraw to make changes effective */
xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, 100);
}
}
return NULL;
}
/*
* --- RgbToJpeg -------------------------------------------------------------
*
* source: vdr-1.3.42, tools.c
* modified to accept YUV data
*
* - move to xine_input_vdr ?
*/
#ifdef HAVE_LIBJPEG
#define JPEGCOMPRESSMEM 500000
typedef struct tJpegCompressData_s {
int size;
unsigned char *mem;
} tJpegCompressData;
static void JpegCompressInitDestination(const j_compress_ptr cinfo)
{
tJpegCompressData *jcd = (tJpegCompressData *)cinfo->client_data;
if (jcd) {
cinfo->dest->free_in_buffer = jcd->size = JPEGCOMPRESSMEM;
cinfo->dest->next_output_byte = jcd->mem =
(unsigned char *)malloc(jcd->size);
}
}
static boolean JpegCompressEmptyOutputBuffer(const j_compress_ptr cinfo)
{
tJpegCompressData *jcd = (tJpegCompressData *)cinfo->client_data;
if (jcd) {
int Used = jcd->size;
jcd->size += JPEGCOMPRESSMEM;
jcd->mem = (unsigned char *)realloc(jcd->mem, jcd->size);
if (jcd->mem) {
cinfo->dest->next_output_byte = jcd->mem + Used;
cinfo->dest->free_in_buffer = jcd->size - Used;
return TRUE;
}
}
return FALSE;
}
static void JpegCompressTermDestination(const j_compress_ptr cinfo)
{
tJpegCompressData *jcd = (tJpegCompressData *)cinfo->client_data;
if (jcd) {
int Used = cinfo->dest->next_output_byte - jcd->mem;
if (Used < jcd->size) {
jcd->size = Used;
jcd->mem = (unsigned char *)realloc(jcd->mem, jcd->size);
}
}
}
#ifndef HAVE_XINE_GRAB_VIDEO_FRAME
static vo_frame_t *yuy2_to_yv12_frame(xine_stream_t *stream, vo_frame_t *frame)
{
/* convert yuy12 frames to yv12 */
if (frame && frame->format == XINE_IMGFMT_YUY2) {
vo_frame_t *img = NULL;
if (_x_lock_port_rewiring(stream->xine, 0)) {
img = stream->video_out->get_frame (stream->video_out,
frame->width, frame->height,
frame->ratio, XINE_IMGFMT_YV12,
VO_BOTH_FIELDS);
_x_unlock_port_rewiring(stream->xine);
}
if (!img) {
LOGMSG("yuy2_to_yv12_frame: get_frame failed");
frame->free(frame);
return NULL;
}
init_yuv_conversion();
yuy2_to_yv12(frame->base[0], frame->pitches[0],
img->base[0], img->pitches[0],
img->base[1], img->pitches[1],
img->base[2], img->pitches[2],
frame->width, frame->height);
frame->free(frame);
return img;
}
return frame;
}
static char *frame_compress_jpeg(fe_t *this, int *size, int quality, vo_frame_t *frame)
{
struct jpeg_destination_mgr jdm;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
tJpegCompressData jcd;
/* convert yuy2 frames to yv12 */
frame = yuy2_to_yv12_frame(this->stream, frame);
if (!frame)
return NULL;
/* Compress JPEG */
jdm.init_destination = JpegCompressInitDestination;
jdm.empty_output_buffer = JpegCompressEmptyOutputBuffer;
jdm.term_destination = JpegCompressTermDestination;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
cinfo.dest = &jdm;
cinfo.client_data = &jcd;
cinfo.image_width = frame->width;
cinfo.image_height = frame->height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_YCbCr;
switch (frame->format) {
case XINE_IMGFMT_YV12: {
JSAMPARRAY pp[3];
JSAMPROW *rpY = (JSAMPROW*)malloc(sizeof(JSAMPROW) * frame->height);
JSAMPROW *rpU = (JSAMPROW*)malloc(sizeof(JSAMPROW) * frame->height);
JSAMPROW *rpV = (JSAMPROW*)malloc(sizeof(JSAMPROW) * frame->height);
int k;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
cinfo.raw_data_in = TRUE;
#if JPEG_LIB_VERSION >= 70
cinfo.do_fancy_downsampling = FALSE;
#endif
jpeg_set_colorspace(&cinfo, JCS_YCbCr);
cinfo.comp_info[0].h_samp_factor =
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor =
cinfo.comp_info[1].v_samp_factor =
cinfo.comp_info[2].h_samp_factor =
cinfo.comp_info[2].v_samp_factor = 1;
jpeg_start_compress(&cinfo, TRUE);
for (k = 0; k < frame->height; k+=2) {
rpY[k] = frame->base[0] + k*frame->pitches[0];
rpY[k+1] = frame->base[0] + (k+1)*frame->pitches[0];
rpU[k/2] = frame->base[1] + (k/2)*frame->pitches[1];
rpV[k/2] = frame->base[2] + (k/2)*frame->pitches[2];
}
for (k = 0; k < frame->height; k+=2*DCTSIZE) {
pp[0] = &rpY[k];
pp[1] = &rpU[k/2];
pp[2] = &rpV[k/2];
jpeg_write_raw_data(&cinfo, pp, 2*DCTSIZE);
}
free(rpY);
free(rpU);
free(rpV);
break;
}
#if 0
case XINE_IMGFMT_RGB: {
JSAMPROW rp[height];
int rs, k;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
rs = frame->pitches[0];
for (k = 0; k < height; k++)
rp[k] = frame->base[0] + k*rs;
jpeg_write_scanlines(&cinfo, rp, height);
break;
}
#endif
default:
LOGMSG("fe_grab: grabbing failed (unsupported image format %d)",
frame->format);
break;
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
frame->free(frame);
*size = jcd.size;
return (char*) jcd.mem;
}
#endif /* HAVE_XINE_GRAB_VIDEO_FRAME */
#endif /* HAVE_LIBJPEG */
#ifndef HAVE_XINE_GRAB_VIDEO_FRAME
static vo_frame_t *yv12_to_yuy2_frame(xine_stream_t *stream, vo_frame_t *frame)
{
/* convert yv12 frames to yuy2 */
if (frame && frame->format == XINE_IMGFMT_YV12) {
vo_frame_t *img = NULL;
if (_x_lock_port_rewiring(stream->xine, 0)) {
img = stream->video_out->get_frame (stream->video_out,
frame->width, frame->height,
frame->ratio, XINE_IMGFMT_YUY2,
VO_BOTH_FIELDS);
_x_unlock_port_rewiring(stream->xine);
}
if (!img) {
LOGMSG("yv12_to_yuy2_frame: get_frame failed");
frame->free(frame);
return NULL;
}
init_yuv_conversion();
yv12_to_yuy2(frame->base[0], frame->pitches[0],
frame->base[1], frame->pitches[1],
frame->base[2], frame->pitches[2],
img->base[0], img->pitches[0],
frame->width, frame->height,
frame->progressive_frame);
frame->free(frame);
return img;
}
return frame;
}
#define YCBCR_TO_RGB( y, cb, cr, r, g, b ) \
do { \
int _y, _cb, _cr, _r, _g, _b; \
_y = ((y) - 16) * 76309; \
_cb = (cb) - 128; \
_cr = (cr) - 128; \
_r = (_y + _cr * 104597 + 0x8000) >> 16; \
_g = (_y - _cb * 25675 - _cr * 53279 + 0x8000) >> 16; \
_b = (_y + _cb * 132201 + 0x8000) >> 16; \
(r) = (_r < 0) ? 0 : ((_r > 255) ? 255 : _r); \
(g) = (_g < 0) ? 0 : ((_g > 255) ? 255 : _g); \
(b) = (_b < 0) ? 0 : ((_b > 255) ? 255 : _b); \
} while (0)
static char *frame_compress_pnm(fe_t *this, int *size, vo_frame_t *frame)
{
/* ensure yuy2 */
if (!(frame = yv12_to_yuy2_frame(this->stream, frame)))
return NULL;
/* convert to PNM */
/* allocate memory for result */
size_t bytes = frame->width * frame->height * 3;
uint8_t *pnm = malloc(bytes + 64);
if (!pnm) {
LOGMSG("fe_grab: malloc failed");
return NULL;
}
/* PNM header */
sprintf((char*)pnm, "P6\n%d\n%d\n255\n", frame->width, frame->height);
int hdrlen = strlen((char*)pnm);
uint8_t *p = pnm + hdrlen;
uint8_t *s = frame->base[0];
int x, y;
*size = bytes + hdrlen;
/* convert to RGB */
for (y=0; y < frame->height; y++) {
for (x=0; x < frame->width; x+=2, s+=4, p+=6) {
YCBCR_TO_RGB(s[0], s[1], s[3], p[0], p[1], p[2]);
YCBCR_TO_RGB(s[2], s[1], s[3], p[3], p[4], p[5]);
}
s = frame->base[0] + y*frame->pitches[0];
}
return (char*)pnm;
}
#endif /* HAVE_XINE_GRAB_VIDEO_FRAME */
#ifdef HAVE_XINE_GRAB_VIDEO_FRAME
static char *fe_compress_grab_frame(int *size, int jpeg, int quality, int width, int height, xine_grab_video_frame_t *frame)
{
#ifdef HAVE_LIBJPEG
if (jpeg) {
/* Compress JPEG */
struct jpeg_destination_mgr jdm;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
tJpegCompressData jcd;
jdm.init_destination = JpegCompressInitDestination;
jdm.empty_output_buffer = JpegCompressEmptyOutputBuffer;
jdm.term_destination = JpegCompressTermDestination;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
cinfo.dest = &jdm;
cinfo.client_data = &jcd;
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
JSAMPROW rp[height];
int rs = width * 3;
int k;
for (k = 0; k < height; k++)
rp[k] = frame->img + k * rs;
jpeg_write_scanlines(&cinfo, rp, height);
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
*size = jcd.size;
return (char*) jcd.mem;
}
#endif
/* convert to PNM */
/* allocate memory for result */
size_t bytes = width * height * 3;
uint8_t *pnm = malloc(bytes + 64);
if (!pnm) {
LOGMSG("fe_grab: malloc failed");
return NULL;
}
/* PNM header */
sprintf((char*)pnm, "P6\n%d\n%d\n255\n", width, height);
int hdrlen = strlen((char*)pnm);
/* copy image */
xine_fast_memcpy(pnm + hdrlen, frame->img, bytes);
*size = bytes + hdrlen;
return (char*)pnm;
}
#endif /* HAVE_XINE_GRAB_VIDEO_FRAME */
static char *fe_grab(frontend_t *this_gen, int *size, int jpeg,
int quality, int width, int height)
{
fe_t *this = (fe_t*)this_gen;
#ifndef HAVE_LIBJPEG
if(jpeg) {
LOGMSG("fe_grab: JPEG grab support was not compiled in");
return 0;
}
#endif /* HAVE_LIBJPEG */
if(!find_input_plugin(this))
return 0;
LOGDBG("fe_grab: grabbing %s %d %dx%d",
jpeg ? "JPEG" : "PNM", quality, width, height);
/* validate parameters */
if ((quality < 0) || (quality > 100))
quality = 100;
width = (MAX(16, MIN(width, 1920)) + 1) & ~1; /* 16...1920, even */
height = (MAX(16, MIN(height, 1200)) + 1) & ~1; /* 16...1200, even */
/* get last frame */
#ifdef HAVE_XINE_GRAB_VIDEO_FRAME
xine_grab_video_frame_t *grab_frame = NULL;
char *img = NULL;
if (_x_lock_port_rewiring(this->xine, 0)) {
grab_frame = xine_new_grab_video_frame(this->stream);
_x_unlock_port_rewiring(this->xine);
}
if (grab_frame) {
grab_frame->width = width;
grab_frame->height = height;
if (!grab_frame->grab(grab_frame))
img = fe_compress_grab_frame(size, jpeg, quality, width, height, grab_frame);
grab_frame->dispose(grab_frame);
}
return img;
#else
vo_frame_t *frame = NULL;
if (_x_lock_port_rewiring(this->xine, 0)) {
frame = this->stream->video_out->get_last_frame (this->stream->video_out);
#if XINE_VERSION_CODE < 10190
if (frame)
frame->lock(frame);
#endif
_x_unlock_port_rewiring(this->xine);
}
if(!frame) {
LOGMSG("fe_grab: get_last_frame() failed");
return NULL;
}
/* Scale image */
if (frame->width != width || frame->height != height) {
/* #warning TODO - scaling here */
LOGMSG("fe_grab: scaling not implemented");
}
if (!jpeg)
return frame_compress_pnm(this, size, frame);
#ifdef HAVE_LIBJPEG
return frame_compress_jpeg(this, size, quality, frame);
#else /* HAVE_LIBJPEG */
return NULL;
#endif
#endif /* HAVE_XINE_GRAB_VIDEO_FRAME */
}
/*
* init_fe()
*
* initialize function pointers
*/
void init_fe(fe_t *fe)
{
fe->fe.xine_init = fe_xine_init;
fe->fe.xine_open = fe_xine_open;
fe->fe.xine_play = fe_xine_play;
fe->fe.xine_stop = fe_xine_stop;
fe->fe.xine_close = fe_xine_close;
fe->fe.xine_exit = fe_xine_exit;
fe->fe.shutdown_init = fe_shutdown_init;
fe->fe.fe_free = fe_free;
fe->fe.xine_is_finished = fe_is_finished;
fe->fe.xine_osd_command = xine_osd_command;
fe->fe.xine_control = xine_control;
fe->fe.xine_queue_pes_packet = xine_queue_pes_packet;
fe->fe.grab = fe_grab;
fe->fe.send_event = fe_send_event;
fe->fe.send_input_event = fe_send_input_event;
fe->dest_pixel_aspect = fe_dest_pixel_aspect;
fe->frame_output_handler = fe_frame_output_cb;
_xl_atomic_init(&fe->playback_finished, 0);
_xl_atomic_init(&fe->terminate_key_pressed, 0);
pthread_mutex_init(&fe->geom_mutex, NULL);
}
|