diff --git a/mpd/fixtures/hbbtv_profile.mpd b/mpd/fixtures/hbbtv_profile.mpd index 19cd3a5..089edbb 100644 --- a/mpd/fixtures/hbbtv_profile.mpd +++ b/mpd/fixtures/hbbtv_profile.mpd @@ -1,7 +1,7 @@ - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -12,11 +12,11 @@ - + - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -27,13 +27,13 @@ - - - - + + + + - - + + http://example.com/content/sintel/subtitles/subtitles_en.vtt diff --git a/mpd/fixtures/live_profile.mpd b/mpd/fixtures/live_profile.mpd index a6334f1..4d4579a 100644 --- a/mpd/fixtures/live_profile.mpd +++ b/mpd/fixtures/live_profile.mpd @@ -1,7 +1,7 @@ - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -12,9 +12,9 @@ - + - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -25,13 +25,13 @@ - - - - + + + + - - + + http://example.com/content/sintel/subtitles/subtitles_en.vtt diff --git a/mpd/fixtures/newperiod.mpd b/mpd/fixtures/newperiod.mpd new file mode 100644 index 0000000..f86987c --- /dev/null +++ b/mpd/fixtures/newperiod.mpd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/mpd/fixtures/ondemand_profile.mpd b/mpd/fixtures/ondemand_profile.mpd index e6e40e9..977ea68 100644 --- a/mpd/fixtures/ondemand_profile.mpd +++ b/mpd/fixtures/ondemand_profile.mpd @@ -1,7 +1,7 @@ - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -10,14 +10,14 @@ BgIAAAEAAQD8ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4ATAA5AFcAOQBXAGsAcABWAEsAawArADQAMABHAEgAMwBZAFUASgBSAFYAUQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBJAEsAegBZADIASABaAEwAQQBsAEkAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA= AAACJnBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAgYGAgAAAQABAPwBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBMADkAVwA5AFcAawBwAFYASwBrACsANAAwAEcASAAzAFkAVQBKAFIAVgBRAD0APQA8AC8ASwBJAEQAPgA8AEMASABFAEMASwBTAFUATQA+AEkASwB6AFkAMgBIAFoATABBAGwASQA9ADwALwBDAEgARQBDAEsAUwBVAE0APgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA== - + 800k/output-audio-und.mp4 - + AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA== @@ -26,21 +26,21 @@ BgIAAAEAAQD8ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4ATAA5AFcAOQBXAGsAcABWAEsAawArADQAMABHAEgAMwBZAFUASgBSAFYAUQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBJAEsAegBZADIASABaAEwAQQBsAEkAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA= AAACJnBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAgYGAgAAAQABAPwBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBMADkAVwA5AFcAawBwAFYASwBrACsANAAwAEcASAAzAFkAVQBKAFIAVgBRAD0APQA8AC8ASwBJAEQAPgA8AEMASABFAEMASwBTAFUATQA+AEkASwB6AFkAMgBIAFoATABBAGwASQA9ADwALwBDAEgARQBDAEsAUwBVAE0APgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA== - + 800k/output-video-1.mp4 - + 1200k/output-video-1.mp4 - - + + http://example.com/content/sintel/subtitles/subtitles_en.vtt diff --git a/mpd/fixtures/segment_list.mpd b/mpd/fixtures/segment_list.mpd index b30153d..65aff6e 100644 --- a/mpd/fixtures/segment_list.mpd +++ b/mpd/fixtures/segment_list.mpd @@ -2,8 +2,8 @@ http://localhost:8002/dash/ - - + + @@ -13,8 +13,8 @@ - - + + diff --git a/mpd/fixtures/segment_timeline.mpd b/mpd/fixtures/segment_timeline.mpd index f322108..b7541d6 100644 --- a/mpd/fixtures/segment_timeline.mpd +++ b/mpd/fixtures/segment_timeline.mpd @@ -2,8 +2,8 @@ http://localhost:8002/public/ - - + + @@ -16,8 +16,8 @@ - - + + diff --git a/mpd/fixtures/segment_timeline_multi_period.mpd b/mpd/fixtures/segment_timeline_multi_period.mpd index 64ad456..d4f46c0 100644 --- a/mpd/fixtures/segment_timeline_multi_period.mpd +++ b/mpd/fixtures/segment_timeline_multi_period.mpd @@ -1,87 +1,87 @@ - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + diff --git a/mpd/mpd.go b/mpd/mpd.go index 0e5679b..cf65698 100644 --- a/mpd/mpd.go +++ b/mpd/mpd.go @@ -81,13 +81,48 @@ type Period struct { AdaptationSets []*AdaptationSet `xml:"AdaptationSet,omitempty"` } +type DescriptorType struct { + SchemeIDURI *string `xml:"schemeIDURI,attr"` + Value *string `xml:"value,attr"` + ID *string `xml:"id,attr"` +} + +// ISO 23009-1-2014 5.3.7 +type CommonAttributesAndElements struct { + Profiles *string `xml:"profiles,attr"` + Width *string `xml:"width,attr"` + Height *string `xml:"height,attr"` + Sar *string `xml:"sar,attr"` + FrameRate *string `xml:"frameRate,attr"` + AudioSamplingRate *string `xml:"audioSamplingRate,attr"` + MimeType *string `xml:"mimeType,attr"` + SegmentProfiles *string `xml:"segmentProfiles,attr"` + Codecs *string `xml:"codecs,attr"` + MaximumSAPPeriod *string `xml:"maximumSAPPeriod,attr"` + StartWithSAP *int64 `xml:"startWithSAP,attr"` + MaxPlayoutRate *string `xml:"maxPlayoutRate,attr"` + ScanType *string `xml:"scanType,attr"` + FramePacking *DescriptorType `xml:"framePacking,attr"` + AudioChannelConfiguration *DescriptorType `xml:"audioChannelConfiguration,attr"` + ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` + EssentialProperty *DescriptorType `xml:"essentialProperty,attr"` + SupplementalProperty *DescriptorType `xml:"supplmentalProperty,attr"` + InbandEventStream *DescriptorType `xml:"inbandEventStream,attr"` +} + type AdaptationSet struct { - MimeType *string `xml:"mimeType,attr"` - ScanType *string `xml:"scanType,attr"` + XMLName xml.Name `xml:"AdaptationSet"` + ID *string `xml:"id,attr"` + CommonAttributesAndElements SegmentAlignment *bool `xml:"segmentAlignment,attr"` - StartWithSAP *int64 `xml:"startWithSAP,attr"` Lang *string `xml:"lang,attr"` - ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` + Group *string `xml:"group,attr"` + PAR *string `xml:"par,attr"` + MinBandwidth *string `xml:"minBandwidth,attr"` + MaxBandwidth *string `xml:"maxBandwidth,attr"` + MinWidth *string `xml:"minWidth,attr"` + MaxWidth *string `xml:"maxWidth,attr"` + ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here Roles []*Role `xml:"Role,omitempty"` SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` SegmentList *SegmentList `xml:"SegmentList,omitempty"` @@ -159,6 +194,8 @@ type SegmentTemplate struct { } type Representation struct { + ID *string `xml:"id,attr"` // Audio + Video + CommonAttributesAndElements AdaptationSet *AdaptationSet `xml:"-"` AudioChannelConfiguration *AudioChannelConfiguration `xml:"AudioChannelConfiguration,omitempty"` AudioSamplingRate *int64 `xml:"audioSamplingRate,attr"` // Audio @@ -166,7 +203,6 @@ type Representation struct { Codecs *string `xml:"codecs,attr"` // Audio + Video FrameRate *string `xml:"frameRate,attr,omitempty"` // Video Height *int64 `xml:"height,attr"` // Video - ID *string `xml:"id,attr"` // Audio + Video Width *int64 `xml:"width,attr"` // Video BaseURL *string `xml:"BaseURL,omitempty"` // On-Demand Profile SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` // On-Demand Profile @@ -219,8 +255,8 @@ func (period *Period) SetDuration(d time.Duration) { // segmentAlignment - Segment Alignment(i.e. true). // startWithSAP - Starts With SAP (i.e. 1). // lang - Language (i.e. en). -func (m *MPD) AddNewAdaptationSetAudio(mimeType string, segmentAlignment bool, startWithSAP int64, lang string) (*AdaptationSet, error) { - return m.period.AddNewAdaptationSetAudio(mimeType, segmentAlignment, startWithSAP, lang) +func (m *MPD) AddNewAdaptationSetAudio(id string, mimeType string, segmentAlignment bool, startWithSAP int64, lang string) (*AdaptationSet, error) { + return m.period.AddNewAdaptationSetAudio(id, mimeType, segmentAlignment, startWithSAP, lang) } // Create a new Adaptation Set for Audio Assets. @@ -228,12 +264,15 @@ func (m *MPD) AddNewAdaptationSetAudio(mimeType string, segmentAlignment bool, s // segmentAlignment - Segment Alignment(i.e. true). // startWithSAP - Starts With SAP (i.e. 1). // lang - Language (i.e. en). -func (period *Period) AddNewAdaptationSetAudio(mimeType string, segmentAlignment bool, startWithSAP int64, lang string) (*AdaptationSet, error) { +func (period *Period) AddNewAdaptationSetAudio(id string, mimeType string, segmentAlignment bool, startWithSAP int64, lang string) (*AdaptationSet, error) { as := &AdaptationSet{ - MimeType: Strptr(mimeType), + ID: Strptr(id), SegmentAlignment: Boolptr(segmentAlignment), - StartWithSAP: Int64ptr(startWithSAP), Lang: Strptr(lang), + CommonAttributesAndElements: CommonAttributesAndElements{ + MimeType: Strptr(mimeType), + StartWithSAP: Int64ptr(startWithSAP), + }, } err := period.addAdaptationSet(as) if err != nil { @@ -247,8 +286,8 @@ func (period *Period) AddNewAdaptationSetAudio(mimeType string, segmentAlignment // scanType - Scan Type (i.e.progressive). // segmentAlignment - Segment Alignment(i.e. true). // startWithSAP - Starts With SAP (i.e. 1). -func (m *MPD) AddNewAdaptationSetVideo(mimeType string, scanType string, segmentAlignment bool, startWithSAP int64) (*AdaptationSet, error) { - return m.period.AddNewAdaptationSetVideo(mimeType, scanType, segmentAlignment, startWithSAP) +func (m *MPD) AddNewAdaptationSetVideo(id string, mimeType string, scanType string, segmentAlignment bool, startWithSAP int64) (*AdaptationSet, error) { + return m.period.AddNewAdaptationSetVideo(id, mimeType, scanType, segmentAlignment, startWithSAP) } // Create a new Adaptation Set for Video Assets. @@ -256,12 +295,15 @@ func (m *MPD) AddNewAdaptationSetVideo(mimeType string, scanType string, segment // scanType - Scan Type (i.e.progressive). // segmentAlignment - Segment Alignment(i.e. true). // startWithSAP - Starts With SAP (i.e. 1). -func (period *Period) AddNewAdaptationSetVideo(mimeType string, scanType string, segmentAlignment bool, startWithSAP int64) (*AdaptationSet, error) { +func (period *Period) AddNewAdaptationSetVideo(id string, mimeType string, scanType string, segmentAlignment bool, startWithSAP int64) (*AdaptationSet, error) { as := &AdaptationSet{ - MimeType: Strptr(mimeType), - ScanType: Strptr(scanType), SegmentAlignment: Boolptr(segmentAlignment), - StartWithSAP: Int64ptr(startWithSAP), + ID: Strptr(id), + CommonAttributesAndElements: CommonAttributesAndElements{ + MimeType: Strptr(mimeType), + StartWithSAP: Int64ptr(startWithSAP), + ScanType: Strptr(scanType), + }, } err := period.addAdaptationSet(as) if err != nil { @@ -273,17 +315,20 @@ func (period *Period) AddNewAdaptationSetVideo(mimeType string, scanType 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) +func (m *MPD) AddNewAdaptationSetSubtitle(id string, mimeType string, lang string) (*AdaptationSet, error) { + return m.period.AddNewAdaptationSetSubtitle(id, mimeType, lang) } // 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) { +func (period *Period) AddNewAdaptationSetSubtitle(id string, mimeType string, lang string) (*AdaptationSet, error) { as := &AdaptationSet{ - MimeType: Strptr(mimeType), - Lang: Strptr(lang), + ID: Strptr(id), + Lang: Strptr(lang), + CommonAttributesAndElements: CommonAttributesAndElements{ + MimeType: Strptr(mimeType), + }, } err := period.addAdaptationSet(as) if err != nil { diff --git a/mpd/mpd_read_write_test.go b/mpd/mpd_read_write_test.go index e3bae94..5a55528 100644 --- a/mpd/mpd_read_write_test.go +++ b/mpd/mpd_read_write_test.go @@ -1,7 +1,6 @@ package mpd import ( - "fmt" "os" "testing" "time" @@ -68,14 +67,14 @@ func TestNewMPDOnDemandWriteToString(t *testing.T) { func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) xmlStr, err := m.WriteToString() require.Nil(t, err) expectedXML := ` - + ` @@ -85,14 +84,14 @@ func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) { func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) xmlStr, err := m.WriteToString() require.Nil(t, err) expectedXML := ` - + ` @@ -102,70 +101,52 @@ func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) { func TestAddNewAdaptationSetSubtitleWriteToString(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - m.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) xmlStr, err := m.WriteToString() require.Nil(t, err) expectedXML := ` - + ` require.Equal(t, expectedXML, xmlStr) } -func ExampleAddNewPeriod() { +func TestExampleAddNewPeriod(t *testing.T) { // a new MPD is created with a single Period m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) // you can add content to the Period p := m.GetCurrentPeriod() - as, _ := p.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + as, _ := p.AddNewAdaptationSetVideo("1", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) as.SetNewSegmentTemplate(1968, "$RepresentationID$/video-1.mp4", "$RepresentationID$/video-1/seg-$Number$.m4f", 0, 1000) // or directly to the MPD, which will use the current Period. - as, _ = m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + as, _ = m.AddNewAdaptationSetAudio("1", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) as.SetNewSegmentTemplate(1968, "$RepresentationID$/audio-1.mp4", "$RepresentationID$/audio-1/seg-$Number$.m4f", 0, 1000) // add a second period p = m.AddNewPeriod() p.SetDuration(3 * time.Minute) - as, _ = p.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + as, _ = p.AddNewAdaptationSetVideo("2", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) as.SetNewSegmentTemplate(1968, "$RepresentationID$/video-2.mp4", "$RepresentationID$/video-2/seg-$Number$.m4f", 0, 1000) - as, _ = m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + as, _ = m.AddNewAdaptationSetAudio("2", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) as.SetNewSegmentTemplate(1968, "$RepresentationID$/audio-2.mp4", "$RepresentationID$/audio-2/seg-$Number$.m4f", 0, 1000) - xmlStr, _ := m.WriteToString() - fmt.Print(xmlStr) - // Output: - // - // - // - // - // - // - // - // - // - // - // - // - // - // - // - // - // - // - // + xmlStr, err := m.WriteToString() + require.Nil(t, err) + expectedXML := testfixtures.LoadFixture("fixtures/newperiod.mpd") + require.Equal(t, expectedXML, xmlStr) } func LiveProfile() *MPD { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) audioAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") audioAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -176,7 +157,7 @@ func LiveProfile() *MPD { audioAS.SetNewSegmentTemplate(1968, "$RepresentationID$/audio/en/init.mp4", "$RepresentationID$/audio/en/seg-$Number$.m4f", 0, 1000) audioAS.AddNewRepresentationAudio(44100, 67095, "mp4a.40.2", "800") - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) videoAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") videoAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -190,7 +171,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.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + subtitleAS, _ := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID) subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL) @@ -210,6 +191,9 @@ func TestFullLiveProfileWriteToFile(t *testing.T) { m := LiveProfile() require.NotNil(t, m) err := m.WriteToFile("test_live.mpd") + xmlStr := testfixtures.LoadFixture("test_live.mpd") + expectedXML := testfixtures.LoadFixture("fixtures/live_profile.mpd") + require.Equal(t, expectedXML, xmlStr) defer os.Remove("test_live.mpd") require.Nil(t, err) } @@ -217,7 +201,7 @@ func TestFullLiveProfileWriteToFile(t *testing.T) { func HbbTVProfile() *MPD { m := NewMPD(DASH_PROFILE_HBBTV_1_5_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) audioAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") audioAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -229,7 +213,7 @@ func HbbTVProfile() *MPD { r, _ := audioAS.AddNewRepresentationAudio(44100, 67095, "mp4a.40.2", "800") r.AddNewAudioChannelConfiguration(AUDIO_CHANNEL_CONFIGURATION_MPEG_DASH, "2") - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) videoAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") videoAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -243,7 +227,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.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + subtitleAS, _ := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID) subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL) @@ -263,6 +247,9 @@ func TestFullHbbTVProfileWriteToFile(t *testing.T) { m := HbbTVProfile() require.NotNil(t, m) err := m.WriteToFile("test_hbbtv.mpd") + xmlStr := testfixtures.LoadFixture("test_hbbtv.mpd") + expectedXML := testfixtures.LoadFixture("fixtures/hbbtv_profile.mpd") + require.Equal(t, expectedXML, xmlStr) defer os.Remove("test_hbbtv.mpd") require.Nil(t, err) } @@ -270,7 +257,7 @@ func TestFullHbbTVProfileWriteToFile(t *testing.T) { func OnDemandProfile() *MPD { m := NewMPD(DASH_PROFILE_ONDEMAND, "PT30S", VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, "und") + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, "und") audioAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") audioAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -280,7 +267,7 @@ func OnDemandProfile() *MPD { audioRep.SetNewBaseURL("800k/output-audio-und.mp4") audioRep.AddNewSegmentBase("629-756", "0-628") - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) videoAS.AddNewContentProtectionRoot("08e367028f33436ca5dd60ffe5571e60") videoAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) @@ -294,7 +281,7 @@ func OnDemandProfile() *MPD { videoRep2.SetNewBaseURL("1200k/output-video-1.mp4") videoRep2.AddNewSegmentBase("686-813", "0-685") - subtitleAS, _ := m.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + subtitleAS, _ := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) subtitleRep, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID) subtitleRep.SetNewBaseURL(VALID_SUBTITLE_URL) @@ -314,6 +301,9 @@ func TestFullOnDemandProfileWriteToFile(t *testing.T) { m := OnDemandProfile() require.NotNil(t, m) err := m.WriteToFile("test-ondemand.mpd") + xmlStr := testfixtures.LoadFixture("test-ondemand.mpd") + expectedXML := testfixtures.LoadFixture("fixtures/ondemand_profile.mpd") + require.Equal(t, expectedXML, xmlStr) defer os.Remove("test-ondemand.mpd") require.Nil(t, err) } diff --git a/mpd/mpd_test.go b/mpd/mpd_test.go index 0e95f66..4e57028 100644 --- a/mpd/mpd_test.go +++ b/mpd/mpd_test.go @@ -155,14 +155,34 @@ func TestNewMPDOnDemand(t *testing.T) { func TestAddNewAdaptationSetAudio(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - as, err := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + as, err := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) require.NotNil(t, as) require.Nil(t, err) expectedAS := &AdaptationSet{ - MimeType: Strptr(VALID_MIME_TYPE_AUDIO), SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT), - StartWithSAP: Int64ptr(VALID_START_WITH_SAP), Lang: Strptr(VALID_LANG), + ID: Strptr("7357"), + CommonAttributesAndElements: CommonAttributesAndElements{ + Profiles: nil, + Width: nil, + Height: nil, + Sar: nil, + FrameRate: nil, + AudioSamplingRate: nil, + MimeType: Strptr(VALID_MIME_TYPE_AUDIO), + SegmentProfiles: nil, + Codecs: nil, + MaximumSAPPeriod: nil, + StartWithSAP: Int64ptr(VALID_START_WITH_SAP), + MaxPlayoutRate: nil, + ScanType: nil, + FramePacking: nil, + AudioChannelConfiguration: nil, + ContentProtection: nil, + EssentialProperty: nil, + SupplementalProperty: nil, + InbandEventStream: nil, + }, } require.Equal(t, expectedAS, as) } @@ -170,14 +190,33 @@ func TestAddNewAdaptationSetAudio(t *testing.T) { func TestAddNewAdaptationSetVideo(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - as, err := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + as, err := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) require.NotNil(t, as) require.Nil(t, err) expectedAS := &AdaptationSet{ - MimeType: Strptr(VALID_MIME_TYPE_VIDEO), - ScanType: Strptr(VALID_SCAN_TYPE), SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT), - StartWithSAP: Int64ptr(VALID_START_WITH_SAP), + ID: Strptr("7357"), + CommonAttributesAndElements: CommonAttributesAndElements{ + Profiles: nil, + Width: nil, + Height: nil, + Sar: nil, + FrameRate: nil, + AudioSamplingRate: nil, + MimeType: Strptr(VALID_MIME_TYPE_VIDEO), + SegmentProfiles: nil, + Codecs: nil, + MaximumSAPPeriod: nil, + StartWithSAP: Int64ptr(VALID_START_WITH_SAP), + MaxPlayoutRate: nil, + ScanType: Strptr(VALID_SCAN_TYPE), + FramePacking: nil, + AudioChannelConfiguration: nil, + ContentProtection: nil, + EssentialProperty: nil, + SupplementalProperty: nil, + InbandEventStream: nil, + }, } require.Equal(t, expectedAS, as) } @@ -185,12 +224,15 @@ func TestAddNewAdaptationSetVideo(t *testing.T) { func TestAddNewAdaptationSetSubtitle(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - as, err := m.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + as, err := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) require.NotNil(t, as) require.Nil(t, err) expectedAS := &AdaptationSet{ - MimeType: Strptr(VALID_MIME_TYPE_SUBTITLE_VTT), - Lang: Strptr(VALID_LANG), + ID: Strptr("7357"), + Lang: Strptr(VALID_LANG), + CommonAttributesAndElements: CommonAttributesAndElements{ + MimeType: Strptr(VALID_MIME_TYPE_SUBTITLE_VTT), + }, } require.Equal(t, expectedAS, as) } @@ -205,7 +247,7 @@ func TestAddAdaptationSetErrorNil(t *testing.T) { func TestAddNewContentProtectionRoot(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionRoot(VALID_DEFAULT_KID_HEX) require.Nil(t, err) @@ -230,7 +272,7 @@ func (s *TestProprietaryContentProtection) ContentProtected() {} func TestAddNewContentProtection_Proprietary(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - as, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + as, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp := &ContentProtection{ SchemeIDURI: Strptr(CONTENT_PROTECTION_ROOT_SCHEME_ID_URI), @@ -245,7 +287,7 @@ func TestAddNewContentProtection_Proprietary(t *testing.T) { func TestAddNewContentProtectionRootErrorInvalidLengthDefaultKID(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionRoot("invalidkid") require.NotNil(t, err) @@ -255,7 +297,7 @@ func TestAddNewContentProtectionRootErrorInvalidLengthDefaultKID(t *testing.T) { func TestAddNewContentProtectionRootErrorEmptyDefaultKID(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionRoot("") require.NotNil(t, err) @@ -265,7 +307,7 @@ func TestAddNewContentProtectionRootErrorEmptyDefaultKID(t *testing.T) { func TestAddNewContentProtectionSchemeWidevineWithPSSH(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes()) require.Nil(t, err) @@ -280,7 +322,7 @@ func TestAddNewContentProtectionSchemeWidevineWithPSSH(t *testing.T) { func TestAddNewContentProtectionSchemeWidevine(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemeWidevine() require.Nil(t, err) @@ -292,7 +334,7 @@ func TestAddNewContentProtectionSchemeWidevine(t *testing.T) { func TestAddNewContentProtectionSchemePlayreadyErrorEmptyPRO(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayready("") require.NotNil(t, err) @@ -302,7 +344,7 @@ func TestAddNewContentProtectionSchemePlayreadyErrorEmptyPRO(t *testing.T) { func TestAddNewContentProtectionSchemePlayready(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayready(VALID_PLAYREADY_PRO) require.Nil(t, err) @@ -318,7 +360,7 @@ func TestAddNewContentProtectionSchemePlayready(t *testing.T) { func TestAddNewContentProtectionSchemePlayreadyV10ErrorEmptyPRO(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayreadyV10("") require.NotNil(t, err) @@ -328,7 +370,7 @@ func TestAddNewContentProtectionSchemePlayreadyV10ErrorEmptyPRO(t *testing.T) { func TestAddNewContentProtectionSchemePlayreadyV10(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayreadyV10(VALID_PLAYREADY_PRO) require.Nil(t, err) @@ -344,7 +386,7 @@ func TestAddNewContentProtectionSchemePlayreadyV10(t *testing.T) { func TestAddNewContentProtectionSchemePlayreadyWithPSSH(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayreadyWithPSSH(VALID_PLAYREADY_PRO) require.Nil(t, err) @@ -362,7 +404,7 @@ func TestAddNewContentProtectionSchemePlayreadyWithPSSH(t *testing.T) { func TestAddNewContentProtectionSchemePlayreadyV10WithPSSH(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - s, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + s, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) cp, err := s.AddNewContentProtectionSchemePlayreadyV10WithPSSH(VALID_PLAYREADY_PRO) require.Nil(t, err) @@ -380,7 +422,7 @@ func TestAddNewContentProtectionSchemePlayreadyV10WithPSSH(t *testing.T) { func TestSetNewSegmentTemplate(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) st, err := audioAS.SetNewSegmentTemplate(VALID_DURATION, VALID_INIT_PATH_AUDIO, VALID_MEDIA_PATH_AUDIO, VALID_START_NUMBER, VALID_TIMESCALE) require.NotNil(t, st) require.Nil(t, err) @@ -395,7 +437,7 @@ func TestSetNewSegmentTemplateErrorNoDASHProfile(t *testing.T) { MinBufferTime: Strptr(VALID_MIN_BUFFER_TIME), period: &Period{}, } - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) audioAS.SetNewSegmentTemplate(VALID_DURATION, VALID_INIT_PATH_AUDIO, VALID_MEDIA_PATH_AUDIO, VALID_START_NUMBER, VALID_TIMESCALE) err := m.Validate() require.Equal(t, ErrNoDASHProfileSet, err) @@ -403,7 +445,7 @@ func TestSetNewSegmentTemplateErrorNoDASHProfile(t *testing.T) { func TestAddRepresentationAudio(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) r, err := audioAS.AddNewRepresentationAudio(VALID_AUDIO_SAMPLE_RATE, VALID_AUDIO_BITRATE, VALID_AUDIO_CODEC, VALID_AUDIO_ID) @@ -413,7 +455,7 @@ func TestAddRepresentationAudio(t *testing.T) { func TestAddAudioChannelConfiguration(t *testing.T) { m := NewMPD(DASH_PROFILE_HBBTV_1_5_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) r, _ := audioAS.AddNewRepresentationAudio(VALID_AUDIO_SAMPLE_RATE, VALID_AUDIO_BITRATE, VALID_AUDIO_CODEC, VALID_AUDIO_ID) @@ -425,7 +467,7 @@ func TestAddAudioChannelConfiguration(t *testing.T) { func TestAddRepresentationVideo(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, err := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -436,7 +478,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.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + subtitleAS, _ := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) r, err := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID) @@ -446,7 +488,7 @@ func TestAddRepresentationSubtitle(t *testing.T) { func TestAddRepresentationErrorNil(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) err := videoAS.addRepresentation(nil) require.NotNil(t, err) @@ -455,7 +497,7 @@ func TestAddRepresentationErrorNil(t *testing.T) { func TestAddRole(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) r, err := audioAS.AddNewRole("urn:mpeg:dash:role:2011", VALID_ROLE) @@ -465,7 +507,7 @@ func TestAddRole(t *testing.T) { func TestSetSegmentTemplateErrorNil(t *testing.T) { m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - audioAS, _ := m.AddNewAdaptationSetAudio(DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) + audioAS, _ := m.AddNewAdaptationSetAudio("7357", DASH_MIME_TYPE_AUDIO_MP4, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP, VALID_LANG) err := audioAS.setSegmentTemplate(nil) require.NotNil(t, err) require.Equal(t, ErrSegmentTemplateNil, err) @@ -473,7 +515,7 @@ func TestSetSegmentTemplateErrorNil(t *testing.T) { func TestSetNewBaseURLVideo(t *testing.T) { m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -484,7 +526,7 @@ func TestSetNewBaseURLVideo(t *testing.T) { func TestSetNewBaseURLSubtitle(t *testing.T) { m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - subtitleAS, _ := m.AddNewAdaptationSetSubtitle(DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) + subtitleAS, _ := m.AddNewAdaptationSetSubtitle("7357", DASH_MIME_TYPE_SUBTITLE_VTT, VALID_LANG) r, _ := subtitleAS.AddNewRepresentationSubtitle(VALID_SUBTITLE_BANDWIDTH, VALID_SUBTITLE_ID) @@ -502,7 +544,7 @@ func TestSetNewBaseURLErrorNoDASHProfile(t *testing.T) { MinBufferTime: Strptr(VALID_MIN_BUFFER_TIME), period: &Period{}, } - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -515,7 +557,7 @@ func TestSetNewBaseURLErrorNoDASHProfile(t *testing.T) { func TestSetNewBaseURLErrorEmpty(t *testing.T) { m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -527,7 +569,7 @@ func TestSetNewBaseURLErrorEmpty(t *testing.T) { func TestSetNewSegmentBase(t *testing.T) { m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -545,7 +587,7 @@ func TestSetNewSegmentBaseErrorNoDASHProfile(t *testing.T) { MinBufferTime: Strptr(VALID_MIN_BUFFER_TIME), period: &Period{}, } - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) @@ -557,7 +599,7 @@ func TestSetNewSegmentBaseErrorNoDASHProfile(t *testing.T) { func TestSetSegmentBaseErrorNil(t *testing.T) { m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME) - videoAS, _ := m.AddNewAdaptationSetVideo(DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) + videoAS, _ := m.AddNewAdaptationSetVideo("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP) r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT) diff --git a/mpd/segment_list_test.go b/mpd/segment_list_test.go index b40eae4..7e682f0 100644 --- a/mpd/segment_list_test.go +++ b/mpd/segment_list_test.go @@ -53,7 +53,7 @@ func getSegmentListMPD() *MPD { m := NewMPD(DASH_PROFILE_LIVE, "PT30.016S", "PT2.000S") m.period.BaseURL = "http://localhost:8002/dash/" - aas, _ := m.AddNewAdaptationSetAudio("audio/mp4", true, 1, "English") + aas, _ := m.AddNewAdaptationSetAudio("1","audio/mp4", true, 1, "English") ra, _ := aas.AddNewRepresentationAudio(48000, 255000, "mp4a.40.2", "audio_1") asl := new(SegmentList) @@ -70,7 +70,7 @@ func getSegmentListMPD() *MPD { ra.SegmentList = asl - vas, _ := m.AddNewAdaptationSetVideo("video/mp4", "progressive", true, 1) + vas, _ := m.AddNewAdaptationSetVideo("2","video/mp4", "progressive", true, 1) va, _ := vas.AddNewRepresentationVideo(int64(4172274), "avc1.640028", "video_1", "30000/1001", int64(1280), int64(720)) vsl := new(SegmentList) diff --git a/mpd/segment_timeline_test.go b/mpd/segment_timeline_test.go index 1ac525c..2d9e46b 100644 --- a/mpd/segment_timeline_test.go +++ b/mpd/segment_timeline_test.go @@ -59,7 +59,7 @@ func getMultiPeriodSegmentTimelineMPD() *MPD { p := m.GetCurrentPeriod() p.ID = strconv.Itoa(i) p.Duration = Duration(30 * time.Second) - aas, _ := p.AddNewAdaptationSetAudio("audio/mp4", true, 1, "en") + aas, _ := p.AddNewAdaptationSetAudio("1", "audio/mp4", true, 1, "en") aas.AddNewRepresentationAudio(48000, 92000, "mp4a.40.2", "audio_1") aas.SegmentTemplate = &SegmentTemplate{ Timescale: ptrs.Int64ptr(48000), @@ -72,7 +72,7 @@ func getMultiPeriodSegmentTimelineMPD() *MPD { }, }, } - vas, _ := p.AddNewAdaptationSetVideo("video/mp4", "progressive", true, 1) + vas, _ := p.AddNewAdaptationSetVideo("2", "video/mp4", "progressive", true, 1) vas.AddNewRepresentationVideo(3532000, "avc1.640028", "video_1", "2997/100", 2048, 854) vas.AddNewRepresentationVideo(453000, "avc1.420016", "video_2", "2997/100", 648, 270) vas.SegmentTemplate = &SegmentTemplate{ @@ -101,7 +101,7 @@ func getSegmentTimelineMPD() *MPD { m := NewMPD(DASH_PROFILE_LIVE, "PT65.063S", "PT2.000S") m.period.BaseURL = "http://localhost:8002/public/" - aas, _ := m.AddNewAdaptationSetAudio("audio/mp4", true, 1, "English") + aas, _ := m.AddNewAdaptationSetAudio("1", "audio/mp4", true, 1, "English") ra, _ := aas.AddNewRepresentationAudio(48000, 255000, "mp4a.40.2", "audio_1") ra.SegmentTemplate = &SegmentTemplate{ @@ -120,7 +120,7 @@ func getSegmentTimelineMPD() *MPD { }, } - vas, _ := m.AddNewAdaptationSetVideo("video/mp4", "progressive", true, 1) + vas, _ := m.AddNewAdaptationSetVideo("2", "video/mp4", "progressive", true, 1) va, _ := vas.AddNewRepresentationVideo(int64(4172274), "avc1.640028", "video_1", "30000/1001", int64(1280), int64(720)) va.SegmentTemplate = &SegmentTemplate{