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 /* AndroidConfiguration implementation */
18
19 #include "sles_allinclusive.h"
20
21
IAndroidConfiguration_SetConfiguration(SLAndroidConfigurationItf self,const SLchar * configKey,const void * pConfigValue,SLuint32 valueSize)22 static SLresult IAndroidConfiguration_SetConfiguration(SLAndroidConfigurationItf self,
23 const SLchar *configKey,
24 const void *pConfigValue,
25 SLuint32 valueSize)
26 {
27 SL_ENTER_INTERFACE
28
29 // object-specific code will check that valueSize is large enough for the key
30 if (NULL == configKey || NULL == pConfigValue || valueSize == 0) {
31 result = SL_RESULT_PARAMETER_INVALID;
32
33 } else {
34 IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
35 interface_lock_exclusive(thiz);
36
37 // route configuration to the appropriate object
38 switch (IObjectToObjectID((thiz)->mThis)) {
39 case SL_OBJECTID_AUDIORECORDER:
40 SL_LOGV("SetConfiguration issued for AudioRecorder key=%s valueSize=%u",
41 configKey, valueSize);
42 result = android_audioRecorder_setConfig((CAudioRecorder *) thiz->mThis, configKey,
43 pConfigValue, valueSize);
44 break;
45 case SL_OBJECTID_AUDIOPLAYER:
46 SL_LOGV("SetConfiguration issued for AudioPlayer key=%s valueSize=%u",
47 configKey, valueSize);
48 result = android_audioPlayer_setConfig((CAudioPlayer *) thiz->mThis, configKey,
49 pConfigValue, valueSize);
50 break;
51 default:
52 result = SL_RESULT_FEATURE_UNSUPPORTED;
53 break;
54 }
55
56 interface_unlock_exclusive(thiz);
57 }
58
59 SL_LEAVE_INTERFACE
60 }
61
62
IAndroidConfiguration_GetConfiguration(SLAndroidConfigurationItf self,const SLchar * configKey,SLuint32 * pValueSize,void * pConfigValue)63 static SLresult IAndroidConfiguration_GetConfiguration(SLAndroidConfigurationItf self,
64 const SLchar *configKey,
65 SLuint32 *pValueSize,
66 void *pConfigValue)
67 {
68 SL_ENTER_INTERFACE
69
70 // non-NULL pValueSize is required, but a NULL pConfigValue is allowed, so
71 // that we can report the actual value size without returning the value itself
72 if (NULL == configKey || NULL == pValueSize) {
73 result = SL_RESULT_PARAMETER_INVALID;
74 } else {
75 IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
76 interface_lock_exclusive(thiz);
77
78 // route configuration request to the appropriate object
79 switch (IObjectToObjectID((thiz)->mThis)) {
80 case SL_OBJECTID_AUDIORECORDER:
81 result = android_audioRecorder_getConfig((CAudioRecorder *) thiz->mThis, configKey,
82 pValueSize, pConfigValue);
83 break;
84 case SL_OBJECTID_AUDIOPLAYER:
85 result = android_audioPlayer_getConfig((CAudioPlayer *) thiz->mThis, configKey,
86 pValueSize, pConfigValue);
87 default:
88 result = SL_RESULT_FEATURE_UNSUPPORTED;
89 break;
90 }
91
92 interface_unlock_exclusive(thiz);
93 }
94
95 SL_LEAVE_INTERFACE
96 }
97
98
99 static const struct SLAndroidConfigurationItf_ IAndroidConfiguration_Itf = {
100 IAndroidConfiguration_SetConfiguration,
101 IAndroidConfiguration_GetConfiguration
102 };
103
IAndroidConfiguration_init(void * self)104 void IAndroidConfiguration_init(void *self)
105 {
106 IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
107 thiz->mItf = &IAndroidConfiguration_Itf;
108 }
109