Skip to content

Commit

Permalink
Fix the regex used for validating custom CMCD key names
Browse files Browse the repository at this point in the history
Relax the regex to only check for hyphen which is required by the specification.

Issue: #1028
#minor-release
PiperOrigin-RevId: 604719300
  • Loading branch information
marcbaechinger authored and Copybara-Service committed Feb 6, 2024
1 parent ccd603a commit 138532e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Add source prefix to all `Format.id` fields generated from
`MergingMediaSource`. This helps to identify which source produced a
`Format` ([#883](https://github.com/androidx/media/issues/883)).
* Fix the regex used for validating custom Common Media Client Data (CMCD)
key names by modifying it to only check for hyphen
([#1028](https://github.com/androidx/media/issues/1028)).
* Transformer:
* Track Selection:
* Extractors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ public static final class Factory {
/** 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";

private static final Pattern CUSTOM_KEY_NAME_PATTERN =
Pattern.compile("[a-zA-Z0-9]+(-[a-zA-Z0-9]+)+");
/**
* 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
* syntax when defining their own prefix.
*/
private static final Pattern CUSTOM_KEY_NAME_PATTERN = Pattern.compile(".*-.*");

private final CmcdConfiguration cmcdConfiguration;
private final ExoTrackSelection trackSelection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "key-3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "key-4=5.0")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "com.example-key3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "com.example.test-key4=5.0")
.build();
}
};
Expand All @@ -487,9 +487,11 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
"CMCD-Request",
"bl=0,dl=0,key-2=\"stringValue\",mtp=1000,nor=\"..%2Fvideo_4000_700000.m4s\",nrr=\"0-\",su",
"CMCD-Session",
"cid=\"mediaId\",key-3=3,sf=d,sid=\"" + cmcdConfiguration.sessionId + "\",st=v",
"cid=\"mediaId\",com.example-key3=3,sf=d,sid=\""
+ cmcdConfiguration.sessionId
+ "\",st=v",
"CMCD-Status",
"key-4=5.0");
"com.example.test-key4=5.0");
}

@Test
Expand All @@ -505,7 +507,7 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
getCustomData() {
return new ImmutableListMultimap.Builder<
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "com.example.test-key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.build();
}
Expand Down Expand Up @@ -534,9 +536,9 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
output.chunk.dataSpec.uri.getQueryParameter(
CmcdConfiguration.CMCD_QUERY_PARAMETER_KEY)))
.isEqualTo(
"bl=0,br=700,cid=\"mediaId\",d=4000,dl=0,key-1=1,key-2=\"stringValue\","
+ "mtp=1000,nor=\"..%2Fvideo_4000_700000.m4s\",nrr=\"0-\",ot=v,sf=d,"
+ "sid=\"sessionId\",st=v,su,tb=1300");
"bl=0,br=700,cid=\"mediaId\",com.example.test-key-1=1,d=4000,dl=0,"
+ "key-2=\"stringValue\",mtp=1000,nor=\"..%2Fvideo_4000_700000.m4s\",nrr=\"0-\","
+ "ot=v,sf=d,sid=\"sessionId\",st=v,su,tb=1300");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "key-3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "key-4=5.0")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "com.example-key3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "com.example.test-key4=5.0")
.build();
}
};
Expand Down Expand Up @@ -396,9 +396,11 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
"CMCD-Request",
"bl=0,dl=0,key-2=\"stringValue\",nor=\"..%2F3.mp4\",nrr=\"0-\",su",
"CMCD-Session",
"cid=\"mediaId\",key-3=3,sf=h,sid=\"" + cmcdConfiguration.sessionId + "\",st=v",
"cid=\"mediaId\",com.example-key3=3,sf=h,sid=\""
+ cmcdConfiguration.sessionId
+ "\",st=v",
"CMCD-Status",
"key-4=5.0");
"com.example.test-key4=5.0");
}

@Test
Expand All @@ -414,7 +416,7 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
getCustomData() {
return new ImmutableListMultimap.Builder<
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "com.example.test-key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.build();
}
Expand Down Expand Up @@ -444,8 +446,9 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
output.chunk.dataSpec.uri.getQueryParameter(
CmcdConfiguration.CMCD_QUERY_PARAMETER_KEY)))
.isEqualTo(
"bl=0,br=800,cid=\"mediaId\",d=4000,dl=0,key-1=1,key-2=\"stringValue\","
+ "nor=\"..%2F3.mp4\",nrr=\"0-\",ot=v,sf=h,sid=\"sessionId\",st=v,su,tb=800");
"bl=0,br=800,cid=\"mediaId\",com.example.test-key-1=1,d=4000,dl=0,"
+ "key-2=\"stringValue\",nor=\"..%2F3.mp4\",nrr=\"0-\",ot=v,sf=h,"
+ "sid=\"sessionId\",st=v,su,tb=800");
}

private HlsChunkSource createHlsChunkSource(@Nullable CmcdConfiguration cmcdConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "key-3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "key-4=5.0")
.put(CmcdConfiguration.KEY_CMCD_SESSION, "com.example-key3=3")
.put(CmcdConfiguration.KEY_CMCD_STATUS, "com.example.test-key4=5.0")
.build();
}
};
Expand All @@ -238,9 +238,11 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
"CMCD-Request",
"bl=0,dl=0,key-2=\"stringValue\",mtp=1000,nor=\"..%2FFragments(video%3D19680000)\",su",
"CMCD-Session",
"cid=\"mediaId\",key-3=3,sf=s,sid=\"" + cmcdConfiguration.sessionId + "\",st=v",
"cid=\"mediaId\",com.example-key3=3,sf=s,sid=\""
+ cmcdConfiguration.sessionId
+ "\",st=v",
"CMCD-Status",
"key-4=5.0");
"com.example.test-key4=5.0");
}

@Test
Expand All @@ -256,7 +258,7 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
getCustomData() {
return new ImmutableListMultimap.Builder<
@CmcdConfiguration.HeaderKey String, String>()
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "key-1=1")
.put(CmcdConfiguration.KEY_CMCD_OBJECT, "com.example.test-key-1=1")
.put(CmcdConfiguration.KEY_CMCD_REQUEST, "key-2=\"stringValue\"")
.build();
}
Expand Down Expand Up @@ -285,9 +287,9 @@ public int getRequestedMaximumThroughputKbps(int throughputKbps) {
output.chunk.dataSpec.uri.getQueryParameter(
CmcdConfiguration.CMCD_QUERY_PARAMETER_KEY)))
.isEqualTo(
"bl=0,br=308,cid=\"mediaId\",d=1968,dl=0,key-1=1,key-2=\"stringValue\","
+ "mtp=1000,nor=\"..%2FFragments(video%3D19680000)\",ot=v,sf=s,sid=\"sessionId\","
+ "st=v,su,tb=1536");
"bl=0,br=308,cid=\"mediaId\",com.example.test-key-1=1,d=1968,dl=0,"
+ "key-2=\"stringValue\",mtp=1000,nor=\"..%2FFragments(video%3D19680000)\",ot=v,"
+ "sf=s,sid=\"sessionId\",st=v,su,tb=1536");
}

private SsChunkSource createSsChunkSource(
Expand Down

0 comments on commit 138532e

Please sign in to comment.