Skip to content

Commit

Permalink
support optional URI in EXT-X-MEDIA tag (#104)
Browse files Browse the repository at this point in the history
* URI is OPTIONAL in EXT-X-MEDIA tag

* make URI mandatory in case of SUBTITLES

* adapt client in order to work with renditions without URLs

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
  • Loading branch information
Lysander66 and aler9 committed Nov 22, 2023
1 parent 6cb7c43 commit 30c4379
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
42 changes: 22 additions & 20 deletions client_downloader_primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,29 @@ func (d *clientDownloaderPrimary) run(ctx context.Context) error {
return fmt.Errorf("audio playlist with id \"%s\" not found", leadingPlaylist.Audio)
}

u, err := clientAbsoluteURL(d.primaryPlaylistURL, audioPlaylist.URI)
if err != nil {
return err
if audioPlaylist.URI != "" {
u, err := clientAbsoluteURL(d.primaryPlaylistURL, audioPlaylist.URI)
if err != nil {
return err
}

ds := newClientDownloaderStream(
false,
d.httpClient,
d.onDownloadStreamPlaylist,
d.onDownloadSegment,
d.onDecodeError,
u,
nil,
d.rp,
d.onStreamTracks,
d.onSetLeadingTimeSync,
d.onGetLeadingTimeSync,
d.onData,
)
d.rp.add(ds)
streamCount++
}

ds := newClientDownloaderStream(
false,
d.httpClient,
d.onDownloadStreamPlaylist,
d.onDownloadSegment,
d.onDecodeError,
u,
nil,
d.rp,
d.onStreamTracks,
d.onSetLeadingTimeSync,
d.onGetLeadingTimeSync,
d.onData,
)
d.rp.add(ds)
streamCount++
}

default:
Expand Down
34 changes: 24 additions & 10 deletions pkg/playlist/multivariant_rendition.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,32 @@ func (t *MultivariantRendition) unmarshal(v string) error {
return fmt.Errorf("GROUP-ID missing")
}

if t.Type != MultivariantRenditionTypeClosedCaptions {
if t.URI == "" {
return fmt.Errorf("missing URI")
}

if t.InstreamID != "" {
return fmt.Errorf("INSTREAM-ID is forbidden with type %s", t.Type)
}
} else {
// If the TYPE is CLOSED-CAPTIONS, the URI
// attribute MUST NOT be present.
// The URI attribute of the EXT-X-MEDIA tag is REQUIRED if the media
// type is SUBTITLES, but OPTIONAL if the media type is VIDEO or AUDIO.
switch t.Type {
case MultivariantRenditionTypeClosedCaptions:
if t.URI != "" {
return fmt.Errorf("URI is forbidden for type CLOSED-CAPTIONS")
}

case MultivariantRenditionTypeSubtitles:
if t.URI == "" {
return fmt.Errorf("URI is required for type SUBTITLES")
}

default:
}

// This attribute is REQUIRED if the TYPE attribute is CLOSED-CAPTIONS
// For all other TYPE values, the INSTREAM-ID MUST NOT be specified.
if t.Type == MultivariantRenditionTypeClosedCaptions {
if t.InstreamID == "" {
return fmt.Errorf("missing INSTREAM-ID")
}
} else if t.InstreamID != "" {
return fmt.Errorf("INSTREAM-ID is forbidden with type %s", t.Type)
}

return nil
Expand Down Expand Up @@ -164,7 +174,11 @@ func (t MultivariantRendition) marshal() string {
ret += ",CHANNELS=\"" + t.Channels + "\""
}

ret += ",URI=\"" + t.URI + "\"\n"
if t.URI != "" {
ret += ",URI=\"" + t.URI + "\""
}

ret += "\n"

return ret
}
2 changes: 1 addition & 1 deletion pkg/playlist/multivariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ v2/prog_index.m3u8
#EXT-X-MEDIA:TYPE="AUDIO",GROUP-ID="aud1",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2",URI="a1/prog_index.m3u8"
#EXT-X-MEDIA:TYPE="AUDIO",GROUP-ID="aud2",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="6",URI="a2/prog_index.m3u8"
#EXT-X-MEDIA:TYPE="AUDIO",GROUP-ID="aud3",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="6",URI="a3/prog_index.m3u8"
#EXT-X-MEDIA:TYPE="CLOSED-CAPTIONS",GROUP-ID="cc1",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,URI=""
#EXT-X-MEDIA:TYPE="CLOSED-CAPTIONS",GROUP-ID="cc1",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES
#EXT-X-MEDIA:TYPE="SUBTITLES",GROUP-ID="sub1",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,URI="s1/en/prog_index.m3u8"
`,
Multivariant{
Expand Down

0 comments on commit 30c4379

Please sign in to comment.