Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WASM parser): parse correctly <Label> to a tag and not an attribute #1541

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parsers/manifest/dash/wasm-parser/rs/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub enum TagName {
// -- Inside a <SegmentList> --
/// Indicate a <SegmentURL> node
SegmentUrl = 20,

/// Indicate a <Label> node
Label = 21,
}

#[derive(PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -276,8 +279,6 @@ pub enum AttributeName {
/// namespaces that will appear in it.
Namespace = 70,

Label = 71, // String

ServiceLocation = 72, // String

// SegmentTemplate
Expand Down
8 changes: 6 additions & 2 deletions src/parsers/manifest/dash/wasm-parser/rs/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ impl MPDProcessor {
}
b"cenc:pssh" => self.process_cenc_element(),
b"Location" => self.process_location_element(),
b"Label" => self.process_label_element(),
b"Label" => {
TagName::Label.report_tag_open();
self.process_label_element();
}
b"SegmentTimeline" => self.process_segment_timeline_element(),

b"EventStream" => {
Expand Down Expand Up @@ -274,7 +277,7 @@ impl MPDProcessor {
Ok(Event::Text(t)) => {
if t.len() > 0 {
match t.unescape() {
Ok(unescaped) => AttributeName::Label.report(unescaped),
Ok(unescaped) => AttributeName::Text.report(unescaped),
Err(err) => ParsingError::from(err).report_err(),
}
}
Expand All @@ -284,6 +287,7 @@ impl MPDProcessor {
if inner_tag > 0 {
inner_tag -= 1;
} else {
TagName::Label.report_tag_close();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { parseFloatOrBool, parseString } from "../utils";
import { generateBaseUrlAttrParser } from "./BaseURL";
import { generateContentComponentAttrParser } from "./ContentComponent";
import { generateContentProtectionAttrParser } from "./ContentProtection";
import { generateLabelElementParser } from "./Label";
import {
generateRepresentationAttrParser,
generateRepresentationChildrenParser,
Expand Down Expand Up @@ -209,6 +210,15 @@ export function generateAdaptationSetChildrenParser(
break;
}

case TagName.Label: {
parsersStack.pushParsers(
nodeId,
noop, // Label as treated like an attribute
generateLabelElementParser(adaptationSetChildren, linearMemory),
);
break;
}

default:
// Allows to make sure we're not mistakenly closing a re-opened
// tag.
Expand Down Expand Up @@ -363,11 +373,6 @@ export function generateAdaptationSetAttrParser(
case AttributeName.AvailabilityTimeComplete:
adaptationAttrs.availabilityTimeComplete = dataView.getUint8(0) === 0;
break;
case AttributeName.Label: {
const label = parseString(textDecoder, linearMemory.buffer, ptr, len);
adaptationAttrs.label = label;
break;
}

// TODO
// case AttributeName.StartsWithSap:
Expand Down
16 changes: 16 additions & 0 deletions src/parsers/manifest/dash/wasm-parser/ts/generators/Label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { IAdaptationSetChildren } from "../../../node_parser_types";
import type { IAttributeParser } from "../parsers_stack";
import { AttributeName } from "../types";
import { parseString } from "../utils";

export function generateLabelElementParser(
adaptationSet: IAdaptationSetChildren,
linearMemory: WebAssembly.Memory,
): IAttributeParser {
const textDecoder = new TextDecoder();
return function onMPDAttribute(attr: AttributeName, ptr: number, len: number) {
if (attr === AttributeName.Text) {
adaptationSet.label = parseString(textDecoder, linearMemory.buffer, ptr, len);
}
};
}
3 changes: 3 additions & 0 deletions src/parsers/manifest/dash/wasm-parser/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export const enum TagName {

/// Indicate a <SegmentURL> node
SegmentUrl = 20,

/// Indicate a <Label> node
Label = 21,
}

/**
Expand Down
Loading