Skip to content

Commit

Permalink
Merge pull request #1109 from canalplus/feat/wasm-parser-label-tag
Browse files Browse the repository at this point in the history
Feature / Parse labels for adaptation sets in the WASM Parser
  • Loading branch information
peaBerberian committed Jun 7, 2022
2 parents 61abbd8 + 6449c6f commit c8154ed
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
Binary file modified dist/mpd-parser.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions src/parsers/manifest/dash/node_parser_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface IAdaptationSetAttributes {
width? : number;
availabilityTimeComplete?: boolean;
availabilityTimeOffset?: number;
label?: string;
}

export interface IRepresentationIntermediateRepresentation {
Expand Down
2 changes: 2 additions & 0 deletions src/parsers/manifest/dash/wasm-parser/rs/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub enum AttributeName {
/// format: the browser's `DOMParser` API needs to know all potential
/// namespaces that will appear in it.
Namespace = 70,

Label = 71, // String
}

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

Expand Down Expand Up @@ -261,6 +262,42 @@ impl MPDProcessor {
}
}

fn process_label_element(&mut self) {
// Count inner Label tags if it exists.
// Allowing to not close the current node when it is an inner that is closed
let mut inner_tag : u32 = 0;

loop {
match self.read_next_event() {
Ok(Event::Text(t)) => if t.len() > 0 {
match t.unescaped() {
Ok(unescaped) => AttributeName::Label.report(unescaped),
Err(err) => ParsingError::from(err).report_err(),
}
},
Ok(Event::Start(tag)) if tag.name() == b"Label" => inner_tag += 1,
Ok(Event::End(tag)) if tag.name() == b"Label" => {
if inner_tag > 0 {
inner_tag -= 1;
} else {
break;
}
},
Ok(Event::Eof) => {
ParsingError("Unexpected end of file in a Label tag.".to_owned())
.report_err();
break;
}
Err(e) => {
ParsingError::from(e).report_err();
break;
},
_ => (),
}
self.reader_buf.clear();
}
}

fn process_base_url_element(&mut self) {
// Count inner BaseURL tags if it exists.
// Allowing to not close the current node when it is an inner that is closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ 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
2 changes: 2 additions & 0 deletions src/parsers/manifest/dash/wasm-parser/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,6 @@ export const enum AttributeName {
/// format: the browser's `DOMParser` API needs to know all potential
/// namespaces that will appear in it.
Namespace = 70,

Label = 71, // String
}

0 comments on commit c8154ed

Please sign in to comment.