IOutputMix.c revision 262059f71a68edc5e510427c63f5f1623d3672a8
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 *this = (IOutputMix *) self; 53 interface_lock_exclusive(this); 54 this->mCallback = callback; 55 this->mContext = pContext; 56 interface_unlock_exclusive(this); 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 result = SL_RESULT_SUCCESS; 74 break; 75 default: 76 result = SL_RESULT_PARAMETER_INVALID; 77 break; 78 } 79 } 80 81 SL_LEAVE_INTERFACE 82} 83 84 85static const struct SLOutputMixItf_ IOutputMix_Itf = { 86 IOutputMix_GetDestinationOutputDeviceIDs, 87 IOutputMix_RegisterDeviceChangeCallback, 88 IOutputMix_ReRoute 89}; 90 91void IOutputMix_init(void *self) 92{ 93 IOutputMix *this = (IOutputMix *) self; 94 this->mItf = &IOutputMix_Itf; 95 this->mCallback = NULL; 96 this->mContext = NULL; 97} 98