Exemple #1
0
bool WMWriter::setProfile(IWMProfile* wmProfile)
{
	HRESULT hr;

	INT i;
	hr = m_wmWriter->SetProfile( wmProfile );

	DWORD streamCount;
	wmProfile->GetStreamCount(&streamCount);
	for(i=0;i<(INT)streamCount;i++)
	{
		WORD streamNumber;
		IWMStreamConfig* streamConfig = NULL;
		hr = wmProfile->GetStream( i, &streamConfig );
		streamConfig->GetStreamNumber(&streamNumber);
	}
	return true;
}
Exemple #2
0
bool WMWriter::setSource(IWMReader* wmReader)
{
	INT i;
	if(!wmReader)
		return false;
	AutoCom<IWMHeaderInfo3> readerInfo;
	AutoCom<IWMProfile> readerProfile;
	AutoCom<IWMHeaderInfo3> writeInfo;
	AutoCom<IWMReaderAdvanced2> wmRaderAdvanced;


	HRESULT hr;
	hr = wmReader->QueryInterface( IID_IWMHeaderInfo3, (void **)readerInfo);
	hr = wmReader->QueryInterface( IID_IWMProfile, (void **)readerProfile );
	hr = wmReader->QueryInterface( IID_IWMReaderAdvanced2, (void **)wmRaderAdvanced );
	hr = m_wmWriter->QueryInterface( IID_IWMHeaderInfo3, (void **)writeInfo);
	hr = m_wmWriter->SetProfile( readerProfile );

	if(FAILED(hr))
		return false;
	WCHAR name[1024];
	DWORD s = 1024;
	readerProfile->GetName(name,&s);


	DWORD streamCount;
	readerProfile->GetStreamCount(&streamCount);
	for(i=0;i<(INT)streamCount;i++)
	{
		WORD streamNumber;
		IWMStreamConfig* streamConfig = NULL;
		readerProfile->GetStream( i, &streamConfig );
		streamConfig->GetStreamNumber(&streamNumber);
		wmRaderAdvanced->SetReceiveStreamSamples(streamNumber, true );
		streamConfig->Release();
	}

	start();
	return true;
}
///////////////////////////////////////////////////////////////
//// Retrieve video and audio stream numbers from profile
////
HRESULT CReader::GetStreamNumbers(IWMProfile* pProfile)
{
    HRESULT             hr = S_OK;
    IWMStreamConfig*    pStream = NULL;
    DWORD               dwStreams = 0;
    GUID                pguidStreamType;

    if ( NULL == pProfile )
    {
        return( E_INVALIDARG );
    }

    hr = pProfile->GetStreamCount( &dwStreams );
    if ( FAILED( hr ) )
    {
        _tprintf( _T(  "GetStreamCount on IWMProfile failed (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    m_wAudioStreamNum = 0;
    m_wVideoStreamNum = 0;

    for ( DWORD i = 0; i < dwStreams; i++ )
    {
        hr = pProfile->GetStream( i, &pStream );
        if ( FAILED( hr ) )
        {
            _tprintf( _T(  "Could not get Stream %d of %d from IWMProfile (hr=0x%08x).\n" ),
                    i, dwStreams, hr );
            break;
        }

        WORD wStreamNumber = 0 ;

        //
        //  Get the stream number of the current stream
        //

        hr = pStream->GetStreamNumber( &wStreamNumber );
        if ( FAILED( hr ) )
        {
            _tprintf( _T(  "Could not get stream number from IWMStreamConfig %d of %d (hr=0x%08x).\n" ),
                    i, dwStreams, hr );
            break;
        }

        hr = pStream->GetStreamType( &pguidStreamType );
        if ( FAILED( hr ) )
        {
            _tprintf( _T("Could not get stream type of stream %d of %d from IWMStreamConfig (hr=0x%08x).\n" ),
                i, dwStreams, hr ) ;
            break ;
        }
        
        if( WMMEDIATYPE_Audio == pguidStreamType )
        {
            m_wAudioStreamNum = wStreamNumber;
        }
        else if( WMMEDIATYPE_Video == pguidStreamType )
        {
            m_wVideoStreamNum = wStreamNumber;
        }

        SAFE_RELEASE( pStream );
    }

    return( hr );
}
//------------------------------------------------------------------------------
// Name: CStreamData::SetAllStreamData()
// Desc: Sets the stream numbers and media types in the member variables 
//       for the specified profile.
//------------------------------------------------------------------------------
HRESULT CStreamData::SetAllStreamData( IWMProfile * pProfile )
{
    if( NULL == pProfile )
    {
        return( E_INVALIDARG );
    }
    //
    // Make an array of pointers to WM_MEDIA_TYPE
    //
    m_ptrMediaArray = new WM_MEDIA_TYPE* [m_dwStreamCount];

    m_ptrStreamNumArray = new WORD [m_dwStreamCount];

    m_ptrStreamBufferWindow = new DWORD [m_dwStreamCount];

    m_pfVBRStream = new BOOL[m_dwStreamCount];
    
	if( NULL == m_ptrMediaArray || NULL == m_ptrStreamNumArray || NULL == m_ptrStreamBufferWindow )
    {
        _tprintf( _T( "Internal Error: Out of memory\n" ) );
        return(  E_OUTOFMEMORY );
    }
    
    ZeroMemory( m_ptrMediaArray, m_dwStreamCount * sizeof( WM_MEDIA_TYPE * ) );

    ZeroMemory( m_ptrStreamNumArray, m_dwStreamCount * sizeof( WORD ) );

    ZeroMemory( m_ptrStreamBufferWindow, m_dwStreamCount * sizeof( DWORD ) );

    HRESULT hr = S_OK;
    DWORD   cbType = 0;

    IWMMediaProps *     pProps  = NULL;
    IWMStreamConfig *   pStream = NULL;
    IWMPropertyVault *  pPropertyVault = NULL;
    WMT_ATTR_DATATYPE   enumAttrType;
    DWORD               dwAttrSize;

    //
    // Get all the stream numbers and the WM_MEDIA_TYPEs in the arrays
    //
    for( DWORD i = 0; i < m_dwStreamCount; i++ )
    {
        
	    hr = pProfile->GetStream( i, &pStream );
        if( FAILED( hr ) )
        {
		    _tprintf( _T( "Could not get Stream %d from IWMProfile (hr=0x%08x).\n" ), i, hr );
            break;
        }
        
        pStream->GetStreamNumber( &m_ptrStreamNumArray[i] );
        if ( FAILED( hr ) )
        {
            _tprintf( _T( "Could not GetStreamNumber from IWMStreamConfig %d (hr=0x%08x).\n" ), i, hr );
            break;
        }
        
        hr = pStream->QueryInterface( IID_IWMMediaProps, ( VOID ** )&pProps );
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not QI for IWMMediaProps (hr=0x%08x).\n" ), hr );
            break;
        }
        
        hr = pStream->GetBufferWindow( &m_ptrStreamBufferWindow[ i ] );
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not get Buffer Window from IWMStreamConfig (hr=0x%08x).\n" ), hr );
            break;
        }

        hr = pStream->QueryInterface( IID_IWMPropertyVault, ( VOID ** )&pPropertyVault );
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not QI for IWMMediaProps (hr=0x%08x).\n" ), hr );
            break;
        }

        //
        // Check to see if this stream is a VBR stream
        //
        dwAttrSize = sizeof( m_pfVBRStream[i] );
        hr = pPropertyVault->GetPropertyByName( g_wszVBREnabled, &enumAttrType, (BYTE *)&m_pfVBRStream[ i ], &dwAttrSize );
        if( FAILED( hr ) )
        {
            m_pfVBRStream[ i ] = FALSE;
            hr = S_OK;
        }
        
        //
        // Get the memory required for WM_MEDIA_TYPE of this stream
        //
        hr = pProps->GetMediaType( NULL, &cbType );
		if ( FAILED( hr ) )
		{
            _tprintf( _T( "Could not Get Media Type (hr=0x%08x).\n" ), hr );
			break;
		}

		m_ptrMediaArray[i] = (WM_MEDIA_TYPE*) new BYTE[ cbType ];
		
		if( m_ptrMediaArray[i] == NULL )
		{
			hr = E_OUTOFMEMORY;			
            _tprintf( _T( "Internal Error: Out of memory\n" ) );
			break;
		}

        hr = pProps->GetMediaType( m_ptrMediaArray[i], &cbType );
		if ( FAILED( hr ) )
		{
			_tprintf( _T( "Could not Get Media Type (hr=0x%08x).\n" ), hr );
			break;
		}

        SAFE_RELEASE( pStream );
        SAFE_RELEASE( pPropertyVault );
		SAFE_RELEASE( pProps );
        cbType = 0;
    }

    SAFE_RELEASE( pProps );
    SAFE_RELEASE( pStream );
    SAFE_RELEASE( pPropertyVault );
    
    return(  hr );
}