From daccf40f73133a1220cc4ab8af45c59b1df9eeae Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Mon, 27 Sep 2010 17:30:18 -0700 Subject: [PATCH] Enable and test more interface ID queries Enable Engine::IEngine_QueryNumSupportedInterfaces and Engine::QuerySupportedInterfaces. Add object ID test. Return SL_RESULT_FEATURE_UNSUPPORTED from Engine::Create... if the corresponding class is not configured.. Add slesutObjectIDToString to utility toolkit. Change-Id: I28b8beff71d65e7eccd558e586652bb606c89848 --- opensles/libopensles/IEngine.c | 66 ++++++++++++++++++++++++------------ opensles/libopensles/MPH_to.c | 15 +++++++++ opensles/libopensles/OpenSLESUT.c | 20 +++++++++++ opensles/libopensles/OpenSLESUT.h | 1 + opensles/libopensles/classes.c | 70 +++++++++++++++++++++++++++++++++++++-- opensles/libopensles/sles.c | 1 + opensles/tests/sandbox/Android.mk | 30 +++++++++++++++++ opensles/tests/sandbox/object.c | 69 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 247 insertions(+), 25 deletions(-) create mode 100644 opensles/tests/sandbox/object.c diff --git a/opensles/libopensles/IEngine.c b/opensles/libopensles/IEngine.c index 30eb766e..865da4de 100644 --- a/opensles/libopensles/IEngine.c +++ b/opensles/libopensles/IEngine.c @@ -31,8 +31,12 @@ static SLresult IEngine_CreateLEDDevice(SLEngineItf self, SLObjectItf *pDevice, *pDevice = NULL; unsigned exposedMask; const ClassTable *pCLEDDevice_class = objectIDtoClass(SL_OBJECTID_LEDDEVICE); - result = checkInterfaces(pCLEDDevice_class, numInterfaces, pInterfaceIds, - pInterfaceRequired, &exposedMask); + if (NULL == pCLEDDevice_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCLEDDevice_class, numInterfaces, pInterfaceIds, + pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { CLEDDevice *this = (CLEDDevice *) construct(pCLEDDevice_class, exposedMask, self); if (NULL == this) { @@ -65,8 +69,12 @@ static SLresult IEngine_CreateVibraDevice(SLEngineItf self, SLObjectItf *pDevice *pDevice = NULL; unsigned exposedMask; const ClassTable *pCVibraDevice_class = objectIDtoClass(SL_OBJECTID_VIBRADEVICE); - result = checkInterfaces(pCVibraDevice_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pCVibraDevice_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCVibraDevice_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { CVibraDevice *this = (CVibraDevice *) construct(pCVibraDevice_class, exposedMask, self); if (NULL == this) { @@ -99,6 +107,7 @@ static SLresult IEngine_CreateAudioPlayer(SLEngineItf self, SLObjectItf *pPlayer *pPlayer = NULL; unsigned exposedMask; const ClassTable *pCAudioPlayer_class = objectIDtoClass(SL_OBJECTID_AUDIOPLAYER); + assert(NULL != pCAudioPlayer_class); result = checkInterfaces(pCAudioPlayer_class, numInterfaces, pInterfaceIds, pInterfaceRequired, &exposedMask); if (SL_RESULT_SUCCESS == result) { @@ -242,8 +251,12 @@ static SLresult IEngine_CreateAudioRecorder(SLEngineItf self, SLObjectItf *pReco *pRecorder = NULL; unsigned exposedMask; const ClassTable *pCAudioRecorder_class = objectIDtoClass(SL_OBJECTID_AUDIORECORDER); - result = checkInterfaces(pCAudioRecorder_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pCAudioRecorder_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCAudioRecorder_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { @@ -348,8 +361,12 @@ static SLresult IEngine_CreateMidiPlayer(SLEngineItf self, SLObjectItf *pPlayer, *pPlayer = NULL; unsigned exposedMask; const ClassTable *pCMidiPlayer_class = objectIDtoClass(SL_OBJECTID_MIDIPLAYER); - result = checkInterfaces(pCMidiPlayer_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pCMidiPlayer_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCMidiPlayer_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { CMidiPlayer *this = (CMidiPlayer *) construct(pCMidiPlayer_class, exposedMask, self); if (NULL == this) { @@ -383,8 +400,12 @@ static SLresult IEngine_CreateListener(SLEngineItf self, SLObjectItf *pListener, *pListener = NULL; unsigned exposedMask; const ClassTable *pCListener_class = objectIDtoClass(SL_OBJECTID_LISTENER); - result = checkInterfaces(pCListener_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pCListener_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCListener_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { CListener *this = (CListener *) construct(pCListener_class, exposedMask, self); if (NULL == this) { @@ -416,8 +437,12 @@ static SLresult IEngine_Create3DGroup(SLEngineItf self, SLObjectItf *pGroup, SLu *pGroup = NULL; unsigned exposedMask; const ClassTable *pC3DGroup_class = objectIDtoClass(SL_OBJECTID_3DGROUP); - result = checkInterfaces(pC3DGroup_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pC3DGroup_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pC3DGroup_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { C3DGroup *this = (C3DGroup *) construct(pC3DGroup_class, exposedMask, self); if (NULL == this) { @@ -449,6 +474,7 @@ static SLresult IEngine_CreateOutputMix(SLEngineItf self, SLObjectItf *pMix, SLu *pMix = NULL; unsigned exposedMask; const ClassTable *pCOutputMix_class = objectIDtoClass(SL_OBJECTID_OUTPUTMIX); + assert(NULL != pCOutputMix_class); result = checkInterfaces(pCOutputMix_class, numInterfaces, pInterfaceIds, pInterfaceRequired, &exposedMask); if (SL_RESULT_SUCCESS == result) { @@ -500,8 +526,12 @@ static SLresult IEngine_CreateMetadataExtractor(SLEngineItf self, SLObjectItf *p unsigned exposedMask; const ClassTable *pCMetadataExtractor_class = objectIDtoClass(SL_OBJECTID_METADATAEXTRACTOR); - result = checkInterfaces(pCMetadataExtractor_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask); + if (NULL == pCMetadataExtractor_class) { + result = SL_RESULT_FEATURE_UNSUPPORTED; + } else { + result = checkInterfaces(pCMetadataExtractor_class, numInterfaces, + pInterfaceIds, pInterfaceRequired, &exposedMask); + } if (SL_RESULT_SUCCESS == result) { CMetadataExtractor *this = (CMetadataExtractor *) construct(pCMetadataExtractor_class, exposedMask, self); @@ -545,7 +575,6 @@ static SLresult IEngine_QueryNumSupportedInterfaces(SLEngineItf self, { SL_ENTER_INTERFACE -#if USE_PROFILES & USE_PROFILES_BASE if (NULL == pNumSupportedInterfaces) { result = SL_RESULT_PARAMETER_INVALID; } else { @@ -574,9 +603,6 @@ static SLresult IEngine_QueryNumSupportedInterfaces(SLEngineItf self, result = SL_RESULT_SUCCESS; } } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif SL_LEAVE_INTERFACE; } @@ -587,7 +613,6 @@ static SLresult IEngine_QuerySupportedInterfaces(SLEngineItf self, { SL_ENTER_INTERFACE -#if USE_PROFILES & USE_PROFILES_BASE if (NULL == pInterfaceId) { result = SL_RESULT_PARAMETER_INVALID; } else { @@ -621,9 +646,6 @@ static SLresult IEngine_QuerySupportedInterfaces(SLEngineItf self, } } } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif SL_LEAVE_INTERFACE }; diff --git a/opensles/libopensles/MPH_to.c b/opensles/libopensles/MPH_to.c index 51556980..3a9dd147 100644 --- a/opensles/libopensles/MPH_to.c +++ b/opensles/libopensles/MPH_to.c @@ -39,6 +39,8 @@ // IObject is the first interface in a class, so the index for MPH_OBJECT must be zero. // Don't cross streams, otherwise bad things happen. + +#if USE_PROFILES & USE_PROFILE_GAME const signed char MPH_to_3DGroup[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -69,6 +71,7 @@ const signed char MPH_to_3DGroup[MPH_MAX] = { END #endif }; +#endif const signed char MPH_to_AudioPlayer[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS @@ -160,6 +163,7 @@ const signed char MPH_to_AudioPlayer[MPH_MAX] = { #endif }; +#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) const signed char MPH_to_AudioRecorder[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -208,6 +212,7 @@ const signed char MPH_to_AudioRecorder[MPH_MAX] = { END #endif }; +#endif const signed char MPH_to_Engine[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS @@ -261,6 +266,7 @@ const signed char MPH_to_Engine[MPH_MAX] = { #endif }; +#if USE_PROFILES & USE_PROFILES_OPTIONAL const signed char MPH_to_LEDDevice[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -284,7 +290,9 @@ const signed char MPH_to_LEDDevice[MPH_MAX] = { END #endif }; +#endif +#if USE_PROFILES & USE_PROFILE_GAME const signed char MPH_to_Listener[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -311,7 +319,9 @@ const signed char MPH_to_Listener[MPH_MAX] = { END #endif }; +#endif +#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) const signed char MPH_to_MetadataExtractor[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -339,7 +349,9 @@ const signed char MPH_to_MetadataExtractor[MPH_MAX] = { END #endif }; +#endif +#if USE_PROFILES & USE_PROFILE_GAME const signed char MPH_to_MidiPlayer[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -420,6 +432,7 @@ const signed char MPH_to_MidiPlayer[MPH_MAX] = { END #endif }; +#endif const signed char MPH_to_OutputMix[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS @@ -475,6 +488,7 @@ const signed char MPH_to_OutputMix[MPH_MAX] = { #endif }; +#if USE_PROFILES & USE_PROFILE_OPTIONAL const signed char MPH_to_Vibra[MPH_MAX] = { #ifdef USE_DESIGNATED_INITIALIZERS [0 ... MPH_MAX-1] = -1, @@ -498,3 +512,4 @@ const signed char MPH_to_Vibra[MPH_MAX] = { END #endif }; +#endif diff --git a/opensles/libopensles/OpenSLESUT.c b/opensles/libopensles/OpenSLESUT.c index 70ab75b7..2365f01b 100644 --- a/opensles/libopensles/OpenSLESUT.c +++ b/opensles/libopensles/OpenSLESUT.c @@ -159,3 +159,23 @@ const char *slesutResultToString(SLresult result) // note that SLresult is unsigned return result < SLESUT_RESULT_MAX ? slesutResultStrings[result] : "UNKNOWN"; } + + +/** \brief Convert an object ID to a string or NULL. */ + +const char *slesutObjectIDToString(SLuint32 objectID) +{ + static const char * const objectIDstrings[10] = { + "SL_OBJECTID_ENGINE", + "SL_OBJECTID_LEDDEVICE", + "SL_OBJECTID_VIBRADEVICE", + "SL_OBJECTID_AUDIOPLAYER", + "SL_OBJECTID_AUDIORECORDER", + "SL_OBJECTID_MIDIPLAYER", + "SL_OBJECTID_LISTENER", + "SL_OBJECTID_3DGROUP", + "SL_OBJECTID_OUTPUTMIX", + "SL_OBJECTID_METADATAEXTRACTOR" + }; + return (0x1001 <= objectID) && (objectID <= 0x100A) ? objectIDstrings[objectID - 0x1001] : NULL; +} diff --git a/opensles/libopensles/OpenSLESUT.h b/opensles/libopensles/OpenSLESUT.h index 4be6f424..486b58fa 100644 --- a/opensles/libopensles/OpenSLESUT.h +++ b/opensles/libopensles/OpenSLESUT.h @@ -27,6 +27,7 @@ extern "C" { extern const char * const slesutResultStrings[SLESUT_RESULT_MAX]; extern void slesutPrintIID(SLInterfaceID iid); extern const char *slesutResultToString(SLresult result); +extern const char *slesutObjectIDToString(SLuint32 objectID); #ifdef __cplusplus } diff --git a/opensles/libopensles/classes.c b/opensles/libopensles/classes.c index b9eb8584..14fc741c 100644 --- a/opensles/libopensles/classes.c +++ b/opensles/libopensles/classes.c @@ -18,6 +18,9 @@ #include "sles_allinclusive.h" + +#if USE_PROFILES & USE_PROFILES_GAME + // 3DGroup class static const struct iid_vtable _3DGroup_interfaces[INTERFACES_3DGroup] = { @@ -43,6 +46,9 @@ static const ClassTable C3DGroup_class = { C3DGroup_PreDestroy }; +#endif + + // AudioPlayer class static const struct iid_vtable AudioPlayer_interfaces[INTERFACES_AudioPlayer] = { @@ -103,6 +109,9 @@ static const ClassTable CAudioPlayer_class = { CAudioPlayer_PreDestroy }; + +#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) + // AudioRecorder class static const struct iid_vtable AudioRecorder_interfaces[INTERFACES_AudioRecorder] = { @@ -136,6 +145,9 @@ static const ClassTable CAudioRecorder_class = { CAudioRecorder_PreDestroy }; +#endif + + // Engine class static const struct iid_vtable Engine_interfaces[INTERFACES_Engine] = { @@ -172,6 +184,9 @@ static const ClassTable CEngine_class = { CEngine_PreDestroy }; + +#if USE_PROFILES & USE_PROFILES_OPTIONAL + // LEDDevice class static const struct iid_vtable LEDDevice_interfaces[INTERFACES_LEDDevice] = { @@ -194,6 +209,11 @@ static const ClassTable CLEDDevice_class = { NULL }; +#endif + + +#if USE_PROFILES & USE_PROFILES_GAME + // Listener class static const struct iid_vtable Listener_interfaces[INTERFACES_Listener] = { @@ -217,6 +237,11 @@ static const ClassTable CListener_class = { NULL }; +#endif + + +#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) + // MetadataExtractor class static const struct iid_vtable MetadataExtractor_interfaces[INTERFACES_MetadataExtractor] = { @@ -241,6 +266,11 @@ static const ClassTable CMetadataExtractor_class = { NULL }; +#endif + + +#if USE_PROFILES & USE_PROFILES_GAME + // MidiPlayer class static const struct iid_vtable MidiPlayer_interfaces[INTERFACES_MidiPlayer] = { @@ -290,6 +320,9 @@ static const ClassTable CMidiPlayer_class = { NULL }; +#endif + + // OutputMix class static const struct iid_vtable OutputMix_interfaces[INTERFACES_OutputMix] = { @@ -331,6 +364,9 @@ static const ClassTable COutputMix_class = { COutputMix_PreDestroy }; + +#if USE_PROFILES & USE_PROFILES_OPTIONAL + // Vibra class static const struct iid_vtable VibraDevice_interfaces[INTERFACES_VibraDevice] = { @@ -353,27 +389,55 @@ static const ClassTable CVibraDevice_class = { NULL }; -/* Map SL_OBJECTID to class */ +#endif + static const ClassTable * const classes[] = { // Do not change order of these entries; they are in numerical order &CEngine_class, +#if USE_PROFILES & USE_PROFILES_OPTIONAL &CLEDDevice_class, &CVibraDevice_class, +#else + NULL, + NULL, +#endif &CAudioPlayer_class, +#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) &CAudioRecorder_class, +#else + NULL, +#endif +#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_PHONE) &CMidiPlayer_class, +#else + NULL, +#endif +#if USE_PROFILES & USE_PROFILES_GAME &CListener_class, &C3DGroup_class, +#else + NULL, + NULL, +#endif &COutputMix_class, +#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) &CMetadataExtractor_class +#else + NULL +#endif }; + +/* \brief Map SL_OBJECTID to class or NULL if object ID not supported */ + const ClassTable *objectIDtoClass(SLuint32 objectID) { + // object ID is the engine and always present + assert(NULL != classes[0]); SLuint32 objectID0 = classes[0]->mObjectID; - if (objectID0 <= objectID && - classes[sizeof(classes)/sizeof(classes[0])-1]->mObjectID >= objectID) + if ((objectID0 <= objectID) && ((objectID0 + sizeof(classes)/sizeof(classes[0])) > objectID)) { return classes[objectID - objectID0]; + } return NULL; } diff --git a/opensles/libopensles/sles.c b/opensles/libopensles/sles.c index 77331d05..4c038be5 100644 --- a/opensles/libopensles/sles.c +++ b/opensles/libopensles/sles.c @@ -1112,6 +1112,7 @@ SLresult SLAPIENTRY slCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions, unsigned exposedMask; const ClassTable *pCEngine_class = objectIDtoClass(SL_OBJECTID_ENGINE); + assert(NULL != pCEngine_class); result = checkInterfaces(pCEngine_class, numInterfaces, pInterfaceIds, pInterfaceRequired, &exposedMask); if (SL_RESULT_SUCCESS != result) { diff --git a/opensles/tests/sandbox/Android.mk b/opensles/tests/sandbox/Android.mk index ee2cbcf0..189a6d72 100644 --- a/opensles/tests/sandbox/Android.mk +++ b/opensles/tests/sandbox/Android.mk @@ -66,6 +66,9 @@ LOCAL_SHARED_LIBRARIES := \ libutils \ libOpenSLES +LOCAL_STATIC_LIBRARIES := \ + libOpenSLESUT + ifeq ($(TARGET_OS),linux) LOCAL_CFLAGS += -DXP_UNIX endif @@ -73,3 +76,30 @@ endif LOCAL_MODULE:= slesTest_engine include $(BUILD_EXECUTABLE) + +# + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_C_INCLUDES:= \ + system/media/opensles/include + +LOCAL_SRC_FILES:= \ + object.c + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libOpenSLES + +LOCAL_STATIC_LIBRARIES := \ + libOpenSLESUT + +ifeq ($(TARGET_OS),linux) + LOCAL_CFLAGS += -DXP_UNIX +endif + +LOCAL_MODULE:= slesTest_object + +include $(BUILD_EXECUTABLE) diff --git a/opensles/tests/sandbox/object.c b/opensles/tests/sandbox/object.c new file mode 100644 index 00000000..2285ed76 --- /dev/null +++ b/opensles/tests/sandbox/object.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "SLES/OpenSLES.h" +#include "SLES/OpenSLESUT.h" + +int main(int arg, char **argv) +{ + SLresult result; + + printf("Create engine\n"); + SLObjectItf engineObject; + // create engine + result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); + assert(SL_RESULT_SUCCESS == result); + result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); + assert(SL_RESULT_SUCCESS == result); + SLEngineItf engineEngine; + result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); + assert(SL_RESULT_SUCCESS == result); + // loop through both valid and invalid object IDs + SLuint32 objectID; + for (objectID = 0x1000; objectID <= 0x100B; ++objectID) { + printf("object ID %lx", objectID); + const char *string = slesutObjectIDToString(objectID); + if (NULL != string) + printf(" (%s)", string); + printf(":\n"); + SLuint32 numSupportedInterfaces = 12345; + result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, objectID, + &numSupportedInterfaces); + if (SL_RESULT_FEATURE_UNSUPPORTED == result) { + printf(" unsupported\n"); + continue; + } + assert(SL_RESULT_SUCCESS == result); + printf("numSupportedInterfaces %lu\n", numSupportedInterfaces); + SLuint32 i; + for (i = 0; i < numSupportedInterfaces + 1; ++i) { + SLInterfaceID interfaceID; + result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, i, + &interfaceID); + if (i < numSupportedInterfaces) { + assert(SL_RESULT_SUCCESS == result); + printf(" interface %lu ", i); + slesutPrintIID(interfaceID); + } else { + assert(SL_RESULT_PARAMETER_INVALID == result); + } + } + } + return EXIT_SUCCESS; +} -- 2.11.0