Skip to content

Commit

Permalink
Merge branch 'master' into issue_26
Browse files Browse the repository at this point in the history
# Conflicts:
#	mpd/mpd.go

Updated tests to have correct element order in AdaptationSet.
  • Loading branch information
bahern committed Mar 10, 2016
2 parents 1f1642c + 714d83a commit 47f03bb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ go install ./...
* Profiles
* Live
* On Demand
* Adaption Sets / Representations
* Adaption Sets / Representations / Roles
* Audio
* Video
* Subtitles
Expand Down
2 changes: 2 additions & 0 deletions mpd/fixtures/live_profile.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<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="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="en">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"></Role>
<ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" xmlns:cenc="urn:mpeg:cenc:2013" cenc:default_KID="08e36702-8f33-436c-a5dd60ffe5571e60" value="cenc"></ContentProtection>
<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" xmlns:cenc="urn:mpeg:cenc:2013">
<cenc:pssh>AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA==</cenc:pssh>
Expand All @@ -14,6 +15,7 @@
<Representation audioSamplingRate="44100" bandwidth="67095" codecs="mp4a.40.2" id="800"></Representation>
</AdaptationSet>
<AdaptationSet mimeType="video/mp4" scanType="progressive" segmentAlignment="true" startWithSAP="1">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"></Role>
<ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" xmlns:cenc="urn:mpeg:cenc:2013" cenc:default_KID="08e36702-8f33-436c-a5dd60ffe5571e60" value="cenc"></ContentProtection>
<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" xmlns:cenc="urn:mpeg:cenc:2013">
<cenc:pssh>AAAAYXBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAEEIARIQWr3VL1VKTyq40GH3YUJRVRoIY2FzdGxhYnMiGFdyM1ZMMVZLVHlxNDBHSDNZVUpSVlE9PTIHZGVmYXVsdA==</cenc:pssh>
Expand Down
20 changes: 20 additions & 0 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type AdaptationSet struct {
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
StartWithSAP *int64 `xml:"startWithSAP,attr"`
Lang *string `xml:"lang,attr"`
Roles []*Role `xml:"Role,omitempty"`
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"`
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
Expand Down Expand Up @@ -121,6 +122,12 @@ type WidevineContentProtection struct {

func (s ContentProtection) ContentProtected() {}

type Role struct {
AdaptationSet *AdaptationSet `xml:"-"`
SchemeIDURI *string `xml:"schemeIdUri,attr"`
Value *string `xml:"value,attr"`
}

// Segment Template is for Live Profile Only
type SegmentTemplate struct {
AdaptationSet *AdaptationSet `xml:"-"`
Expand Down Expand Up @@ -482,6 +489,19 @@ func (as *AdaptationSet) addRepresentation(r *Representation) error {
return nil
}

// Adds a new Role to an AdaptationSet
// schemeIdUri - Scheme ID URI string (i.e. urn:mpeg:dash:role:2011)
// value - Value for this role, (i.e. caption, subtitle, main, alternate, supplementary, commentary, dub)
func (as *AdaptationSet) AddNewRole(schemeIDURI string, value string) (*Role, error) {
r := &Role{
SchemeIDURI: Strptr(schemeIDURI),
Value: Strptr(value),
}
r.AdaptationSet = as
as.Roles = append(as.Roles, r)
return r, nil
}

// Sets the BaseURL for a Representation.
// baseURL - Base URL as a string (i.e. 800k/output-audio-und.mp4)
func (r *Representation) SetNewBaseURL(baseURL string) error {
Expand Down
4 changes: 4 additions & 0 deletions mpd/mpd_read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func LiveProfile() *MPD {
audioAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes())
audioAS.AddNewContentProtectionSchemePlayreadyWithPSSH(VALID_PLAYREADY_PRO)

audioAS.AddNewRole("urn:mpeg:dash:role:2011", VALID_ROLE)

audioAS.SetNewSegmentTemplate(1968, "$RepresentationID$/audio/en/init.mp4", "$RepresentationID$/audio/en/seg-$Number$.m4f", 0, 1000)
audioAS.AddNewRepresentationAudio(44100, 67095, "mp4a.40.2", "800")

Expand All @@ -132,6 +134,8 @@ func LiveProfile() *MPD {
videoAS.AddNewContentProtectionSchemeWidevineWithPSSH(getValidWVHeaderBytes())
videoAS.AddNewContentProtectionSchemePlayreadyWithPSSH(VALID_PLAYREADY_PRO)

videoAS.AddNewRole("urn:mpeg:dash:role:2011", VALID_ROLE)

videoAS.SetNewSegmentTemplate(1968, "$RepresentationID$/video/1/init.mp4", "$RepresentationID$/video/1/seg-$Number$.m4f", 0, 1000)
videoAS.AddNewRepresentationVideo(1518664, "avc1.4d401f", "800", "30000/1001", 960, 540)
videoAS.AddNewRepresentationVideo(1911775, "avc1.4d401f", "1000", "30000/1001", 1024, 576)
Expand Down
11 changes: 11 additions & 0 deletions mpd/mpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
VALID_SUBTITLE_BANDWIDTH int64 = 256
VALID_SUBTITLE_ID string = "subtitle_en"
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
VALID_ROLE string = "main"
)

func (s *MPDSuite) TestNewMPDLive() {
Expand Down Expand Up @@ -406,6 +407,16 @@ func (s *MPDSuite) TestAddRepresentationErrorNil() {
assert.Equal(s.T(), ErrRepresentationNil, err)
}

func (s *MPDSuite) TestAddRole() {
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)

r, err := audioAS.AddNewRole("urn:mpeg:dash:role:2011", VALID_ROLE)

assert.NotNil(s.T(), r)
assert.Nil(s.T(), err)
}

func (s *MPDSuite) TestSetSegmentTemplateErrorNil() {
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)
Expand Down

0 comments on commit 47f03bb

Please sign in to comment.