Home | History | Annotate | Download | only in libopensles
      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 
     22 static 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 
     47 static 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 
     63 static 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 #if 0 // FIXME These OEM-specific constants should be configurable
     74         case DEVICE_ID_HEADSET:
     75         case DEVICE_ID_HANDSFREE:
     76 #endif
     77             result = SL_RESULT_SUCCESS;
     78             break;
     79         default:
     80             result = SL_RESULT_PARAMETER_INVALID;
     81             break;
     82         }
     83     }
     84 
     85     SL_LEAVE_INTERFACE
     86 }
     87 
     88 
     89 static const struct SLOutputMixItf_ IOutputMix_Itf = {
     90     IOutputMix_GetDestinationOutputDeviceIDs,
     91     IOutputMix_RegisterDeviceChangeCallback,
     92     IOutputMix_ReRoute
     93 };
     94 
     95 void IOutputMix_init(void *self)
     96 {
     97     IOutputMix *this = (IOutputMix *) self;
     98     this->mItf = &IOutputMix_Itf;
     99     this->mCallback = NULL;
    100     this->mContext = NULL;
    101 }
    102