Skip to content

Commit

Permalink
Add support for extracting Vorbis audio in WebM Extractor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ojw28 committed Nov 18, 2014
1 parent 6a544da commit 2472637
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public DashChunkSource(DataSource dataSource, FormatEvaluator evaluator,
formats[i] = representations[i].format;
maxWidth = Math.max(formats[i].width, maxWidth);
maxHeight = Math.max(formats[i].height, maxHeight);
Extractor extractor = formats[i].mimeType.startsWith(MimeTypes.VIDEO_WEBM)
Extractor extractor = mimeTypeIsWebm(formats[i].mimeType)
? new WebmExtractor() : new FragmentedMp4Extractor();
extractors.put(formats[i].id, extractor);
this.representations.put(formats[i].id, representations[i]);
Expand Down Expand Up @@ -197,6 +197,10 @@ public void onChunkLoadError(Chunk chunk, Exception e) {
// Do nothing.
}

private boolean mimeTypeIsWebm(String mimeType) {
return mimeType.startsWith(MimeTypes.VIDEO_WEBM) || mimeType.startsWith(MimeTypes.AUDIO_WEBM);
}

private Chunk newInitializationChunk(RangedUri initializationUri, RangedUri indexUri,
Representation representation, Extractor extractor, DataSource dataSource,
int trigger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.android.exoplayer.parser.webm;

import com.google.android.exoplayer.C;
import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.upstream.NonBlockingInputStream;
import com.google.android.exoplayer.util.Assertions;

Expand Down Expand Up @@ -134,7 +135,7 @@ public void setEventHandler(EbmlEventHandler eventHandler) {
}

@Override
public int read(NonBlockingInputStream inputStream) {
public int read(NonBlockingInputStream inputStream) throws ParserException {
Assertions.checkState(eventHandler != null);
while (true) {
while (!masterElementsStack.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.parser.webm;

import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.upstream.NonBlockingInputStream;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -46,41 +47,47 @@
* @param elementOffsetBytes The byte offset where this element starts
* @param headerSizeBytes The byte length of this element's ID and size header
* @param contentsSizeBytes The byte length of this element's children
* @throws ParserException If a parsing error occurs.
*/
public void onMasterElementStart(
int id, long elementOffsetBytes, int headerSizeBytes, long contentsSizeBytes);
int id, long elementOffsetBytes, int headerSizeBytes,
long contentsSizeBytes) throws ParserException;

/**
* Called when a master element has finished reading in all of its children from the
* {@link NonBlockingInputStream}.
*
* @param id The integer ID of this element
* @throws ParserException If a parsing error occurs.
*/
public void onMasterElementEnd(int id);
public void onMasterElementEnd(int id) throws ParserException;

/**
* Called when an integer element is encountered in the {@link NonBlockingInputStream}.
*
* @param id The integer ID of this element
* @param value The integer value this element contains
* @throws ParserException If a parsing error occurs.
*/
public void onIntegerElement(int id, long value);
public void onIntegerElement(int id, long value) throws ParserException;

/**
* Called when a float element is encountered in the {@link NonBlockingInputStream}.
*
* @param id The integer ID of this element
* @param value The float value this element contains
* @throws ParserException If a parsing error occurs.
*/
public void onFloatElement(int id, double value);
public void onFloatElement(int id, double value) throws ParserException;

/**
* Called when a string element is encountered in the {@link NonBlockingInputStream}.
*
* @param id The integer ID of this element
* @param value The string value this element contains
* @throws ParserException If a parsing error occurs.
*/
public void onStringElement(int id, String value);
public void onStringElement(int id, String value) throws ParserException;

/**
* Called when a binary element is encountered in the {@link NonBlockingInputStream}.
Expand Down Expand Up @@ -109,9 +116,10 @@ public void onMasterElementStart(
* @param inputStream The {@link NonBlockingInputStream} from which this
* element's contents should be read
* @return True if the element was read. False otherwise.
* @throws ParserException If a parsing error occurs.
*/
public boolean onBinaryElement(
int id, long elementOffsetBytes, int headerSizeBytes, int contentsSizeBytes,
NonBlockingInputStream inputStream);
NonBlockingInputStream inputStream) throws ParserException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.parser.webm;

import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.upstream.NonBlockingInputStream;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -53,8 +54,9 @@
*
* @param inputStream The input stream from which data should be read
* @return One of the {@code RESULT_*} flags defined in this interface
* @throws ParserException If parsing fails.
*/
public int read(NonBlockingInputStream inputStream);
public int read(NonBlockingInputStream inputStream) throws ParserException;

/**
* The total number of bytes consumed by the reader since first created or last {@link #reset()}.
Expand Down
Loading

0 comments on commit 2472637

Please sign in to comment.