1 /*
2  * Copyright (C) 2015 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 #include <SLES/OpenSLES.h>
18 #include "channels.h"
19 
20 // Return an OpenSL ES channel mask, as used in SLDataFormat_PCM.channelMask
channelCountToMask(unsigned channelCount)21 SLuint32 channelCountToMask(unsigned channelCount)
22 {
23     // FIXME channel mask is not yet implemented by Stagefright, so use a reasonable default
24     //       that is computed from the channel count
25     switch (channelCount) {
26     case 1:
27         // see explanation in data.c re: default channel mask for mono
28         return SL_SPEAKER_FRONT_LEFT;
29     case 2:
30         return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
31     // Android-specific
32     case 3:
33         return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
34     case 4:
35         return SL_ANDROID_SPEAKER_QUAD;
36     case 5:
37         return SL_ANDROID_SPEAKER_QUAD | SL_SPEAKER_FRONT_CENTER;
38     case 6:
39         return SL_ANDROID_SPEAKER_5DOT1;
40     case 7:
41         return SL_ANDROID_SPEAKER_5DOT1 | SL_SPEAKER_BACK_CENTER;
42     case 8:
43         return SL_ANDROID_SPEAKER_7DOT1;
44     // FIXME FCC_8
45     default:
46         return UNKNOWN_CHANNELMASK;
47     }
48 }
49