Skip to content

Commit 6727424

Browse files
committed
Fix DescriptorTypes
1 parent 4c1e141 commit 6727424

File tree

4 files changed

+118
-39
lines changed

4 files changed

+118
-39
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT30.016S" minBufferTime="PT2.000S">
3+
<Period>
4+
<BaseURL>http://localhost:8002/dash/</BaseURL>
5+
<AdaptationSet mimeType="audio/mp4" startWithSAP="1" id="1" segmentAlignment="true" lang="English">
6+
<AudioChannelConfiguration></AudioChannelConfiguration>
7+
<Representation audioSamplingRate="48000" bandwidth="255000" codecs="mp4a.40.2" id="audio_1">
8+
<SegmentList timescale="48000" duration="479232">
9+
<Initialization sourceURL="b4324d65-ad06-4735-9535-5cd4af84ebb6/dcb11457-9092-4410-b204-67b3c6d9a9e2/init.m4f"></Initialization>
10+
<SegmentURL media="b4324d65-ad06-4735-9535-5cd4af84ebb6/dcb11457-9092-4410-b204-67b3c6d9a9e2/segment0.m4f"></SegmentURL>
11+
</SegmentList>
12+
</Representation>
13+
</AdaptationSet>
14+
<AdaptationSet mimeType="video/mp4" startWithSAP="1" scanType="progressive" id="2" segmentAlignment="true">
15+
<SupplementalProperty schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016" value="3"></SupplementalProperty>
16+
<Representation bandwidth="4172274" codecs="avc1.640028" frameRate="30000/1001" height="720" id="video_1" width="1280">
17+
<SegmentList timescale="30000" duration="225120">
18+
<Initialization sourceURL="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/init.m4f"></Initialization>
19+
<SegmentURL media="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/segment0.m4f"></SegmentURL>
20+
</SegmentList>
21+
</Representation>
22+
</AdaptationSet>
23+
<AdaptationSet mimeType="video/hevc" startWithSAP="1" scanType="progressive" id="3" segmentAlignment="true">
24+
<SupplementalProperty schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016" value="2"></SupplementalProperty>
25+
<Representation bandwidth="4172274" codecs="avc1.640028" frameRate="30000/1001" height="720" id="video_1" width="1280">
26+
<SegmentList timescale="30000" duration="225120">
27+
<Initialization sourceURL="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/init.m4f"></Initialization>
28+
<SegmentURL media="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/segment0.m4f"></SegmentURL>
29+
</SegmentList>
30+
</Representation>
31+
</AdaptationSet>
32+
</Period>
33+
</MPD>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT30.016S" minBufferTime="PT2.000S">
3+
<Period>
4+
<BaseURL>http://localhost:8002/dash/</BaseURL>
5+
<AdaptationSet mimeType="audio/mp4" startWithSAP="1" id="1" segmentAlignment="true" lang="English">
6+
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
7+
<Representation audioSamplingRate="48000" bandwidth="255000" codecs="mp4a.40.2" id="audio_1">
8+
<SegmentList timescale="48000" duration="479232">
9+
<Initialization sourceURL="b4324d65-ad06-4735-9535-5cd4af84ebb6/dcb11457-9092-4410-b204-67b3c6d9a9e2/init.m4f"></Initialization>
10+
<SegmentURL media="b4324d65-ad06-4735-9535-5cd4af84ebb6/dcb11457-9092-4410-b204-67b3c6d9a9e2/segment0.m4f"></SegmentURL>
11+
</SegmentList>
12+
</Representation>
13+
</AdaptationSet>
14+
<AdaptationSet mimeType="video/mp4" startWithSAP="1" scanType="progressive" id="2" segmentAlignment="true">
15+
<Representation bandwidth="4172274" codecs="avc1.640028" frameRate="30000/1001" height="720" id="video_1" width="1280">
16+
<SegmentList timescale="30000" duration="225120">
17+
<Initialization sourceURL="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/init.m4f"></Initialization>
18+
<SegmentURL media="b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/segment0.m4f"></SegmentURL>
19+
</SegmentList>
20+
</Representation>
21+
</AdaptationSet>
22+
</Period>
23+
</MPD>

mpd/mpd.go

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ type CommonAttributesAndElements struct {
118118
StartWithSAP *int64 `xml:"startWithSAP,attr"`
119119
MaxPlayoutRate *string `xml:"maxPlayoutRate,attr"`
120120
ScanType *string `xml:"scanType,attr"`
121-
FramePacking *DescriptorType `xml:"framePacking,attr"`
122-
AudioChannelConfiguration *DescriptorType `xml:"audioChannelConfiguration,attr"`
121+
FramePacking []DescriptorType `xml:"FramePacking,omitempty"`
122+
AudioChannelConfiguration []DescriptorType `xml:"AudioChannelConfiguration,omitempty"`
123123
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"`
124-
EssentialProperty *DescriptorType `xml:"essentialProperty,attr"`
125-
SupplementalProperty *DescriptorType `xml:"supplmentalProperty,attr"`
124+
EssentialProperty []DescriptorType `xml:"EssentialProperty,omitempty"`
125+
SupplementalProperty []DescriptorType `xml:"SupplementalProperty,omitempty"`
126126
InbandEventStream *DescriptorType `xml:"inbandEventStream,attr"`
127127
}
128128

