From 2dfe7a7ad6a784482b8de094c41b7815a09444b8 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Wed, 31 Oct 2018 20:37:59 +0000 Subject: [PATCH] Misc fixes / stylistic consistency changes for merged pull requests --- .../ext/cronet/CronetDataSource.java | 5 +- .../exoplayer2/upstream/HttpDataSource.java | 11 ++- .../DefaultLoadErrorHandlingPolicyTest.java | 6 +- .../source/dash/manifest/DashManifest.java | 74 ++++++++++++++++--- .../dash/manifest/DashManifestParser.java | 58 +++++++++++---- .../dash/manifest/ProgramInformation.java | 40 ++++------ .../dash/manifest/DashManifestParserTest.java | 12 +-- .../dash/manifest/DashManifestTest.java | 13 +++- .../hls/playlist/HlsPlaylistParser.java | 2 +- 9 files changed, 155 insertions(+), 66 deletions(-) diff --git a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java index 9f381d0053..af85401100 100644 --- a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java +++ b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java @@ -616,10 +616,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { if (responseCode == 307 || responseCode == 308) { exception = new InvalidResponseCodeException( - responseCode, - info.getHttpStatusText(), - info.getAllHeaders(), - currentDataSpec); + responseCode, info.getHttpStatusText(), info.getAllHeaders(), currentDataSpec); operation.open(); return; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java index e73901eccb..e3e93bd6fb 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java @@ -295,9 +295,7 @@ public interface HttpDataSource extends DataSource { */ public final int responseCode; - /** - * The HTTP status message. - */ + /** The http status message. */ @Nullable public final String responseMessage; /** @@ -305,6 +303,13 @@ public interface HttpDataSource extends DataSource { */ public final Map> headerFields; + /** @deprecated Use {@link #InvalidResponseCodeException(int, String, Map, DataSpec)}. */ + @Deprecated + public InvalidResponseCodeException( + int responseCode, Map> headerFields, DataSpec dataSpec) { + this(responseCode, /* responseMessage= */ null, headerFields, dataSpec); + } + public InvalidResponseCodeException( int responseCode, @Nullable String responseMessage, diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java index f0f737828c..cf30fce3a6 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultLoadErrorHandlingPolicyTest.java @@ -34,7 +34,8 @@ public final class DefaultLoadErrorHandlingPolicyTest { @Test public void getBlacklistDurationMsFor_blacklist404() { InvalidResponseCodeException exception = - new InvalidResponseCodeException(404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); + new InvalidResponseCodeException( + 404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); assertThat(getDefaultPolicyBlacklistOutputFor(exception)) .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); } @@ -42,7 +43,8 @@ public final class DefaultLoadErrorHandlingPolicyTest { @Test public void getBlacklistDurationMsFor_blacklist410() { InvalidResponseCodeException exception = - new InvalidResponseCodeException(410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); + new InvalidResponseCodeException( + 410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY)); assertThat(getDefaultPolicyBlacklistOutputFor(exception)) .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); } diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java index 6446909808..3637b80ecb 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java @@ -16,6 +16,7 @@ package com.google.android.exoplayer2.source.dash.manifest; import android.net.Uri; +import android.support.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.offline.FilterableManifest; import com.google.android.exoplayer2.offline.StreamKey; @@ -86,17 +87,56 @@ public class DashManifest implements FilterableManifest { */ public final Uri location; - /** - * The ProgramInformation of this manifest. - */ - public final ProgramInformation programInformation; + /** The {@link ProgramInformation}, or null if not present. */ + @Nullable public final ProgramInformation programInformation; private final List periods; - public DashManifest(long availabilityStartTimeMs, long durationMs, long minBufferTimeMs, - boolean dynamic, long minUpdatePeriodMs, long timeShiftBufferDepthMs, - long suggestedPresentationDelayMs, long publishTimeMs, UtcTimingElement utcTiming, - Uri location, ProgramInformation programInformation, List periods) { + /** + * @deprecated Use {@link #DashManifest(long, long, long, boolean, long, long, long, long, + * ProgramInformation, UtcTimingElement, Uri, List)}. + */ + @Deprecated + public DashManifest( + long availabilityStartTimeMs, + long durationMs, + long minBufferTimeMs, + boolean dynamic, + long minUpdatePeriodMs, + long timeShiftBufferDepthMs, + long suggestedPresentationDelayMs, + long publishTimeMs, + UtcTimingElement utcTiming, + Uri location, + List periods) { + this( + availabilityStartTimeMs, + durationMs, + minBufferTimeMs, + dynamic, + minUpdatePeriodMs, + timeShiftBufferDepthMs, + suggestedPresentationDelayMs, + publishTimeMs, + /* programInformation= */ null, + utcTiming, + location, + periods); + } + + public DashManifest( + long availabilityStartTimeMs, + long durationMs, + long minBufferTimeMs, + boolean dynamic, + long minUpdatePeriodMs, + long timeShiftBufferDepthMs, + long suggestedPresentationDelayMs, + long publishTimeMs, + @Nullable ProgramInformation programInformation, + UtcTimingElement utcTiming, + Uri location, + List periods) { this.availabilityStartTimeMs = availabilityStartTimeMs; this.durationMs = durationMs; this.minBufferTimeMs = minBufferTimeMs; @@ -105,9 +145,9 @@ public class DashManifest implements FilterableManifest { this.timeShiftBufferDepthMs = timeShiftBufferDepthMs; this.suggestedPresentationDelayMs = suggestedPresentationDelayMs; this.publishTimeMs = publishTimeMs; + this.programInformation = programInformation; this.utcTiming = utcTiming; this.location = location; - this.programInformation = programInformation; this.periods = periods == null ? Collections.emptyList() : periods; } @@ -154,9 +194,19 @@ public class DashManifest implements FilterableManifest { } } long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET; - return new DashManifest(availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic, - minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs, - utcTiming, location, programInformation, copyPeriods); + return new DashManifest( + availabilityStartTimeMs, + newDuration, + minBufferTimeMs, + dynamic, + minUpdatePeriodMs, + timeShiftBufferDepthMs, + suggestedPresentationDelayMs, + publishTimeMs, + programInformation, + utcTiming, + location, + copyPeriods); } private static ArrayList copyAdaptationSets( diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java index d048e22b33..f017ae64ad 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java @@ -120,9 +120,9 @@ public class DashManifestParser extends DefaultHandler long suggestedPresentationDelayMs = dynamic ? parseDuration(xpp, "suggestedPresentationDelay", C.TIME_UNSET) : C.TIME_UNSET; long publishTimeMs = parseDateTime(xpp, "publishTime", C.TIME_UNSET); + ProgramInformation programInformation = null; UtcTimingElement utcTiming = null; Uri location = null; - ProgramInformation programInformation = null; List periods = new ArrayList<>(); long nextPeriodStartMs = dynamic ? C.TIME_UNSET : 0; @@ -135,12 +135,12 @@ public class DashManifestParser extends DefaultHandler baseUrl = parseBaseUrl(xpp, baseUrl); seenFirstBaseUrl = true; } + } else if (XmlPullParserUtil.isStartTag(xpp, "ProgramInformation")) { + programInformation = parseProgramInformation(xpp); } else if (XmlPullParserUtil.isStartTag(xpp, "UTCTiming")) { utcTiming = parseUtcTiming(xpp); } else if (XmlPullParserUtil.isStartTag(xpp, "Location")) { location = Uri.parse(xpp.nextText()); - } else if (XmlPullParserUtil.isStartTag(xpp, "ProgramInformation")) { - programInformation = parseProgramInformation(xpp); } else if (XmlPullParserUtil.isStartTag(xpp, "Period") && !seenEarlyAccessPeriod) { Pair periodWithDurationMs = parsePeriod(xpp, baseUrl, nextPeriodStartMs); Period period = periodWithDurationMs.first; @@ -176,18 +176,47 @@ public class DashManifestParser extends DefaultHandler throw new ParserException("No periods found."); } - return buildMediaPresentationDescription(availabilityStartTime, durationMs, minBufferTimeMs, - dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, - publishTimeMs, utcTiming, location, programInformation, periods); + return buildMediaPresentationDescription( + availabilityStartTime, + durationMs, + minBufferTimeMs, + dynamic, + minUpdateTimeMs, + timeShiftBufferDepthMs, + suggestedPresentationDelayMs, + publishTimeMs, + programInformation, + utcTiming, + location, + periods); } - protected DashManifest buildMediaPresentationDescription(long availabilityStartTime, - long durationMs, long minBufferTimeMs, boolean dynamic, long minUpdateTimeMs, - long timeShiftBufferDepthMs, long suggestedPresentationDelayMs, long publishTimeMs, - UtcTimingElement utcTiming, Uri location, ProgramInformation programInformation, List periods) { - return new DashManifest(availabilityStartTime, durationMs, minBufferTimeMs, - dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, - publishTimeMs, utcTiming, location, programInformation, periods); + protected DashManifest buildMediaPresentationDescription( + long availabilityStartTime, + long durationMs, + long minBufferTimeMs, + boolean dynamic, + long minUpdateTimeMs, + long timeShiftBufferDepthMs, + long suggestedPresentationDelayMs, + long publishTimeMs, + ProgramInformation programInformation, + UtcTimingElement utcTiming, + Uri location, + List periods) { + return new DashManifest( + availabilityStartTime, + durationMs, + minBufferTimeMs, + dynamic, + minUpdateTimeMs, + timeShiftBufferDepthMs, + suggestedPresentationDelayMs, + publishTimeMs, + programInformation, + utcTiming, + location, + periods); } protected UtcTimingElement parseUtcTiming(XmlPullParser xpp) { @@ -1001,7 +1030,8 @@ public class DashManifestParser extends DefaultHandler return new RangedUri(urlText, rangeStart, rangeLength); } - protected ProgramInformation parseProgramInformation(XmlPullParser xpp) throws IOException, XmlPullParserException { + protected ProgramInformation parseProgramInformation(XmlPullParser xpp) + throws IOException, XmlPullParserException { String title = null; String source = null; String copyright = null; diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/ProgramInformation.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/ProgramInformation.java index 71b4af3a21..73e8ef986e 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/ProgramInformation.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/ProgramInformation.java @@ -17,36 +17,25 @@ package com.google.android.exoplayer2.source.dash.manifest; import com.google.android.exoplayer2.util.Util; -/** - * A parsed ProgramInformation element. - */ +/** A parsed program information element. */ public class ProgramInformation { - /** - * The title for the media presentation. - */ + /** The title for the media presentation. */ public final String title; - /** - * Information about the original source of the media presentation. - */ + /** Information about the original source of the media presentation. */ public final String source; - /** - * A copyright statement for the media presentation. - */ + /** A copyright statement for the media presentation. */ public final String copyright; - /** - * A URL that provides more information about the media presentation. - */ + /** A URL that provides more information about the media presentation. */ public final String moreInformationURL; - /** - * Declares the language code(s) for this ProgramInformation. - */ + /** Declares the language code(s) for this ProgramInformation. */ public final String lang; - public ProgramInformation(String title, String source, String copyright, String moreInformationURL, String lang) { + public ProgramInformation( + String title, String source, String copyright, String moreInformationURL, String lang) { this.title = title; this.source = source; this.copyright = copyright; @@ -56,15 +45,18 @@ public class ProgramInformation { @Override public boolean equals(Object obj) { - if (!(obj instanceof ProgramInformation)) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { return false; } ProgramInformation other = (ProgramInformation) obj; return Util.areEqual(this.title, other.title) - && Util.areEqual(this.source, other.source) - && Util.areEqual(this.copyright, other.copyright) - && Util.areEqual(this.moreInformationURL, other.moreInformationURL) - && Util.areEqual(this.lang, other.lang); + && Util.areEqual(this.source, other.source) + && Util.areEqual(this.copyright, other.copyright) + && Util.areEqual(this.moreInformationURL, other.moreInformationURL) + && Util.areEqual(this.lang, other.lang); } @Override diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java index 3183e3c672..a1693f6985 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java @@ -25,7 +25,6 @@ import com.google.android.exoplayer2.testutil.TestUtil; import com.google.android.exoplayer2.util.Util; import java.io.IOException; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -156,11 +155,14 @@ public class DashManifestParserTest { @Test public void testParseMediaPresentationDescriptionCanParseProgramInformation() throws IOException { DashManifestParser parser = new DashManifestParser(); - DashManifest mpd = parser.parse(Uri.parse("Https://example.com/test.mpd"), + DashManifest mpd = + parser.parse( + Uri.parse("Https://example.com/test.mpd"), TestUtil.getInputStream(RuntimeEnvironment.application, SAMPLE_MPD_1)); - ProgramInformation programInformation = new ProgramInformation("MediaTitle", "MediaSource", - "MediaCopyright", "www.example.com", "enUs"); - assertThat(programInformation).isEqualTo(mpd.programInformation); + ProgramInformation expectedProgramInformation = + new ProgramInformation( + "MediaTitle", "MediaSource", "MediaCopyright", "www.example.com", "enUs"); + assertThat(mpd.programInformation).isEqualTo(expectedProgramInformation); } @Test diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestTest.java index 17a96fded3..0d08df42e9 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestTest.java @@ -219,7 +219,18 @@ public class DashManifestTest { private static DashManifest newDashManifest(int duration, Period... periods) { return new DashManifest( - 0, duration, 1, false, 2, 3, 4, 12345, DUMMY_UTC_TIMING, Uri.EMPTY, null, Arrays.asList(periods)); + /* availabilityStartTimeMs= */ 0, + duration, + /* minBufferTimeMs= */ 1, + /* dynamic= */ false, + /* minUpdatePeriodMs= */ 2, + /* timeShiftBufferDepthMs= */ 3, + /* suggestedPresentationDelayMs= */ 4, + /* publishTimeMs= */ 12345, + /* programInformation= */ null, + DUMMY_UTC_TIMING, + Uri.EMPTY, + Arrays.asList(periods)); } private static Period newPeriod(String id, int startMs, AdaptationSet... adaptationSets) { diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java index bd2bea0197..65f4796187 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylistParser.java @@ -341,7 +341,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser