@@ -83,7 +83,7 @@ public final class CodecSpecificDataUtil {
83
83
private CodecSpecificDataUtil () {}
84
84
85
85
/**
86
- * Parses an AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
86
+ * Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
87
87
*
88
88
* @param audioSpecificConfig A byte array containing the AudioSpecificConfig to parse.
89
89
* @return A pair consisting of the sample rate in Hz and the channel count.
@@ -95,7 +95,7 @@ public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpe
95
95
}
96
96
97
97
/**
98
- * Parses an AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
98
+ * Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
99
99
*
100
100
* @param bitArray A {@link ParsableBitArray} containing the AudioSpecificConfig to parse. The
101
101
* position is advanced to the end of the AudioSpecificConfig.
@@ -104,8 +104,8 @@ public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpe
104
104
* @return A pair consisting of the sample rate in Hz and the channel count.
105
105
* @throws ParserException If the AudioSpecificConfig cannot be parsed as it's not supported.
106
106
*/
107
- public static Pair <Integer , Integer > parseAacAudioSpecificConfig (ParsableBitArray bitArray ,
108
- boolean forceReadToEnd ) throws ParserException {
107
+ public static Pair <Integer , Integer > parseAacAudioSpecificConfig (
108
+ ParsableBitArray bitArray , boolean forceReadToEnd ) throws ParserException {
109
109
int audioObjectType = getAacAudioObjectType (bitArray );
110
110
int sampleRate = getAacSamplingFrequency (bitArray );
111
111
int channelConfiguration = bitArray .readBits (4 );
@@ -166,10 +166,10 @@ public static Pair<Integer, Integer> parseAacAudioSpecificConfig(ParsableBitArra
166
166
* Builds a simple HE-AAC LC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
167
167
*
168
168
* @param sampleRate The sample rate in Hz.
169
- * @param numChannels The number of channels .
169
+ * @param channelCount The channel count .
170
170
* @return The AudioSpecificConfig.
171
171
*/
172
- public static byte [] buildAacLcAudioSpecificConfig (int sampleRate , int numChannels ) {
172
+ public static byte [] buildAacLcAudioSpecificConfig (int sampleRate , int channelCount ) {
173
173
int sampleRateIndex = C .INDEX_UNSET ;
174
174
for (int i = 0 ; i < AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE .length ; ++i ) {
175
175
if (sampleRate == AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE [i ]) {
@@ -178,13 +178,13 @@ public static byte[] buildAacLcAudioSpecificConfig(int sampleRate, int numChanne
178
178
}
179
179
int channelConfig = C .INDEX_UNSET ;
180
180
for (int i = 0 ; i < AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE .length ; ++i ) {
181
- if (numChannels == AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE [i ]) {
181
+ if (channelCount == AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE [i ]) {
182
182
channelConfig = i ;
183
183
}
184
184
}
185
185
if (sampleRate == C .INDEX_UNSET || channelConfig == C .INDEX_UNSET ) {
186
- throw new IllegalArgumentException ("Invalid sample rate or number of channels: "
187
- + sampleRate + ", " + numChannels );
186
+ throw new IllegalArgumentException (
187
+ "Invalid sample rate or number of channels: " + sampleRate + ", " + channelCount );
188
188
}
189
189
return buildAacAudioSpecificConfig (AUDIO_OBJECT_TYPE_AAC_LC , sampleRateIndex , channelConfig );
190
190
}
@@ -205,6 +205,22 @@ public static byte[] buildAacAudioSpecificConfig(int audioObjectType, int sample
205
205
return specificConfig ;
206
206
}
207
207
208
+ /**
209
+ * Parses an ALAC AudioSpecificConfig (i.e. an <a
210
+ * href="https://github.com/macosforge/alac/blob/master/ALACMagicCookieDescription.txt">ALACSpecificConfig</a>).
211
+ *
212
+ * @param audioSpecificConfig A byte array containing the AudioSpecificConfig to parse.
213
+ * @return A pair consisting of the sample rate in Hz and the channel count.
214
+ */
215
+ public static Pair <Integer , Integer > parseAlacAudioSpecificConfig (byte [] audioSpecificConfig ) {
216
+ ParsableByteArray byteArray = new ParsableByteArray (audioSpecificConfig );
217
+ byteArray .setPosition (9 );
218
+ int channelCount = byteArray .readUnsignedByte ();
219
+ byteArray .setPosition (20 );
220
+ int sampleRate = byteArray .readUnsignedIntToInt ();
221
+ return Pair .create (sampleRate , channelCount );
222
+ }
223
+
208
224
/**
209
225
* Builds an RFC 6381 AVC codec string using the provided parameters.
210
226
*
0 commit comments