Skip to content

Commit

Permalink
Support Opus and Flac in MP4/DASH
Browse files Browse the repository at this point in the history
Issue: #4883

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222392621
  • Loading branch information
ojw28 committed Nov 27, 2018
1 parent 233ff07 commit 56b0294
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### 2.9.2 ###

* MP4: Support Opus and FLAC in the MP4 container, and in DASH
([#4883](https://github.com/google/ExoPlayer/issues/4883)).
* Support seeking for a wider range of MPEG-TS streams
([#5097](https://github.com/google/ExoPlayer/issues/5097)).
* DASH: Fix detecting the end of live events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
public static final int TYPE_alac = Util.getIntegerCodeForString("alac");
public static final int TYPE_alaw = Util.getIntegerCodeForString("alaw");
public static final int TYPE_ulaw = Util.getIntegerCodeForString("ulaw");
public static final int TYPE_Opus = Util.getIntegerCodeForString("Opus");
public static final int TYPE_dOps = Util.getIntegerCodeForString("dOps");
public static final int TYPE_fLaC = Util.getIntegerCodeForString("fLaC");
public static final int TYPE_dfLa = Util.getIntegerCodeForString("dfLa");

public final int type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
*/
private static final int MAX_GAPLESS_TRIM_SIZE_SAMPLES = 3;

/** The magic signature for an Opus Identification header, as defined in RFC-7845. */
private static final byte[] opusMagic = Util.getUtf8Bytes("OpusHead");

/**
* Parses a trak atom (defined in 14496-12).
*
Expand Down Expand Up @@ -679,7 +682,9 @@ private static StsdData parseStsd(ParsableByteArray stsd, int trackId, int rotat
|| childAtomType == Atom.TYPE__mp3
|| childAtomType == Atom.TYPE_alac
|| childAtomType == Atom.TYPE_alaw
|| childAtomType == Atom.TYPE_ulaw) {
|| childAtomType == Atom.TYPE_ulaw
|| childAtomType == Atom.TYPE_Opus
|| childAtomType == Atom.TYPE_fLaC) {
parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId,
language, isQuickTime, drmInitData, out, i);
} else if (childAtomType == Atom.TYPE_TTML || childAtomType == Atom.TYPE_tx3g
Expand Down Expand Up @@ -976,6 +981,10 @@ private static void parseAudioSampleEntry(ParsableByteArray parent, int atomType
mimeType = MimeTypes.AUDIO_ALAW;
} else if (atomType == Atom.TYPE_ulaw) {
mimeType = MimeTypes.AUDIO_MLAW;
} else if (atomType == Atom.TYPE_Opus) {
mimeType = MimeTypes.AUDIO_OPUS;
} else if (atomType == Atom.TYPE_fLaC) {
mimeType = MimeTypes.AUDIO_FLAC;
}

byte[] initializationData = null;
Expand Down Expand Up @@ -1016,7 +1025,20 @@ private static void parseAudioSampleEntry(ParsableByteArray parent, int atomType
} else if (childAtomType == Atom.TYPE_alac) {
initializationData = new byte[childAtomSize];
parent.setPosition(childPosition);
parent.readBytes(initializationData, 0, childAtomSize);
parent.readBytes(initializationData, /* offset= */ 0, childAtomSize);
} else if (childAtomType == Atom.TYPE_dOps) {
// Build an Opus Identification Header (defined in RFC-7845) by concatenating the Opus Magic
// Signature and the body of the dOps atom.
int childAtomBodySize = childAtomSize - Atom.HEADER_SIZE;
initializationData = new byte[opusMagic.length + childAtomBodySize];
System.arraycopy(opusMagic, 0, initializationData, 0, opusMagic.length);
parent.setPosition(childPosition + Atom.HEADER_SIZE);
parent.readBytes(initializationData, opusMagic.length, childAtomBodySize);
} else if (childAtomSize == Atom.TYPE_dfLa) {
int childAtomBodySize = childAtomSize - Atom.FULL_HEADER_SIZE;
initializationData = new byte[childAtomBodySize];
parent.setPosition(childPosition + Atom.FULL_HEADER_SIZE);
parent.readBytes(initializationData, /* offset= */ 0, childAtomBodySize);
}
childPosition += childAtomSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static boolean isApplication(@Nullable String mimeType) {
if (codec == null) {
return null;
}
codec = codec.trim();
codec = Util.toLowerInvariant(codec.trim());
if (codec.startsWith("avc1") || codec.startsWith("avc3")) {
return MimeTypes.VIDEO_H264;
} else if (codec.startsWith("hev1") || codec.startsWith("hvc1")) {
Expand Down Expand Up @@ -245,6 +245,8 @@ public static boolean isApplication(@Nullable String mimeType) {
return MimeTypes.AUDIO_OPUS;
} else if (codec.startsWith("vorbis")) {
return MimeTypes.AUDIO_VORBIS;
} else if (codec.startsWith("flac")) {
return MimeTypes.AUDIO_FLAC;
} else {
return getCustomMimeTypeForCodec(codec);
}
Expand Down

0 comments on commit 56b0294

Please sign in to comment.