Move WEBVTT custom header constants.

They're current location is annoying, because it creates a dependency
from the dash package to the webvtt package. For apps like Play Movies
where WEBVTT isn't used, it's nice just to delete the whole package at
import time, which requires that this dependency be removed.
This commit is contained in:
Oliver Woodman 2015-05-22 21:36:35 +01:00
parent efd0b1e3cf
commit 79d557dd80
3 changed files with 24 additions and 21 deletions

View File

@ -84,6 +84,22 @@ public final class C {
*/
public static final int RESULT_END_OF_INPUT = -1;
/**
* A prefix for custom ExoPlayer WebVTT headers.
*
* @hide
*/
public static final String WEBVTT_EXO_HEADER = "EXO-HEADER";
/**
* An element of a custom ExoPlayer WebVTT header. An {@code WEBVTT_OFFSET + value} element can
* be added to a custom ExoPlayer WebVTT header to specify an offset time (in microseconds) that
* should be subtracted from the embedded MPEGTS value.
*
* @hide
*/
public static final String WEBVTT_EXO_HEADER_OFFSET = "OFFSET:";
private C() {}
}

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer.dash;
import com.google.android.exoplayer.BehindLiveWindowException;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.TimeRange;
import com.google.android.exoplayer.TrackInfo;
@ -43,7 +44,6 @@ import com.google.android.exoplayer.extractor.ChunkIndex;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.extractor.mp4.FragmentedMp4Extractor;
import com.google.android.exoplayer.extractor.webm.WebmExtractor;
import com.google.android.exoplayer.text.webvtt.WebvttParser;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DataSpec;
import com.google.android.exoplayer.util.Clock;
@ -566,8 +566,9 @@ public class DashChunkSource implements ChunkSource {
if (representationHolder.vttHeaderOffsetUs != presentationTimeOffsetUs) {
// Update the VTT header.
headerBuilder.setLength(0);
headerBuilder.append(WebvttParser.EXO_HEADER).append("=")
.append(WebvttParser.OFFSET).append(presentationTimeOffsetUs).append("\n");
headerBuilder.append(C.WEBVTT_EXO_HEADER).append("=")
.append(C.WEBVTT_EXO_HEADER_OFFSET).append(presentationTimeOffsetUs)
.append("\n");
representationHolder.vttHeader = headerBuilder.toString().getBytes();
representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs;
}

View File

@ -40,22 +40,7 @@ import java.util.regex.Pattern;
*/
public class WebvttParser implements SubtitleParser {
static final String TAG = "WebvttParser";
/**
* This parser allows a custom header to be prepended to the WebVTT data, in the form of a text
* line starting with this string.
*
* @hide
*/
public static final String EXO_HEADER = "EXO-HEADER";
/**
* A {@code OFFSET + value} element can be added to the custom header to specify an offset time
* (in microseconds) that should be subtracted from the embedded MPEGTS value.
*
* @hide
*/
public static final String OFFSET = "OFFSET:";
private static final String TAG = "WebvttParser";
private static final long SAMPLING_RATE = 90;
@ -73,7 +58,8 @@ public class WebvttParser implements SubtitleParser {
private static final String WEBVTT_CUE_SETTING_STRING = "\\S*:\\S*";
private static final Pattern WEBVTT_CUE_SETTING = Pattern.compile(WEBVTT_CUE_SETTING_STRING);
private static final Pattern MEDIA_TIMESTAMP_OFFSET = Pattern.compile(OFFSET + "\\d+");
private static final Pattern MEDIA_TIMESTAMP_OFFSET =
Pattern.compile(C.WEBVTT_EXO_HEADER_OFFSET + "\\d+");
private static final Pattern MEDIA_TIMESTAMP = Pattern.compile("MPEGTS:\\d+");
private static final String NON_NUMERIC_STRING = ".*[^0-9].*";
@ -108,7 +94,7 @@ public class WebvttParser implements SubtitleParser {
throw new ParserException("Expected WEBVTT or EXO-HEADER. Got null");
}
if (line.startsWith(EXO_HEADER)) {
if (line.startsWith(C.WEBVTT_EXO_HEADER)) {
// parse the timestamp offset, if present
Matcher matcher = MEDIA_TIMESTAMP_OFFSET.matcher(line);
if (matcher.find()) {