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) {
exception =
new InvalidResponseCodeException(
responseCode,
info.getHttpStatusText(),
info.getAllHeaders(),
currentDataSpec);
responseCode, info.getHttpStatusText(), info.getAllHeaders(), currentDataSpec);
operation.open();
return;
}

View File

@ -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<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(
int responseCode,
@Nullable String responseMessage,

View File

@ -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);
}

View File

@ -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<DashManifest> {
*/
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<Period> 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<Period> 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<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.durationMs = durationMs;
this.minBufferTimeMs = minBufferTimeMs;
@ -105,9 +145,9 @@ public class DashManifest implements FilterableManifest<DashManifest> {
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<DashManifest> {
}
}
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<AdaptationSet> copyAdaptationSets(

View File

@ -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<Period> 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<Period, Long> 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<Period> 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<Period> 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;

View File

@ -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,7 +45,10 @@ 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;

View File

@ -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

View File

@ -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) {

View File

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