Skip to content

Commit

Permalink
Add MediaItem.SubtitleConfiguration#id field
Browse files Browse the repository at this point in the history
Issue: #9673

#minor-release

PiperOrigin-RevId: 414413320
  • Loading branch information
icbaker committed Dec 7, 2021
1 parent daeea81 commit 2e55643
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
* Extractors:
* Fix inconsistency with spec in H.265 SPS nal units parsing
((#9719)[https://github.com/google/ExoPlayer/issues/9719]).
* Text:
* Add a `MediaItem.SubtitleConfiguration#id` field which is propagated to
the `Format#id` field of the subtitle track created from the
configuration
((#9673)[https://github.com/google/ExoPlayer/issues/9673]).
* DRM:
* Remove `playbackLooper` from `DrmSessionManager.(pre)acquireSession`.
When a `DrmSessionManager` is used by an app in a custom `MediaSource`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ public static final class Builder {
private @C.SelectionFlags int selectionFlags;
private @C.RoleFlags int roleFlags;
@Nullable private String label;
@Nullable private String id;

/**
* Constructs an instance.
Expand All @@ -1255,6 +1256,7 @@ private Builder(SubtitleConfiguration subtitleConfiguration) {
this.selectionFlags = subtitleConfiguration.selectionFlags;
this.roleFlags = subtitleConfiguration.roleFlags;
this.label = subtitleConfiguration.label;
this.id = subtitleConfiguration.id;
}

/** Sets the {@link Uri} to the subtitle file. */
Expand Down Expand Up @@ -1293,6 +1295,12 @@ public Builder setLabel(@Nullable String label) {
return this;
}

/** Sets the optional ID for this subtitle track. */
public Builder setId(@Nullable String id) {
this.id = id;
return this;
}

/** Creates a {@link SubtitleConfiguration} from the values of this builder. */
public SubtitleConfiguration build() {
return new SubtitleConfiguration(this);
Expand All @@ -1315,20 +1323,27 @@ private Subtitle buildSubtitle() {
public final @C.RoleFlags int roleFlags;
/** The label. */
@Nullable public final String label;
/**
* The ID of the subtitles. This will be propagated to the {@link Format#id} of the subtitle
* track created from this configuration.
*/
@Nullable public final String id;

private SubtitleConfiguration(
Uri uri,
String mimeType,
@Nullable String language,
@C.SelectionFlags int selectionFlags,
@C.RoleFlags int roleFlags,
@Nullable String label) {
int selectionFlags,
int roleFlags,
@Nullable String label,
@Nullable String id) {
this.uri = uri;
this.mimeType = mimeType;
this.language = language;
this.selectionFlags = selectionFlags;
this.roleFlags = roleFlags;
this.label = label;
this.id = id;
}

private SubtitleConfiguration(Builder builder) {
Expand All @@ -1338,6 +1353,7 @@ private SubtitleConfiguration(Builder builder) {
this.selectionFlags = builder.selectionFlags;
this.roleFlags = builder.roleFlags;
this.label = builder.label;
this.id = builder.id;
}

/** Returns a {@link Builder} initialized with the values of this instance. */
Expand All @@ -1361,7 +1377,8 @@ public boolean equals(@Nullable Object obj) {
&& Util.areEqual(language, other.language)
&& selectionFlags == other.selectionFlags
&& roleFlags == other.roleFlags
&& Util.areEqual(label, other.label);
&& Util.areEqual(label, other.label)
&& Util.areEqual(id, other.id);
}

@Override
Expand All @@ -1372,6 +1389,7 @@ public int hashCode() {
result = 31 * result + selectionFlags;
result = 31 * result + roleFlags;
result = 31 * result + (label == null ? 0 : label.hashCode());
result = 31 * result + (id == null ? 0 : id.hashCode());
return result;
}
}
Expand Down Expand Up @@ -1402,7 +1420,7 @@ public Subtitle(
@C.SelectionFlags int selectionFlags,
@C.RoleFlags int roleFlags,
@Nullable String label) {
super(uri, mimeType, language, selectionFlags, roleFlags, label);
super(uri, mimeType, language, selectionFlags, roleFlags, label, /* id= */ null);
}

private Subtitle(Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public void builderSetSubtitleConfigurations() {
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label")
.setId("id")
.build());

MediaItem mediaItem =
Expand Down Expand Up @@ -619,6 +620,7 @@ public void buildUpon_individualSetters_equalsToOriginal() {
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label")
.setId("id")
.build()))
.setTag(new Object())
.build();
Expand Down Expand Up @@ -675,6 +677,7 @@ public void buildUpon_wholeObjectSetters_equalsToOriginal() {
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label")
.setId("id")
.build()))
.setTag(new Object())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public MediaSource createMediaSource(MediaItem mediaItem) {
.setSelectionFlags(subtitleConfigurations.get(i).selectionFlags)
.setRoleFlags(subtitleConfigurations.get(i).roleFlags)
.setLabel(subtitleConfigurations.get(i).label)
.setId(subtitleConfigurations.get(i).id)
.build();
ExtractorsFactory extractorsFactory =
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private SingleSampleMediaSource(
.setSelectionFlags(subtitleConfiguration.selectionFlags)
.setRoleFlags(subtitleConfiguration.roleFlags)
.setLabel(subtitleConfiguration.label)
.setId(subtitleConfiguration.id)
.build();
dataSpec =
new DataSpec.Builder()
Expand Down

0 comments on commit 2e55643

Please sign in to comment.