void PrintAllFilters(IFilterGraph* filterGraph)
{
	IEnumFilters *enumFilters;
	HRESULT hr;

	hr = filterGraph->EnumFilters(&enumFilters);
	if(FAILED(hr))
	{
		ErrorPrint("Enum filters error", hr);
		return ;
	}
	ComReleaser enumFiltersReleaser(enumFilters);

	std::cout<<"Start print filter graphs:"<<endl;
	IBaseFilter* filter;
	while (S_OK == enumFilters->Next(1, &filter, NULL))
	{
		ComReleaser filterReleaser(filter);
		FILTER_INFO filterInfo;
		filter->QueryFilterInfo(&filterInfo);
		char* name = WideCharToChar(filterInfo.achName);
		std::cout<<name<<endl;
		delete[] name;
	}
	std::cout<<"Print end"<<endl;
}
//
// FindSubtitleFilter
//
// be careful with this method, can cause deadlock with CSync::Stop, so should only be called in Run()
HRESULT CTsReaderFilter::FindSubtitleFilter()
{
  if( m_pDVBSubtitle )
  {
    return S_OK;
  }
  //LogDebug( "FindSubtitleFilter - start");

  IEnumFilters * piEnumFilters = NULL;
  if (GetFilterGraph() && SUCCEEDED(GetFilterGraph()->EnumFilters(&piEnumFilters)))
  {
    IBaseFilter * pFilter;
    while (piEnumFilters->Next(1, &pFilter, 0) == NOERROR )
    {
      FILTER_INFO filterInfo;
      if (pFilter->QueryFilterInfo(&filterInfo) == S_OK)
      {
        if (!wcsicmp(L"MediaPortal DVBSub2", filterInfo.achName))
        {
          HRESULT fhr = pFilter->QueryInterface( IID_IDVBSubtitle2, ( void**)&m_pDVBSubtitle );
          assert( fhr == S_OK);
          //LogDebug("Testing that DVBSub2 works");
          m_pDVBSubtitle->Test(1);
        }
        filterInfo.pGraph->Release();
      }
      pFilter->Release();
      pFilter = NULL;
    }
    piEnumFilters->Release();
  }
  //LogDebug( "FindSubtitleFilter - End");
  return S_OK;
}
示例#3
0
HRESULT CBDReaderFilter::FindSubtitleFilter()
{
  if (m_pDVBSubtitle)
    return S_OK;

  HRESULT hr = S_FALSE;
  ULONG fetched = 0;

  IEnumFilters * piEnumFilters = NULL;
  if (GetFilterGraph() && SUCCEEDED(GetFilterGraph()->EnumFilters(&piEnumFilters)))
  {
    IBaseFilter * pFilter;
    while (piEnumFilters->Next(1, &pFilter, &fetched) == NOERROR)
    {
      FILTER_INFO filterInfo;
      if (pFilter->QueryFilterInfo(&filterInfo) == S_OK)
      {
        if (!wcsicmp(L"MediaPortal DVBSub3", filterInfo.achName))
          hr = pFilter->QueryInterface(IID_IDVBSubtitle3, (void**)&m_pDVBSubtitle);

        filterInfo.pGraph->Release();
      }
      pFilter->Release();
      pFilter = NULL;
    }
    piEnumFilters->Release();
  }

  return hr;
}
//Show Filter in FilterGpragh
int show_filters_in_filtergraph(IGraphBuilder *pGraph){
	printf("Filters in FilterGpragh=======\n");
	USES_CONVERSION;
	IEnumFilters *pFilterEnum=NULL;
	if(FAILED(pGraph->EnumFilters(&pFilterEnum))){
		pFilterEnum->Release();
		return -1;
	}
	pFilterEnum->Reset();
	IBaseFilter * filter = NULL;
	ULONG fetchCount = 0;
	//Pin Info
	while (SUCCEEDED(pFilterEnum->Next(1, &filter, &fetchCount)) && fetchCount){
		if (!filter){
			continue;
		}
		FILTER_INFO FilterInfo;
		if (FAILED(filter->QueryFilterInfo(&FilterInfo))){
			continue;
		}
		printf("[%s]\n",W2A(FilterInfo.achName));
		filter->Release();
	}
	pFilterEnum->Release();
	printf("==============================\n");
	return 0;
}
示例#5
0
文件: wxdebug.cpp 项目: DragonZX/fdm2
/*  Display filter or pin */
CDisp::CDisp(IUnknown *pUnk)
{
    IBaseFilter *pf;
    HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void **)&pf);
    if(SUCCEEDED(hr))
    {
        FILTER_INFO fi;
        hr = pf->QueryFilterInfo(&fi);
        if(SUCCEEDED(hr))
        {
            QueryFilterInfoReleaseGraph(fi);

            m_pString = new TCHAR[lstrlenW(fi.achName)  + 1];
            if(m_pString)
            {
                wsprintf(m_pString, TEXT("%ls"), fi.achName);
            }
        }

        pf->Release();

        return;
    }

    IPin *pp;
    hr = pUnk->QueryInterface(IID_IPin, (void **)&pp);
    if(SUCCEEDED(hr))
    {
        CDisp::CDisp(pp);
        pp->Release();
        return;
    }
}
示例#6
0
void CFilterProp::ShowProperties()
{
	if ( !pGB ) return;

    HRESULT hr;
    IBaseFilter *pFilter = NULL;
    TCHAR szNameToFind[128];
    ISpecifyPropertyPages *pSpecify;

    // Read the current filter name from the list box
    int nCurSel = m_ListFilters.GetCurSel();
    m_ListFilters.GetText(nCurSel, szNameToFind);

    // Read the current list box name and find it in the graph
    pFilter = FindFilterFromName(szNameToFind);
    if (!pFilter)
        return;

    // Discover if this filter contains a property page
    hr = pFilter->QueryInterface(IID_ISpecifyPropertyPages, (void **)&pSpecify);
    if (SUCCEEDED(hr)) 
    {
        do 
        {
            FILTER_INFO FilterInfo;
            hr = pFilter->QueryFilterInfo(&FilterInfo);
            if (FAILED(hr))
                break;

            CAUUID caGUID;
            hr = pSpecify->GetPages(&caGUID);
            if (FAILED(hr))
                break;

            pSpecify->Release();
        
            // Display the filter's property page
            OleCreatePropertyFrame(
                m_hWnd,                 // Parent window
                0,                      // x (Reserved)
                0,                      // y (Reserved)
                FilterInfo.achName,     // Caption for the dialog box
                1,                      // Number of filters
                (IUnknown **)&pFilter,  // Pointer to the filter 
                caGUID.cElems,          // Number of property pages
                caGUID.pElems,          // Pointer to property page CLSIDs
                0,                      // Locale identifier
                0,                      // Reserved
                NULL                    // Reserved
            );
            CoTaskMemFree(caGUID.pElems);
            FilterInfo.pGraph->Release(); 

        } while(0);
    }

    pFilter->Release();

}
示例#7
0
HRESULT CFilterProp::EnumFilters()
{
	if ( !pGB ) return E_FAIL;

    HRESULT hr;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pFilter = NULL;
    ULONG cFetched;

    // Clear filters list box
    m_ListFilters.ResetContent();
    
    // Get filter enumerator
    hr = pGB->EnumFilters(&pEnum);
    if (FAILED(hr))
    {
        m_ListFilters.AddString(TEXT("<ERROR>"));
        return hr;
    }

    // Enumerate all filters in the graph
    while(pEnum->Next(1, &pFilter, &cFetched) == S_OK)
    {
        FILTER_INFO FilterInfo;
        TCHAR szName[256];
        
        hr = pFilter->QueryFilterInfo(&FilterInfo);
        if (FAILED(hr))
        {
            m_ListFilters.AddString(TEXT("<ERROR>"));
        }
        else
        {
				ISpecifyPropertyPages *pSpecify;
				hr = pFilter->QueryInterface(IID_ISpecifyPropertyPages, (void **)&pSpecify);
				if (SUCCEEDED(hr)) 
				{
	            pSpecify->Release();

					// Add the filter name to the filters listbox
					USES_CONVERSION;

					lstrcpy(szName, W2T(FilterInfo.achName));
					m_ListFilters.AddString(szName);

				}
				FilterInfo.pGraph->Release();
        }       
        pFilter->Release();
    }
    pEnum->Release();

    return hr;
}
示例#8
0
//
// The GraphBuilder interface provides a FindFilterByName() method,
// which provides similar functionality to the method below.
// This local method is provided for educational purposes.
//
IBaseFilter *FindFilterFromName(IGraphBuilder *pGB, LPTSTR szNameToFind)
{
    USES_CONVERSION;

    HRESULT hr;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pFilter = NULL;
    ULONG cFetched;
    BOOL bFound = FALSE;

    // Verify graph builder interface
    if (!pGB)
        return NULL;

    // Get filter enumerator
    hr = pGB->EnumFilters(&pEnum);
    if (FAILED(hr))
        return NULL;

    // Enumerate all filters in the graph
    while((pEnum->Next(1, &pFilter, &cFetched) == S_OK) && (!bFound))
    {
        FILTER_INFO FilterInfo;
        TCHAR szName[256];
        
        hr = pFilter->QueryFilterInfo(&FilterInfo);
        if (FAILED(hr))
        {
            pFilter->Release();
            pEnum->Release();
            return NULL;
        }

        // Compare this filter's name with the one we want
        lstrcpy(szName, W2T(FilterInfo.achName));
        if (! lstrcmp(szName, szNameToFind))
        {
            bFound = TRUE;
        }

        FilterInfo.pGraph->Release();

        // If we found the right filter, don't release its interface.
        // The caller will use it and release it later.
        if (!bFound)
            pFilter->Release();
        else
            break;
    }
    pEnum->Release();

    return (bFound ? pFilter : NULL);
}
HRESULT CNetworkProvider::RegisterDeviceFilter(IUnknown* pUnkFilterControl,ULONG* ppvRegisitrationContext) {
	RegisterDevice* device;
	FILTER_INFO filterinfo;
	HRESULT hr;
	IBaseFilter* filter;
	LOG4CPLUS_INFO(logger,"RegisterDeviceFilter start");
	IMpeg2Demultiplexer* demux;
	if (m_pNetworkProviderPin->GetConnected() != NULL){
		hr = m_pNetworkProviderPin->CreateOutputPin(m_pNetworkProviderPin->GetConnected());
	}
	CAutoLock lock(&m_Lock);
	if (pUnkFilterControl == NULL){
		return E_POINTER;
	}
	if (&ppvRegisitrationContext == NULL ){
		return E_POINTER;
	}
	hr = pUnkFilterControl->QueryInterface(IID_IBaseFilter, (void**) &filter);
	if (hr != S_OK ){
		return S_FALSE;
	}
	hr = filter->QueryFilterInfo(&filterinfo);
	filterinfo.pGraph = NULL;
	if (hr != S_OK ){
		return S_FALSE;
	}
	LOG4CPLUS_DEBUG(logger,"RegisterDeviceFilter checks finished");
	m_fid = m_fid + 1;
	device = new RegisterDevice();
	device->id = m_fid;
	device->control = filter;
	wcstombs( device->name, filterinfo.achName, sizeof(device->name)); 
	ppvRegisitrationContext = &m_fid;
	hr = pUnkFilterControl->QueryInterface(IID_IMpeg2Demultiplexer, (void**) &demux);
	if (hr == S_OK ){
		LOG4CPLUS_DEBUG(logger,"RegisterDeviceFilter device prepared for registration - Name: "<<device->name<<" - "<<m_fid<<" - "<<&m_fid);
		device->control = NULL;
		delete device;
		LOG4CPLUS_INFO(logger,"RegisterDeviceFilter demux skipped");
		return S_FALSE;
	}else{
		LOG4CPLUS_INFO(logger,"RegisterDeviceFilter device prepared for registration - Name: "<<device->name<<" - "<<m_fid<<" - "<<&m_fid);
		IBDA_DeviceControl* ctrl;
		if( filter->QueryInterface(_uuidof(IBDA_DeviceControl), (void**) &ctrl)==S_OK){
			device->deviceControl=ctrl;
		}
		m_vecDevices.push_back(device);
		CheckCapabilities(filter);
	}
	LOG4CPLUS_DEBUG(logger,"RegisterDeviceFilter finished");
	return S_OK;
}
示例#10
0
HRESULT AddGraphFiltersToList (IGraphBuilder *pGB, CListBox& m_ListFilters) 
{
    HRESULT hr;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pFilter = NULL;
    ULONG cFetched;

    // Clear filters list box
    m_ListFilters.ResetContent();
    
    // Verify graph builder interface
    if (!pGB)
        return E_NOINTERFACE;

    // Get filter enumerator
    hr = pGB->EnumFilters(&pEnum);
    if (FAILED(hr))
    {
        m_ListFilters.AddString(TEXT("<ERROR>"));
        return hr;
    }

    // Enumerate all filters in the graph
    while(pEnum->Next(1, &pFilter, &cFetched) == S_OK)
    {
        FILTER_INFO FilterInfo;
        TCHAR szName[256];
        
        hr = pFilter->QueryFilterInfo(&FilterInfo);
        if (FAILED(hr))
        {
            m_ListFilters.AddString(TEXT("<ERROR>"));
        }
        else
        {
            USES_CONVERSION;

            // Add the filter name to the filters listbox
            lstrcpy(szName, W2T(FilterInfo.achName));
            m_ListFilters.AddString(szName);

            // Must release filter graph reference
            FilterInfo.pGraph->Release();
        }       
        pFilter->Release();
    }
    pEnum->Release();

    return hr;
}
示例#11
0
//
// OnConnect
//
// Called when the property page connects to a filter
//
HRESULT CProgramProperties::OnConnect(IUnknown *pUnknown)
{
    ASSERT(m_pProgram == NULL);
    CheckPointer(pUnknown,E_POINTER);

    HRESULT hr = pUnknown->QueryInterface(IID_IMpeg2PsiParser, (void **) &m_pProgram);
    if(FAILED(hr))
    {
        return E_NOINTERFACE;
    }
    ASSERT(m_pProgram);

    IBaseFilter * pParserFilter ;
    hr = m_pProgram->QueryInterface(IID_IBaseFilter, (void **) &pParserFilter);
    RETURN_FALSE_IF_FAILED(TEXT("CProgramProperties::OnUpdate() QueryInterface() failed."), hr);

    FILTER_INFO Info;
    IFilterGraph * pGraph;
    hr = pParserFilter->QueryFilterInfo(&Info);

    RETURN_FALSE_IF_FAILED(TEXT("CProgramProperties::OnUpdate() QueryFilterInfo() failed."), hr);
    pGraph = Info.pGraph;
    pParserFilter->Release();

    hr = pGraph->QueryInterface(IID_IGraphBuilder, (void **) & m_pGraphBuilder);
    RETURN_FALSE_IF_FAILED(TEXT("CProgramProperties::OnUpdate() QueryInterface() failed."), hr);

    // get demux filter
    hr = GetDemuxFilter(pGraph, &m_pDemux);
    RETURN_FALSE_IF_FAILED(TEXT("CProgramProperties::OnUpdate() GetDemuxFilter() failed."), hr);
    pGraph->Release();

    // if there is no streaming, the following variables will not be initialized.
    if(m_pDemux != NULL && m_pGraphBuilder != NULL){
        hr = m_pGraphBuilder->QueryInterface(IID_IMediaControl, (void **) & m_pMediaControl);
        RETURN_FALSE_IF_FAILED( TEXT(" CProgramProperties::OnUpdate():Failed to QI IMediaControl."), hr);

        // Get the initial Program value
        m_pProgram->GetTransportStreamId( &m_stream_id);
        m_pProgram->GetPatVersionNumber( &m_pat_version);
        m_pProgram->GetCountOfPrograms( &m_number_of_programs );

    }

    if(!OnUpdate())
        return FALSE;

    return NOERROR;
}
void videoInputCamera::destroyGraph(){
	HRESULT hr = NULL;
	int FuncRetval=0;
	int NumFilters=0;

	int i = 0;
	while (hr == NOERROR)
	{
		IEnumFilters * pEnum = 0;
		ULONG cFetched;

		// We must get the enumerator again every time because removing a filter from the graph
		// invalidates the enumerator. We always get only the first filter from each enumerator.
		hr = pGraphBuilder->EnumFilters(&pEnum);
		//if (FAILED(hr)) { printf("SETUP: pGraph->EnumFilters() failed. \n"); return; }

		IBaseFilter * pFilter = NULL;
		if (pEnum->Next(1, &pFilter, &cFetched) == S_OK)
		{
			FILTER_INFO FilterInfo={0};
			hr = pFilter->QueryFilterInfo(&FilterInfo);
			FilterInfo.pGraph->Release();

			int count = 0;
			char buffer[255];
			memset(buffer, 0, 255 * sizeof(char));

			while( FilterInfo.achName[count] != 0x00 )
			{
				buffer[count] = static_cast<char>(FilterInfo.achName[count]);
				count++;
			}

			//printf("SETUP: removing filter %s...\n", buffer);
			hr = pGraphBuilder->RemoveFilter(pFilter);
			//if (FAILED(hr)) { printf("SETUP: pGraph->RemoveFilter() failed. \n"); return; }
			//printf("SETUP: filter removed %s  \n",buffer);

			pFilter->Release();
			pFilter = NULL;
		}
		else hr = 1;
		pEnum->Release();
		pEnum = NULL;
		i++;
	}

	return;
}
示例#13
0
HRESULT CTMReceiverGraph::Destroy()
{
	HRESULT hr = S_OK;

	m_pMediaEvent = NULL;
	m_pMeidaSeeking = NULL;
	m_pRecordStream = NULL;
	m_pSetCallBack = NULL;
	m_pVideoWindow = NULL;
	m_pBasicVideo = NULL;

	if(m_pGraphBuilder && m_pMediaControl)
	{
		m_pMediaControl->Stop();

		CComPtr<IEnumFilters> pEnum = NULL;
		hr = m_pGraphBuilder->EnumFilters(&pEnum);
		if(SUCCEEDED(hr))
		{
			IBaseFilter *pFilter = NULL;
			while(S_OK == pEnum->Next(1, &pFilter, NULL))
			{
				FILTER_INFO filterInfo;
				if(SUCCEEDED(pFilter->QueryFilterInfo(&filterInfo)))
				{
					SAFE_RELEASE(filterInfo.pGraph);
					CComPtr<IEnumPins> pIEnumPins = NULL;
					hr = pFilter->EnumPins(&pIEnumPins);
					if(SUCCEEDED(hr))
					{
						IPin *pIPin = NULL;
						while(S_OK == pIEnumPins->Next(1, &pIPin, NULL))
						{
							m_pGraphBuilder->Disconnect(pIPin);
							SAFE_RELEASE(pIPin);
						}
					}
				}
				SAFE_RELEASE(pFilter);
			}
		}
	}
	else
	{
		hr = S_FALSE;
	}
	return hr;
}
示例#14
0
int TffDecoder::loadAVInameAndPreset(void)
{
 IEnumFilters *eff=NULL;
 int cnt=0;
 if (m_pGraph->EnumFilters(&eff)==S_OK)
  {
   eff->Reset();
   IBaseFilter *bff;
   while (eff->Next(1,&bff,NULL)==S_OK)
    {
     CLSID iffclsid;
     bff->GetClassID(&iffclsid);
     if (iffclsid==CLSID_FFDSHOW) cnt++;
     if (AVIname[0]=='\0')
      {
       FILTER_INFO iff;
       bff->QueryFilterInfo(&iff);
       IFileSourceFilter *ifsf=NULL;
       bff->QueryInterface(IID_IFileSourceFilter,(void**)&ifsf);
       if (ifsf)
        {
         LPOLESTR aviNameL;
         ifsf->GetCurFile(&aviNameL,NULL);
         ifsf->Release();
         WideCharToMultiByte(CP_ACP,0,aviNameL,-1,AVIname,511, NULL, NULL );
         if (globalSettings.autoPreset)
          {
           TpresetSettings *preset=presets.getAutoPreset(AVIname,globalSettings.autoPresetFileFirst);
           if (preset)
            setPresetPtr(preset);
          }
        }
       if (iff.pGraph) iff.pGraph->Release();
      }
     bff->Release();
    }
   eff->Release();
  }
 return cnt;
}
示例#15
0
/*  Display filter or pin */
CDisp::CDisp(IUnknown *pUnk)
{
    IBaseFilter *pf;
    HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void **)&pf);
    if(SUCCEEDED(hr))
    {
        FILTER_INFO fi;
        hr = pf->QueryFilterInfo(&fi);
        if(SUCCEEDED(hr))
        {
            QueryFilterInfoReleaseGraph(fi);

            size_t len = lstrlenW(fi.achName)  + 1;
            m_pString = new TCHAR[len];
            if(m_pString)
            {
                #ifdef UNICODE
                LPCTSTR FORMAT_STRING = TEXT("%s");
                #else
                LPCTSTR FORMAT_STRING = TEXT("%S");
                #endif 

                (void)StringCchPrintf(m_pString, len, FORMAT_STRING, fi.achName);
            }
        }

        pf->Release();

        return;
    }

    IPin *pp;
    hr = pUnk->QueryInterface(IID_IPin, (void **)&pp);
    if(SUCCEEDED(hr))
    {
        CDisp::CDisp(pp);
        pp->Release();
        return;
    }
}
示例#16
0
文件: wxdebug.cpp 项目: DragonZX/fdm2
void WINAPI DumpGraph(IFilterGraph *pGraph, DWORD dwLevel)
{
    if( !pGraph )
    {
        return;
    }

    IEnumFilters *pFilters;

    DbgLog((LOG_TRACE,dwLevel,TEXT("DumpGraph [%x]"), pGraph));

    if (FAILED(pGraph->EnumFilters(&pFilters))) {
	DbgLog((LOG_TRACE,dwLevel,TEXT("EnumFilters failed!")));
    }

    IBaseFilter *pFilter;
    ULONG	n;
    while (pFilters->Next(1, &pFilter, &n) == S_OK) {
	FILTER_INFO	info;

	if (FAILED(pFilter->QueryFilterInfo(&info))) {
	    DbgLog((LOG_TRACE,dwLevel,TEXT("    Filter [%x]  -- failed QueryFilterInfo"), pFilter));
	} else {
	    QueryFilterInfoReleaseGraph(info);

	    // !!! should QueryVendorInfo here!
	
	    DbgLog((LOG_TRACE,dwLevel,TEXT("    Filter [%x]  '%ls'"), pFilter, info.achName));

	    IEnumPins *pins;

	    if (FAILED(pFilter->EnumPins(&pins))) {
		DbgLog((LOG_TRACE,dwLevel,TEXT("EnumPins failed!")));
	    } else {

		IPin *pPin;
		while (pins->Next(1, &pPin, &n) == S_OK) {
		    PIN_INFO	info;

		    if (FAILED(pPin->QueryPinInfo(&info))) {
			DbgLog((LOG_TRACE,dwLevel,TEXT("          Pin [%x]  -- failed QueryPinInfo"), pPin));
		    } else {
			QueryPinInfoReleaseFilter(info);

			IPin *pPinConnected = NULL;

			HRESULT hr = pPin->ConnectedTo(&pPinConnected);

			if (pPinConnected) {
			    DbgLog((LOG_TRACE,dwLevel,TEXT("          Pin [%x]  '%ls' [%sput]")
							   TEXT("  Connected to pin [%x]"),
				    pPin, info.achName,
				    info.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out"),
				    pPinConnected));

			    pPinConnected->Release();

			    // perhaps we should really dump the type both ways as a sanity
			    // check?
			    if (info.dir == PINDIR_OUTPUT) {
				AM_MEDIA_TYPE mt;

				hr = pPin->ConnectionMediaType(&mt);

				if (SUCCEEDED(hr)) {
				    DisplayType(TEXT("Connection type"), &mt);

				    FreeMediaType(mt);
				}
			    }
			} else {
			    DbgLog((LOG_TRACE,dwLevel,
				    TEXT("          Pin [%x]  '%ls' [%sput]"),
				    pPin, info.achName,
				    info.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out")));

			}
		    }

		    pPin->Release();

		}

		pins->Release();
	    }

	}
	
	pFilter->Release();
    }

    pFilters->Release();

}
// Open multimedia stream.
BOOL CDShow::Open(ZString& pFileName, IDirectDraw7 *pDD)
{
	// Multimedia stream pointer
	IAMMultiMediaStream *pAMStream;
	IGraphBuilder *pGb; // 7/10 #110
	IEnumFilters *pEfs;
	IBasicAudio *pBa;

    
	//7/29/09 we can now do stuff while the video plays
	CoInitializeEx(NULL,COINIT_MULTITHREADED); 
	

    // Create Multimedia stream object
	if (FAILED(CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
				 IID_IAMMultiMediaStream, (void **)&pAMStream)))
	{		
		// Return FALSE to let caller know we failed.	
		return FALSE; 
	}
    
	// Initialize Multimedia stream object
	if (FAILED(pAMStream->Initialize(STREAMTYPE_READ, 0, NULL)))
	{	
		// There are alot of possiblities to fail.....		
		return FALSE; 
	}

    // Add primary video stream.
	if (FAILED((pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL))))
	{		
		return FALSE; 
	}

    // Add default sound render to primary video stream,
	// so sound will be played back automatically.
	if (FAILED(pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL)))
	{
		// Return FALSE to let caller know we failed.		
		return FALSE; 
	}

    // Convert filename to UNICODE.
	// Notice the safe way to get the actual size of a string.
	WCHAR wPath[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0, pFileName, -1, wPath, sizeof(wPath)/sizeof(wPath[0]));   
    
	// Build the filter graph for our multimedia stream.
	if (FAILED((pAMStream->OpenFile(wPath, 0))))
	{	
		// Return FALSE to let caller know we failed.		
		return FALSE; 
	}

	//7/10 #110
	FILTER_INFO FilterInfo;
	pAMStream->GetFilterGraph(&pGb);
	pGb->EnumFilters(&pEfs);

    IBaseFilter *pFilter;
	unsigned long cFetched;
    while(pEfs->Next(1, &pFilter, &cFetched) == S_OK) {
		FILTER_INFO FilterInfo;
		pFilter->QueryFilterInfo(&FilterInfo);
		char szName[MAX_FILTER_NAME];
		long cch = WideCharToMultiByte(CP_ACP,0,FilterInfo.achName,MAX_FILTER_NAME,szName,MAX_FILTER_NAME,0,0);
		if (cch > 0) {
			if (!strcmp("WMAudio Decoder DMO",szName)) {
				// set the volume to music level
				FilterInfo.pGraph->QueryInterface(IID_IBasicAudio,(void**)&pBa);
				HKEY hKey;
				DWORD dwResult = 0;
				if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,0, KEY_READ, &hKey)) {
					DWORD dwSize = sizeof(dwResult);
					DWORD dwType = REG_DWORD;
					::RegQueryValueEx(hKey, "MusicGain", NULL, &dwType, (BYTE*)&dwResult, &dwSize);
					::RegCloseKey(hKey);
					if (dwType != REG_DWORD)
						dwResult = 0;
				}
				long vol = (dwResult * -1) * 100;
				if (vol < -5000) {
					vol = -10000;
				}
				pBa->put_Volume(vol);
				pBa->Release();
			}
           if (FilterInfo.pGraph != NULL)
               FilterInfo.pGraph->Release();
           pFilter->Release();
		}
	}
	pEfs->Release();
	pGb->Release();

    // Assign member to temperary stream pointer.
	m_pMMStream = pAMStream;
	
	// Add a reference to the file
	pAMStream->AddRef();
    	
	// Get media stream interface
	if (FAILED(m_pMMStream->GetMediaStream(MSPID_PrimaryVideo, &m_pPrimaryVideoStream)))
	{	
		return FALSE;
	}
	
	// Get DirectDraw media stream interface
	if (FAILED(m_pPrimaryVideoStream->QueryInterface(IID_IDirectDrawMediaStream,(void **)&m_pDDStream)))
	{				
		return FALSE;
	}	
	
	// Create stream sample
	if (FAILED(m_pDDStream->CreateSample(NULL,NULL,0,&m_pSample)))
	{			
		return FALSE;
	}	
	
	// Get DirectDraw surface interface from Sample.
	if (FAILED(m_pSample->GetSurface(&m_pDDSurface,&m_rSrcRect)))
	{			

		return FALSE;
	}	
	
	// Get DirectDraw surface7 interface
	if (FAILED(m_pDDSurface->QueryInterface(IID_IDirectDrawSurface7,(void**)&m_pDDSurface7)))
	{		
		return FALSE;
	}	
	
	// Ok. Media is open now.
	m_bMediaOpen=TRUE;
	
	// If we are here, everything turned out ok. Return TRUE.
	return TRUE;
}
示例#18
0
HRESULT FindRenderer(IGraphBuilder *pGB, const GUID *mediatype, IBaseFilter **ppFilter)
{
    HRESULT hr;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pFilter = NULL;
    IPin *pPin;
    ULONG ulFetched, ulInPins, ulOutPins;
    BOOL bFound=FALSE;

    // Verify graph builder interface
    if (!pGB)
        return E_NOINTERFACE;

    // Verify that a media type was passed
    if (!mediatype)
        return E_POINTER;

    // Clear the filter pointer in case there is no match
    if (ppFilter)
        *ppFilter = NULL;

    // Get filter enumerator
    hr = pGB->EnumFilters(&pEnum);
    if (FAILED(hr))
        return hr;

    pEnum->Reset();

    // Enumerate all filters in the graph
    while(!bFound && (pEnum->Next(1, &pFilter, &ulFetched) == S_OK))
    {
#ifdef DEBUG
        // Read filter name for debugging purposes
        FILTER_INFO FilterInfo;
        TCHAR szName[256];

        hr = pFilter->QueryFilterInfo(&FilterInfo);
        if (SUCCEEDED(hr))
        {
            // Show filter name in debugger
#ifdef UNICODE
            lstrcpy(szName, FilterInfo.achName);
#else
            WideCharToMultiByte(CP_ACP, 0, FilterInfo.achName, -1, szName, 256, 0, 0);
#endif
            FilterInfo.pGraph->Release();
        }
#endif

        // Find a filter with one input and no output pins
        hr = CountFilterPins(pFilter, &ulInPins, &ulOutPins);
        if (FAILED(hr))
            break;

        if ((ulInPins == 1) && (ulOutPins == 0))
        {
            // Get the first pin on the filter
            pPin=0;
            pPin = GetInPin(pFilter, 0);

            // Read this pin's major media type
            AM_MEDIA_TYPE type= {0};
            hr = pPin->ConnectionMediaType(&type);
            if (FAILED(hr))
                break;

            // Is this pin's media type the requested type?
            // If so, then this is the renderer for which we are searching.
            // Copy the interface pointer and return.
            if (type.majortype == *mediatype)
            {
                // Found our filter
                *ppFilter = pFilter;
                bFound = TRUE;;
            }
            // This is not the renderer, so release the interface.
            else
                pFilter->Release();

            // Delete memory allocated by ConnectionMediaType()
            FreeMediaType(type);
        }
        else
        {
            // No match, so release the interface
            pFilter->Release();
        }
    }

    pEnum->Release();
    return hr;
}
示例#19
0
void gui::dx::audio_playerX::initialize_speedup_filter() {
	if (speedup_filter_available_valid && !speedup_filter_available) {
		// We don't seem to have the filter. Too bad.
		return;
	}
	// Either the filter exists or we haven't tried yet. Let's try to create
	// it and remember whether it worked.
	IBaseFilter *pNewFilter = NULL;

	HRESULT res;
	res = CoCreateInstance(CLSID_TPBVupp69, NULL, CLSCTX_INPROC_SERVER,
		IID_IBaseFilter, (void**)&pNewFilter);

	if (res != S_OK) {
		traceX("dx_audio_player: Speedup filter not available, error 0x%x", res);
		speedup_filter_available = false;
		speedup_filter_available_valid = true;
		return;
	}
	res = m_graph_builder->AddFilter(pNewFilter, NULL);
	if (res != S_OK) {
		traceX("dx_audio_player: AddFilter(Speedup filter): error 0x%x", res);
		pNewFilter->Release();
		return;
	}
	speedup_filter_available = true;
	speedup_filter_available_valid = true;
	//	AM_DBG lib::debugX("dx_audio_player: added speedup filter to graph");

	// Next step: find out where we want to add the filter to the graph.
	// We iterate over the filter graph, then for each item in the graph
	// we iterate over the connected output pins util we find one we like.
	IPin *pOutputPin = NULL;
	IPin *pInputPin = NULL;
	IEnumFilters *pEnumFilters = NULL;
	res = m_graph_builder->EnumFilters(&pEnumFilters);
	if (res != S_OK) {
		traceX("dx_audio_filter: EnumFilters: error 0x%x", res);
		return;
	}

	IBaseFilter *pCurFilter;
	while (pOutputPin == NULL && (res=pEnumFilters->Next(1, &pCurFilter, NULL)) == S_OK) {
		AM_DBG {
			FILTER_INFO info;
			LPWSTR vendorInfo;
			res = pCurFilter->QueryFilterInfo(&info);
			if (res != S_OK) info.achName[0] = 0;
			res = pCurFilter->QueryVendorInfo(&vendorInfo);
			if (res != S_OK) vendorInfo = L"";
			//ambulant::lib::textptr tInfo(info.achName);
			//ambulant::lib::textptr tVendorInfo(vendorInfo);
			//lib::debugX("dx_audio_filter: filter found: '%s' vendor '%s'", tInfo.c_str(), tVendorInfo.c_str());
		}
		IEnumPins *pEnumPins;
		res = pCurFilter->EnumPins(&pEnumPins);
		IPin *pCurPin;
		while (pOutputPin == NULL && (res=pEnumPins->Next(1, &pCurPin, NULL)) == S_OK) {
			AM_MEDIA_TYPE mediaType;
			PIN_DIRECTION curPinDir;
			res = pCurPin->QueryDirection(&curPinDir);
			HRESULT res2 = pCurPin->ConnectionMediaType(&mediaType);
			if (res == S_OK && 
				res2 == S_OK && 
				curPinDir == PINDIR_OUTPUT &&
				mediaType.majortype == MEDIATYPE_Audio&& 
				mediaType.subtype == MEDIASUBTYPE_PCM){
					pOutputPin = pCurPin;
					res = pOutputPin->ConnectedTo(&pInputPin);
					if (res != S_OK) {
						// This output pin was the correct type, but not connected.
						// So it cannot be the one we're looking for.
						pOutputPin = pInputPin = NULL;
					} else {
						// Found it!
						pOutputPin->AddRef();
						pInputPin->AddRef();
					}
				}
				if (res2 == S_OK) {
					if (mediaType.cbFormat != 0) {
						CoTaskMemFree((PVOID)mediaType.pbFormat);
					}
				}
				pCurPin->Release();
		}
		if (res != S_FALSE && res != S_OK) 
			traceX("dx_audio_filter: enumerating pins: error 0x%x", res);
		pEnumPins->Release();
		pCurFilter->Release();
	}
	if (res != S_FALSE && res != S_OK)
		traceX("dx_audio_filter: enumerating filters: error 0x%x", res);

	pEnumFilters->Release();
	// We have the correct pins now.
	if (pOutputPin) {
		traceX("dx_audio_filter: found the right pins!");
	} else {
		traceX("dx_audio_filter: could not find a good pin");
		pOutputPin->Release();
		pInputPin->Release();
		return;
	}
	// Now we need to find the pins on our speedup filter.
	IPin *pFilterInputPin = NULL;
	IPin *pFilterOutputPin = NULL;
	IEnumPins *pEnumPins;
	res = pNewFilter->EnumPins(&pEnumPins);
	IPin *pCurPin;
	while (res=pEnumPins->Next(1, &pCurPin, NULL) == S_OK) {
		PIN_DIRECTION pinDir;
		res = pCurPin->QueryDirection(&pinDir);
		//assert(res == S_OK);
		if (pinDir == PINDIR_INPUT) {
			if (pFilterInputPin) {
				traceX("dx_audio_filter: multiple input pins on filter");
				goto bad;
			}
			pFilterInputPin = pCurPin;
			pFilterInputPin->AddRef();
		} else {
			if (pFilterOutputPin) {
				traceX("dx_audio_filter: multiple output pins on filter");
				goto bad;
			}
			pFilterOutputPin = pCurPin;
			pFilterOutputPin->AddRef();
		}
	}
	if (!pFilterInputPin) {
		traceX("dx_audio_filter: no input pin on filter");
		goto bad;
	}
	if (!pFilterOutputPin) {
		traceX("dx_audio_filter: no output pin on filter");
		goto bad;
	}
	// We have everything. Sever the old connection and insert the filter.
	res = m_graph_builder->Disconnect(pOutputPin);
	if (res) {
		traceX("dx_audio_filter: Severing old connection: error 0x%x", res);
		goto bad;
	}
	res = m_graph_builder->Disconnect(pInputPin);
	if (res) {
		traceX("dx_audio_filter: Severing old connection: error 0x%x", res);
		goto bad;
	}
	res = m_graph_builder->Connect(pOutputPin, pFilterInputPin);
	if (res) {
		traceX("dx_audio_filter: Creating filter input connection: error 0x%x", res);
		goto bad;
	}
	res = m_graph_builder->Connect(pFilterOutputPin, pInputPin);
	if (res) {
		traceX("dx_audio_filter: Creating filter output connection: error 0x%x", res);
		goto bad;
	}
	// Finally remember the interface to set speedup/slowdown, and register ourselves
	// in the global pool (so Amis can change our speed).
	res = pNewFilter->QueryInterface(IID_IVuppInterface, (void**) &m_audio_speedup);
	if (res != S_OK) {
		traceX("dx_audio_filter: filter does not provide IVuppInterface");
		goto bad;
	}
	set_rate(s_current_playback_rate);

bad:
	if (pOutputPin) pOutputPin->Release();
	if (pInputPin) pInputPin->Release();
	if (pFilterOutputPin) pFilterOutputPin->Release();
	if (pFilterInputPin) pFilterInputPin->Release();
	return;

}
示例#20
0
void COggSplitter::ShowPopupMenu()
{
	int				groupID[16];
	HMENU			groupMenu[16];
	int				cGroups = 0;
	MENUITEMINFO	myItem;

	int				i = 0;

	AM_MEDIA_TYPE*	pmt;
	DWORD			dwGroup;
	DWORD			dwFlags;
	wchar_t*		pwzCaption;

	HMENU	hPopup = CreatePopupMenu();

	while (Info(i, &pmt, &dwFlags, NULL, &dwGroup, &pwzCaption, NULL, NULL) == NOERROR)
	{
		// Is there already a submenu for this group?
		int	j = 0;
		while ((j < cGroups) && (groupID[j] != dwGroup)) j++;

		if (j == cGroups)	// There is still no submenu ..
		{
            char*	pMenuType;

			if (!pmt)
				pMenuType = GetLocString(sidTypeOther);
			else if (pmt->majortype == MEDIATYPE_Audio)
				pMenuType = GetLocString(sidTypeAudio);
			else if (pmt->majortype == MEDIATYPE_Text)
				pMenuType = GetLocString(sidTypeSubtitle);
			else if (pmt->majortype == MEDIATYPE_Video)
			{			
				if (pmt->pbFormat)
					pMenuType = GetLocString(sidTypeVideo);
				else
					pMenuType = GetLocString(sidTypeChapter);
			}

			groupMenu[j] = CreatePopupMenu();
			groupID[j] = dwGroup;
			
			memset(&myItem, 0, sizeof(myItem));
			myItem.cbSize = sizeof(myItem);
			myItem.fMask = MIIM_TYPE | MIIM_SUBMENU;
			myItem.fType = MFT_STRING;
			myItem.hSubMenu = groupMenu[j];
			myItem.dwTypeData = pMenuType;
			myItem.cch = strlen(pMenuType);
			InsertMenuItem(hPopup, -1, TRUE, &myItem);
			cGroups++;
		}
		
		char		szItemText[128];
		wchar_t*	pwzItemText = pwzCaption;
		
		// Let´s skip the first word if not chapter
		if (pmt && ((pmt->majortype != MEDIATYPE_Video) || pmt->pbFormat))
		{
			pwzItemText = wcsstr(pwzItemText, L" ");
			pwzItemText++;
		}

		wsprintf(szItemText, "%S", pwzItemText);

		memset(&myItem, 0, sizeof(myItem));
		myItem.cbSize = sizeof(myItem);
		myItem.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
		myItem.fType = MFT_STRING | MFT_RADIOCHECK;
		myItem.fState = MFS_ENABLED;
		if (dwFlags == AMSTREAMSELECTINFO_ENABLED)
			myItem.fState |= MFS_CHECKED;
		myItem.wID = i;
		myItem.dwTypeData = szItemText;
		myItem.cch = strlen(myItem.dwTypeData);

		InsertMenuItem(groupMenu[j], -1, TRUE, &myItem);

		if (pmt)
			DeleteMediaType(pmt);
		CoTaskMemFree(pwzCaption);
		i++;
	}

	HMENU	hPropMenu = NULL;
	char	szName[MAX_FILTER_NAME];
	
	// If we are in the graph find all filters with property pages
	if (m_pGraph)
	{
		hPropMenu = CreatePopupMenu();

		// Insert the separator
		memset(&myItem, 0, sizeof(myItem));
		myItem.cbSize = sizeof(myItem);
		myItem.fMask = MIIM_TYPE;
		myItem.fType = MFT_SEPARATOR;
		InsertMenuItem(hPopup, -1, TRUE, &myItem);

		// Insert the properties item
		memset(&myItem, 0, sizeof(myItem));
		myItem.cbSize = sizeof(myItem);
		myItem.fMask = MIIM_TYPE | MIIM_SUBMENU;
		myItem.fType = MFT_STRING;
		myItem.hSubMenu = hPropMenu;
		myItem.dwTypeData = GetLocString(sidProperties);
		myItem.cch = strlen(myItem.dwTypeData);
		InsertMenuItem(hPopup, -1, TRUE, &myItem);

		IEnumFilters*			pEnum;
		IBaseFilter*			pFilter;
		ISpecifyPropertyPages*	pSPP;
		ULONG					cFetched;
		DWORD					dwID = ID_MENUITEM_PROPERTIES;

		m_pGraph->EnumFilters(&pEnum);

		do
		{
			if (FAILED(pEnum->Next(1, &pFilter, &cFetched)))
				cFetched = 0;

			if (cFetched)
			{
				if (SUCCEEDED(pFilter->QueryInterface(IID_ISpecifyPropertyPages,
														(void**)&pSPP)))
				{
					pSPP->Release();

					FILTER_INFO	Info;

					pFilter->QueryFilterInfo(&Info);
					wsprintf(szName, "%S", Info.achName);
					Info.pGraph->Release();

					memset(&myItem, 0, sizeof(myItem));
					myItem.cbSize = sizeof(myItem);
					myItem.fMask = MIIM_TYPE | MIIM_ID;
					myItem.fType = MFT_STRING;
					myItem.wID = dwID;
					myItem.dwTypeData = szName;
					myItem.cch = strlen(myItem.dwTypeData);
					InsertMenuItem(hPropMenu, -1, TRUE, &myItem);
					dwID++;
				}
				pFilter->Release();
			}
		} while (cFetched);
		pEnum->Release();
	}

	POINT	ptCursorPos;
	DWORD	dwSelection;

	GetCursorPos(&ptCursorPos);
	SetForegroundWindow(m_hTrayWnd);
	PostMessage(m_hTrayWnd, WM_NULL, 0, 0); 
	dwSelection = TrackPopupMenu(hPopup, TPM_NONOTIFY | TPM_RETURNCMD,
					ptCursorPos.x, ptCursorPos.y, 0, m_hTrayWnd, NULL);

	if (dwSelection <  ID_MENUITEM_PROPERTIES)
	{
		Enable(dwSelection, AMSTREAMSELECTENABLE_ENABLE);
		return;
	}

	GetMenuString(hPropMenu, dwSelection, szName, MAX_FILTER_NAME, MF_BYCOMMAND);
	if (m_pGraph)
	{
		wchar_t					wszName[MAX_FILTER_NAME];
		IBaseFilter*			pFilter;
		ISpecifyPropertyPages*	pSPP;
		
		wsprintfW(wszName, L"%s", szName);
		if (SUCCEEDED(m_pGraph->FindFilterByName(wszName, &pFilter)))
		{
			if (SUCCEEDED(pFilter->QueryInterface(IID_ISpecifyPropertyPages,
													(void**)&pSPP)))
			{
				IUnknown*	pFilterUnk;
				pFilter->QueryInterface(IID_IUnknown, (void **)&pFilterUnk);
				
				CAUUID caGUID;
				pSPP->GetPages(&caGUID);
				pSPP->Release();
			    OleCreatePropertyFrame(m_hTrayWnd, 0, 0, wszName, 1, &pFilterUnk,
										caGUID.cElems, caGUID.pElems, 0, 0, NULL);
				pFilterUnk->Release();
				CoTaskMemFree(caGUID.pElems);
			}
			pFilter->Release();
		}
	}

	DestroyMenu(hPopup);
}