- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想使用 Windows Media Foundation 枚举我计算机上的相机设备,我使用了 Microsoft 上的代码:http://msdn.microsoft.com/en-us/library/windows/desktop/dd940326(v=vs.85).aspx我复制了他们在这里使用的相同代码:http://msdn.microsoft.com/en-us/library/windows/desktop/ee663604(v=vs.85).aspx
当我使用他们的代码时,我得到了我的网络摄像头设备名称,但是我的代码没有找到任何摄像头捕获设备。我能够找到原因。
代码如下:
#pragma once
#include <new>
#include <windows.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <Wmcodecdsp.h>
#include <assert.h>
#include <Dbt.h>
#include <shlwapi.h>
#include <mfplay.h>
#include <iostream>
const UINT WM_APP_PREVIEW_ERROR = WM_APP + 1; // wparam = HRESULT
class DeviceList
{
UINT32 m_cDevices; // contains the number of devices
IMFActivate **m_ppDevices; // contains properties about each device
public:
DeviceList() : m_ppDevices(NULL), m_cDevices(0)
{
}
~DeviceList()
{
Clear();
}
UINT32 Count() const { return m_cDevices; }
void Clear();
HRESULT EnumerateDevices();
HRESULT GetDevice(UINT32 index, IMFActivate **ppActivate);
HRESULT GetDeviceName(UINT32 index, WCHAR **ppszName);
};
#include "DeviceList.h"
/*
* A templated Function SafeRelease releasing pointers memories
* @param ppT the pointer to release
*/
template <class T> void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
/*
* A function which copy attribute form source to a destination
* @ param pSrc is an Interface to store key/value pairs of an Object
* @ param pDest is an Interface to store key/value pairs of an Object
* @ param GUID is an unique identifier
* @ return HRESULT return errors warning condition on windows
*/
HRESULT CopyAttribute(IMFAttributes *pSrc, IMFAttributes *pDest, const GUID& key);
/*
* A Method form DeviceList which clear the list of Devices
*/
void DeviceList::Clear()
{
for (UINT32 i = 0; i < m_cDevices; i++)
{
SafeRelease(&m_ppDevices[i]);
}
CoTaskMemFree(m_ppDevices);
m_ppDevices = NULL;
m_cDevices = 0;
}
/*
* A function which enumerate the list of Devices.
* @ return HRESULT return errors warning condition on windows
*/
HRESULT DeviceList::EnumerateDevices()
{
HRESULT hr = S_OK;
IMFAttributes *pAttributes = NULL;
this->Clear();
// Initialize an attribute store. We will use this to
// specify the enumeration parameters.
std::cout << "Enumerate devices" << std::endl;
hr = MFCreateAttributes(&pAttributes, 1);
// Ask for source type = video capture devices
if (SUCCEEDED(hr))
{
std::cout << "Enumerate devices" << std::endl;
hr = pAttributes->SetGUID(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
);
}
// Enumerate devices.
if (SUCCEEDED(hr))
{
std::cout << "Enumerate devices:" << m_cDevices << std::endl;
hr = MFEnumDeviceSources(pAttributes, &m_ppDevices, &m_cDevices);
}
SafeRelease(&pAttributes);
return hr;
}
/*
* A function which copy attribute form source to a destination
* @ param index the index in an array
* @ param ppActivate is an Interface to store key/value pairs of an Object
* @ return HRESULT return errors warning condition on windows
*/
HRESULT DeviceList::GetDevice(UINT32 index, IMFActivate **ppActivate)
{
if (index >= Count())
{
return E_INVALIDARG;
}
*ppActivate = m_ppDevices[index];
(*ppActivate)->AddRef();
return S_OK;
}
/*
* A function which get the name of the devices
* @ param index the index in an array
* @ param ppszName Name of the device
*/
HRESULT DeviceList::GetDeviceName(UINT32 index, WCHAR **ppszName)
{
std::cout << "Get Device name" << std::endl;
if (index >= Count())
{
return E_INVALIDARG;
}
HRESULT hr = S_OK;
hr = m_ppDevices[index]->GetAllocatedString(
MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME,
ppszName,
NULL
);
return hr;
}
#include <iostream>
#include "DeviceList.h"
HRESULT UpdateDeviceList()
{
HRESULT hr = S_OK;
WCHAR *szFriendlyName = NULL;
DeviceList g_devices;
g_devices.Clear();
hr = g_devices.EnumerateDevices();
if (FAILED(hr)) { goto done; }
std::cout << "Nb devices found:"<< g_devices.Count() << std::endl;
for (UINT32 iDevice = 0; iDevice < g_devices.Count(); iDevice++)
{
//std::cout << "" << std::endl;
hr = g_devices.GetDeviceName(iDevice, &szFriendlyName);
if (FAILED(hr)) { goto done; }
std::cout << szFriendlyName << std::endl;
// The list might be sorted, so the list index is not always the same as the
// array index. Therefore, set the array index as item data.
CoTaskMemFree(szFriendlyName);
szFriendlyName = NULL;
}
std::cout << "End of EnumDeviceList" << std::endl;
done:
return hr;
}
int main()
{
std::cout <<"Main" << std::endl;
UpdateDeviceList();
while (1);
return 0;
最佳答案
在开始调用其他媒体基础 API 函数之前,您需要执行 MFStartup(MF_VERSION);
。
然后在 MFEnumDeviceSources
下一行对其进行初始化之前打印 m_cDevices
。
std::cout << "Enumerate devices:" << m_cDevices << std::endl;
hr = MFEnumDeviceSources(pAttributes, &m_ppDevices, &m_cDevices);
修复此问题后,您的代码将开始为您获取设备。
关于c++ - Windows Media Foundation 枚举相机设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23144501/
我想加载带有本地回退的 foundation.min.js 的 CDN 版本。问题是:如何检测是否加载了 foundation.js? 我看到它是用 jQuery、modernizr、Bootstra
我从 v3 开始就一直在使用 Foundation,所以我没想到会出现这种困惑。 在这种特殊情况下,我需要一个固定宽度的左列(大 3),然后是一个流动/响应内容列(大 9)作为其余部分。
我在从最新的 Foundation 定制 Orbit 时遇到问题。来自 the docs : Orbit 选项此时只能在初始化时传入。 { timer_speed: 10000, animat
在以下非常基本的示例中,开关可以正常工作并且样式正确。如果我只是将 foundation.css 版本从 5.5.2 更改为 6.0.5,切换样式就会丢失。为什么开关在 Foundation 6.0
如何禁用中/小屏幕的顶部栏折叠? 我按照 Here 中的说明进行操作但无论我将最小宽度设置为什么,我都会得到相同的结果。 最佳答案 如果您使用的是 SCSS 版本,那么您可以修改断点。 $topbar
出于多种原因,复选框在最新的 Foundation (4.1.6) 中存在问题。有没有一种简单的方法可以阻止 Foundation 接管它们?我需要 custom我的类 form s 其他原因。我如何
我希望在显示模式窗口中播放的视频在模式窗口关闭时停止播放(谁不呢?)。通过将 iframe 源设置为空,可以使用 jQuery 轻松完成此操作。 但我不知道如何让它在回调中工作。模态窗口本身按预期运行
我最近开始将 Zurb Foundation 4 用于 Asp MVC 网站,但我不太明白开关控件应该如何工作。文档没有说太多 http://foundation.zurb.com/docs/comp
是否可以合并top-bar和 tab-bar ( Canvas 外)? 这个: 调整到手机尺寸时变成这样: 但我还想包括标签栏( Canvas 外)所以它变成这样 我无法想象这是如何做到的,我试图制作
我的问题是,在桌面上我喜欢先有菜单,然后是最右上角的标志。目前,当我将模板缩小到移动版本时, Logo 位于菜单下方,这并不令人满意。我想在菜单之前吃。我试过使用推/拉没有成功。 在移动 View 中
我直接从他们的网站 https://foundation.zurb.com/sites/docs/top-bar.html 复制了基础导航栏语法并且下拉菜单功能似乎不起作用 代码如下:
刚刚切换我的 Rails 项目以测试 Zurb Foundation 5,现在切换顶部栏菜单不起作用。 当视口(viewport)很小时,顶部栏菜单项消失并且菜单图标像以前一样显示,但是当我单击菜单图
如何在 Foundation 4 中以编程方式显示模态? 在 Foundation 3 中,我们有易于使用的 reveal() 方法。 您可以在 Foundation 4 中使用什么?请帮忙。 最佳答
我正在使用启用了 flexbox 的 Foundation 6 Zurb 模板,但按钮组的扩展功能不起作用。 当我添加扩展类时,最后一个按钮不会填满最后一个空格并掉到左侧的下一行。文本不再内联,按钮的
我正在使用 Zurb Foundation 并具有以下 html: Tab 1 Content of section 1. Tab
我正在尝试使用 zurb Foundation 5 显示模式。但是当我单击按钮时它不起作用并且无法打开。我正在使用这个 html 代码。 index Awesome. I ha
有什么我可以在命令行中输入的东西来找出我正在运行的版本吗? 最佳答案 在不了解您的具体情况的情况下,最简单的方法是在初始化 Foundation ( $(document).foundation();
Foundation 5 上曾经有一个“圆形”类,可以将按钮组转换为具有圆形边缘。我如何在 Foundation 6 中执行此操作? 最佳答案 这在 Foundation 6 中是不可能的。为了减小文
我正在使用 Zurb 的 Foundation 4.2.3,但是当我打印页面时,网格布局始终没有得到维护。 例如, XXX Lorem
作为 Zurb's Foundation 一部分的轨道 slider 好像加了一个类hide-for-small到导航。 我需要导航仍然显示,以便显示我的内容。我试过删除 hide-for-small
我是一名优秀的程序员,十分优秀!