emarsden / dash-mpd-rs

Rust library for parsing, serializing and downloading media content from a DASH MPD manifest.
MIT License
72 stars 23 forks source link

f64 infinity should be serialized as INF instead of inf #49

Closed ypo closed 8 months ago

ypo commented 8 months ago

Serde serialize f64::INFINITY to 'inf', in XML it should be INF see http://www.datypic.com/sc/xsd/t-xsd_float.html

You will find bellow an example of MPD that I want to deserialize and serialize again. availabilityTimeOffset="INF" becomes availabilityTimeOffset="inf" after serialization and then is not accepted by Dash.js

<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:full:2011" type="dynamic" availabilityStartTime="1970-01-01T00:00:00Z" publishTime="1970-01-01T00:00:00Z" minimumUpdatePeriod="PT1S" minBufferTime="PT1S" timeShiftBufferDepth="PT1M" maxSegmentDuration="PT1S">
  <Period id="P0" start="PT0S">
    <AdaptationSet id="1" contentType="video" par="16:9" maxWidth="3840" maxHeight="2160" segmentAlignment="true">
      <SegmentTemplate media="$RepresentationID$/$Number$.m4s" initialization="$RepresentationID$/init.mp4" duration="12800" startNumber="0" timescale="12800" availabilityTimeOffset="INF"></SegmentTemplate>
      <Representation id="2160p" bandwidth="19242008" width="3840" height="2160" mimeType="video/mp4" codecs="hev1.1.6.L153.90" startWithSAP="1"></Representation>
    </AdaptationSet>
    <AdaptationSet id="2" lang="en" contentType="audio" segmentAlignment="true">
      <SegmentTemplate media="$RepresentationID$/$Number$.m4s" initialization="$RepresentationID$/init.mp4" duration="48000" startNumber="0" timescale="48000" availabilityTimeOffset="INF"></SegmentTemplate>
      <Representation id="audio" bandwidth="297168" audioSamplingRate="48000" mimeType="audio/mp4" codecs="mp4a.40.2" startWithSAP="1">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
      </Representation>
    </AdaptationSet>
  </Period>
  <UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-xsdate:2014" value="https://time.akamai.com/?iso&amp;ms"></UTCTiming>
</MPD>

I'm not sure how to fix that, one possibility is to overwrite the f64 serializer

#[serde(rename = "@availabilityTimeOffset", serialize_with = "f64_to_xml")]
 pub availabilityTimeOffset: Option<f64>,

Maybe quick-xml has a solution ?

emarsden commented 8 months ago

Thanks for the report. This is fixed (also for other attributes that are defined as being of xsd:double type) in HEAD.

I don't think that quick-xml or the serde serialization support it depends on would consider this to be a bug, because f64 attributes are not necessarily defined as being of xsd:double type.

ypo commented 8 months ago

Thanks for you work, it looks good to me