outputmix.c revision 7126c25d7c037e5086216cf540ecf40779c3585a
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 17// output mix interface tests 18 19#include "SLES/OpenSLES.h" 20#include "SLES/OpenSLESUT.h" 21#include <assert.h> 22#include <stdio.h> 23#include <stdlib.h> 24#include <string.h> 25 26int main(int argc, char **argv) 27{ 28 // create engine 29 SLObjectItf engineObject; 30 SLresult result; 31 result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); 32 assert(SL_RESULT_SUCCESS == result); 33 printf("Engine object %p\n", engineObject); 34 // realize engine 35 result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); 36 assert(SL_RESULT_SUCCESS == result); 37 // get engine interface 38 SLEngineItf engineEngine; 39 result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 40 assert(SL_RESULT_SUCCESS == result); 41 // query supported interfaces on output mix object ID and display their IDs 42 SLuint32 numSupportedInterfaces; 43 result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, SL_OBJECTID_OUTPUTMIX, 44 &numSupportedInterfaces); 45 assert(SL_RESULT_SUCCESS == result); 46 printf("Output mix supports %lu interfaces:\n", numSupportedInterfaces); 47 SLuint32 i; 48 for (i = 0; i < numSupportedInterfaces; ++i) { 49 SLInterfaceID interfaceID; 50 result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, SL_OBJECTID_OUTPUTMIX, i, 51 &interfaceID); 52 assert(SL_RESULT_SUCCESS == result); 53 printf(" [%lu] = ", i); 54 slesutPrintIID(interfaceID); 55 } 56 // create output mix, with no place to put the new object 57 result = (*engineEngine)->CreateOutputMix(engineEngine, NULL, 0, NULL, NULL); 58 assert(SL_RESULT_PARAMETER_INVALID == result); 59 // create output mix, requesting no explicit interfaces 60 SLObjectItf outputMixObject; 61 result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); 62 assert(SL_RESULT_SUCCESS == result); 63 printf("Output mix object %p\n", outputMixObject); 64 // get object interface before realization 65 SLObjectItf outputMixObject2; 66 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, &outputMixObject2); 67 assert(SL_RESULT_SUCCESS == result); 68 assert(outputMixObject2 == outputMixObject); 69 // get any other interface before realization should fail 70 SLOutputMixItf outputMixOutputMix; 71 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, 72 &outputMixOutputMix); 73 assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); 74 // realize the output mix 75 result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); 76 assert(SL_RESULT_SUCCESS == result); 77 // get each expected implicit interface 78 outputMixObject2 = NULL; 79 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, &outputMixObject2); 80 assert(SL_RESULT_SUCCESS == result); 81 assert(outputMixObject2 == outputMixObject); 82 SLDynamicInterfaceManagementItf outputMixDynamicInterfaceManagement; 83 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, 84 &outputMixDynamicInterfaceManagement); 85 assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); 86 if (SL_RESULT_SUCCESS == result) { 87 printf("Output mix supports dynamic interface management\n"); 88 } else { 89 printf("Output mix does not support dynamic interface management\n"); 90 } 91 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, 92 &outputMixOutputMix); 93 assert(SL_RESULT_SUCCESS == result); 94 // get explicit and optional interfaces should fail since not requested at creation 95 SLEnvironmentalReverbItf outputMixEnvironmentalReverb; 96 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, 97 &outputMixEnvironmentalReverb); 98 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 99 SLEqualizerItf outputMixEqualizer; 100 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_EQUALIZER, 101 &outputMixEqualizer); 102 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 103 SLPresetReverbItf outputMixPresetReverb; 104 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PRESETREVERB, 105 &outputMixPresetReverb); 106 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 107 SLVirtualizerItf outputMixVirtualizer; 108 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VIRTUALIZER, 109 &outputMixVirtualizer); 110 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 111 SLVolumeItf outputMixVolume; 112 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VOLUME, 113 &outputMixVolume); 114 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 115 SLBassBoostItf outputMixBassBoost; 116 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_BASSBOOST, 117 &outputMixBassBoost); 118 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 119 SLVisualizationItf outputMixVisualization; 120 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VISUALIZATION, 121 &outputMixVisualization); 122 assert(SL_RESULT_FEATURE_UNSUPPORTED == result); 123 // destroy output mix 124 (*outputMixObject)->Destroy(outputMixObject); 125 // re-create output mix, this time requesting implicit interfaces as "hard" requirements (must 126 // be there), and explicit interfaces as "soft" requirements (OK if not available) 127 SLInterfaceID ids[10] = {SL_IID_OBJECT, SL_IID_DYNAMICINTERFACEMANAGEMENT, SL_IID_OUTPUTMIX, 128 SL_IID_ENVIRONMENTALREVERB, SL_IID_EQUALIZER, SL_IID_PRESETREVERB, SL_IID_VIRTUALIZER, 129 SL_IID_VOLUME, SL_IID_BASSBOOST, SL_IID_VISUALIZATION}; 130 SLboolean req[10] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE /*SL_BOOLEAN_TRUE*/, SL_BOOLEAN_TRUE, 131 SL_BOOLEAN_TRUE/*FALSE*/, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, 132 SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE}; 133 result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 10, ids, req); 134 assert(SL_RESULT_SUCCESS == result); 135 printf("Output mix object %p\n", outputMixObject); 136 // realize the output mix 137 result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); 138 assert(SL_RESULT_SUCCESS == result); 139 // get implicit interfaces 140 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, 141 &outputMixObject2); 142 assert(SL_RESULT_SUCCESS == result); 143 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, 144 &outputMixDynamicInterfaceManagement); 145 assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); 146 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, 147 &outputMixOutputMix); 148 assert(SL_RESULT_SUCCESS == result); 149 // get explicit and optional interfaces should succeed since they were requested at creation 150 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, 151 &outputMixEnvironmentalReverb); 152 assert(SL_RESULT_SUCCESS == result); 153 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_EQUALIZER, 154 &outputMixEqualizer); 155 assert(SL_RESULT_SUCCESS == result); 156 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PRESETREVERB, 157 &outputMixPresetReverb); 158 assert(SL_RESULT_SUCCESS == result); 159 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VIRTUALIZER, 160 &outputMixVirtualizer); 161 assert(SL_RESULT_SUCCESS == result); 162 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VOLUME, 163 &outputMixVolume); 164 assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); 165 if (SL_RESULT_SUCCESS == result) { 166 printf("Output mix supports volume\n"); 167 } else { 168 printf("Output mix does not support volume\n"); 169 } 170 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_BASSBOOST, 171 &outputMixBassBoost); 172 assert(SL_RESULT_SUCCESS == result); 173 result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VISUALIZATION, 174 &outputMixVisualization); 175 assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); 176 if (SL_RESULT_SUCCESS == result) { 177 printf("Output mix supports visualization\n"); 178 } else { 179 printf("Output mix does not support visualization\n"); 180 } 181 // use the OutputMix interface on output mix object, in order to get code coverage 182 SLint32 numDevices = 1; 183 SLuint32 deviceIDs[1]; 184 result = (*outputMixOutputMix)->GetDestinationOutputDeviceIDs(outputMixOutputMix, &numDevices, 185 deviceIDs); 186 assert(SL_RESULT_SUCCESS == result); 187 assert(1 == numDevices); 188 assert(SL_DEFAULTDEVICEID_AUDIOOUTPUT == deviceIDs[0]); 189 result = (*outputMixOutputMix)->RegisterDeviceChangeCallback(outputMixOutputMix, NULL, NULL); 190 assert(SL_RESULT_SUCCESS == result); 191 result = (*outputMixOutputMix)->ReRoute(outputMixOutputMix, 1, deviceIDs); 192 assert(SL_RESULT_SUCCESS == result); 193 // destroy output mix 194 (*outputMixObject)->Destroy(outputMixObject); 195 // destroy engine 196 (*engineObject)->Destroy(engineObject); 197 return EXIT_SUCCESS; 198} 199