1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
|
//*@@@+++@@@@******************************************************************
//
// Microsoft Windows Media Foundation
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//*@@@---@@@@******************************************************************
//
#include "stdafx.h"
#include "multipinmft.h"
#ifdef MF_WPP
#include "multipinmft.tmh" //--REF_ANALYZER_DONT_REMOVE--
#endif
//
//Note since MFT_UNIQUE_METHOD_NAMES is defined all the functions of IMFTransform have the Mft suffix..
//
extern const CLSID CLSID_HwMFTActivate;
#if _NEED_MFTLOCKING_
#define MFTLOCKED() {\
UINT32 punValue = FALSE; \
hr = GetUINT32(MF_TRANSFORM_ASYNC_UNLOCK, &punValue);\
if (FAILED(hr) || punValue == FALSE){\
return MF_E_TRANSFORM_ASYNC_LOCKED; \
}\
}
#else
#define MFTLOCKED()
#endif
CMultipinMft::CMultipinMft()
: m_nRefCount( 0 ),
m_InputPinCount( 0 ),
m_OutputPinCount( 0 ),
m_dwWorkQueueId ( MFASYNC_CALLBACK_QUEUE_MULTITHREADED ),
m_lWorkQueuePriority ( 0 ),
m_spAttributes( nullptr ),
m_spSourceTransform( nullptr ),
m_PhotoTriggerSent(false),
m_filterHasIndependentPin( false ),
m_FilterInPhotoSequence( false ),
m_filterInWarmStart(false)
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
, m_spPhotoConfirmationCallback(nullptr)
#endif
{
ComPtr<IMFAttributes> pAttributes = nullptr;
MFCreateAttributes( &pAttributes, 0 );
pAttributes->SetUINT32( MF_TRANSFORM_ASYNC, TRUE );
pAttributes->SetUINT32( MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE, TRUE );
pAttributes->SetUINT32( MF_SA_D3D_AWARE, TRUE );
pAttributes->SetString( MFT_ENUM_HARDWARE_URL_Attribute, L"SampleMultiPinMft" );
m_spAttributes = pAttributes;
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
m_guidPhotoConfirmationSubtype = MFVideoFormat_NV12;
#endif
}
CMultipinMft::~CMultipinMft( )
{
CBasePin *pioPin = NULL;
for ( ULONG ulIndex = 0, ulSize = (ULONG) m_InPins.size(); ulIndex < ulSize; ulIndex++ )
{
pioPin = m_InPins[ ulIndex ];
SAFERELEASE( pioPin );
}
m_InPins.clear();
for (ULONG ulIndex = 0, ulSize = (ULONG) m_OutPins.size(); ulIndex < ulSize; ulIndex++)
{
pioPin = m_OutPins[ ulIndex ];
SAFERELEASE( pioPin );
}
m_OutPins.clear();
m_spSourceTransform = nullptr;
}
STDMETHODIMP_(ULONG) CMultipinMft::AddRef(
void
)
{
return InterlockedIncrement(&m_nRefCount);
}
STDMETHODIMP_(ULONG) CMultipinMft::Release(
void
)
{
ULONG uCount = InterlockedDecrement(&m_nRefCount);
if ( uCount == 0 )
{
delete this;
}
return uCount;
}
STDMETHODIMP CMultipinMft::QueryInterface(
_In_ REFIID iid,
_COM_Outptr_ void** ppv
)
{
HRESULT hr = S_OK;
*ppv = NULL;
if ((iid == __uuidof(IMFDeviceTransform)) || (iid == __uuidof(IUnknown)))
{
*ppv = static_cast< IMFDeviceTransform* >(this);
AddRef();
}
else
if ( iid == __uuidof( IMFMediaEventGenerator ) )
{
*ppv = static_cast< IMFMediaEventGenerator* >(this);
AddRef();
}
else
if ( iid == __uuidof( IMFShutdown ) )
{
*ppv = static_cast< IMFShutdown* >( this );
AddRef();
}
#if defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES)
else
if (iid == __uuidof(IMFTransform))
{
*ppv = static_cast< IMFTransform* >(this);
AddRef();
}
#endif
else
if ( iid == __uuidof( IKsControl ) )
{
*ppv = static_cast< IKsControl* >( this );
AddRef();
}
else
if ( iid == __uuidof( IMFRealTimeClientEx ) )
{
*ppv = static_cast< IMFRealTimeClientEx* >( this );
AddRef();
}
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
else
if (iid == __uuidof(IMFCapturePhotoConfirmation))
{
*ppv = static_cast< IMFCapturePhotoConfirmation* >(this);
AddRef();
}
else
if (iid == __uuidof(IMFGetService))
{
*ppv = static_cast< IMFGetService* >(this);
AddRef();
}
#endif
else
{
hr = E_NOINTERFACE;
}
return hr;
}
/*++
Description:
This function is the entry point of the transform
The following things may be initialized here
1) Query for MF_DEVICEMFT_CONNECTED_FILTER_KSCONTROL on the attributes supplied
2) From the IUnknown acquired get the IMFTransform interface.
3) Get the stream count.. The output streams are of consequence to the tranform.
The input streams should correspond to the output streams exposed by the source transform
acquired from the Attributes supplied.
4) Get the IKSControl which is used to send KSPROPERTIES, KSEVENTS and KSMETHODS to the driver for the filer level. Store it in your filter class
5) Get the OutPutStreamAttributes for the output pins of the source transform. This can further be used to QI and acquire
the IKSControl related to the specific pin. This can be used to send PIN level KSPROPERTIES, EVENTS and METHODS to the pins
6) Create the output pins
--*/
STDMETHODIMP CMultipinMft::InitializeTransform (
_In_ IMFAttributes *pAttributes
)
{
HRESULT hr = S_OK;
ComPtr<IUnknown> spFilterUnk = nullptr;
DWORD *pcInputStreams = NULL, *pcOutputStreams = NULL;
DWORD inputStreams = 0;
DWORD outputStreams = 0;
GUID* outGuids = NULL;
GUID streamCategory = GUID_NULL;
DMFTCHECKNULL_GOTO( pAttributes, done, E_INVALIDARG );
//
//The attribute passed with MF_DEVICEMFT_CONNECTED_FILTER_KSCONTROL is the source transform. This generally represents a filter
//This needs to be stored so that we know the device properties. We cache it. We query for the IKSControl which is used to send
//controls to the driver.
//
DMFTCHECKHR_GOTO( pAttributes->GetUnknown( MF_DEVICEMFT_CONNECTED_FILTER_KSCONTROL,IID_PPV_ARGS( &spFilterUnk ) ),done );
DMFTCHECKHR_GOTO( spFilterUnk.As( &m_spSourceTransform ), done );
DMFTCHECKHR_GOTO( m_spSourceTransform.As( &m_spIkscontrol ), done );
DMFTCHECKHR_GOTO( m_spSourceTransform->MFTGetStreamCount( &inputStreams, &outputStreams ), done );
spFilterUnk = nullptr;
//
//The number of input pins created by the device transform should match the pins exposed by
//the source transform i.e. outputStreams from SourceTransform or DevProxy = Input pins of the Device MFT
//
if ( inputStreams > 0 || outputStreams > 0 )
{
pcInputStreams = new DWORD[ inputStreams ];
DMFTCHECKNULL_GOTO( pcInputStreams, done, E_OUTOFMEMORY);
pcOutputStreams = new DWORD[ outputStreams ];
DMFTCHECKNULL_GOTO( pcOutputStreams, done, E_OUTOFMEMORY );
DMFTCHECKHR_GOTO( m_spSourceTransform->MFTGetStreamIDs( inputStreams, pcInputStreams,
outputStreams,
pcOutputStreams ),done );
//
// Output pins from DevProxy = Input pins of device MFT.. We are the first transform in the pipeline before MFT0
//
for ( ULONG ulIndex = 0; ulIndex < outputStreams; ulIndex++ )
{
ComPtr<IMFAttributes> pInAttributes = nullptr;
DMFTCHECKHR_GOTO( m_spSourceTransform->GetOutputStreamAttributes(pcOutputStreams[ulIndex], pInAttributes.GetAddressOf()), done);
DMFTCHECKHR_GOTO( pInAttributes->GetGUID(MF_DEVICESTREAM_STREAM_CATEGORY, &streamCategory), done);
if ( IsEqualCLSID( streamCategory, PINNAME_IMAGE ) )
{
//We have independent pins..
m_filterHasIndependentPin = true;
}
CInPin *pInPin = nullptr;
if (IsEqualCLSID(streamCategory, AVSTREAM_CUSTOM_PIN_IMAGE))
{
pInPin = new CCustomPin( pInAttributes.Get(), pcOutputStreams[ulIndex], this);
DMFTCHECKNULL_GOTO( pInPin, done, E_OUTOFMEMORY);
//
// Since the custom pin is an input pin too we will push it
// in the input pins list. This is however not being connected
// to the output in this sample.
m_CustomPinCount++;
}
else
{
pInPin = new CInPin( pInAttributes.Get(), pcOutputStreams[ulIndex], this);
DMFTCHECKNULL_GOTO(pInPin, done, E_OUTOFMEMORY);
}
hr = ExceptionBoundary([this,pInPin]()
{
m_InPins.push_back(pInPin);
});
DMFTCHECKHR_GOTO(hr, done);
DMFTCHECKHR_GOTO( pInPin->Init(m_spSourceTransform.Get() ), done);
pInPin->AddRef();
}
//
// If we have just one output stream exposed off the source transform create a one to three pin
//
if ( ( outputStreams == 1 ) && IsEqualGUID( streamCategory, PINNAME_VIDEO_CAPTURE ) )
{
outputStreams = 3;
outGuids = new GUID [ outputStreams ];
DMFTCHECKNULL_GOTO(outGuids, done, E_OUTOFMEMORY);
m_OutPins.resize(outputStreams, nullptr);
CInPin *piPin = (CInPin *)m_InPins[0];
*outGuids = PINNAME_VIDEO_CAPTURE;
*( outGuids + 1 ) = PINNAME_VIDEO_PREVIEW;
*(outGuids + 2) = PINNAME_IMAGE; //PINNAME_IMAGE for independent pin and PINNAME_VIDEO_STILL for dependent pin!!
for ( ULONG ulIndex = 0; ulIndex < outputStreams; ulIndex++ )
{
ComPtr<IKsControl> pKsControl = NULL;
COutPin *poPin = nullptr;
DMFTCHECKHR_GOTO( piPin->QueryInterface(IID_PPV_ARGS( &pKsControl ) ), done);
hr = ExceptionBoundary([&]()
{
poPin = new COutPin(ulIndex, this, pKsControl.Get());
});
DMFTCHECKHR_GOTO(hr, done);
DMFTCHECKNULL_GOTO( poPin,done, E_OUTOFMEMORY );
DMFTCHECKHR_GOTO( BridgeInputPinOutputPin( piPin, poPin ),done );
DMFTCHECKHR_GOTO( poPin->SetGUID( MF_DEVICESTREAM_STREAM_CATEGORY, outGuids[ ulIndex ] ),done );
DMFTCHECKHR_GOTO( poPin->SetUINT32( MF_DEVICESTREAM_STREAM_ID, ulIndex ),done );
m_OutPins[ ulIndex ] = poPin;
poPin->AddRef();
}
}
else
{
//
//Create one on one mapping
//
for (ULONG ulIndex = 0; ulIndex < m_InPins.size(); ulIndex++)
{
ULONG ulPinIndex = 0;
GUID pinGuid = GUID_NULL;
ComPtr< IKsControl > pKsControl = nullptr;
CInPin *piPin = ( CInPin * )m_InPins[ ulIndex ];
if (piPin)
{
BOOL isCustom = false;
if ( SUCCEEDED( CheckCustomPin( piPin, &isCustom )) && ( isCustom ) )
{
//
// In this sample we are not connecting the custom pin to the output
// This is because we really have no way of testing the custom pin with the
// pipeline.
// This however can be changed if the custom media type is converted here in
// the device MFT and later exposed to the pipeline..
//
continue;
}
ulPinIndex = piPin->streamId();
DMFTCHECKHR_GOTO(piPin->GetGUID(MF_DEVICESTREAM_STREAM_CATEGORY, &pinGuid), done);
DMFTCHECKHR_GOTO(piPin->QueryInterface(IID_PPV_ARGS(&pKsControl)), done);
COutPin *poPin = new COutPin(ulPinIndex, this, pKsControl.Get());
DMFTCHECKNULL_GOTO(poPin, done, E_OUTOFMEMORY);
DMFTCHECKHR_GOTO(poPin->SetGUID(MF_DEVICESTREAM_STREAM_CATEGORY, pinGuid), done);
DMFTCHECKHR_GOTO(poPin->SetUINT32(MF_DEVICESTREAM_STREAM_ID, ulPinIndex), done);
#if defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES)
//
// If we wish to load MFT0 as well as Device MFT then we should be doing the following
// Copy over the GUID attribute MF_DEVICESTREAM_EXTENSION_PLUGIN_CLSID from the input
// pin to the output pin. This is because Device MFT is the new face of the filter now
// and MFT0 will now get loaded for the output pins exposed from Device MFT rather than
// DevProxy!
//
GUID guidMFT0 = GUID_NULL;
hr = piPin->GetGUID(MF_DEVICESTREAM_EXTENSION_PLUGIN_CLSID, &guidMFT0);
if (SUCCEEDED(hr))
{
//
// This stream has an MFT0 .. Attach the GUID to the Outpin pin attribute
// The downstream will query this attribute on the pins exposed from device MFT
//
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! setting Mft0 guid on pin %d", ulIndex);
DMFTCHECKHR_GOTO(poPin->SetGUID(MF_DEVICESTREAM_EXTENSION_PLUGIN_CLSID, guidMFT0), done);
DMFTCHECKHR_GOTO(poPin->SetUnknown(MF_DEVICESTREAM_EXTENSION_PLUGIN_CONNECTION_POINT,
static_cast< IUnknown* >(static_cast < IKsControl * >(this))), done);
}
else
{
// Reset Error.. MFT0 absence should not be an error
hr = S_OK;
}
#endif
DMFTCHECKHR_GOTO(BridgeInputPinOutputPin(piPin, poPin), done);
hr = ExceptionBoundary([&]()
{
m_OutPins.push_back(poPin);
});
DMFTCHECKHR_GOTO(hr, done);
}
}
}
}
m_InputPinCount = ULONG ( m_InPins.size() );
m_OutputPinCount = ULONG ( m_OutPins.size() );
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!",hr,hr);
if ( pcInputStreams )
{
delete[ ] ( pcInputStreams );
}
if ( pcOutputStreams )
{
delete[ ] ( pcOutputStreams );
}
if ( outGuids )
{
delete [] ( outGuids );
}
if ( FAILED( hr ) )
{
//Release the pins and the resources acquired
while ( m_InPins.size() > 0 )
{
CInPin *pInPin = nullptr;
pInPin = ( CInPin* )m_InPins.back();
m_InPins.pop_back();
SAFERELEASE( pInPin );
}
while ( m_OutPins.size() > 0 )
{
COutPin *pin = nullptr;
pin = ( COutPin* )m_OutPins.back();
m_OutPins.pop_back();
SAFERELEASE( pin );
}
//
// Simply clear the custom pins since the input pins must have deleted the pin
//
m_spSourceTransform = nullptr;
}
return hr;
}
STDMETHODIMP CMultipinMft::SetWorkQueueEx(
_In_ DWORD dwWorkQueueId,
_In_ LONG lWorkItemBasePriority
)
/*++
Description:
Implements IMFRealTimeClientEx::SetWorkQueueEx function
--*/
{
CAutoLock lock( m_critSec );
//
// Cache the WorkQueuId and WorkItemBasePriority
//
m_dwWorkQueueId = dwWorkQueueId;
m_lWorkQueuePriority = lWorkItemBasePriority;
return S_OK;
}
//
// IMFDeviceTransform functions
//
STDMETHODIMP CMultipinMft::GetStreamCount(
_Inout_ DWORD *pdwInputStreams,
_Inout_ DWORD *pdwOutputStreams
)
/*++
Description: Implements IMFTransform::GetStreamCount function
--*/
{
HRESULT hr = S_OK;
CAutoLock lock(m_critSec);
*pdwInputStreams = m_InputPinCount;
*pdwOutputStreams = m_OutputPinCount;
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
//
//Doesn't striclt conform to GetStreamIDs on IMFTransform Interface!
//
STDMETHODIMP CMultipinMft::GetStreamIDs(
_In_ DWORD dwInputIDArraySize,
_When_(dwInputIDArraySize >= m_InputPinCount, _Out_writes_(dwInputIDArraySize)) DWORD* pdwInputIDs,
_In_ DWORD dwOutputIDArraySize,
_When_(dwOutputIDArraySize >= m_OutputPinCount && (pdwInputIDs && (dwInputIDArraySize > 0)),
_Out_writes_(dwOutputIDArraySize)) _On_failure_(_Valid_) DWORD* pdwOutputIDs
)
/*++
Description:
Implements IMFTransform::GetStreamIDs function
--*/
{
HRESULT hr = S_OK;
CAutoLock lock(m_critSec);
MFTLOCKED();
if ( ( dwInputIDArraySize < m_InputPinCount ) && ( dwOutputIDArraySize < m_OutputPinCount ) )
{
hr = MF_E_BUFFERTOOSMALL;
goto done;
}
if ( dwInputIDArraySize )
{
DMFTCHECKNULL_GOTO( pdwInputIDs, done, E_POINTER );
for ( DWORD dwIndex = 0; dwIndex < ((dwInputIDArraySize > m_InputPinCount) ? m_InputPinCount:
dwInputIDArraySize); dwIndex++ )
{
pdwInputIDs[ dwIndex ] = ( m_InPins[dwIndex] )->streamId();
}
}
if ( dwOutputIDArraySize )
{
DMFTCHECKNULL_GOTO( pdwOutputIDs, done, E_POINTER );
for ( DWORD dwIndex = 0; dwIndex < ((dwOutputIDArraySize > m_OutputPinCount)? m_OutputPinCount:
dwOutputIDArraySize); dwIndex++ )
{
pdwOutputIDs[ dwIndex ] = (m_OutPins[ dwIndex ])->streamId();
}
}
done:
return hr;
}
/*++
Name: CMultipinMft::GetInputAvailableType
Description:
Implements IMFTransform::GetInputAvailableType function. This function
gets the media type supported by the specified stream based on the
index dwTypeIndex.
--*/
STDMETHODIMP CMultipinMft::GetInputAvailableType(
_In_ DWORD dwInputStreamID,
_In_ DWORD dwTypeIndex,
_Out_ IMFMediaType** ppMediaType
)
{
HRESULT hr = S_OK;
MFTLOCKED();
CInPin *piPin = ( CInPin* )GetInPin( dwInputStreamID );
DMFTCHECKNULL_GOTO( piPin, done, MF_E_INVALIDSTREAMNUMBER );
*ppMediaType = nullptr;
hr = piPin->GetOutputAvailableType( dwTypeIndex,ppMediaType );
if (FAILED(hr))
{
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Pin: %d Index: %d exiting %!HRESULT!",
dwInputStreamID,
dwTypeIndex,
hr);
}
done:
return hr;
}
STDMETHODIMP CMultipinMft::GetOutputAvailableType(
_In_ DWORD dwOutputStreamID,
_In_ DWORD dwTypeIndex,
_Out_ IMFMediaType** ppMediaType
)
/*++
Description:
Implements IMFTransform::GetOutputAvailableType function. This function
gets the media type supported by the specified stream based on the
index dwTypeIndex.
--*/
{
HRESULT hr = S_OK;
MFTLOCKED();
DMFTCHECKNULL_GOTO(ppMediaType, done, E_INVALIDARG);
COutPin*poPin = ( COutPin* )GetOutPin( dwOutputStreamID );
DMFTCHECKNULL_GOTO( poPin, done, MF_E_INVALIDSTREAMNUMBER );
*ppMediaType = nullptr;
hr = poPin->GetOutputAvailableType( dwTypeIndex, ppMediaType );
if ( FAILED( hr ) )
{
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Pin: %d Index: %d exiting %!HRESULT!",
dwOutputStreamID,
dwTypeIndex,
hr );
}
done:
return hr;
}
STDMETHODIMP CMultipinMft::GetInputCurrentType(
_In_ DWORD dwInputStreamID,
_COM_Outptr_result_maybenull_ IMFMediaType** ppMediaType
)
/*++
Description:
Implements IMFTransform::GetInputCurrentType function. This function
returns the current media type set on the specified stream.
--*/
{
//
//The input current types will not come to this transform.
//The outputs of this transform matter. The DTM manages the
//output of this transform and the inptuts of the source transform
//
UNREFERENCED_PARAMETER(dwInputStreamID);
UNREFERENCED_PARAMETER(ppMediaType);
return S_OK;
}
STDMETHODIMP CMultipinMft::GetOutputCurrentType(
_In_ DWORD dwOutputStreamID,
_Out_ IMFMediaType** ppMediaType
)
/*++
Description:
Implements IMFTransform::GetOutputCurrentType function. This function
returns the current media type set on the specified stream.
--*/
{
HRESULT hr = S_OK;
MFTLOCKED();
CAutoLock lock( m_critSec );
DMFTCHECKNULL_GOTO( ppMediaType, done, E_INVALIDARG );
*ppMediaType = nullptr;
COutPin *poPin = ( COutPin* )GetOutPin( dwOutputStreamID );
DMFTCHECKNULL_GOTO( poPin, done, MF_E_INVALIDSTREAMNUMBER );
DMFTCHECKHR_GOTO( poPin->getMediaType( ppMediaType ),done );
DMFTCHECKNULL_GOTO( *ppMediaType, done, MF_E_TRANSFORM_TYPE_NOT_SET );
done:
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
STDMETHODIMP CMultipinMft::ProcessEvent(
_In_ DWORD dwInputStreamID,
_In_ IMFMediaEvent* pEvent
)
/*++
Description:
Implements IMFTransform::ProcessEvent function. This function
processes events that come to the MFT.
--*/
{
UNREFERENCED_PARAMETER(dwInputStreamID);
UNREFERENCED_PARAMETER(pEvent);
return S_OK;
}
STDMETHODIMP CMultipinMft::ProcessMessage(
_In_ MFT_MESSAGE_TYPE eMessage,
_In_ ULONG_PTR ulParam
)
/*++
Description:
Implements IMFTransform::ProcessMessage function. This function
processes messages coming to the MFT.
--*/
{
HRESULT hr = S_OK;
MFTLOCKED();
UNREFERENCED_PARAMETER(ulParam);
CAutoLock _lock( m_critSec );
printMessageEvent( eMessage );
switch ( eMessage )
{
case MFT_MESSAGE_COMMAND_FLUSH:
//
//This is MFT wide flush.. Flush all output pins
//
(VOID)FlushAllStreams();
break;
case MFT_MESSAGE_COMMAND_DRAIN:
//
//There is no draining for Device MFT. Just kept here for reference
//
break;
case MFT_MESSAGE_NOTIFY_START_OF_STREAM:
//
//No op for device MFTs
//
break;
case MFT_MESSAGE_SET_D3D_MANAGER:
{
if ( ulParam )
{
ComPtr< IDirect3DDeviceManager9 > spD3D9Manager;
ComPtr< IMFDXGIDeviceManager > spDXGIManager;
hr = ( ( IUnknown* ) ulParam )->QueryInterface( IID_PPV_ARGS( &spD3D9Manager ) );
if ( SUCCEEDED( hr ) )
{
m_spDeviceManagerUnk = ( IUnknown* )ulParam;
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! IDirect3DDeviceManager9 %p, is passed", spD3D9Manager.Get() );
}
else
{
hr = ( ( IUnknown* ) ulParam )->QueryInterface( IID_PPV_ARGS( &spDXGIManager ) );
if ( SUCCEEDED(hr) )
{
m_spDeviceManagerUnk = (IUnknown*)ulParam;
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! IMFDXGIDeviceManager %p, is passed", spDXGIManager.Get());
}
}
}
else
{
m_spDeviceManagerUnk = nullptr;
hr = S_OK;
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC!IDirect3DDeviceManager9 was not passed in");
}
}
break;
case MFT_MESSAGE_NOTIFY_BEGIN_STREAMING:
{
SetStreamingState( DeviceStreamState_Run );
//
// Start Streaming custom pins if the device transfrom has any
//
SetStreamingStateCustomPins( DeviceStreamState_Run );
}
break;
case MFT_MESSAGE_NOTIFY_END_STREAMING:
{
SetStreamingState(DeviceStreamState_Stop);
//
// Stop streaming custom pins if the device transform has any
//
SetStreamingStateCustomPins( DeviceStreamState_Stop );
}
break;
case MFT_MESSAGE_NOTIFY_END_OF_STREAM:
{
SetStreamingState(DeviceStreamState_Stop);
}
break;
default:
;
}
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
STDMETHODIMP CMultipinMft::ProcessInput(
_In_ DWORD dwInputStreamID,
_In_ IMFSample* pSample,
_In_ DWORD dwFlags
)
/*++
Description:
Implements IMFTransform::ProcessInput function.This function is called
when the sourcetransform has input to feed. the pins will try to deliver the
samples to the active output pins conencted. if none are connected then just
returns the sample back to the source transform
--*/
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( dwFlags );
MFTLOCKED();
CInPin *inPin = ( CInPin* )GetInPin( dwInputStreamID );
DMFTCHECKNULL_GOTO( inPin, done, E_INVALIDARG );
if ( !IsStreaming() )
{
goto done;
}
DMFTCHECKHR_GOTO( inPin->SendSample( pSample ), done );
QueueEvent( METransformHaveOutput, GUID_NULL, S_OK, NULL );
done:
SAFERELEASE( pSample );
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
STDMETHODIMP CMultipinMft::ProcessOutput(
_In_ DWORD dwFlags,
_In_ DWORD cOutputBufferCount,
_Inout_updates_(cOutputBufferCount) MFT_OUTPUT_DATA_BUFFER *pOutputSamples,
_Out_ DWORD *pdwStatus
)
/*++
Description:
Implements IMFTransform::ProcessOutput function. This is called by the DTM when
the DT indicates it has samples to give. The DTM will send enough MFT_OUTPUT_DATA_BUFFER
pointers to be filled up as is the number of output pins available. The DT should traverse its
output pins and populate the corresponding MFT_OUTPUT_DATA_BUFFER with the samples available
--*/
{
HRESULT hr = S_OK;
BOOL gotOne = false;
MFTLOCKED();
UNREFERENCED_PARAMETER( dwFlags );
if (cOutputBufferCount > m_OutputPinCount )
{
DMFTCHECKHR_GOTO( E_INVALIDARG, done );
}
*pdwStatus = 0;
for ( DWORD i = 0; i < cOutputBufferCount; i++ )
{
DWORD dwStreamID = pOutputSamples[i].dwStreamID;
COutPin *poPin = ( COutPin * )GetOutPin( dwStreamID );
DMFTCHECKNULL_GOTO( poPin, done, E_INVALIDARG );
if ( SUCCEEDED( poPin->ProcessOutput( dwFlags, &pOutputSamples[i],
pdwStatus ) ) )
{
gotOne = true;
}
}
if (gotOne)
{
hr = S_OK;
}
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::GetInputStreamAttributes(
_In_ DWORD dwInputStreamID,
_COM_Outptr_result_maybenull_ IMFAttributes** ppAttributes
)
/*++
Description:
Implements IMFTransform::GetInputStreamAttributes function. This function
gets the specified input stream's attributes.
--*/
{
HRESULT hr = S_OK;
MFTLOCKED();
DMFTCHECKNULL_GOTO( ppAttributes, done, E_INVALIDARG );
*ppAttributes = nullptr;
CInPin *piPin = static_cast<CInPin*>(GetInPin( dwInputStreamID ));
DMFTCHECKNULL_GOTO( piPin, done, E_INVALIDARG );
hr = piPin->getPinAttributes(ppAttributes);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::GetOutputStreamAttributes(
_In_ DWORD dwOutputStreamID,
_Out_ IMFAttributes** ppAttributes
)
/*++
Description:
Implements IMFTransform::GetOutputStreamAttributes function. This function
gets the specified output stream's attributes.
--*/
{
HRESULT hr = S_OK;
MFTLOCKED();
DMFTCHECKNULL_GOTO(ppAttributes, done, E_INVALIDARG);
*ppAttributes = nullptr;
COutPin *poPin = (COutPin *)GetOutPin(dwOutputStreamID);
DMFTCHECKNULL_GOTO( poPin, done, E_INVALIDARG );
DMFTCHECKHR_GOTO( poPin->getPinAttributes(ppAttributes), done );
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
_Requires_no_locks_held_
STDMETHODIMP CMultipinMft::SetInputStreamState(
_In_ DWORD dwStreamID,
_In_ IMFMediaType *pMediaType,
_In_ DeviceStreamState value,
_In_ DWORD dwFlags
)
/*++
Description:
Implements IMFdeviceTransform::SetInputStreamState function.
Sets the input stream state.
The control lock is not taken here. The lock is taken for operations on
output pins. This operation is a result of the DT notifying the DTM that
output pin change has resulted in the need for the input to be changed. In
this case the DTM sends a getpreferredinputstate and then this call
--*/
{
HRESULT hr = S_OK;
CInPin *piPin = (CInPin*)GetInPin(dwStreamID);
DMFTCHECKNULL_GOTO(piPin, done, MF_E_INVALIDSTREAMNUMBER);
DMFTCHECKHR_GOTO(piPin->SetInputStreamState(pMediaType, value, dwFlags),done);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::GetInputStreamState(
_In_ DWORD dwStreamID,
_Out_ DeviceStreamState *value
)
{
HRESULT hr = S_OK;
CInPin *piPin = (CInPin*)GetInPin(dwStreamID);
DMFTCHECKNULL_GOTO(piPin, done, MF_E_INVALIDSTREAMNUMBER);
*value = piPin->GetState();
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::SetOutputStreamState(
_In_ DWORD dwStreamID,
_In_ IMFMediaType *pMediaType,
_In_ DeviceStreamState state,
_In_ DWORD dwFlags
)
/*++
Description:
Implements IMFdeviceTransform::SetOutputStreamState function.
Sets the output stream state. This is called whenever the stream
is selected or deslected i.e. started or stopped.
The control lock taken here and this operation should be atomic.
This function should check the input pins connected to the output pin
switch off the state of the input pin. Check if any other Pin connected
to the input pin is in a conflicting state with the state requested on this
output pin. Accordinly it calculates the media type to be set on the input pin
and the state to transition into. It then might recreate the other output pins
connected to it
--*/
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER(dwFlags);
CAutoLock Lock(m_critSec);
DMFTCHECKHR_GOTO(ChangeMediaTypeEx(dwStreamID, pMediaType, state),done);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::GetOutputStreamState(
_In_ DWORD dwStreamID,
_Out_ DeviceStreamState *value
)
/*++
Description:
Implements IMFdeviceTransform::GetOutputStreamState function.
Gets the output stream state.
Called by the DTM to checks states. Atomic operation. needs a lock
--*/
{
HRESULT hr = S_OK;
CAutoLock lock(m_critSec);
COutPin *poPin = (COutPin *)GetOutPin(dwStreamID);
DMFTCHECKNULL_GOTO(poPin, done, MF_E_INVALIDSTREAMNUMBER);
*value = poPin->GetState();
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::GetInputStreamPreferredState(
_In_ DWORD dwStreamID,
_Inout_ DeviceStreamState *value,
_Outptr_opt_result_maybenull_ IMFMediaType **ppMediaType
)
/*++
Description:
Implements IMFdeviceTransform::GetInputStreamPreferredState function.
Gets the preferred state and the media type to be set on the input pin.
The lock is not held as this will always be called only when we notify
DTM to call us. We notify DTM only from the context on operations
happening on the output pin
--*/
{
HRESULT hr = S_OK;
CInPin *piPin = (CInPin*)GetInPin(dwStreamID);
DMFTCHECKNULL_GOTO(piPin, done, MF_E_INVALIDSTREAMNUMBER);
piPin->GetInputStreamPreferredState(value, ppMediaType);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::FlushInputStream(
_In_ DWORD dwStreamIndex,
_In_ DWORD dwFlags
)
/*++
Description:
Implements IMFdeviceTransform::FlushInputStream function.
--*/
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER(dwStreamIndex);
UNREFERENCED_PARAMETER(dwFlags);
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::FlushOutputStream(
_In_ DWORD dwStreamIndex,
_In_ DWORD dwFlags
)
/*++
Description:
Implements IMFdeviceTransform::FlushOutputStream function.
Called by the DTM to flush streams
--*/
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER(dwFlags);
CAutoLock Lock(m_critSec);
COutPin *poPin = (COutPin*)GetOutPin(dwStreamIndex);
DMFTCHECKNULL_GOTO(poPin, done, E_INVALIDARG);
DeviceStreamState oldState = poPin->SetState(DeviceStreamState_Disabled);
hr = poPin->FlushQueues();
if (FAILED(hr))
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! failed %x = %!HRESULT!", hr, hr);
}
//
//Restore state
//
poPin->SetState(oldState);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
/*++
Description:
Called when the Device Transform gets a MFT_MESSAGE_COMMAND_FLUSH. We drain all the queues.
This is called in device source when the source gets end of streaming.
--*/
STDMETHODIMP_(VOID) CMultipinMft::FlushAllStreams(
VOID
)
{
DeviceStreamState oldState;
for ( DWORD dwIndex = 0, dwSize = (DWORD)m_OutPins.size(); dwIndex < dwSize; dwIndex++ )
{
COutPin *poPin = (COutPin *)m_OutPins[dwIndex];
oldState = poPin->SetState(DeviceStreamState_Disabled);
poPin->FlushQueues();
//
//Restore state
//
poPin->SetState(oldState);
}
}
//
// IKsControl interface functions
//
STDMETHODIMP CMultipinMft::KsProperty(
_In_reads_bytes_(ulPropertyLength) PKSPROPERTY pProperty,
_In_ ULONG ulPropertyLength,
_Inout_updates_bytes_(ulDataLength) LPVOID pvPropertyData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pulBytesReturned
)
/*++
Description:
Implements IKSProperty::KsProperty function.
used to pass control commands to the driver (generally)
This can be used to intercepted the control to figure out
if it needs to be propogated to the driver or not
--*/
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER(pulBytesReturned);
DMFTCHECKNULL_GOTO(pProperty, done, E_INVALIDARG);
DMFTCHECKNULL_GOTO(pulBytesReturned, done, E_INVALIDARG);
//
// Enable Warm Start on All filters for the sample. Please comment out this
// section if this is not needed
//
if (IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl)
&& (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_WARMSTART))
{
DMFTCHECKHR_GOTO(WarmStartHandler(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned),done);
goto done;
}
if (IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl)
&& (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOTHUMBNAIL))
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Thumbnail sent %d",pProperty->Flags);
}
if (IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl)
&&(!filterHasIndependentPin()))
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Extended Control %d Passed ",pProperty->Id);
switch (pProperty->Id)
{
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMODE:
hr = ExtendedPhotoModeHandler(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned);
goto done;
break;
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMAXFRAMERATE:
hr = ExtendedPhotoMaxFrameRate(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned);
goto done;
break;
case KSPROPERTY_CAMERACONTROL_EXTENDED_MAXVIDFPS_PHOTORES:
hr = MaxVidFPS_PhotoResHandler(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned);
goto done;
break;
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOTRIGGERTIME:
hr = QPCTimeHandler(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned);
goto done;
break;
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOFRAMERATE:
hr = PhotoFrameRateHandler(pProperty,
ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned);
goto done;
break;
}
}
else
if ((IsEqualCLSID(pProperty->Set, PROPSETID_VIDCAP_VIDEOCONTROL)) &&
(pProperty->Id == KSPROPERTY_VIDEOCONTROL_MODE))
{
//
//A photo trigger was sent!!!
//We need to set the event haveoutput
//
PKSPROPERTY_VIDEOCONTROL_MODE_S VideoControl = NULL;
if (sizeof(KSPROPERTY_VIDEOCONTROL_MODE_S) == ulDataLength)
{
VideoControl = (PKSPROPERTY_VIDEOCONTROL_MODE_S)pvPropertyData;
m_PhotoModeIsPhotoSequence = false;
if (VideoControl->Mode == KS_VideoControlFlag_StartPhotoSequenceCapture)
{
//
//Signalling start of photo sequence
//
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Starting PhotoSequence Trigger");
m_PhotoModeIsPhotoSequence = true;
setPhotoTriggerSent(true);
}
else
if (VideoControl->Mode == KS_VideoControlFlag_StopPhotoSequenceCapture)
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Stopping PhotoSequence Trigger");
m_PhotoModeIsPhotoSequence = false;
setPhotoTriggerSent(false);
}
else
{
//
//Normal trigger sent for single photo acquisition!
//
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Take Single Photo Trigger");
setPhotoTriggerSent(true);
}
}
if (!filterHasIndependentPin())
{
goto done;
}
}
hr = m_spIkscontrol->KsProperty(pProperty,
ulPropertyLength,
pvPropertyData,
ulDataLength,
pulBytesReturned);
done:
LPSTR guidStr = DumpGUIDA(pProperty->Set);
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! g:%s p:%d exiting %x = %!HRESULT!", guidStr, pProperty->Id, hr, hr);
delete(guidStr);
return hr;
}
STDMETHODIMP CMultipinMft::KsMethod(
_In_reads_bytes_(ulPropertyLength) PKSMETHOD pMethod,
_In_ ULONG ulPropertyLength,
_Inout_updates_bytes_(ulDataLength) LPVOID pvPropertyData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pulBytesReturned
)
/*++
Description:
Implements IKSProperty::KsMethod function.
--*/
{
return m_spIkscontrol->KsMethod(
pMethod,
ulPropertyLength,
pvPropertyData,
ulDataLength,
pulBytesReturned
);
}
STDMETHODIMP CMultipinMft::KsEvent(
_In_reads_bytes_(ulEventLength) PKSEVENT pEvent,
_In_ ULONG ulEventLength,
_Inout_updates_bytes_opt_(ulDataLength) LPVOID pEventData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pBytesReturned
)
/*++
Description:
Implements IKSProperty::KsEvent function.
--*/
{
HRESULT hr = S_OK;
if (pEvent && (pEvent->Set == KSEVENTSETID_ExtendedCameraControl) &&
(pEvent->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_WARMSTART))
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Acquiring Event for Async Extended Control");
//
// For the Sample the warmstate handlers are supported by Device MFT and not passed to driver
//
hr = m_eventHandler.KSEvent(pEvent,
ulEventLength,
pEventData,
ulDataLength,
pBytesReturned
);
goto done;
}
if ((pEvent && (pEvent->Set == KSEVENTSETID_ExtendedCameraControl))
&& (!filterHasIndependentPin()))
{
//
// Important: Extended controls will send events which are strictly
// One shot. The event comes first where it should be duped and stored,
// the control comes next. The event should be set after control completes
// and it should be then closed.
// The below code handles only certain events needed for
// implementing photo sequence. For a complete exhaustive
// list refer documentation.
//
switch (pEvent->Id)
{
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMODE:
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMAXFRAMERATE:
case KSPROPERTY_CAMERACONTROL_EXTENDED_MAXVIDFPS_PHOTORES:
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOTRIGGERTIME:
case KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOFRAMERATE:
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Acquiring Event for Async Extended Control");
//
// Let the event handler handle the event
//
DMFTCHECKHR_GOTO(m_eventHandler.KSEvent(pEvent,
ulEventLength,
pEventData,
ulDataLength,
pBytesReturned
),done);
goto done;
}
}
}
//
// All the Events we don't handle should be sent to the driver!
//
hr = m_spIkscontrol->KsEvent(pEvent,
ulEventLength,
pEventData,
ulDataLength,
pBytesReturned);
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
//
//IMFGetService functions
//
STDMETHODIMP CMultipinMft::GetService(
__in REFGUID guidService,
__in REFIID riid,
__deref_out LPVOID* ppvObject
)
{
//
//This doesn't necessarily need to be a GetService function, but this is just so that the
//pipeline implementation and the Device transform implementation is consistent.
//In this sample the photoconfirmation interface is implementated by the same class
//we can delegate it later to any of the pins if needed
//
UNREFERENCED_PARAMETER(guidService);
if (riid == __uuidof(IMFCapturePhotoConfirmation))
{
return QueryInterface(riid, ppvObject);
}
else
return MF_E_UNSUPPORTED_SERVICE;
}
//
//IMFCapturePhotoConfirmation functions implemented
//
STDMETHODIMP CMultipinMft::SetPhotoConfirmationCallback(
_In_ IMFAsyncCallback* pNotificationCallback
)
{
CAutoLock Lock(m_critSec);
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Setting PhotoConfirmation %p, is passed", pNotificationCallback);
m_spPhotoConfirmationCallback = pNotificationCallback;
return S_OK;
}
STDMETHODIMP CMultipinMft::SetPixelFormat(
_In_ GUID subtype
)
{
m_guidPhotoConfirmationSubtype = subtype;
return S_OK;
}
STDMETHODIMP CMultipinMft::GetPixelFormat(
_Out_ GUID* subtype
)
{
*subtype = m_guidPhotoConfirmationSubtype;
return S_OK;
}
#endif
#if defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES)
//
// IMFTransform function(s).
//
//
// Note: This is the only IMFTransform function which is not a redirector to the
// DeviceTransform functions. The rest of IMFTransform functions are in the file common.h
// This function returns the IMFAttribute created for Device MFT. If DMFT is
// not loaded (usually )MFT0's call to GetAttributes will get the Attribute store of DevProxy.
// A device MFT loaded will not pass through the devproxy attribute store, but it will pass
// the device MFT attributes. This should be similar to the singular DevProxy attribute
// which the MFT0 providers can use to synchronize across various MFT0's
//
STDMETHODIMP CMultipinMft::GetAttributes(
_COM_Outptr_opt_result_maybenull_ IMFAttributes** ppAttributes
)
{
HRESULT hr = S_OK;
DMFTCHECKNULL_GOTO(ppAttributes, done, E_INVALIDARG);
*ppAttributes = nullptr;
if (m_spAttributes != nullptr)
{
m_spAttributes.CopyTo(ppAttributes);
}
else
{
hr = E_OUTOFMEMORY;
}
done:
return hr;
}
#endif
//
//HELPER FUNCTIONS
//
STDMETHODIMP_(CBasePin*) CMultipinMft::GetInPin(
_In_ DWORD dwStreamId
)
{
CInPin *inPin = NULL;
for (DWORD dwIndex = 0, dwSize = (DWORD)m_InPins.size(); dwIndex < dwSize; dwIndex++)
{
inPin = (CInPin *)m_InPins[dwIndex];
if (dwStreamId == inPin->streamId())
{
break;
}
inPin = NULL;
}
return inPin;
}
STDMETHODIMP_(CBasePin*) CMultipinMft::GetOutPin(
_In_ DWORD dwStreamId
)
{
COutPin *outPin = NULL;
for ( DWORD dwIndex = 0, dwSize = (DWORD) m_OutPins.size(); dwIndex < dwSize; dwIndex++ )
{
outPin = ( COutPin * )m_OutPins[ dwIndex ];
if ( dwStreamId == outPin->streamId() )
{
break;
}
outPin = NULL;
}
return outPin;
}
/*++
Description:
This is a critical function which changes the state on an output pin
This should be called under the control lock of the DT.
Here the
--*/
STDMETHODIMP CMultipinMft::ChangeMediaTypeEx(
_In_ ULONG pinId,
_In_opt_ IMFMediaType *pMediaType,
_In_ DeviceStreamState reqState
)
{
HRESULT hr = S_OK;
DeviceStreamState oldOutPinState;
DeviceStreamState newOutStreamState;
ComPtr<IMFMediaType> pFullType = nullptr;
COutPin *poPin = static_cast<COutPin*>( GetOutPin(pinId) );
MMFTMMAPITERATOR inputPinPos;
DMFTCHECKNULL_GOTO( poPin, done, E_INVALIDARG );
//
//Check if the media type requested is a supported type
//
if ( pMediaType )
{
if ( !poPin->IsMediaTypeSupported( pMediaType, &pFullType ) )
{
DMFTCHECKHR_GOTO(MF_E_INVALIDMEDIATYPE, done);
}
}
//
//First step disable the output pin. store the old state
//
oldOutPinState = poPin->SetState( DeviceStreamState_Disabled );
(void)poPin->FlushQueues();
newOutStreamState = pinStateTransition[oldOutPinState][reqState]; //New state needed
//
//Go through the output pins' maps that has the conencted input pin to the output pin
//
inputPinPos = m_outputPinMap.equal_range( pinId );
for (std::multimap<int, int>::iterator piterator = inputPinPos.first; piterator != inputPinPos.second;piterator++)
{
//
//Get the output pins connected to the input pin. The input pin map consists of the output pins connected
//
ULONG connectedInputPin = (*piterator).second;
BOOL isAnyConnectedOutPinActive = false;
BOOL isAnyConnectedOutPinPaused = false;
BOOL isAnyConnectedOutPinRunning = false;
BOOL doWeWaitForSetInput = false;
DeviceStreamState oldInputStreamState;
MF_TRANSFORM_XVP_OPERATION operation = DeviceMftTransformXVPIllegal;
ComPtr<IMFMediaType> pInputMediaType = nullptr;
CInPin *pconnectedInPin = (CInPin*)GetInPin( connectedInputPin );
oldInputStreamState = pconnectedInPin->SetState( DeviceStreamState_Disabled );
DeviceStreamState newRequestedInPinState = pinStateTransition[oldInputStreamState][newOutStreamState];
if (pFullType)
{
pconnectedInPin->getMediaType( &pInputMediaType );
}
//
// Check if we need an XVP to be inserted between this input and output pins.
//
CompareMediaTypesForXVP( pInputMediaType.Get(), pFullType.Get(), &operation );
DMFTCHECKHR_GOTO( GetConnectOutPinStatus( connectedInputPin,
pinId, // pinId = stream which should be excluded from the search. This function searches if
&isAnyConnectedOutPinPaused, // there are any other output pins connected other than the ouput pin (on which the change media type is requested)
&isAnyConnectedOutPinRunning, //, which is streaming, paused. This way if the output pin is requested to go to Pause, Stop and if any of the
&isAnyConnectedOutPinActive ),done ); //other connected output pins are active, then input it not deactivated
//
//Check if we are asked to go to an active state
//Check for the new media type. if
//
if ( !IsPinStateInActive( newRequestedInPinState ) )
{
//
//We are being told to go active
//We will request a change in input stream state.
//
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! %p Going active IN: %d OUT: %d ", this, connectedInputPin, pinId );
doWeWaitForSetInput = true;
if ( !pFullType )
{
DMFTCHECKHR_GOTO(MF_E_INVALIDMEDIATYPE, done);
}
if ( (! pInputMediaType ) || ( operation == DeviceMftTransformXVPDisruptiveIn ) )
{
pInputMediaType = pFullType;
}
if ( newRequestedInPinState == DeviceStreamState_Pause && isAnyConnectedOutPinRunning )
{
newRequestedInPinState = DeviceStreamState_Run;
}
}
else
{
//
//We have been requested to go inactive
//
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! %p Going Inactive IN: %d OUT: %d ", this, connectedInputPin, pinId );
if ( operation == DeviceMftTransformXVPDisruptiveIn )
{
//
//Only where we recieve a disruptive media type change and a media type along with it, which is unlikely!!
//
pInputMediaType = pFullType;
doWeWaitForSetInput = true;
}
if ( isAnyConnectedOutPinActive )
{
newRequestedInPinState = ( isAnyConnectedOutPinRunning ) ? DeviceStreamState_Run : DeviceStreamState_Pause;
}
else
{
//Switch over to the new media type..
pInputMediaType = pFullType;
if ( !IsPinStateInActive( oldInputStreamState ) )
{
//It was originall active.. now going down
doWeWaitForSetInput = true;
}
}
}
//
// This will happen if we need a change in Input media type, We will send an event
// METransformInputStreamStateChanged to the Device transform manager. This will result
// in the Device Transform manager calling us back in getprefferedinputstate where
// we will give it back the state of the input and the media type to be set.
// All this happens when we are holding a lock here in Change output media type. Hence during the
// input media type change we don't hold a lock. THE DTM takes care not to send you any more media
// type change operations that can cause a deadlock.
//
if ( doWeWaitForSetInput )
{
pconnectedInPin->setPreferredMediaType( pInputMediaType.Get() );
pconnectedInPin->setPreferredStreamState( newRequestedInPinState );
SendEventToManager( METransformInputStreamStateChanged, GUID_NULL, pconnectedInPin->streamId() );
//
//The media type will be set on the input pin by the time we return from the wait
//
DMFTCHECKHR_GOTO( pconnectedInPin->WaitForSetInputPinMediaChange(), done );
}
else
{
pconnectedInPin->SetState( oldInputStreamState );
pconnectedInPin->setMediaType( pInputMediaType.Get() );
}
//Now the input type is all set..
pInputMediaType = nullptr;
(VOID)pconnectedInPin->getMediaType( &pInputMediaType );
//
//Now propogate the media type change to the output pins
//
MMFTMMAPITERATOR outputPinPos = m_inputPinMap.equal_range(pconnectedInPin->streamId());
for ( std::multimap<int, int>::iterator poutPinsIterator = outputPinPos.first;
poutPinsIterator != outputPinPos.second;
poutPinsIterator++ )
{
ComPtr<IMFMediaType> pOutMediatype = nullptr;
DeviceStreamState outPinState;
ULONG connectedoutPin = (*poutPinsIterator).second;
COutPin* pIoPin = static_cast<COutPin*>( GetOutPin ( connectedoutPin ) );
(VOID)pIoPin->getMediaType( &pOutMediatype );
outPinState = pIoPin->GetState();
if ( pIoPin->streamId() != pinId)
{
//
//This is the pin other than the output pin where the original change media type was recieved.
//
if ( pInputMediaType != nullptr && pOutMediatype != nullptr )
{
DMFTCHECKHR_GOTO( pIoPin->ChangeMediaTypeFromInpin(pconnectedInPin, pInputMediaType.Get(),
pOutMediatype.Get(),
outPinState ),done);
}
}
else
{
//
//Change the media type of the requested output pin
//
DMFTCHECKHR_GOTO( pIoPin->ChangeMediaTypeFromInpin(pconnectedInPin, pInputMediaType.Get(), pFullType.Get(), newOutStreamState), done);
//Also signal to the manager that a stream state change has happened
SendEventToManager( MEUnknown, MEDeviceStreamCreated, pIoPin->streamId());
//
//Set the First Sample Flag. this will get reset when the first sample comes in. We will signal the discontinuity
//when we get a Processoutput from the Device Transform Manager
//
pIoPin->SetFirstSample(TRUE);
}
pOutMediatype = nullptr;
}
}
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::SendEventToManager(
_In_ MediaEventType eventType,
_In_ REFGUID pGuid,
_In_ UINT32 context
)
/*++
Description:
Used to send the event to DTM.
--*/
{
HRESULT hr = S_OK;
ComPtr<IMFMediaEvent> pEvent = nullptr;
DMFTCHECKHR_GOTO(MFCreateMediaEvent(eventType, pGuid, S_OK, NULL, &pEvent ),done);
DMFTCHECKHR_GOTO(pEvent->SetUINT32(MF_EVENT_MFT_INPUT_STREAM_ID, (ULONG)context),done);
DMFTCHECKHR_GOTO(QueueEvent(pEvent.Get()),done);
done:
return hr;
}
STDMETHODIMP CMultipinMft::GetConnectOutPinStatus(
_In_ ULONG ulPinId,
_In_ ULONG ulOutPinId,
_Inout_ PBOOL pAnyInPauseState,
_Inout_ PBOOL pAnyInRunState,
_Inout_ PBOOL pAnyActive
)
/*++
Description:
This function gets the statuses of the output pins other than the one specified
The arguments are as follows
ulPinId: The input pins which are connected to the ouput pin ulOutPinId
ulOutPinId: The pin to be excluded from the check i.e. the input pin from which the request is usually sent.
--*/
{
HRESULT hr = S_OK;
MMFTMMAPITERATOR outputPinPos;
CInPin *pconnectedInPin = (CInPin*)GetInPin(ulPinId);
DMFTCHECKNULL_GOTO( pconnectedInPin, done, E_INVALIDARG );
outputPinPos = m_inputPinMap.equal_range( pconnectedInPin->streamId() );
DMFTCHECKNULL_GOTO( pconnectedInPin, done, E_FAIL );
*pAnyActive = *pAnyInPauseState = *pAnyInRunState = false;
for ( std::multimap<int, int>::iterator poutPosIterator = outputPinPos.first;
poutPosIterator != outputPinPos.second;
poutPosIterator++ )
{
ULONG connectedoutPin = (*poutPosIterator).second;
COutPin* pconnectedOutPin = ( COutPin * )GetOutPin( connectedoutPin );
if (pconnectedOutPin->streamId() != ulOutPinId)
{
//This is excluding the outpin which requested pin state change
*pAnyActive |= !IsPinStateInActive( pconnectedOutPin->GetState() );
*pAnyInPauseState |= ( pconnectedOutPin->GetState() == DeviceStreamState_Pause );
*pAnyInRunState |= ( pconnectedOutPin->GetState() == DeviceStreamState_Run );
}
}
done:
return S_OK;
}
/*++
Description:
This function connects the input and output pins.
Any media type filtering can happen here
--*/
STDMETHODIMP CMultipinMft::BridgeInputPinOutputPin(
_In_ CInPin* piPin,
_In_ COutPin* poPin
)
{
HRESULT hr = S_OK;
ULONG ulIndex = 0;
ComPtr<IMFMediaType> pMediaType = nullptr;
DMFTCHECKNULL_GOTO( piPin, done, E_INVALIDARG );
DMFTCHECKNULL_GOTO( poPin, done, E_INVALIDARG );
//
// Copy over the media types from input pin to output pin. Since there is no
// decoder support, only the uncompressed media types are inserted. Please make
// sure any pin advertised supports at least one media type. The pipeline doesn't
// like pins with no media types
//
while ( SUCCEEDED( hr = piPin->GetMediaTypeAt( ulIndex++, &pMediaType )))
{
GUID subType = GUID_NULL;
DMFTCHECKHR_GOTO( pMediaType->GetGUID(MF_MT_SUBTYPE,&subType), done );
if ( IsKnownUncompressedVideoType( subType ) )
{
DMFTCHECKHR_GOTO( poPin->AddMediaType(NULL, pMediaType.Get() ), done );
}
pMediaType = nullptr;
}
//
//Add the Input Pin to the output Pin
//
DMFTCHECKHR_GOTO(poPin->AddPin(piPin->streamId()), done);
hr = ExceptionBoundary([&](){
//
//Add the output pin to the input pin.
//
piPin->ConnectPin(poPin);
});
DMFTCHECKHR_GOTO(hr, done);
//
//Create the map. This will be useful when we have to decide the state transitions of the pins
//
m_inputPinMap.insert ( std::pair< int,int >( piPin->streamId(), poPin->streamId()) );
m_outputPinMap.insert ( std::pair< int, int >( poPin->streamId(), piPin->streamId()) );
done:
//
//Failed adding media types
//
if (FAILED(hr))
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_ERROR, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
}
return hr;
}
//
//The below routines are used to implement the extended controls needed to implement the photo sequence
//The photo sequence is enabled for cameras with no independent image pins
//The extended controls needed to enable photo sequence are discussed in detail in the photo sequence document
//
/*++
Extended Photo Mode handler is the extended property handler dealing with the photosequence and single mode capabilities of the camera
--*/
STDMETHODIMP CMultipinMft::ExtendedPhotoModeHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE );
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if ( ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE ) )
{
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE ) )
{
PBYTE pPayload = ( PBYTE )pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
//
//Use the below structure to make changes to the Property and thus affect the configuration
//PKSCAMERA_EXTENDEDPROP_PHOTOMODE pExtendedValue = (PKSCAMERA_EXTENDEDPROP_PHOTOMODE)(pPayload + sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
m_FilterInPhotoSequence = pExtendedHeader->Flags & KSCAMERA_EXTENDEDPROP_PHOTOMODE_SEQUENCE;
DMFTCHECKHR_GOTO(m_eventHandler.SetOneShot(KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMODE), done);
}
else
{
DMFTCHECKHR_GOTO(E_INVALIDARG, done);
}
}
else if ( Property->Flags & KSPROPERTY_TYPE_GET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE );
hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE ) )
{
PBYTE pPayload = (PBYTE)pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
PKSCAMERA_EXTENDEDPROP_PHOTOMODE pExtendedValue = ( PKSCAMERA_EXTENDEDPROP_PHOTOMODE )( pPayload + sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) );
pExtendedHeader->Capability = ( KSCAMERA_EXTENDEDPROP_CAPS_ASYNCCONTROL | KSCAMERA_EXTENDEDPROP_PHOTOMODE_SEQUENCE );
pExtendedHeader->Flags = ( m_FilterInPhotoSequence ) ? KSCAMERA_EXTENDEDPROP_PHOTOMODE_SEQUENCE : KSCAMERA_EXTENDEDPROP_PHOTOMODE_NORMAL;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE );
pExtendedHeader->Version = 1;
pExtendedValue->MaxHistoryFrames = 10;
pExtendedValue->RequestedHistoryFrames = 0 ;
pExtendedValue->SubMode = 0 ;
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_PHOTOMODE );
}
else
{
DMFTCHECKHR_GOTO( E_INVALIDARG, done );
}
}
done:
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
/*++
The Extended Max Frame rate is self explanatory
--*/
STDMETHODIMP CMultipinMft::ExtendedPhotoMaxFrameRate(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if (ulOutputBufferLength < sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_EXTENDEDPROP_VALUE))
{
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if (pData && ulOutputBufferLength >= sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_EXTENDEDPROP_VALUE))
{
//
//This is for setting the Max frame rate..
//
//PBYTE pPayload = (PBYTE)pData;
//PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = (PKSCAMERA_EXTENDEDPROP_HEADER)(pPayload);
//PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = (PKSCAMERA_EXTENDEDPROP_VALUE)(pPayload + sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
DMFTCHECKHR_GOTO(m_eventHandler.SetOneShot(KSPROPERTY_CAMERACONTROL_EXTENDED_PHOTOMAXFRAMERATE), done);
}
else
{
DMFTCHECKHR_GOTO(E_INVALIDARG, done);
}
}
else if ( Property->Flags & KSPROPERTY_TYPE_GET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
hr = HRESULT_FROM_WIN32( ERROR_MORE_DATA );
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
PBYTE pPayload = ( PBYTE )pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = ( PKSCAMERA_EXTENDEDPROP_VALUE )( pPayload + sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) );
pExtendedHeader->Capability = KSCAMERA_EXTENDEDPROP_CAPS_ASYNCCONTROL;
pExtendedHeader->Flags = 0;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_EXTENDEDPROP_VALUE);
pExtendedHeader->Version = 1;
pExtendedValue->Value.ratio.HighPart = 30;
pExtendedValue->Value.ratio.LowPart = 1;
*pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_EXTENDEDPROP_VALUE);
}
else
{
DMFTCHECKHR_GOTO(E_INVALIDARG, done);
}
}
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::MaxVidFPS_PhotoResHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+ sizeof( KSCAMERA_MAXVIDEOFPS_FORPHOTORES );
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if ( ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+ sizeof( KSCAMERA_MAXVIDEOFPS_FORPHOTORES ) )
{
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if (pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_MAXVIDEOFPS_FORPHOTORES ))
{
PBYTE pPayload = (PBYTE)pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
//
//Use the extended value to make changes to the property.. refer documentation
//PKSCAMERA_MAXVIDEOFPS_FORPHOTORES pExtendedValue = (PKSCAMERA_MAXVIDEOFPS_FORPHOTORES)(pPayload + sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
pExtendedHeader->Capability = 0;
pExtendedHeader->Flags = 0;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
pExtendedHeader->Version = 1;
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_MAXVIDEOFPS_FORPHOTORES );
}
else
{
hr = E_INVALIDARG;
}
}
else if (Property->Flags & KSPROPERTY_TYPE_GET)
{
if (ulOutputBufferLength == 0)
{
*pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_MAXVIDEOFPS_FORPHOTORES);
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if (ulOutputBufferLength < sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_MAXVIDEOFPS_FORPHOTORES))
{
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if (pData && ulOutputBufferLength >= sizeof(KSCAMERA_EXTENDEDPROP_HEADER)+sizeof(KSCAMERA_MAXVIDEOFPS_FORPHOTORES))
{
PBYTE pPayload = (PBYTE)pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )(pPayload );
PKSCAMERA_MAXVIDEOFPS_FORPHOTORES pExtendedValue = (PKSCAMERA_MAXVIDEOFPS_FORPHOTORES)(pPayload + sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
pExtendedHeader->Capability = 0;
pExtendedHeader->Flags = 0;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof(KSCAMERA_EXTENDEDPROP_HEADER) + sizeof(PKSCAMERA_MAXVIDEOFPS_FORPHOTORES);
pExtendedHeader->Version = 1;
pExtendedValue->PreviewFPSNum = 30;
pExtendedValue->PreviewFPSDenom = 1;
pExtendedValue->CaptureFPSNum = 30;
pExtendedValue->CaptureFPSDenom = 1;
pExtendedValue->PhotoResHeight = 240;
pExtendedValue->PhotoResWidth = 320;
*pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER) + sizeof(KSCAMERA_MAXVIDEOFPS_FORPHOTORES);
}
else
{
hr = E_INVALIDARG;
}
}
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
STDMETHODIMP CMultipinMft::QPCTimeHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if ( ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ) )
{
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ) )
{
//PBYTE pPayload = (PBYTE)pData;
//
//If the payload is to be used.. use the below structures
//
//PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = (PKSCAMERA_EXTENDEDPROP_HEADER)(pPayload);
//Use the extended value to make changes to the property.. refer documentation
//PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = (PKSCAMERA_EXTENDEDPROP_VALUE)(pPayload +sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
*pulBytesReturned = sizeof( PKSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
}
else
{
hr = E_INVALIDARG;
}
}
else if ( Property->Flags & KSPROPERTY_TYPE_GET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if ( ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) + sizeof( KSCAMERA_EXTENDEDPROP_VALUE ) )
{
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) + sizeof( KSCAMERA_EXTENDEDPROP_VALUE ) )
{
PBYTE pPayload = (PBYTE)pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = ( PKSCAMERA_EXTENDEDPROP_VALUE )( pPayload + sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) );
pExtendedHeader->Capability = 0;
pExtendedHeader->Flags = KSPROPERTY_CAMERA_PHOTOTRIGGERTIME_SET;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) + sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
pExtendedHeader->Version = 1;
pExtendedValue->Value.ull = 0;
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+ sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
}
else
{
hr = E_INVALIDARG;
}
}
done:
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
STDMETHODIMP CMultipinMft::PhotoFrameRateHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
//
//This is a read only property!!!
//
hr = E_INVALIDARG;
}
else if ( Property->Flags & KSPROPERTY_TYPE_GET )
{
if ( ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
PBYTE pPayload = (PBYTE)pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = ( PKSCAMERA_EXTENDEDPROP_VALUE )( pPayload + sizeof( KSCAMERA_EXTENDEDPROP_HEADER ) );
pExtendedHeader->Capability = 0;
pExtendedHeader->Flags = 0;
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
pExtendedHeader->Version = 1;
pExtendedValue->Value.ratio.HighPart = 30;
pExtendedValue->Value.ratio.LowPart = 1;
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
}
done:
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
STDMETHODIMP CMultipinMft::WarmStartHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
)
{
HRESULT hr = S_OK;
UNREFERENCED_PARAMETER( ulPropertyLength );
*pulBytesReturned = 0;
if ( Property->Flags & KSPROPERTY_TYPE_SET )
{
if ( ulOutputBufferLength == 0 )
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done);
}
else if (ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done);
}
else if ( pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
PBYTE pPayload = ( PBYTE )pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )pPayload;
//
//Use the extended value to make changes to the property.. refer documentation
//PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = (PKSCAMERA_EXTENDEDPROP_VALUE)(pPayload + sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
if ( pExtendedHeader->Flags & KSCAMERA_EXTENDEDPROP_WARMSTART_MODE_ENABLED )
{
m_filterInWarmStart = true;
}
else
{
m_filterInWarmStart = false;
}
*pulBytesReturned = sizeof( PKSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
m_eventHandler.SetOneShot(KSPROPERTY_CAMERACONTROL_EXTENDED_WARMSTART);
}
else
{
hr = S_OK;
}
}
else if (Property->Flags & KSPROPERTY_TYPE_GET)
{
if (ulOutputBufferLength == 0)
{
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done);
}
else if (ulOutputBufferLength < sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
DMFTCHECKHR_GOTO( HRESULT_FROM_WIN32( ERROR_MORE_DATA ), done );
}
else if (pData && ulOutputBufferLength >= sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE ))
{
PBYTE pPayload = ( PBYTE )pData;
PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = ( PKSCAMERA_EXTENDEDPROP_HEADER )( pPayload );
//
//Use the extended value to make changes to the property.. refer documentation
//PKSCAMERA_EXTENDEDPROP_VALUE pExtendedValue = (PKSCAMERA_EXTENDEDPROP_VALUE)(pPayload +sizeof(KSCAMERA_EXTENDEDPROP_HEADER));
//
pExtendedHeader->Capability = KSCAMERA_EXTENDEDPROP_CAPS_ASYNCCONTROL | KSCAMERA_EXTENDEDPROP_WARMSTART_MODE_ENABLED;
pExtendedHeader->Flags = 0;
if (m_filterInWarmStart)
{
pExtendedHeader->Flags |= KSCAMERA_EXTENDEDPROP_WARMSTART_MODE_ENABLED;
}
pExtendedHeader->Result = 0;
pExtendedHeader->Size = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
pExtendedHeader->Version = 1;
*pulBytesReturned = sizeof( KSCAMERA_EXTENDEDPROP_HEADER )+sizeof( KSCAMERA_EXTENDEDPROP_VALUE );
hr = S_OK;
}
else
{
hr = S_OK;
}
}
done:
DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr );
return hr;
}
//
// IMFShutdown interface functions
//
/*++
Description:
Implements the Shutdown from IMFShutdown
--*/
STDMETHODIMP CMultipinMft::Shutdown(
void
)
{
CAutoLock Lock(m_critSec);
(VOID) m_eventHandler.Clear();
return ShutdownEventGenerator();
}
//
// Static method to create an instance of the MFT.
//
HRESULT CMultipinMft::CreateInstance(REFIID iid, void **ppMFT)
{
HRESULT hr = S_OK;
CMultipinMft *pMFT = NULL;
DMFTCHECKNULL_GOTO(ppMFT, done, E_POINTER);
pMFT = new (std::nothrow) CMultipinMft();
DMFTCHECKNULL_GOTO(pMFT, done, E_OUTOFMEMORY);
DMFTCHECKHR_GOTO(pMFT->QueryInterface(iid, ppMFT), done);
done:
if (FAILED(hr))
{
SAFERELEASE(pMFT);
}
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
/*
Desciption:
This function will be called by the preview pin to execute the photo confirmation stored with the
MFT.
*/
STDMETHODIMP CMultipinMft::ProcessCapturePhotoConfirmationCallBack(
_In_ IMFMediaType* pMediaType,
_In_ IMFSample* pSample
)
{
//
//PhotoConfirmation Implementation
//Note this function doesn't scan the metadata as the pipeline does to find out which buffer is the photoconfirmation buffer
//The pipeline treats the preview buffer as the photo confirmation buffer and the driver marks the metadata on the buffer as being so.
//This example treats every buffer coming on the pin as the confirmation buffer.
//
HRESULT hr = S_OK;
ComPtr<IMFMediaType> spMediaType = nullptr;
LONGLONG timeStamp = 0;
DMFTCHECKHR_GOTO(MFCreateMediaType(&spMediaType), done);
DMFTCHECKHR_GOTO(pMediaType->CopyAllItems(spMediaType.Get()), done);
DMFTCHECKHR_GOTO(pSample->SetUnknown(MFSourceReader_SampleAttribute_MediaType_priv, spMediaType.Get()), done);
DMFTCHECKHR_GOTO(pSample->GetSampleTime(&timeStamp), done);
DMFTCHECKHR_GOTO(pSample->SetUINT64(MFSampleExtension_DeviceReferenceSystemTime, timeStamp), done);
if (m_spPhotoConfirmationCallback)
{
//
//We are directly sending the photo sample over to the consumers of the photoconfirmation interface.
//
ComPtr<IMFAsyncResult> spResult;
DMFTCHECKHR_GOTO(MFCreateAsyncResult(pSample, m_spPhotoConfirmationCallback.Get(), NULL, &spResult), done);
DMFTCHECKHR_GOTO(MFInvokeCallback(spResult.Get()), done);
}
done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
#endif
//
// Only worry about this if you have customs pins defined in the driver
//
STDMETHODIMP CMultipinMft::SetStreamingStateCustomPins(
DeviceStreamState State
)
{
HRESULT hr = S_OK;
if ( m_CustomPinCount > 0 )
{
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! Custom Pin State changing to %d", State);
for (ULONG ulIndex = 0; ulIndex < m_InPins.size(); ulIndex++)
{
BOOL isCustom = false;
CInPin* pInPin = static_cast<CInPin*>(m_InPins[ulIndex]);
if ( SUCCEEDED( CheckCustomPin(pInPin, &isCustom) )
&& ( isCustom ) )
{
pInPin->SetState(State);
}
}
}
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
}
|