blob: 99b5f8592e5dfe992e8fefeac6a05b6a684f8708 (
plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* 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_DOLBY_TRUEHD 14
#define ENCODING_AAC_ELD 15
#define ENCODING_AAC_XHE 16
#define ENCODING_AC4 17
#define ENCODING_E_AC3_JOC 18
#define ENCODING_DOLBY_MAT 19
#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_DOLBY_TRUEHD:
return AUDIO_FORMAT_DOLBY_TRUEHD;
case ENCODING_AAC_ELD:
return AUDIO_FORMAT_AAC_ELD;
case ENCODING_AAC_XHE:
return AUDIO_FORMAT_AAC_XHE;
case ENCODING_AC4:
return AUDIO_FORMAT_AC4;
case ENCODING_E_AC3_JOC:
return AUDIO_FORMAT_E_AC3_JOC;
case ENCODING_DEFAULT:
return AUDIO_FORMAT_DEFAULT;
case ENCODING_DOLBY_MAT:
return AUDIO_FORMAT_MAT;
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_DOLBY_TRUEHD:
return ENCODING_DOLBY_TRUEHD;
case AUDIO_FORMAT_AAC_ELD:
return ENCODING_AAC_ELD;
case AUDIO_FORMAT_AAC_XHE:
return ENCODING_AAC_XHE;
case AUDIO_FORMAT_AC4:
return ENCODING_AC4;
case AUDIO_FORMAT_E_AC3_JOC:
return ENCODING_E_AC3_JOC;
case AUDIO_FORMAT_MAT:
case AUDIO_FORMAT_MAT_1_0:
case AUDIO_FORMAT_MAT_2_0:
case AUDIO_FORMAT_MAT_2_1:
return ENCODING_DOLBY_MAT;
case AUDIO_FORMAT_DEFAULT:
return ENCODING_DEFAULT;
default:
return ENCODING_INVALID;
}
}
// This function converts Java channel masks to a native channel mask.
// validity should be checked with audio_is_output_channel().
static inline audio_channel_mask_t nativeChannelMaskFromJavaChannelMasks(
jint channelPositionMask, jint channelIndexMask)
{
// 0 is the java android.media.AudioFormat.CHANNEL_INVALID value
if (channelIndexMask != 0) { // channel index mask takes priority
// To convert to a native channel mask, the Java channel index mask
// requires adding the index representation.
return audio_channel_mask_from_representation_and_bits(
AUDIO_CHANNEL_REPRESENTATION_INDEX,
channelIndexMask);
}
// To convert to a native channel mask, the Java channel position mask
// requires a shift by 2 to skip the two deprecated channel
// configurations "default" and "mono".
return (audio_channel_mask_t)((uint32_t)channelPositionMask >> 2);
}
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
|