Skip to content

Commit 24ad295

Browse files
committed
Added WidevineMessage
1 parent 143cf74 commit 24ad295

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
public enum AllowedTrackTypes {
4+
SD_ONLY,
5+
SD_HD
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
public class ContentKeySpecs {
7+
/**
8+
* A track type name.
9+
*/
10+
@JsonProperty
11+
public String track_type;
12+
13+
/**
14+
* Unique identifier for the key.
15+
*/
16+
@JsonProperty
17+
public String key_id;
18+
19+
/**
20+
* Defines client robustness requirements for playback.
21+
* 1 - Software-based whitebox crypto is required.
22+
* 2 - Software crypto and an obfuscated decoder is required.
23+
* 3 - The key material and crypto operations must be performed
24+
* within a hardware backed trusted execution environment.
25+
* 4 - The crypto and decoding of content must be performed within
26+
* a hardware backed trusted execution environment.
27+
* 5 - The crypto, decoding and all handling of the media (compressed
28+
* and uncompressed) must be handled within a hardware backed trusted
29+
* execution environment.
30+
*/
31+
@JsonProperty
32+
public Integer security_level;
33+
34+
/**
35+
* Indicates whether HDCP V1 or V2 is required or not.
36+
*/
37+
@JsonProperty
38+
public RequiredOutputProtection required_output_protection;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
public enum Hdcp {
4+
HDCP_NONE,
5+
HDCP_V1,
6+
HDCP_V2
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class RequiredOutputProtection {
6+
/**
7+
* Indicates whether HDCP is required.
8+
*/
9+
@JsonProperty
10+
public Hdcp hdcp;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonInclude(JsonInclude.Include.NON_NULL)
7+
public class WidevineMessage {
8+
/**
9+
* Controls which content keys should be included in a license.
10+
* Only one of allowed_track_types and content_key_specs can be specified.
11+
*/
12+
@JsonProperty
13+
public AllowedTrackTypes allowed_track_types;
14+
15+
/**
16+
* A finer grained control on what content keys to return.
17+
* Only one of allowed_track_types and content_key_specs can be specified.
18+
*/
19+
@JsonProperty
20+
public ContentKeySpecs[] content_key_specs;
21+
22+
/**
23+
* Policy settings for this license. In the event this asset has
24+
* a pre-defined policy, these specified values will be used.
25+
*/
26+
@JsonProperty
27+
public Object policy_overrides;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.microsoft.windowsazure.services.media.implementation.templates.widevine;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertNull;
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import javax.xml.bind.JAXBException;
9+
10+
import org.junit.Test;
11+
import com.fasterxml.jackson.core.JsonProcessingException;
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
14+
public class WidevineMessageSerializerTests {
15+
16+
@Test
17+
public void RoundTripTest() throws JAXBException, URISyntaxException, IOException {
18+
ObjectMapper mapper = new ObjectMapper();
19+
WidevineMessage message = new WidevineMessage();
20+
message.allowed_track_types = AllowedTrackTypes.SD_HD;
21+
ContentKeySpecs ckspecs = new ContentKeySpecs();
22+
message.content_key_specs = new ContentKeySpecs[] { ckspecs };
23+
ckspecs.required_output_protection = new RequiredOutputProtection();
24+
ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE;
25+
ckspecs.security_level = 1;
26+
ckspecs.track_type = "SD";
27+
message.policy_overrides = new Object() {
28+
public boolean can_play = true;
29+
public boolean can_persist = true;
30+
public boolean can_renew = false;
31+
};
32+
33+
String json = mapper.writeValueAsString(message);
34+
35+
WidevineMessage result = mapper.readValue(json, WidevineMessage.class);
36+
37+
assertEqualsWidevineMessage(message, result);
38+
}
39+
40+
@Test
41+
public void FromJsonTest() throws JAXBException, URISyntaxException, JsonProcessingException {
42+
String expected = "{\"allowed_track_types\":\"SD_HD\",\"content_key_specs\":[{\"track_type\":\"SD\",\"key_id\":null,\"security_level\":1,\"required_output_protection\":{\"hdcp\":\"HDCP_NONE\"}}],\"policy_overrides\":{\"can_play\":true,\"can_persist\":true,\"can_renew\":false}}";
43+
ObjectMapper mapper = new ObjectMapper();
44+
WidevineMessage message = new WidevineMessage();
45+
message.allowed_track_types = AllowedTrackTypes.SD_HD;
46+
ContentKeySpecs ckspecs = new ContentKeySpecs();
47+
message.content_key_specs = new ContentKeySpecs[] { ckspecs };
48+
ckspecs.required_output_protection = new RequiredOutputProtection();
49+
ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE;
50+
ckspecs.security_level = 1;
51+
ckspecs.track_type = "SD";
52+
message.policy_overrides = new Object() {
53+
public boolean can_play = true;
54+
public boolean can_persist = true;
55+
public boolean can_renew = false;
56+
};
57+
58+
String json = mapper.writeValueAsString(message);
59+
60+
assertEquals(expected, json);
61+
}
62+
63+
private static void assertEqualsWidevineMessage(WidevineMessage expected, WidevineMessage actual) {
64+
assertEquals(expected.allowed_track_types, actual.allowed_track_types);
65+
if (expected.content_key_specs == null) {
66+
assertNull(actual.content_key_specs);
67+
} else {
68+
assertNotNull(actual.content_key_specs);
69+
assertEquals(expected.content_key_specs.length, actual.content_key_specs.length);
70+
for(int i = 0; i < expected.content_key_specs.length; i++) {
71+
ContentKeySpecs expectedCks = expected.content_key_specs[i];
72+
ContentKeySpecs actualCks = actual.content_key_specs[i];
73+
assertEquals(expectedCks.key_id, actualCks.key_id);
74+
assertEquals(expectedCks.security_level, actualCks.security_level);
75+
assertEquals(expectedCks.track_type, actualCks.track_type);
76+
if (expectedCks.required_output_protection != null) {
77+
assertNotNull(actualCks.required_output_protection);
78+
assertEquals(expectedCks.required_output_protection.hdcp, actualCks.required_output_protection.hdcp);
79+
} else {
80+
assertNull(actualCks.required_output_protection);
81+
}
82+
assertEquals(expectedCks.key_id, actualCks.key_id);
83+
}
84+
}
85+
if (expected.policy_overrides == null) {
86+
assertNull(actual.policy_overrides);
87+
} else {
88+
assertNotNull(actual.policy_overrides);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)