Skip to content

Commit

Permalink
feat: GetMimeType and GetSegmentTemplatek methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 21, 2023
1 parent 334630d commit 8bb8417
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- GetContentProtections methods to AdaptationSet and Representation
- 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
49 changes: 35 additions & 14 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ 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
Expand Down Expand Up @@ -416,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 @@ -424,39 +441,43 @@ 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 {
Expand Down Expand Up @@ -794,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 8bb8417

Please sign in to comment.