Skip to content

Commit 01b2380

Browse files
authored
Change InbandEventStream to array and add unit test (#91)
* NLP-4379 : Minor changes to inband event stream * NLP-4379 : Add unit test * NLP-4379 : Review comments
1 parent 4b8af7b commit 01b2380

File tree

3 files changed

+88
-14
lines changed

3 files changed

+88
-14
lines changed

mpd/fixtures/inband_event_stream.mpd

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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="PT6M16S" minBufferTime="PT1.97S">
3+
<Period>
4+
<AdaptationSet mimeType="video/mp4" startWithSAP="1" scanType="progressive" id="7357" segmentAlignment="true">
5+
<InbandEventStream schemeIdUri="https://aomedia.org/emsg/ID3" value="0"></InbandEventStream>
6+
<Representation bandwidth="1518664" codecs="avc1.4d401f" frameRate="30000/1001" height="540" id="800" width="960">
7+
<InbandEventStream schemeIdUri="https://aomedia.org/emsg/ID3" value="1"></InbandEventStream>
8+
</Representation>
9+
</AdaptationSet>
10+
</Period>
11+
</MPD>

mpd/mpd.go

+45-14
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ const (
5353

5454
// Known error variables
5555
var (
56-
ErrNoDASHProfileSet error = errors.New("No DASH profile set")
57-
ErrAdaptationSetNil = errors.New("Adaptation Set nil")
58-
ErrSegmentTemplateLiveProfileOnly = errors.New("Segment template can only be used with Live Profile")
59-
ErrSegmentTemplateNil = errors.New("Segment Template nil ")
60-
ErrRepresentationNil = errors.New("Representation nil")
61-
ErrAccessibilityNil = errors.New("Accessibility nil")
62-
ErrBaseURLEmpty = errors.New("Base URL empty")
63-
ErrSegmentBaseOnDemandProfileOnly = errors.New("Segment Base can only be used with On-Demand Profile")
64-
ErrSegmentBaseNil = errors.New("Segment Base nil")
65-
ErrAudioChannelConfigurationNil = errors.New("Audio Channel Configuration nil")
66-
ErrInvalidDefaultKID = errors.New("Invalid Default KID string, should be 32 characters")
67-
ErrPROEmpty = errors.New("PlayReady PRO empty")
68-
ErrContentProtectionNil = errors.New("Content Protection nil")
56+
ErrNoDASHProfileSet error = errors.New("No DASH profile set")
57+
ErrAdaptationSetNil = errors.New("Adaptation Set nil")
58+
ErrSegmentTemplateLiveProfileOnly = errors.New("Segment template can only be used with Live Profile")
59+
ErrSegmentTemplateNil = errors.New("Segment Template nil ")
60+
ErrRepresentationNil = errors.New("Representation nil")
61+
ErrAccessibilityNil = errors.New("Accessibility nil")
62+
ErrBaseURLEmpty = errors.New("Base URL empty")
63+
ErrSegmentBaseOnDemandProfileOnly = errors.New("Segment Base can only be used with On-Demand Profile")
64+
ErrSegmentBaseNil = errors.New("Segment Base nil")
65+
ErrAudioChannelConfigurationNil = errors.New("Audio Channel Configuration nil")
66+
ErrInvalidDefaultKID = errors.New("Invalid Default KID string, should be 32 characters")
67+
ErrPROEmpty = errors.New("PlayReady PRO empty")
68+
ErrContentProtectionNil = errors.New("Content Protection nil")
69+
ErrInbandEventStreamSchemeUriEmpty = errors.New("Inband Event Stream schemeIdUri Empty")
6970
)
7071

7172
type MPD struct {
@@ -124,7 +125,7 @@ type CommonAttributesAndElements struct {
124125
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"`
125126
EssentialProperty []DescriptorType `xml:"EssentialProperty,omitempty"`
126127
SupplementalProperty []DescriptorType `xml:"SupplementalProperty,omitempty"`
127-
InbandEventStream *DescriptorType `xml:"inbandEventStream,attr"`
128+
InbandEventStream []DescriptorType `xml:"InbandEventStream,omitempty"`
128129
}
129130

130131
type contentProtections []ContentProtectioner
@@ -1101,6 +1102,21 @@ func (as *AdaptationSet) AddNewAccessibilityElement(scheme AccessibilityElementS
11011102
return accessibility, nil
11021103
}
11031104

1105+
// AddNewInbandEventStream - Adds a new InbandEventStream Descriptor to an adaptation set
1106+
// uri - Scheme ID URI for the inband event stream
1107+
// val - value for inband event stream
1108+
func (as *AdaptationSet) AddNewInbandEventStream(uri string, val string) error {
1109+
if len(uri) <= 0 {
1110+
return ErrInbandEventStreamSchemeUriEmpty
1111+
}
1112+
evt := DescriptorType{
1113+
SchemeIDURI: Strptr(uri),
1114+
Value: Strptr(val),
1115+
}
1116+
as.InbandEventStream = append(as.InbandEventStream, evt)
1117+
return nil
1118+
}
1119+
11041120
// Sets the BaseURL for a Representation.
11051121
// baseURL - Base URL as a string (i.e. 800k/output-audio-und.mp4)
11061122
func (r *Representation) SetNewBaseURL(baseURL string) error {
@@ -1166,3 +1182,18 @@ func (r *Representation) setAudioChannelConfiguration(acc *AudioChannelConfigura
11661182
r.AudioChannelConfiguration = acc
11671183
return nil
11681184
}
1185+
1186+
// AddNewInbandEventStream - Adds a new InbandEventStream Descriptor to a Representation
1187+
// uri - Scheme ID URI for the inband event stream
1188+
// val - value for inband event stream
1189+
func (r *Representation) AddNewInbandEventStream(uri string, val string) error {
1190+
if len(uri) <= 0 {
1191+
return ErrInbandEventStreamSchemeUriEmpty
1192+
}
1193+
evt := DescriptorType{
1194+
SchemeIDURI: Strptr(uri),
1195+
Value: Strptr(val),
1196+
}
1197+
r.InbandEventStream = append(r.InbandEventStream, evt)
1198+
return nil
1199+
}

mpd/mpd_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
4747
VALID_ROLE string = "main"
4848
VALID_LOCATION string = "https://example.com/location.mpd"
49+
VALID_SCHEME_ID_URI string = "https://aomedia.org/emsg/ID3"
4950
)
5051

5152
func TestNewMPDLive(t *testing.T) {
@@ -558,3 +559,34 @@ func TestReadWriteIdentical(t *testing.T) {
558559
})
559560
}
560561
}
562+
563+
func TestSetInbandEventStream(t *testing.T) {
564+
var (
565+
err error
566+
got string
567+
)
568+
569+
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
570+
videoAS, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
571+
err = videoAS.AddNewInbandEventStream(VALID_SCHEME_ID_URI, "0")
572+
573+
require.NoError(t, err)
574+
575+
r, _ := videoAS.AddNewRepresentationVideo(VALID_VIDEO_BITRATE, VALID_VIDEO_CODEC, VALID_VIDEO_ID, VALID_VIDEO_FRAMERATE, VALID_VIDEO_WIDTH, VALID_VIDEO_HEIGHT)
576+
err = r.AddNewInbandEventStream(VALID_SCHEME_ID_URI, "1")
577+
578+
require.NoError(t, err)
579+
580+
got, err = m.WriteToString()
581+
require.NoError(t, err)
582+
583+
testfixtures.CompareFixture(t, "fixtures/inband_event_stream.mpd", got)
584+
}
585+
586+
func TestSetInbandEventStreamError(t *testing.T) {
587+
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
588+
videoAS, _ := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
589+
err := videoAS.AddNewInbandEventStream("", "")
590+
591+
require.EqualErr(t, ErrInbandEventStreamSchemeUriEmpty, err)
592+
}

0 commit comments

Comments
 (0)