Skip to content

Commit

Permalink
Make some no-op refactoring in CmcdData
Browse files Browse the repository at this point in the history
- Moved static fields for object type, stream type, etc. from `CmcdData.Factory` to `CmcdData`.
- Removed redundant `CmcdData` prefix from `@ObjectType` and `@StreamingFormat` annotations.

#cleanup

PiperOrigin-RevId: 705159876
  • Loading branch information
rohitjoins authored and copybara-github committed Dec 11, 2024
1 parent 893b377 commit de31a37
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,6 @@ public final class CmcdData {
/** {@link CmcdData.Factory} for {@link CmcdData} instances. */
public static final class Factory {

/** Represents the Dynamic Adaptive Streaming over HTTP (DASH) format. */
public static final String STREAMING_FORMAT_DASH = "d";

/** Represents the HTTP Live Streaming (HLS) format. */
public static final String STREAMING_FORMAT_HLS = "h";

/** Represents the Smooth Streaming (SS) format. */
public static final String STREAMING_FORMAT_SS = "s";

/** Represents the Video on Demand (VOD) stream type. */
public static final String STREAM_TYPE_VOD = "v";

/** Represents the Live Streaming stream type. */
public static final String STREAM_TYPE_LIVE = "l";

/** Represents the object type for an initialization segment in a media container. */
public static final String OBJECT_TYPE_INIT_SEGMENT = "i";

/** Represents the object type for audio-only content in a media container. */
public static final String OBJECT_TYPE_AUDIO_ONLY = "a";

/** Represents the object type for video-only content in a media container. */
public static final String OBJECT_TYPE_VIDEO_ONLY = "v";

/** Represents the object type for muxed audio and video content in a media container. */
public static final String OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO = "av";

/** Represents the object type for a manifest or playlist file, in a media container. */
public static final String OBJECT_TYPE_MANIFEST = "m";

/**
* Custom key names MUST carry a hyphenated prefix to ensure that there will not be a namespace
* collision with future revisions to this specification. Clients SHOULD use a reverse-DNS
Expand All @@ -103,15 +73,15 @@ public static final class Factory {
private static final Pattern CUSTOM_KEY_NAME_PATTERN = Pattern.compile(".*-.*");

private final CmcdConfiguration cmcdConfiguration;
private final @CmcdData.StreamingFormat String streamingFormat;
private final @StreamingFormat String streamingFormat;
@Nullable private ExoTrackSelection trackSelection;
private long bufferedDurationUs;
private float playbackRate;
@Nullable private Boolean isLive;
private boolean didRebuffer;
private boolean isBufferEmpty;
private long chunkDurationUs;
@Nullable private @CmcdData.ObjectType String objectType;
@Nullable private @ObjectType String objectType;
@Nullable private String nextObjectRequest;
@Nullable private String nextRangeRequest;

Expand All @@ -121,8 +91,7 @@ public static final class Factory {
* @param cmcdConfiguration The {@link CmcdConfiguration} for this source.
* @param streamingFormat The streaming format of the media content.
*/
public Factory(
CmcdConfiguration cmcdConfiguration, @CmcdData.StreamingFormat String streamingFormat) {
public Factory(CmcdConfiguration cmcdConfiguration, @StreamingFormat String streamingFormat) {
this.cmcdConfiguration = cmcdConfiguration;
this.bufferedDurationUs = C.TIME_UNSET;
this.playbackRate = C.RATE_UNSET;
Expand Down Expand Up @@ -180,7 +149,7 @@ public Factory setChunkDurationUs(long chunkDurationUs) {
* <p>Default is {@code null}.
*/
@CanIgnoreReturnValue
public Factory setObjectType(@Nullable @CmcdData.ObjectType String objectType) {
public Factory setObjectType(@Nullable @ObjectType String objectType) {
this.objectType = objectType;
return this;
}
Expand Down Expand Up @@ -421,13 +390,13 @@ public CmcdData createCmcdData() {
}

private static boolean isManifestObjectType(@Nullable @ObjectType String objectType) {
return Objects.equals(objectType, Factory.OBJECT_TYPE_MANIFEST);
return Objects.equals(objectType, OBJECT_TYPE_MANIFEST);
}

private static boolean isMediaObjectType(@Nullable @ObjectType String objectType) {
return Objects.equals(objectType, Factory.OBJECT_TYPE_AUDIO_ONLY)
|| Objects.equals(objectType, Factory.OBJECT_TYPE_VIDEO_ONLY)
|| Objects.equals(objectType, Factory.OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO);
return Objects.equals(objectType, OBJECT_TYPE_AUDIO_ONLY)
|| Objects.equals(objectType, OBJECT_TYPE_VIDEO_ONLY)
|| Objects.equals(objectType, OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO);
}

private void validateCustomDataListFormat(List<String> customDataList) {
Expand All @@ -440,35 +409,61 @@ private void validateCustomDataListFormat(List<String> customDataList) {

/** Indicates the streaming format used for media content. */
@Retention(RetentionPolicy.SOURCE)
@StringDef({
Factory.STREAMING_FORMAT_DASH,
Factory.STREAMING_FORMAT_HLS,
Factory.STREAMING_FORMAT_SS
})
@StringDef({STREAMING_FORMAT_DASH, STREAMING_FORMAT_HLS, STREAMING_FORMAT_SS})
@Documented
@Target(TYPE_USE)
public @interface StreamingFormat {}

/** Represents the Dynamic Adaptive Streaming over HTTP (DASH) format. */
public static final String STREAMING_FORMAT_DASH = "d";

/** Represents the HTTP Live Streaming (HLS) format. */
public static final String STREAMING_FORMAT_HLS = "h";

/** Represents the Smooth Streaming (SS) format. */
public static final String STREAMING_FORMAT_SS = "s";

/** Indicates the type of streaming for media content. */
@Retention(RetentionPolicy.SOURCE)
@StringDef({Factory.STREAM_TYPE_VOD, Factory.STREAM_TYPE_LIVE})
@StringDef({STREAM_TYPE_VOD, STREAM_TYPE_LIVE})
@Documented
@Target(TYPE_USE)
public @interface StreamType {}

/** Represents the Video on Demand (VOD) stream type. */
public static final String STREAM_TYPE_VOD = "v";

/** Represents the Live Streaming stream type. */
public static final String STREAM_TYPE_LIVE = "l";

/** Indicates the media type of current object being requested. */
@Retention(RetentionPolicy.SOURCE)
@StringDef({
Factory.OBJECT_TYPE_INIT_SEGMENT,
Factory.OBJECT_TYPE_AUDIO_ONLY,
Factory.OBJECT_TYPE_VIDEO_ONLY,
Factory.OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO,
Factory.OBJECT_TYPE_MANIFEST
OBJECT_TYPE_INIT_SEGMENT,
OBJECT_TYPE_AUDIO_ONLY,
OBJECT_TYPE_VIDEO_ONLY,
OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO,
OBJECT_TYPE_MANIFEST
})
@Documented
@Target(TYPE_USE)
public @interface ObjectType {}

/** Represents the object type for an initialization segment in a media container. */
public static final String OBJECT_TYPE_INIT_SEGMENT = "i";

/** Represents the object type for audio-only content in a media container. */
public static final String OBJECT_TYPE_AUDIO_ONLY = "a";

/** Represents the object type for video-only content in a media container. */
public static final String OBJECT_TYPE_VIDEO_ONLY = "v";

/** Represents the object type for muxed audio and video content in a media container. */
public static final String OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO = "av";

/** Represents the object type for a manifest or playlist file, in a media container. */
public static final String OBJECT_TYPE_MANIFEST = "m";

private static final Joiner COMMA_JOINER = Joiner.on(",");

private final CmcdObject cmcdObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public void createInstance_withInvalidFactoryState_throwsIllegalStateException()
"Track selection must be set",
IllegalStateException.class,
() ->
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_INIT_SEGMENT)
.createCmcdData());

assertThrows(
"Buffered duration must be set",
IllegalStateException.class,
() ->
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_AUDIO_ONLY)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_AUDIO_ONLY)
.setTrackSelection(trackSelection)
.setChunkDurationUs(100_000)
.createCmcdData());
Expand All @@ -63,8 +63,8 @@ public void createInstance_withInvalidFactoryState_throwsIllegalStateException()
"Chunk duration must be set",
IllegalStateException.class,
() ->
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_AUDIO_ONLY)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_AUDIO_ONLY)
.setTrackSelection(trackSelection)
.setBufferedDurationUs(100_000)
.createCmcdData());
Expand Down Expand Up @@ -94,9 +94,9 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
when(trackSelection.getLatestBitrateEstimate()).thenReturn(500_000L);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setTrackSelection(trackSelection)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_AUDIO_ONLY)
.setObjectType(CmcdData.OBJECT_TYPE_AUDIO_ONLY)
.setBufferedDurationUs(1_760_000)
.setPlaybackRate(2.0f)
.setIsLive(true)
Expand Down Expand Up @@ -144,8 +144,8 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
when(trackSelection.getLatestBitrateEstimate()).thenReturn(500_000L);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_AUDIO_ONLY)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_AUDIO_ONLY)
.setTrackSelection(trackSelection)
.setBufferedDurationUs(1_760_000)
.setPlaybackRate(2.0f)
Expand Down Expand Up @@ -174,8 +174,8 @@ public void createInstance_manifestObjectType_setsCorrectHttpHeaders() {
cmcdConfigurationFactory.createCmcdConfiguration(mediaItem);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData();

dataSpec = cmcdData.addToDataSpec(dataSpec);
Expand All @@ -199,8 +199,8 @@ public void createInstance_manifestObjectType_setsCorrectQueryParameters() {
cmcdConfigurationFactory.createCmcdConfiguration(mediaItem);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData();

dataSpec = cmcdData.addToDataSpec(dataSpec);
Expand All @@ -226,7 +226,7 @@ public void createInstance_unsetObjectType_setsCorrectHttpHeaders() {
when(trackSelection.getLatestBitrateEstimate()).thenReturn(500_000L);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setTrackSelection(trackSelection)
.setPlaybackRate(2.0f)
.setIsLive(true)
Expand Down Expand Up @@ -268,7 +268,7 @@ public void createInstance_unsetObjectType_setsCorrectQueryParameters() {
when(trackSelection.getLatestBitrateEstimate()).thenReturn(500_000L);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setTrackSelection(trackSelection)
.setPlaybackRate(2.0f)
.setIsLive(true)
Expand Down Expand Up @@ -307,8 +307,8 @@ public void createInstance_customData_setsCorrectHttpHeaders() {
cmcdConfigurationFactory.createCmcdConfiguration(MediaItem.EMPTY);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData();

dataSpec = cmcdData.addToDataSpec(dataSpec);
Expand Down Expand Up @@ -347,8 +347,8 @@ public void createInstance_customData_setsCorrectQueryParameters() {
cmcdConfigurationFactory.createCmcdConfiguration(MediaItem.EMPTY);
DataSpec dataSpec = new DataSpec.Builder().setUri(Uri.EMPTY).build();
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData();

dataSpec = cmcdData.addToDataSpec(dataSpec);
Expand Down Expand Up @@ -381,8 +381,8 @@ public void createInstance_invalidCustomDataKey_throwsException() {
assertThrows(
IllegalStateException.class,
() ->
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ private void startLoadingManifest() {
new DataSpec.Builder().setUri(manifestUri).setFlags(DataSpec.FLAG_ALLOW_GZIP).build();
if (cmcdConfiguration != null) {
CmcdData.Factory cmcdDataFactory =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST);
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST);
if (manifest != null) {
cmcdDataFactory.setIsLive(manifest.dynamic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void getNextChunk(
CmcdData.Factory cmcdDataFactory =
cmcdConfiguration == null
? null
: new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_DASH)
: new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_DASH)
.setTrackSelection(trackSelection)
.setBufferedDurationUs(max(0, bufferedDurationUs))
.setPlaybackRate(loadingInfo.playbackSpeed)
Expand Down Expand Up @@ -747,7 +747,7 @@ protected Chunk newInitializationChunk(
/* httpRequestHeaders= */ ImmutableMap.of());
if (cmcdDataFactory != null) {
CmcdData cmcdData =
cmcdDataFactory.setObjectType(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT).createCmcdData();
cmcdDataFactory.setObjectType(CmcdData.OBJECT_TYPE_INIT_SEGMENT).createCmcdData();
dataSpec = cmcdData.addToDataSpec(dataSpec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void getNextChunk(
@Nullable CmcdData.Factory cmcdDataFactory = null;
if (cmcdConfiguration != null) {
cmcdDataFactory =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_HLS)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_HLS)
.setTrackSelection(trackSelection)
.setBufferedDurationUs(max(0, bufferedDurationUs))
.setPlaybackRate(loadingInfo.playbackSpeed)
Expand All @@ -516,7 +516,7 @@ public void getNextChunk(
.setIsBufferEmpty(queue.isEmpty())
.setObjectType(
getIsMuxedAudioAndVideo()
? CmcdData.Factory.OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO
? CmcdData.OBJECT_TYPE_MUXED_AUDIO_AND_VIDEO
: CmcdData.Factory.getObjectType(trackSelection));
long nextMediaSequence =
segmentBaseHolder.partIndex == C.INDEX_UNSET
Expand Down Expand Up @@ -930,7 +930,7 @@ private Chunk maybeCreateEncryptionChunkFor(
new DataSpec.Builder().setUri(keyUri).setFlags(DataSpec.FLAG_ALLOW_GZIP).build();
if (cmcdDataFactory != null) {
if (isInitSegment) {
cmcdDataFactory.setObjectType(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT);
cmcdDataFactory.setObjectType(CmcdData.OBJECT_TYPE_INIT_SEGMENT);
}
CmcdData cmcdData = cmcdDataFactory.createCmcdData();
dataSpec = cmcdData.addToDataSpec(dataSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ public static HlsMediaChunk createInstance(
.build();
if (cmcdDataFactory != null) {
CmcdData cmcdData =
cmcdDataFactory
.setObjectType(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT)
.createCmcdData();
cmcdDataFactory.setObjectType(CmcdData.OBJECT_TYPE_INIT_SEGMENT).createCmcdData();
initDataSpec = cmcdData.addToDataSpec(initDataSpec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public void start(
.build();
if (cmcdConfiguration != null) {
CmcdData cmcdData =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_HLS)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_HLS)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST)
.createCmcdData();
cmcdData.addToDataSpec(dataSpec);
}
Expand Down Expand Up @@ -791,8 +791,8 @@ private void loadPlaylistImmediately(Uri playlistRequestUri) {
.build();
if (cmcdConfiguration != null) {
CmcdData.Factory cmcdDataFactory =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_HLS)
.setObjectType(CmcdData.Factory.OBJECT_TYPE_MANIFEST);
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_HLS)
.setObjectType(CmcdData.OBJECT_TYPE_MANIFEST);
if (primaryMediaPlaylistSnapshot != null) {
cmcdDataFactory.setIsLive(!primaryMediaPlaylistSnapshot.hasEndTag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public final void getNextChunk(
@Nullable CmcdData.Factory cmcdDataFactory = null;
if (cmcdConfiguration != null) {
cmcdDataFactory =
new CmcdData.Factory(cmcdConfiguration, CmcdData.Factory.STREAMING_FORMAT_SS)
new CmcdData.Factory(cmcdConfiguration, CmcdData.STREAMING_FORMAT_SS)
.setTrackSelection(trackSelection)
.setBufferedDurationUs(max(0, bufferedDurationUs))
.setPlaybackRate(loadingInfo.playbackSpeed)
Expand Down
Loading

0 comments on commit de31a37

Please sign in to comment.