Skip to content

Instantly share code, notes, and snippets.

@mlevkov
Created May 21, 2020 02:51
Show Gist options
  • Save mlevkov/094a3c671b175bba5d0a6511d8c0d348 to your computer and use it in GitHub Desktop.
Save mlevkov/094a3c671b175bba5d0a6511d8c0d348 to your computer and use it in GitHub Desktop.
DASH Parser Work In Progress
use std::io::{Read, Write};
use yaserde::{YaDeserialize, YaSerialize};
use std::prelude::v1::String;
// <!-- Base URL -->
// #[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
// #[yaserde(
// prefix = "mpd",
// namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
// default_namespace = "mpd"
// )]
// pub struct S {
// #[yaserde(flatten)]
// attribute: SAttribute,
// }
// non-standard types
// alias for now
type Duration = String; // temp alias
type DateTime = String; // temp alias
type Ratio = String;
type FrameRate = String;
type ConditionalUintType = String;
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct MPD {
#[yaserde(flatten)]
attribute: MPDAttributes,
#[yaserde(flatten)]
elements: MPDElements,
}
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct MPDElements{
#[yaserde(rename = "ProgramInformation")]
pub program_information: Vec<ProgramInformation>,
#[yaserde(rename = "BaseURL")]
pub base_url: Vec<BaseUrl>,
#[yaserde(rename = "Location")]
pub location: Vec<String>,
#[yaserde(rename = "Period")]
pub period: Vec<Period>,
#[yaserde(rename = "Metrics")]
pub metrics: Vec<Metrics>,
#[yaserde(rename = "EssentialProperty")]
pub essential_property: Vec<Descriptor>,
#[yaserde(rename = "SupplementalProperty")]
pub supplemental_property: Vec<Descriptor>,
#[yaserde(rename = "UTCTiming")]
pub utc_timing: Vec<Descriptor>,
}
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct MPDAttributes{
#[yaserde(attribute, rename = "id")]
pub id: Option<String>,
#[yaserde(attribute, rename = "profiles")]
pub profiles: String,
#[yaserde(attribute, rename = "type")]
pub type_: Option<PresentationType>,
#[yaserde(attribute, rename = "availabilityStartTime")]
pub availability_start_time: Option<DateTime>,
#[yaserde(attribute, rename = "availabilityEndTime")]
pub availability_end_time: Option<DateTime>,
#[yaserde(attribute, rename = "publishTime")]
pub publish_time: Option<DateTime>,
#[yaserde(attribute, rename = "mediaPresentationDuration")]
pub media_presentation_duration: Option<Duration>,
#[yaserde(attribute, rename = "minimumUpdatePeriod")]
pub minimum_update_period: Option<Duration>,
#[yaserde(attribute, rename = "minBufferTime")]
pub min_buffer_time: Duration,
#[yaserde(attribute, rename = "timeShiftBufferDepth")]
pub time_shift_buffer_depth: Option<Duration>,
#[yaserde(attribute, rename = "suggestedPresentationDelay")]
pub suggested_presentation_delay: Option<Duration>,
#[yaserde(attribute, rename = "maxSegmentDuration")]
pub max_segment_duration: Option<Duration>,
#[yaserde(attribute, rename = "maxSubsegmentDuration")]
pub max_subsegment_duration: Option<Duration>,
}
#[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
pub enum PresentationType {
#[yaserde(rename = "static")]
Static,
#[yaserde(rename = "dynamic")]
Dynamic,
__Unknown__(String),
}
impl Default for PresentationType {
fn default() -> PresentationType {
Self::__Unknown__("No valid variants".into())
}
}
// <!-- Period -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct Period {
#[yaserde(flatten)]
attribute: PeriodAttributes,
#[yaserde(flatten)]
element: PeriodElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
struct PeriodAttributes {
#[yaserde(flatten)]
pub xlink: Xlink,
#[yaserde(rename = "id", attribute)]
pub id: Option<String>,
#[yaserde(rename = "start", attribute)]
pub start: Option<Duration>,
#[yaserde(rename = "duration", attribute)]
pub duration: Option<Duration>,
#[yaserde(rename = "bitstreamSwitching", attribute)]
pub bitstream_switching: Option<bool>,
}
impl Default for PeriodAttributes{
fn default () -> Self {
Self {
xlink: Default::default(),
id: None,
start: None,
duration: None,
bitstream_switching: Some(false),
}
}
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct PeriodElements {
#[yaserde(rename = "BaseURL")]
pub base_url: Vec<BaseUrl>,
#[yaserde(rename = "SegmentBase")]
pub segment_base: Vec<SegmentBase>,
#[yaserde(rename = "SegmentList")]
pub segment_list: Vec<SegmentList>,
#[yaserde(rename = "SegmentTemplate")]
pub segment_template: Vec<SegmentTemplate>,
#[yaserde(rename = "AssetIdentifier")]
pub asset_identifier: Vec<Descriptor>,
#[yaserde(rename = "EventStream")]
pub event_stream: Vec<EventStream>,
#[yaserde(rename = "AdaptationSet")]
pub adaptation_set: Vec<AdaptationSet>,
#[yaserde(rename = "Subset")]
pub subset: Vec<Subset>,
#[yaserde(rename = "SupplementalProperty")]
pub supplemental_property: Vec<Descriptor>,
}
// <!-- Event -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct Event {
#[yaserde(flatten)]
pub attribute: EventAttributes
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct EventAttributes {
#[yaserde(rename = "presentationTime", attribute)]
pub presentation_time: Option<u64>,
#[yaserde(rename = "duration", attribute)]
pub duration: Option<u64>,
#[yaserde(rename = "id", attribute)]
pub id: Option<u32>,
#[yaserde(rename = "messageData", attribute)]
pub message_data: Option<String>,
}
// <!-- Event Stream -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct EventStream {
#[yaserde(flatten)]
pub attribute: EventStreamAttributes,
#[yaserde(flatten)]
pub element: EventStreamElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct EventStreamAttributes {
#[yaserde(flatten)]
pub xlink: Xlink,
#[yaserde(rename = "schemeIdUri", attribute)]
pub scheme_id_uri: Option<String>,
#[yaserde(rename = "value", attribute)]
pub value: Option<String>,
#[yaserde(rename = "timescale", attribute)]
pub timescale: Option<u64>,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
pub struct EventStreamElements {
#[yaserde(rename = "Event")]
pub event: Vec<Event>
}
/*
#[derive(PartialEq, Debug, YaSerialize, YaDeserialize)]
pub enum ConditionalUintType {
UnsignedInt(u32),
Boolean(bool),
__Unknown__(String),
}
impl Default for ConditionalUintType {
fn default() -> ConditionalUintType {
Self::__Unknown__("No valid variants".into())
}
}
*/
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct AdaptationSet {
#[yaserde(flatten)]
pub representation_base: RepresentationBase,
#[yaserde(flatten)]
pub attribute: AdaptationSetAttributes,
#[yaserde(flatten)]
pub element: AdaptationSetElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "mpd: urn:mpeg:dash:schema:mpd:2011")]
pub struct AdaptationSetAttributes {
#[yaserde(flatten)]
pub xlink: Xlink,
#[yaserde(rename = "id", attribute)]
pub id: Option<u32>,
#[yaserde(rename = "group", attribute)]
pub group: Option<u32>,
#[yaserde(rename = "lang", attribute)]
pub lang: Option<String>,
// pattern value="[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"
#[yaserde(rename = "contentType", attribute)]
pub content_type: Option<String>,
#[yaserde(rename = "par", attribute)]
pub par: Option<Ratio>,
// pattern value="[0-9]*:[0-9]*"
#[yaserde(rename = "minBandwidth", attribute)]
pub min_bandwidth: Option<u32>,
#[yaserde(rename = "maxBandwidth", attribute)]
pub max_bandwidth: Option<u32>,
#[yaserde(rename = "minWidth", attribute)]
pub min_width: Option<u32>,
#[yaserde(rename = "maxWidth", attribute)]
pub max_width: Option<u32>,
#[yaserde(rename = "minHeight", attribute)]
pub min_height: Option<u32>,
#[yaserde(rename = "maxHeight", attribute)]
pub max_height: Option<u32>,
#[yaserde(rename = "minFrameRate", attribute)]
pub min_frame_rate: Option<FrameRate>,
// pattern value="[0-9]*[0-9](/[0-9]*[0-9])?"
#[yaserde(rename = "maxFrameRate", attribute)]
pub max_frame_rate: Option<FrameRate>,
// pattern value="[0-9]*[0-9](/[0-9]*[0-9])?"
#[yaserde(rename = "segmentAlignment", attribute)]
pub segment_alignment: Option<ConditionalUintType>,
// union memberTypes="xs:unsignedInt xs:boolean", not yet
#[yaserde(rename = "subsegmentAlignment", attribute)]
pub sub_segment_alignment: Option<String>,
// union memberTypes="xs:unsignedInt xs:boolean", not yet
#[yaserde(rename = "subsegmentStartsWithSAP", attribute)]
pub sub_segment_starts_with_sap: u32,
// restrictive min 0, max 6
#[yaserde(rename = "bitstreamSwitching", attribute)]
pub bitstream_switching: bool,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
struct AdaptationSetElements {
#[yaserde(rename = "Accessibility")]
accessibility: Vec<Descriptor>,
#[yaserde(rename = "Role")]
role: Vec<Descriptor>,
#[yaserde(rename = "Rating")]
rating: Vec<Descriptor>,
#[yaserde(rename = "Viewpoint")]
viewpoint: Vec<Descriptor>,
#[yaserde(rename = "ContentComponents")]
content_component: Vec<ContentComponent>,
#[yaserde(rename = "BaseURL")]
base_url: Vec<BaseUrl>,
#[yaserde(rename = "SegmentBase")]
segment_base: Option<SegmentBase>,
#[yaserde(rename = "SegmentList")]
segment_list: Option<SegmentList>,
#[yaserde(rename = "SegmentTemplate")]
segment_template: Option<SegmentTemplate>,
#[yaserde(rename = "Representation")]
representation: Vec<Representation>,
}
// struct Ratio {}
// struct FrameRate {}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct ContentComponent {
#[yaserde(flatten)]
attribute: ContentComponentAttributes,
#[yaserde(flatten)]
element: ContentComponentElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct ContentComponentAttributes {
#[yaserde(rename = "id", attribute)]
id: u32,
#[yaserde(rename = "lang", attribute)]
lang: String,
// pattern value="[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"
#[yaserde(rename = "contentType", attribute)]
content_type: String,
#[yaserde(rename = "par", attribute)]
par: String, // pattern value="[0-9]*:[0-9]*"
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct ContentComponentElements {
#[yaserde(rename = "Accessibility")]
accessibility: Vec<Descriptor>,
#[yaserde(rename = "Role")]
role: Vec<Descriptor>,
#[yaserde(rename = "Rating")]
rating: Vec<Descriptor>,
#[yaserde(rename = "Viewpoint")]
viewpoint: Vec<Descriptor>,
}
// <!-- Representation -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct Representation {
#[yaserde(flatten)]
representation_base: RepresentationBase,
#[yaserde(flatten)]
attribute: RepresentationAttributes,
#[yaserde(flatten)]
element: RepresentationElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct RepresentationAttributes {
#[yaserde(rename = "id", attribute)]
id: String,
#[yaserde(rename = "bandwidth", attribute)]
bandwidth: u32,
#[yaserde(rename = "qualityRanking", attribute)]
quality_ranking: u32,
#[yaserde(rename = "dependencyId", attribute)]
dependency_id: String,
// ^^? Not sure this is the right type
#[yaserde(rename = "mediaStreamStructureId", attribute)]
media_stream_structure_id: String,
// ^^? Not sure this is the right type
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct RepresentationElements{
#[yaserde(rename="BaseURL")]
base_url: Vec<BaseUrl>,
#[yaserde(rename="SubRepresentation")]
sub_representation: Vec<SubRepresentation>,
#[yaserde(rename="SegmentBase")]
segment_base: Option<SegmentBase>,
#[yaserde(rename="SegmentList")]
segment_list: Option<SegmentList>,
#[yaserde(rename="SegmentTemplate")]
segment_template: Option<SegmentTemplate>
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SubRepresentation {
#[yaserde(flatten)]
representation_base: RepresentationBase,
#[yaserde(flatten)]
attribute: SubRepresentationAttributes
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SubRepresentationAttributes{
level: u32,
dependency_level: Vec<u32>, // list itemType="xs:unsignedInt"?
bandwidth: u32,
content_component: Vec<String>
}
// <!-- Representation base (common attributes and elements) -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct RepresentationBase {
#[yaserde(flatten)]
attribute: RepresentationBaseAttributes,
#[yaserde(flatten)]
element: RepresentationBaseElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct RepresentationBaseAttributes {
#[yaserde(rename = "profiles", attribute)]
profiles: String,
#[yaserde(rename = "width", attribute)]
width: u32,
#[yaserde(rename = "height", attribute)]
height: u32,
#[yaserde(rename = "sar", attribute)]
sar: String,
// pattern value="[0-9]*:[0-9]*"
#[yaserde(rename = "frameRate", attribute)]
frame_rate: String,
// pattern value="[0-9]*[0-9](/[0-9]*[0-9])?"
#[yaserde(rename = "audioSamplingRate", attribute)]
audio_sampling_rate: String,
#[yaserde(rename = "mimeType", attribute)]
mime_type: String,
#[yaserde(rename = "segmentProfiles", attribute)]
segment_profiles: String,
#[yaserde(rename = "codecs", attribute)]
codecs: String,
#[yaserde(rename = "maximumSAPPeriod", attribute)]
maximum_sap_period: f64,
#[yaserde(rename = "startWithSAP", attribute)]
start_with_sap: u32,
#[yaserde(rename = "maxPlayoutRate", attribute)]
max_playout_rate: f64,
#[yaserde(rename = "codingDependency", attribute)]
coding_dependency: bool,
#[yaserde(rename = "scanType", attribute)]
scan_type: String,
// should be enum
// enumeration value="progressive"
// enumeration value="interlaced"
// enumeration value="unknown"
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct RepresentationBaseElements {
#[yaserde(rename = "FramePacking")]
frame_packing: Vec<Descriptor>,
#[yaserde(rename = "AudioChannelConfiguration")]
audio_channel_configuration: Vec<Descriptor>,
#[yaserde(rename = "ContentProtection")]
content_protection: Vec<Descriptor>,
#[yaserde(rename = "EssentialProperty")]
essential_property: Vec<Descriptor>,
#[yaserde(rename = "SupplementalProperty")]
supplemental_property: Vec<Descriptor>,
#[yaserde(rename = "InbandEventStream")]
inband_event_stream: Vec<EventStream>,
}
struct SAP {}
struct VideoScan {}
struct Subset {}
// <!-- Segment Base -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentBase {
#[yaserde(flatten)]
attribute: SegmentBaseAttributes,
#[yaserde(flatten)]
element: SegmentBaseElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SegmentBaseAttributes {
#[yaserde(rename = "timescale", attribute)]
timescale: u32,
#[yaserde(rename = "presentationTimeOffset", attribute)]
presentation_time_offset: u64,
#[yaserde(rename = "indexRange", attribute)]
index_range: String,
#[yaserde(rename = "indexRangeExact", attribute)]
index_range_exact: bool,
#[yaserde(rename = "availabilityTimeOffset", attribute)]
availability_time_offset: f64,
#[yaserde(rename = "availabilityTimeComplete", attribute)]
availability_time_complete: bool,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SegmentBaseElements {
#[yaserde(rename = "Initialization")]
initialization: Option<URL>,
#[yaserde(rename = "RepresentationIndex")]
representation_index: Option<URL>,
}
// <!- URL Type ->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct URL {
#[yaserde(flatten)]
attribute: URLAttribute,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct URLAttribute {
#[yaserde(rename = "sourceURL", attribute)]
source_url: Option<String>,
#[yaserde(rename = "range", attribute)]
range: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct MultiSegmentBase {
#[yaserde = (flatten)]
base: SegmentUrl,
#[yaserde = (flatten)]
attribute: MultiSegmentBaseAttribute,
#[yaserde = (flatten)]
element: MultiSegmentBaseElement,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct MultiSegmentBaseAttribute {
#[yaserde(rename = "duration", attribute)]
duration: u32,
#[yaserde(raname = "startNumber", attribute)]
start_number: u32,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct MultiSegmentBaseElement {
#[yaserde(rename = "SegmentTimeline")]
segment_timeline: Option<SegmentTimeline>,
#[yaserde(rename = "BitstreamSwitching")]
bitstream_switching: Option<URL>,
}
// <!-- Segment List -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentList {
#[yaserde(flatten)]
multi_segment_base: MultiSegmentBase,
// ^^^ ?
#[yaserde(flatten)]
attribute: SegmentListAttributes,
#[yaserde(flatten)]
element: SegmentListElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentListAttributes {
#[yaserde(flatten)]
xlink: Xlink,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
struct SegmentListElements {
#[yaserde(rename = "SegmentURL")]
segment_url: Vec<SegmentUrl>,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(namespace = "urn:mpeg:dash:schema:mpd:2011")]
struct Xlink {
#[yaserde(rename = "href", attribute, prefix = "xlink")]
href: Option<String>,
#[yaserde(rename = "actuate", attribute, prefix = "xlink")] //, default = "onRequest")]
actuate: Option<String>,
}
impl Default for Xlink{
fn default() -> Self{
Self{ actuate: Some("onRequest".to_string()), ..Default::default() }
}
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentUrl {
#[yaserde(flatten)]
attribute: SegmentURLAttributes,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SegmentURLAttributes {
#[yaserde(rename = "media", attribute)]
media: String,
#[yaserde(rename = "media_range", attribute)]
media_range: String,
#[yaserde(rename = "index", attribute)]
index: String,
#[yaserde(rename = "indexRange", attribute)]
index_range: String,
}
// <!-- Segment Template -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentTemplate {
#[yaserde(flatten)]
multi_segment_base: MultiSegmentBase,
#[yaserde(flatten)]
attribute: SegmentTemplateAttribute,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SegmentTemplateAttribute {
#[yaserde(rename = "media", attribute)]
media: String,
#[yaserde(rename = "index", attribute)]
index: String,
#[yaserde(rename = "initialization", attribute)]
initialization: String,
#[yaserde(rename = "bitstreamSwitching", attribute)]
bistream_switching: String,
}
// <!-- Segment Timeline -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct SegmentTimeline {
#[yaserde(flatten)]
element: SegmentTimelineElements
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SegmentTimelineElements {
#[yaserde(rename = "S")]
s: Vec<S>
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct S {
#[yaserde(flatten)]
attribute: SAttributes
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct SAttributes {
#[yaserde(rename = "t", attribute)]
t: u64,
#[yaserde(rename = "n", attribute)]
n: Option<u64>,
#[yaserde(rename = "d", attribute)]
d: u64,
#[yaserde(rename = "r", attribute)]
r: Option<i64>,
}
// <!-- Base URL -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct BaseUrl {
#[yaserde(flatten)]
attribute: BaseUrlAttribute,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct BaseUrlAttribute {
#[yaserde(rename = "serviceLocation", attribute)]
service_location: Option<String>,
#[yaserde(rename = "byteRange", attribute)]
byte_range: Option<String>,
#[yaserde(rename = "availabilityTimeOffset", attribute)]
availability_time_offset: Option<f64>, // double
#[yaserde(rename = "availabilityTimeComplete", attribute)]
availability_time_complete: Option<bool>, // boolean
}
// <!-- Program Information -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct ProgramInformation {
#[yaserde(flatten)]
attribute: ProgramInformationAttributes,
#[yaserde(flatten)]
element: ProgramInformationElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct ProgramInformationAttributes {
#[yaserde(rename = "lang", attribute)]
language: Option<String>,
#[yaserde(rename = "moreInformationURL", attribute)]
more_information_url: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct ProgramInformationElements {
#[yaserde(rename = "Title")]
title: Option<String>,
#[yaserde(rename = "Source")]
source: Option<String>,
#[yaserde(rename = "Copyright")]
copyright: Option<String>,
}
// <!-- Descriptor -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct Descriptor {
#[yaserde(flatten)]
attribute: DescriptorAttributes,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct DescriptorAttributes {
#[yaserde(rename = "schemeIdUri", attribute)]
scheme_id_uri: Option<String>,
#[yaserde(attribute)]
value: Option<String>,
#[yaserde(attribute)]
id: Option<String>,
}
// <!-- Metrics -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct Metrics {
#[yaserde(flatten)]
attribute: MetricsAttributes,
#[yaserde(flatten)]
element: MetricsElements,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct MetricsAttributes {
#[yaserde(attribute)]
metrics: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct MetricsElements {
#[yaserde(rename = "schemeIdUri", attribute)]
reporting: Option<Descriptor>,
#[yaserde(attribute)]
range: Option<Range>,
}
// <!-- Metrics Range -->
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
struct Range {
#[yaserde(flatten)]
attribute: RangeAttributes,
}
#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(
prefix = "mpd",
namespace = "mpd: urn:mpeg:dash:schema:mpd:2011",
default_namespace = "mpd"
)]
struct RangeAttributes {
#[yaserde(rename = "starttime", attribute)]
start_time: Option<String>,
#[yaserde(attribute)]
duration: Option<String>,
}
/*
// borrowed from xsd-parser-rs project ;)
|XSD |rust |
|------------------|-----------------------|
|hexBinary |String |
|base64Binary |String |
|boolean |bool |
|integer |Integer (1) |
|nonNegativeInteger|NonNegativeInteger (1) |
|positiveInteger |PositiveInteger (1) |
|nonPositiveInteger|NonPositiveInteger (1) |
|negativeInteger |NegativeInteger (1) |
|long |i64 |
|int |i32 |
|short |i16 |
|byte |i8 |
|unsignedLong |u64 |
|unsignedInt |u32 |
|unsignedShort |u16 |
|unsignedByte |u8 |
|decimal |Decimal (2) |
|double |f64 |
|float |f64 |
|date |Date (3) |
|time |Time (3) |
|dateTime |DateTime (3) |
|dateTimeStamp |DateTimeStamp (3) |
|duration |Duration (4) |
|gDay |GDay (5) |
|gMonth |GMonth (5) |
|gMonthDay |GMonthDay (5) |
|gYear |GYear (5) |
|gYearMonth |GYearMonth (5) |
|string |String |
|normalizedString |String |
|token |String |
|language |String |
|Name |String |
|NCName |String |
|ENTITY |String |
|ID |String |
|IDREF |String |
|NMTOKEN |String |
|anyURI |String |
|QName |String |
|NOTATION |String |
|ENTITIES |Vec\<String\> |
|IDREFS |Vec\<String\> |
|NMTOKENS |Vec\<String\> |
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment