Commit 0bd26b74 by cdrolle Committed by Oliver Woodman

Remove Eia608TrackRenderer

Functionality is moved into Eia608Parser, so that Eia608Parser
can be used with TextTrackRenderer, similar to all the other
text/subtitle formats. Modified some of the other
text/subtitle-related classes to support the new behaviour.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120755145
parent 6c452336
Showing with 215 additions and 60 deletions
...@@ -208,7 +208,6 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer { ...@@ -208,7 +208,6 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
long startElapsedRealtimeMs = SystemClock.elapsedRealtime(); long startElapsedRealtimeMs = SystemClock.elapsedRealtime();
decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE); decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE);
decoder.setOutputMode(outputMode); decoder.setOutputMode(outputMode);
decoder.start();
notifyDecoderInitialized(startElapsedRealtimeMs, SystemClock.elapsedRealtime()); notifyDecoderInitialized(startElapsedRealtimeMs, SystemClock.elapsedRealtime());
codecCounters.codecInitCount++; codecCounters.codecInitCount++;
} }
......
/*
* 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.
*/
package com.google.android.exoplayer.text;
/**
* A {@link Subtitle} output from a subtitle parser that extends {@link SimpleSubtitleParser}.
*/
public final class SimpleSubtitleOutputBuffer extends SubtitleOutputBuffer {
private SimpleSubtitleParser owner;
public SimpleSubtitleOutputBuffer(SimpleSubtitleParser owner) {
super();
this.owner = owner;
}
@Override
public final void release() {
owner.releaseOutputBuffer(this);
}
}
...@@ -19,12 +19,12 @@ import com.google.android.exoplayer.ParserException; ...@@ -19,12 +19,12 @@ import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.util.extensions.SimpleDecoder; import com.google.android.exoplayer.util.extensions.SimpleDecoder;
/** /**
* Parses {@link Subtitle}s from {@link SubtitleInputBuffer}s. * Base class for subtitle parsers that use their own decode thread.
*/ */
public abstract class SubtitleParser extends public abstract class SimpleSubtitleParser extends
SimpleDecoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> { SimpleDecoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> {
protected SubtitleParser() { protected SimpleSubtitleParser() {
super(new SubtitleInputBuffer[2], new SubtitleOutputBuffer[2]); super(new SubtitleInputBuffer[2], new SubtitleOutputBuffer[2]);
setInitialInputBufferSize(1024); setInitialInputBufferSize(1024);
} }
...@@ -36,7 +36,7 @@ public abstract class SubtitleParser extends ...@@ -36,7 +36,7 @@ public abstract class SubtitleParser extends
@Override @Override
protected final SubtitleOutputBuffer createOutputBuffer() { protected final SubtitleOutputBuffer createOutputBuffer() {
return new SubtitleOutputBuffer(this); return new SimpleSubtitleOutputBuffer(this);
} }
@Override @Override
...@@ -56,6 +56,14 @@ public abstract class SubtitleParser extends ...@@ -56,6 +56,14 @@ public abstract class SubtitleParser extends
} }
} }
/**
* Decodes the data and converts it into a {@link Subtitle}.
*
* @param data The data to be decoded.
* @param size The size of the data.
* @return A {@link Subtitle} to rendered.
* @throws ParserException A parsing exception.
*/
protected abstract Subtitle decode(byte[] data, int size) throws ParserException; protected abstract Subtitle decode(byte[] data, int size) throws ParserException;
} }
...@@ -18,9 +18,10 @@ package com.google.android.exoplayer.text; ...@@ -18,9 +18,10 @@ package com.google.android.exoplayer.text;
import com.google.android.exoplayer.DecoderInputBuffer; import com.google.android.exoplayer.DecoderInputBuffer;
/** /**
* An input buffer for {@link SubtitleParser}. * An input buffer for a subtitle parser.
*/ */
/* package */ final class SubtitleInputBuffer extends DecoderInputBuffer { public final class SubtitleInputBuffer extends DecoderInputBuffer
implements Comparable<SubtitleInputBuffer> {
public long subsampleOffsetUs; public long subsampleOffsetUs;
...@@ -28,4 +29,13 @@ import com.google.android.exoplayer.DecoderInputBuffer; ...@@ -28,4 +29,13 @@ import com.google.android.exoplayer.DecoderInputBuffer;
super(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL); super(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
} }
@Override
public int compareTo(SubtitleInputBuffer other) {
long delta = timeUs - other.timeUs;
if (delta == 0) {
return 0;
}
return delta > 0 ? 1 : -1;
}
} }
...@@ -21,17 +21,14 @@ import com.google.android.exoplayer.util.extensions.OutputBuffer; ...@@ -21,17 +21,14 @@ import com.google.android.exoplayer.util.extensions.OutputBuffer;
import java.util.List; import java.util.List;
/** /**
* A {@link Subtitle} output from a {@link SubtitleParser}. * Base class for a {@link Subtitle} output from a subtitle parser.
*/ */
/* package */ final class SubtitleOutputBuffer extends OutputBuffer implements Subtitle { public abstract class SubtitleOutputBuffer extends OutputBuffer implements Subtitle {
private final SubtitleParser owner;
private Subtitle subtitle; private Subtitle subtitle;
private long offsetUs; private long offsetUs;
public SubtitleOutputBuffer(SubtitleParser owner) { public SubtitleOutputBuffer() {
this.owner = owner;
} }
public void setOutput(long timestampUs, Subtitle subtitle, long subsampleOffsetUs) { public void setOutput(long timestampUs, Subtitle subtitle, long subsampleOffsetUs) {
...@@ -62,9 +59,7 @@ import java.util.List; ...@@ -62,9 +59,7 @@ import java.util.List;
} }
@Override @Override
public void release() { public abstract void release();
owner.releaseOutputBuffer(this);
}
@Override @Override
public void clear() { public void clear() {
......
...@@ -16,30 +16,37 @@ ...@@ -16,30 +16,37 @@
package com.google.android.exoplayer.text; package com.google.android.exoplayer.text;
import com.google.android.exoplayer.Format; import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.extensions.Decoder;
/** /**
* A factory for {@link SubtitleParser} instances. * A factory for {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>}
* instances that will parse subtitles.
*/ */
public interface SubtitleParserFactory { public interface SubtitleParserFactory {
/** /**
* Returns whether the factory is able to instantiate a {@link SubtitleParser} for the given * Returns whether the factory is able to instantiate a
* {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>} for the given
* {@link Format}. * {@link Format}.
* *
* @param format The {@link Format}. * @param format The {@link Format}.
* @return True if the factory can instantiate a suitable {@link SubtitleParser}. False otherwise. * @return True if the factory can instantiate a suitable
* {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>}. False
* otherwise.
*/ */
boolean supportsFormat(Format format); boolean supportsFormat(Format format);
/** /**
* Creates a {@link SubtitleParser} for the given {@link Format}. * Creates a {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>} for
* the given {@link Format}.
* *
* @param format The {@link Format}. * @param format The {@link Format}.
* @return A new {@link SubtitleParser}. * @return A new {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>}.
* @throws IllegalArgumentException If the {@link Format} is not supported. * @throws IllegalArgumentException If the {@link Format} is not supported.
*/ */
SubtitleParser createParser(Format format); Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> createParser(Format format);
/** /**
* Default {@link SubtitleParserFactory} implementation. * Default {@link SubtitleParserFactory} implementation.
...@@ -51,6 +58,7 @@ public interface SubtitleParserFactory { ...@@ -51,6 +58,7 @@ public interface SubtitleParserFactory {
* <li>TTML ({@link com.google.android.exoplayer.text.ttml.TtmlParser})</li> * <li>TTML ({@link com.google.android.exoplayer.text.ttml.TtmlParser})</li>
* <li>SubRip ({@link com.google.android.exoplayer.text.subrip.SubripParser})</li> * <li>SubRip ({@link com.google.android.exoplayer.text.subrip.SubripParser})</li>
* <li>TX3G ({@link com.google.android.exoplayer.text.tx3g.Tx3gParser})</li> * <li>TX3G ({@link com.google.android.exoplayer.text.tx3g.Tx3gParser})</li>
* <li>Eia608 ({@link com.google.android.exoplayer.text.eia608.Eia608Parser})</li>
* </ul> * </ul>
*/ */
SubtitleParserFactory DEFAULT = new SubtitleParserFactory() { SubtitleParserFactory DEFAULT = new SubtitleParserFactory() {
...@@ -61,13 +69,14 @@ public interface SubtitleParserFactory { ...@@ -61,13 +69,14 @@ public interface SubtitleParserFactory {
} }
@Override @Override
public SubtitleParser createParser(Format format) { public Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> createParser(
Format format) {
try { try {
Class<?> clazz = getParserClass(format.sampleMimeType); Class<?> clazz = getParserClass(format.sampleMimeType);
if (clazz == null) { if (clazz == null) {
throw new IllegalArgumentException("Attempted to create parser for unsupported format"); throw new IllegalArgumentException("Attempted to create parser for unsupported format");
} }
return clazz.asSubclass(SubtitleParser.class).newInstance(); return clazz.asSubclass(Decoder.class).newInstance();
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Unexpected error instantiating parser", e); throw new IllegalStateException("Unexpected error instantiating parser", e);
} }
...@@ -86,6 +95,8 @@ public interface SubtitleParserFactory { ...@@ -86,6 +95,8 @@ public interface SubtitleParserFactory {
return Class.forName("com.google.android.exoplayer.text.subrip.SubripParser"); return Class.forName("com.google.android.exoplayer.text.subrip.SubripParser");
case MimeTypes.APPLICATION_TX3G: case MimeTypes.APPLICATION_TX3G:
return Class.forName("com.google.android.exoplayer.text.tx3g.Tx3gParser"); return Class.forName("com.google.android.exoplayer.text.tx3g.Tx3gParser");
case MimeTypes.APPLICATION_EIA608:
return Class.forName("com.google.android.exoplayer.text.eia608.Eia608Parser");
default: default:
return null; return null;
} }
......
...@@ -24,6 +24,7 @@ import com.google.android.exoplayer.TrackRenderer; ...@@ -24,6 +24,7 @@ import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackStream; import com.google.android.exoplayer.TrackStream;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.extensions.Decoder;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Handler; import android.os.Handler;
...@@ -38,8 +39,9 @@ import java.util.List; ...@@ -38,8 +39,9 @@ import java.util.List;
/** /**
* A {@link TrackRenderer} for subtitles. * A {@link TrackRenderer} for subtitles.
* <p> * <p>
* Text is parsed from sample data using {@link SubtitleParser} instances obtained from a * Text is parsed from sample data using
* {@link SubtitleParserFactory}. The actual rendering of each line of text is delegated to a * {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>} instances obtained
* from a {@link SubtitleParserFactory}. The actual rendering of each line of text is delegated to a
* {@link TextRenderer}. * {@link TextRenderer}.
*/ */
@TargetApi(16) @TargetApi(16)
...@@ -54,7 +56,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -54,7 +56,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
private boolean inputStreamEnded; private boolean inputStreamEnded;
private boolean outputStreamEnded; private boolean outputStreamEnded;
private SubtitleParser parser; private Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> parser;
private SubtitleInputBuffer nextInputBuffer; private SubtitleInputBuffer nextInputBuffer;
private SubtitleOutputBuffer subtitle; private SubtitleOutputBuffer subtitle;
private SubtitleOutputBuffer nextSubtitle; private SubtitleOutputBuffer nextSubtitle;
...@@ -79,7 +81,8 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -79,7 +81,8 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
* normally be the looper associated with the application's main thread, which can be obtained * normally be the looper associated with the application's main thread, which can be obtained
* using {@link android.app.Activity#getMainLooper()}. Null may be passed if the renderer * using {@link android.app.Activity#getMainLooper()}. Null may be passed if the renderer
* should be invoked directly on the player's internal rendering thread. * should be invoked directly on the player's internal rendering thread.
* @param parserFactory A factory from which to obtain {@link SubtitleParser} instances. * @param parserFactory A factory from which to obtain
* {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>} instances.
*/ */
public TextTrackRenderer(TextRenderer textRenderer, Looper textRendererLooper, public TextTrackRenderer(TextRenderer textRenderer, Looper textRendererLooper,
SubtitleParserFactory parserFactory) { SubtitleParserFactory parserFactory) {
...@@ -101,7 +104,6 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -101,7 +104,6 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException { protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
super.onEnabled(formats, joining); super.onEnabled(formats, joining);
parser = parserFactory.createParser(formats[0]); parser = parserFactory.createParser(formats[0]);
parser.start();
} }
@Override @Override
...@@ -174,7 +176,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -174,7 +176,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
} }
try { try {
if (!inputStreamEnded && nextSubtitle == null) { while (!inputStreamEnded) {
if (nextInputBuffer == null) { if (nextInputBuffer == null) {
nextInputBuffer = parser.dequeueInputBuffer(); nextInputBuffer = parser.dequeueInputBuffer();
if (nextInputBuffer == null) { if (nextInputBuffer == null) {
...@@ -193,6 +195,8 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -193,6 +195,8 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
} }
parser.queueInputBuffer(nextInputBuffer); parser.queueInputBuffer(nextInputBuffer);
nextInputBuffer = null; nextInputBuffer = null;
} else if (result == TrackStream.NOTHING_READ) {
break;
} }
} }
} catch (ParserException e) { } catch (ParserException e) {
......
...@@ -15,25 +15,14 @@ ...@@ -15,25 +15,14 @@
*/ */
package com.google.android.exoplayer.text.eia608; package com.google.android.exoplayer.text.eia608;
/* package */ final class ClosedCaptionList implements Comparable<ClosedCaptionList> { /* package */ final class ClosedCaptionList {
public final long timeUs; public final long timeUs;
public final boolean decodeOnly;
public final ClosedCaption[] captions; public final ClosedCaption[] captions;
public ClosedCaptionList(long timeUs, boolean decodeOnly, ClosedCaption[] captions) { public ClosedCaptionList(long timeUs, ClosedCaption[] captions) {
this.timeUs = timeUs; this.timeUs = timeUs;
this.decodeOnly = decodeOnly;
this.captions = captions; this.captions = captions;
} }
@Override
public int compareTo(ClosedCaptionList other) {
long delta = timeUs - other.timeUs;
if (delta == 0) {
return 0;
}
return delta > 0 ? 1 : -1;
}
} }
/*
* 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.
*/
package com.google.android.exoplayer.text.eia608;
import com.google.android.exoplayer.text.Cue;
import com.google.android.exoplayer.text.Subtitle;
import java.util.Collections;
import java.util.List;
/**
* A representation of an EIA-608 subtitle.
*/
public final class Eia608Subtitle implements Subtitle {
private final String caption;
public Eia608Subtitle(String caption) {
this.caption = caption;
}
@Override
public int getNextEventTimeIndex(long timeUs) {
return 0;
}
@Override
public int getEventTimeCount() {
return 1;
}
@Override
public long getEventTime(int index) {
return 0;
}
@Override
public List<Cue> getCues(long timeUs) {
if (caption == null || caption.isEmpty()) {
return Collections.<Cue>emptyList();
} else {
return Collections.singletonList(new Cue(caption));
}
}
}
/*
* 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.
*/
package com.google.android.exoplayer.text.eia608;
import com.google.android.exoplayer.text.Subtitle;
import com.google.android.exoplayer.text.SubtitleOutputBuffer;
/**
* A {@link Subtitle} output from an {@link Eia608Parser}.
*/
public final class Eia608SubtitleOutputBuffer extends SubtitleOutputBuffer {
private Eia608Parser owner;
public Eia608SubtitleOutputBuffer(Eia608Parser owner) {
super();
this.owner = owner;
}
@Override
public final void release() {
owner.releaseOutputBuffer(this);
}
}
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package com.google.android.exoplayer.text.subrip; package com.google.android.exoplayer.text.subrip;
import com.google.android.exoplayer.text.Cue; import com.google.android.exoplayer.text.Cue;
import com.google.android.exoplayer.text.SubtitleParser; import com.google.android.exoplayer.text.SimpleSubtitleParser;
import com.google.android.exoplayer.util.LongArray; import com.google.android.exoplayer.util.LongArray;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
...@@ -32,7 +32,7 @@ import java.util.regex.Pattern; ...@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
/** /**
* A simple SubRip parser. * A simple SubRip parser.
*/ */
public final class SubripParser extends SubtitleParser { public final class SubripParser extends SimpleSubtitleParser {
private static final String TAG = "SubripParser"; private static final String TAG = "SubripParser";
......
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.ttml; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.ttml;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.ParserException; import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.text.SubtitleParser; import com.google.android.exoplayer.text.SimpleSubtitleParser;
import com.google.android.exoplayer.util.ColorParser; import com.google.android.exoplayer.util.ColorParser;
import com.google.android.exoplayer.util.ParserUtil; import com.google.android.exoplayer.util.ParserUtil;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
...@@ -58,7 +58,7 @@ import java.util.regex.Pattern; ...@@ -58,7 +58,7 @@ import java.util.regex.Pattern;
* </p> * </p>
* @see <a href="http://www.w3.org/TR/ttaf1-dfxp/">TTML specification</a> * @see <a href="http://www.w3.org/TR/ttaf1-dfxp/">TTML specification</a>
*/ */
public final class TtmlParser extends SubtitleParser { public final class TtmlParser extends SimpleSubtitleParser {
private static final String TAG = "TtmlParser"; private static final String TAG = "TtmlParser";
......
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
package com.google.android.exoplayer.text.tx3g; package com.google.android.exoplayer.text.tx3g;
import com.google.android.exoplayer.text.Cue; import com.google.android.exoplayer.text.Cue;
import com.google.android.exoplayer.text.SimpleSubtitleParser;
import com.google.android.exoplayer.text.Subtitle; import com.google.android.exoplayer.text.Subtitle;
import com.google.android.exoplayer.text.SubtitleParser;
/** /**
* A {@link SubtitleParser} for tx3g. * A subtitle parser for tx3g.
* <p> * <p>
* Currently only supports parsing of a single text track. * Currently only supports parsing of a single text track.
*/ */
public final class Tx3gParser extends SubtitleParser { public final class Tx3gParser extends SimpleSubtitleParser {
@Override @Override
protected Subtitle decode(byte[] bytes, int length) { protected Subtitle decode(byte[] bytes, int length) {
......
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.webvtt; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.ParserException; import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.text.Cue; import com.google.android.exoplayer.text.Cue;
import com.google.android.exoplayer.text.SubtitleParser; import com.google.android.exoplayer.text.SimpleSubtitleParser;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
...@@ -26,9 +26,9 @@ import java.util.Collections; ...@@ -26,9 +26,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* A {@link SubtitleParser} for Webvtt embedded in a Mp4 container file. * A subtitle parser for Webvtt embedded in a Mp4 container file.
*/ */
public final class Mp4WebvttParser extends SubtitleParser { public final class Mp4WebvttParser extends SimpleSubtitleParser {
private static final int BOX_HEADER_SIZE = 8; private static final int BOX_HEADER_SIZE = 8;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package com.google.android.exoplayer.text.webvtt; package com.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.ParserException; import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.text.SubtitleParser; import com.google.android.exoplayer.text.SimpleSubtitleParser;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -29,7 +29,7 @@ import java.util.List; ...@@ -29,7 +29,7 @@ import java.util.List;
* <p> * <p>
* @see <a href="http://dev.w3.org/html5/webvtt">WebVTT specification</a> * @see <a href="http://dev.w3.org/html5/webvtt">WebVTT specification</a>
*/ */
public final class WebvttParser extends SubtitleParser { public final class WebvttParser extends SimpleSubtitleParser {
private static final int NO_EVENT_FOUND = -1; private static final int NO_EVENT_FOUND = -1;
private static final int END_OF_FILE_FOUND = 0; private static final int END_OF_FILE_FOUND = 0;
......
...@@ -132,7 +132,6 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements ...@@ -132,7 +132,6 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
notifyDecoderError(e); notifyDecoderError(e);
throw ExoPlaybackException.createForRenderer(e, getIndex()); throw ExoPlaybackException.createForRenderer(e, getIndex());
} }
decoder.start();
codecCounters.codecInitCount++; codecCounters.codecInitCount++;
} }
......
...@@ -25,7 +25,7 @@ import java.util.LinkedList; ...@@ -25,7 +25,7 @@ import java.util.LinkedList;
* Base class for {@link Decoder}s that use their own decode thread. * Base class for {@link Decoder}s that use their own decode thread.
*/ */
public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends OutputBuffer, public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends OutputBuffer,
E extends Exception> extends Thread implements Decoder<I, O, E> { E extends Exception> implements Decoder<I, O, E> {
/** /**
* Listener for {@link SimpleDecoder} events. * Listener for {@link SimpleDecoder} events.
...@@ -41,6 +41,8 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp ...@@ -41,6 +41,8 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
} }
private final Thread decodeThread;
private final Object lock; private final Object lock;
private final LinkedList<I> queuedInputBuffers; private final LinkedList<I> queuedInputBuffers;
private final LinkedList<O> queuedOutputBuffers; private final LinkedList<O> queuedOutputBuffers;
...@@ -73,6 +75,13 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp ...@@ -73,6 +75,13 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
for (int i = 0; i < availableOutputBufferCount; i++) { for (int i = 0; i < availableOutputBufferCount; i++) {
availableOutputBuffers[i] = createOutputBuffer(); availableOutputBuffers[i] = createOutputBuffer();
} }
decodeThread = new Thread() {
@Override
public void run() {
SimpleDecoder.this.run();
}
};
decodeThread.start();
} }
/** /**
...@@ -159,7 +168,7 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp ...@@ -159,7 +168,7 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
lock.notify(); lock.notify();
} }
try { try {
join(); decodeThread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
...@@ -188,8 +197,7 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp ...@@ -188,8 +197,7 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
} }
} }
@Override private void run() {
public final void run() {
try { try {
while (decode()) { while (decode()) {
// Do nothing. // Do nothing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment