[Deinterlace-checkins] CVS: DScaler/DScaler/dshowsource DShowFileSource.cpp,1.2,1.3
Brought to you by:
adcockj,
dschmelzer
From: Torbj?rn J. <to...@us...> - 2002-07-29 17:42:56
|
Update of /cvsroot/deinterlace/DScaler/DScaler/dshowsource In directory usw-pr-cvs1:/tmp/cvs-serv19966 Modified Files: DShowFileSource.cpp Log Message: support for opening graphedit saved filter graphs Index: DShowFileSource.cpp =================================================================== RCS file: /cvsroot/deinterlace/DScaler/DScaler/dshowsource/DShowFileSource.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** DShowFileSource.cpp 3 Apr 2002 19:54:28 -0000 1.2 --- DShowFileSource.cpp 29 Jul 2002 17:42:53 -0000 1.3 *************** *** 25,28 **** --- 25,31 ---- // // $Log$ + // Revision 1.3 2002/07/29 17:42:53 tobbej + // support for opening graphedit saved filter graphs + // // Revision 1.2 2002/04/03 19:54:28 tobbej // modified connect() to try a little more before giving up on the file *************** *** 47,50 **** --- 50,54 ---- #include "exception.h" #include "PinEnum.h" + #include "..\..\..\DSRend\DSRend.h" #ifdef _DEBUG *************** *** 59,70 **** { USES_CONVERSION; ! ! HRESULT hr=m_pGraph->AddSourceFilter(A2W(filename.c_str()),NULL,&m_pFileSource); ! if(FAILED(hr)) ! { ! throw CDShowException("Failed to add file",hr); ! } ! ! hr=m_pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2); if(FAILED(hr)) { --- 63,67 ---- { USES_CONVERSION; ! HRESULT hr=m_pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2); if(FAILED(hr)) { *************** *** 76,79 **** --- 73,87 ---- throw CDShowException("SetFiltergraph failed on capture graph builder",hr); } + + CString tmp; + tmp=m_file.substr((m_file.size()<4 ? 0 : m_file.size()-4)).c_str(); + if(stricmp(tmp.GetBuffer(0),".grf")!=0) + { + hr=m_pGraph->AddSourceFilter(A2W(filename.c_str()),NULL,&m_pFileSource); + if(FAILED(hr)) + { + throw CDShowException("Failed to add file",hr); + } + } } *************** *** 85,134 **** void CDShowFileSource::connect(CComPtr<IBaseFilter> filter) { HRESULT hr; ! //the simple case, RenderStream is able to properly connect the filters ! hr=m_pBuilder->RenderStream(NULL,NULL,m_pFileSource,NULL,filter); ! if(FAILED(hr)) { ! //that didnt work, try to manualy connect the pins on the source filter ! CDShowPinEnum outPins(m_pFileSource,PINDIR_OUTPUT); ! CComPtr<IPin> outPin; ! bool bSucceeded=false; ! while(outPin=outPins.next(),bSucceeded==false && outPin!=NULL) ! { ! CDShowPinEnum inPins(filter,PINDIR_INPUT); ! CComPtr<IPin> inPin; ! while(inPin=inPins.next(),inPin!=NULL) { ! hr=m_pGraph->Connect(outPin,inPin); ! if(SUCCEEDED(hr)) { ! //now the video is connected properly ! ! //render the other pins if any, it is not a big problem if it fails, ! //just continue with the stream we already got ! outPins.reset(); ! CComPtr<IPin> pin; ! while(pin=outPins.next(),pin!=NULL) { ! CComPtr<IPin> dest; ! hr=pin->ConnectedTo(&dest); ! if(FAILED(hr)) { ! m_pGraph->Render(pin); } } ! bSucceeded=true; ! break; } } } ! if(!bSucceeded) { ! throw CDShowException("Cant connect filesource to renderer",hr); } } - //try to render audio, if this fails then this file probably dont have any audio - hr=m_pBuilder->RenderStream(NULL,&MEDIATYPE_Audio,m_pFileSource,NULL,NULL); m_bIsConnected=true; --- 93,233 ---- void CDShowFileSource::connect(CComPtr<IBaseFilter> filter) { + USES_CONVERSION; HRESULT hr; ! ! //is this a grf file? grf files needs special handling ! CString tmp; ! tmp=m_file.substr((m_file.size()<4 ? 0 : m_file.size()-4)).c_str(); ! if(stricmp(tmp.GetBuffer(0),".grf")!=0) { ! //the simple case, RenderStream is able to properly connect the filters ! hr=m_pBuilder->RenderStream(NULL,NULL,m_pFileSource,NULL,filter); ! if(FAILED(hr)) ! { ! //that didnt work, try to manualy connect the pins on the source filter ! CDShowPinEnum outPins(m_pFileSource,PINDIR_OUTPUT); ! CComPtr<IPin> outPin; ! bool bSucceeded=false; ! while(outPin=outPins.next(),bSucceeded==false && outPin!=NULL) { ! CDShowPinEnum inPins(filter,PINDIR_INPUT); ! CComPtr<IPin> inPin; ! while(inPin=inPins.next(),inPin!=NULL) { ! hr=m_pGraph->Connect(outPin,inPin); ! if(SUCCEEDED(hr)) { ! //now the video is connected properly ! ! //render the other pins if any, it is not a big problem if it fails, ! //just continue with the stream we already got ! outPins.reset(); ! CComPtr<IPin> pin; ! while(pin=outPins.next(),pin!=NULL) { ! CComPtr<IPin> dest; ! hr=pin->ConnectedTo(&dest); ! if(FAILED(hr)) ! { ! m_pGraph->Render(pin); ! } } + + bSucceeded=true; + break; } + } + } + if(!bSucceeded) + { + throw CDShowException("Cant connect filesource to renderer",hr); + } + } + //try to render audio, if this fails then this file probably dont have any audio + hr=m_pBuilder->RenderStream(NULL,&MEDIATYPE_Audio,m_pFileSource,NULL,NULL); + } + else + { + hr=m_pGraph->RenderFile(A2W(m_file.c_str()),NULL); + if(FAILED(hr)) + { + throw CDShowException("Faild to render grapedit .grf file",hr); + } ! CDShowGenericEnum<IEnumFilters,IBaseFilter> filterEnum; ! HRESULT hr=m_pGraph->EnumFilters(&filterEnum.m_pEnum); ! if(FAILED(hr)) ! { ! throw CDShowException("Failed to get filter enumerator!!!",hr); ! } ! ! bool bFound=false; ! CComPtr<IDSRendFilter> pDSRend; ! CComPtr<IBaseFilter> pFilter; ! while(hr=filterEnum.next(&pFilter),hr==S_OK && pFilter!=NULL) ! { ! hr=pFilter.QueryInterface(&pDSRend); ! if(SUCCEEDED(hr)) ! { ! bFound=true; ! //replace the dsrend filter in the grf file with our renderer. ! //this might need to be changed to allow settings on the ! //dsrend filter from the grf file to be preserved ! //(not implemented yet on the filter) ! ! CDShowPinEnum InPins(pFilter,PINDIR_INPUT); ! CComPtr<IPin> pInPin=InPins.next(); ! if(pInPin==NULL) ! { ! throw CDShowException("DSRend filter do not have an input pin!!! (bug)"); ! } ! CComPtr<IPin> pOutPin; ! hr=pInPin->ConnectedTo(&pOutPin); ! if(FAILED(hr)) ! { ! if(hr==VFW_E_NOT_CONNECTED) ! { ! throw CDShowException("The dsrend filter is not connected in the grf file",hr); ! } ! else ! { ! throw CDShowException("Failed to find filter that is connected to dscaler renderer",hr); ! } ! } ! ! //preserve the mediatype on the connection ! AM_MEDIA_TYPE mt; ! memset(&mt,0,sizeof(AM_MEDIA_TYPE)); ! hr=pOutPin->ConnectionMediaType(&mt); ! ASSERT(SUCCEEDED(hr)); ! ! hr=m_pGraph->RemoveFilter(pFilter); ! ! CDShowPinEnum InPins2(filter,PINDIR_INPUT); ! CComPtr<IPin> pInPin2=InPins2.next(); ! hr=pOutPin->Connect(pInPin2,&mt); ! if(mt.cbFormat>0 && mt.pbFormat!=NULL) ! { ! CoTaskMemFree(mt.pbFormat); ! mt.cbFormat=0; ! mt.pbFormat=NULL; ! } ! if(mt.pUnk!=NULL) ! { ! mt.pUnk->Release(); ! mt.pUnk=NULL; ! } ! if(FAILED(hr)) ! { ! throw CDShowException("Failed to connect dsrend filter",hr); } + break; } } ! if(!bFound) { ! throw CDShowException("This filter graph file does not contain a dscaler renderer filter"); } } m_bIsConnected=true; |