IAndroidConfiguration.c revision a8179ea15c4ff78db589d742b135649f0eda7ef2
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
22static SLresult IAndroidConfiguration_SetConfiguration(SLAndroidConfigurationItf self,
23        const SLchar *configKey,
24        const void *pConfigValue,
25        SLuint32 valueSize)
26{
27    SL_ENTER_INTERFACE
28
29    IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
30
31    interface_lock_exclusive(thiz);
32
33    // route configuration to the appropriate object
34    if (SL_OBJECTID_AUDIORECORDER == IObjectToObjectID((thiz)->mThis)) {
35        SL_LOGV("SetConfiguration issued for AudioRecorder key=%s valueSize=%u",
36                configKey, valueSize);
37        result = android_audioRecorder_setConfig((CAudioRecorder *) thiz->mThis, configKey,
38                pConfigValue, valueSize);
39    } else if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID((thiz)->mThis)) {
40        SL_LOGV("SetConfiguration issued for AudioPlayer key=%s valueSize=%u",
41                configKey, valueSize);
42        result = android_audioPlayer_setConfig((CAudioPlayer *) thiz->mThis, configKey,
43                pConfigValue, valueSize);
44    } else {
45        result = SL_RESULT_PARAMETER_INVALID;
46    }
47
48    interface_unlock_exclusive(thiz);
49
50    SL_LEAVE_INTERFACE
51}
52
53
54static SLresult IAndroidConfiguration_GetConfiguration(SLAndroidConfigurationItf self,
55        const SLchar *configKey,
56        SLuint32 *pValueSize,
57        void *pConfigValue)
58{
59    SL_ENTER_INTERFACE
60
61    // having value size is required, but pConfigValue being NULL is allowed to allow properties
62    // to report their actual value size (if applicable)
63    if (NULL == pValueSize) {
64        result = SL_RESULT_PARAMETER_INVALID;
65    } else {
66        IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
67
68        interface_lock_exclusive(thiz);
69
70        // route configuration request to the appropriate object
71        if (SL_OBJECTID_AUDIORECORDER == IObjectToObjectID((thiz)->mThis)) {
72            result = android_audioRecorder_getConfig((CAudioRecorder *) thiz->mThis, configKey,
73                    pValueSize, pConfigValue);
74        } else if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID((thiz)->mThis)) {
75            result = android_audioPlayer_getConfig((CAudioPlayer *) thiz->mThis, configKey,
76                    pValueSize, pConfigValue);
77        } else {
78            result = SL_RESULT_PARAMETER_INVALID;
79        }
80
81        interface_unlock_exclusive(thiz);
82    }
83
84    SL_LEAVE_INTERFACE
85}
86
87
88static const struct SLAndroidConfigurationItf_ IAndroidConfiguration_Itf = {
89    IAndroidConfiguration_SetConfiguration,
90    IAndroidConfiguration_GetConfiguration
91};
92
93void IAndroidConfiguration_init(void *self)
94{
95    IAndroidConfiguration *thiz = (IAndroidConfiguration *) self;
96    thiz->mItf = &IAndroidConfiguration_Itf;
97}
98