Esempio n. 1
0
bool UBWindowsMediaFile::close()
{
    bool result = true;

    if (mWMWriter)
    {
        if (FAILED(mWMWriter->EndWriting()))
        {
            result = false;
        }
    }

    if (mPushSink)
    {
        mPushSink->Disconnect();
        mPushSink->EndSession();
        mPushSink->Release();
    }

    if(mChapters.length() > 0)
    {
        IWMMetadataEditor *editor = 0;
        IWMHeaderInfo     *headerInfo = 0;

        WMCreateEditor(&editor);
        editor->Open((LPCTSTR) mVideoFileName.utf16());
        editor->QueryInterface(IID_IWMHeaderInfo, (void**)&headerInfo);

        foreach(MarkerInfo mi, mChapters)
        {
            headerInfo->AddMarker((LPWSTR)mi.label.utf16(),  msToSampleTime(mi.timestamp));
        }
Esempio n. 2
0
//------------------------------------------------------------------------------
// Name: DeleteAttrib()
// Desc: Delete the specified attribute.
//------------------------------------------------------------------------------
HRESULT DeleteAttrib( __in LPWSTR pwszInFile, 
                      WORD wStreamNum, 
                      WORD wAttribIndex )
{
    HRESULT hr = S_OK;
        
    IWMMetadataEditor   * pEditor       = NULL;
    IWMHeaderInfo3      * pHeaderInfo3  = NULL;

    do
    {
        hr = EditorOpenFile( pwszInFile, &pEditor, NULL, &pHeaderInfo3 );
        if(FAILED( hr ) )
        {
            break;
        }

        hr = pHeaderInfo3->DeleteAttribute( wStreamNum, wAttribIndex );
        if( FAILED( hr ) )
        {
            _tprintf( _T( "DeleteAttribute failed for stream = %d and index = %d ( hr=0x%08x ).\n" ), 
                wStreamNum, wAttribIndex, hr );
            break;
        }

        hr = pEditor->Flush();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not flush the file %ws ( hr=0x%08x ).\n" ), 
                pwszInFile, hr );
            break;
        }

        hr = pEditor->Close();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not close the file %ws ( hr=0x%08x ).\n" ), 
                pwszInFile, hr );
            break;
        }
    }
    while( FALSE );
    
    SAFE_RELEASE( pHeaderInfo3 );
    SAFE_RELEASE( pEditor );

    return( hr );
}
void CVideoInstance::StartCruncher(CVideoInstance* aInstance)
{
    aInstance->myThreadIsDone = false;
    ::CoInitialize(nullptr);
    HRESULT hr;
    hr = WMCreateSyncReader(NULL, 0, &aInstance->mySyncReader);
    if (hr != S_OK)
    {
        INFO_PRINT("%s", "Error: Could not create WMCreateSyncReader, video can not be played!");
        return;
    }
    //Step 2: Open the file
    //note: When the synchronous reader opens the file, it assigns an output number to each stream

    hr = aInstance->mySyncReader->Open(aInstance->myFileName);
    if (hr != S_OK)
    {
        INFO_PRINT("%s%ls", "Error: Could not open file, video can not be played! ", aInstance->myFileName);
        return;
    }


    aInstance->mySyncReader->GetOutputCount(&aInstance->mytheOutputsCount);

    int videoIndex = 0;
    DWORD theSize;
    IWMOutputMediaProps* videoOutputProps = nullptr;
    for (unsigned int i = 0; i<aInstance->mytheOutputsCount; i++)
    {
        SAFE_ARRAYDELETE(aInstance->mytheMediaType);
        aInstance->mySyncReader->GetOutputProps(i, &videoOutputProps);
        hr = videoOutputProps->GetMediaType(NULL, &theSize);
        aInstance->mytheMediaType = (WM_MEDIA_TYPE*) new BYTE[theSize];
        hr = videoOutputProps->GetMediaType(aInstance->mytheMediaType, &theSize);

        if (FAILED(hr))
        {
            INFO_PRINT("%s%s", "Error: Could not query for the space needed for media type, video can not be played!", aInstance->myFileName);
            return;
            //_tcscpy( tszErrMsg, _T( "Could not query for the space needed for media type" ) );
            //break;
        }

        if (WMMEDIATYPE_Video == aInstance->mytheMediaType->majortype)//pMediaType->majortype )
        {
            videoIndex = i;
            aInstance->mySyncReader->GetStreamNumberForOutput(videoIndex, (WORD*)&aInstance->myVideoStreamNumber);

            if (aInstance->mytheMediaType->formattype == WMFORMAT_VideoInfo)
            {
                //setting the bitmapInfoHeader by reading the WmvInfoHeader
                memcpy(&aInstance->myTheVideoInfoHeader, aInstance->mytheMediaType->pbFormat, sizeof(WMVIDEOINFOHEADER));
                aInstance->myBitmapInfoHdr = aInstance->myTheVideoInfoHeader.bmiHeader;

                aInstance->myWidth = aInstance->myBitmapInfoHdr.biWidth;
                aInstance->myHeight = aInstance->myBitmapInfoHdr.biHeight;

                WORD bitCount = aInstance->myBitmapInfoHdr.biBitCount;
                aInstance->myBytes_per_pixel = bitCount / 8;


                unsigned int rowSize = (bitCount * aInstance->myBitmapInfoHdr.biWidth + 7) / 8; // +7 to round up
                if (rowSize % 4)
                    rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary

                aInstance->myRow_increment = rowSize;// theInfoHeader.biWidth * bytes_per_pixel_;

            }


        }
        if (WMMEDIATYPE_Audio == aInstance->mytheMediaType->majortype)
        {
            aInstance->myAudioOutputNumber = i;
            aInstance->mySyncReader->GetStreamNumberForOutput(aInstance->myAudioOutputNumber, (WORD*)&aInstance->m_iAudioStreamNumber);
        }

    }
    //relesae the memory
    SAFE_RELEASE(videoOutputProps);
    videoOutputProps = nullptr;
    SAFE_ARRAYDELETE(aInstance->mytheMediaType);

    BYTE* pValue = new BYTE[5];
    strcpy((char*)pValue, "TRUE");
    hr = aInstance->mySyncReader->SetOutputSetting(videoIndex, g_wszVideoSampleDurations, WMT_TYPE_BOOL, pValue, sizeof(pValue));
    delete[]pValue;
    if (FAILED(hr))
    {
        INFO_PRINT("%s%s", "Error: Could not set Video Ouptut Sample durations, video can not be played!", aInstance->myFileName);
        return;
        //AfxMessageBox("could not set Video Ouptut Sample durations");
    }


    hr = aInstance->mySyncReader->SetReadStreamSamples(aInstance->myVideoStreamNumber, FALSE);
    if (FAILED(hr))
    {
        INFO_PRINT("%s%s", "Error: Could not set Video Stream to give Uncompressed Samples, video can not be played!", aInstance->myFileName);
        return;
        //AfxMessageBox("could not set Video Stream to give Uncompressed Samples");
    }

    IWMMetadataEditor *pEditor;

    hr = WMCreateEditor(&pEditor);
    if (hr == S_OK)
    {
        pEditor->Open(aInstance->myFileName);
        IWMHeaderInfo3* pHdrInfo;
        pHdrInfo = NULL;
        hr = pEditor->QueryInterface(IID_IWMHeaderInfo3, (void**)&pHdrInfo);
        WORD wStream = 0;
        WMT_ATTR_DATATYPE dType;
        QWORD dwDuration;
        WORD wSize = 0;
        hr = pHdrInfo->GetAttributeByName(&wStream, L"Duration", &dType, (BYTE*)NULL, &wSize);

        BYTE* pValue = nullptr;
        if (wSize > 0)
        {
            pValue = new BYTE[wSize];
            hr = pHdrInfo->GetAttributeByName(&wStream, L"Duration", &dType, pValue, &wSize);
            dwDuration = *((QWORD*)pValue);
            aInstance->m_qwTotalTimeInSeconds = (dwDuration * 100) / 1000000000;
            SAFE_ARRAYDELETE(pValue);
            SAFE_RELEASE(pHdrInfo);
            SAFE_RELEASE(pEditor);
        }

    }
    aInstance->myOpenSuccesfully = true;
    StartUpdateLoop(aInstance);
}
Esempio n. 4
0
//------------------------------------------------------------------------------
// Name: ShowAttributes()
// Desc: Display all attributes for the specified stream,
//       using IWMHeaderInfo.
//------------------------------------------------------------------------------
HRESULT ShowAttributes( __in LPWSTR pwszInFile, WORD wStreamNum )
{
    HRESULT             hr                  = S_OK;

    IWMMetadataEditor   * pEditor           = NULL;
    IWMHeaderInfo*      pHeaderInfo         = NULL;

    WCHAR               * pwszAttribName    = NULL;
    WORD                wAttribNameLen      = 0;
    WMT_ATTR_DATATYPE   wAttribType;
    BYTE                * pbAttribValue     = NULL;
    WORD                wAttribValueLen     = 0;

    do
    {
        hr = EditorOpenFile( pwszInFile, &pEditor, &pHeaderInfo, NULL );
        if(FAILED( hr ) )
        {
            break;
        }

        WORD wAttributeCount = 0;

        hr = pHeaderInfo->GetAttributeCount( wStreamNum, &wAttributeCount );
        if(FAILED( hr ) )
        {
            _tprintf( _T( "GetAttributeCount failed for stream = %d ( hr=0x%08x ).\n" ), 
                wStreamNum, hr );
            break;
        }

        PrintListHeader();

        for( WORD wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++ )
        {
            SAFE_ARRAYDELETE( pwszAttribName );
            SAFE_ARRAYDELETE( pbAttribValue );

            hr = pHeaderInfo->GetAttributeByIndex( wAttribIndex,
                                                   &wStreamNum,
                                                   pwszAttribName,
                                                   &wAttribNameLen,
                                                   &wAttribType,
                                                   pbAttribValue,
                                                   &wAttribValueLen );
            if( FAILED( hr ) )
            {
                _tprintf( _T( "GetAttributeByIndex failed for index = %d ( hr=0x%08x ).\n" ), 
                    wAttribIndex, hr );
                break;
            }

            pwszAttribName = new WCHAR[ wAttribNameLen ];
            if( NULL == pwszAttribName )
            {
                hr = E_OUTOFMEMORY;
                break;
            }

            pbAttribValue = new BYTE[ wAttribValueLen ];
            if( NULL == pbAttribValue )
            {
                hr = E_OUTOFMEMORY;
                break;
            }

            hr = pHeaderInfo->GetAttributeByIndex( wAttribIndex,
                                                   &wStreamNum,
                                                   pwszAttribName,
                                                   &wAttribNameLen,
                                                   &wAttribType,
                                                   pbAttribValue,
                                                   &wAttribValueLen );
            if( FAILED( hr ) )
            {
                _tprintf( _T( "GetAttributeByIndex failed for index = %d ( hr=0x%08x ).\n" ), 
                    wAttribIndex, hr );
                break;
            }

            hr = PrintAttribute( wAttribIndex, 
                                 wStreamNum, 
                                 pwszAttribName, 
                                 wAttribType, 
                                 0, 
                                 pbAttribValue, 
                                 wAttribValueLen );
            if( FAILED( hr ) )
            {
                break;
            }
        }
        
        hr = pEditor->Close();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not close the file %ws ( hr=0x%08x ).\n" ), pwszInFile, hr );
            break;
        }
    }
    while( FALSE );
    
    SAFE_RELEASE( pHeaderInfo );
    SAFE_RELEASE( pEditor );

    SAFE_ARRAYDELETE( pwszAttribName );
    SAFE_ARRAYDELETE( pbAttribValue );

    return( hr );
}
Esempio n. 5
0
//------------------------------------------------------------------------------
// Name: SetAttrib()
// Desc: Adds an attribute by using IWMHeaderInfo::SetAttribute.
//------------------------------------------------------------------------------
HRESULT SetAttrib( __in LPWSTR pwszInFile, 
                   WORD wStreamNum, 
                   __in LPWSTR pwszAttribName, 
                   WORD wAttribType, 
                   __in LPWSTR pwszAttribValue )
{
    if( ( NULL == pwszInFile ) ||
        ( NULL == pwszAttribName ) ||
        ( NULL == pwszAttribValue ) )
    {
        return( E_INVALIDARG );
    }

    HRESULT hr = S_OK;

    IWMMetadataEditor   * pEditor       = NULL;
    IWMHeaderInfo       * pHeaderInfo   = NULL;

    BYTE*               pbAttribValue   = NULL;
    WORD                wAttribValueLen = 0;

    WMT_ATTR_DATATYPE   AttribDataType  = ( WMT_ATTR_DATATYPE ) wAttribType;

    DWORD               dwAttribValue   = 0;
    WORD                wAttribValue    = 0;
    QWORD               qwAttribValue   = 0;
    BOOL                fAttribValue    = 0;

    do
    {
        hr = EditorOpenFile( pwszInFile, &pEditor, &pHeaderInfo, NULL);
        if(FAILED( hr ) )
        {
            break;
        }

        switch( AttribDataType )
        {
        case WMT_TYPE_DWORD:
            dwAttribValue = _wtoi( pwszAttribValue );                               
            wAttribValueLen = sizeof( DWORD );
            pbAttribValue = (BYTE *)&dwAttribValue;

            break;

        case WMT_TYPE_WORD:
            wAttribValue = (WORD)_wtoi( pwszAttribValue );                                
            wAttribValueLen = sizeof(WORD);
            pbAttribValue = (BYTE *)&wAttribValue;

            break;

        case WMT_TYPE_QWORD:
            qwAttribValue = _wtoi64( pwszAttribValue );                             
            wAttribValueLen = sizeof(QWORD );
            pbAttribValue = (BYTE *)&qwAttribValue;

            break;
                    
        case WMT_TYPE_STRING:
            wAttribValueLen = ( wcslen( pwszAttribValue ) + 1 )* sizeof( WCHAR );
            pbAttribValue = (BYTE *)pwszAttribValue;

            break;

        case WMT_TYPE_BOOL:
            fAttribValue = (BOOL)_wtoi( pwszAttribValue );                              
            wAttribValueLen = sizeof(BOOL);
            pbAttribValue = (BYTE *)&fAttribValue;

            break;

        default:
            _tprintf( _T( "Unsupported data type for SetAttribute\n" ) );
            hr = E_INVALIDARG;
            break;
        }

        hr = pHeaderInfo->SetAttribute( wStreamNum,
                                        pwszAttribName,
                                        AttribDataType,                                        
                                        pbAttribValue,
                                        wAttribValueLen );
        if( FAILED( hr ) )
        {
            _tprintf( _T( "SetAttribute failed for Attribute name %ws ( hr=0x%08x ).\n" ), 
                pwszAttribName, hr );
            break;
        }

        hr = pEditor->Flush();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not flush the file %ws ( hr=0x%08x ).\n" ), 
                pwszInFile, hr );
            break;
        }

        hr = pEditor->Close();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not close the file %ws ( hr=0x%08x ).\n" ), 
                pwszInFile, hr );
            break;
        }
    }
    while( FALSE );
    
    SAFE_RELEASE( pHeaderInfo );
    SAFE_RELEASE( pEditor );

    return( hr );
}
Esempio n. 6
0
int tagwrite(const string fname,  struct fennec_audiotag *wtag)
{	

	HRESULT               hres;
	IWMHeaderInfo*        wminfo;
	WORD                  wmistream = 0;
	BOOL                  sdef = 1;
	IWMMetadataEditor    *pEdit = 0;
	IWMHeaderInfo        *pInfo = 0;
	int                   twrote = 1;

	if(!wtag)return 0;

	CoInitialize(0);

	hres = WMCreateEditor(&pEdit);
	hres = pEdit->Open(fname);

	pEdit->QueryInterface(IID_IWMHeaderInfo, (VOID **)(&wminfo));


	if(wtag->tag_title.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTitle          ,wtag->tag_title.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTitle          , 0); }

	if(wtag->tag_album.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAlbumTitle     ,wtag->tag_album.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAlbumTitle     , 0); }

	if(wtag->tag_artist.tsize        ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthor         ,wtag->tag_artist.tdata        ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthor         , 0); }
	
	if(wtag->tag_origartist.tsize    ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMOriginalArtist ,wtag->tag_origartist.tdata    ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMOriginalArtist , 0); }
	
	if(wtag->tag_composer.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMComposer       ,wtag->tag_composer.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMComposer       , 0); }
	
	if(wtag->tag_lyricist.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         ,wtag->tag_lyricist.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMWriter         , 0); }
 
	/* band: not used */
	
	if(wtag->tag_copyright.tsize     ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMCopyright      ,wtag->tag_copyright.tdata     ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMCopyright      , 0); }
	
	if(wtag->tag_publish.tsize       ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMPublisher      ,wtag->tag_publish.tdata       ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMPublisher      , 0); }
	
	if(wtag->tag_encodedby.tsize     ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMEncodedBy      ,wtag->tag_encodedby.tdata     ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMEncodedBy      , 0); }
	
	if(wtag->tag_genre.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMGenre          ,wtag->tag_genre.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMGenre          , 0); }
	
	if(wtag->tag_year.tsize          ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMYear           ,wtag->tag_year.tdata          ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMYear           , 0); }
	
	if(wtag->tag_url.tsize           ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMUserWebURL     ,wtag->tag_url.tdata           ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMUserWebURL     , 0); }
	
	if(wtag->tag_offiartisturl.tsize ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthorURL      ,wtag->tag_offiartisturl.tdata ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthorURL      , 0); }
	
	if(wtag->tag_comments.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMDescription    ,wtag->tag_comments.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMDescription    , 0); }
	
	if(wtag->tag_lyric.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         ,wtag->tag_lyric.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         , 0); }

	if(wtag->tag_bpm.tsize           ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMBeatsPerMinute ,wtag->tag_bpm.tdata           ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMBeatsPerMinute , 0); }

	if(wtag->tag_tracknum.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTrack          ,wtag->tag_tracknum.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTrack          , 0); }

	if(!twrote)
	{
		MessageBox(0, uni("Couldn't set tag(s), if you're setting tags on currently playing media, try stopping it."), uni("Error on tagging"), MB_ICONQUESTION);
	}

	pEdit->Flush();
	pEdit->Close();
	wminfo->Release();
	pEdit->Release();

	return 1;
}
Esempio n. 7
0
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;
}