Skip to content

Commit ab4b358

Browse files
committed
Made message parsing more lenient
Observing Disney+ playback revealed several deviations from the protocol. To prevent these from causing parsing errors, the following have been done: - Added invalid PlayerState "LOADING" - Created custom fontFamily parser to handle non-string node - Made TextTrackEdgeType accept constants with invalid case
1 parent cc11dc1 commit ab4b358

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

src/main/java/org/digitalmediaserver/cast/message/entity/TextTrackStyle.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import org.digitalmediaserver.cast.message.enumeration.TextTrackFontGenericFamily;
2727
import org.digitalmediaserver.cast.message.enumeration.TextTrackFontStyle;
2828
import org.digitalmediaserver.cast.message.enumeration.TextTrackWindowType;
29+
import org.digitalmediaserver.cast.util.FontFamilyDeserializer;
2930
import com.fasterxml.jackson.annotation.JsonInclude;
3031
import com.fasterxml.jackson.annotation.JsonProperty;
32+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
3133

3234

3335
/**
@@ -73,6 +75,7 @@ public class TextTrackStyle {
7375
@Nullable
7476
@JsonProperty
7577
@JsonInclude(JsonInclude.Include.NON_NULL)
78+
@JsonDeserialize(using = FontFamilyDeserializer.class)
7679
protected final String fontFamily;
7780

7881
/** The text track generic font family */

src/main/java/org/digitalmediaserver/cast/message/enumeration/PlayerState.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public enum PlayerState {
4343
PAUSED,
4444

4545
/** The player is in BUFFERING state */
46-
BUFFERING;
46+
BUFFERING,
47+
48+
/** The player is in LOADING state (this isn't a valid state, but try telling that to Disney) */
49+
LOADING;
4750

4851
/**
4952
* Parses the specified string and returns the corresponding

src/main/java/org/digitalmediaserver/cast/message/enumeration/TextTrackEdgeType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@
1515
*/
1616
package org.digitalmediaserver.cast.message.enumeration;
1717

18+
import com.fasterxml.jackson.annotation.JsonAlias;
1819

1920
/**
2021
* Defines the text track edge type.
2122
*/
2223
public enum TextTrackEdgeType {
2324

2425
/** No edge is displayed around text */
26+
@JsonAlias("none")
2527
NONE,
2628

2729
/** Solid outline is displayed around text */
30+
@JsonAlias("outline")
2831
OUTLINE,
2932

3033
/** A fading shadow is casted around text */
34+
@JsonAlias("drop_shadow")
3135
DROP_SHADOW,
3236

3337
/** Text is embossed on background */
38+
@JsonAlias("raised")
3439
RAISED,
3540

3641
/** Text is debossed on background */
42+
@JsonAlias("depressed")
3743
DEPRESSED
3844
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (C) 2025 Digital Media Server developers.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.digitalmediaserver.cast.util;
17+
18+
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.Iterator;
21+
import java.util.List;
22+
import java.util.Map.Entry;
23+
import com.fasterxml.jackson.core.JsonParser;
24+
import com.fasterxml.jackson.core.JsonProcessingException;
25+
import com.fasterxml.jackson.databind.DeserializationContext;
26+
import com.fasterxml.jackson.databind.JavaType;
27+
import com.fasterxml.jackson.databind.JsonNode;
28+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
29+
30+
31+
/**
32+
* A custom deserializer for {@code fontFamily} values since despite the
33+
* documentation stating that they should be strings, it's not always the case,
34+
* which leads to parsing errors.
35+
*
36+
* @author Nadahar
37+
*/
38+
public class FontFamilyDeserializer extends StdDeserializer<String> {
39+
40+
private static final long serialVersionUID = 1L;
41+
42+
/**
43+
* Creates a new instance.
44+
*/
45+
public FontFamilyDeserializer() {
46+
super((Class<?>) null);
47+
}
48+
49+
/**
50+
* Creates a new instance using the specified parameter.
51+
*
52+
* @param vc the {@link Class} to use.
53+
*/
54+
public FontFamilyDeserializer(Class<?> vc) {
55+
super(vc);
56+
}
57+
58+
/**
59+
* Creates a new instance using the specified parameter.
60+
*
61+
* @param valueType the {@link JavaType} to use.
62+
*/
63+
public FontFamilyDeserializer(JavaType valueType) {
64+
super(valueType);
65+
}
66+
67+
/**
68+
* Creates a new instance using the specified parameter.
69+
*
70+
* @param src the {@link StdDeserializer} to use.
71+
*/
72+
public FontFamilyDeserializer(StdDeserializer<?> src) {
73+
super(src);
74+
}
75+
76+
@Override
77+
public String deserialize(
78+
JsonParser parser,
79+
DeserializationContext ctxt
80+
) throws IOException, JsonProcessingException {
81+
JsonNode node = parser.getCodec().readTree(parser);
82+
if (node.isContainerNode()) {
83+
List<String> strings = new ArrayList<>();
84+
String s;
85+
if (node.isArray()) {
86+
for (int i = 0; i < node.size(); i++) {
87+
s = node.get(i).textValue();
88+
if (!Util.isBlank(s)) {
89+
strings.add(s);
90+
}
91+
}
92+
} else {
93+
Entry<String, JsonNode> entry;
94+
for (Iterator<Entry<String, JsonNode>> iterator = node.fields(); iterator.hasNext();) {
95+
entry = iterator.next();
96+
s = entry.getValue().textValue();
97+
if (!Util.isBlank(s)) {
98+
strings.add(s);
99+
}
100+
}
101+
}
102+
StringBuilder sb = new StringBuilder();
103+
for (String string : strings) {
104+
if (sb.length() > 0) {
105+
sb.append(", ");
106+
}
107+
sb.append(string);
108+
}
109+
return sb.toString();
110+
}
111+
return node.asText();
112+
}
113+
}

src/main/java/org/digitalmediaserver/cast/util/MediaStatusResponseDeserializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public MediaStatusResponseDeserializer(JavaType valueType) {
7272
public MediaStatusResponseDeserializer(StdDeserializer<?> src) {
7373
super(src);
7474
}
75+
7576
@Override
7677
public MediaStatusResponse deserialize(
7778
JsonParser parser,

0 commit comments

Comments
 (0)