Skip to content

Commit

Permalink
DELIVER-2153: Add caption labels to dash manifests (#95)
Browse files Browse the repository at this point in the history
* Add Label Attribute to Dash structure

* Add Labels on Dash manifest

* Updated tests to meet new label criteria

* Updated comments with a more accurate description of the subtitle functions

Co-authored-by: Jorge Guerra <[email protected]>
  • Loading branch information
jguerraBC and Jorge Guerra authored Nov 14, 2022
1 parent 912863f commit b7eec0a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
_, _ = videoAS.AddNewRepresentationVideo(2295158, "avc1.4d401f", "1200", "30000/1001", 1024, 576)
_, _ = videoAS.AddNewRepresentationVideo(2780732, "avc1.4d401f", "1500", "30000/1001", 1280, 720)

subtitleAS, _ := m.AddNewAdaptationSetSubtitle(mpd.DASH_MIME_TYPE_SUBTITLE_VTT, "en")
subtitleAS, _ := m.AddNewAdaptationSetSubtitle(mpd.DASH_MIME_TYPE_SUBTITLE_VTT, "en", "Subtitle (En)")
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(256, "subtitle_en")
_ = subtitleRep.SetNewBaseURL("http://example.com/content/sintel/subtitles/subtitles_en.vtt")
schemeIDURI := "urn:mpeg:dash:utc:direct:2014"
Expand Down
2 changes: 1 addition & 1 deletion examples/ondemand.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func exampleOndemand() {
_ = videoRep2.SetNewBaseURL("1200k/output-video-1.mp4")
_, _ = videoRep2.AddNewSegmentBase("686-813", "0-685")

subtitleAS, _ := m.AddNewAdaptationSetSubtitle(mpd.DASH_MIME_TYPE_SUBTITLE_VTT, "en")
subtitleAS, _ := m.AddNewAdaptationSetSubtitle(mpd.DASH_MIME_TYPE_SUBTITLE_VTT, "en", "Subtitle (En)")
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(256, "captions_en")
_ = subtitleRep.SetNewBaseURL("http://example.com/content/sintel/subtitles/subtitles_en.vtt")

Expand Down
2 changes: 1 addition & 1 deletion mpd/fixtures/hbbtv_profile.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Representation bandwidth="2295158" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1200" width="1024"></Representation>
<Representation bandwidth="2780732" codecs="avc1.4d401f" frameRate="30000/1001" height="720" id="1500" width="1280"></Representation>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en">
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)">
<Representation bandwidth="256" id="subtitle_en">
<BaseURL>http://example.com/content/sintel/subtitles/subtitles_en.vtt</BaseURL>
</Representation>
Expand Down
2 changes: 1 addition & 1 deletion mpd/fixtures/live_profile.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Representation bandwidth="2295158" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1200" width="1024"></Representation>
<Representation bandwidth="2780732" codecs="avc1.4d401f" frameRate="30000/1001" height="720" id="1500" width="1280"></Representation>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en">
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)">
<Representation bandwidth="256" id="subtitle_en">
<BaseURL>http://example.com/content/sintel/subtitles/subtitles_en.vtt</BaseURL>
</Representation>
Expand Down
2 changes: 1 addition & 1 deletion mpd/fixtures/live_profile_dynamic.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Representation bandwidth="2295158" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1200" width="1024"></Representation>
<Representation bandwidth="2780732" codecs="avc1.4d401f" frameRate="30000/1001" height="720" id="1500" width="1280"></Representation>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en">
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)">
<Representation bandwidth="256" id="subtitle_en">
<BaseURL>http://example.com/content/sintel/subtitles/subtitles_en.vtt</BaseURL>
</Representation>
Expand Down
2 changes: 1 addition & 1 deletion mpd/fixtures/live_profile_multi_base_url.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Representation bandwidth="2295158" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1200" width="1024"></Representation>
<Representation bandwidth="2780732" codecs="avc1.4d401f" frameRate="30000/1001" height="720" id="1500" width="1280"></Representation>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en">
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)">
<Representation bandwidth="256" id="subtitle_en">
<BaseURL>http://example.com/content/sintel/subtitles/subtitles_en.vtt</BaseURL>
</Representation>
Expand Down
2 changes: 1 addition & 1 deletion mpd/fixtures/ondemand_profile.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en">
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)">
<Representation bandwidth="256" id="subtitle_en">
<BaseURL>http://example.com/content/sintel/subtitles/subtitles_en.vtt</BaseURL>
</Representation>
Expand Down
25 changes: 16 additions & 9 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type AdaptationSet struct {
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
Representations []*Representation `xml:"Representation,omitempty"`
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
Label *string `xml:"label,attr"`
}

func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
Expand Down Expand Up @@ -639,23 +640,27 @@ func (period *Period) AddNewAdaptationSetVideoWithID(id string, mimeType string,
// Create a new Adaptation Set for Subtitle Assets.
// mimeType - MIME Type (i.e. text/vtt).
// lang - Language (i.e. en).
func (m *MPD) AddNewAdaptationSetSubtitle(mimeType string, lang string) (*AdaptationSet, error) {
return m.period.AddNewAdaptationSetSubtitle(mimeType, lang)
// label - Label for the subtitle from Studio (i.e. American)
func (m *MPD) AddNewAdaptationSetSubtitle(mimeType string, lang string, label string) (*AdaptationSet, error) {
return m.period.AddNewAdaptationSetSubtitle(mimeType, lang, label)
}

// Create a new Adaptation Set for Subtitle Assets.
// mimeType - MIME Type (i.e. text/vtt).
// lang - Language (i.e. en).
func (m *MPD) AddNewAdaptationSetSubtitleWithID(id string, mimeType string, lang string) (*AdaptationSet, error) {
return m.period.AddNewAdaptationSetSubtitleWithID(id, mimeType, lang)
// label - Label for the subtitle from Studio (i.e. American)
func (m *MPD) AddNewAdaptationSetSubtitleWithID(id string, mimeType string, lang string, label string) (*AdaptationSet, error) {
return m.period.AddNewAdaptationSetSubtitleWithID(id, mimeType, lang, label)
}

// Create a new Adaptation Set for Subtitle Assets.
// mimeType - MIME Type (i.e. text/vtt).
// lang - Language (i.e. en).
func (period *Period) AddNewAdaptationSetSubtitle(mimeType string, lang string) (*AdaptationSet, error) {
// label - Label for the subtitle from Studio (i.e. American)
func (period *Period) AddNewAdaptationSetSubtitle(mimeType string, lang string, label string) (*AdaptationSet, error) {
as := &AdaptationSet{
Lang: Strptr(lang),
Lang: Strptr(lang),
Label: Strptr(label),
CommonAttributesAndElements: CommonAttributesAndElements{
MimeType: Strptr(mimeType),
},
Expand All @@ -670,10 +675,12 @@ func (period *Period) AddNewAdaptationSetSubtitle(mimeType string, lang string)
// Create a new Adaptation Set for Subtitle Assets.
// mimeType - MIME Type (i.e. text/vtt).
// lang - Language (i.e. en).
func (period *Period) AddNewAdaptationSetSubtitleWithID(id string, mimeType string, lang string) (*AdaptationSet, error) {
// label - Label for the subtitle from Studio (i.e. American)
func (period *Period) AddNewAdaptationSetSubtitleWithID(id string, mimeType string, lang string, label string) (*AdaptationSet, error) {
as := &AdaptationSet{
ID: Strptr(id),
Lang: Strptr(lang),
ID: Strptr(id),
Lang: Strptr(lang),
Label: Strptr(label),
CommonAttributesAndElements: CommonAttributesAndElements{
MimeType: Strptr(mimeType),
},
Expand Down
12 changes: 6 additions & 6 deletions mpd/mpd_read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) {
func TestAddNewAdaptationSetSubtitleWriteToString(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)

_, _ = m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
_, _ = m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)

xmlStr, err := m.WriteToString()
require.NoError(t, err)
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
<Period>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en"></AdaptationSet>
<AdaptationSet mimeType="text/vtt" id="7357" lang="en" label="Subtitle (En)"></AdaptationSet>
</Period>
</MPD>
`
Expand Down Expand Up @@ -266,7 +266,7 @@ func LiveProfile() *MPD {
_, _ = videoAS.AddNewRepresentationVideo(2295158, "avc1.4d401f", "1200", "30000/1001", 1024, 576)
_, _ = videoAS.AddNewRepresentationVideo(2780732, "avc1.4d401f", "1500", "30000/1001", 1280, 720)

subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)
_ = subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL)

Expand Down Expand Up @@ -334,7 +334,7 @@ func LiveProfileDynamic() *MPD {
_, _ = videoAS.AddNewRepresentationVideo(2295158, "avc1.4d401f", "1200", "30000/1001", 1024, 576)
_, _ = videoAS.AddNewRepresentationVideo(2780732, "avc1.4d401f", "1500", "30000/1001", 1280, 720)

subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)
_ = subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL)

Expand Down Expand Up @@ -390,7 +390,7 @@ func HbbTVProfile() *MPD {
_, _ = videoAS.AddNewRepresentationVideo(2295158, "avc1.4d401f", "1200", "30000/1001", 1024, 576)
_, _ = videoAS.AddNewRepresentationVideo(2780732, "avc1.4d401f", "1500", "30000/1001", 1280, 720)

subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)
_ = subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL)

Expand Down Expand Up @@ -443,7 +443,7 @@ func OnDemandProfile() *MPD {
_ = videoRep2.SetNewBaseURL("1200k/output-video-1.mp4")
_, _ = videoRep2.AddNewSegmentBase("686-813", "0-685")

subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)
subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)
_ = subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL)

Expand Down
5 changes: 3 additions & 2 deletions mpd/mpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
VALID_WV_HEADER string = "CAESEFq91S9VSk8quNBh92FCUVUaCGNhc3RsYWJzIhhXcjNWTDFWS1R5cTQwR0gzWVVKUlZRPT0yB2RlZmF1bHQ="
VALID_SUBTITLE_BANDWIDTH int64 = 256
VALID_SUBTITLE_ID string = "subtitle_en"
VALID_SUBTITLE_LABEL string = "Subtitle (En)"
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
VALID_ROLE string = "main"
VALID_LOCATION string = "https://example.com/location.mpd"
Expand Down Expand Up @@ -356,7 +357,7 @@ func TestAddRepresentationVideo(t *testing.T) {
func TestAddRepresentationSubtitle(t *testing.T) {
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)

subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)

r, err := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)

Expand Down Expand Up @@ -422,7 +423,7 @@ func TestAddNewBaseURLVideo(t *testing.T) {

func TestSetNewBaseURLSubtitle(t *testing.T) {
m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG)
subtitleAS, _ := m.AddNewAdaptationSetSubtitleWithID("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG, VALID_SUBTITLE_LABEL)

r, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID)

Expand Down

0 comments on commit b7eec0a

Please sign in to comment.