1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_MEDIA_AUDIOFORMAT_H
#define ANDROID_MEDIA_AUDIOFORMAT_H
#include <system/audio.h>
// keep these values in sync with AudioFormat.java
#define ENCODING_PCM_16BIT 2
#define ENCODING_PCM_8BIT 3
#define ENCODING_PCM_FLOAT 4
#define ENCODING_AC3 5
#define ENCODING_E_AC3 6
#define ENCODING_DTS 7
#define ENCODING_DTS_HD 8
#define ENCODING_MP3 9
#define ENCODING_AAC_LC 10
#define ENCODING_AAC_HE_V1 11
#define ENCODING_AAC_HE_V2 12
#define ENCODING_IEC61937 13
#define ENCODING_INVALID 0
#define ENCODING_DEFAULT 1
#define CHANNEL_INVALID 0
#define CHANNEL_OUT_DEFAULT 1
static inline audio_format_t audioFormatToNative(int audioFormat)
{
switch (audioFormat) {
case ENCODING_PCM_16BIT:
return AUDIO_FORMAT_PCM_16_BIT;
case ENCODING_PCM_8BIT:
return AUDIO_FORMAT_PCM_8_BIT;
case ENCODING_PCM_FLOAT:
return AUDIO_FORMAT_PCM_FLOAT;
case ENCODING_AC3:
return AUDIO_FORMAT_AC3;
case ENCODING_E_AC3:
return AUDIO_FORMAT_E_AC3;
case ENCODING_DTS:
return AUDIO_FORMAT_DTS;
case ENCODING_DTS_HD:
return AUDIO_FORMAT_DTS_HD;
case ENCODING_MP3:
return AUDIO_FORMAT_MP3;
case ENCODING_AAC_LC:
return AUDIO_FORMAT_AAC_LC;
case ENCODING_AAC_HE_V1:
return AUDIO_FORMAT_AAC_HE_V1;
case ENCODING_AAC_HE_V2:
return AUDIO_FORMAT_AAC_HE_V2;
case ENCODING_IEC61937:
return AUDIO_FORMAT_IEC61937;
case ENCODING_DEFAULT:
return AUDIO_FORMAT_DEFAULT;
default:
return AUDIO_FORMAT_INVALID;
}
}
static inline int audioFormatFromNative(audio_format_t nativeFormat)
{
switch (nativeFormat) {
case AUDIO_FORMAT_PCM_16_BIT:
return ENCODING_PCM_16BIT;
case AUDIO_FORMAT_PCM_8_BIT:
return ENCODING_PCM_8BIT;
case AUDIO_FORMAT_PCM_FLOAT:
return ENCODING_PCM_FLOAT;
// map these to ENCODING_PCM_FLOAT
case AUDIO_FORMAT_PCM_8_24_BIT:
case AUDIO_FORMAT_PCM_24_BIT_PACKED:
case AUDIO_FORMAT_PCM_32_BIT:
return ENCODING_PCM_FLOAT;
case AUDIO_FORMAT_AC3:
return ENCODING_AC3;
case AUDIO_FORMAT_E_AC3:
return ENCODING_E_AC3;
case AUDIO_FORMAT_DTS:
return ENCODING_DTS;
case AUDIO_FORMAT_DTS_HD:
return ENCODING_DTS_HD;
case AUDIO_FORMAT_MP3:
return ENCODING_MP3;
case AUDIO_FORMAT_AAC_LC:
return ENCODING_AAC_LC;
case AUDIO_FORMAT_AAC_HE_V1:
return ENCODING_AAC_HE_V1;
case AUDIO_FORMAT_AAC_HE_V2:
return ENCODING_AAC_HE_V2;
case AUDIO_FORMAT_IEC61937:
return ENCODING_IEC61937;
case AUDIO_FORMAT_DEFAULT:
return ENCODING_DEFAULT;
default:
return ENCODING_INVALID;
}
}
static inline audio_channel_mask_t outChannelMaskToNative(int channelMask)
{
switch (channelMask) {
case CHANNEL_OUT_DEFAULT:
case CHANNEL_INVALID:
return AUDIO_CHANNEL_NONE;
default:
return (audio_channel_mask_t)(channelMask>>2);
}
}
static inline int outChannelMaskFromNative(audio_channel_mask_t nativeMask)
{
switch (nativeMask) {
case AUDIO_CHANNEL_NONE:
return CHANNEL_OUT_DEFAULT;
default:
return (int)nativeMask<<2;
}
}
static inline audio_channel_mask_t inChannelMaskToNative(int channelMask)
{
return (audio_channel_mask_t)channelMask;
}
static inline int inChannelMaskFromNative(audio_channel_mask_t nativeMask)
{
return (int)nativeMask;
}
#endif // ANDROID_MEDIA_AUDIOFORMAT_H
|