161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten/*
261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Copyright (C) 2010 The Android Open Source Project
361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Licensed under the Apache License, Version 2.0 (the "License");
561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * you may not use this file except in compliance with the License.
661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * You may obtain a copy of the License at
761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *      http://www.apache.org/licenses/LICENSE-2.0
961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
1061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Unless required by applicable law or agreed to in writing, software
1161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * distributed under the License is distributed on an "AS IS" BASIS,
1261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * See the License for the specific language governing permissions and
1461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * limitations under the License.
1561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten */
1661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
1761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten/* DeviceVolume implementation */
1861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
1961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten#include "sles_allinclusive.h"
2061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
21ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
22d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kastenstatic SLresult IDeviceVolume_GetVolumeScale(SLDeviceVolumeItf self, SLuint32 deviceID,
23d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    SLint32 *pMinValue, SLint32 *pMaxValue, SLboolean *pIsMillibelScale)
2461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
25ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_ENTER_INTERFACE
26ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
27d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    switch (deviceID) {
28d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case SL_DEFAULTDEVICEID_AUDIOINPUT:
29d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case SL_DEFAULTDEVICEID_AUDIOOUTPUT:
30d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case DEVICE_ID_HEADSET:
31d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case DEVICE_ID_HANDSFREE:
32ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        if (NULL != pMinValue)
33ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            *pMinValue = 0;
34ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        if (NULL != pMaxValue)
35ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            *pMaxValue = 10;
36ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        if (NULL != pIsMillibelScale)
37ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            *pIsMillibelScale = SL_BOOLEAN_FALSE;
38ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        result = SL_RESULT_SUCCESS;
39d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten        break;
40d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    default:
41ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        result = SL_RESULT_PARAMETER_INVALID;
42ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        break;
43d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    }
44ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
45ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_LEAVE_INTERFACE
4661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
4761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
48ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
49d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kastenstatic SLresult IDeviceVolume_SetVolume(SLDeviceVolumeItf self, SLuint32 deviceID, SLint32 volume)
5061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
51ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_ENTER_INTERFACE
52ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
5361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    switch (deviceID) {
547a79f519d89eb0e1a5b3f4005484b16d6854d7e2Glenn Kasten    // These are treated same as generic audio output for now
55d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case DEVICE_ID_HEADSET:
56d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    case DEVICE_ID_HANDSFREE:
57a438eb1cf1ae602afab00336528dd230bd929206Glenn Kasten        deviceID = SL_DEFAULTDEVICEID_AUDIOOUTPUT;
58ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        // fall through
59ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    case SL_DEFAULTDEVICEID_AUDIOINPUT:
60ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    case SL_DEFAULTDEVICEID_AUDIOOUTPUT:
61ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        {
62bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten        IDeviceVolume *thiz = (IDeviceVolume *) self;
63bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten        interface_lock_poke(thiz);
64bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten        thiz->mVolume[~deviceID] = volume;
65bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten        interface_unlock_poke(thiz);
66ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        result = SL_RESULT_SUCCESS;
67ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        }
68a438eb1cf1ae602afab00336528dd230bd929206Glenn Kasten        break;
6961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    default:
70ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        result = SL_RESULT_PARAMETER_INVALID;
71ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        break;
7261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    }
73ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
74ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_LEAVE_INTERFACE
7561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
7661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
77ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
78e5bf0d2c9531a7064eb3ddcafaf93ac1b0974037Glenn Kastenstatic SLresult IDeviceVolume_GetVolume(SLDeviceVolumeItf self, SLuint32 deviceID, SLint32 *pVolume)
7961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
80ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_ENTER_INTERFACE
81ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
82ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    if (NULL == pVolume) {
83ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        result = SL_RESULT_PARAMETER_INVALID;
84ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    } else {
85ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        switch (deviceID) {
867a79f519d89eb0e1a5b3f4005484b16d6854d7e2Glenn Kasten        // These are treated same as generic audio output for now
87ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        case DEVICE_ID_HEADSET:
88ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        case DEVICE_ID_HANDSFREE:
89ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            deviceID = SL_DEFAULTDEVICEID_AUDIOOUTPUT;
90ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            // fall through
91ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        case SL_DEFAULTDEVICEID_AUDIOINPUT:
92ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        case SL_DEFAULTDEVICEID_AUDIOOUTPUT:
93ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            {
94bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten            IDeviceVolume *thiz = (IDeviceVolume *) self;
95bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten            interface_lock_peek(thiz);
96bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten            SLint32 volume = thiz->mVolume[~deviceID];
97bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten            interface_unlock_peek(thiz);
98ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            *pVolume = volume;
99ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            result = SL_RESULT_SUCCESS;
100ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            }
101ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            break;
102ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        default:
103ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            result = SL_RESULT_PARAMETER_INVALID;
104ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten            break;
105ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten        }
10661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    }
107ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
108ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten    SL_LEAVE_INTERFACE
10961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
11061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
111ed46c29d6a09112dbbf584c82953f63289596fd6Glenn Kasten
11261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenstatic const struct SLDeviceVolumeItf_ IDeviceVolume_Itf = {
11361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IDeviceVolume_GetVolumeScale,
11461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IDeviceVolume_SetVolume,
11561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IDeviceVolume_GetVolume
11661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten};
11761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
11861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenvoid IDeviceVolume_init(void *self)
11961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
120bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten    IDeviceVolume *thiz = (IDeviceVolume *) self;
121bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten    thiz->mItf = &IDeviceVolume_Itf;
122a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten    unsigned i;
123a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten    for (i = 0; i < MAX_DEVICE; ++i) {
124bcc5c7225e3b7a1dbf2e9e830987f69167acf06fGlenn Kasten        thiz->mVolume[i] = 10;
125a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten    }
12661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
127