コード例 #1
0
ファイル: audio decoder.cpp プロジェクト: hownam/fennec
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;
}
コード例 #2
0
ファイル: App.cpp プロジェクト: rkabir/Cinder
bool WMA::PostOpen()
{
    WaitForSingleObject( m_hRespondEvent, INFINITE );
    if( FAILED(m_hrCallbackResult) ) {
        return false;
    }

    uint32_t nOutputCount;
    HRESULT hr = m_pReader->GetOutputCount( &nOutputCount );

    if( FAILED(hr) ) {
        return false;
    }

    //ensure this is audio only
    if( nOutputCount != 1 ) {
        return false;
    }

    uint32_t nOutputFormatCount;
    hr = m_pReader->GetOutputFormatCount(0, &nOutputFormatCount);
    if(FAILED(hr)) {
        return FALSE;
    }

    uint32_t nFormatSize = 0;
    BYTE* pBuf = 0;
    IWMOutputMediaProps* pProps = 0;
    for( uint32_t j = 0; j < nOutputFormatCount; j++ ) {
        hr = m_pReader->GetOutputFormat( 0, j, &pProps  );
        if(FAILED(hr)) {
            continue;
        }

        //get required size of the media type structure
        uint32_t nNewSize = 0;
        hr = pProps->GetMediaType( NULL, & nNewSize );
        if( FAILED(hr) ) {
            continue;
        }

        if(nNewSize > nFormatSize)
        {
            if( pBuf ) {
                delete [] pBuf;
                pBuf = 0;
            }

            nFormatSize = nNewSize;
            pBuf = new BYTE[nFormatSize];
        }

        WM_MEDIA_TYPE* pType = (WM_MEDIA_TYPE*) pBuf;
        hr = pProps->GetMediaType(pType, & nFormatSize);
        if(FAILED(hr))
            continue;


        if(pType->formattype == WMFORMAT_WaveFormatEx)
        {
            memcpy( &m_WaveFormatEx, pType->pbFormat, pType->cbFormat );
            if((m_WaveFormatEx.nChannels == 2) && (m_WaveFormatEx.wBitsPerSample == 16) && (m_WaveFormatEx.nSamplesPerSec == 44100)) {
                break;
            }
        }
        if(pProps) {
            pProps->Release();
            pProps = 0;
        }


    }
    if(pBuf) {
        delete [] pBuf;
        pBuf = 0;
    }

    m_pReader->SetOutputProps( 0, pProps );
    if(FAILED(hr)) {
        return false;
    }

    if(pProps) {
        pProps->Release();
        pProps = 0;
    }


    //tells it to read as fast possible
    //hr = m_pReaderAdvanced->SetUserProvidedClock(true);

    if(FAILED(hr)) {
        return false;
    }

    WORD wStreamNum = 0;
    WMT_ATTR_DATATYPE Type;
    QWORD dwDuration = 0;
    WORD wLength = 8;
    hr = m_pHeaderInfo->GetAttributeByName(&wStreamNum, g_wszWMDuration, &Type, (BYTE*)&dwDuration, &wLength);
    if(FAILED(hr)) {
        return false;
    }

    //divide by 10 million to get seconds
    double fTime = double(dwDuration) / 10000000.0f;

    m_nStreamSize = fTime * m_WaveFormatEx.nAvgBytesPerSec * 1.5;

    //create a default 1.5 second scratch buffer for seconding streams
    m_pBuffer = new uint8_t[m_WaveFormatEx.nAvgBytesPerSec * 1.5];
    m_nBufferSize = m_WaveFormatEx.nAvgBytesPerSec * 1.5;

    m_nTargetPtr = 0;
    m_nWritePtr = 0;

    m_bOpen = true;

    return true;
}
コード例 #3
0
ファイル: Helper.cpp プロジェクト: RenniePet/explorerplusplus
HRESULT GetMediaMetadata(const TCHAR *szFileName,const TCHAR *szAttribute,BYTE **pszOutput)
{
    typedef HRESULT (WINAPI *WMCREATEEDITOR_PROC)(IWMMetadataEditor **);
    WMCREATEEDITOR_PROC pWMCreateEditor = NULL;
    HMODULE hWMVCore;
    IWMMetadataEditor *pEditor = NULL;
    IWMHeaderInfo *pWMHeaderInfo = NULL;
    HRESULT hr = E_FAIL;

    hWMVCore = LoadLibrary(_T("wmvcore.dll"));

    if(hWMVCore != NULL)
    {
        pWMCreateEditor = (WMCREATEEDITOR_PROC)GetProcAddress(hWMVCore,"WMCreateEditor");

        if(pWMCreateEditor != NULL)
        {
            hr = pWMCreateEditor(&pEditor);

            if(SUCCEEDED(hr))
            {
                hr = pEditor->Open(szFileName);

                if(SUCCEEDED(hr))
                {
                    hr = pEditor->QueryInterface(IID_PPV_ARGS(&pWMHeaderInfo));

                    if(SUCCEEDED(hr))
                    {
                        WORD wStreamNum;
                        WMT_ATTR_DATATYPE Type;
                        WORD cbLength;

                        /* Any stream. Should be zero for MP3 files. */
                        wStreamNum = 0;

                        hr = pWMHeaderInfo->GetAttributeByName(&wStreamNum,szAttribute,&Type,NULL,&cbLength);

                        if(SUCCEEDED(hr))
                        {
                            *pszOutput = (BYTE *)malloc(cbLength);

                            if(*pszOutput != NULL)
                            {
                                hr = pWMHeaderInfo->GetAttributeByName(&wStreamNum,szAttribute,&Type,
                                                                       *pszOutput,&cbLength);
                            }
                        }

                        pWMHeaderInfo->Release();
                    }
                }

                pEditor->Release();
            }
        }

        FreeLibrary(hWMVCore);
    }

    return hr;
}