|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionTo get a list of available audio devices, video devices, and codecs on your system, you would require a starting point in DirectX or rather DirectShow. This extremely small program will give you a place to start with. Though, to play audio and videos, we need modifications to our program, and especially, if we are to write a program that would require instant playback and file-saving etc. This small program will, however, give the main starting point for beginners who are interested in leering DirectShow programming with access to input/output devices and audio/video codecs. BackgroundDirectX uses the term 'filters' to specify different hardware and software codecs. Whereas, here in the program, I have used the term 'Device'. When I started programming, I never liked to use the term 'filters', and always resorted to the term 'device', so I personally think that some of you feel like that too! There is limited exception handling, as with my previous tutorials. I deliberately did that so that the code would become more user-friendly, instead of being a collection of professional code. As you know, DirectX is COM based, so a little COM understanding would be good. CodeThere are two simple functions apart from void HR_Failed(HRESULT); void Device_Reader(GUID,ICreateDeviceEnum); First, let us see what we have in The hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);// Initialise COM if (SUCCEEDED(hr)) { cout<<"COM Initialisation successful"<<endl; } else HR_Failed(hr) In the above lines of code, void HR_Failed(HRESULT hr) { TCHAR szErr[MAX_ERROR_TEXT_LEN]; DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN); if (res == 0) { StringCchPrintf(szErr, MAX_ERROR_TEXT_LEN, L"Unknown Error: 0x%2x", hr); } MessageBox(0, szErr, TEXT("Error!"), MB_OK | MB_ICONERROR); return; } The function First, we initialize the device enumeration with a call to hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pDeviceEnum);//Initialise Device enumerator We then need to create a device enumeration which allows us to get hold of or "read in" the audio devices that are available on the system. Here, we need to specify the category of devices that we are trying to read or get hold of. We do this enumeration by passing on the GUID for each category as defined by the MSDN documentation. In this case, I have used quite a few: The other usefulness of using a device enumeration via Class ID is that suppose we have two sound cards and both of them support the same filters, using this enumeration we can treat them distinctively as separate instances. After the enumeration, we cannot simply use pin properties or access any other methods for the devices in the void Device_Reader(GUID DEVICE_CLSID,ICreateDevEnum *pDeviceEnum ) { HRESULT hr; IMoniker *pDeviceMonik = NULL;// Device moniker IEnumMoniker *pEnumCat = NULL;// Device enumeration moniker VARIANT varName; // Enumerate the specified device, distinguished by DEVICE_CLSID hr = pDeviceEnum->CreateClassEnumerator(DEVICE_CLSID, &pEnumCat, 0); if (hr == S_OK) { ULONG cFetched; while (pEnumCat->Next(1, &pDeviceMonik, &cFetched) == S_OK) //Pickup as moniker { IPropertyBag *pPropBag = NULL; //bind the properties of the moniker hr = pDeviceMonik->BindToStorage(0, 0, IID_IPropertyBag,(void **)&pPropBag); if (SUCCEEDED(hr)) { // Initialise the variant data type VariantInit(&varName); //extract the FriendlyName // - This is the name we see in GraphEdit hr = pPropBag->Read(L"FriendlyName", &varName, 0); if (SUCCEEDED(hr)) { wcout<<varName.bstrVal<<endl; // show the name } else HR_Failed(hr); //clear the variant data type VariantClear(&varName); pPropBag->Release();//release the properties } else HR_Failed(hr); pDeviceMonik->Release();//release Device moniker } pEnumCat->Release();//release category enumerator } else HR_Failed(hr); } The function accepts the GUID and the pointer to the
What happens when a filter is not found??A call to
Points of interestGraphEdit has always been the tool for developers to get out of trouble. Though it looks very primitive, it is an absolute beauty. Only after using GraphEdit did I realise that it displays exactly the same "FriendlyName" as seen in the console output. So, be sure you have a go at it. If you cannot find GraphEdit on your system, make sure you have installed the Windows SDK, and look in the 'Bin' directory to find GrapEdit.exe. The code is built with the following
HistoryFirst post. Will be updated if required. References
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||