HRESULT CSampleCGB::RenderToMPEG2Demux( IPin *pPin )
{
	if(!pPin)
	{
		return E_INVALIDARG;
	}

	REGPINMEDIUM pinMedium;//pin所支持的媒体类型如果媒体类型的CLSID为GUID_NULL或者KSMEDIUMSETID_Standard,那么pin就没法连接。
	HRESULT hr = GetMedium(pPin,pinMedium);
	if(FAILED(hr))return hr;

	SmartPtr<IEnumMoniker> pEncoders;
	if(::IsEqualGUID(pinMedium.clsMedium,GUID_NULL))
	{
		hr = GetEncodersByCategory(&pEncoders);
		if(FAILED(hr))return hr;

		hr = RenderToMPEG2Demux( pPin, pEncoders );
		if( SUCCEEDED( hr ) )
		{
			return S_OK;
		}
	}
	else
	{
		//
		//  search through encoders category; identify
		//  the encoder using the medium
		//
		hr = GetEncodersByCategory( &pEncoders );
		if( FAILED( hr ) )
		{
			return hr;
		}

		hr = RenderToMPEG2Demux( pPin, pinMedium, pEncoders  );
		if( SUCCEEDED( hr ) )
		{
			return S_OK;
		}

		pEncoders = NULL;
		hr = GetEncodersByEnumerating( pinMedium, &pEncoders );
		if( FAILED( hr ) )
		{
			return hr;
		}

		hr = RenderToMPEG2Demux( pPin, pinMedium, pEncoders );
		if( FAILED( hr ) )
		{
			return hr;
		}
	}
	return S_OK;
}
Exemple #2
0
HRESULT 
ISampleCaptureGraphBuilder::RenderToMPEG2Demux( IPin *pPin )
{
    if( !pPin )
    {
        return E_INVALIDARG;
    }

    REGPINMEDIUM pinMedium;
    HRESULT hr = GetMedium( pPin, pinMedium );
    if( FAILED( hr ) )
    {
        return hr;
    }


    SmartPtr< IEnumMoniker > pEncoders;
    if( ::IsEqualGUID( pinMedium.clsMedium, GUID_NULL ) )
    {
        //
        //  Search throgh the codec category 
        //  
        hr = GetEncodersByCategory( &pEncoders );
        if( FAILED( hr ) )
        {
                return hr;
        }

        hr = RenderToMPEG2Demux( pPin, pEncoders );
        if( SUCCEEDED( hr ) )
        {
            return S_OK;
        }
    }
    else
    {
        //
        //  search through encoders category; identify
        //  the encoder using the medium
        //
        hr = GetEncodersByCategory( &pEncoders );
        if( FAILED( hr ) )
        {
            return hr;
        }

        hr = RenderToMPEG2Demux( pPin, pinMedium, pEncoders  );
        if( SUCCEEDED( hr ) )
        {
            return S_OK;
        }
        
        pEncoders = NULL;
        hr = GetEncodersByEnumerating( pPin, pinMedium, &pEncoders );
        if( FAILED( hr ) )
        {
            return hr;
        }

        hr = RenderToMPEG2Demux( pPin, pinMedium, pEncoders );
        if( FAILED( hr ) )
        {
            return hr;
        }
    }
    return S_OK;
}
Exemple #3
0
HRESULT 
ISampleCaptureGraphBuilder::ConnectAudioPinToMultiplexer( 
                                            IPin *pPin, 
                                            IBaseFilter *pMultiplexer)
{
    if( !pPin || !pMultiplexer )
    {
        return E_INVALIDARG;
    }

    REGPINMEDIUM pinMedium;
    HRESULT hr = GetMedium( pPin, pinMedium );
    if( FAILED( hr ) )
    {
        return hr;
    }

    SmartPtr<IBaseFilter> pEncoder;
    SmartPtr<IEnumMoniker> pEncoders;

    if( FALSE == ::IsEqualGUID( pinMedium.clsMedium, GUID_NULL ) )
    {
        //
        //  search through encoders category; identify
        //  the encoder using the medium
        //
        hr = GetEncodersByCategory( &pEncoders );
        if( FAILED( hr ) )
        {
            return hr;
        }

        hr = FindEncoder( pEncoders, pinMedium, &pEncoder );
        if( SUCCEEDED( hr ) )
        {
            hr = graph_->AddFilter( pEncoder, L"Audio Encoder" );
            if( SUCCEEDED( hr ) &&
                SUCCEEDED( ConnectPin( pPin, pEncoder ) ) &&
                SUCCEEDED( ConnectFilters( pEncoder, pMultiplexer ) )
            )
            {
                return S_OK;
            }
        }
        
        
        pEncoders = NULL;
        hr = GetEncodersByEnumerating( pPin, pinMedium, &pEncoders );
        if( FAILED( hr ) )
        {
            return hr;
        }

        hr = FindEncoder( pEncoders, pinMedium, &pEncoder );
        if( SUCCEEDED( hr ) )
        {
            hr = graph_->AddFilter( pEncoder, L"Audio Encoder" );
            if( SUCCEEDED( hr ) &&
                SUCCEEDED( ConnectPin( pPin, pEncoder ) ) &&
                SUCCEEDED( ConnectFilters( pEncoder, pMultiplexer ) )
            )
            {
                return S_OK;
            }
        }
        return E_FAIL;
    }


    //
    //  Search throgh the codec category 
    //  
    hr = GetEncodersByCategory( &pEncoders );
    if( FAILED( hr ) )
    {
        return hr;
    }


    SmartPtr<IBaseFilter>    pFilter;
    SmartPtr<IMoniker>       pMoniker;
    ULONG                   fetched;
    while( pFilter.Release(), pMoniker.Release(), S_OK == pEncoders->Next( 1, &pMoniker, &fetched ) )
    {
        hr = pMoniker->BindToObject(
            0, 0, IID_IBaseFilter, reinterpret_cast<void **>( &pFilter ) );
        if( FAILED( hr ) )
        {
            continue;
        }

        hr = graph_->AddFilter( pFilter, L"Audio Encoder" );
        if( FAILED( hr ) )
        {
            continue;
        }

        hr = ConnectPin( pPin, pFilter );
        if( FAILED( hr ) )
        {
            graph_->RemoveFilter( pFilter );
            continue;
        }

        hr = ConnectFilters( pFilter, pMultiplexer );
        if( SUCCEEDED( hr ) )
        {
            return S_OK;
        }
        graph_->RemoveFilter( pFilter );
    }

    return E_FAIL;

}