• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  // Test dynamic interface management
18  
19  #include <assert.h>
20  #include <math.h>
21  #include <stdio.h>
22  #include <stdlib.h>
23  
24  #include <SLES/OpenSLES.h>
25  #ifdef ANDROID
26  #include <SLES/OpenSLES_Android.h>
27  #endif
28  
29  int main(int argc, char **argv)
30  {
31      if (argc != 1) {
32          fprintf(stderr, "usage: %s\n", argv[0]);
33          return EXIT_FAILURE;
34      }
35  
36      SLresult result;
37      SLObjectItf engineObject;
38  
39      // create engine
40      result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
41      assert(SL_RESULT_SUCCESS == result);
42      SLEngineItf engineEngine;
43      result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
44      assert(SL_RESULT_SUCCESS == result);
45      result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
46      assert(SL_RESULT_SUCCESS == result);
47  
48      // create output mix
49      SLObjectItf outputMixObject;
50      result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL);
51      assert(SL_RESULT_SUCCESS == result);
52  
53      // get the dynamic interface management interface for output mix, before realize
54      SLDynamicInterfaceManagementItf outputMixDIM;
55      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT,
56              &outputMixDIM);
57      assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
58      assert(NULL == outputMixDIM);
59  
60      // realize output mix
61      result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
62      assert(SL_RESULT_SUCCESS == result);
63  
64      // get the dynamic interface management interface for output mix, after realize
65      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT,
66              &outputMixDIM);
67      assert(SL_RESULT_SUCCESS == result);
68      assert(NULL != outputMixDIM);
69  
70      // register callback
71      result = (*outputMixDIM)->RegisterCallback(outputMixDIM, NULL, NULL);
72      assert(SL_RESULT_SUCCESS == result);
73  
74      // get environmental reverb interface, before add or resume
75      SLEnvironmentalReverbItf outputMixEnvironmentalReverb;
76      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
77              &outputMixEnvironmentalReverb);
78      assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
79      assert(NULL == outputMixEnvironmentalReverb);
80  
81      // resume environmental reverb interface
82      result = (*outputMixDIM)->ResumeInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB,
83              SL_BOOLEAN_FALSE);
84      assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
85  
86      // get environmental reverb interface, after resume but before add
87      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
88              &outputMixEnvironmentalReverb);
89      assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
90      assert(NULL == outputMixEnvironmentalReverb);
91  
92      // add environmental reverb interface
93      result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB,
94              SL_BOOLEAN_FALSE);
95      assert(SL_RESULT_SUCCESS == result);
96  
97      // get environmental reverb interface, after add
98      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
99              &outputMixEnvironmentalReverb);
100      assert(SL_RESULT_SUCCESS == result);
101      assert(NULL != outputMixEnvironmentalReverb);
102  
103      // add environmental reverb interface again
104      result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB,
105              SL_BOOLEAN_FALSE);
106      assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
107  
108      // resume environmental reverb interface
109      result = (*outputMixDIM)->ResumeInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB,
110              SL_BOOLEAN_FALSE);
111      assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
112  
113      // remove environmental reverb interface (FIXME not yet implemented)
114      result = (*outputMixDIM)->RemoveInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB);
115      assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED == result));
116  
117      // FIXME once remove is implemented we can try this
118      if (SL_RESULT_SUCCESS == result) {
119          result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
120                  &outputMixEnvironmentalReverb);
121          assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
122          assert(NULL == outputMixEnvironmentalReverb);
123          result = (*outputMixDIM)->RemoveInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB);
124          assert(SL_RESULT_PRECONDITIONS_VIOLATED == result);
125          result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB,
126                  SL_BOOLEAN_FALSE);
127          assert(SL_RESULT_SUCCESS == result);
128          result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
129                  &outputMixEnvironmentalReverb);
130          assert(SL_RESULT_SUCCESS == result);
131          assert(NULL != outputMixEnvironmentalReverb);
132      }
133  
134      // get non-sensical play interface, before add
135      SLPlayItf outputMixPlay;
136      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PLAY, &outputMixPlay);
137      assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
138      assert(NULL == outputMixPlay);
139  
140      // add play interface
141      result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_PLAY, SL_BOOLEAN_FALSE);
142      assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
143  
144      // get play interface should still fail
145      result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PLAY, &outputMixPlay);
146      assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
147      assert(NULL == outputMixPlay);
148  
149      // destroy output mix
150      (*outputMixObject)->Destroy(outputMixObject);
151  
152      // destroy engine
153      (*engineObject)->Destroy(engineObject);
154  
155      return EXIT_SUCCESS;
156  }
157