void DirectShowMovieTexture::loadMovie( const Ogre::String& moviePath, bool horizontalMirroring) { HRESULT hr; // log it! Ogre::LogManager::getSingletonPtr()->logMessage( Ogre::String("[DSHOW] Loading movie named '")+ moviePath+"'."); // destroy previous movie objects (if any) unloadMovie(); // create filter graph and get interfaces hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**) &dsdata->pGraph); if (FAILED(hr)) throw("[DSHOW] Error in creating graph"); hr=dsdata->pGraph->QueryInterface(IID_IMediaControl, (void**) & dsdata->pControl); if (FAILED(hr)) throw("[DSHOW] Error in querying media control"); hr=dsdata->pGraph->QueryInterface(IID_IMediaEvent, (void**) & dsdata->pEvent); if (FAILED(hr)) throw("[DSHOW] Error in querying media event"); hr=dsdata->pGraph->QueryInterface(IID_IMediaSeeking, (void**) & dsdata->pSeeking); if (FAILED(hr)) throw("[DSHOW] Error in querying seeking interface"); // create sample grabber hr=CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&dsdata->pGrabberF); if (FAILED(hr)) throw("[DSHOW] Error in creating sample grabber"); // add sample grabber to the graph hr=dsdata->pGraph->AddFilter(dsdata->pGrabberF, L"Sample Grabber"); if (FAILED(hr)) throw("[DSHOW] Error in adding sample grabber to the graph"); // get sample grabber object dsdata->pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&dsdata->pGrabber); // set sample grabber media type AM_MEDIA_TYPE mt; ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; mt.formattype = FORMAT_VideoInfo; hr=dsdata->pGrabber->SetMediaType(&mt); if (FAILED(hr)) throw("[DSHOW] Error in setting sample grabber media type"); //--------------- Seregvan's modification IBaseFilter* srcFilter; WCHAR* filepath = util_convertCStringToWString(moviePath.c_str()); hr = dsdata->pGraph->AddSourceFilter(filepath, L"Source", &srcFilter); if(FAILED(hr)) throw ("[DSHOW] Unsupported media type!"); // Connect the src and grabber hr = ConnectFilters(dsdata->pGraph, srcFilter, dsdata->pGrabberF); if(FAILED(hr)) throw ("[DSHOW] Unsupported media type!"); IBaseFilter * render; hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&render); if(FAILED(hr)) throw ("[DSHOW] Unsupported media type!"); dsdata->pGraph->AddFilter(render, L"Render"); hr = ConnectFilters(dsdata->pGraph, dsdata->pGrabberF, render); if(FAILED(hr)) throw ("[DSHOW] Can't create render!"); //--------------- End of modification // open the file! filepath=util_convertCStringToWString(moviePath.c_str()); hr=dsdata->pGraph->RenderFile(filepath, NULL); if (FAILED(hr)) throw("[DSHOW] Error opening video file!"); // disable auto show // (wouldn't be needed if we used the null renderer) hr=dsdata->pGraph->QueryInterface(IID_IVideoWindow, (void**) & dsdata->pWindow); if (FAILED(hr)) throw("[DSHOW] Error getting video window interface"); dsdata->pWindow->put_AutoShow(OAFALSE); // get video information AM_MEDIA_TYPE mtt; hr=dsdata->pGrabber->GetConnectedMediaType(&mtt); if (FAILED(hr)) throw("[DSHOW] Error getting connected media type info"); VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*) mtt.pbFormat; dsdata->videoWidth=vih->bmiHeader.biWidth; dsdata->videoHeight=vih->bmiHeader.biHeight; // microsoft's help version of free media type if (mtt.cbFormat != 0) { CoTaskMemFree((PVOID)mtt.pbFormat); mtt.cbFormat = 0; mtt.pbFormat = NULL; } if (mtt.pUnk != NULL) { mtt.pUnk->Release(); mtt.pUnk = NULL; } // log it Ogre::LogManager::getSingletonPtr()->logMessage( Ogre::String("[DSHOW] -> This movie has dimensions: ")+ Ogre::StringConverter::toString(dsdata->videoWidth)+"x"+ Ogre::StringConverter::toString(dsdata->videoHeight)+"."); // set sampling options dsdata->pGrabber->SetOneShot(FALSE); dsdata->pGrabber->SetBufferSamples(TRUE); // set some basic data mHorizontalMirroring=horizontalMirroring; // clean the texture, so that it's ready for rendering this video cleanTextureContents(); }
void DirectShowMovieTexture::loadMovie( const Ogre::String& moviePath, bool horizontalMirroring) { HRESULT hr; // log it! Ogre::LogManager::getSingletonPtr()->logMessage( Ogre::String("[DSHOW] Loading movie named '")+ moviePath+"'."); // destroy previous movie objects (if any) unloadMovie(); // create filter graph and get interfaces hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**) &dsdata->pGraph); if (FAILED(hr)) throw("[DSHOW] Error in creating graph"); hr=dsdata->pGraph->QueryInterface(IID_IMediaControl, (void**) & dsdata->pControl); if (FAILED(hr)) throw("[DSHOW] Error in querying media control"); hr=dsdata->pGraph->QueryInterface(IID_IMediaEvent, (void**) & dsdata->pEvent); if (FAILED(hr)) throw("[DSHOW] Error in querying media event"); hr=dsdata->pGraph->QueryInterface(IID_IMediaSeeking, (void**) & dsdata->pSeeking); if (FAILED(hr)) throw("[DSHOW] Error in querying seeking interface"); // create sample grabber hr=CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&dsdata->pGrabberF); if (FAILED(hr)) throw("[DSHOW] Error in creating sample grabber"); // add sample grabber to the graph hr=dsdata->pGraph->AddFilter(dsdata->pGrabberF, L"Sample Grabber"); if (FAILED(hr)) throw("[DSHOW] Error in adding sample grabber to the graph"); // get sample grabber object dsdata->pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&dsdata->pGrabber); // set sample grabber media type AM_MEDIA_TYPE mt; ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; mt.formattype = FORMAT_VideoInfo; hr=dsdata->pGrabber->SetMediaType(&mt); if (FAILED(hr)) throw("[DSHOW] Error in setting sample grabber media type"); // open the file! WCHAR* filepath=util_convertCStringToWString(moviePath.c_str()); hr=dsdata->pGraph->RenderFile(L"C:\Users\Harry\Desktop\Ogre_Framework\bin\welcome.avi", NULL); if (FAILED(hr)) throw("[DSHOW] Error opening video file!"); // disable auto show // (wouldn't be needed if we used the null renderer) hr=dsdata->pGraph->QueryInterface(IID_IVideoWindow, (void**) & dsdata->pWindow); if (FAILED(hr)) throw("[DSHOW] Error getting video window interface"); dsdata->pWindow->put_AutoShow(OAFALSE); // get video information AM_MEDIA_TYPE mtt; hr=dsdata->pGrabber->GetConnectedMediaType(&mtt); if (FAILED(hr)) throw("[DSHOW] Error getting connected media type info"); VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*) mtt.pbFormat; dsdata->videoWidth=vih->bmiHeader.biWidth; dsdata->videoHeight=vih->bmiHeader.biHeight; ResetSize(dsdata->videoWidth,dsdata->videoHeight); //纹理的创建现在修改到了这里,原来在构造函数中 //放在这里可以根据视频的大小来生成纹理的大小 //这样可以让视频完全平铺到面片上 mTexture=Ogre::TextureManager::getSingleton().createManual( "DirectShowManualTexture",// name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,// texture type mTexWidth, mTexHeight, 0,// number of mipmaps Ogre::PF_BYTE_BGRA,// pixel format Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE// usage ); // microsoft's help version of free media type if (mtt.cbFormat != 0) { CoTaskMemFree((PVOID)mtt.pbFormat); mtt.cbFormat = 0; mtt.pbFormat = NULL; } if (mtt.pUnk != NULL) { mtt.pUnk->Release(); mtt.pUnk = NULL; } // log it Ogre::LogManager::getSingletonPtr()->logMessage( Ogre::String("[DSHOW] -> This movie has dimensions: ")+ Ogre::StringConverter::toString(dsdata->videoWidth)+"x"+ Ogre::StringConverter::toString(dsdata->videoHeight)+"."); // set sampling options dsdata->pGrabber->SetOneShot(FALSE); dsdata->pGrabber->SetBufferSamples(TRUE); // set some basic data mHorizontalMirroring=horizontalMirroring; // clean the texture, so that it's ready for rendering this video cleanTextureContents(); }