Dash-Industry-Forum / dash.js

A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.
http://reference.dashif.org/dash.js/nightly/samples/dash-if-reference-player/index.html
Other
5.09k stars 1.67k forks source link

Memory leak when InbandEventStream is set in the AdaptationSet of the live stream manifest. #4561

Open grand719 opened 2 weeks ago

grand719 commented 2 weeks ago
Environment
Steps to reproduce
  1. Prepare Stream with AWS Elemental MediaPackage
  2. Run the prepared stream, which contains the <InbandEventStream schemeIdUri="https://aomedia.org/emsg/ID3" value="0"/> field in the AdaptationSet, in the referenced player."
  3. Take a Heap Snapshot and Analyze JsArrayBuffer
Observed behavior

In the taken snapshot, we can observe that the JsArrayBuffer is consistently increasing, and the memory usage is not dropping. During the debug session, I noticed that unusual memory management behavior is caused by the <InbandEventStream schemeIdUri="https://aomedia.org/emsg/ID3" value="0"/> element, which is added to the video AdaptationSet. Additionally, after deleting the InbandEventStream and InbandEventStream_asArray properties from the adaptation set object in DashManifestModel.js within the getRealAdaptations function, everything works as intended.

Memory usage when Adaptation Set contains InbandEventStream: image

Manifest
<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" id="201" type="dynamic" publishTime="2024-08-30T10:09:25+00:00" minimumUpdatePeriod="PT2S" availabilityStartTime="2024-08-29T14:57:30+00:00" minBufferTime="PT10S" suggestedPresentationDelay="PT20.000S" timeShiftBufferDepth="PT37.000S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
  <Period start="PT0.000S" id="1">
    <AdaptationSet id="1485523442" mimeType="video/mp4" segmentAlignment="true" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1" bitstreamSwitching="true">
      <InbandEventStream schemeIdUri="https://aomedia.org/emsg/ID3" value="0"/>
      <Representation id="1" width="1920" height="1080" frameRate="30/1" bandwidth="2000000" codecs="avc1.640028">
        <SegmentTemplate timescale="30000" media="index_video_3_0_$Time$.mp4?m=1724934975" initialization="index_video_3_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="2072232040" d="180000" r="6"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="2" width="1280" height="720" frameRate="30/1" bandwidth="1000000" codecs="avc1.64001F">
        <SegmentTemplate timescale="30000" media="index_video_5_0_$Time$.mp4?m=1724934975" initialization="index_video_5_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="2072232040" d="180000" r="6"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="3" width="853" height="480" frameRate="30/1" bandwidth="499968" codecs="avc1.4D401E">
        <SegmentTemplate timescale="30000" media="index_video_7_0_$Time$.mp4?m=1724934975" initialization="index_video_7_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="2072232040" d="180000" r="6"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="4" width="426" height="240" frameRate="30/1" bandwidth="249984" codecs="avc1.4D400D">
        <SegmentTemplate timescale="30000" media="index_video_9_0_$Time$.mp4?m=1724934975" initialization="index_video_9_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="2072232040" d="180000" r="6"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
    </AdaptationSet>
    <AdaptationSet id="2083690061" mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="und" bitstreamSwitching="true">
      <Label>und</Label>
      <Representation id="5" bandwidth="192357" audioSamplingRate="48000" codecs="mp4a.40.2">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
        <SegmentTemplate timescale="48000" media="index_audio_4_0_$Time$.mp4?m=1724934975" initialization="index_audio_4_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="3315571968" d="287744" r="1"/>
            <S t="3316147456" d="288768"/>
            <S t="3316436224" d="287744" r="2"/>
            <S t="3317299456" d="288768"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="6" bandwidth="192357" audioSamplingRate="48000" codecs="mp4a.40.2">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
        <SegmentTemplate timescale="48000" media="index_audio_6_0_$Time$.mp4?m=1724934975" initialization="index_audio_6_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="3315571968" d="287744" r="1"/>
            <S t="3316147456" d="288768"/>
            <S t="3316436224" d="287744" r="2"/>
            <S t="3317299456" d="288768"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="7" bandwidth="128651" audioSamplingRate="48000" codecs="mp4a.40.2">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
        <SegmentTemplate timescale="48000" media="index_audio_8_0_$Time$.mp4?m=1724934975" initialization="index_audio_8_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="3315571968" d="287744" r="1"/>
            <S t="3316147456" d="288768"/>
            <S t="3316436224" d="287744" r="2"/>
            <S t="3317299456" d="288768"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
      <Representation id="8" bandwidth="128651" audioSamplingRate="48000" codecs="mp4a.40.2">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
        <SegmentTemplate timescale="48000" media="index_audio_10_0_$Time$.mp4?m=1724934975" initialization="index_audio_10_0_init.mp4?m=1724934975" startNumber="15912">
          <SegmentTimeline>
            <S t="3315571968" d="287744" r="1"/>
            <S t="3316147456" d="288768"/>
            <S t="3316436224" d="287744" r="2"/>
            <S t="3317299456" d="288768"/>
          </SegmentTimeline>
        </SegmentTemplate>
      </Representation>
    </AdaptationSet>
    <SupplementalProperty schemeIdUri="urn:scte:dash:utc-time" value="2024-08-29T14:57:25.400Z"/>
  </Period>
  <UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-iso:2014" value="https://time.akamai.com/?iso&amp;ms"/>
</MPD>
Expected behavior

There should be no memory leaks when playing a live stream, even with InbandEventStream set in the AdaptationSet. Memory should be released correctly, and the size of the JsArrayBuffer should remain stable or decrease as unneeded resources are freed.

grand719 commented 1 week ago

After further investigation, I managed to find out that the issue occurs due to the event_duration being set to 40 hours in IsoBox - emsg. How should this situation be approached, and how should the player react in such a case? We also managed to remove the emsg IsoBox using AWS MediaLive, but I believe the player should also have logic in place to prevent behavior like overloading the memory when events are too long.