Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing attributes for dash mpd model #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mpd [![GoDoc](https://godoc.org/github.com/mc2soft/mpd?status.svg)](https://godoc.org/github.com/mc2soft/mpd) [![Build Status](https://travis-ci.org/mc2soft/mpd.svg)](https://travis-ci.org/mc2soft/mpd)
# go-dash-mpd [![GoDoc](https://godoc.org/github.com/RamanPndy/go-dash-mpd?status.svg)](https://godoc.org/github.com/RamanPndy/go-dash-mpd)

Go library for parsing and generating MPEG-DASH Media Presentation Description (MPD) files.

[Documentation](http://godoc.org/github.com/mc2soft/mpd).
[Documentation](http://godoc.org/github.com/RamanPndy/go-dash-mpd).
2 changes: 1 addition & 1 deletion fixture_elemental_delta_live.mpd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" id="695765" type="dynamic" publishTime="2020-09-04T10:46:11" minimumUpdatePeriod="PT16S" availabilityStartTime="2020-06-30T09:39:43.723000+00:00" minBufferTime="PT40S" suggestedPresentationDelay="PT25.00S" timeShiftBufferDepth="PT60.00S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
<Period start="PT0.00S" id="1">
<AdaptationSet mimeType="video/mp4" segmentAlignment="true" startWithSAP="1" bitstreamSwitching="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
Expand Down
2 changes: 1 addition & 1 deletion fixture_elemental_delta_vod.mpd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" id="1141785" type="static" mediaPresentationDuration="PT136.680S" minBufferTime="PT40S" profiles="urn:mpeg:dash:profile:isoff-main:2011" xmlns:scte35="urn:scte:scte35:2013:xml">
<Period start="PT0.000S" id="1" duration="PT136.680S">
<AdaptationSet mimeType="video/mp4" segmentAlignment="true" startWithSAP="1" bitstreamSwitching="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
Expand Down
2 changes: 1 addition & 1 deletion fixture_elemental_delta_vod_multi_drm.mpd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" id="1135124" type="static" mediaPresentationDuration="PT136.680S" minBufferTime="PT40S" profiles="urn:mpeg:dash:profile:isoff-main:2011" xmlns:scte35="urn:scte:scte35:2013:xml">
<Period start="PT0.000S" id="1" duration="PT136.680S">
<AdaptationSet mimeType="video/mp4" segmentAlignment="true" startWithSAP="1" bitstreamSwitching="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
Expand Down
2 changes: 1 addition & 1 deletion fixture_flussonic_live.mpd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd" id="dash" type="dynamic" publishTime="2021-09-21T14:28:50Z" minimumUpdatePeriod="PT5.6S" availabilityStartTime="2021-09-17T04:42:54Z" minBufferTime="PT17S" suggestedPresentationDelay="PT17S" timeShiftBufferDepth="PT136S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
<Period start="PT0S" id="1631853774">
<AdaptationSet mimeType="video/mp4" segmentAlignment="true" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
Expand Down
2 changes: 1 addition & 1 deletion fixture_vod_with_base_url.mpd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd" id="dash" type="dynamic" publishTime="2021-09-21T14:28:50Z" minimumUpdatePeriod="PT5.6S" availabilityStartTime="2021-09-17T04:42:54Z" minBufferTime="PT17S" suggestedPresentationDelay="PT17S" timeShiftBufferDepth="PT136S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
<BaseURL>https://video-1-2/</BaseURL>
<Period start="PT0S" id="1631853774">
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mc2soft/mpd
module github.com/RamanPndy/go-dash-mpd

go 1.16

Expand Down
209 changes: 154 additions & 55 deletions mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strconv"

copyobj "github.com/mc2soft/mpd/utils"
copyobj "github.com/RamanPndy/go-dash-mpd/utils"
)

// http://mpeg.chiariglione.org/standards/mpeg-dash
Expand Down Expand Up @@ -75,6 +75,7 @@ type MPD struct {
PublishTime *string `xml:"publishTime,attr"`
Profiles string `xml:"profiles,attr"`
XSI *string `xml:"xsi,attr,omitempty"`
Cenc *string `xml:"cenc,attr,omitempty"`
SCTE35 *string `xml:"scte35,attr,omitempty"`
XSISchemaLocation *string `xml:"schemaLocation,attr"`
ID *string `xml:"id,attr"`
Expand All @@ -86,6 +87,7 @@ type MPD struct {
type mpdMarshal struct {
XMLName xml.Name `xml:"MPD"`
XSI *string `xml:"xmlns:xsi,attr,omitempty"`
Cenc *string `xml:"xmlns:cenc,attr,omitempty"`
XMLNS *string `xml:"xmlns,attr"`
XSISchemaLocation *string `xml:"xsi:schemaLocation,attr"`
ID *string `xml:"id,attr"`
Expand Down Expand Up @@ -121,7 +123,7 @@ func (m *MPD) Encode() ([]byte, error) {

// hacks for self-closing tags
res := new(bytes.Buffer)
res.WriteString(`<?xml version="1.0" encoding="utf-8"?>`)
res.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
res.WriteByte('\n')
for {
s, err := x.ReadString('\n')
Expand Down Expand Up @@ -163,58 +165,112 @@ type periodMarshal struct {

// AdaptationSet represents XSD's AdaptationSetType.
type AdaptationSet struct {
MimeType string `xml:"mimeType,attr"`
SegmentAlignment ConditionalUint `xml:"segmentAlignment,attr"`
StartWithSAP *uint64 `xml:"startWithSAP,attr"`
BitstreamSwitching *bool `xml:"bitstreamSwitching,attr"`
SubsegmentAlignment ConditionalUint `xml:"subsegmentAlignment,attr"`
SubsegmentStartsWithSAP *uint64 `xml:"subsegmentStartsWithSAP,attr"`
Lang *string `xml:"lang,attr"`
ContentProtections []DRMDescriptor `xml:"ContentProtection,omitempty"`
Representations []Representation `xml:"Representation,omitempty"`
Codecs *string `xml:"codecs,attr"`
Role *Role `xml:"Role,omitempty"`
MimeType string `xml:"mimeType,attr,omitempty"`
SegmentAlignment ConditionalUint `xml:"segmentAlignment,attr"`
StartWithSAP *uint64 `xml:"startWithSAP,attr"`
BitstreamSwitching *bool `xml:"bitstreamSwitching,attr"`
SubsegmentAlignment ConditionalUint `xml:"subsegmentAlignment,attr"`
SubsegmentStartsWithSAP *uint64 `xml:"subsegmentStartsWithSAP,attr"`
Lang *string `xml:"lang,attr"`
ContentProtections []DRMDescriptor `xml:"ContentProtection,omitempty"`
Representations []Representation `xml:"Representation,omitempty"`
Codecs *string `xml:"codecs,attr"`
ContentType string `xml:"contentType,attr,omitempty"`
ID *string `xml:"id,attr"`
Width *string `xml:"width,attr,omitempty"`
Height *string `xml:"height,attr,omitempty"`
MaxWidth *string `xml:"maxWidth,attr,omitempty"`
MaxHeight *string `xml:"maxHeight,attr,omitempty"`
FrameRate *string `xml:"frameRate,attr,omitempty"`
Par *string `xml:"par,attr,omitempty"`
SupplementalProperty *SupplementalProperty `xml:"SupplementalProperty,omitempty"`
}

type adaptationSetMarshal struct {
MimeType string `xml:"mimeType,attr"`
SegmentAlignment ConditionalUint `xml:"segmentAlignment,attr"`
StartWithSAP *uint64 `xml:"startWithSAP,attr"`
BitstreamSwitching *bool `xml:"bitstreamSwitching,attr"`
SubsegmentAlignment ConditionalUint `xml:"subsegmentAlignment,attr"`
SubsegmentStartsWithSAP *uint64 `xml:"subsegmentStartsWithSAP,attr"`
Lang *string `xml:"lang,attr"`
ContentProtections []drmDescriptorMarshal `xml:"ContentProtection,omitempty"`
Representations []representationMarshal `xml:"Representation,omitempty"`
Codecs *string `xml:"codecs,attr"`
Role *roleMarshal `xml:"Role,omitempty"`
MimeType string `xml:"mimeType,attr,omitempty"`
SegmentAlignment ConditionalUint `xml:"segmentAlignment,attr"`
StartWithSAP *uint64 `xml:"startWithSAP,attr"`
BitstreamSwitching *bool `xml:"bitstreamSwitching,attr"`
SubsegmentAlignment ConditionalUint `xml:"subsegmentAlignment,attr"`
SubsegmentStartsWithSAP *uint64 `xml:"subsegmentStartsWithSAP,attr"`
Lang *string `xml:"lang,attr"`
ContentProtections []drmDescriptorMarshal `xml:"ContentProtection,omitempty"`
Representations []representationMarshal `xml:"Representation,omitempty"`
Codecs *string `xml:"codecs,attr"`
ContentType string `xml:"contentType,attr,omitempty"`
ID *string `xml:"id,attr"`
Width *string `xml:"width,attr,omitempty"`
Height *string `xml:"height,attr,omitempty"`
MaxWidth *string `xml:"maxWidth,attr,omitempty"`
MaxHeight *string `xml:"maxHeight,attr,omitempty"`
FrameRate *string `xml:"frameRate,attr,omitempty"`
Par *string `xml:"par,attr,omitempty"`
SupplementalProperty *supplementalPropertyMarshal `xml:"SupplementalProperty,omitempty"`
}

type Role struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

type roleMarshal struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

type SupplementalProperty struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

type supplementalPropertyMarshal struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

// Representation represents XSD's RepresentationType.
type Representation struct {
ID *string `xml:"id,attr"`
Width *uint64 `xml:"width,attr"`
Height *uint64 `xml:"height,attr"`
SAR *string `xml:"sar,attr"`
FrameRate *string `xml:"frameRate,attr"`
Bandwidth *uint64 `xml:"bandwidth,attr"`
AudioSamplingRate *string `xml:"audioSamplingRate,attr"`
Codecs *string `xml:"codecs,attr"`
BaseURL *string `xml:"BaseURL,omitempty"`
ContentProtections []DRMDescriptor `xml:"ContentProtection,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
ID *string `xml:"id,attr"`
Width *uint64 `xml:"width,attr"`
Height *uint64 `xml:"height,attr"`
SAR *string `xml:"sar,attr"`
FrameRate *string `xml:"frameRate,attr"`
Bandwidth *uint64 `xml:"bandwidth,attr"`
AudioSamplingRate *string `xml:"audioSamplingRate,attr"`
Codecs *string `xml:"codecs,attr"`
BaseURL *string `xml:"BaseURL,omitempty"`
ContentProtections []DRMDescriptor `xml:"ContentProtection,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
MimeType string `xml:"mimeType,attr,omitempty"`
AudioChannelConfiguration *AudioChannelConfiguration `xml:"AudioChannelConfiguration,omitempty"`
}

type representationMarshal struct {
ID *string `xml:"id,attr"`
Width *uint64 `xml:"width,attr"`
Height *uint64 `xml:"height,attr"`
SAR *string `xml:"sar,attr"`
FrameRate *string `xml:"frameRate,attr"`
Bandwidth *uint64 `xml:"bandwidth,attr"`
AudioSamplingRate *string `xml:"audioSamplingRate,attr"`
Codecs *string `xml:"codecs,attr"`
BaseURL *string `xml:"BaseURL,omitempty"`
ContentProtections []drmDescriptorMarshal `xml:"ContentProtection,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
ID *string `xml:"id,attr"`
Width *uint64 `xml:"width,attr"`
Height *uint64 `xml:"height,attr"`
SAR *string `xml:"sar,attr"`
FrameRate *string `xml:"frameRate,attr"`
Bandwidth *uint64 `xml:"bandwidth,attr"`
AudioSamplingRate *string `xml:"audioSamplingRate,attr"`
Codecs *string `xml:"codecs,attr"`
BaseURL *string `xml:"BaseURL,omitempty"`
ContentProtections []drmDescriptorMarshal `xml:"ContentProtection,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
MimeType string `xml:"mimeType,attr,omitempty"`
AudioChannelConfiguration *audioChannelConfigurationMarshal `xml:"AudioChannelConfiguration,omitempty"`
}

type AudioChannelConfiguration struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

type audioChannelConfigurationMarshal struct {
SchemeIdUri *string `xml:"schemeIdUri,attr,omitempty"`
Value *string `xml:"value,attr,omitempty"`
}

// Descriptor represents XSD's DescriptorType.
Expand Down Expand Up @@ -278,6 +334,7 @@ func modifyMPD(mpd *MPD) *mpdMarshal {
XSI: copyobj.String(mpd.XSI),
SCTE35: copyobj.String(mpd.SCTE35),
XSISchemaLocation: copyobj.String(mpd.XSISchemaLocation),
Cenc: copyobj.String(mpd.Cenc),
ID: copyobj.String(mpd.ID),
BaseURL: copyobj.String(mpd.BaseURL),
Period: modifyPeriod(mpd.Period),
Expand Down Expand Up @@ -312,13 +369,23 @@ func modifyAdaptationSets(as []*AdaptationSet) []*adaptationSetMarshal {
BitstreamSwitching: copyobj.Bool(a.BitstreamSwitching),
Codecs: copyobj.String(a.Codecs),
Lang: copyobj.String(a.Lang),
ID: copyobj.String(a.ID),
ContentType: a.ContentType,
MimeType: a.MimeType,
SegmentAlignment: a.SegmentAlignment,
StartWithSAP: copyobj.UInt64(a.StartWithSAP),
SubsegmentAlignment: a.SubsegmentAlignment,
SubsegmentStartsWithSAP: copyobj.UInt64(a.SubsegmentStartsWithSAP),
Representations: modifyRepresentations(a.Representations),
ContentProtections: modifyContentProtections(a.ContentProtections),
Role: modifyRole(a.Role),
Width: copyobj.String(a.Width),
Height: copyobj.String(a.Height),
MaxWidth: copyobj.String(a.MaxWidth),
MaxHeight: copyobj.String(a.MaxHeight),
Par: copyobj.String(a.Par),
FrameRate: copyobj.String(a.FrameRate),
SupplementalProperty: modifySupplementalProperty(a.SupplementalProperty),
}
asm = append(asm, adaptationSet)
}
Expand All @@ -329,17 +396,19 @@ func modifyRepresentations(rs []Representation) []representationMarshal {
rsm := make([]representationMarshal, 0, len(rs))
for _, r := range rs {
representation := representationMarshal{
AudioSamplingRate: copyobj.String(r.AudioSamplingRate),
Bandwidth: copyobj.UInt64(r.Bandwidth),
Codecs: copyobj.String(r.Codecs),
FrameRate: copyobj.String(r.FrameRate),
Height: copyobj.UInt64(r.Height),
ID: copyobj.String(r.ID),
Width: copyobj.UInt64(r.Width),
SegmentTemplate: copySegmentTemplate(r.SegmentTemplate),
SAR: copyobj.String(r.SAR),
ContentProtections: modifyContentProtections(r.ContentProtections),
BaseURL: copyobj.String(r.BaseURL),
AudioSamplingRate: copyobj.String(r.AudioSamplingRate),
Bandwidth: copyobj.UInt64(r.Bandwidth),
Codecs: copyobj.String(r.Codecs),
FrameRate: copyobj.String(r.FrameRate),
Height: copyobj.UInt64(r.Height),
ID: copyobj.String(r.ID),
Width: copyobj.UInt64(r.Width),
SegmentTemplate: copySegmentTemplate(r.SegmentTemplate),
SAR: copyobj.String(r.SAR),
ContentProtections: modifyContentProtections(r.ContentProtections),
BaseURL: copyobj.String(r.BaseURL),
MimeType: r.MimeType,
AudioChannelConfiguration: modifyAudioChannelConfiguration(r.AudioChannelConfiguration),
}
rsm = append(rsm, representation)
}
Expand Down Expand Up @@ -397,3 +466,33 @@ func modifyPssh(p *Pssh) *psshMarshal {
Value: copyobj.String(p.Value),
}
}

func modifyRole(r *Role) *roleMarshal {
if r == nil {
return nil
}
return &roleMarshal{
SchemeIdUri: copyobj.String(r.SchemeIdUri),
Value: copyobj.String(r.Value),
}
}

func modifySupplementalProperty(s *SupplementalProperty) *supplementalPropertyMarshal {
if s == nil {
return nil
}
return &supplementalPropertyMarshal{
SchemeIdUri: copyobj.String(s.SchemeIdUri),
Value: copyobj.String(s.Value),
}
}

func modifyAudioChannelConfiguration(a *AudioChannelConfiguration) *audioChannelConfigurationMarshal {
if a == nil {
return nil
}
return &audioChannelConfigurationMarshal{
SchemeIdUri: copyobj.String(a.SchemeIdUri),
Value: copyobj.String(a.Value),
}
}