Exemple #1
0
HRESULT CSVPWMVReader::Open( IAsyncReader* pAsyncReader )
{

    HRESULT hr = S_OK;


    if ( NULL == m_pReader )
    {
        hr = WMCreateSyncReader(  NULL, 0, &m_pReader );
    }

    if ( FAILED( hr ) )
    {
        _tprintf( _T( "Could not create reader (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    //
    // Open the requested file using IStream just to show how to use IStream with the synchronous reader 
    //
	m_pStream = new CROStream((CAsyncFileReader*)pAsyncReader);
	if( NULL == m_pStream )
	{
		hr = E_OUTOFMEMORY;
        _tprintf( _T( "Could not open file (hr=0x%08x).\n" ), hr );
		return( hr );
	}

    hr = m_pReader->OpenStream( m_pStream );
    if ( FAILED( hr ) )
    {
        _tprintf( _T( "Could not open file (hr=0x%08x).\n" ), hr );
        return( hr );
    }
    
    //
    // Get the profile interface
    //
    IWMProfile*    pProfile = NULL;

    hr = m_pReader->QueryInterface( IID_IWMProfile, ( VOID ** )&pProfile );
    if ( FAILED( hr ) ) 
    {
        _tprintf( _T(  "Could not QI for IWMProfile (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    //
    // Find out stream numbers for video and audio using the profile
    //
    hr = GetStreamNumbers( pProfile );
    SAFE_RELEASE( pProfile );
    if ( FAILED( hr ) ) 
    {
        _tprintf( _T(  "Could not stream numbers (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    return( hr );
}
HRESULT CReader::Open( const TCHAR *ptszFile )
{

    HRESULT hr = S_OK;


    if ( NULL == ptszFile || NULL == _tcslen(ptszFile))
    {
        return( E_INVALIDARG );
    }

    //
    //  Currently we can play only files. Streams are not supported.
    //
    if( 0 == _tcsnicmp( ptszFile, TEXT( "http" ), 4 ) )
    {
        _tprintf( _T( "Wrong input file - streams are not supported : (hr=0x%08x).\n" ) ,hr );
        return( E_INVALIDARG );
    }

    if ( NULL == m_pReader )
    {
        hr = WMCreateSyncReader(  NULL, 0, &m_pReader );
    }

    if ( FAILED( hr ) )
    {
        _tprintf( _T( "Could not create reader (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    //
    // Open the requested file using IStream just to show how to use IStream with the synchronous reader 
    //
	m_pStream = new CROStream;
	if( NULL == m_pStream )
	{
		hr = E_OUTOFMEMORY;
        _tprintf( _T( "Could not open file (hr=0x%08x).\n" ), hr );
		return( hr );
	}

    hr = m_pStream->Open( ptszFile );
    
    if( FAILED( hr ) )
    {
        _tprintf( _T( "Could not open file (hr=0x%08x).\n" ) ,hr );
        return( hr );
    }

    hr = m_pReader->OpenStream( m_pStream );
    if ( FAILED( hr ) )
    {
        _tprintf( _T( "Could not open file (hr=0x%08x).\n" ), hr );
        return( hr );
    }
    
    //
    // Get the profile interface
    //
    IWMProfile*    pProfile = NULL;

    hr = m_pReader->QueryInterface( IID_IWMProfile, ( VOID ** )&pProfile );
    if ( FAILED( hr ) ) 
    {
        _tprintf( _T(  "Could not QI for IWMProfile (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    //
    // Find out stream numbers for video and audio using the profile
    //
    hr = GetStreamNumbers( pProfile );
    SAFE_RELEASE( pProfile );
    if ( FAILED( hr ) ) 
    {
        _tprintf( _T(  "Could not stream numbers (hr=0x%08x).\n" ), hr );
        return( hr );
    }

    return( hr );
}
//------------------------------------------------------------------------------
// Name: IsFrameSeekable()
// Desc: Ascertains whether the file contains a stream that is seekable by frame.
//       If so, the method returns the stream number and the number of frames.
//
// wszFile:           Specifies the file name.
// ppSyncReader:      Receives a pointer to the synchronous reader's IWMSyncReader 
//                    interface.
// pwFrameSeekStream: Receives the stream number of the seekable stream.
// pqqTotalFrames:    Receives the number of frames in the stream.
//------------------------------------------------------------------------------
BOOL IsFrameSeekable( LPCWSTR wszFile, IWMSyncReader ** ppSyncReader, 
                      WORD *pwFrameSeekStream, QWORD *pqwTotalFrames )
{
    if( !ppSyncReader || !pwFrameSeekStream )
        return FALSE;

    HRESULT hr = E_FAIL;

    // Create a synchronous reader and load the specified file.
    hr = WMCreateSyncReader( 0, 0, ppSyncReader );
    if( FAILED( hr ) )
    {
        _tprintf(_T("Couldn't create the synchronous reader for ASF frame seeking! hr=0x%x\nPlayback aborted.\n\n"), hr);
    } 
    
    if( SUCCEEDED( hr ) )
    {
        // Open the source file.
        hr = (*ppSyncReader)->Open( wszFile );
        if( FAILED( hr ) )
        {
            _tprintf(_T("WMSDK Sync reader failed to open file! hr=0x%x\nPlayback aborted.\n\n"), hr);
        }
    }

    if( SUCCEEDED( hr ) )
    {
        CComPtr <IWMProfile> pProfile;

        hr = (*ppSyncReader)->QueryInterface( IID_IWMProfile, (void **) &pProfile );
        if( SUCCEEDED( hr ) ) 
        {

            // Loop through each stream and check the "NumberOfFrames" attribute in the 
            // ASF header for that stream number. This attribute is present if the stream
            // has been indexed by frame.

            DWORD cStreams;
            WORD wStreamNum;

            // Get the number of streams.
            hr = pProfile->GetStreamCount(&cStreams);
            if( SUCCEEDED( hr ) )
            {
                for( DWORD dw = 0; dw < cStreams; dw++ )
                {
                    CComPtr <IWMStreamConfig> pConfig;

                    hr = pProfile->GetStream( dw, &pConfig );
                    if( SUCCEEDED( hr ) )
                    {
                        // Get the stream number for this stream. 
                        hr = pConfig->GetStreamNumber( &wStreamNum );
                        if( SUCCEEDED( hr ) )
                        {
                            CComPtr <IWMHeaderInfo> pWMHI;

                            hr = (*ppSyncReader)->QueryInterface( IID_IWMHeaderInfo, (void **) &pWMHI );
                            if( SUCCEEDED( hr ) )
                            {
                                // Check whether the header contains a "NumberOfFrames" attribute 
                                // (g_wszWMNumberOfFrames) for this stream. If so, the value of the
                                // attribute is the number of frames in the stream.

                                WMT_ATTR_DATATYPE Type;
                                QWORD qwFrames;
                                WORD cbLength = sizeof(qwFrames);

                                hr = pWMHI->GetAttributeByName(&wStreamNum,
                                                               g_wszWMNumberOfFrames,
                                                               &Type,
                                                               (BYTE *) &qwFrames,
                                                               &cbLength);
                                if( SUCCEEDED( hr ) ) 
                                {
                                    // This stream is seekable by frame. Return the stream number
                                    // and the number of frames.
                                    *pwFrameSeekStream = wStreamNum;
                                    *pqwTotalFrames = qwFrames;
                                } 
                            }
                        }
                    }
                }
            }
        }
    }

    return ( S_OK == hr );
}
Exemple #4
0
int tagread(const string fname, struct fennec_audiotag *rtag)
{ 
	struct fennec_audiotag_item* ct;
	HRESULT               hres;
	IWMHeaderInfo*        wminfo;
	WORD                  wmistream = 0;
	IWMSyncReader*        wmreader;
	BOOL                  sdef = 1;

	if(!rtag)return 0;

	CoInitialize(0);

	if(!fname)
	{
		if(rtag->tag_title.tsize         ) { free(rtag->tag_title.tdata         ); rtag->tag_title.tsize         = 0; }
		if(rtag->tag_album.tsize         ) { free(rtag->tag_album.tdata         ); rtag->tag_album.tsize         = 0; }
		if(rtag->tag_artist.tsize        ) { free(rtag->tag_artist.tdata        ); rtag->tag_artist.tsize        = 0; }
		if(rtag->tag_origartist.tsize    ) { free(rtag->tag_origartist.tdata    ); rtag->tag_origartist.tsize    = 0; }
		if(rtag->tag_composer.tsize      ) { free(rtag->tag_composer.tdata      ); rtag->tag_composer.tsize      = 0; }
		if(rtag->tag_lyricist.tsize      ) { free(rtag->tag_lyricist.tdata      ); rtag->tag_lyricist.tsize      = 0; }
		if(rtag->tag_band.tsize          ) { free(rtag->tag_band.tdata          ); rtag->tag_band.tsize          = 0; }
		if(rtag->tag_copyright.tsize     ) { free(rtag->tag_copyright.tdata     ); rtag->tag_copyright.tsize     = 0; }
		if(rtag->tag_publish.tsize       ) { free(rtag->tag_publish.tdata       ); rtag->tag_publish.tsize       = 0; }
		if(rtag->tag_encodedby.tsize     ) { free(rtag->tag_encodedby.tdata     ); rtag->tag_encodedby.tsize     = 0; }
		if(rtag->tag_genre.tsize         ) { free(rtag->tag_genre.tdata         ); rtag->tag_genre.tsize         = 0; }
		if(rtag->tag_year.tsize          ) { free(rtag->tag_year.tdata          ); rtag->tag_year.tsize          = 0; }
		if(rtag->tag_url.tsize           ) { free(rtag->tag_url.tdata           ); rtag->tag_url.tsize           = 0; }
		if(rtag->tag_offiartisturl.tsize ) { free(rtag->tag_offiartisturl.tdata ); rtag->tag_offiartisturl.tsize = 0; }
      //if(rtag->tag_filepath.tsize      ) { free(rtag->tag_filepath.tdata      ); rtag->tag_filepath.tsize      = 0; }
      //if(rtag->tag_filename.tsize      ) { free(rtag->tag_filename.tdata      ); rtag->tag_filename.tsize      = 0; }
		if(rtag->tag_comments.tsize      ) { free(rtag->tag_comments.tdata      ); rtag->tag_comments.tsize      = 0; }
		if(rtag->tag_lyric.tsize         ) { free(rtag->tag_lyric.tdata         ); rtag->tag_lyric.tsize         = 0; }
		if(rtag->tag_bpm.tsize           ) { free(rtag->tag_bpm.tdata           ); rtag->tag_bpm.tsize           = 0; }
		if(rtag->tag_tracknum.tsize      ) { free(rtag->tag_tracknum.tdata      ); rtag->tag_tracknum.tsize      = 0; }

	}else{

		hres = WMCreateSyncReader(0, 0, &wmreader);
		if(FAILED(hres))return 0;

		hres = wmreader->Open(fname);

		/* get information */

		hres = wmreader->QueryInterface(IID_IWMHeaderInfo, (VOID **)&wminfo);
		if(FAILED(hres))return 0;

		wmistream = 0;


		ct = &rtag->tag_title;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMTitle);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;

		ct = &rtag->tag_album;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMAlbumTitle);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_artist;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMAuthor);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_origartist;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMOriginalArtist);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_composer;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMComposer);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_lyricist;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMWriter);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_band;
		ct->tdata  = 0;
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_copyright;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMCopyright);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_publish;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMPublisher);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_encodedby;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMEncodedBy);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_genre;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMGenre);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_year;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMYear);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_url;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMUserWebURL);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_offiartisturl;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMAuthorURL);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_comments;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMDescription);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_lyric;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMLyrics);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) + 2 : 0;
	
		ct = &rtag->tag_bpm;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMBeatsPerMinute);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;
	
		ct = &rtag->tag_tracknum;
		ct->tdata  = WM_GetTagString(wminfo, &wmistream, g_wszWMTrack);
		ct->tdatai = 0;
		ct->tmode  = ct->tdata ? tag_memmode_dynamic : tag_memmode_static;
		ct->tsize  = ct->tdata ? (unsigned int)str_size(ct->tdata) : 0;

		wminfo->Release();
		wmreader->Close();
		wmreader->Release();

	}
	return 1;
}
Exemple #5
0
int decoder_load(unsigned long id, const string sname)
{
	HRESULT               hres;
	IWMOutputMediaProps*  ppProps;
	WM_MEDIA_TYPE*        wmt = 0;
	DWORD                 wmpz = 0;
	WAVEFORMATEX          wfx;
	DWORD                 i, outcount = 0;
	IWMHeaderInfo*        wminfo;
	WORD                  wmistream = 0;
    WMT_ATTR_DATATYPE     Type;
	WORD                  wmilen;

	CoInitialize(0);

	hres = WMCreateSyncReader(0, 0, &pstreams[id].wmreader);
	if(FAILED(hres))return 0;

	hres = pstreams[id].wmreader->Open(sname);

	pstreams[id].wmreader->GetOutputCount(&outcount);

	for(i=0; i<outcount; i++)
	{
		
		hres = pstreams[id].wmreader->GetOutputProps(i, &ppProps);
		if(FAILED(hres))
		{
			ppProps->Release();
			continue;
		}

		hres = ppProps->GetMediaType(0, &wmpz);
		if(FAILED(hres))
		{
			ppProps->Release();
			continue;
		}

		wmt = (WM_MEDIA_TYPE*) malloc(wmpz);

		hres = ppProps->GetMediaType(wmt, &wmpz);

		if(WMMEDIATYPE_Audio != wmt->majortype)
		{
			ppProps->Release();
			free(wmt);
			continue;
		}

		memcpy(&wfx, wmt->pbFormat, wmt->cbFormat);

		pstreams[id].channels      = wfx.nChannels;
		pstreams[id].frequency     = wfx.nSamplesPerSec;
		pstreams[id].bitspersample = wfx.wBitsPerSample;

		pstreams[id].wmaudioout = i;

		free(wmt);

		ppProps->Release();
		break;
	}
	pstreams[id].buffer = 0;
	pstreams[id].buffersize = 0;

	/* get information */

	hres = pstreams[id].wmreader->QueryInterface(IID_IWMHeaderInfo, (VOID **)&wminfo);
	if(FAILED(hres))return 0;

	wmistream = 0;

	hres = wminfo->GetAttributeByName(&wmistream, g_wszWMDuration, &Type, 0, &wmilen);

	if(hres == S_OK)
	{
		QWORD dur;
		wminfo->GetAttributeByName(&wmistream, g_wszWMDuration, &Type, (BYTE*)&dur,&wmilen);
		pstreams[id].duration = (DWORD)(dur / 10000);
	}

	wminfo->Release();
	return 1;
}