PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wilhelm/src/itf/IEngineCapabilities.c

https://bitbucket.org/generalplus/android_system_media
C | 226 lines | 174 code | 33 blank | 19 comment | 67 complexity | 985251266409c27da270d46e7a55001d MD5 | raw file
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* EngineCapabilities implementation */
  17. #include "sles_allinclusive.h"
  18. static SLresult IEngineCapabilities_QuerySupportedProfiles(
  19. SLEngineCapabilitiesItf self, SLuint16 *pProfilesSupported)
  20. {
  21. SL_ENTER_INTERFACE
  22. if (NULL == pProfilesSupported) {
  23. result = SL_RESULT_PARAMETER_INVALID;
  24. } else {
  25. // The generic implementation doesn't implement any of the profiles, they shouldn't be
  26. // declared as supported. Also exclude the fake profiles BASE and OPTIONAL.
  27. *pProfilesSupported = USE_PROFILES &
  28. (USE_PROFILES_GAME | USE_PROFILES_MUSIC | USE_PROFILES_PHONE);
  29. result = SL_RESULT_SUCCESS;
  30. }
  31. SL_LEAVE_INTERFACE
  32. }
  33. static SLresult IEngineCapabilities_QueryAvailableVoices(SLEngineCapabilitiesItf self,
  34. SLuint16 voiceType, SLint16 *pNumMaxVoices, SLboolean *pIsAbsoluteMax, SLint16 *pNumFreeVoices)
  35. {
  36. SL_ENTER_INTERFACE
  37. switch (voiceType) {
  38. case SL_VOICETYPE_2D_AUDIO:
  39. case SL_VOICETYPE_MIDI:
  40. case SL_VOICETYPE_3D_AUDIO:
  41. case SL_VOICETYPE_3D_MIDIOUTPUT:
  42. if (NULL != pNumMaxVoices)
  43. *pNumMaxVoices = MAX_INSTANCE - 2;
  44. if (NULL != pIsAbsoluteMax)
  45. *pIsAbsoluteMax = SL_BOOLEAN_TRUE;
  46. if (NULL != pNumFreeVoices)
  47. *pNumFreeVoices = MAX_INSTANCE - 2;
  48. result = SL_RESULT_SUCCESS;
  49. break;
  50. default:
  51. result = SL_RESULT_PARAMETER_INVALID;
  52. break;
  53. }
  54. SL_LEAVE_INTERFACE
  55. }
  56. static SLresult IEngineCapabilities_QueryNumberOfMIDISynthesizers(
  57. SLEngineCapabilitiesItf self, SLint16 *pNum)
  58. {
  59. SL_ENTER_INTERFACE
  60. if (NULL == pNum) {
  61. result = SL_RESULT_PARAMETER_INVALID;
  62. } else {
  63. *pNum = 1;
  64. result = SL_RESULT_SUCCESS;
  65. }
  66. SL_LEAVE_INTERFACE
  67. }
  68. static SLresult IEngineCapabilities_QueryAPIVersion(SLEngineCapabilitiesItf self,
  69. SLint16 *pMajor, SLint16 *pMinor, SLint16 *pStep)
  70. {
  71. SL_ENTER_INTERFACE
  72. if (!(NULL != pMajor && NULL != pMinor && NULL != pStep)) {
  73. result = SL_RESULT_PARAMETER_INVALID;
  74. } else {
  75. *pMajor = 1;
  76. *pMinor = 0;
  77. *pStep = 1;
  78. result = SL_RESULT_SUCCESS;
  79. }
  80. SL_LEAVE_INTERFACE
  81. }
  82. SLresult IEngineCapabilities_QueryLEDCapabilities(SLEngineCapabilitiesItf self,
  83. SLuint32 *pIndex, SLuint32 *pLEDDeviceID, SLLEDDescriptor *pDescriptor)
  84. {
  85. SL_ENTER_INTERFACE
  86. IEngineCapabilities *thiz = (IEngineCapabilities *) self;
  87. const struct LED_id_descriptor *id_descriptor;
  88. SLuint32 index;
  89. if (NULL != pIndex) {
  90. result = SL_RESULT_SUCCESS;
  91. if (NULL != pLEDDeviceID || NULL != pDescriptor) {
  92. index = *pIndex;
  93. if (index >= thiz->mMaxIndexLED) {
  94. result = SL_RESULT_PARAMETER_INVALID;
  95. } else {
  96. id_descriptor = &LED_id_descriptors[index];
  97. if (NULL != pLEDDeviceID)
  98. *pLEDDeviceID = id_descriptor->id;
  99. if (NULL != pDescriptor)
  100. *pDescriptor = *id_descriptor->descriptor;
  101. }
  102. }
  103. *pIndex = thiz->mMaxIndexLED;
  104. } else {
  105. result = SL_RESULT_PARAMETER_INVALID;
  106. if (NULL != pLEDDeviceID && NULL != pDescriptor) {
  107. SLuint32 id = *pLEDDeviceID;
  108. for (index = 0; index < thiz->mMaxIndexLED; ++index) {
  109. id_descriptor = &LED_id_descriptors[index];
  110. if (id == id_descriptor->id) {
  111. *pDescriptor = *id_descriptor->descriptor;
  112. result = SL_RESULT_SUCCESS;
  113. break;
  114. }
  115. }
  116. }
  117. }
  118. SL_LEAVE_INTERFACE
  119. }
  120. SLresult IEngineCapabilities_QueryVibraCapabilities(SLEngineCapabilitiesItf self,
  121. SLuint32 *pIndex, SLuint32 *pVibraDeviceID, SLVibraDescriptor *pDescriptor)
  122. {
  123. SL_ENTER_INTERFACE
  124. IEngineCapabilities *thiz = (IEngineCapabilities *) self;
  125. const struct Vibra_id_descriptor *id_descriptor;
  126. SLuint32 index;
  127. if (NULL != pIndex) {
  128. result = SL_RESULT_SUCCESS;
  129. if (NULL != pVibraDeviceID || NULL != pDescriptor) {
  130. index = *pIndex;
  131. if (index >= thiz->mMaxIndexVibra) {
  132. result = SL_RESULT_PARAMETER_INVALID;
  133. } else {
  134. id_descriptor = &Vibra_id_descriptors[index];
  135. if (NULL != pVibraDeviceID)
  136. *pVibraDeviceID = id_descriptor->id;
  137. if (NULL != pDescriptor)
  138. *pDescriptor = *id_descriptor->descriptor;
  139. }
  140. }
  141. *pIndex = thiz->mMaxIndexVibra;
  142. } else {
  143. result = SL_RESULT_PARAMETER_INVALID;
  144. if (NULL != pVibraDeviceID && NULL != pDescriptor) {
  145. SLuint32 id = *pVibraDeviceID;
  146. for (index = 0; index < thiz->mMaxIndexVibra; ++index) {
  147. id_descriptor = &Vibra_id_descriptors[index];
  148. if (id == id_descriptor->id) {
  149. *pDescriptor = *id_descriptor->descriptor;
  150. result = SL_RESULT_SUCCESS;
  151. break;
  152. }
  153. }
  154. }
  155. }
  156. SL_LEAVE_INTERFACE
  157. }
  158. static SLresult IEngineCapabilities_IsThreadSafe(SLEngineCapabilitiesItf self,
  159. SLboolean *pIsThreadSafe)
  160. {
  161. SL_ENTER_INTERFACE
  162. if (NULL == pIsThreadSafe) {
  163. result = SL_RESULT_PARAMETER_INVALID;
  164. } else {
  165. IEngineCapabilities *thiz = (IEngineCapabilities *) self;
  166. *pIsThreadSafe = thiz->mThreadSafe;
  167. result = SL_RESULT_SUCCESS;
  168. }
  169. SL_LEAVE_INTERFACE
  170. }
  171. static const struct SLEngineCapabilitiesItf_ IEngineCapabilities_Itf = {
  172. IEngineCapabilities_QuerySupportedProfiles,
  173. IEngineCapabilities_QueryAvailableVoices,
  174. IEngineCapabilities_QueryNumberOfMIDISynthesizers,
  175. IEngineCapabilities_QueryAPIVersion,
  176. IEngineCapabilities_QueryLEDCapabilities,
  177. IEngineCapabilities_QueryVibraCapabilities,
  178. IEngineCapabilities_IsThreadSafe
  179. };
  180. void IEngineCapabilities_init(void *self)
  181. {
  182. IEngineCapabilities *thiz = (IEngineCapabilities *) self;
  183. thiz->mItf = &IEngineCapabilities_Itf;
  184. // mThreadSafe is initialized in slCreateEngine
  185. const struct LED_id_descriptor *id_descriptor_LED = LED_id_descriptors;
  186. while (NULL != id_descriptor_LED->descriptor)
  187. ++id_descriptor_LED;
  188. thiz->mMaxIndexLED = id_descriptor_LED - LED_id_descriptors;
  189. const struct Vibra_id_descriptor *id_descriptor_Vibra = Vibra_id_descriptors;
  190. while (NULL != id_descriptor_Vibra->descriptor)
  191. ++id_descriptor_Vibra;
  192. thiz->mMaxIndexVibra = id_descriptor_Vibra - Vibra_id_descriptors;
  193. }