1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2006-2012 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // A permission to use the source code is granted as long as reference to |
---|
6 | // source website http://alax.info is retained. |
---|
7 | |
---|
8 | #include "stdafx.h" |
---|
9 | #include <windows.h> |
---|
10 | #include <dshow.h> |
---|
11 | |
---|
12 | #pragma comment(lib, "strmiids.lib") |
---|
13 | |
---|
14 | int _tmain(int argc, _TCHAR* argv[]) |
---|
15 | { |
---|
16 | _ATLTRY |
---|
17 | { |
---|
18 | ATLENSURE_SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); |
---|
19 | _ATLTRY |
---|
20 | { |
---|
21 | CComPtr<ICreateDevEnum> pCreateDevEnum; |
---|
22 | ATLENSURE_SUCCEEDED(pCreateDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum)); |
---|
23 | CComPtr<IEnumMoniker> pEnumMoniker; |
---|
24 | ATLENSURE_SUCCEEDED(pCreateDevEnum->CreateClassEnumerator(CLSID_AudioInputDeviceCategory, &pEnumMoniker, 0)); |
---|
25 | CComPtr<IMoniker> pMoniker; |
---|
26 | while(pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK) |
---|
27 | { |
---|
28 | _ATLTRY |
---|
29 | { |
---|
30 | LPOLESTR pszDisplayName = NULL; |
---|
31 | ATLVERIFY(SUCCEEDED(pMoniker->GetDisplayName(NULL, NULL, &pszDisplayName))); |
---|
32 | // TODO: Free pszDisplayName |
---|
33 | if(pszDisplayName) |
---|
34 | _tprintf(_T("Moniker Display Name: %ls\n"), pszDisplayName); |
---|
35 | CComPtr<IPropertyBag> pPropertyBag; |
---|
36 | ATLENSURE_SUCCEEDED(pMoniker->BindToStorage(NULL, NULL, __uuidof(IPropertyBag), (VOID**) &pPropertyBag)); |
---|
37 | CComVariant vFriendlyName; |
---|
38 | ATLENSURE_SUCCEEDED(pPropertyBag->Read(L"FriendlyName", &vFriendlyName, NULL)); |
---|
39 | ATLENSURE_THROW(vFriendlyName.vt == VT_BSTR, E_FAIL); |
---|
40 | _tprintf(_T("Friendly Name: %s\n"), CString(vFriendlyName.bstrVal)); |
---|
41 | CComPtr<IBaseFilter> pBaseFilter; |
---|
42 | ATLENSURE_SUCCEEDED(pMoniker->BindToObject(NULL, NULL, __uuidof(IBaseFilter), (VOID**) &pBaseFilter)); |
---|
43 | CComPtr<IEnumPins> pEnumPins; |
---|
44 | ATLENSURE_SUCCEEDED(pBaseFilter->EnumPins(&pEnumPins)); |
---|
45 | CComPtr<IPin> pPin; |
---|
46 | while(pEnumPins->Next(1, &pPin, NULL) == S_OK) |
---|
47 | { |
---|
48 | _ATLTRY |
---|
49 | { |
---|
50 | CComQIPtr<IAMStreamConfig> pAmStreamConfig = pPin; |
---|
51 | if(pAmStreamConfig) |
---|
52 | { |
---|
53 | PIN_INFO PinInformation; |
---|
54 | ATLENSURE_SUCCEEDED(pPin->QueryPinInfo(&PinInformation)); |
---|
55 | reinterpret_cast<CComPtr<IBaseFilter>&>(PinInformation.pFilter) = NULL; |
---|
56 | _tprintf(_T(" Pin: %s\n"), CString(PinInformation.achName)); |
---|
57 | INT nCapabilityCount = 0; |
---|
58 | INT nSize = 0; |
---|
59 | ATLENSURE_SUCCEEDED(pAmStreamConfig->GetNumberOfCapabilities(&nCapabilityCount, &nSize)); |
---|
60 | _tprintf(_T(" Capability Count: %d\n"), nCapabilityCount); |
---|
61 | CTempBuffer<AUDIO_STREAM_CONFIG_CAPS> pCapability; |
---|
62 | ATLENSURE_THROW(nSize >= sizeof *pCapability, E_FAIL); |
---|
63 | ATLENSURE_THROW(pCapability.AllocateBytes(nSize), E_OUTOFMEMORY); |
---|
64 | for(INT nCapabilityIndex = 0; nCapabilityIndex < nCapabilityCount; nCapabilityIndex++) |
---|
65 | { |
---|
66 | _tprintf(_T(" Capability %d:\n"), nCapabilityIndex); |
---|
67 | AM_MEDIA_TYPE* pMediaType = NULL; |
---|
68 | ATLENSURE_SUCCEEDED(pAmStreamConfig->GetStreamCaps(nCapabilityIndex, &pMediaType, (BYTE*) (AUDIO_STREAM_CONFIG_CAPS*) pCapability)); |
---|
69 | ATLASSERT(pMediaType); |
---|
70 | // TODO: Free pMediaType |
---|
71 | _tprintf(_T(" AM_MEDIA_TYPE:\n")); |
---|
72 | // SUGG: majortype, subtype |
---|
73 | _tprintf(_T(" .bFixedSizeSamples: %d\n"), pMediaType->bFixedSizeSamples); |
---|
74 | _tprintf(_T(" .bTemporalCompression: %d\n"), pMediaType->bTemporalCompression); |
---|
75 | _tprintf(_T(" .lSampleSize: %d\n"), pMediaType->lSampleSize); |
---|
76 | // SUGG: formattype, pUnk |
---|
77 | _tprintf(_T(" .cbFormat: %d\n"), pMediaType->cbFormat); |
---|
78 | if(pMediaType->formattype == FORMAT_WaveFormatEx) |
---|
79 | { |
---|
80 | WAVEFORMATEX* pWaveFormatEx = (WAVEFORMATEX*) pMediaType->pbFormat; |
---|
81 | _tprintf(_T(" WAVEFORMATEX:\n")); |
---|
82 | _tprintf(_T(" .wFormatTag: %d\n"), pWaveFormatEx->wFormatTag); |
---|
83 | _tprintf(_T(" .nChannels: %d\n"), pWaveFormatEx->nChannels); |
---|
84 | _tprintf(_T(" .nSamplesPerSec: %d\n"), pWaveFormatEx->nSamplesPerSec); |
---|
85 | _tprintf(_T(" .nAvgBytesPerSec: %d\n"), pWaveFormatEx->nAvgBytesPerSec); |
---|
86 | _tprintf(_T(" .nBlockAlign: %d\n"), pWaveFormatEx->nBlockAlign); |
---|
87 | _tprintf(_T(" .wBitsPerSample: %d\n"), pWaveFormatEx->wBitsPerSample); |
---|
88 | _tprintf(_T(" .cbSize: %d\n"), pWaveFormatEx->cbSize); |
---|
89 | // SUGG: Extra data |
---|
90 | } |
---|
91 | ATLASSERT(pCapability->guid == MEDIATYPE_Audio); |
---|
92 | _tprintf(_T(" AUDIO_STREAM_CONFIG_CAPS:\n")); |
---|
93 | _tprintf(_T(" .MinimumChannels: %d\n"), pCapability->MinimumChannels); |
---|
94 | _tprintf(_T(" .MaximumChannels: %d\n"), pCapability->MaximumChannels); |
---|
95 | _tprintf(_T(" .ChannelsGranularity: %d\n"), pCapability->ChannelsGranularity); |
---|
96 | _tprintf(_T(" .MinimumBitsPerSample: %d\n"), pCapability->MinimumBitsPerSample); |
---|
97 | _tprintf(_T(" .MaximumBitsPerSample: %d\n"), pCapability->MaximumBitsPerSample); |
---|
98 | _tprintf(_T(" .BitsPerSampleGranularity: %d\n"), pCapability->BitsPerSampleGranularity); |
---|
99 | _tprintf(_T(" .MinimumSampleFrequency: %d\n"), pCapability->MinimumSampleFrequency); |
---|
100 | _tprintf(_T(" .MaximumSampleFrequency: %d\n"), pCapability->MaximumSampleFrequency); |
---|
101 | _tprintf(_T(" .SampleFrequencyGranularity: %d\n"), pCapability->SampleFrequencyGranularity); |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | _ATLCATCHALL() |
---|
106 | { |
---|
107 | _tprintf(_T("An exception has been caught\n")); |
---|
108 | } |
---|
109 | pPin.Release(); |
---|
110 | } |
---|
111 | } |
---|
112 | _ATLCATCHALL() |
---|
113 | { |
---|
114 | _tprintf(_T("An exception has been caught\n")); |
---|
115 | } |
---|
116 | pMoniker.Release(); |
---|
117 | } |
---|
118 | } |
---|
119 | _ATLCATCHALL() |
---|
120 | { |
---|
121 | CoUninitialize(); |
---|
122 | _ATLRETHROW; |
---|
123 | } |
---|
124 | CoUninitialize(); |
---|
125 | } |
---|
126 | _ATLCATCHALL() |
---|
127 | { |
---|
128 | } |
---|
129 | return 0; |
---|
130 | } |
---|
131 | |
---|