Commit 9fd575e1 by Oliver Woodman

Allow Representations to have custom cache keys.

parent 632ccc6c
...@@ -53,6 +53,7 @@ public abstract class Representation implements FormatWrapper { ...@@ -53,6 +53,7 @@ public abstract class Representation implements FormatWrapper {
*/ */
public final long presentationTimeOffsetUs; public final long presentationTimeOffsetUs;
private final String cacheKey;
private final RangedUri initializationUri; private final RangedUri initializationUri;
/** /**
...@@ -66,12 +67,27 @@ public abstract class Representation implements FormatWrapper { ...@@ -66,12 +67,27 @@ public abstract class Representation implements FormatWrapper {
*/ */
public static Representation newInstance(String contentId, long revisionId, Format format, public static Representation newInstance(String contentId, long revisionId, Format format,
SegmentBase segmentBase) { SegmentBase segmentBase) {
return newInstance(contentId, revisionId, format, segmentBase, null);
}
/**
* Constructs a new instance.
*
* @param contentId Identifies the piece of content to which this representation belongs.
* @param revisionId Identifies the revision of the content.
* @param format The format of the representation.
* @param segmentBase A segment base element for the representation.
* @param customCacheKey A custom value to be returned from {@link #getCacheKey()}, or null.
* @return The constructed instance.
*/
public static Representation newInstance(String contentId, long revisionId, Format format,
SegmentBase segmentBase, String customCacheKey) {
if (segmentBase instanceof SingleSegmentBase) { if (segmentBase instanceof SingleSegmentBase) {
return new SingleSegmentRepresentation(contentId, revisionId, format, return new SingleSegmentRepresentation(contentId, revisionId, format,
(SingleSegmentBase) segmentBase, -1); (SingleSegmentBase) segmentBase, customCacheKey, -1);
} else if (segmentBase instanceof MultiSegmentBase) { } else if (segmentBase instanceof MultiSegmentBase) {
return new MultiSegmentRepresentation(contentId, revisionId, format, return new MultiSegmentRepresentation(contentId, revisionId, format,
(MultiSegmentBase) segmentBase); (MultiSegmentBase) segmentBase, customCacheKey);
} else { } else {
throw new IllegalArgumentException("segmentBase must be of type SingleSegmentBase or " throw new IllegalArgumentException("segmentBase must be of type SingleSegmentBase or "
+ "MultiSegmentBase"); + "MultiSegmentBase");
...@@ -79,10 +95,12 @@ public abstract class Representation implements FormatWrapper { ...@@ -79,10 +95,12 @@ public abstract class Representation implements FormatWrapper {
} }
private Representation(String contentId, long revisionId, Format format, private Representation(String contentId, long revisionId, Format format,
SegmentBase segmentBase) { SegmentBase segmentBase, String customCacheKey) {
this.contentId = contentId; this.contentId = contentId;
this.revisionId = revisionId; this.revisionId = revisionId;
this.format = format; this.format = format;
this.cacheKey = customCacheKey != null ? customCacheKey
: contentId + "." + format.id + "." + revisionId;
initializationUri = segmentBase.getInitialization(this); initializationUri = segmentBase.getInitialization(this);
presentationTimeOffsetUs = segmentBase.getPresentationTimeOffsetUs(); presentationTimeOffsetUs = segmentBase.getPresentationTimeOffsetUs();
} }
...@@ -119,13 +137,13 @@ public abstract class Representation implements FormatWrapper { ...@@ -119,13 +137,13 @@ public abstract class Representation implements FormatWrapper {
public abstract DashSegmentIndex getIndex(); public abstract DashSegmentIndex getIndex();
/** /**
* Generates a cache key for the {@link Representation}, in the format * A cache key for the {@link Representation}, in the format
* {@code contentId + "." + format.id + "." + revisionId}. * {@code contentId + "." + format.id + "." + revisionId}.
* *
* @return A cache key. * @return A cache key.
*/ */
public String getCacheKey() { public String getCacheKey() {
return contentId + "." + format.id + "." + revisionId; return cacheKey;
} }
/** /**
...@@ -155,17 +173,18 @@ public abstract class Representation implements FormatWrapper { ...@@ -155,17 +173,18 @@ public abstract class Representation implements FormatWrapper {
* @param initializationEnd The offset of the last byte of initialization data. * @param initializationEnd The offset of the last byte of initialization data.
* @param indexStart The offset of the first byte of index data. * @param indexStart The offset of the first byte of index data.
* @param indexEnd The offset of the last byte of index data. * @param indexEnd The offset of the last byte of index data.
* @param customCacheKey A custom value to be returned from {@link #getCacheKey()}, or null.
* @param contentLength The content length, or -1 if unknown. * @param contentLength The content length, or -1 if unknown.
*/ */
public static SingleSegmentRepresentation newInstance(String contentId, long revisionId, public static SingleSegmentRepresentation newInstance(String contentId, long revisionId,
Format format, String uri, long initializationStart, long initializationEnd, Format format, String uri, long initializationStart, long initializationEnd,
long indexStart, long indexEnd, long contentLength) { long indexStart, long indexEnd, String customCacheKey, long contentLength) {
RangedUri rangedUri = new RangedUri(uri, null, initializationStart, RangedUri rangedUri = new RangedUri(uri, null, initializationStart,
initializationEnd - initializationStart + 1); initializationEnd - initializationStart + 1);
SingleSegmentBase segmentBase = new SingleSegmentBase(rangedUri, 1, 0, uri, indexStart, SingleSegmentBase segmentBase = new SingleSegmentBase(rangedUri, 1, 0, uri, indexStart,
indexEnd - indexStart + 1); indexEnd - indexStart + 1);
return new SingleSegmentRepresentation(contentId, revisionId, return new SingleSegmentRepresentation(contentId, revisionId,
format, segmentBase, contentLength); format, segmentBase, customCacheKey, contentLength);
} }
/** /**
...@@ -173,11 +192,12 @@ public abstract class Representation implements FormatWrapper { ...@@ -173,11 +192,12 @@ public abstract class Representation implements FormatWrapper {
* @param revisionId Identifies the revision of the content. * @param revisionId Identifies the revision of the content.
* @param format The format of the representation. * @param format The format of the representation.
* @param segmentBase The segment base underlying the representation. * @param segmentBase The segment base underlying the representation.
* @param customCacheKey A custom value to be returned from {@link #getCacheKey()}, or null.
* @param contentLength The content length, or -1 if unknown. * @param contentLength The content length, or -1 if unknown.
*/ */
public SingleSegmentRepresentation(String contentId, long revisionId, Format format, public SingleSegmentRepresentation(String contentId, long revisionId, Format format,
SingleSegmentBase segmentBase, long contentLength) { SingleSegmentBase segmentBase, String customCacheKey, long contentLength) {
super(contentId, revisionId, format, segmentBase); super(contentId, revisionId, format, segmentBase, customCacheKey);
this.uri = Uri.parse(segmentBase.uri); this.uri = Uri.parse(segmentBase.uri);
this.indexUri = segmentBase.getIndex(); this.indexUri = segmentBase.getIndex();
this.contentLength = contentLength; this.contentLength = contentLength;
...@@ -212,10 +232,11 @@ public abstract class Representation implements FormatWrapper { ...@@ -212,10 +232,11 @@ public abstract class Representation implements FormatWrapper {
* @param revisionId Identifies the revision of the content. * @param revisionId Identifies the revision of the content.
* @param format The format of the representation. * @param format The format of the representation.
* @param segmentBase The segment base underlying the representation. * @param segmentBase The segment base underlying the representation.
* @param customCacheKey A custom value to be returned from {@link #getCacheKey()}, or null.
*/ */
public MultiSegmentRepresentation(String contentId, long revisionId, Format format, public MultiSegmentRepresentation(String contentId, long revisionId, Format format,
MultiSegmentBase segmentBase) { MultiSegmentBase segmentBase, String customCacheKey) {
super(contentId, revisionId, format, segmentBase); super(contentId, revisionId, format, segmentBase, customCacheKey);
this.segmentBase = segmentBase; this.segmentBase = segmentBase;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment