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 {
long startElapsedRealtimeMs = SystemClock.elapsedRealtime();
decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE);
decoder.setOutputMode(outputMode);
decoder.start();
notifyDecoderInitialized(startElapsedRealtimeMs, SystemClock.elapsedRealtime());
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;
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> {
protected SubtitleParser() {
protected SimpleSubtitleParser() {
super(new SubtitleInputBuffer[2], new SubtitleOutputBuffer[2]);
setInitialInputBufferSize(1024);
}
......@@ -36,7 +36,7 @@ public abstract class SubtitleParser extends
@Override
protected final SubtitleOutputBuffer createOutputBuffer() {
return new SubtitleOutputBuffer(this);
return new SimpleSubtitleOutputBuffer(this);
}
@Override
......@@ -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;
}
......@@ -18,9 +18,10 @@ package com.google.android.exoplayer.text;
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;
......@@ -28,4 +29,13 @@ import com.google.android.exoplayer.DecoderInputBuffer;
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;
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 {
private final SubtitleParser owner;
public abstract class SubtitleOutputBuffer extends OutputBuffer implements Subtitle {
private Subtitle subtitle;
private long offsetUs;
public SubtitleOutputBuffer(SubtitleParser owner) {
this.owner = owner;
public SubtitleOutputBuffer() {
}
public void setOutput(long timestampUs, Subtitle subtitle, long subsampleOffsetUs) {
......@@ -62,9 +59,7 @@ import java.util.List;
}
@Override
public void release() {
owner.releaseOutputBuffer(this);
}
public abstract void release();
@Override
public void clear() {
......
......@@ -16,30 +16,37 @@
package com.google.android.exoplayer.text;
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.extensions.Decoder;
/**
* A factory for {@link SubtitleParser} instances.
* A factory for {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>}
* instances that will parse subtitles.
*/
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}.
*
* @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);
/**
* 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}.
* @return A new {@link SubtitleParser}.
* @return A new {@link Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException>}.
* @throws IllegalArgumentException If the {@link Format} is not supported.
*/
SubtitleParser createParser(Format format);
Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> createParser(Format format);
/**
* Default {@link SubtitleParserFactory} implementation.
......@@ -51,6 +58,7 @@ public interface SubtitleParserFactory {
* <li>TTML ({@link com.google.android.exoplayer.text.ttml.TtmlParser})</li>
* <li>SubRip ({@link com.google.android.exoplayer.text.subrip.SubripParser})</li>
* <li>TX3G ({@link com.google.android.exoplayer.text.tx3g.Tx3gParser})</li>
* <li>Eia608 ({@link com.google.android.exoplayer.text.eia608.Eia608Parser})</li>
* </ul>
*/
SubtitleParserFactory DEFAULT = new SubtitleParserFactory() {
......@@ -61,13 +69,14 @@ public interface SubtitleParserFactory {
}
@Override
public SubtitleParser createParser(Format format) {
public Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> createParser(
Format format) {
try {
Class<?> clazz = getParserClass(format.sampleMimeType);
if (clazz == null) {
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) {
throw new IllegalStateException("Unexpected error instantiating parser", e);
}
......@@ -86,6 +95,8 @@ public interface SubtitleParserFactory {
return Class.forName("com.google.android.exoplayer.text.subrip.SubripParser");
case MimeTypes.APPLICATION_TX3G:
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:
return null;
}
......
......@@ -24,6 +24,7 @@ import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackStream;
import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.extensions.Decoder;
import android.annotation.TargetApi;
import android.os.Handler;
......@@ -38,8 +39,9 @@ import java.util.List;
/**
* A {@link TrackRenderer} for subtitles.
* <p>
* Text is parsed from sample data using {@link SubtitleParser} instances obtained from a
* {@link SubtitleParserFactory}. The actual rendering of each line of text is delegated to a
* Text is parsed from sample data using
* {@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}.
*/
@TargetApi(16)
......@@ -54,7 +56,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
private boolean inputStreamEnded;
private boolean outputStreamEnded;
private SubtitleParser parser;
private Decoder<SubtitleInputBuffer, SubtitleOutputBuffer, ParserException> parser;
private SubtitleInputBuffer nextInputBuffer;
private SubtitleOutputBuffer subtitle;
private SubtitleOutputBuffer nextSubtitle;
......@@ -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
* using {@link android.app.Activity#getMainLooper()}. Null may be passed if the renderer
* 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,
SubtitleParserFactory parserFactory) {
......@@ -101,7 +104,6 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
super.onEnabled(formats, joining);
parser = parserFactory.createParser(formats[0]);
parser.start();
}
@Override
......@@ -174,7 +176,7 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
}
try {
if (!inputStreamEnded && nextSubtitle == null) {
while (!inputStreamEnded) {
if (nextInputBuffer == null) {
nextInputBuffer = parser.dequeueInputBuffer();
if (nextInputBuffer == null) {
......@@ -193,6 +195,8 @@ public final class TextTrackRenderer extends TrackRenderer implements Callback {
}
parser.queueInputBuffer(nextInputBuffer);
nextInputBuffer = null;
} else if (result == TrackStream.NOTHING_READ) {
break;
}
}
} catch (ParserException e) {
......
......@@ -15,25 +15,14 @@
*/
package com.google.android.exoplayer.text.eia608;
/* package */ final class ClosedCaptionList implements Comparable<ClosedCaptionList> {
/* package */ final class ClosedCaptionList {
public final long timeUs;
public final boolean decodeOnly;
public final ClosedCaption[] captions;
public ClosedCaptionList(long timeUs, boolean decodeOnly, ClosedCaption[] captions) {
public ClosedCaptionList(long timeUs, ClosedCaption[] captions) {
this.timeUs = timeUs;
this.decodeOnly = decodeOnly;
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 @@
package com.google.android.exoplayer.text.subrip;
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.ParsableByteArray;
......@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
/**
* A simple SubRip parser.
*/
public final class SubripParser extends SubtitleParser {
public final class SubripParser extends SimpleSubtitleParser {
private static final String TAG = "SubripParser";
......
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.ttml;
import com.google.android.exoplayer.C;
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.ParserUtil;
import com.google.android.exoplayer.util.Util;
......@@ -58,7 +58,7 @@ import java.util.regex.Pattern;
* </p>
* @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";
......
......@@ -16,15 +16,15 @@
package com.google.android.exoplayer.text.tx3g;
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.SubtitleParser;
/**
* A {@link SubtitleParser} for tx3g.
* A subtitle parser for tx3g.
* <p>
* Currently only supports parsing of a single text track.
*/
public final class Tx3gParser extends SubtitleParser {
public final class Tx3gParser extends SimpleSubtitleParser {
@Override
protected Subtitle decode(byte[] bytes, int length) {
......
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.ParserException;
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.Util;
......@@ -26,9 +26,9 @@ import java.util.Collections;
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;
......
......@@ -16,7 +16,7 @@
package com.google.android.exoplayer.text.webvtt;
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 android.text.TextUtils;
......@@ -29,7 +29,7 @@ import java.util.List;
* <p>
* @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 END_OF_FILE_FOUND = 0;
......
......@@ -132,7 +132,6 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
notifyDecoderError(e);
throw ExoPlaybackException.createForRenderer(e, getIndex());
}
decoder.start();
codecCounters.codecInitCount++;
}
......
......@@ -25,7 +25,7 @@ import java.util.LinkedList;
* Base class for {@link Decoder}s that use their own decode thread.
*/
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.
......@@ -41,6 +41,8 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
}
private final Thread decodeThread;
private final Object lock;
private final LinkedList<I> queuedInputBuffers;
private final LinkedList<O> queuedOutputBuffers;
......@@ -73,6 +75,13 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
for (int i = 0; i < availableOutputBufferCount; i++) {
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
lock.notify();
}
try {
join();
decodeThread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
......@@ -188,8 +197,7 @@ public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends Outp
}
}
@Override
public final void run() {
private void run() {
try {
while (decode()) {
// 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