mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Unwrap all nested IntDef values
This seems to work with R8 but interact badly with ProGuard. issue:#6771 PiperOrigin-RevId: 286215262
This commit is contained in:
parent
1106aba351
commit
5d2ca02c5a
@ -59,9 +59,7 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||
|
||||
/**
|
||||
* Thrown when a failure occurs instantiating a decoder.
|
||||
*/
|
||||
/** Thrown when a failure occurs instantiating a decoder. */
|
||||
public static class DecoderInitializationException extends Exception {
|
||||
|
||||
private static final int CUSTOM_ERROR_CODE_BASE = -50000;
|
||||
|
@ -300,12 +300,12 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
|
||||
float screenWidth,
|
||||
float screenHeight) {
|
||||
@SsaStyle.SsaAlignment int alignment;
|
||||
if (styleOverrides.alignment != SsaStyle.SsaAlignment.UNKNOWN) {
|
||||
if (styleOverrides.alignment != SsaStyle.SSA_ALIGNMENT_UNKNOWN) {
|
||||
alignment = styleOverrides.alignment;
|
||||
} else if (style != null) {
|
||||
alignment = style.alignment;
|
||||
} else {
|
||||
alignment = SsaStyle.SsaAlignment.UNKNOWN;
|
||||
alignment = SsaStyle.SSA_ALIGNMENT_UNKNOWN;
|
||||
}
|
||||
@Cue.AnchorType int positionAnchor = toPositionAnchor(alignment);
|
||||
@Cue.AnchorType int lineAnchor = toLineAnchor(alignment);
|
||||
@ -337,19 +337,19 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
|
||||
@Nullable
|
||||
private static Layout.Alignment toTextAlignment(@SsaStyle.SsaAlignment int alignment) {
|
||||
switch (alignment) {
|
||||
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
|
||||
case SsaStyle.SsaAlignment.TOP_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
|
||||
return Layout.Alignment.ALIGN_NORMAL;
|
||||
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
|
||||
case SsaStyle.SsaAlignment.TOP_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
|
||||
return Layout.Alignment.ALIGN_CENTER;
|
||||
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
|
||||
case SsaStyle.SsaAlignment.TOP_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
|
||||
return Layout.Alignment.ALIGN_OPPOSITE;
|
||||
case SsaStyle.SsaAlignment.UNKNOWN:
|
||||
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
|
||||
return null;
|
||||
default:
|
||||
Log.w(TAG, "Unknown alignment: " + alignment);
|
||||
@ -360,19 +360,19 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
|
||||
@Cue.AnchorType
|
||||
private static int toLineAnchor(@SsaStyle.SsaAlignment int alignment) {
|
||||
switch (alignment) {
|
||||
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
|
||||
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
|
||||
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
|
||||
return Cue.ANCHOR_TYPE_END;
|
||||
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
|
||||
return Cue.ANCHOR_TYPE_MIDDLE;
|
||||
case SsaStyle.SsaAlignment.TOP_LEFT:
|
||||
case SsaStyle.SsaAlignment.TOP_CENTER:
|
||||
case SsaStyle.SsaAlignment.TOP_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
|
||||
return Cue.ANCHOR_TYPE_START;
|
||||
case SsaStyle.SsaAlignment.UNKNOWN:
|
||||
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
|
||||
return Cue.TYPE_UNSET;
|
||||
default:
|
||||
Log.w(TAG, "Unknown alignment: " + alignment);
|
||||
@ -383,19 +383,19 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
|
||||
@Cue.AnchorType
|
||||
private static int toPositionAnchor(@SsaStyle.SsaAlignment int alignment) {
|
||||
switch (alignment) {
|
||||
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
|
||||
case SsaStyle.SsaAlignment.TOP_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
|
||||
return Cue.ANCHOR_TYPE_START;
|
||||
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
|
||||
case SsaStyle.SsaAlignment.TOP_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
|
||||
return Cue.ANCHOR_TYPE_MIDDLE;
|
||||
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
|
||||
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
|
||||
case SsaStyle.SsaAlignment.TOP_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
|
||||
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
|
||||
return Cue.ANCHOR_TYPE_END;
|
||||
case SsaStyle.SsaAlignment.UNKNOWN:
|
||||
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
|
||||
return Cue.TYPE_UNSET;
|
||||
default:
|
||||
Log.w(TAG, "Unknown alignment: " + alignment);
|
||||
|
@ -37,6 +37,52 @@ import java.util.regex.Pattern;
|
||||
|
||||
private static final String TAG = "SsaStyle";
|
||||
|
||||
/**
|
||||
* The SSA/ASS alignments.
|
||||
*
|
||||
* <p>Allowed values:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #SSA_ALIGNMENT_UNKNOWN}
|
||||
* <li>{@link #SSA_ALIGNMENT_BOTTOM_LEFT}
|
||||
* <li>{@link #SSA_ALIGNMENT_BOTTOM_CENTER}
|
||||
* <li>{@link #SSA_ALIGNMENT_BOTTOM_RIGHT}
|
||||
* <li>{@link #SSA_ALIGNMENT_MIDDLE_LEFT}
|
||||
* <li>{@link #SSA_ALIGNMENT_MIDDLE_CENTER}
|
||||
* <li>{@link #SSA_ALIGNMENT_MIDDLE_RIGHT}
|
||||
* <li>{@link #SSA_ALIGNMENT_TOP_LEFT}
|
||||
* <li>{@link #SSA_ALIGNMENT_TOP_CENTER}
|
||||
* <li>{@link #SSA_ALIGNMENT_TOP_RIGHT}
|
||||
* </ul>
|
||||
*/
|
||||
@IntDef({
|
||||
SSA_ALIGNMENT_UNKNOWN,
|
||||
SSA_ALIGNMENT_BOTTOM_LEFT,
|
||||
SSA_ALIGNMENT_BOTTOM_CENTER,
|
||||
SSA_ALIGNMENT_BOTTOM_RIGHT,
|
||||
SSA_ALIGNMENT_MIDDLE_LEFT,
|
||||
SSA_ALIGNMENT_MIDDLE_CENTER,
|
||||
SSA_ALIGNMENT_MIDDLE_RIGHT,
|
||||
SSA_ALIGNMENT_TOP_LEFT,
|
||||
SSA_ALIGNMENT_TOP_CENTER,
|
||||
SSA_ALIGNMENT_TOP_RIGHT,
|
||||
})
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
public @interface SsaAlignment {}
|
||||
|
||||
// The numbering follows the ASS (v4+) spec (i.e. the points on the number pad).
|
||||
public static final int SSA_ALIGNMENT_UNKNOWN = -1;
|
||||
public static final int SSA_ALIGNMENT_BOTTOM_LEFT = 1;
|
||||
public static final int SSA_ALIGNMENT_BOTTOM_CENTER = 2;
|
||||
public static final int SSA_ALIGNMENT_BOTTOM_RIGHT = 3;
|
||||
public static final int SSA_ALIGNMENT_MIDDLE_LEFT = 4;
|
||||
public static final int SSA_ALIGNMENT_MIDDLE_CENTER = 5;
|
||||
public static final int SSA_ALIGNMENT_MIDDLE_RIGHT = 6;
|
||||
public static final int SSA_ALIGNMENT_TOP_LEFT = 7;
|
||||
public static final int SSA_ALIGNMENT_TOP_CENTER = 8;
|
||||
public static final int SSA_ALIGNMENT_TOP_RIGHT = 9;
|
||||
|
||||
public final String name;
|
||||
@SsaAlignment public final int alignment;
|
||||
|
||||
@ -77,22 +123,22 @@ import java.util.regex.Pattern;
|
||||
// Swallow the exception and return UNKNOWN below.
|
||||
}
|
||||
Log.w(TAG, "Ignoring unknown alignment: " + alignmentStr);
|
||||
return SsaAlignment.UNKNOWN;
|
||||
return SSA_ALIGNMENT_UNKNOWN;
|
||||
}
|
||||
|
||||
private static boolean isValidAlignment(@SsaAlignment int alignment) {
|
||||
switch (alignment) {
|
||||
case SsaAlignment.BOTTOM_CENTER:
|
||||
case SsaAlignment.BOTTOM_LEFT:
|
||||
case SsaAlignment.BOTTOM_RIGHT:
|
||||
case SsaAlignment.MIDDLE_CENTER:
|
||||
case SsaAlignment.MIDDLE_LEFT:
|
||||
case SsaAlignment.MIDDLE_RIGHT:
|
||||
case SsaAlignment.TOP_CENTER:
|
||||
case SsaAlignment.TOP_LEFT:
|
||||
case SsaAlignment.TOP_RIGHT:
|
||||
case SSA_ALIGNMENT_BOTTOM_CENTER:
|
||||
case SSA_ALIGNMENT_BOTTOM_LEFT:
|
||||
case SSA_ALIGNMENT_BOTTOM_RIGHT:
|
||||
case SSA_ALIGNMENT_MIDDLE_CENTER:
|
||||
case SSA_ALIGNMENT_MIDDLE_LEFT:
|
||||
case SSA_ALIGNMENT_MIDDLE_RIGHT:
|
||||
case SSA_ALIGNMENT_TOP_CENTER:
|
||||
case SSA_ALIGNMENT_TOP_LEFT:
|
||||
case SSA_ALIGNMENT_TOP_RIGHT:
|
||||
return true;
|
||||
case SsaAlignment.UNKNOWN:
|
||||
case SSA_ALIGNMENT_UNKNOWN:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -177,7 +223,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
|
||||
public static Overrides parseFromDialogue(String text) {
|
||||
@SsaAlignment int alignment = SsaAlignment.UNKNOWN;
|
||||
@SsaAlignment int alignment = SSA_ALIGNMENT_UNKNOWN;
|
||||
PointF position = null;
|
||||
Matcher matcher = BRACES_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
@ -192,7 +238,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
try {
|
||||
@SsaAlignment int parsedAlignment = parseAlignmentOverride(braceContents);
|
||||
if (parsedAlignment != SsaAlignment.UNKNOWN) {
|
||||
if (parsedAlignment != SSA_ALIGNMENT_UNKNOWN) {
|
||||
alignment = parsedAlignment;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
@ -249,36 +295,7 @@ import java.util.regex.Pattern;
|
||||
@SsaAlignment
|
||||
private static int parseAlignmentOverride(String braceContents) {
|
||||
Matcher matcher = ALIGNMENT_OVERRIDE_PATTERN.matcher(braceContents);
|
||||
return matcher.find() ? parseAlignment(matcher.group(1)) : SsaAlignment.UNKNOWN;
|
||||
return matcher.find() ? parseAlignment(matcher.group(1)) : SSA_ALIGNMENT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/** The SSA/ASS alignments. */
|
||||
@IntDef({
|
||||
SsaAlignment.UNKNOWN,
|
||||
SsaAlignment.BOTTOM_LEFT,
|
||||
SsaAlignment.BOTTOM_CENTER,
|
||||
SsaAlignment.BOTTOM_RIGHT,
|
||||
SsaAlignment.MIDDLE_LEFT,
|
||||
SsaAlignment.MIDDLE_CENTER,
|
||||
SsaAlignment.MIDDLE_RIGHT,
|
||||
SsaAlignment.TOP_LEFT,
|
||||
SsaAlignment.TOP_CENTER,
|
||||
SsaAlignment.TOP_RIGHT,
|
||||
})
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
/* package */ @interface SsaAlignment {
|
||||
// The numbering follows the ASS (v4+) spec (i.e. the points on the number pad).
|
||||
int UNKNOWN = -1;
|
||||
int BOTTOM_LEFT = 1;
|
||||
int BOTTOM_CENTER = 2;
|
||||
int BOTTOM_RIGHT = 3;
|
||||
int MIDDLE_LEFT = 4;
|
||||
int MIDDLE_CENTER = 5;
|
||||
int MIDDLE_RIGHT = 6;
|
||||
int TOP_LEFT = 7;
|
||||
int TOP_CENTER = 8;
|
||||
int TOP_RIGHT = 9;
|
||||
}
|
||||
}
|
||||
|
@ -77,39 +77,40 @@ public final class WebvttCue extends Cue {
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
@IntDef({
|
||||
TextAlignment.START,
|
||||
TextAlignment.CENTER,
|
||||
TextAlignment.END,
|
||||
TextAlignment.LEFT,
|
||||
TextAlignment.RIGHT
|
||||
TEXT_ALIGNMENT_START,
|
||||
TEXT_ALIGNMENT_CENTER,
|
||||
TEXT_ALIGNMENT_END,
|
||||
TEXT_ALIGNMENT_LEFT,
|
||||
TEXT_ALIGNMENT_RIGHT
|
||||
})
|
||||
public @interface TextAlignment {
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-start-alignment">align:start</a>.
|
||||
*/
|
||||
int START = 1;
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-center-alignment">align:center</a>.
|
||||
*/
|
||||
int CENTER = 2;
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-end-alignment">align:end</a>.
|
||||
*/
|
||||
int END = 3;
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-left-alignment">align:left</a>.
|
||||
*/
|
||||
int LEFT = 4;
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-right-alignment">align:right</a>.
|
||||
*/
|
||||
int RIGHT = 5;
|
||||
}
|
||||
public @interface TextAlignment {}
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-start-alignment">align:start</a>.
|
||||
*/
|
||||
public static final int TEXT_ALIGNMENT_START = 1;
|
||||
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-center-alignment">align:center</a>.
|
||||
*/
|
||||
public static final int TEXT_ALIGNMENT_CENTER = 2;
|
||||
|
||||
/**
|
||||
* See WebVTT's <a href="https://www.w3.org/TR/webvtt1/#webvtt-cue-end-alignment">align:end</a>.
|
||||
*/
|
||||
public static final int TEXT_ALIGNMENT_END = 3;
|
||||
|
||||
/**
|
||||
* See WebVTT's <a href="https://www.w3.org/TR/webvtt1/#webvtt-cue-left-alignment">align:left</a>.
|
||||
*/
|
||||
public static final int TEXT_ALIGNMENT_LEFT = 4;
|
||||
|
||||
/**
|
||||
* See WebVTT's <a
|
||||
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-right-alignment">align:right</a>.
|
||||
*/
|
||||
public static final int TEXT_ALIGNMENT_RIGHT = 5;
|
||||
|
||||
private static final String TAG = "WebvttCueBuilder";
|
||||
|
||||
@ -140,7 +141,7 @@ public final class WebvttCue extends Cue {
|
||||
endTime = 0;
|
||||
text = null;
|
||||
// Default: https://www.w3.org/TR/webvtt1/#webvtt-cue-text-alignment
|
||||
textAlignment = TextAlignment.CENTER;
|
||||
textAlignment = TEXT_ALIGNMENT_CENTER;
|
||||
line = Cue.DIMEN_UNSET;
|
||||
// Defaults to NUMBER (true): https://www.w3.org/TR/webvtt1/#webvtt-cue-snap-to-lines-flag
|
||||
lineType = Cue.LINE_TYPE_NUMBER;
|
||||
@ -251,13 +252,13 @@ public final class WebvttCue extends Cue {
|
||||
// https://www.w3.org/TR/webvtt1/#webvtt-cue-position
|
||||
private static float derivePosition(@TextAlignment int textAlignment) {
|
||||
switch (textAlignment) {
|
||||
case TextAlignment.LEFT:
|
||||
case TEXT_ALIGNMENT_LEFT:
|
||||
return 0.0f;
|
||||
case TextAlignment.RIGHT:
|
||||
case TEXT_ALIGNMENT_RIGHT:
|
||||
return 1.0f;
|
||||
case TextAlignment.START:
|
||||
case TextAlignment.CENTER:
|
||||
case TextAlignment.END:
|
||||
case TEXT_ALIGNMENT_START:
|
||||
case TEXT_ALIGNMENT_CENTER:
|
||||
case TEXT_ALIGNMENT_END:
|
||||
default:
|
||||
return DEFAULT_POSITION;
|
||||
}
|
||||
@ -267,13 +268,13 @@ public final class WebvttCue extends Cue {
|
||||
@AnchorType
|
||||
private static int derivePositionAnchor(@TextAlignment int textAlignment) {
|
||||
switch (textAlignment) {
|
||||
case TextAlignment.LEFT:
|
||||
case TextAlignment.START:
|
||||
case TEXT_ALIGNMENT_LEFT:
|
||||
case TEXT_ALIGNMENT_START:
|
||||
return Cue.ANCHOR_TYPE_START;
|
||||
case TextAlignment.RIGHT:
|
||||
case TextAlignment.END:
|
||||
case TEXT_ALIGNMENT_RIGHT:
|
||||
case TEXT_ALIGNMENT_END:
|
||||
return Cue.ANCHOR_TYPE_END;
|
||||
case TextAlignment.CENTER:
|
||||
case TEXT_ALIGNMENT_CENTER:
|
||||
default:
|
||||
return Cue.ANCHOR_TYPE_MIDDLE;
|
||||
}
|
||||
@ -282,13 +283,13 @@ public final class WebvttCue extends Cue {
|
||||
@Nullable
|
||||
private static Alignment convertTextAlignment(@TextAlignment int textAlignment) {
|
||||
switch (textAlignment) {
|
||||
case TextAlignment.START:
|
||||
case TextAlignment.LEFT:
|
||||
case TEXT_ALIGNMENT_START:
|
||||
case TEXT_ALIGNMENT_LEFT:
|
||||
return Alignment.ALIGN_NORMAL;
|
||||
case TextAlignment.CENTER:
|
||||
case TEXT_ALIGNMENT_CENTER:
|
||||
return Alignment.ALIGN_CENTER;
|
||||
case TextAlignment.END:
|
||||
case TextAlignment.RIGHT:
|
||||
case TEXT_ALIGNMENT_END:
|
||||
case TEXT_ALIGNMENT_RIGHT:
|
||||
return Alignment.ALIGN_OPPOSITE;
|
||||
default:
|
||||
Log.w(TAG, "Unknown textAlignment: " + textAlignment);
|
||||
|
@ -308,20 +308,20 @@ public final class WebvttCueParser {
|
||||
private static int parseTextAlignment(String s) {
|
||||
switch (s) {
|
||||
case "start":
|
||||
return WebvttCue.Builder.TextAlignment.START;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_START;
|
||||
case "left":
|
||||
return WebvttCue.Builder.TextAlignment.LEFT;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_LEFT;
|
||||
case "center":
|
||||
case "middle":
|
||||
return WebvttCue.Builder.TextAlignment.CENTER;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_CENTER;
|
||||
case "end":
|
||||
return WebvttCue.Builder.TextAlignment.END;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_END;
|
||||
case "right":
|
||||
return WebvttCue.Builder.TextAlignment.RIGHT;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_RIGHT;
|
||||
default:
|
||||
Log.w(TAG, "Invalid alignment value: " + s);
|
||||
// Default value: https://www.w3.org/TR/webvtt1/#webvtt-cue-text-alignment
|
||||
return WebvttCue.Builder.TextAlignment.CENTER;
|
||||
return WebvttCue.Builder.TEXT_ALIGNMENT_CENTER;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
private final TimestampAdjusterProvider timestampAdjusterProvider;
|
||||
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||
private final boolean allowChunklessPreparation;
|
||||
private final @HlsMetadataType int metadataType;
|
||||
private final @HlsMediaSource.MetadataType int metadataType;
|
||||
private final boolean useSessionKeys;
|
||||
|
||||
@Nullable private Callback callback;
|
||||
@ -118,7 +118,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
Allocator allocator,
|
||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||
boolean allowChunklessPreparation,
|
||||
@HlsMetadataType int metadataType,
|
||||
@HlsMediaSource.MetadataType int metadataType,
|
||||
boolean useSessionKeys) {
|
||||
this.extractorFactory = extractorFactory;
|
||||
this.playlistTracker = playlistTracker;
|
||||
|
@ -15,8 +15,11 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.source.hls;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||
@ -47,6 +50,8 @@ import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.List;
|
||||
|
||||
/** An HLS {@link MediaSource}. */
|
||||
@ -57,6 +62,28 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
ExoPlayerLibraryInfo.registerModule("goog.exo.hls");
|
||||
}
|
||||
|
||||
/**
|
||||
* The types of metadata that can be extracted from HLS streams.
|
||||
*
|
||||
* <p>Allowed values:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #METADATA_TYPE_ID3}
|
||||
* <li>{@link #METADATA_TYPE_EMSG}
|
||||
* </ul>
|
||||
*
|
||||
* <p>See {@link Factory#setMetadataType(int)}.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
@IntDef({METADATA_TYPE_ID3, METADATA_TYPE_EMSG})
|
||||
public @interface MetadataType {}
|
||||
|
||||
/** Type for ID3 metadata in HLS streams. */
|
||||
public static final int METADATA_TYPE_ID3 = 1;
|
||||
/** Type for ESMG metadata in HLS streams. */
|
||||
public static final int METADATA_TYPE_EMSG = 3;
|
||||
|
||||
/** Factory for {@link HlsMediaSource}s. */
|
||||
public static final class Factory implements MediaSourceFactory {
|
||||
|
||||
@ -70,7 +97,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
private DrmSessionManager<?> drmSessionManager;
|
||||
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
private boolean allowChunklessPreparation;
|
||||
@HlsMetadataType private int metadataType;
|
||||
@MetadataType private int metadataType;
|
||||
private boolean useSessionKeys;
|
||||
private boolean isCreateCalled;
|
||||
@Nullable private Object tag;
|
||||
@ -100,7 +127,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
||||
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
||||
metadataType = HlsMetadataType.ID3;
|
||||
metadataType = METADATA_TYPE_ID3;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,24 +273,24 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
|
||||
/**
|
||||
* Sets the type of metadata to extract from the HLS source (defaults to {@link
|
||||
* HlsMetadataType#ID3}).
|
||||
* #METADATA_TYPE_ID3}).
|
||||
*
|
||||
* <p>HLS supports in-band ID3 in both TS and fMP4 streams, but in the fMP4 case the data is
|
||||
* wrapped in an EMSG box [<a href="https://aomediacodec.github.io/av1-id3/">spec</a>].
|
||||
*
|
||||
* <p>If this is set to {@link HlsMetadataType#ID3} then raw ID3 metadata of will be extracted
|
||||
* <p>If this is set to {@link #METADATA_TYPE_ID3} then raw ID3 metadata of will be extracted
|
||||
* from TS sources. From fMP4 streams EMSGs containing metadata of this type (in the variant
|
||||
* stream only) will be unwrapped to expose the inner data. All other in-band metadata will be
|
||||
* dropped.
|
||||
*
|
||||
* <p>If this is set to {@link HlsMetadataType#EMSG} then all EMSG data from the fMP4 variant
|
||||
* <p>If this is set to {@link #METADATA_TYPE_EMSG} then all EMSG data from the fMP4 variant
|
||||
* stream will be extracted. No metadata will be extracted from TS streams, since they don't
|
||||
* support EMSG.
|
||||
*
|
||||
* @param metadataType The type of metadata to extract.
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
public Factory setMetadataType(@HlsMetadataType int metadataType) {
|
||||
public Factory setMetadataType(@MetadataType int metadataType) {
|
||||
Assertions.checkState(!isCreateCalled);
|
||||
this.metadataType = metadataType;
|
||||
return this;
|
||||
@ -347,7 +374,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
private final DrmSessionManager<?> drmSessionManager;
|
||||
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
private final boolean allowChunklessPreparation;
|
||||
private final @HlsMetadataType int metadataType;
|
||||
private final @MetadataType int metadataType;
|
||||
private final boolean useSessionKeys;
|
||||
private final HlsPlaylistTracker playlistTracker;
|
||||
@Nullable private final Object tag;
|
||||
@ -363,7 +390,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||
HlsPlaylistTracker playlistTracker,
|
||||
boolean allowChunklessPreparation,
|
||||
@HlsMetadataType int metadataType,
|
||||
@MetadataType int metadataType,
|
||||
boolean useSessionKeys,
|
||||
@Nullable Object tag) {
|
||||
this.manifestUri = manifestUri;
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.exoplayer2.source.hls;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
/**
|
||||
* The types of metadata that can be extracted from HLS streams.
|
||||
*
|
||||
* <p>See {@link HlsMediaSource.Factory#setMetadataType(int)}.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
@IntDef({HlsMetadataType.ID3, HlsMetadataType.EMSG})
|
||||
public @interface HlsMetadataType {
|
||||
/** Type for ID3 metadata in HLS streams. */
|
||||
int ID3 = 1;
|
||||
/** Type for ESMG metadata in HLS streams. */
|
||||
int EMSG = 3;
|
||||
}
|
@ -116,7 +116,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
private final Loader loader;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final @HlsMetadataType int metadataType;
|
||||
private final @HlsMediaSource.MetadataType int metadataType;
|
||||
private final HlsChunkSource.HlsChunkHolder nextChunkHolder;
|
||||
private final ArrayList<HlsMediaChunk> mediaChunks;
|
||||
private final List<HlsMediaChunk> readOnlyMediaChunks;
|
||||
@ -190,7 +190,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
DrmSessionManager<?> drmSessionManager,
|
||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||
EventDispatcher eventDispatcher,
|
||||
@HlsMetadataType int metadataType) {
|
||||
@HlsMediaSource.MetadataType int metadataType) {
|
||||
this.trackType = trackType;
|
||||
this.callback = callback;
|
||||
this.chunkSource = chunkSource;
|
||||
@ -1362,14 +1362,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
private byte[] buffer;
|
||||
private int bufferPosition;
|
||||
|
||||
public EmsgUnwrappingTrackOutput(TrackOutput delegate, @HlsMetadataType int metadataType) {
|
||||
public EmsgUnwrappingTrackOutput(
|
||||
TrackOutput delegate, @HlsMediaSource.MetadataType int metadataType) {
|
||||
this.emsgDecoder = new EventMessageDecoder();
|
||||
this.delegate = delegate;
|
||||
switch (metadataType) {
|
||||
case HlsMetadataType.ID3:
|
||||
case HlsMediaSource.METADATA_TYPE_ID3:
|
||||
delegateFormat = ID3_FORMAT;
|
||||
break;
|
||||
case HlsMetadataType.EMSG:
|
||||
case HlsMediaSource.METADATA_TYPE_EMSG:
|
||||
delegateFormat = EMSG_FORMAT;
|
||||
break;
|
||||
default:
|
||||
|
@ -92,7 +92,7 @@ public final class HlsMediaPeriodTest {
|
||||
mock(Allocator.class),
|
||||
mock(CompositeSequenceableLoaderFactory.class),
|
||||
/* allowChunklessPreparation =*/ true,
|
||||
HlsMetadataType.ID3,
|
||||
HlsMediaSource.METADATA_TYPE_ID3,
|
||||
/* useSessionKeys= */ false);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user