Misc fixes / stylistic consistency changes for merged pull requests

This commit is contained in:
Oliver Woodman 2018-10-31 20:37:59 +00:00
parent 16326bae46
commit 2dfe7a7ad6
9 changed files with 155 additions and 66 deletions

View File

@ -616,10 +616,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
if (responseCode == 307 || responseCode == 308) { if (responseCode == 307 || responseCode == 308) {
exception = exception =
new InvalidResponseCodeException( new InvalidResponseCodeException(
responseCode, responseCode, info.getHttpStatusText(), info.getAllHeaders(), currentDataSpec);
info.getHttpStatusText(),
info.getAllHeaders(),
currentDataSpec);
operation.open(); operation.open();
return; return;
} }

View File

@ -295,9 +295,7 @@ public interface HttpDataSource extends DataSource {
*/ */
public final int responseCode; public final int responseCode;
/** /** The http status message. */
* The HTTP status message.
*/
@Nullable public final String responseMessage; @Nullable public final String responseMessage;
/** /**
@ -305,6 +303,13 @@ public interface HttpDataSource extends DataSource {
*/ */
public final Map<String, List<String>> headerFields; public final Map<String, List<String>> headerFields;
/** @deprecated Use {@link #InvalidResponseCodeException(int, String, Map, DataSpec)}. */
@Deprecated
public InvalidResponseCodeException(
int responseCode, Map<String, List<String>> headerFields, DataSpec dataSpec) {
this(responseCode, /* responseMessage= */ null, headerFields, dataSpec);
}
public InvalidResponseCodeException( public InvalidResponseCodeException(
int responseCode, int responseCode,
@Nullable String responseMessage, @Nullable String responseMessage,

View File

@ -34,7 +34,8 @@ public final class DefaultLoadErrorHandlingPolicyTest {
@Test @Test
public void getBlacklistDurationMsFor_blacklist404() { public void getBlacklistDurationMsFor_blacklist404() {
InvalidResponseCodeException exception = 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)) assertThat(getDefaultPolicyBlacklistOutputFor(exception))
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
} }
@ -42,7 +43,8 @@ public final class DefaultLoadErrorHandlingPolicyTest {
@Test @Test
public void getBlacklistDurationMsFor_blacklist410() { public void getBlacklistDurationMsFor_blacklist410() {
InvalidResponseCodeException exception = 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)) assertThat(getDefaultPolicyBlacklistOutputFor(exception))
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); .isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
} }

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.dash.manifest; package com.google.android.exoplayer2.source.dash.manifest;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.FilterableManifest; import com.google.android.exoplayer2.offline.FilterableManifest;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
@ -86,17 +87,56 @@ public class DashManifest implements FilterableManifest<DashManifest> {
*/ */
public final Uri location; public final Uri location;
/** /** The {@link ProgramInformation}, or null if not present. */
* The ProgramInformation of this manifest. @Nullable public final ProgramInformation programInformation;
*/
public final ProgramInformation programInformation;
private final List<Period> periods; private final List<Period> periods;
public DashManifest(long availabilityStartTimeMs, long durationMs, long minBufferTimeMs, /**
boolean dynamic, long minUpdatePeriodMs, long timeShiftBufferDepthMs, * @deprecated Use {@link #DashManifest(long, long, long, boolean, long, long, long, long,
long suggestedPresentationDelayMs, long publishTimeMs, UtcTimingElement utcTiming, * ProgramInformation, UtcTimingElement, Uri, List)}.
Uri location, ProgramInformation programInformation, List<Period> periods) { */
@Deprecated
public DashManifest(
long availabilityStartTimeMs,
long durationMs,
long minBufferTimeMs,
boolean dynamic,
long minUpdatePeriodMs,
long timeShiftBufferDepthMs,
long suggestedPresentationDelayMs,
long publishTimeMs,
UtcTimingElement utcTiming,
Uri location,
List<Period> 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<Period> periods) {
this.availabilityStartTimeMs = availabilityStartTimeMs; this.availabilityStartTimeMs = availabilityStartTimeMs;
this.durationMs = durationMs; this.durationMs = durationMs;
this.minBufferTimeMs = minBufferTimeMs; this.minBufferTimeMs = minBufferTimeMs;
@ -105,9 +145,9 @@ public class DashManifest implements FilterableManifest<DashManifest> {
this.timeShiftBufferDepthMs = timeShiftBufferDepthMs; this.timeShiftBufferDepthMs = timeShiftBufferDepthMs;
this.suggestedPresentationDelayMs = suggestedPresentationDelayMs; this.suggestedPresentationDelayMs = suggestedPresentationDelayMs;
this.publishTimeMs = publishTimeMs; this.publishTimeMs = publishTimeMs;
this.programInformation = programInformation;
this.utcTiming = utcTiming; this.utcTiming = utcTiming;
this.location = location; this.location = location;
this.programInformation = programInformation;
this.periods = periods == null ? Collections.emptyList() : periods; this.periods = periods == null ? Collections.emptyList() : periods;
} }
@ -154,9 +194,19 @@ public class DashManifest implements FilterableManifest<DashManifest> {
} }
} }
long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET; long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
return new DashManifest(availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic, return new DashManifest(
minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs, availabilityStartTimeMs,
utcTiming, location, programInformation, copyPeriods); newDuration,
minBufferTimeMs,
dynamic,
minUpdatePeriodMs,
timeShiftBufferDepthMs,
suggestedPresentationDelayMs,
publishTimeMs,
programInformation,
utcTiming,
location,
copyPeriods);
} }
private static ArrayList<AdaptationSet> copyAdaptationSets( private static ArrayList<AdaptationSet> copyAdaptationSets(

View File

@ -120,9 +120,9 @@ public class DashManifestParser extends DefaultHandler
long suggestedPresentationDelayMs = dynamic long suggestedPresentationDelayMs = dynamic
? parseDuration(xpp, "suggestedPresentationDelay", C.TIME_UNSET) : C.TIME_UNSET; ? parseDuration(xpp, "suggestedPresentationDelay", C.TIME_UNSET) : C.TIME_UNSET;
long publishTimeMs = parseDateTime(xpp, "publishTime", C.TIME_UNSET); long publishTimeMs = parseDateTime(xpp, "publishTime", C.TIME_UNSET);
ProgramInformation programInformation = null;
UtcTimingElement utcTiming = null; UtcTimingElement utcTiming = null;
Uri location = null; Uri location = null;
ProgramInformation programInformation = null;
List<Period> periods = new ArrayList<>(); List<Period> periods = new ArrayList<>();
long nextPeriodStartMs = dynamic ? C.TIME_UNSET : 0; long nextPeriodStartMs = dynamic ? C.TIME_UNSET : 0;
@ -135,12 +135,12 @@ public class DashManifestParser extends DefaultHandler
baseUrl = parseBaseUrl(xpp, baseUrl); baseUrl = parseBaseUrl(xpp, baseUrl);
seenFirstBaseUrl = true; seenFirstBaseUrl = true;
} }
} else if (XmlPullParserUtil.isStartTag(xpp, "ProgramInformation")) {
programInformation = parseProgramInformation(xpp);
} else if (XmlPullParserUtil.isStartTag(xpp, "UTCTiming")) { } else if (XmlPullParserUtil.isStartTag(xpp, "UTCTiming")) {
utcTiming = parseUtcTiming(xpp); utcTiming = parseUtcTiming(xpp);
} else if (XmlPullParserUtil.isStartTag(xpp, "Location")) { } else if (XmlPullParserUtil.isStartTag(xpp, "Location")) {
location = Uri.parse(xpp.nextText()); location = Uri.parse(xpp.nextText());
} else if (XmlPullParserUtil.isStartTag(xpp, "ProgramInformation")) {
programInformation = parseProgramInformation(xpp);
} else if (XmlPullParserUtil.isStartTag(xpp, "Period") && !seenEarlyAccessPeriod) { } else if (XmlPullParserUtil.isStartTag(xpp, "Period") && !seenEarlyAccessPeriod) {
Pair<Period, Long> periodWithDurationMs = parsePeriod(xpp, baseUrl, nextPeriodStartMs); Pair<Period, Long> periodWithDurationMs = parsePeriod(xpp, baseUrl, nextPeriodStartMs);
Period period = periodWithDurationMs.first; Period period = periodWithDurationMs.first;
@ -176,18 +176,47 @@ public class DashManifestParser extends DefaultHandler
throw new ParserException("No periods found."); throw new ParserException("No periods found.");
} }
return buildMediaPresentationDescription(availabilityStartTime, durationMs, minBufferTimeMs, return buildMediaPresentationDescription(
dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, availabilityStartTime,
publishTimeMs, utcTiming, location, programInformation, periods); durationMs,
minBufferTimeMs,
dynamic,
minUpdateTimeMs,
timeShiftBufferDepthMs,
suggestedPresentationDelayMs,
publishTimeMs,
programInformation,
utcTiming,
location,
periods);
} }
protected DashManifest buildMediaPresentationDescription(long availabilityStartTime, protected DashManifest buildMediaPresentationDescription(
long durationMs, long minBufferTimeMs, boolean dynamic, long minUpdateTimeMs, long availabilityStartTime,
long timeShiftBufferDepthMs, long suggestedPresentationDelayMs, long publishTimeMs, long durationMs,
UtcTimingElement utcTiming, Uri location, ProgramInformation programInformation, List<Period> periods) { long minBufferTimeMs,
return new DashManifest(availabilityStartTime, durationMs, minBufferTimeMs, boolean dynamic,
dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, long minUpdateTimeMs,
publishTimeMs, utcTiming, location, programInformation, periods); long timeShiftBufferDepthMs,
long suggestedPresentationDelayMs,
long publishTimeMs,
ProgramInformation programInformation,
UtcTimingElement utcTiming,
Uri location,
List<Period> periods) {
return new DashManifest(
availabilityStartTime,
durationMs,
minBufferTimeMs,
dynamic,
minUpdateTimeMs,
timeShiftBufferDepthMs,
suggestedPresentationDelayMs,
publishTimeMs,
programInformation,
utcTiming,
location,
periods);
} }
protected UtcTimingElement parseUtcTiming(XmlPullParser xpp) { protected UtcTimingElement parseUtcTiming(XmlPullParser xpp) {
@ -1001,7 +1030,8 @@ public class DashManifestParser extends DefaultHandler
return new RangedUri(urlText, rangeStart, rangeLength); 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 title = null;
String source = null; String source = null;
String copyright = null; String copyright = null;

View File

@ -17,36 +17,25 @@ package com.google.android.exoplayer2.source.dash.manifest;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
/** /** A parsed program information element. */
* A parsed ProgramInformation element.
*/
public class ProgramInformation { public class ProgramInformation {
/** /** The title for the media presentation. */
* The title for the media presentation.
*/
public final String title; 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; public final String source;
/** /** A copyright statement for the media presentation. */
* A copyright statement for the media presentation.
*/
public final String copyright; 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; 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 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.title = title;
this.source = source; this.source = source;
this.copyright = copyright; this.copyright = copyright;
@ -56,15 +45,18 @@ public class ProgramInformation {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof ProgramInformation)) { if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
ProgramInformation other = (ProgramInformation) obj; ProgramInformation other = (ProgramInformation) obj;
return Util.areEqual(this.title, other.title) return Util.areEqual(this.title, other.title)
&& Util.areEqual(this.source, other.source) && Util.areEqual(this.source, other.source)
&& Util.areEqual(this.copyright, other.copyright) && Util.areEqual(this.copyright, other.copyright)
&& Util.areEqual(this.moreInformationURL, other.moreInformationURL) && Util.areEqual(this.moreInformationURL, other.moreInformationURL)
&& Util.areEqual(this.lang, other.lang); && Util.areEqual(this.lang, other.lang);
} }
@Override @Override

View File

@ -25,7 +25,6 @@ import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -156,11 +155,14 @@ public class DashManifestParserTest {
@Test @Test
public void testParseMediaPresentationDescriptionCanParseProgramInformation() throws IOException { public void testParseMediaPresentationDescriptionCanParseProgramInformation() throws IOException {
DashManifestParser parser = new DashManifestParser(); 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)); TestUtil.getInputStream(RuntimeEnvironment.application, SAMPLE_MPD_1));
ProgramInformation programInformation = new ProgramInformation("MediaTitle", "MediaSource", ProgramInformation expectedProgramInformation =
"MediaCopyright", "www.example.com", "enUs"); new ProgramInformation(
assertThat(programInformation).isEqualTo(mpd.programInformation); "MediaTitle", "MediaSource", "MediaCopyright", "www.example.com", "enUs");
assertThat(mpd.programInformation).isEqualTo(expectedProgramInformation);
} }
@Test @Test

View File

@ -219,7 +219,18 @@ public class DashManifestTest {
private static DashManifest newDashManifest(int duration, Period... periods) { private static DashManifest newDashManifest(int duration, Period... periods) {
return new DashManifest( 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) { private static Period newPeriod(String id, int startMs, AdaptationSet... adaptationSets) {

View File

@ -341,7 +341,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
String name = parseStringAttr(line, REGEX_NAME, variableDefinitions); String name = parseStringAttr(line, REGEX_NAME, variableDefinitions);
String language = parseOptionalStringAttr(line, REGEX_LANGUAGE, variableDefinitions); String language = parseOptionalStringAttr(line, REGEX_LANGUAGE, variableDefinitions);
String groupId = parseOptionalStringAttr(line, REGEX_GROUP_ID, variableDefinitions); String groupId = parseOptionalStringAttr(line, REGEX_GROUP_ID, variableDefinitions);
String id = String.format("%s:%s", groupId, name); String id = groupId + ":" + name;
Format format; Format format;
switch (parseStringAttr(line, REGEX_TYPE, variableDefinitions)) { switch (parseStringAttr(line, REGEX_TYPE, variableDefinitions)) {
case TYPE_AUDIO: case TYPE_AUDIO: