Parse role and accessibility descriptor values from adaptation sets#5578
Parse role and accessibility descriptor values from adaptation sets#5578ojw28 merged 5 commits intogoogle:dev-v2from
Conversation
| return MimeTypes.AUDIO_E_AC3; | ||
| } | ||
|
|
||
| protected static String parseRole(List<Descriptor> roleDescriptors) { |
There was a problem hiding this comment.
Making these non-static to allow overriding seems fine to me. And move them up to be grouped with the other protected non-static methods.
Note that after the suggestions I made on the corresponding issue, these methods will return @Role and @Accessibility integers respectively.
There was a problem hiding this comment.
I'd be tempted to make a parseSelectionFlags method too, that can parse selection flags from the role descriptors. The default implementation will contain the little piece of code that decides whether to set C.SELECTION_FLAG_DEFAULT that's currently further up in this class.
| /** | ||
| * The Role descriptor value. | ||
| */ | ||
| public final String role; |
There was a problem hiding this comment.
Note that video formats can have role/accessibility as well. As can selection flags actually. So these three params shouldn't be under "// Audio and text specific.". They should probably be right up under the label param, or somewhere near there.
There was a problem hiding this comment.
Then I guess the parsing also needs to be moved up, right now it is called only in case of mimeTypeIsRawText(sampleMimeType) == true in DashManifestParser. Right?
… also for video / audio tracks
|
Updated. |
| */ | ||
| @Documented | ||
| @Retention(RetentionPolicy.SOURCE) | ||
| @IntDef({ |
There was a problem hiding this comment.
As per the issue thread, I'd suggest merging the two IntDefs and making it flag = true. You can then also remove the UNSET constants, since unset is just 0 for flags.
| public final int selectionFlags; | ||
| /** Track role descriptor value, or {@link C#ROLE_UNSET} if unknown or not applicable. **/ | ||
| @C.Role | ||
| public final int role; |
There was a problem hiding this comment.
And having a single roleFlags, rather than separate role and accessibility fields.
| return C.ROLE_UNSET; | ||
| } | ||
|
|
||
| protected @C.Accessibility int parseAccessibility(List<Descriptor> accessibilityDescriptors) { |
There was a problem hiding this comment.
If going with my suggested approach, this method will return C.RoleFlags, which is slightly strange. But then it's somewhat strange DASH-IF separated use of urn:mpeg:dash:role:2011 across Role and Accessibility elements to start with, in my opinion :)... They should then be OR'd with the parseRole result to get the final flags.
You could probably have a single method parse "urn:mpeg:dash:role:2011" that you call from both parseRole and parseAccessibility. I think we'd probably want to handle things like "description" appearing as Role elements as well.
There was a problem hiding this comment.
You could probably have a single method parse "urn:mpeg💨role:2011" that you call from both parseRole and parseAccessibility. I think we'd probably want to handle things like "description" appearing as Role elements as well.
This would mean that the roleFlags would have a common flag for role's "description" and accessibility's "description" values. In this case we couldn't decide if the "description" came from role or from accessibility.
Even if a couple of values could be the same for role and accessibility, I would store them as separate flags, as at the end we need to know where a value comes from (role or accessibility descriptor). Or am I missing something?
There was a problem hiding this comment.
Nevermind, probably we can merge these as you said under the correspondent issue.
|
Merged role and accessibility fields together as you've suggested. |
| public static final int NETWORK_TYPE_OTHER = 8; | ||
|
|
||
| /** | ||
| * Adaptation set's role and accessibility descriptor value. |
There was a problem hiding this comment.
nit - Avoid DASH specific terms; there's no reason roles can't be used for other media formats. I would also avoid mentioning accessibility; since outside of the DASH specific parsing where they're merged, they're just "roles" and nothing else. Would suggest documenting like:
Track role flags. Possible values are {@link XXX}, ...
See how SelectionFlags is documented for an example.
ojw28
left a comment
There was a problem hiding this comment.
Looking good. Just a bunch of nitty little things really, and then we'll get this merged. Thanks!
| }) | ||
| public @interface RoleFlags {} | ||
|
|
||
| public static final int ROLE_FLAGS_MAIN = 1; |
There was a problem hiding this comment.
Can we please add Javadoc on each of these constants?
There was a problem hiding this comment.
Yeah, I wanted but I didn't find the standard you were referred to (draft of third version of 23009-1) and I wanted to take the definition from there. In the second edition fo 23009-1 a couple of role values are missing (e.g. "sign"). But I will search for it again.
There was a problem hiding this comment.
Feel free to leave them if you don't have the doc. I can add in some documentation when I merge.
There was a problem hiding this comment.
I haven't found it yet, please add these comments.
| /** Track selection flags. **/ | ||
| @C.SelectionFlags | ||
| public final int selectionFlags; | ||
| /** Track role and accessibility descriptor values. **/ |
There was a problem hiding this comment.
nit: Just "Track role flags."
| @C.SelectionFlags int selectionFlags, | ||
| @Nullable String language) { | ||
| @Nullable String language, | ||
| @C.RoleFlags int roleFlags) { |
There was a problem hiding this comment.
nit: Seems nice to group selectionFlags and roleFlags together, as in the methods above? Ditto for methods below this one.
| @C.SelectionFlags int selectionFlags, | ||
| @Nullable String language, | ||
| int accessibilityChannel, | ||
| @C.RoleFlags int roleFlags, |
There was a problem hiding this comment.
nit: Put next to selectionFlags? Ditto x lots below.
| } else if (XmlPullParserUtil.isStartTag(xpp, "Role")) { | ||
| selectionFlags |= parseRole(xpp); | ||
| Descriptor descriptor = parseDescriptor(xpp, "Role"); | ||
| selectionFlags |= parseSelectionFlags(descriptor); |
There was a problem hiding this comment.
It seems cleaner to have a parseSelection(roleDescriptors) that you can call in buildFormat. This saves you from having to pass selectionFlags into that method separately.
| language, | ||
| accessibilityChannel); | ||
| accessibilityChannel, | ||
| roleFlags); |
There was a problem hiding this comment.
I think you probably need to pass roleFlags into the Format.createContainerFormat on L647 (below) as well as the ones you've already done.
| if ("urn:mpeg:dash:role:2011".equalsIgnoreCase(descriptor.schemeIdUri) && descriptor.value != null) { | ||
| result |= parseRoleSchemeValue(descriptor.value); | ||
| } | ||
| if ("urn:tva:metadata:cs:AudioPurposeCS:2007".equalsIgnoreCase(descriptor.schemeIdUri) && |
| } | ||
| if ("urn:tva:metadata:cs:AudioPurposeCS:2007".equalsIgnoreCase(descriptor.schemeIdUri) && | ||
| descriptor.value != null) { | ||
| switch (descriptor.value){ |
There was a problem hiding this comment.
Although it's only used here, it might be nice to split this into a parseAudioPurposeValue method, for consistency with parseRoleSchemeValue.
| @C.RoleFlags int result = 0; | ||
| switch (value) { | ||
| case "main": | ||
| result |= C.ROLE_FLAGS_MAIN; |
There was a problem hiding this comment.
You can just return C.ROLE_FLAGS_X; for each case, and add a default case that returns 0. Ditto for parseAudioPurposeValue if you make that a method too.
| @C.RoleFlags int result = 0; | ||
| for (int i = 0; i < roleDescriptors.size(); i++) { | ||
| Descriptor descriptor = roleDescriptors.get(i); | ||
| if ("urn:mpeg:dash:role:2011".equalsIgnoreCase(descriptor.schemeIdUri) && descriptor.value != null) { |
There was a problem hiding this comment.
It would IMO be neater for the null check to happen at the start of parseRoleSchemeValue (ditto parseAudioPurposeValue if you make that).
|
I will do these minor changes later today. You would like to have some test cases for this whole role flags, or do you think isn't so important right now? |
|
Thanks! Feel free to add some test cases if you think they'd be helpful, but I don't think it's hugely important in this case. The non-parser parts are trivial, and parsing code tends to be write-once-never-touch-again. |
|
Updated. I hope I've covered everything, please say so if not. I decided to not to add tests for now :) |
|
Thanks! |
This is a precursor to merging #5578 PiperOrigin-RevId: 239371046
Pull request for Issue #5529 .