mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Merge pull request #2326 from devint1/alac-dev
Apple Lossless (ALAC) support
This commit is contained in:
commit
a7dd0f7609
@ -63,6 +63,7 @@ git clone git://source.ffmpeg.org/ffmpeg ffmpeg && cd ffmpeg && \
|
||||
--enable-decoder=vorbis \
|
||||
--enable-decoder=opus \
|
||||
--enable-decoder=flac \
|
||||
--enable-decoder=alac \
|
||||
&& \
|
||||
make -j4 && \
|
||||
make install-libs
|
||||
|
@ -19,6 +19,7 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
import com.google.android.exoplayer2.decoder.SimpleDecoder;
|
||||
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
@ -88,6 +89,13 @@ import java.util.List;
|
||||
if (!hasOutputFormat) {
|
||||
channelCount = ffmpegGetChannelCount(nativeContext);
|
||||
sampleRate = ffmpegGetSampleRate(nativeContext);
|
||||
if (sampleRate == 0 && "alac".equals(codecName)) {
|
||||
// ALAC decoder did not set the sample rate in earlier versions of FFMPEG.
|
||||
// See https://trac.ffmpeg.org/ticket/6096
|
||||
ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
|
||||
parsableExtraData.setPosition(extraData.length - 4);
|
||||
sampleRate = parsableExtraData.readUnsignedIntToInt();
|
||||
}
|
||||
hasOutputFormat = true;
|
||||
}
|
||||
outputBuffer.data.position(0);
|
||||
@ -123,6 +131,7 @@ import java.util.List;
|
||||
private static byte[] getExtraData(String mimeType, List<byte[]> initializationData) {
|
||||
switch (mimeType) {
|
||||
case MimeTypes.AUDIO_AAC:
|
||||
case MimeTypes.AUDIO_ALAC:
|
||||
case MimeTypes.AUDIO_OPUS:
|
||||
return initializationData.get(0);
|
||||
case MimeTypes.AUDIO_VORBIS:
|
||||
|
@ -92,6 +92,8 @@ public final class FfmpegLibrary {
|
||||
return "amrwb";
|
||||
case MimeTypes.AUDIO_FLAC:
|
||||
return "flac";
|
||||
case MimeTypes.AUDIO_ALAC:
|
||||
return "alac";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ import java.util.List;
|
||||
public static final int TYPE_vp09 = Util.getIntegerCodeForString("vp09");
|
||||
public static final int TYPE_vpcC = Util.getIntegerCodeForString("vpcC");
|
||||
public static final int TYPE_camm = Util.getIntegerCodeForString("camm");
|
||||
public static final int TYPE_alac = Util.getIntegerCodeForString("alac");
|
||||
|
||||
public final int type;
|
||||
|
||||
|
@ -604,7 +604,7 @@ import java.util.List;
|
||||
|| childAtomType == Atom.TYPE_dtsh || childAtomType == Atom.TYPE_dtsl
|
||||
|| childAtomType == Atom.TYPE_samr || childAtomType == Atom.TYPE_sawb
|
||||
|| childAtomType == Atom.TYPE_lpcm || childAtomType == Atom.TYPE_sowt
|
||||
|| childAtomType == Atom.TYPE__mp3) {
|
||||
|| childAtomType == Atom.TYPE__mp3 || childAtomType == Atom.TYPE_alac) {
|
||||
parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId,
|
||||
language, isQuickTime, drmInitData, out, i);
|
||||
} else if (childAtomType == Atom.TYPE_TTML) {
|
||||
@ -839,6 +839,8 @@ import java.util.List;
|
||||
mimeType = MimeTypes.AUDIO_RAW;
|
||||
} else if (atomType == Atom.TYPE__mp3) {
|
||||
mimeType = MimeTypes.AUDIO_MPEG;
|
||||
} else if (atomType == Atom.TYPE_alac) {
|
||||
mimeType = MimeTypes.AUDIO_ALAC;
|
||||
}
|
||||
|
||||
byte[] initializationData = null;
|
||||
@ -876,6 +878,10 @@ import java.util.List;
|
||||
out.format = Format.createAudioSampleFormat(Integer.toString(trackId), mimeType, null,
|
||||
Format.NO_VALUE, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0,
|
||||
language);
|
||||
} else if (childAtomType == Atom.TYPE_alac) {
|
||||
initializationData = new byte[childAtomSize];
|
||||
parent.setPosition(childPosition);
|
||||
parent.readBytes(initializationData, 0, childAtomSize);
|
||||
}
|
||||
childPosition += childAtomSize;
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ public final class MimeTypes {
|
||||
public static final String AUDIO_AMR_NB = BASE_TYPE_AUDIO + "/3gpp";
|
||||
public static final String AUDIO_AMR_WB = BASE_TYPE_AUDIO + "/amr-wb";
|
||||
public static final String AUDIO_FLAC = BASE_TYPE_AUDIO + "/x-flac";
|
||||
public static final String AUDIO_ALAC = BASE_TYPE_AUDIO + "/alac";
|
||||
|
||||
public static final String TEXT_VTT = BASE_TYPE_TEXT + "/vtt";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user