Windows Mobile 6.0 SDK環境下,如何用DirectShow

來源:互聯網
上載者:User

Windows  Mobile  6.0  SDK環境下,如何用DirectShow

(2009-04-15 16:00:17)

http://topic.csdn.net/u/20090303/13/20118bcc-d703-490d-b7e2-1ebe2e4f9446.html

setformat 失敗的原因:

問題得到解決,非常感謝野蠻人的參與,讓我有信心做下去。
問題解決總結如下:
為什麼不能夠設定另外的解析度呢。後面我在資料上看到了一句話:
VIDEO_STREAM_CONFIG_CAPS中,setFormat如果PIN沒有串連,當串連的時候就試圖用新的格式;如果pin已經串連了,他就會用新的媒體格式重新串連,但是在這任何的一種情況下,下遊的filter都有可能拒絕新的媒體格式。
因為我在設定解析度之前先將pin串連到輸出的,因此,重新設定出錯了。
最後,我在pin串連之前設定解析度,就成功了。
總之,謝謝大家,尤其謝謝野蠻人,結貼。

http://topic.csdn.net/u/20080123/14/2AC749B0-EE67-4A56-96F1-FD5C772BDC3F.html

大概發下代碼吧
1.初始化
HRESULT hr = S_OK;
hr = CoInitializeEx(NULL,COINIT_MULTITHREADED );
if(FAILED(hr))
{
OutputDebugString(L"CoInitializeEx Failed!\r\n");
CoUninitialize();
return FALSE;
}
// 建立ICaptureGraphBuilder2介面
hr = CoCreateInstance(CLSID_CaptureGraphBuilder, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2,(void**)&pCaptureGraphBuild);
if(FAILED(hr))
{
OutputDebugString(L"CoCreateInstance CaptureGraphBuilder Failed!\r\n");
return FALSE;
}
// 建立IGraphBuilder介面
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&pGraphBuilder);
if(FAILED(hr))
{
OutputDebugString(L"CoCreateInstance GraphBuilder Failed!\r\n");
return FALSE;
}
hr = pCaptureGraphBuild->SetFiltergraph(pGraphBuilder);
if(FAILED(hr))
{
OutputDebugString(L"pCaptureGraphBuild SetFiltergraph GraphBuilder Failed!\r\n");
return FALSE;
}
2.尋找Camera
GUID guidCamera = { 0xCB998A05, 0x122C, 0x4166, 0x84, 0x6A, 0x93, 0x3E, 0x4D, 0x7E, 0x3C, 0x86 };
// Note about the above: The driver material doesn't ship as part of the SDK. This GUID is hardcoded
// here to be able to enumerate the camera drivers and pass the name of the driver to the video capture filter
di.dwSize = sizeof(di);
handle = FindFirstDevice( DeviceSearchByGuid, &guidCamera, &di );
if(( handle == NULL ) || ( di.hDevice == NULL ))
{
OutputDebugString(L"FindCameraDevice Failed!\r\n");
return FALSE;
}
FindClose( handle );
varCamName = di.szLegacyName;
PropBag.Write( _T("VCapName"), &varCamName );
hr = CoCreateInstance(CLSID_VideoCapture, NULL, CLSCTX_INPROC,IID_IBaseFilter, (void**)&pBaseFilter);
if(FAILED(hr))
{
OutputDebugString(L"CoCreateInstance pBaseFilter Failed!\r\n");
return FALSE;
}
hr = pBaseFilter->QueryInterface(IID_IPersistPropertyBag,(void**)&pPropertyBag );
if(FAILED(hr))
{
OutputDebugString(L"pBaseFilter QueryInterface pPropertyBag Failed!\r\n");
return FALSE;
}
pPropertyBag->Load( &PropBag, NULL );
hr = pGraphBuilder->AddFilter(pBaseFilter,_T("Video Capture Filter"));
if(FAILED(hr))
{
OutputDebugString(L"pGraphBuilder AddFilter pBaseFilter Failed!\r\n");
return FALSE;
}
hr = pCaptureGraphBuild->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,pBaseFilter, NULL, NULL);
if (FAILED(hr))
{
OutputDebugString(TEXT("Couldn't render the video capture stream.\r\n"));
pBaseFilter->Release();
return hr;
}
pBaseFilter->Release();
3.串連
HRESULT hr = S_OK;
IMediaControl* pMediaControl = NULL;
IVideoWindow* pVideoWindow = NULL;
//查詢IMediaControl介面
hr = pGraphBuilder->QueryInterface(IID_IMediaControl,(void**)&pMediaControl);
if(FAILED(hr))
{
OutputDebugString(L"pGraphBuilder QueryInterface pMediaControl Failed!\r\n");
return FALSE;
}
//查詢IVideoWindow
hr = pGraphBuilder->QueryInterface(IID_IVideoWindow,(void**)&pVideoWindow);
if(FAILED(hr))
{
OutputDebugString(L"pGraphBuilder QueryInterface pVideoWindow Failed!\r\n");
pMediaControl->Release();
return FALSE;
}
hr = pGraphBuilder->QueryInterface(IID_IMediaEventEx, (void **)&pMediaEvent);
if(FAILED(hr))
{
OutputDebugString(L"pGraphBuilder QueryInterface pMediaEvent Failed!\r\n");
return FALSE;
}
hr = pMediaEvent->SetNotifyWindow((OAHWND)g_hWnd,WM_GRAPHNOTIFY,0);//自訂訊息WM_GRAPHNOTIFY,到第三步裡Wndproc裡得到該訊息
hr = pVideoWindow->put_Owner(OAHWND(g_hWnd));
if(FAILED(hr))
{
OutputDebugString(L"pVideoWindow put_Owner Failed!\r\n");
return FALSE;
}
hr = pVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
if(FAILED(hr))
{
OutputDebugString(L"pVideoWindow put_WindowStyle Failed!\r\n");
return FALSE;
}
hr = pVideoWindow->put_Visible(OATRUE);
if(FAILED(hr))
{
OutputDebugString(L"pVideoWindow put_Visible Failed!\r\n");
return FALSE;
}
hr = pVideoWindow->SetWindowPosition(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
if(FAILED(hr))
{
OutputDebugString(L"pVideoWindow SetWindowPosition Failed!\r\n");
return FALSE;
}
hr = pVideoWindow->put_FullScreenMode(OATRUE);
hr = pMediaControl->Run();//開始視頻捕捉
if(FAILED(hr))
{
OutputDebugString(L"pMediaControl Run Failed!\r\n");
return FALSE;
}
4.播放
case WM_GRAPHNOTIFY:
HandleGraphEvent();
HRESULT HandleGraphEvent(void)
{
LONG evCode, evParam1, evParam2;
HRESULT hr=S_OK;
// Make sure that we don't access the media event interface
// after it has already been released.
if (!pMediaEvent)
return S_OK;
// Process all queued events
while(SUCCEEDED(pMediaEvent->GetEvent(&evCode, (LONG_PTR *) &evParam1,
(LONG_PTR *) &evParam2, 0)))
{
// Free memory associated with callback, since we're not using it
hr = pMediaEvent->FreeEventParams(evCode, evParam1, evParam2);
// If this is the end of the clip, reset to beginning
if(EC_COMPLETE == evCode)
{
LONGLONG pos=0;
// Reset to first frame of movie
hr = pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,NULL, AM_SEEKING_NoPositioning);
if (FAILED(hr))
{
// Some custom filters (like the Windows CE MIDI filter)
// may not implement seeking interfaces (IMediaSeeking)
// to allow seeking to the start.  In that case, just stop
// and restart for the same effect.  This should not be
// necessary in most cases.
if (FAILED(hr = pMediaControl->Stop()))
{
//Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr);
break;
}
if (FAILED(hr = pMediaControl->Run()))
{
//Msg(TEXT("Failed(0x%08lx) to reset media clip!\r\n"), hr);
break;
}
}
}
}
return hr;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.