videojs / mpd-parser

https://videojs.github.io/mpd-parser/
Other
78 stars 54 forks source link

Duplicate Playlist Entries with BaseURL tags at different levels of the Manifest #175

Open wseymour15 opened 1 year ago

wseymour15 commented 1 year ago

There are occurrences in the inheritAttributes functionality where this representationInfo array contains undesired duplicates. This generally occurs when there are multiple BaseURL nodes that are direct children of the MPD node. When we attempt to resolve URLs from a combination of the parent BaseURL and a child BaseURL, and the value does not resolve, we end up returning the child BaseURL multiple times. We need to determine a way to remove these duplicates in a safe way.

See: https://github.com/videojs/mpd-parser/pull/17#discussion_r162750527

Example Input (Note that there are multiple BaseURLs as direct children of the MPD tag)

<MPD type="dyanmic">
    <BaseURL serviceLocation="alpha">https://cdn1.example.com/</BaseURL>
    <BaseURL serviceLocation="beta">https://cdn2.example.com/</BaseURL>
    <Period start="PT0S">
      ...
      <AdaptationSet mimeType="text/vtt" lang="en">
        <Representation bandwidth="256" id="en">
          <BaseURL>https://example.com/en.vtt</BaseURL>
        </Representation>
      </AdaptationSet>
    </Period>
  </MPD>

Current Actual RepresentationInfo

representationInfo: [
      {
        attributes: {
          baseUrl: 'https://cdn1.example.com/',
          ...
        },
        segmentInfo: {...}
      },
      {
        attributes: {
          baseUrl: 'https://cdn2.example.com/',
          ... 
        },
        segmentInfo: {...}
      },
      {
        attributes: {
          baseUrl: 'https://example.com/en.vtt',
          ... 
        },
        segmentInfo: {...}
      },
      {
        attributes: {
          baseUrl: 'https://example.com/en.vtt',
          ...
        },
        segmentInfo: {...}
      }
    ]

Expected (Notice there is one less entry than the last)

representationInfo: [
      {
        attributes: {
          baseUrl: 'https://cdn1.example.com/',
          ...
        },
        segmentInfo: {...}
      },
      {
        attributes: {
          baseUrl: 'https://cdn2.example.com/',
          ... 
        },
        segmentInfo: {...}
      },
      {
        attributes: {
          baseUrl: 'https://example.com/en.vtt',
          ... 
        },
        segmentInfo: {...}
      }
    ]