I am writing an app on top media foundation under win 7, I use IMFMediaSource to query the cameras interfaces to get frames and other properties. its weird but I cant find a way to change resolution. it seems that if I used IMFCaptureSource i could use SetCurrentDeviceMediaType to change resolution but its only supported in Windows 8. so we cant change resolution under win 7 using media foundation?? is there a way to use direct show with IMFMediaSource to change resolution?? if so, can anyone help with some code sample?

thanks!

有帮助吗?

解决方案

ok, so I found out eventually. Iam using IMFSourceReader to get samples from the MFMediaSource, so after configurating the SourceReader you can iterate the native media types that the camera supports like this :

HRESULT nativeTypeErrorCode = S_OK;
DWORD count = 0;
UINT32 streamIndex = 0;
UINT32 requiredWidth = 1600;
UINT32 requiredheight = 900;
while (nativeTypeErrorCode == S_OK)
{
    IMFMediaType * nativeType = NULL;    
    nativeTypeErrorCode = m_pReader->GetNativeMediaType(streamIndex, count, &nativeType);
    if(nativeTypeErrorCode != S_OK) continue;

    // get the media type 
    GUID nativeGuid = {0};
    hr = nativeType->GetGUID(MF_MT_SUBTYPE, &nativeGuid);

    if (FAILED(hr)) return hr;

    UINT32 width, height;
    hr = ::MFGetAttributeSize(nativeType, MF_MT_FRAME_SIZE, &width, &height);

    if (FAILED(hr)) return hr;

    if(nativeGuid == <my type guid> && width == requiredWidth && height == requiredheight)
    {
        // found native config, set it
        hr = m_pReader->SetCurrentMediaType(streamIndex, NULL, nativeType);
        if (FAILED(hr)) return hr;
        break;
    }

    SafeRelease(&nativeType);
    count++;
}

this means that Iam not creating a new media type with the resolution I require, I get the native media type with the configuration I need, and I set it on the SourceReader.

hope it will help the future media foundation traveler... :)

其他提示

You can query directshow interface from IMediaSource which can change resolution.

for ex:for Camera control properties I do like this.

IAMCameraControl* m_pCameraControl = NULL;
HRESULT hr = S_OK;

hr = pMediaSource->QueryInterface(IID_PPV_ARGS(&m_pCameraControl));
if (m_pCameraControl == NULL)
{
    return E_FAIL;
}

In the same way in your case I am not sure about the interface but I guess it will be in following way.

 IAMStreamConfig * m_pStreamConfig = NULL;
HRESULT hr = S_OK;

hr = pMediaSource->QueryInterface(IID_PPV_ARGS(&m_pStreamConfig ));
if (m_pCameraControl == NULL)
{
    return E_FAIL;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top