@@ -151,32 +151,30 @@ type AdaptationSet struct {
151151
}
152152

153153
func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
154-
155-
adaptationSet := struct {
156-
CommonAttributesAndElements
157-
XMLName xml.Name `xml:"AdaptationSet"`
158-
ID *string `xml:"id,attr"`
159-
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
160-
Lang *string `xml:"lang,attr"`
161-
Group *string `xml:"group,attr"`
162-
PAR *string `xml:"par,attr"`
163-
MinBandwidth *string `xml:"minBandwidth,attr"`
164-
MaxBandwidth *string `xml:"maxBandwidth,attr"`
165-
MinWidth *string `xml:"minWidth,attr"`
166-
MaxWidth *string `xml:"maxWidth,attr"`
167-
MinHeight *string `xml:"minHeight,attr"`
168-
MaxHeight *string `xml:"maxHeight,attr"`
169-
ContentType *string `xml:"contentType,attr"`
170-
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
171-
Roles []*Role `xml:"Role,omitempty"`
172-
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
173-
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
174-
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
175-
Representations []*Representation `xml:"Representation,omitempty"`
176-
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
177-
}{}
178-
179154
var (
155+
adaptationSet struct {
156+
CommonAttributesAndElements
157+
XMLName xml.Name `xml:"AdaptationSet"`
158+
ID *string `xml:"id,attr"`
159+
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
160+
Lang *string `xml:"lang,attr"`
161+
Group *string `xml:"group,attr"`
162+
PAR *string `xml:"par,attr"`
163+
MinBandwidth *string `xml:"minBandwidth,attr"`
164+
MaxBandwidth *string `xml:"maxBandwidth,attr"`
165+
MinWidth *string `xml:"minWidth,attr"`
166+
MaxWidth *string `xml:"maxWidth,attr"`
167+
MinHeight *string `xml:"minHeight,attr"`
168+
MaxHeight *string `xml:"maxHeight,attr"`
169+
ContentType *string `xml:"contentType,attr"`
170+
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
171+
Roles []*Role `xml:"Role,omitempty"`
172+
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
173+
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
174+
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
175+
Representations []*Representation `xml:"Representation,omitempty"`
176+
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
177+
}
180178
contentProtectionTags []ContentProtectioner
181179
roles []*Role
182180
segmentBase *SegmentBase
@@ -258,11 +256,23 @@ func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
258256
}
259257
representations = append(representations, rp)
260258
case "Accessibility":
261-
ac := new(Accessibility)
262-
err = d.DecodeElement(ac, &tt)
263-
if err != nil {
259+
var a Accessibility
260+
adaptationSet.AccessibilityElems = append(adaptationSet.AccessibilityElems, &a)
261+
if err = d.DecodeElement(&a, &tt); err != nil {
262+
return err
263+
}
264+
case "AudioChannelConfiguration":
265+
var dt DescriptorType
266+
if err = d.DecodeElement(&dt, &tt); err != nil {
267+
return err
268+
}
269+
adaptationSet.AudioChannelConfiguration = append(adaptationSet.AudioChannelConfiguration, dt)
270+
case "SupplementalProperty":
271+
var dt DescriptorType
272+
if err = d.DecodeElement(&dt, &tt); err != nil {
264273
return err
265274
}
275+
adaptationSet.SupplementalProperty = append(adaptationSet.SupplementalProperty, dt)
266276
default:
267277
return fmt.Errorf("unrecognized element in AdaptationSet %q", tt.Name.Local)
268278
}

mpd/mpd_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mpd
22

33
import (
44
"encoding/base64"
5+
"path/filepath"
56
"testing"
67

78
. "github.com/zencoder/go-dash/helpers/ptrs"
@@ -504,12 +505,24 @@ func TestLocationWriteToString(t *testing.T) {
504505
testfixtures.CompareFixture(t, "fixtures/location.mpd", got)
505506
}
506507

507-
func TestReadLocation(t *testing.T) {
508-
m, err := ReadFromFile("fixtures/location.mpd")
508+
func TestReadWriteIdentical(t *testing.T) {
509+
const fixtures = "fixtures/"
510+
var (
511+
skipFixtures = map[string]struct{}{"invalid.mpd": {}}
512+
matches, err = filepath.Glob(fixtures + "*.mpd")
513+
)
509514
require.NoError(t, err)
510-
511-
got, err := m.WriteToString()
512-
require.NoError(t, err)
513-
514-
testfixtures.CompareFixture(t, "fixtures/location.mpd", got)
515+
for _, file := range matches {
516+
file := filepath.Base(file)
517+
if _, ok := skipFixtures[file]; ok {
518+
continue
519+
}
520+
t.Run(file, func(t *testing.T) {
521+
m, err := ReadFromFile(fixtures + file)
522+
require.NoError(t, err)
523+
got, err := m.WriteToString()
524+
require.NoError(t, err)
525+
testfixtures.CompareFixture(t, fixtures+file, got)
526+
})
527+
}
515528
}

0 commit comments

Comments
 (0)