mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
DataSpec: Add customData field.
PiperOrigin-RevId: 294520836
This commit is contained in:
parent
14d3ed09d5
commit
c7b6a2e045
3 changed files with 44 additions and 8 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
* Move player message-related constants from `C` to `Renderer`, to avoid
|
* Move player message-related constants from `C` to `Renderer`, to avoid
|
||||||
having the constants class depend on player/renderer classes.
|
having the constants class depend on player/renderer classes.
|
||||||
* Split out `common` and `extractor` submodules.
|
* Split out `common` and `extractor` submodules.
|
||||||
* Add `DataSpec.Builder`.
|
* Add `DataSpec.Builder` and `DataSpec.customData`.
|
||||||
* Text:
|
* Text:
|
||||||
* Parse `<ruby>` and `<rt>` tags in WebVTT subtitles (rendering is coming
|
* Parse `<ruby>` and `<rt>` tags in WebVTT subtitles (rendering is coming
|
||||||
later).
|
later).
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public final class DataSpec {
|
||||||
private long length;
|
private long length;
|
||||||
@Nullable private String key;
|
@Nullable private String key;
|
||||||
@Flags private int flags;
|
@Flags private int flags;
|
||||||
|
@Nullable private Object customData;
|
||||||
|
|
||||||
/** Creates a new instance with default values. */
|
/** Creates a new instance with default values. */
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
|
@ -67,6 +68,7 @@ public final class DataSpec {
|
||||||
length = dataSpec.length;
|
length = dataSpec.length;
|
||||||
key = dataSpec.key;
|
key = dataSpec.key;
|
||||||
flags = dataSpec.flags;
|
flags = dataSpec.flags;
|
||||||
|
customData = dataSpec.customData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -168,6 +170,17 @@ public final class DataSpec {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link DataSpec#customData}. The default value is {@code null}.
|
||||||
|
*
|
||||||
|
* @param customData The {@link DataSpec#customData}.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public Builder setCustomData(@Nullable Object customData) {
|
||||||
|
this.customData = customData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a {@link DataSpec} with the builder's current values.
|
* Builds a {@link DataSpec} with the builder's current values.
|
||||||
*
|
*
|
||||||
|
|
@ -185,7 +198,8 @@ public final class DataSpec {
|
||||||
position,
|
position,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
customData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,6 +339,14 @@ public final class DataSpec {
|
||||||
/** Request {@link Flags flags}. */
|
/** Request {@link Flags flags}. */
|
||||||
@Flags public final int flags;
|
@Flags public final int flags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application specific data.
|
||||||
|
*
|
||||||
|
* <p>This field is intended for advanced use cases in which applications require the ability to
|
||||||
|
* attach custom data to {@link DataSpec} instances. The custom data should be immutable.
|
||||||
|
*/
|
||||||
|
@Nullable public final Object customData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance.
|
* Constructs an instance.
|
||||||
*
|
*
|
||||||
|
|
@ -517,7 +539,8 @@ public final class DataSpec {
|
||||||
position,
|
position,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
/* customData= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
@ -530,7 +553,8 @@ public final class DataSpec {
|
||||||
long position,
|
long position,
|
||||||
long length,
|
long length,
|
||||||
@Nullable String key,
|
@Nullable String key,
|
||||||
@Flags int flags) {
|
@Flags int flags,
|
||||||
|
@Nullable Object customData) {
|
||||||
// TODO: Replace this assertion with a stricter one checking "uriPositionOffset >= 0", after
|
// TODO: Replace this assertion with a stricter one checking "uriPositionOffset >= 0", after
|
||||||
// validating there are no violations in ExoPlayer and 1P apps.
|
// validating there are no violations in ExoPlayer and 1P apps.
|
||||||
Assertions.checkArgument(uriPositionOffset + position >= 0);
|
Assertions.checkArgument(uriPositionOffset + position >= 0);
|
||||||
|
|
@ -546,6 +570,7 @@ public final class DataSpec {
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
|
this.customData = customData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -601,7 +626,8 @@ public final class DataSpec {
|
||||||
position + offset,
|
position + offset,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
customData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -621,7 +647,8 @@ public final class DataSpec {
|
||||||
position,
|
position,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
customData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -641,7 +668,8 @@ public final class DataSpec {
|
||||||
position,
|
position,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
customData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -664,7 +692,8 @@ public final class DataSpec {
|
||||||
position,
|
position,
|
||||||
length,
|
length,
|
||||||
key,
|
key,
|
||||||
flags);
|
flags,
|
||||||
|
customData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ public class DataSpecTest {
|
||||||
Uri uri = Uri.parse("www.google.com");
|
Uri uri = Uri.parse("www.google.com");
|
||||||
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(3);
|
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(3);
|
||||||
byte[] httpBody = new byte[] {0, 1, 2, 3};
|
byte[] httpBody = new byte[] {0, 1, 2, 3};
|
||||||
|
Object customData = new Object();
|
||||||
|
|
||||||
DataSpec dataSpec =
|
DataSpec dataSpec =
|
||||||
new DataSpec.Builder()
|
new DataSpec.Builder()
|
||||||
|
|
@ -153,6 +154,7 @@ public class DataSpecTest {
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setFlags(DataSpec.FLAG_ALLOW_GZIP)
|
.setFlags(DataSpec.FLAG_ALLOW_GZIP)
|
||||||
.setHttpRequestHeaders(httpRequestHeaders)
|
.setHttpRequestHeaders(httpRequestHeaders)
|
||||||
|
.setCustomData(customData)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(dataSpec.uri).isEqualTo(uri);
|
assertThat(dataSpec.uri).isEqualTo(uri);
|
||||||
|
|
@ -166,6 +168,7 @@ public class DataSpecTest {
|
||||||
assertThat(dataSpec.length).isEqualTo(5);
|
assertThat(dataSpec.length).isEqualTo(5);
|
||||||
assertThat(dataSpec.key).isEqualTo("key");
|
assertThat(dataSpec.key).isEqualTo("key");
|
||||||
assertThat(dataSpec.flags).isEqualTo(DataSpec.FLAG_ALLOW_GZIP);
|
assertThat(dataSpec.flags).isEqualTo(DataSpec.FLAG_ALLOW_GZIP);
|
||||||
|
assertThat(dataSpec.customData).isEqualTo(customData);
|
||||||
assertHttpRequestHeadersReadOnly(dataSpec);
|
assertHttpRequestHeadersReadOnly(dataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,6 +178,7 @@ public class DataSpecTest {
|
||||||
Uri uri = Uri.parse("www.google.com");
|
Uri uri = Uri.parse("www.google.com");
|
||||||
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(3);
|
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(3);
|
||||||
byte[] httpBody = new byte[] {0, 1, 2, 3};
|
byte[] httpBody = new byte[] {0, 1, 2, 3};
|
||||||
|
Object customData = new Object();
|
||||||
|
|
||||||
DataSpec dataSpec =
|
DataSpec dataSpec =
|
||||||
new DataSpec.Builder()
|
new DataSpec.Builder()
|
||||||
|
|
@ -187,6 +191,7 @@ public class DataSpecTest {
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setFlags(DataSpec.FLAG_ALLOW_GZIP)
|
.setFlags(DataSpec.FLAG_ALLOW_GZIP)
|
||||||
.setHttpRequestHeaders(httpRequestHeaders)
|
.setHttpRequestHeaders(httpRequestHeaders)
|
||||||
|
.setCustomData(customData)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Build upon the DataSpec.
|
// Build upon the DataSpec.
|
||||||
|
|
@ -203,6 +208,7 @@ public class DataSpecTest {
|
||||||
assertThat(dataSpec.length).isEqualTo(5);
|
assertThat(dataSpec.length).isEqualTo(5);
|
||||||
assertThat(dataSpec.key).isEqualTo("key");
|
assertThat(dataSpec.key).isEqualTo("key");
|
||||||
assertThat(dataSpec.flags).isEqualTo(DataSpec.FLAG_ALLOW_GZIP);
|
assertThat(dataSpec.flags).isEqualTo(DataSpec.FLAG_ALLOW_GZIP);
|
||||||
|
assertThat(dataSpec.customData).isEqualTo(customData);
|
||||||
assertHttpRequestHeadersReadOnly(dataSpec);
|
assertHttpRequestHeadersReadOnly(dataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,6 +353,7 @@ public class DataSpecTest {
|
||||||
assertThat(dataSpec.length).isEqualTo(C.LENGTH_UNSET);
|
assertThat(dataSpec.length).isEqualTo(C.LENGTH_UNSET);
|
||||||
assertThat(dataSpec.key).isNull();
|
assertThat(dataSpec.key).isNull();
|
||||||
assertThat(dataSpec.flags).isEqualTo(0);
|
assertThat(dataSpec.flags).isEqualTo(0);
|
||||||
|
assertThat(dataSpec.customData).isNull();
|
||||||
assertHttpRequestHeadersReadOnly(dataSpec);
|
assertHttpRequestHeadersReadOnly(dataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue