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/* OutputMix implementation */
18
19#include "sles_allinclusive.h"
20
21
22static SLresult IOutputMix_GetDestinationOutputDeviceIDs(SLOutputMixItf self,
23   SLint32 *pNumDevices, SLuint32 *pDeviceIDs)
24{
25    SL_ENTER_INTERFACE
26
27    if (NULL == pNumDevices) {
28        result = SL_RESULT_PARAMETER_INVALID;
29    } else {
30        result = SL_RESULT_SUCCESS;
31        // The application can set pDeviceIDs == NULL in order to find out number of devices.
32        // Then the application can allocate a proper-sized device ID array and try again.
33        if (NULL != pDeviceIDs) {
34            if (1 > *pNumDevices) {
35                result = SL_RESULT_BUFFER_INSUFFICIENT;
36            } else {
37                pDeviceIDs[0] = SL_DEFAULTDEVICEID_AUDIOOUTPUT;
38            }
39        }
40        *pNumDevices = 1;
41    }
42
43    SL_LEAVE_INTERFACE
44}
45
46
47static SLresult IOutputMix_RegisterDeviceChangeCallback(SLOutputMixItf self,
48    slMixDeviceChangeCallback callback, void *pContext)
49{
50    SL_ENTER_INTERFACE
51
52    IOutputMix *thiz = (IOutputMix *) self;
53    interface_lock_exclusive(thiz);
54    thiz->mCallback = callback;
55    thiz->mContext = pContext;
56    interface_unlock_exclusive(thiz);
57    result = SL_RESULT_SUCCESS;
58
59    SL_LEAVE_INTERFACE
60}
61
62
63static SLresult IOutputMix_ReRoute(SLOutputMixItf self, SLint32 numOutputDevices,
64    SLuint32 *pOutputDeviceIDs)
65{
66    SL_ENTER_INTERFACE
67
68    if ((1 != numOutputDevices) || (NULL == pOutputDeviceIDs)) {
69        result = SL_RESULT_PARAMETER_INVALID;
70    } else {
71        switch (pOutputDeviceIDs[0]) {
72        case SL_DEFAULTDEVICEID_AUDIOOUTPUT:
73        case DEVICE_ID_HEADSET:
74            result = SL_RESULT_SUCCESS;
75            break;
76        default:
77            result = SL_RESULT_PARAMETER_INVALID;
78            break;
79        }
80    }
81
82    SL_LEAVE_INTERFACE
83}
84
85
86static const struct SLOutputMixItf_ IOutputMix_Itf = {
87    IOutputMix_GetDestinationOutputDeviceIDs,
88    IOutputMix_RegisterDeviceChangeCallback,
89    IOutputMix_ReRoute
90};
91
92void IOutputMix_init(void *self)
93{
94    IOutputMix *thiz = (IOutputMix *) self;
95    thiz->mItf = &IOutputMix_Itf;
96    thiz->mCallback = NULL;
97    thiz->mContext = NULL;
98}
99