Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
5.2 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "milesbase.h"
  8. #include "tier0/dbg.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. static int s_MilesRefCount = 0;
  12. void IncrementRefMiles()
  13. {
  14. if(s_MilesRefCount == 0)
  15. {
  16. #ifdef WIN32
  17. AIL_set_redist_directory( "." );
  18. #elif defined( OSX )
  19. AIL_set_redist_directory( "osx32" );
  20. #elif defined( LINUX )
  21. #ifdef PLATFORM_64BITS
  22. AIL_set_redist_directory( "bin/linux64" );
  23. #else
  24. AIL_set_redist_directory( "bin/linux32" );
  25. #endif
  26. #else
  27. Assert( !"Using default MSS_REDIST_DIR_NAME - this will most likely fail." );
  28. AIL_set_redist_directory( MSS_REDIST_DIR_NAME );
  29. #endif
  30. AIL_startup();
  31. }
  32. ++s_MilesRefCount;
  33. }
  34. void DecrementRefMiles()
  35. {
  36. Assert(s_MilesRefCount > 0);
  37. --s_MilesRefCount;
  38. if(s_MilesRefCount == 0)
  39. {
  40. CProvider::FreeAllProviders();
  41. AIL_shutdown();
  42. }
  43. }
  44. // ------------------------------------------------------------------------ //
  45. // CProvider functions.
  46. // ------------------------------------------------------------------------ //
  47. CProvider *CProvider::s_pHead = NULL;
  48. CProvider::CProvider( HPROVIDER hProvider )
  49. {
  50. m_hProvider = hProvider;
  51. // Add to the global list of CProviders.
  52. m_pNext = s_pHead;
  53. s_pHead = this;
  54. }
  55. CProvider::~CProvider()
  56. {
  57. RIB_free_provider_library( m_hProvider );
  58. // Remove from the global list.
  59. CProvider **ppPrev = &s_pHead;
  60. for ( CProvider *pCur=s_pHead; pCur; pCur=pCur->m_pNext )
  61. {
  62. if ( pCur == this )
  63. {
  64. *ppPrev = m_pNext;
  65. return;
  66. }
  67. ppPrev = &pCur->m_pNext;
  68. }
  69. }
  70. CProvider* CProvider::FindProvider( HPROVIDER hProvider )
  71. {
  72. for ( CProvider *pCur=s_pHead; pCur; pCur=pCur->m_pNext )
  73. {
  74. if ( pCur->GetProviderHandle() == hProvider )
  75. {
  76. return pCur;
  77. }
  78. }
  79. return NULL;
  80. }
  81. void CProvider::FreeAllProviders()
  82. {
  83. CProvider *pNext;
  84. for ( CProvider *pCur=s_pHead; pCur; pCur=pNext )
  85. {
  86. pNext = pCur->m_pNext;
  87. delete pCur;
  88. }
  89. }
  90. HPROVIDER CProvider::GetProviderHandle()
  91. {
  92. return m_hProvider;
  93. }
  94. // ------------------------------------------------------------------------ //
  95. // ASISTRUCT functions.
  96. // ------------------------------------------------------------------------ //
  97. ASISTRUCT::ASISTRUCT()
  98. {
  99. Clear();
  100. IncrementRefMiles();
  101. }
  102. ASISTRUCT::~ASISTRUCT()
  103. {
  104. Shutdown();
  105. DecrementRefMiles();
  106. }
  107. void ASISTRUCT::Clear()
  108. {
  109. m_pProvider = NULL;
  110. ASI_stream_open = NULL;
  111. ASI_stream_process = NULL;
  112. ASI_stream_close = NULL;
  113. ASI_stream_property = NULL;
  114. ASI_stream_seek = NULL;
  115. OUTPUT_BITS = NULL;
  116. OUTPUT_CHANNELS = NULL;
  117. INPUT_BITS = NULL;
  118. INPUT_CHANNELS = NULL;
  119. POSITION = NULL;
  120. m_stream = NULL;
  121. }
  122. bool ASISTRUCT::Init( void *pCallbackObject, const char *pInputFileType, const char *pOutputFileType, AILASIFETCHCB cb )
  123. {
  124. // Get the provider.
  125. HPROVIDER hProvider = RIB_find_files_provider( "ASI codec",
  126. "Output file types", pOutputFileType, "Input file types", pInputFileType );
  127. if ( !hProvider )
  128. return false;
  129. m_pProvider = CProvider::FindProvider( hProvider );
  130. if ( !m_pProvider )
  131. {
  132. m_pProvider = new CProvider( hProvider );
  133. }
  134. if ( !m_pProvider )
  135. return false;
  136. RIB_INTERFACE_ENTRY ASISTR[] =
  137. {
  138. FN( ASI_stream_property ),
  139. FN( ASI_stream_open ),
  140. FN( ASI_stream_close ),
  141. FN( ASI_stream_process ),
  142. PR( "Output sample rate", OUTPUT_RATE ),
  143. PR( "Output sample width", OUTPUT_BITS ),
  144. PR( "Output channels", OUTPUT_CHANNELS ),
  145. PR( "Input sample rate", INPUT_RATE ),
  146. PR( "Input sample width", INPUT_BITS ),
  147. PR( "Input channels", INPUT_CHANNELS ),
  148. PR( "Minimum input block size", INPUT_BLOCK_SIZE ),
  149. PR( "Position", POSITION ),
  150. };
  151. RIBRESULT result = RIB_request( m_pProvider->GetProviderHandle(), "ASI stream", ASISTR );
  152. if(result != RIB_NOERR)
  153. return false;
  154. // This function doesn't exist for the voice DLLs, but it's not fatal in that case.
  155. RIB_INTERFACE_ENTRY seekFn[] =
  156. {
  157. FN( ASI_stream_seek ),
  158. };
  159. result = RIB_request( m_pProvider->GetProviderHandle(), "ASI stream", seekFn );
  160. if(result != RIB_NOERR)
  161. ASI_stream_seek = NULL;
  162. m_stream = ASI_stream_open( (MSS_ALLOC_TYPE *)MSS_CALLBACK_ALIGNED_NAME( MSS_alloc_info ),
  163. (MSS_FREE_TYPE *)MSS_CALLBACK_ALIGNED_NAME( MSS_free_info ),
  164. (UINTa)pCallbackObject, cb, 0);
  165. if(!m_stream)
  166. return false;
  167. return true;
  168. }
  169. void ASISTRUCT::Shutdown()
  170. {
  171. if ( m_pProvider )
  172. {
  173. if (m_stream && ASI_stream_close)
  174. {
  175. ASI_stream_close(m_stream);
  176. m_stream = NULL;
  177. }
  178. //m_pProvider->Release();
  179. m_pProvider = NULL;
  180. }
  181. Clear();
  182. }
  183. int ASISTRUCT::Process( void *pBuffer, unsigned int bufferSize )
  184. {
  185. return ASI_stream_process( m_stream, pBuffer, bufferSize );
  186. }
  187. bool ASISTRUCT::IsActive() const
  188. {
  189. return m_stream != NULL ? true : false;
  190. }
  191. unsigned int ASISTRUCT::GetProperty( HPROPERTY hProperty )
  192. {
  193. uint32 nValue = 0;
  194. if ( ASI_stream_property( m_stream, hProperty, &nValue, NULL, NULL ) )
  195. {
  196. return nValue;
  197. }
  198. return 0;
  199. }
  200. void ASISTRUCT::Seek( int position )
  201. {
  202. if ( !ASI_stream_seek )
  203. Error( "ASI_stream_seek called, but it doesn't exist." );
  204. ASI_stream_seek( m_stream, (S32)position );
  205. }