📄 genprofile_lib.cpp
字号:
break;
}
//
// If this profile will be used by writer, we should set the properties
// on the stream configuration
//
if ( SUCCEEDED( pStreamConfig->QueryInterface( IID_IWMPropertyVault, (void**)&pPropertyVault ) ) )
{
assert( pPropertyVault );
hr = pPropertyVault->SetProperty( g_wszVBREnabled, WMT_TYPE_BOOL, (BYTE*) &fIsVBR, sizeof( fIsVBR ) );
if ( FAILED( hr ) )
{
break;
}
switch( vbrMode )
{
case VBR_QUALITYBASED:
//
// Only the quality needs to be set
//
hr = pPropertyVault->SetProperty( g_wszVBRQuality, WMT_TYPE_DWORD, (BYTE*) &dwVBRQuality, sizeof( DWORD ) );
break;
case VBR_CONSTRAINED:
//
// The peak bitrate and, optionally, max buffer window need to be set
//
hr = pPropertyVault->SetProperty( g_wszVBRBitrateMax, WMT_TYPE_DWORD, (BYTE*) &dwMaxBitrate, sizeof( DWORD ) );
if ( FAILED( hr ) )
{
break;
}
if( dwMaxBufferWindow != 0 )
{
hr = pPropertyVault->SetProperty( g_wszVBRBufferWindowMax, WMT_TYPE_DWORD, (BYTE*) &dwMaxBufferWindow, sizeof( DWORD ) );
}
break;
case VBR_UNCONSTRAINED:
break;
case VBR_OFF:
break;
default:
hr = E_FAIL;
break;
}
if ( FAILED( hr ) )
{
break;
}
SAFE_RELEASE( pPropertyVault );
}
/*
hr = SetStreamLanguage( pStreamConfig, dwLanguage );
if ( FAILED( hr ) )
{
break;
}
*/
//
// Return the pStreamConfig to the caller
//
SAFE_ADDREF( pStreamConfig );
*ppStreamConfig = pStreamConfig;
}
while ( FALSE );
SAFE_RELEASE( pStreamConfig );
SAFE_RELEASE( pPropertyVault );
SAFE_ARRAYDELETE( pMediaType );
SAFE_RELEASE( pVideoMediaProps );
return hr;
}
//------------------------------------------------------------------------------
// Name: CreateMediatypeForFormat()
// Desc: Initializes a WM_MEDIA_TYPE for a codec format, setting VBR attributes.
//------------------------------------------------------------------------------
STDMETHODIMP CreateMediatypeForFormat( Twmv9dll *dll,
WM_MEDIA_TYPE** ppmtDestination,
IWMCodecInfo3* pCodecInfo3,
IWMStreamConfig** ppFormatConfig,
GUID guidCodecType,
DWORD dwCodecIndex,
DWORD dwFormatIndex,
BOOL fIsVBR,
DWORD dwVBRPasses )
{
HRESULT hr = S_OK;
IWMProfileManager* pProfileManager = NULL;
IWMStreamConfig* pStreamConfig = NULL;
IWMMediaProps* pMediaProps = NULL;
if ( !ppmtDestination )
{
return E_INVALIDARG;
}
do
{
*ppmtDestination = NULL;
//
// Make sure the pCodecInfo3 exists, and there's an outstanding reference
//
hr = EnsureIWMCodecInfo3( dll,&pCodecInfo3 );
if ( FAILED( hr ) )
{
break;
}
assert( pCodecInfo3 );
//
// Set the VBR settings appropriately
//
hr = SetCodecVBRSettings( pCodecInfo3,
guidCodecType,
dwCodecIndex,
fIsVBR,
dwVBRPasses );
if ( FAILED( hr ) )
{
break;
}
//
// Call the version that doesn't set the VBR attributes
//
hr = CreateMediatypeForFormat( dll,
ppmtDestination,
pCodecInfo3,
ppFormatConfig,
guidCodecType,
dwCodecIndex,
dwFormatIndex );
if ( FAILED( hr ) )
{
break;
}
assert( *ppmtDestination );
}
while ( FALSE );
if ( FAILED( hr ) )
{
SAFE_ARRAYDELETE( (*ppmtDestination) );
}
SAFE_RELEASE( pCodecInfo3 );
SAFE_RELEASE( pProfileManager );
SAFE_RELEASE( pStreamConfig );
SAFE_RELEASE( pMediaProps );
return hr;
}
//------------------------------------------------------------------------------
// Name: CreateMediatypeForFormat() (Overloaded)
// Desc: Initializes a WM_MEDIA_TYPE for a codec format, without setting
// VBR attributes.
//------------------------------------------------------------------------------
STDMETHODIMP CreateMediatypeForFormat( Twmv9dll *dll,
WM_MEDIA_TYPE** ppmtDestination,
IWMCodecInfo3* pCodecInfo3,
IWMStreamConfig** ppFormatConfig,
GUID guidCodecType,
DWORD dwCodecIndex,
DWORD dwFormatIndex )
{
HRESULT hr = S_OK;
IWMProfileManager* pProfileManager = NULL;
IWMStreamConfig* pFormatConfig = NULL;
IWMMediaProps* pMediaProps = NULL;
DWORD dwMediaTypeLength;
if ( !ppmtDestination )
{
return E_INVALIDARG;
}
do
{
*ppmtDestination = NULL;
//
// Make sure the pCodecInfo3 exists, and there's an outstanding reference
//
hr = EnsureIWMCodecInfo3(dll, &pCodecInfo3 );
if ( FAILED( hr ) )
{
break;
}
assert( pCodecInfo3 );
//
// Get the stream configuration for the given format
//
hr = pCodecInfo3->GetCodecFormat( guidCodecType, dwCodecIndex, dwFormatIndex, &pFormatConfig );
if ( FAILED( hr ) )
{
break;
}
assert( pFormatConfig );
//
// Get the media type for the requested format
//
hr = pFormatConfig->QueryInterface( IID_IWMMediaProps, (void**) &pMediaProps );
if ( FAILED( hr ) )
{
break;
}
assert( pMediaProps );
dwMediaTypeLength = 0;
hr = pMediaProps->GetMediaType( NULL, &dwMediaTypeLength );
if( FAILED( hr ) )
{
break;
}
*ppmtDestination = (WM_MEDIA_TYPE *) new BYTE[ dwMediaTypeLength ];
if( !*ppmtDestination )
{
hr = E_OUTOFMEMORY;
break;
}
hr = pMediaProps->GetMediaType( *ppmtDestination, &dwMediaTypeLength );
if( FAILED( hr ) )
{
break;
}
assert( *ppmtDestination );
if ( ppFormatConfig )
{
SAFE_ADDREF( pFormatConfig );
*ppFormatConfig = pFormatConfig;
}
}
while ( FALSE );
if ( FAILED( hr ) )
{
SAFE_ARRAYDELETE( *ppmtDestination );
}
SAFE_RELEASE( pCodecInfo3 );
SAFE_RELEASE( pProfileManager );
SAFE_RELEASE( pFormatConfig );
SAFE_RELEASE( pMediaProps );
return hr;
}
//------------------------------------------------------------------------------
// Name: WriteProfileAsPRX()
// Desc: Writes a profile to a PRX file.
//------------------------------------------------------------------------------
STDMETHODIMP WriteProfileAsPRX( LPCTSTR tszFilename, LPCWSTR wszProfileData, DWORD dwProfileDataLength )
{
HANDLE hFile = NULL;
HRESULT hr = S_OK;
DWORD dwBytesWritten;
BOOL bResult;
assert( tszFilename );
assert( wszProfileData );
assert( 0 != dwProfileDataLength );
do
{
//
// Create the file, overwriting any existing file
//
hFile = CreateFile( tszFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
if ( INVALID_HANDLE_VALUE == hFile )
{
hr = HRESULT_FROM_WIN32( GetLastError() );
break;
}
//
// Write the profile data to the file
//
bResult = WriteFile( hFile, wszProfileData, dwProfileDataLength, &dwBytesWritten, NULL );
if ( !bResult )
{
hr = HRESULT_FROM_WIN32( GetLastError() );
break;
}
}
while ( FALSE );
//
// Close the file, if it was opened successfully
//
SAFE_CLOSEHANDLE( hFile );
return hr;
}
//------------------------------------------------------------------------------
// Name: AddSMPTEExtensionToStream()
// Desc: Add a data unit extension for SMPTE time code.
//------------------------------------------------------------------------------
STDMETHODIMP AddSMPTEExtensionToStream( IWMStreamConfig* pStream )
{
HRESULT hr = S_OK;
IWMStreamConfig2* pStreamConfig2 = NULL;
if ( !pStream )
{
return E_INVALIDARG;
}
do
{
//
// Get the IWMStreamConfig2 interface
//
hr = pStream->QueryInterface( IID_IWMStreamConfig2, (void**) &pStreamConfig2 );
if ( FAILED( hr ) )
{
break;
}
assert( pStreamConfig2 );
//
// Add SMPTE extension
//
hr = pStreamConfig2->AddDataUnitExtension( WM_SampleExtensionGUID_Timecode,
sizeof( WMT_TIMECODE_EXTENSION_DATA ),
NULL,
0 );
if ( FAILED( hr ) )
{
break;
}
}
while ( FALSE );
SAFE_RELEASE( pStreamConfig2 );
return hr;
}
//------------------------------------------------------------------------------
// Name: GetUncompressedWaveFormatCount()
// Desc: Returns the number of uncompressed wave formats, four for each
// frequency in the WaveFrequency array.
//------------------------------------------------------------------------------
STDMETHODIMP GetUncompressedWaveFormatCount( DWORD * pdwCount )
{
*pdwCount = 4 * sizeof( WaveFrequency ) / sizeof( WaveFrequency[0] );
return S_OK;
}
//------------------------------------------------------------------------------
// Name: GetUncompressedWaveFormat()
// Desc: Retrieves wave format parameters by index.
//------------------------------------------------------------------------------
STDMETHODIMP GetUncompressedWaveFormat( DWORD dwIndex,
DWORD * pdwSamplesPerSecond,
WORD * pwNumChannels,
WORD * pwBitsPerSample )
{
if ( NULL == pdwSamplesPerSecond
|| NULL == pwNumChannels
|| NULL == pwBitsPerSample )
{
return E_POINTER;
}
DWORD dwCount;
HRESULT hr;
hr = GetUncompressedWaveFormatCount( &dwCount );
if ( FAILED( hr ) )
{
return hr;
}
if ( dwIndex >= dwCount )
{
return E_INVALIDARG;
}
*pdwSamplesPerSecond = WaveFrequency[ dwIndex / 4 ];
switch ( dwIndex % 4 )
{
case 0:
*pwBitsPerSample = 8;
*pwNumChannels = 1;
break;
case 1:
*pwBitsPerSample = 8;
*pwNumChannels = 2;
break;
case 2:
*pwBitsPerSample = 16;
*pwNumChannels = 1;
break;
case 3:
*pwBitsPerSample = 16;
*pwNumChannels = 2;
break;
}
return S_OK;
}
//------------------------------------------------------------------------------
// Name: GetUncompressedPixelFormatCount()
// Desc: Returns the number of formats in the PixelFormats array.
//------------------------------------------------------------------------------
STDMETHODIMP GetUncompressedPixelFormatCount( DWORD * pdwCount )
{
*pdwCount = sizeof( PixelFormats ) / sizeof( PixelFormats[0] );
return S_OK;
}
//------------------------------------------------------------------------------
// Name: GetUncompressedPixelFormat()
// Desc: Retrieves pixel format parameters by index.
//------------------------------------------------------------------------------
STDMETHODIMP GetUncompressedPixelFormat( DWORD dwIndex,
GUID * pguidFormat,
DWORD * pdwFourCC,
WORD * pwBitsPerPixel )
{
if ( NULL == pguidFormat
|| NULL == pdwFourCC
|| NULL == pwBitsPerPixel )
{
return E_POINTER;
}
DWORD dwCount = sizeof( PixelFormats ) / sizeof( PixelFormats[0] );
if ( dwIndex > dwCount )
{
return E_INVALIDARG;
}
*pguidFormat = *PixelFormats[ dwIndex ].guidFormat;
*pdwFourCC = PixelFormats[ dwIndex ].dwFourCC;
*pwBitsPerPixel = PixelFormats[ dwIndex ].wBitsPerPixel;
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -