Skip to content

Commit

Permalink
Merge pull request #19 from Eyevinn/contentprotection-getter
Browse files Browse the repository at this point in the history
feat: GetContentProtection, GetMimeType, GetSegmentTemplate methods
  • Loading branch information
tobbee authored Nov 24, 2023
2 parents f7748ed + 8bb8417 commit 7ebfce3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet
### Added

- GetContentProtections, GetMimeType, and GetSegmentTemplate methods for AdaptationSet and Representation

## [0.10.0] - 2023-05-26

Expand Down
1 change: 1 addition & 0 deletions mpd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var (
ErrASTRequired = errors.New("availabilityStartTime is required for dynamic MPDs")
ErrPeriodNotFound = errors.New("period not found in MPD")
ErrParentNotSet = errors.New("parent not set")
ErrSegmentTemplateNotSet = errors.New("segmentTemplate not set")
ErrNoMediaPresentationDuration = errors.New("no MediaPresentationDuration in static MPD")
ErrUnknownPeriodDur = errors.New("period duration cannot be derived")
ErrUnknownPeriodStart = errors.New("period start cannot be derived")
Expand Down
62 changes: 48 additions & 14 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,21 @@ func (a *AdaptationSetType) Clone() *AdaptationSetType {
return ac
}

// GetSegmentTemplate returns the segment template of the AdaptationSet or nil if not set.
func (a *AdaptationSetType) GetSegmentTemplate() *SegmentTemplateType {
return a.SegmentTemplate
}

// GetMimeType returns the mime type.
func (a *AdaptationSetType) GetMimeType() string {
return a.MimeType
}

// GetRepresentations returns the ContentProtections of the adaptation set.
func (a *AdaptationSetType) GetContentProtections() []*ContentProtectionType {
return a.ContentProtections
}

// ContentComponentType is Content Component.
type ContentComponentType struct {
XMLName xml.Name `xml:"ContentComponent"`
Expand Down Expand Up @@ -411,6 +426,13 @@ type RepresentationBaseType struct {
Resyncs []*ResyncType `xml:"Resync"`
}

func (r *RepresentationType) GetSegmentTemplate() *SegmentTemplateType {
if r.SegmentTemplate == nil {
return r.parent.GetSegmentTemplate()
}
return r.SegmentTemplate
}

// GetInit returns the representation's initialization URI with replaced identifiers.
//
// TODO: Apply BaseURLs
Expand All @@ -419,39 +441,51 @@ func (r *RepresentationType) GetInit() (string, error) {
if a == nil {
return "", ErrParentNotSet
}
var initialization string
if a.SegmentTemplate != nil {
initialization = a.SegmentTemplate.Initialization
}
if r.SegmentTemplate != nil {
initialization = r.SegmentTemplate.Initialization
st := r.GetSegmentTemplate()
if st == nil {
return "", ErrSegmentTemplateNotSet
}
initialization := st.Initialization
initialization = strings.ReplaceAll(initialization, "$RepresentationID$", r.Id)
initialization = strings.ReplaceAll(initialization, "$Bandwidth$", strconv.Itoa(int(r.Bandwidth)))
return initialization, nil
}

// GetRepMedia returns the representaion's media path with replaced ID and bandwidth identifiers.
// GetRepMedia returns the representation's media path with replaced ID and bandwidth identifiers.
//
// TODO: Apply BaseURLs.
func (r *RepresentationType) GetMedia() (string, error) {
a := r.parent
if a == nil || r == nil {
return "", ErrParentNotSet
}
var media string
if a.SegmentTemplate != nil {
media = a.SegmentTemplate.Media
}
if r.SegmentTemplate != nil {
media = r.SegmentTemplate.Media
st := r.GetSegmentTemplate()
if st == nil {
return "", ErrSegmentTemplateNotSet
}
media := st.Media
media = strings.ReplaceAll(media, "$RepresentationID$", r.Id)
media = strings.ReplaceAll(media, "$Bandwidth$", strconv.Itoa(int(r.Bandwidth)))

return media, nil
}

// GetMimeType returns the representation's or its parent's mime type.
func (r *RepresentationType) GetMimeType() string {
if r.MimeType == "" {
return r.parent.GetMimeType()
}
return r.MimeType
}

// GetContentProtections returns the representation's or its parent's content protections.
func (r *RepresentationType) GetContentProtections() []*ContentProtectionType {
if len(r.ContentProtections) == 0 {
return r.parent.GetContentProtections()
}
return r.ContentProtections
}

// ContentProtectionType is Content Protection.
type ContentProtectionType struct {
XMLName xml.Name `xml:"ContentProtection"`
Expand Down Expand Up @@ -781,7 +815,7 @@ type StringNoWhitespaceType string
// VideoScanType is enumeration "progressive", "interlaced", "unknown".
type VideoScanType string

// ProducerReferenceTimeTypeType is enumaration "encoder", "captured", "application".
// ProducerReferenceTimeTypeType is enumeration "encoder", "captured", "application".
type ProducerReferenceTimeTypeType string

// PreselectionOrderType is enumeration "undefined", "time-ordered", "fully-ordered".
Expand Down

0 comments on commit 7ebfce3

Please sign in to comment.