slesTestEffectCapabilities.cpp revision 01e9f5fa4698856f92bcfd88188ee4c8397b22db
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#define LOG_NDEBUG 0
18#define LOG_TAG "slesTest_virtualizer"
19
20#include <utils/Log.h>
21#include <getopt.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#include <unistd.h>
26#include <sys/time.h>
27#include <fcntl.h>
28
29#include "SLES/OpenSLES.h"
30#include "SLES/OpenSLES_Android.h"
31
32
33#define MAX_NUMBER_INTERFACES 3
34
35#define GUID_DISPLAY_LENGTH 35
36#define FX_NAME_LENGTH 64
37
38static int testMode;
39//-----------------------------------------------------------------
40/* Exits the application if an error is encountered */
41#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__)
42
43void ExitOnErrorFunc( SLresult result , int line)
44{
45    if (SL_RESULT_SUCCESS != result) {
46        fprintf(stderr, "%lu error code encountered at line %d, exiting\n", result, line);
47        exit(1);
48    }
49}
50
51//-----------------------------------------------------------------
52void guidToString(const SLInterfaceID guid, char *str) {
53    if ((NULL == guid) || (NULL == str)) {
54        return;
55    }
56    snprintf(str, GUID_DISPLAY_LENGTH, "%08lx-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
57            guid->time_low,
58            guid->time_mid,
59            guid->time_hi_and_version,
60            guid->clock_seq,
61            guid->node[0],
62            guid->node[1],
63            guid->node[2],
64            guid->node[3],
65            guid->node[4],
66            guid->node[5]);
67}
68
69//-----------------------------------------------------------------
70
71/* Query available effects on Android  */
72void TestGenericFxCapabilities(  )
73{
74
75    SLresult    result;
76    SLObjectItf sl;
77
78    /* ------------------------------------------------------ */
79    /* Engine configuration and creation */
80
81    SLEngineOption EngineOption[] = {
82            {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE}
83    };
84
85    SLboolean required[MAX_NUMBER_INTERFACES];
86    SLInterfaceID iidArray[MAX_NUMBER_INTERFACES];
87
88    /* Initialize arrays required[] and iidArray[] */
89    for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) {
90        required[i] = SL_BOOLEAN_FALSE;
91        iidArray[i] = SL_IID_NULL;
92    }
93
94    iidArray[0] = SL_IID_ANDROIDEFFECTCAPABILITIES;
95    required[0] = SL_BOOLEAN_TRUE;
96
97
98    result = slCreateEngine( &sl, 1, EngineOption, 1, iidArray, required);
99    ExitOnError(result);
100
101    /* Realizing the SL Engine in synchronous mode. */
102    result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE);
103    ExitOnError(result);
104
105
106    SLEngineItf EngineItf;
107    SLAndroidEffectCapabilitiesItf EffectLibItf;
108
109    /* Get the SL Engine interface which is implicit */
110    result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf);
111    ExitOnError(result);
112
113    /* Get the Android Effect Capabilities interface */
114    result = (*sl)->GetInterface(sl, SL_IID_ANDROIDEFFECTCAPABILITIES, (void*)&EffectLibItf);
115    ExitOnError(result);
116
117    /* ------------------------------------------------------ */
118    /* Query the effect library */
119
120    SLuint32 nbEffects = 0;
121    result = (*EffectLibItf)->QueryNumEffects(EffectLibItf, &nbEffects);
122    ExitOnError(result);
123    fprintf(stdout, "Effect library contains %ld effects:\n", nbEffects);
124
125    SLchar effectName[FX_NAME_LENGTH];
126    SLuint16 effectNameLength = FX_NAME_LENGTH;
127    char typeString[GUID_DISPLAY_LENGTH];
128    char implString[GUID_DISPLAY_LENGTH];
129
130    SLInterfaceID effectType, effectImplementation;
131    for (SLuint32 i = 0 ; i < nbEffects ; i++ ) {
132        fprintf(stdout,"- effect %ld: ", i);
133        result = (*EffectLibItf)->QueryEffect(EffectLibItf, i,
134                &effectType, &effectImplementation, effectName, &effectNameLength);
135        ExitOnError(result);
136        guidToString(effectType, typeString);
137        guidToString(effectImplementation, implString);
138        fprintf(stdout, "type = %s impl = %s name = %s \n", typeString, implString, effectName);
139    }
140
141    /* Shutdown OpenSL ES */
142     (*sl)->Destroy(sl);
143}
144
145//-----------------------------------------------------------------
146int main(int argc, char* const argv[])
147{
148    LOGV("Starting %s\n", argv[0]);
149
150    SLresult    result;
151    SLObjectItf sl;
152
153    fprintf(stdout, "OpenSL ES test %s: exercises SLAndroidEffectCapabilitiesItf.\n", argv[0]);
154
155    TestGenericFxCapabilities();
156
157    return 0;
158}
159