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
|
/*****************************************************************************
* bdagraph.cpp : DirectShow BDA graph for vlc
*****************************************************************************
* Copyright( C ) 2007 the VideoLAN team
*
* Author: Ken Self <kenself(at)optusnet(dot)com(dot)au>
*
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "bdagraph.h"
#include <ctype.h>
/****************************************************************************
* Interfaces for calls from C
****************************************************************************/
extern "C" {
void dvb_newBDAGraph( access_t* p_access )
{
p_access->p_sys->p_bda_module = new BDAGraph( p_access );
};
void dvb_deleteBDAGraph( access_t* p_access )
{
delete p_access->p_sys->p_bda_module;
};
int dvb_SubmitATSCTuneRequest( access_t* p_access )
{
if( p_access->p_sys->p_bda_module )
return p_access->p_sys->p_bda_module->SubmitATSCTuneRequest();
return VLC_EGENERIC;
};
int dvb_SubmitDVBTTuneRequest( access_t* p_access )
{
if( p_access->p_sys->p_bda_module )
return p_access->p_sys->p_bda_module->SubmitDVBTTuneRequest();
return VLC_EGENERIC;
};
int dvb_SubmitDVBCTuneRequest( access_t* p_access )
{
if( p_access->p_sys->p_bda_module )
return p_access->p_sys->p_bda_module->SubmitDVBCTuneRequest();
return VLC_EGENERIC;
};
int dvb_SubmitDVBSTuneRequest( access_t* p_access )
{
if( p_access->p_sys->p_bda_module )
return p_access->p_sys->p_bda_module->SubmitDVBSTuneRequest();
return VLC_EGENERIC;
};
block_t *dvb_Pop( access_t* p_access )
{
if( p_access->p_sys->p_bda_module )
return p_access->p_sys->p_bda_module->Pop();
return NULL;
};
};
/*****************************************************************************
* BDAOutput
*****************************************************************************/
BDAOutput::BDAOutput( access_t *p_access ) :
p_access(p_access), p_first(NULL), pp_next(&p_first)
{
vlc_mutex_init( &lock );
vlc_cond_init( &wait );
}
BDAOutput::~BDAOutput()
{
Empty();
vlc_mutex_destroy( &lock );
vlc_cond_destroy( &wait );
}
void BDAOutput::Push( block_t *p_block )
{
vlc_mutex_locker l( &lock );
block_ChainLastAppend( &pp_next, p_block );
vlc_cond_signal( &wait );
}
block_t *BDAOutput::Pop()
{
vlc_mutex_locker l( &lock );
if( !p_first )
vlc_cond_timedwait( &wait, &lock, mdate() + 250*1000 );
block_t *p_ret = p_first;
p_first = NULL;
pp_next = &p_first;
return p_ret;
}
void BDAOutput::Empty()
{
vlc_mutex_locker l( &lock );
if( p_first )
block_ChainRelease( p_first );
p_first = NULL;
pp_next = &p_first;
}
/*****************************************************************************
* Constructor
*****************************************************************************/
BDAGraph::BDAGraph( access_t* p_this ):
p_access( p_this ),
guid_network_type(GUID_NULL),
l_tuner_used(-1),
d_graph_register( 0 ),
output( p_this )
{
p_tuning_space = NULL;
p_tune_request = NULL;
p_media_control = NULL;
p_filter_graph = NULL;
p_system_dev_enum = NULL;
p_network_provider = p_tuner_device = p_capture_device = NULL;
p_sample_grabber = p_mpeg_demux = p_transport_info = NULL;
p_scanning_tuner = NULL;
p_grabber = NULL;
/* Initialize COM - MS says to use CoInitializeEx in preference to
* CoInitialize */
CoInitializeEx( 0, COINIT_APARTMENTTHREADED );
}
/*****************************************************************************
* Destructor
*****************************************************************************/
BDAGraph::~BDAGraph()
{
Destroy();
CoUninitialize();
}
/*****************************************************************************
* Submit an ATSC Tune Request
*****************************************************************************/
int BDAGraph::SubmitATSCTuneRequest()
{
HRESULT hr = S_OK;
class localComPtr
{
public:
IATSCChannelTuneRequest* p_atsc_tune_request;
IATSCLocator* p_atsc_locator;
localComPtr(): p_atsc_tune_request(NULL), p_atsc_locator(NULL) {};
~localComPtr()
{
if( p_atsc_tune_request )
p_atsc_tune_request->Release();
if( p_atsc_locator )
p_atsc_locator->Release();
}
} l;
long l_major_channel, l_minor_channel, l_physical_channel;
long l_frequency;
l_major_channel = var_GetInteger( p_access, "dvb-major-channel" );
l_minor_channel = var_GetInteger( p_access, "dvb-minor-channel" );
l_physical_channel = var_GetInteger( p_access, "dvb-physical-channel" );
l_frequency = var_GetInteger( p_access, "dvb-frequency" );
guid_network_type = CLSID_ATSCNetworkProvider;
hr = CreateTuneRequest();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot create Tuning Space: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->QueryInterface( IID_IATSCChannelTuneRequest,
(void**)&l.p_atsc_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot QI for IATSCChannelTuneRequest: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = ::CoCreateInstance( CLSID_ATSCLocator, 0, CLSCTX_INPROC,
IID_IATSCLocator, (void**)&l.p_atsc_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot create the ATSC locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = S_OK;
if( l_frequency > 0 )
hr = l.p_atsc_locator->put_CarrierFrequency( l_frequency );
if( l_major_channel > 0 )
hr = l.p_atsc_tune_request->put_Channel( l_major_channel );
if( SUCCEEDED( hr ) && l_minor_channel > 0 )
hr = l.p_atsc_tune_request->put_MinorChannel( l_minor_channel );
if( SUCCEEDED( hr ) && l_physical_channel > 0 )
hr = l.p_atsc_locator->put_PhysicalChannel( l_physical_channel );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot set tuning parameters: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->put_Locator( l.p_atsc_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot put the locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
/* Build and Run the Graph. If a Tuner device is in use the graph will
* fail to run. Repeated calls to build will check successive tuner
* devices */
do
{
hr = Build();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitATSCTuneRequest: "\
"Cannot Build the Graph: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = Start();
}
while( hr != S_OK );
return VLC_SUCCESS;
}
/*****************************************************************************
* Submit a DVB-T Tune Request
******************************************************************************/
int BDAGraph::SubmitDVBTTuneRequest()
{
HRESULT hr = S_OK;
class localComPtr
{
public:
IDVBTuneRequest* p_dvbt_tune_request;
IDVBTLocator* p_dvbt_locator;
IDVBTuningSpace2* p_dvb_tuning_space;
localComPtr(): p_dvbt_tune_request(NULL), p_dvbt_locator(NULL),
p_dvb_tuning_space(NULL) {};
~localComPtr()
{
if( p_dvbt_tune_request )
p_dvbt_tune_request->Release();
if( p_dvbt_locator )
p_dvbt_locator->Release();
if( p_dvb_tuning_space )
p_dvb_tuning_space->Release();
}
} l;
long l_frequency, l_bandwidth, l_hp_fec, l_lp_fec, l_guard;
long l_transmission, l_hierarchy;
BinaryConvolutionCodeRate i_hp_fec, i_lp_fec;
GuardInterval i_guard;
TransmissionMode i_transmission;
HierarchyAlpha i_hierarchy;
l_frequency = var_GetInteger( p_access, "dvb-frequency" ) / 1000;
l_bandwidth = var_GetInteger( p_access, "dvb-bandwidth" );
l_hp_fec = var_GetInteger( p_access, "dvb-code-rate-hp" );
l_lp_fec = var_GetInteger( p_access, "dvb-code-rate-lp" );
l_guard = var_GetInteger( p_access, "dvb-guard" );
l_transmission = var_GetInteger( p_access, "dvb-transmission" );
l_hierarchy = var_GetInteger( p_access, "dvb-hierarchy" );
switch( l_hp_fec )
{
case 1:
i_hp_fec = BDA_BCC_RATE_1_2; break;
case 2:
i_hp_fec = BDA_BCC_RATE_2_3; break;
case 3:
i_hp_fec = BDA_BCC_RATE_3_4; break;
case 4:
i_hp_fec = BDA_BCC_RATE_5_6; break;
case 5:
i_hp_fec = BDA_BCC_RATE_7_8;break;
default:
i_hp_fec = BDA_BCC_RATE_NOT_SET;
}
switch( l_lp_fec )
{
case 1:
i_lp_fec = BDA_BCC_RATE_1_2; break;
case 2:
i_lp_fec = BDA_BCC_RATE_2_3; break;
case 3:
i_lp_fec = BDA_BCC_RATE_3_4; break;
case 4:
i_lp_fec = BDA_BCC_RATE_5_6; break;
case 5:
i_lp_fec = BDA_BCC_RATE_7_8; break;
default:
i_lp_fec = BDA_BCC_RATE_NOT_SET;
}
switch( l_guard )
{
case 32:
i_guard = BDA_GUARD_1_32; break;
case 16:
i_guard = BDA_GUARD_1_16; break;
case 8:
i_guard = BDA_GUARD_1_8; break;
case 4:
i_guard = BDA_GUARD_1_4; break;
default:
i_guard = BDA_GUARD_NOT_SET;
}
switch( l_transmission )
{
case 2:
i_transmission = BDA_XMIT_MODE_2K; break;
case 8:
i_transmission = BDA_XMIT_MODE_8K; break;
default:
i_transmission = BDA_XMIT_MODE_NOT_SET;
}
switch( l_hierarchy )
{
case 1:
i_hierarchy = BDA_HALPHA_1; break;
case 2:
i_hierarchy = BDA_HALPHA_2; break;
case 4:
i_hierarchy = BDA_HALPHA_4; break;
default:
i_hierarchy = BDA_HALPHA_NOT_SET;
}
guid_network_type = CLSID_DVBTNetworkProvider;
hr = CreateTuneRequest();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot create Tune Request: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->QueryInterface( IID_IDVBTuneRequest,
(void**)&l.p_dvbt_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot QI for IDVBTuneRequest: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
l.p_dvbt_tune_request->put_ONID( -1 );
l.p_dvbt_tune_request->put_SID( -1 );
l.p_dvbt_tune_request->put_TSID( -1 );
hr = ::CoCreateInstance( CLSID_DVBTLocator, 0, CLSCTX_INPROC,
IID_IDVBTLocator, (void**)&l.p_dvbt_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot create the DVBT Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tuning_space->QueryInterface( IID_IDVBTuningSpace2,
(void**)&l.p_dvb_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot QI for IDVBTuningSpace2: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = S_OK;
hr = l.p_dvb_tuning_space->put_SystemType( DVB_Terrestrial );
if( SUCCEEDED( hr ) && l_frequency > 0 )
hr = l.p_dvbt_locator->put_CarrierFrequency( l_frequency );
if( SUCCEEDED( hr ) && l_bandwidth > 0 )
hr = l.p_dvbt_locator->put_Bandwidth( l_bandwidth );
if( SUCCEEDED( hr ) && i_hp_fec != BDA_BCC_RATE_NOT_SET )
hr = l.p_dvbt_locator->put_InnerFECRate( i_hp_fec );
if( SUCCEEDED( hr ) && i_lp_fec != BDA_BCC_RATE_NOT_SET )
hr = l.p_dvbt_locator->put_LPInnerFECRate( i_lp_fec );
if( SUCCEEDED( hr ) && i_guard != BDA_GUARD_NOT_SET )
hr = l.p_dvbt_locator->put_Guard( i_guard );
if( SUCCEEDED( hr ) && i_transmission != BDA_XMIT_MODE_NOT_SET )
hr = l.p_dvbt_locator->put_Mode( i_transmission );
if( SUCCEEDED( hr ) && i_hierarchy != BDA_HALPHA_NOT_SET )
hr = l.p_dvbt_locator->put_HAlpha( i_hierarchy );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot set tuning parameters on Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->put_Locator( l.p_dvbt_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot put the locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
/* Build and Run the Graph. If a Tuner device is in use the graph will
* fail to run. Repeated calls to build will check successive tuner
* devices */
do
{
hr = Build();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
"Cannot Build the Graph: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = Start();
}
while( hr != S_OK );
return VLC_SUCCESS;
}
/*****************************************************************************
* Submit a DVB-C Tune Request
******************************************************************************/
int BDAGraph::SubmitDVBCTuneRequest()
{
HRESULT hr = S_OK;
class localComPtr
{
public:
IDVBTuneRequest* p_dvbc_tune_request;
IDVBCLocator* p_dvbc_locator;
IDVBTuningSpace2* p_dvb_tuning_space;
localComPtr(): p_dvbc_tune_request(NULL), p_dvbc_locator(NULL),
p_dvb_tuning_space(NULL) {};
~localComPtr()
{
if( p_dvbc_tune_request )
p_dvbc_tune_request->Release();
if( p_dvbc_locator )
p_dvbc_locator->Release();
if( p_dvb_tuning_space )
p_dvb_tuning_space->Release();
}
} l;
long l_frequency, l_symbolrate;
int i_qam;
ModulationType i_qam_mod;
l_frequency = var_GetInteger( p_access, "dvb-frequency" ) / 1000;
l_symbolrate = var_GetInteger( p_access, "dvb-srate" );
i_qam = var_GetInteger( p_access, "dvb-modulation" );
switch( i_qam )
{
case 16:
i_qam_mod = BDA_MOD_16QAM; break;
case 32:
i_qam_mod = BDA_MOD_32QAM; break;
case 64:
i_qam_mod = BDA_MOD_64QAM; break;
case 128:
i_qam_mod = BDA_MOD_128QAM; break;
case 256:
i_qam_mod = BDA_MOD_256QAM; break;
default:
i_qam_mod = BDA_MOD_NOT_SET;
}
guid_network_type = CLSID_DVBCNetworkProvider;
hr = CreateTuneRequest();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot create Tune Request: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->QueryInterface( IID_IDVBTuneRequest,
(void**)&l.p_dvbc_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot QI for IDVBTuneRequest: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
l.p_dvbc_tune_request->put_ONID( -1 );
l.p_dvbc_tune_request->put_SID( -1 );
l.p_dvbc_tune_request->put_TSID( -1 );
hr = ::CoCreateInstance( CLSID_DVBCLocator, 0, CLSCTX_INPROC,
IID_IDVBCLocator, (void**)&l.p_dvbc_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot create the DVB-C Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tuning_space->QueryInterface( IID_IDVBTuningSpace2,
(void**)&l.p_dvb_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot QI for IDVBTuningSpace2: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = S_OK;
hr = l.p_dvb_tuning_space->put_SystemType( DVB_Cable );
if( SUCCEEDED( hr ) && l_frequency > 0 )
hr = l.p_dvbc_locator->put_CarrierFrequency( l_frequency );
if( SUCCEEDED( hr ) && l_symbolrate > 0 )
hr = l.p_dvbc_locator->put_SymbolRate( l_symbolrate );
if( SUCCEEDED( hr ) && i_qam_mod != BDA_MOD_NOT_SET )
hr = l.p_dvbc_locator->put_Modulation( i_qam_mod );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot set tuning parameters on Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->put_Locator( l.p_dvbc_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot put the locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
/* Build and Run the Graph. If a Tuner device is in use the graph will
* fail to run. Repeated calls to build will check successive tuner
* devices */
do
{
hr = Build();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
"Cannot Build the Graph: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = Start();
}
while( hr != S_OK );
return VLC_SUCCESS;
}
/*****************************************************************************
* Submit a DVB-S Tune Request
******************************************************************************/
int BDAGraph::SubmitDVBSTuneRequest()
{
HRESULT hr = S_OK;
class localComPtr
{
public:
IDVBTuneRequest* p_dvbs_tune_request;
IDVBSLocator* p_dvbs_locator;
IDVBSTuningSpace* p_dvbs_tuning_space;
char* psz_polarisation;
char* psz_input_range;
BSTR bstr_input_range;
WCHAR* pwsz_input_range;
int i_range_len;
localComPtr(): p_dvbs_tune_request(NULL), p_dvbs_locator(NULL),
p_dvbs_tuning_space(NULL), bstr_input_range(NULL),
pwsz_input_range(NULL), i_range_len(0), psz_polarisation(NULL),
psz_input_range(NULL) {};
~localComPtr()
{
if( p_dvbs_tuning_space )
p_dvbs_tuning_space->Release();
if( p_dvbs_tune_request )
p_dvbs_tune_request->Release();
if( p_dvbs_locator )
p_dvbs_locator->Release();
SysFreeString( bstr_input_range );
delete pwsz_input_range;
free( psz_input_range );
free( psz_polarisation );
}
} l;
long l_frequency, l_symbolrate, l_azimuth, l_elevation, l_longitude;
long l_lnb_lof1, l_lnb_lof2, l_lnb_slof, l_inversion, l_network_id;
long l_hp_fec;
int i_mod;
Polarisation i_polar;
SpectralInversion i_inversion;
VARIANT_BOOL b_west;
BinaryConvolutionCodeRate i_hp_fec;
ModulationType i_mod_typ;
l_frequency = var_GetInteger( p_access, "dvb-frequency" );
l_symbolrate = var_GetInteger( p_access, "dvb-srate" );
l_azimuth = var_GetInteger( p_access, "dvb-azimuth" );
l_elevation = var_GetInteger( p_access, "dvb-elevation" );
l_longitude = var_GetInteger( p_access, "dvb-longitude" );
l_lnb_lof1 = var_GetInteger( p_access, "dvb-lnb-lof1" );
l_lnb_lof2 = var_GetInteger( p_access, "dvb-lnb-lof2" );
l_lnb_slof = var_GetInteger( p_access, "dvb-lnb-slof" );
i_mod = var_GetInteger( p_access, "dvb-modulation" );
l_hp_fec = var_GetInteger( p_access, "dvb-code-rate-hp" );
l_inversion = var_GetInteger( p_access, "dvb-inversion" );
l_network_id = var_GetInteger( p_access, "dvb-network-id" );
l.psz_input_range = var_GetNonEmptyString( p_access, "dvb-range" );
l.psz_polarisation = var_GetNonEmptyString( p_access, "dvb-polarisation" );
b_west = ( l_longitude < 0 );
i_polar = BDA_POLARISATION_NOT_SET;
if( l.psz_polarisation != NULL )
{
switch( toupper( l.psz_polarisation[0] ) )
{
case 'H':
i_polar = BDA_POLARISATION_LINEAR_H;
break;
case 'V':
i_polar = BDA_POLARISATION_LINEAR_V;
break;
case 'L':
i_polar = BDA_POLARISATION_CIRCULAR_L;
break;
case 'R':
i_polar = BDA_POLARISATION_CIRCULAR_R;
break;
}
}
switch( l_inversion )
{
case 0:
i_inversion = BDA_SPECTRAL_INVERSION_NORMAL; break;
case 1:
i_inversion = BDA_SPECTRAL_INVERSION_INVERTED; break;
case 2:
i_inversion = BDA_SPECTRAL_INVERSION_AUTOMATIC; break;
default:
i_inversion = BDA_SPECTRAL_INVERSION_NOT_SET;
}
switch( i_mod )
{
case 16:
i_mod_typ = BDA_MOD_16QAM; break;
case 128:
i_mod_typ = BDA_MOD_128QAM; break;
case 256:
i_mod_typ = BDA_MOD_256QAM; break;
case 10004:
i_mod_typ = BDA_MOD_QPSK; break;
default:
i_mod_typ = BDA_MOD_NOT_SET;
}
switch( l_hp_fec )
{
case 1:
i_hp_fec = BDA_BCC_RATE_1_2; break;
case 2:
i_hp_fec = BDA_BCC_RATE_2_3; break;
case 3:
i_hp_fec = BDA_BCC_RATE_3_4; break;
case 4:
i_hp_fec = BDA_BCC_RATE_5_6; break;
case 5:
i_hp_fec = BDA_BCC_RATE_7_8; break;
default:
i_hp_fec = BDA_BCC_RATE_NOT_SET;
}
l.i_range_len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
l.psz_input_range, -1, l.pwsz_input_range, 0 );
if( l.i_range_len > 0 )
{
l.pwsz_input_range = new WCHAR[l.i_range_len];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
l.psz_input_range, -1, l.pwsz_input_range, l.i_range_len );
l.bstr_input_range=SysAllocString( l.pwsz_input_range );
}
guid_network_type = CLSID_DVBSNetworkProvider;
hr = CreateTuneRequest();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot create Tune Request: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->QueryInterface( IID_IDVBTuneRequest,
(void**)&l.p_dvbs_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot QI for IDVBTuneRequest: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
l.p_dvbs_tune_request->put_ONID( -1 );
l.p_dvbs_tune_request->put_SID( -1 );
l.p_dvbs_tune_request->put_TSID( -1 );
hr = ::CoCreateInstance( CLSID_DVBSLocator, 0, CLSCTX_INPROC,
IID_IDVBSLocator, (void**)&l.p_dvbs_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot create the DVBS Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tuning_space->QueryInterface( IID_IDVBSTuningSpace,
(void**)&l.p_dvbs_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot QI for IDVBSTuningSpace: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = S_OK;
hr = l.p_dvbs_tuning_space->put_SystemType( DVB_Satellite );
if( SUCCEEDED( hr ) && l_lnb_lof1 > 0 )
hr = l.p_dvbs_tuning_space->put_LowOscillator( l_lnb_lof1 );
if( SUCCEEDED( hr ) && l_lnb_slof > 0 )
hr = l.p_dvbs_tuning_space->put_LNBSwitch( l_lnb_slof );
if( SUCCEEDED( hr ) && l_lnb_lof2 > 0 )
hr = l.p_dvbs_tuning_space->put_HighOscillator( l_lnb_lof2 );
if( SUCCEEDED( hr ) && i_inversion != BDA_SPECTRAL_INVERSION_NOT_SET )
hr = l.p_dvbs_tuning_space->put_SpectralInversion( i_inversion );
if( SUCCEEDED( hr ) && l_network_id > 0 )
hr = l.p_dvbs_tuning_space->put_NetworkID( l_network_id );
if( SUCCEEDED( hr ) && l.i_range_len > 0 )
hr = l.p_dvbs_tuning_space->put_InputRange( l.bstr_input_range );
if( SUCCEEDED( hr ) && l_frequency > 0 )
hr = l.p_dvbs_locator->put_CarrierFrequency( l_frequency );
if( SUCCEEDED( hr ) && l_symbolrate > 0 )
hr = l.p_dvbs_locator->put_SymbolRate( l_symbolrate );
if( SUCCEEDED( hr ) && i_polar != BDA_POLARISATION_NOT_SET )
hr = l.p_dvbs_locator->put_SignalPolarisation( i_polar );
if( SUCCEEDED( hr ) && i_mod_typ != BDA_MOD_NOT_SET )
hr = l.p_dvbs_locator->put_Modulation( i_mod_typ );
if( SUCCEEDED( hr ) && i_hp_fec != BDA_BCC_RATE_NOT_SET )
hr = l.p_dvbs_locator->put_InnerFECRate( i_hp_fec );
if( SUCCEEDED( hr ) && l_azimuth > 0 )
hr = l.p_dvbs_locator->put_Azimuth( l_azimuth );
if( SUCCEEDED( hr ) && l_elevation > 0 )
hr = l.p_dvbs_locator->put_Elevation( l_elevation );
if( SUCCEEDED( hr ) )
hr = l.p_dvbs_locator->put_WestPosition( b_west );
if( SUCCEEDED( hr ) )
hr = l.p_dvbs_locator->put_OrbitalPosition( labs( l_longitude ) );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot set tuning parameters on Locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = p_tune_request->put_Locator( l.p_dvbs_locator );
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot put the locator: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
/* Build and Run the Graph. If a Tuner device is in use the graph will
* fail to run. Repeated calls to build will check successive tuner
* devices */
do
{
hr = Build();
if( FAILED( hr ) )
{
msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
"Cannot Build the Graph: hr=0x%8lx", hr );
return VLC_EGENERIC;
}
hr = Start();
}
while( hr != S_OK );
return VLC_SUCCESS;
}
/*****************************************************************************
* Load the Tuning Space from System Tuning Spaces according to the
* Network Type requested
******************************************************************************/
HRESULT BDAGraph::CreateTuneRequest()
{
HRESULT hr = S_OK;
GUID guid_this_network_type;
class localComPtr
{
public:
ITuningSpaceContainer* p_tuning_space_container;
IEnumTuningSpaces* p_tuning_space_enum;
ITuningSpace* p_this_tuning_space;
IDVBTuningSpace2* p_dvb_tuning_space;
BSTR bstr_name;
char * psz_network_name;
char * psz_create_name;
char * psz_bstr_name;
WCHAR * wpsz_create_name;
int i_name_len;
localComPtr(): p_tuning_space_container(NULL),
p_tuning_space_enum(NULL), p_this_tuning_space(NULL),
p_dvb_tuning_space(NULL),
i_name_len(0), psz_network_name(NULL), wpsz_create_name(NULL),
psz_create_name(NULL), bstr_name(NULL), psz_bstr_name(NULL) {};
~localComPtr()
{
if( p_tuning_space_enum )
p_tuning_space_enum->Release();
if( p_tuning_space_container )
p_tuning_space_container->Release();
if( p_this_tuning_space )
p_this_tuning_space->Release();
if( p_dvb_tuning_space )
p_dvb_tuning_space->Release();
SysFreeString( bstr_name );
delete[] psz_bstr_name;
delete[] wpsz_create_name;
free( psz_network_name );
free( psz_create_name );
}
} l;
/* We shall test for a specific Tuning space name supplied on the command
* line as dvb-networkname=xxx.
* For some users with multiple cards and/or multiple networks this could
* be useful. This allows us to reasonably safely apply updates to the
* System Tuning Space in the registry without disrupting other streams. */
l.psz_network_name = var_GetNonEmptyString( p_access, "dvb-network-name" );
if( l.psz_network_name )
{
msg_Dbg( p_access, "CreateTuneRequest: Find Tuning Space: %s",
l.psz_network_name );
}
else
{
l.psz_network_name = new char[1];
*l.psz_network_name = '\0';
}
/* A Tuning Space may already have been set up. If it is for the same
* network type then all is well. Otherwise, reset the Tuning Space and get
* a new one */
if( p_tuning_space )
{
hr = p_tuning_space->get__NetworkType( &guid_this_network_type );
if( FAILED( hr ) ) guid_this_network_type = GUID_NULL;
if( guid_this_network_type == guid_network_type )
{
hr = p_tuning_space->get_UniqueName( &l.bstr_name );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot get UniqueName for Tuning Space: hr=0x%8lx", hr );
return hr;
}
l.i_name_len = WideCharToMultiByte( CP_ACP, 0, l.bstr_name, -1,
l.psz_bstr_name, 0, NULL, NULL );
l.psz_bstr_name = new char[ l.i_name_len ];
l.i_name_len = WideCharToMultiByte( CP_ACP, 0, l.bstr_name, -1,
l.psz_bstr_name, l.i_name_len, NULL, NULL );
/* Test for a specific Tuning space name supplied on the command
* line as dvb-networkname=xxx */
if( strlen( l.psz_network_name ) == 0 ||
strcmp( l.psz_network_name, l.psz_bstr_name ) == 0 )
{
msg_Dbg( p_access, "CreateTuneRequest: Using Tuning Space: %s",
l.psz_network_name );
return S_OK;
}
}
/* else different guid_network_type */
if( p_tuning_space )
p_tuning_space->Release();
if( p_tune_request )
p_tune_request->Release();
p_tuning_space = NULL;
p_tune_request = NULL;
}
/* Force use of the first available Tuner Device during Build */
l_tuner_used = -1;
/* Get the SystemTuningSpaces container to enumerate through all the
* defined tuning spaces.
* l.p_tuning_space_container->Refcount = 1 */
hr = ::CoCreateInstance( CLSID_SystemTuningSpaces, 0, CLSCTX_INPROC,
IID_ITuningSpaceContainer, (void**)&l.p_tuning_space_container );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot CoCreate SystemTuningSpaces: hr=0x%8lx", hr );
return hr;
}
/* Get the SystemTuningSpaces container to enumerate through all the
* defined tuning spaces.
* l.p_tuning_space_container->Refcount = 2
* l.p_tuning_space_enum->Refcount = 1 */
hr = l.p_tuning_space_container->get_EnumTuningSpaces(
&l.p_tuning_space_enum );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot create SystemTuningSpaces Enumerator: hr=0x%8lx", hr );
return hr;
}
do
{
/* l.p_this_tuning_space->RefCount = 1 after the first pass
* Release before overwriting with Next */
if( l.p_this_tuning_space )
l.p_this_tuning_space->Release();
l.p_this_tuning_space = NULL;
SysFreeString( l.bstr_name );
hr = l.p_tuning_space_enum->Next( 1, &l.p_this_tuning_space, NULL );
if( hr != S_OK ) break;
hr = l.p_this_tuning_space->get__NetworkType( &guid_this_network_type );
/* GUID_NULL means a non-BDA network was found e.g analog
* Ignore failures and non-BDA networks and keep looking */
if( FAILED( hr ) ) guid_this_network_type == GUID_NULL;
if( guid_this_network_type == guid_network_type )
{
/* QueryInterface to clone l.p_this_tuning_space
* l.p_this_tuning_space->RefCount = 2 */
hr = l.p_this_tuning_space->Clone( &p_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot QI Tuning Space: hr=0x%8lx", hr );
return hr;
}
hr = p_tuning_space->get_UniqueName( &l.bstr_name );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot get UniqueName for Tuning Space: hr=0x%8lx", hr );
return hr;
}
/* Test for a specific Tuning space name supplied on the command
* line as dvb-networkname=xxx */
delete[] l.psz_bstr_name;
l.i_name_len = WideCharToMultiByte( CP_ACP, 0, l.bstr_name, -1,
l.psz_bstr_name, 0, NULL, NULL );
l.psz_bstr_name = new char[ l.i_name_len ];
l.i_name_len = WideCharToMultiByte( CP_ACP, 0, l.bstr_name, -1,
l.psz_bstr_name, l.i_name_len, NULL, NULL );
if( strlen( l.psz_network_name ) == 0 ||
strcmp( l.psz_network_name, l.psz_bstr_name ) == 0 )
{
msg_Dbg( p_access, "CreateTuneRequest: Using Tuning Space: %s",
l.psz_bstr_name );
/* CreateTuneRequest adds TuneRequest to p_tuning_space
* p_tune_request->RefCount = 1 */
hr = p_tuning_space->CreateTuneRequest( &p_tune_request );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Create Tune Request: hr=0x%8lx", hr );
return hr;
}
if( p_tuning_space )
p_tuning_space->Release();
p_tuning_space = NULL;
}
}
while( true );
/* No tuning space was found. If the create-name parameter was set then
* create a tuning space. By rights should use the same name used in
* network-name
* Also would be nice to copy a tuning space but we only come here if we do
* not find any. */
l.psz_create_name = var_GetNonEmptyString( p_access, "dvb-create-name" );
if( !l.psz_create_name || strlen( l.psz_create_name ) <= 0 )
{
hr = E_FAIL;
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot find a suitable System Tuning Space: hr=0x%8lx", hr );
return hr;
}
if( strcmp( l.psz_create_name, l.psz_network_name ) )
{
hr = E_FAIL;
msg_Warn( p_access, "CreateTuneRequest: "\
"dvb-create-name %s must match dvb-network-name %s",
l.psz_create_name, l.psz_network_name );
return hr;
}
/* Need to use DVBSTuningSpace for DVB-S and ATSCTuningSpace for ATSC */
VARIANT var_id;
CLSID cls_tuning_space;
if( IsEqualCLSID( guid_network_type, CLSID_ATSCNetworkProvider ) )
cls_tuning_space = CLSID_ATSCTuningSpace;
if( IsEqualCLSID( guid_network_type, CLSID_DVBTNetworkProvider ) )
cls_tuning_space = CLSID_DVBTuningSpace;
if( IsEqualCLSID( guid_network_type, CLSID_DVBCNetworkProvider ) )
cls_tuning_space = CLSID_DVBTuningSpace;
if( IsEqualCLSID( guid_network_type, CLSID_DVBSNetworkProvider ) )
cls_tuning_space = CLSID_DVBSTuningSpace;
l.i_name_len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
l.psz_create_name, -1, l.wpsz_create_name, 0 );
if( l.i_name_len <= 0 )
{
hr = E_FAIL;
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot convert zero length dvb-create-name %s",
l.psz_create_name );
return hr;
}
l.wpsz_create_name = new WCHAR[l.i_name_len];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, l.psz_create_name, -1,
l.wpsz_create_name, l.i_name_len );
if( l.bstr_name )
SysFreeString( l.bstr_name );
l.bstr_name = SysAllocString( l.wpsz_create_name );
msg_Dbg( p_access, "CreateTuneRequest: Create Tuning Space: %s",
l.psz_create_name );
hr = ::CoCreateInstance( cls_tuning_space, 0, CLSCTX_INPROC,
IID_ITuningSpace, (void**)&p_tuning_space );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot CoCreate new TuningSpace: hr=0x%8lx", hr );
if( SUCCEEDED( hr ) )
hr = p_tuning_space->put__NetworkType( guid_network_type );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Put Network Type: hr=0x%8lx", hr );
if( SUCCEEDED( hr ) )
hr = p_tuning_space->put_UniqueName( l.bstr_name );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Put Unique Name: hr=0x%8lx", hr );
if( SUCCEEDED( hr ) )
hr = p_tuning_space->put_FriendlyName( l.bstr_name );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Put Friendly Name: hr=0x%8lx", hr );
if( guid_network_type == CLSID_DVBTNetworkProvider ||
guid_network_type == CLSID_DVBCNetworkProvider ||
guid_network_type == CLSID_DVBSNetworkProvider )
{
hr = p_tuning_space->QueryInterface( IID_IDVBTuningSpace2,
(void**)&l.p_dvb_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot QI for IDVBTuningSpace2: hr=0x%8lx", hr );
return hr;
}
if( guid_network_type == CLSID_DVBTNetworkProvider )
hr = l.p_dvb_tuning_space->put_SystemType( DVB_Terrestrial );
if( guid_network_type == CLSID_DVBCNetworkProvider )
hr = l.p_dvb_tuning_space->put_SystemType( DVB_Cable );
if( guid_network_type == CLSID_DVBSNetworkProvider )
hr = l.p_dvb_tuning_space->put_SystemType( DVB_Satellite );
}
if( SUCCEEDED( hr ) )
hr = l.p_tuning_space_container->Add( p_tuning_space, &var_id );
if( FAILED( hr ) )
{
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Create new TuningSpace: hr=0x%8lx", hr );
return hr;
}
msg_Dbg( p_access, "CreateTuneRequest: Tuning Space: %s created",
l.psz_create_name );
hr = p_tuning_space->CreateTuneRequest( &p_tune_request );
if( FAILED( hr ) )
msg_Warn( p_access, "CreateTuneRequest: "\
"Cannot Create Tune Request: hr=0x%8lx", hr );
return hr;
}
/******************************************************************************
* Build
* Step 4: Build the Filter Graph
* Build sets up devices, adds and connects filters
******************************************************************************/
HRESULT BDAGraph::Build()
{
HRESULT hr = S_OK;
long l_capture_used, l_tif_used;
VARIANT l_tuning_space_id;
AM_MEDIA_TYPE grabber_media_type;
class localComPtr
{
public:
ITuningSpaceContainer* p_tuning_space_container;
localComPtr(): p_tuning_space_container(NULL) {};
~localComPtr()
{
if( p_tuning_space_container )
p_tuning_space_container->Release();
}
} l;
/* Get the SystemTuningSpaces container to save the Tuning space */
l_tuning_space_id.vt = VT_I4;
l_tuning_space_id.lVal = 0L;
hr = ::CoCreateInstance( CLSID_SystemTuningSpaces, 0, CLSCTX_INPROC,
IID_ITuningSpaceContainer, (void**)&l.p_tuning_space_container );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot CoCreate SystemTuningSpaces: hr=0x%8lx", hr );
return hr;
}
hr = l.p_tuning_space_container->FindID( p_tuning_space,
&l_tuning_space_id.lVal );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot Find Tuning Space ID: hr=0x%8lx", hr );
return hr;
}
msg_Dbg( p_access, "Build: Using Tuning Space ID %d",
l_tuning_space_id.lVal );
hr = l.p_tuning_space_container->put_Item( l_tuning_space_id,
p_tuning_space );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot save Tuning Space: hr=0x%8lx (ignored)", hr );
}
/* If we have already have a filter graph, rebuild it*/
Destroy();
hr = ::CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void**)&p_filter_graph );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot CoCreate IFilterGraph: hr=0x%8lx", hr );
return hr;
}
/* First filter in the graph is the Network Provider and
* its Scanning Tuner which takes the Tune Request*/
hr = ::CoCreateInstance( guid_network_type, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void**)&p_network_provider);
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot CoCreate Network Provider: hr=0x%8lx", hr );
return hr;
}
hr = p_filter_graph->AddFilter( p_network_provider, L"Network Provider" );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot load network provider: hr=0x%8lx", hr );
return hr;
}
hr = p_network_provider->QueryInterface( IID_IScanningTuner,
(void**)&p_scanning_tuner );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot QI Network Provider for Scanning Tuner: hr=0x%8lx", hr );
return hr;
}
hr = p_scanning_tuner->Validate( p_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Tune Request is invalid: hr=0x%8lx", hr );
return hr;
}
hr = p_scanning_tuner->put_TuneRequest( p_tune_request );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot submit the tune request: hr=0x%8lx", hr );
return hr;
}
/* Add the Network Tuner to the Network Provider. On subsequent calls,
* l_tuner_used will cause a different tuner to be selected
* To select a specific device first get the parameter that nominates the
* device (dvb-adapter) and use the value to initialise l_tuner_used.
* When FindFilter returns check the contents of l_tuner_used.
* If it is not what was selected then the requested device was not
* available so return with an error. */
long l_adapter = -1;
l_adapter = var_GetInteger( p_access, "dvb-adapter" );
if( l_tuner_used < 0 && l_adapter >= 0 )
l_tuner_used = l_adapter - 1;
hr = FindFilter( KSCATEGORY_BDA_NETWORK_TUNER, &l_tuner_used,
p_network_provider, &p_tuner_device );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot load tuner device and connect network provider: "\
"hr=0x%8lx", hr );
return hr;
}
if( l_adapter > 0 && l_tuner_used != l_adapter )
{
msg_Warn( p_access, "Build: "\
"Tuner device %d is not available", l_adapter );
return E_FAIL;
}
msg_Dbg( p_access, "BDAGraph: Using adapter %d", l_tuner_used );
/* VLC 1.0 works reliably up this point then crashes
* Obvious candidate is FindFilter */
/* Always look for all capture devices to match the Network Tuner */
l_capture_used = -1;
hr = FindFilter( KSCATEGORY_BDA_RECEIVER_COMPONENT, &l_capture_used,
p_tuner_device, &p_capture_device );
if( FAILED( hr ) )
{
/* Some BDA drivers do not provide a Capture Device Filter so force
* the Sample Grabber to connect directly to the Tuner Device */
p_capture_device = p_tuner_device;
p_tuner_device = NULL;
msg_Warn( p_access, "Build: "\
"Cannot find Capture device. Connecting to tuner: hr=0x%8lx", hr );
}
if( p_sample_grabber )
p_sample_grabber->Release();
p_sample_grabber = NULL;
/* Insert the Sample Grabber to tap into the Transport Stream. */
hr = ::CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void**)&p_sample_grabber );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot load Sample Grabber Filter: hr=0x%8lx", hr );
return hr;
}
hr = p_filter_graph->AddFilter( p_sample_grabber, L"Sample Grabber" );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot add Sample Grabber Filter to graph: hr=0x%8lx", hr );
return hr;
}
if( p_grabber )
p_grabber->Release();
p_grabber = NULL;
hr = p_sample_grabber->QueryInterface( IID_ISampleGrabber,
(void**)&p_grabber );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot QI Sample Grabber Filter: hr=0x%8lx", hr );
return hr;
}
/* Try the possible stream type */
hr = E_FAIL;
for( int i = 0; i < 2; i++ )
{
ZeroMemory( &grabber_media_type, sizeof( AM_MEDIA_TYPE ) );
grabber_media_type.majortype = MEDIATYPE_Stream;
grabber_media_type.subtype = i == 0 ? MEDIASUBTYPE_MPEG2_TRANSPORT : KSDATAFORMAT_SUBTYPE_BDA_MPEG2_TRANSPORT;
msg_Dbg( p_access, "Build: "
"Trying connecting with subtype %s",
i == 0 ? "MEDIASUBTYPE_MPEG2_TRANSPORT" : "KSDATAFORMAT_SUBTYPE_BDA_MPEG2_TRANSPORT" );
hr = p_grabber->SetMediaType( &grabber_media_type );
if( SUCCEEDED( hr ) )
{
hr = Connect( p_capture_device, p_sample_grabber );
if( SUCCEEDED( hr ) )
break;
msg_Warn( p_access, "Build: "\
"Cannot connect Sample Grabber to Capture device: hr=0x%8lx (try %d/2)", hr, 1+i );
}
else
{
msg_Warn( p_access, "Build: "\
"Cannot set media type on grabber filter: hr=0x%8lx (try %d/2", hr, 1+i );
}
}
if( hr )
return hr;
/* We need the MPEG2 Demultiplexer even though we are going to use the VLC
* TS demuxer. The TIF filter connects to the MPEG2 demux and works with
* the Network Provider filter to set up the stream */
hr = ::CoCreateInstance( CLSID_MPEG2Demultiplexer, NULL,
CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&p_mpeg_demux );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot CoCreateInstance MPEG2 Demultiplexer: hr=0x%8lx", hr );
return hr;
}
hr = p_filter_graph->AddFilter( p_mpeg_demux, L"Demux" );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot add demux filter to graph: hr=0x%8lx", hr );
return hr;
}
hr = Connect( p_sample_grabber, p_mpeg_demux );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot connect demux to grabber: hr=0x%8lx", hr );
return hr;
}
/* Always look for the Transform Information Filter from the start
* of the collection*/
l_tif_used = -1;
hr = FindFilter( KSCATEGORY_BDA_TRANSPORT_INFORMATION, &l_tif_used,
p_mpeg_demux, &p_transport_info );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot load TIF onto demux: hr=0x%8lx", hr );
return hr;
}
/* Configure the Sample Grabber to buffer the samples continuously */
hr = p_grabber->SetBufferSamples( true );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot set Sample Grabber to buffering: hr=0x%8lx", hr );
return hr;
}
hr = p_grabber->SetOneShot( false );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot set Sample Grabber to multi shot: hr=0x%8lx", hr );
return hr;
}
hr = p_grabber->SetCallback( this, 0 );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot set SampleGrabber Callback: hr=0x%8lx", hr );
return hr;
}
hr = Register();
if( FAILED( hr ) )
{
d_graph_register = 0;
}
/* The Media Control is used to Run and Stop the Graph */
if( p_media_control )
p_media_control->Release();
p_media_control = NULL;
hr = p_filter_graph->QueryInterface( IID_IMediaControl,
(void**)&p_media_control );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Build: "\
"Cannot QI Media Control: hr=0x%8lx", hr );
return hr;
}
return hr;
}
/******************************************************************************
* FindFilter
* Looks up all filters in a category and connects to the upstream filter until
* a successful match is found. The index of the connected filter is returned.
* On subsequent calls, this can be used to start from that point to find
* another match.
* This is used when the graph does not run because a tuner device is in use so
* another one needs to be selected.
******************************************************************************/
HRESULT BDAGraph::FindFilter( REFCLSID clsid, long* i_moniker_used,
IBaseFilter* p_upstream, IBaseFilter** p_p_downstream )
{
HRESULT hr = S_OK;
int i_moniker_index = -1;
class localComPtr
{
public:
IMoniker* p_moniker;
IEnumMoniker* p_moniker_enum;
IBaseFilter* p_filter;
IPropertyBag* p_property_bag;
VARIANT var_bstr;
char * psz_bstr;
int i_bstr_len;
localComPtr():
p_moniker(NULL),
p_moniker_enum(NULL),
p_filter(NULL),
p_property_bag(NULL),
psz_bstr( NULL )
{ ::VariantInit(&var_bstr); };
~localComPtr()
{
if( p_property_bag )
p_property_bag->Release();
if( p_filter )
p_filter->Release();
if( p_moniker )
p_moniker->Release();
if( p_moniker_enum )
p_moniker_enum->Release();
::VariantClear(&var_bstr);
delete[] psz_bstr;
}
} l;
if( !p_system_dev_enum )
{
hr = ::CoCreateInstance( CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC,
IID_ICreateDevEnum, (void**)&p_system_dev_enum );
if( FAILED( hr ) )
{
msg_Warn( p_access, "FindFilter: "\
"Cannot CoCreate SystemDeviceEnum: hr=0x%8lx", hr );
return hr;
}
}
hr = p_system_dev_enum->CreateClassEnumerator( clsid,
&l.p_moniker_enum, 0 );
if( hr != S_OK )
{
msg_Warn( p_access, "FindFilter: "\
"Cannot CreateClassEnumerator: hr=0x%8lx", hr );
return E_FAIL;
}
do
{
/* We are overwriting l.p_moniker so we should Release and nullify
* It is important that p_moniker and p_property_bag are fully released
* l.p_filter may not be dereferenced so we could force to NULL */
if( l.p_property_bag )
l.p_property_bag->Release();
l.p_property_bag = NULL;
if( l.p_filter )
l.p_filter->Release();
l.p_filter = NULL;
if( l.p_moniker )
l.p_moniker->Release();
l.p_moniker = NULL;
hr = l.p_moniker_enum->Next( 1, &l.p_moniker, 0 );
if( hr != S_OK ) break;
i_moniker_index++;
/* Skip over devices already found on previous calls */
if( i_moniker_index <= *i_moniker_used ) continue;
*i_moniker_used = i_moniker_index;
/* l.p_filter is Released at the top of the loop */
hr = l.p_moniker->BindToObject( NULL, NULL, IID_IBaseFilter,
(void**)&l.p_filter );
if( FAILED( hr ) )
{
continue;
}
/* l.p_property_bag is released at the top of the loop */
hr = l.p_moniker->BindToStorage( NULL, NULL, IID_IPropertyBag,
(void**)&l.p_property_bag );
if( FAILED( hr ) )
{
msg_Warn( p_access, "FindFilter: "\
"Cannot Bind to Property Bag: hr=0x%8lx", hr );
return hr;
}
hr = l.p_property_bag->Read( L"FriendlyName", &l.var_bstr, NULL );
if( FAILED( hr ) )
{
msg_Warn( p_access, "FindFilter: "\
"Cannot read filter friendly name: hr=0x%8lx", hr );
return hr;
}
hr = p_filter_graph->AddFilter( l.p_filter, l.var_bstr.bstrVal );
if( FAILED( hr ) )
{
msg_Warn( p_access, "FindFilter: "\
"Cannot add filter: hr=0x%8lx", hr );
return hr;
}
hr = Connect( p_upstream, l.p_filter );
if( SUCCEEDED( hr ) )
{
/* p_p_downstream has not been touched yet so no release needed */
delete[] l.psz_bstr;
l.i_bstr_len = WideCharToMultiByte( CP_ACP, 0,
l.var_bstr.bstrVal, -1, l.psz_bstr, 0, NULL, NULL );
l.psz_bstr = new char[l.i_bstr_len];
l.i_bstr_len = WideCharToMultiByte( CP_ACP, 0,
l.var_bstr.bstrVal, -1, l.psz_bstr, l.i_bstr_len, NULL, NULL );
msg_Dbg( p_access, "FindFilter: Connected %s", l.psz_bstr );
l.p_filter->QueryInterface( IID_IBaseFilter,
(void**)p_p_downstream );
return S_OK;
}
/* Not the filter we want so unload and try the next one */
hr = p_filter_graph->RemoveFilter( l.p_filter );
if( FAILED( hr ) )
{
msg_Warn( p_access, "FindFilter: "\
"Failed unloading Filter: hr=0x%8lx", hr );
return hr;
}
}
while( true );
hr = E_FAIL;
msg_Warn( p_access, "FindFilter: No filter connected: hr=0x%8lx", hr );
return hr;
}
/*****************************************************************************
* Connect is called from Build to enumerate and connect pins
*****************************************************************************/
HRESULT BDAGraph::Connect( IBaseFilter* p_upstream, IBaseFilter* p_downstream )
{
HRESULT hr = E_FAIL;
class localComPtr
{
public:
IPin* p_pin_upstream;
IPin* p_pin_downstream;
IEnumPins* p_pin_upstream_enum;
IEnumPins* p_pin_downstream_enum;
IPin* p_pin_temp;
localComPtr(): p_pin_upstream(NULL), p_pin_downstream(NULL),
p_pin_upstream_enum(NULL), p_pin_downstream_enum(NULL),
p_pin_temp(NULL) { };
~localComPtr()
{
if( p_pin_temp )
p_pin_temp->Release();
if( p_pin_downstream )
p_pin_downstream->Release();
if( p_pin_upstream )
p_pin_upstream->Release();
if( p_pin_downstream_enum )
p_pin_downstream_enum->Release();
if( p_pin_upstream_enum )
p_pin_upstream_enum->Release();
}
} l;
PIN_DIRECTION pin_dir;
hr = p_upstream->EnumPins( &l.p_pin_upstream_enum );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Connect: "\
"Cannot get upstream filter enumerator: hr=0x%8lx", hr );
return hr;
}
do
{
/* Release l.p_pin_upstream before next iteration */
if( l.p_pin_upstream )
l.p_pin_upstream ->Release();
l.p_pin_upstream = NULL;
hr = l.p_pin_upstream_enum->Next( 1, &l.p_pin_upstream, 0 );
if( hr != S_OK ) break;
hr = l.p_pin_upstream->QueryDirection( &pin_dir );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Connect: "\
"Cannot get upstream filter pin direction: hr=0x%8lx", hr );
return hr;
}
hr = l.p_pin_upstream->ConnectedTo( &l.p_pin_downstream );
if( SUCCEEDED( hr ) )
{
l.p_pin_downstream->Release();
l.p_pin_downstream = NULL;
}
if( FAILED( hr ) && hr != VFW_E_NOT_CONNECTED )
{
msg_Warn( p_access, "Connect: "\
"Cannot check upstream filter connection: hr=0x%8lx", hr );
return hr;
}
if( ( pin_dir == PINDIR_OUTPUT ) && ( hr == VFW_E_NOT_CONNECTED ) )
{
/* The upstream pin is not yet connected so check each pin on the
* downstream filter */
hr = p_downstream->EnumPins( &l.p_pin_downstream_enum );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Connect: Cannot get "\
"downstream filter enumerator: hr=0x%8lx", hr );
return hr;
}
do
{
/* Release l.p_pin_downstream before next iteration */
if( l.p_pin_downstream )
l.p_pin_downstream ->Release();
l.p_pin_downstream = NULL;
hr = l.p_pin_downstream_enum->Next( 1, &l.p_pin_downstream, 0 );
if( hr != S_OK ) break;
hr = l.p_pin_downstream->QueryDirection( &pin_dir );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Connect: Cannot get "\
"downstream filter pin direction: hr=0x%8lx", hr );
return hr;
}
/* Looking for a free Pin to connect to
* A connected Pin may have an reference count > 1
* so Release and nullify the pointer */
hr = l.p_pin_downstream->ConnectedTo( &l.p_pin_temp );
if( SUCCEEDED( hr ) )
{
l.p_pin_temp->Release();
l.p_pin_temp = NULL;
}
if( hr != VFW_E_NOT_CONNECTED )
{
if( FAILED( hr ) )
{
msg_Warn( p_access, "Connect: Cannot check "\
"downstream filter connection: hr=0x%8lx", hr );
return hr;
}
}
if( ( pin_dir == PINDIR_INPUT ) &&
( hr == VFW_E_NOT_CONNECTED ) )
{
hr = p_filter_graph->ConnectDirect( l.p_pin_upstream,
l.p_pin_downstream, NULL );
if( SUCCEEDED( hr ) )
{
/* If we arrive here then we have a matching pair of
* pins. */
return S_OK;
}
}
/* If we arrive here it means this downstream pin is not
* suitable so try the next downstream pin.
* l.p_pin_downstream is released at the top of the loop */
}
while( true );
/* If we arrive here then we ran out of pins before we found a
* suitable one. Release outstanding refcounts */
if( l.p_pin_downstream_enum )
l.p_pin_downstream_enum->Release();
l.p_pin_downstream_enum = NULL;
if( l.p_pin_downstream )
l.p_pin_downstream->Release();
l.p_pin_downstream = NULL;
}
/* If we arrive here it means this upstream pin is not suitable
* so try the next upstream pin
* l.p_pin_upstream is released at the top of the loop */
}
while( true );
/* If we arrive here it means we did not find any pair of suitable pins
* Outstanding refcounts are released in the destructor */
return E_FAIL;
}
/*****************************************************************************
* Start uses MediaControl to start the graph
*****************************************************************************/
HRESULT BDAGraph::Start()
{
HRESULT hr = S_OK;
OAFilterState i_state; /* State_Stopped, State_Paused, State_Running */
if( !p_media_control )
{
msg_Dbg( p_access, "Start: Media Control has not been created" );
return E_FAIL;
}
hr = p_media_control->Run();
msg_Dbg( p_access, "Graph started hr=0x%lx", hr );
if( hr == S_OK )
return hr;
/* Query the state of the graph - timeout after 100 milliseconds */
while( hr = p_media_control->GetState( 100, &i_state ) != S_OK )
{
if( FAILED( hr ) )
{
msg_Warn( p_access,
"Start: Cannot get Graph state: hr=0x%8lx", hr );
return hr;
}
}
if( i_state == State_Running )
return hr;
/* The Graph is not running so stop it and return an error */
msg_Warn( p_access, "Start: Graph not started: %d", i_state );
hr = p_media_control->StopWhenReady(); /* Instead of Stop() */
if( FAILED( hr ) )
{
msg_Warn( p_access,
"Start: Cannot stop Graph after Run failed: hr=0x%8lx", hr );
return hr;
}
return E_FAIL;
}
/*****************************************************************************
* Pop the stream of data
*****************************************************************************/
block_t *BDAGraph::Pop()
{
return output.Pop();
}
/******************************************************************************
* SampleCB - Callback when the Sample Grabber has a sample
******************************************************************************/
STDMETHODIMP BDAGraph::SampleCB( double d_time, IMediaSample *p_sample )
{
if( p_sample->IsDiscontinuity() == S_OK )
msg_Warn( p_access, "BDA SampleCB: Sample Discontinuity.");
const size_t i_sample_size = p_sample->GetActualDataLength();
BYTE *p_sample_data;
p_sample->GetPointer( &p_sample_data );
if( i_sample_size > 0 && p_sample_data )
{
block_t *p_block = block_New( p_access, i_sample_size );
if( p_block )
{
memcpy( p_block->p_buffer, p_sample_data, i_sample_size );
output.Push( p_block );
}
}
return S_OK;
}
STDMETHODIMP BDAGraph::BufferCB( double d_time, BYTE* p_buffer,
long l_buffer_len )
{
return E_FAIL;
}
/******************************************************************************
* removes each filter from the graph
******************************************************************************/
HRESULT BDAGraph::Destroy()
{
HRESULT hr = S_OK;
ULONG ul_refcount = 0;
if( p_media_control )
hr = p_media_control->StopWhenReady(); /* Instead of Stop() */
if( d_graph_register )
{
Deregister();
}
output.Empty();
if( p_grabber )
{
p_grabber->Release();
p_grabber = NULL;
}
if( p_transport_info )
{
p_filter_graph->RemoveFilter( p_transport_info );
p_transport_info->Release();
p_transport_info = NULL;
}
if( p_mpeg_demux )
{
p_filter_graph->RemoveFilter( p_mpeg_demux );
p_mpeg_demux->Release();
p_mpeg_demux = NULL;
}
if( p_sample_grabber )
{
p_filter_graph->RemoveFilter( p_sample_grabber );
p_sample_grabber->Release();
p_sample_grabber = NULL;
}
if( p_capture_device )
{
p_filter_graph->RemoveFilter( p_capture_device );
p_capture_device->Release();
p_capture_device = NULL;
}
if( p_tuner_device )
{
p_filter_graph->RemoveFilter( p_tuner_device );
p_tuner_device->Release();
p_tuner_device = NULL;
}
if( p_scanning_tuner )
{
p_scanning_tuner->Release();
p_scanning_tuner = NULL;
}
if( p_network_provider )
{
p_filter_graph->RemoveFilter( p_network_provider );
p_network_provider->Release();
p_network_provider = NULL;
}
if( p_media_control )
{
p_media_control->Release();
p_media_control = NULL;
}
if( p_filter_graph )
{
p_filter_graph->Release();
p_filter_graph = NULL;
}
if( p_system_dev_enum )
{
p_system_dev_enum->Release();
p_system_dev_enum = NULL;
}
return S_OK;
}
/*****************************************************************************
* Add/Remove a DirectShow filter graph to/from the Running Object Table.
* Allows GraphEdit to "spy" on a remote filter graph.
******************************************************************************/
HRESULT BDAGraph::Register()
{
class localComPtr
{
public:
IMoniker* p_moniker;
IRunningObjectTable* p_ro_table;
localComPtr(): p_moniker(NULL), p_ro_table(NULL) {};
~localComPtr()
{
if( p_moniker )
p_moniker->Release();
if( p_ro_table )
p_ro_table->Release();
}
} l;
WCHAR psz_w_graph_name[128];
HRESULT hr;
hr = ::GetRunningObjectTable( 0, &l.p_ro_table );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Register: Cannot get ROT: hr=0x%8lx", hr );
return hr;
}
wsprintfW( psz_w_graph_name, L"VLC BDA Graph %08x Pid %08x",
(DWORD_PTR) p_filter_graph, ::GetCurrentProcessId() );
hr = CreateItemMoniker( L"!", psz_w_graph_name, &l.p_moniker );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Register: Cannot Create Moniker: hr=0x%8lx", hr );
return hr;
}
hr = l.p_ro_table->Register( ROTFLAGS_REGISTRATIONKEEPSALIVE,
p_filter_graph, l.p_moniker, &d_graph_register );
if( FAILED( hr ) )
{
msg_Warn( p_access, "Register: Cannot Register Graph: hr=0x%8lx", hr );
return hr;
}
// msg_Dbg( p_access, "Register: registered Graph: %S", psz_w_graph_name );
return hr;
}
void BDAGraph::Deregister()
{
HRESULT hr;
IRunningObjectTable* p_ro_table;
hr = ::GetRunningObjectTable( 0, &p_ro_table );
if( SUCCEEDED( hr ) )
p_ro_table->Revoke( d_graph_register );
d_graph_register = 0;
p_ro_table->Release();
}
|