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;
}
Beispiel #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;
}
Beispiel #3
0
HRESULT 
ISampleCaptureGraphBuilder::BuildMPEG2Segment(IBaseFilter *pFilter)
{

    if( ! pFilter )
    {
        return E_FAIL;
    }

    
    HRESULT hr = AddMPEG2Demux( );
    if( FAILED( hr ) )
    {
        return hr;
    }

    //
    //  Search a MPEG2 pin on the 
    //  filter
    //
    SmartPtr<IPin> pPin;
    hr = FindMPEG2Pin( pFilter, &pPin );
    if( SUCCEEDED( hr ) )
    {
        hr = ConnectPin( pPin, pMPEG2Demux_ );
        if( FAILED( hr ) )
        {
            graph_->RemoveFilter( pMPEG2Demux_ );
            return E_FAIL;
        }
        return S_OK;
    }

    //
    //  no pins that streams directly MPEG2 stream
    //
    hr = FindVideoPin( pFilter, &pPin );
    if( FAILED( hr ) )
    {
        graph_->RemoveFilter( pMPEG2Demux_ );
        return hr; // no video pin
    }

    hr = RenderToMPEG2Demux( pPin );
    if( FAILED( hr ) )
    {
        graph_->RemoveFilter( pMPEG2Demux_ );
        return hr;
    }

    SmartPtr<IPin> pAudioPin;
    hr = FindAudioPin( pFilter, &pAudioPin );
    if( FAILED( hr ) )
    {
        //
        //  don't bother with audio
        //
        return S_OK;
    }

    //
    //  try to connect the audio pin directly to encoder
    //  if this is not possible, then try to find an encoder
    //  and connect it to the multiplexer
    //
    ASSERT( pEncoder_ );
    hr = ConnectPin( pAudioPin, pEncoder_ );
    if( FAILED( hr ) )
    {
        hr = ConnectAudioPinToMultiplexer( pAudioPin, pMultiplexer_ );
    }

    return S_OK;
}