+++ /dev/null
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include "stdafx.h"\r
-\r
-#include "../DataStream.h"\r
-#include "IAudioProcessor.h"\r
-\r
-using namespace System;\r
-using namespace SlimDX::Multimedia;\r
-\r
-namespace SlimDX\r
-{\r
-namespace XAPO\r
-{\r
- XAPOShim::XAPOShim( IAudioProcessor^ wrappedInterface )\r
- {\r
- m_interface = wrappedInterface;\r
- refCount = 1;\r
-\r
- if( IParameterProvider::typeid->IsAssignableFrom( wrappedInterface->GetType() ) )\r
- m_parameters = safe_cast<IParameterProvider^>( wrappedInterface );\r
- else\r
- m_parameters = nullptr;\r
- }\r
-\r
- HRESULT XAPOShim::QueryInterface( const IID &iid, LPVOID *ppv )\r
- {\r
- if( iid == __uuidof(IXAPO) )\r
- {\r
- AddRef();\r
- *ppv = static_cast<IXAPO*>( this );\r
- return S_OK;\r
- }\r
- else if( iid == __uuidof(IUnknown) )\r
- {\r
- AddRef();\r
- *ppv = static_cast<IUnknown*>( static_cast<IXAPO*>( this ) );\r
- return S_OK;\r
- }\r
- else if( iid == __uuidof(IXAPOParameters) && safe_cast<IParameterProvider^>( m_parameters ) != nullptr )\r
- {\r
- AddRef();\r
- *ppv = static_cast<IXAPOParameters*>( this );\r
- return S_OK;\r
- }\r
-\r
- return E_NOTIMPL;\r
- }\r
-\r
- ULONG XAPOShim::AddRef()\r
- {\r
- return InterlockedIncrement( &refCount );\r
- }\r
-\r
- ULONG XAPOShim::Release()\r
- {\r
- if( InterlockedDecrement( &refCount ) == 0 )\r
- delete this;\r
- return refCount;\r
- }\r
-\r
- UINT32 WINAPI XAPOShim::CalcInputFrames( UINT32 OutputFrameCount )\r
- {\r
- try\r
- {\r
- return m_interface->CalculateInputFrames( OutputFrameCount );\r
- }\r
- catch(...)\r
- {\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- UINT32 WINAPI XAPOShim::CalcOutputFrames( UINT32 InputFrameCount )\r
- {\r
- try\r
- {\r
- return m_interface->CalculateOutputFrames( InputFrameCount );\r
- }\r
- catch(...)\r
- {\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- HRESULT WINAPI XAPOShim::GetRegistrationProperties( XAPO_REGISTRATION_PROPERTIES **ppRegistrationProperties )\r
- {\r
- try\r
- {\r
- XAPO_REGISTRATION_PROPERTIES *ptr = reinterpret_cast<XAPO_REGISTRATION_PROPERTIES*>( XAPOAlloc( sizeof( XAPO_REGISTRATION_PROPERTIES ) ) );\r
- XAPO_REGISTRATION_PROPERTIES properties = m_interface->RegistrationProperties.ToUnmanaged();\r
- memcpy( ptr, &properties, sizeof( XAPO_REGISTRATION_PROPERTIES ) );\r
-\r
- *ppRegistrationProperties = ptr;\r
- }\r
- catch( SlimDXException^ ex )\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
-\r
- return S_OK;\r
- }\r
-\r
- HRESULT WINAPI XAPOShim::Initialize( const void *pData, UINT32 DataByteSize )\r
- {\r
- try\r
- {\r
- DataStream^ data = gcnew DataStream( pData, DataByteSize, true, false );\r
- \r
- return m_interface->Initialize( data ).Code;\r
- }\r
- catch( SlimDXException^ ex )\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
-\r
- return S_OK;\r
- }\r
-\r
- HRESULT WINAPI XAPOShim::IsInputFormatSupported( const WAVEFORMATEX *pOutputFormat, const WAVEFORMATEX *pRequestedInputFormat, WAVEFORMATEX **ppSupportedInputFormat )\r
- {\r
- try\r
- {\r
- WaveFormat^ format;\r
- bool result = m_interface->IsInputFormatSupported( WaveFormat::FromUnmanaged( *pOutputFormat ), WaveFormat::FromUnmanaged( *pRequestedInputFormat ), format );\r
-\r
- auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );\r
- *ppSupportedInputFormat = native.release();\r
-\r
- return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;\r
- }\r
- catch( SlimDXException^ ex )\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
-\r
- return S_OK;\r
- }\r
-\r
- HRESULT WINAPI XAPOShim::IsOutputFormatSupported( const WAVEFORMATEX *pInputFormat, const WAVEFORMATEX *pRequestedOutputFormat, WAVEFORMATEX **ppSupportedOutputFormat )\r
- {\r
- try\r
- {\r
- WaveFormat^ format;\r
- bool result = m_interface->IsOutputFormatSupported( WaveFormat::FromUnmanaged( *pInputFormat ), WaveFormat::FromUnmanaged( *pRequestedOutputFormat ), format );\r
-\r
- auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );\r
- *ppSupportedOutputFormat = native.release();\r
-\r
- return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;\r
- }\r
- catch( SlimDXException^ ex )\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
-\r
- return S_OK;\r
- }\r
-\r
- HRESULT WINAPI XAPOShim::LockForProcess( UINT32 InputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pInputLockedParameters, UINT32 OutputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pOutputLockedParameters )\r
- {\r
- try\r
- {\r
- array<LockParameter>^ input = gcnew array<LockParameter>( InputLockedParameterCount );\r
- for( int i = 0; i < input->Length; i++ )\r
- {\r
- LockParameter p;\r
- p.Format = WaveFormat::FromUnmanaged( *pInputLockedParameters[i].pFormat );\r
- p.MaxFrameCount = pInputLockedParameters[i].MaxFrameCount;\r
-\r
- input[i] = p;\r
- }\r
-\r
- array<LockParameter>^ output = gcnew array<LockParameter>( OutputLockedParameterCount );\r
- for( int i = 0; i < output->Length; i++ )\r
- {\r
- LockParameter p;\r
- p.Format = WaveFormat::FromUnmanaged( *pOutputLockedParameters[i].pFormat );\r
- p.MaxFrameCount = pOutputLockedParameters[i].MaxFrameCount;\r
-\r
- output[i] = p;\r
- }\r
-\r
- return m_interface->LockForProcess( input, output ).Code;\r
- }\r
- catch( SlimDXException^ ex )\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
-\r
- return S_OK;\r
- }\r
-\r
- void WINAPI XAPOShim::Process( UINT32 InputProcessParameterCount, const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters, UINT32 OutputProcessParameterCount, XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters, BOOL IsEnabled )\r
- {\r
- try\r
- {\r
- array<BufferParameter>^ input = gcnew array<BufferParameter>( InputProcessParameterCount );\r
- for( int i = 0; i < input->Length; i++ )\r
- {\r
- BufferParameter p;\r
- p.Buffer = IntPtr( pInputProcessParameters[i].pBuffer );\r
- p.Flags = static_cast<BufferFlags>( pInputProcessParameters[i].BufferFlags );\r
- p.ValidFrameCount = pInputProcessParameters[i].ValidFrameCount;\r
-\r
- input[i] = p;\r
- }\r
-\r
- array<BufferParameter>^ output = gcnew array<BufferParameter>( OutputProcessParameterCount );\r
- for( int i = 0; i < output->Length; i++ )\r
- {\r
- BufferParameter p;\r
- p.Buffer = IntPtr( pOutputProcessParameters[i].pBuffer );\r
- p.Flags = static_cast<BufferFlags>( pOutputProcessParameters[i].BufferFlags );\r
- p.ValidFrameCount = pOutputProcessParameters[i].ValidFrameCount;\r
-\r
- output[i] = p;\r
- }\r
-\r
- m_interface->Process( input, output, IsEnabled > 0 );\r
- }\r
- catch(...)\r
- {\r
- }\r
- }\r
-\r
- void WINAPI XAPOShim::Reset()\r
- {\r
- try\r
- {\r
- m_interface->Reset();\r
- }\r
- catch(...)\r
- {\r
- }\r
- }\r
-\r
- void WINAPI XAPOShim::UnlockForProcess()\r
- {\r
- try\r
- {\r
- m_interface->UnlockForProcess();\r
- }\r
- catch(...)\r
- {\r
- }\r
- }\r
-\r
- void WINAPI XAPOShim::GetParameters( void *pParameters, UINT32 ParameterByteSize )\r
- {\r
- try\r
- {\r
- m_parameters->GetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, true, false ) );\r
- }\r
- catch(...)\r
- {\r
- }\r
- }\r
-\r
- void WINAPI XAPOShim::SetParameters( const void *pParameters, UINT32 ParameterByteSize )\r
- {\r
- try\r
- {\r
- m_parameters->SetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, false ) );\r
- }\r
- catch(...)\r
- {\r
- }\r
- }\r
-}\r
-}
\ No newline at end of file