123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /* Copyright (C) 2013 Mamadou DIOP
- * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
- *
- * This file is part of Open Source Doubango Framework.
- *
- * DOUBANGO 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 3 of the License, or
- * (at your option) any later version.
- *
- * DOUBANGO 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 DOUBANGO.
- */
- #include "mf_devices.h"
- #include "mf_utils.h"
- DeviceList::DeviceList()
- : m_ppDevices(NULL)
- , m_cDevices(0)
- {
- }
- DeviceList::~DeviceList()
- {
- Clear();
- }
- UINT32 DeviceList::Count()const
- {
- return m_cDevices;
- }
- void DeviceList::Clear()
- {
- for (UINT32 i = 0; i < m_cDevices; i++) {
- SafeRelease(&m_ppDevices[i]);
- }
- CoTaskMemFree(m_ppDevices);
- m_ppDevices = NULL;
- m_cDevices = 0;
- }
- HRESULT DeviceList::EnumerateDevices(const GUID& sourceType)
- {
- HRESULT hr = S_OK;
- IMFAttributes *pAttributes = NULL;
- Clear();
- // Initialize an attribute store. We will use this to
- // specify the enumeration parameters.
- hr = MFCreateAttributes(&pAttributes, 1);
- // Ask for source type = video capture devices
- if (SUCCEEDED(hr)) {
- hr = pAttributes->SetGUID(
- MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
- sourceType
- );
- }
- // Enumerate devices.
- if (SUCCEEDED(hr)) {
- hr = MFEnumDeviceSources(pAttributes, &m_ppDevices, &m_cDevices);
- }
- SafeRelease(&pAttributes);
- return hr;
- }
- HRESULT DeviceList::GetDeviceAtIndex(UINT32 index, IMFActivate **ppActivate)
- {
- if (index >= Count()) {
- return E_INVALIDARG;
- }
- *ppActivate = m_ppDevices[index];
- (*ppActivate)->AddRef();
- return S_OK;
- }
- HRESULT DeviceList::GetDeviceBest(IMFActivate **ppActivate, WCHAR *pszName /*= NULL*/)
- {
- UINT32 index = 0;
- if(pszName) {
- WCHAR *_pszName = NULL;
- BOOL bFound = FALSE;
- for(UINT32 i = 0; i < Count() && !bFound; ++i) {
- if((SUCCEEDED(GetDeviceName(i, &_pszName)))) {
- if(wcscmp(_pszName, pszName) == 0) {
- index = i;
- bFound = TRUE;
- // do not break the loop because we need to free(_pszName)
- }
- }
- if(_pszName) {
- CoTaskMemFree(_pszName), _pszName = NULL;
- }
- }
- }
- return GetDeviceAtIndex(index, ppActivate);
- }
- // The caller must free the memory for the string by calling CoTaskMemFree
- HRESULT DeviceList::GetDeviceName(UINT32 index, WCHAR **ppszName)
- {
- if (index >= Count()) {
- return E_INVALIDARG;
- }
- HRESULT hr = S_OK;
- hr = m_ppDevices[index]->GetAllocatedString(
- MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME,
- ppszName,
- NULL
- );
- return hr;
- }
- HRESULT DeviceListAudio::EnumerateDevices()
- {
- // call base class function
- return DeviceList::EnumerateDevices(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID);
- }
- HRESULT DeviceListVideo::EnumerateDevices()
- {
- // call base class function
- return DeviceList::EnumerateDevices(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
- }
|