Skip to content

Commit

Permalink
Merge pull request #154 from Dash-Industry-Forum/fix-missing-contenttype
Browse files Browse the repository at this point in the history
fix: derive and set contentType from mimeType if absent
  • Loading branch information
tobbee committed Jan 30, 2024
2 parents 166ec0d + 0cde247 commit a6fba5f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Make HTTP OPTIONS method work for all URLs
- Make --playurl work for general paths

### Added

- Support for DASH-IF Enhanced Clear Key Content Protection (ECCP)
- On the fly encryption for ECCP using cbcs or cenc scheme

### Fixed

- Make HTTP OPTIONS method work for all URLs
- Make --playurl work for general paths
- Derive and insert contentType if missing

## [1.1.1] - 2024-01-19

### Fixed
Expand Down
21 changes: 21 additions & 0 deletions cmd/livesim2/app/livempd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package app

import (
"fmt"
"log/slog"
"math"
"strings"

Expand Down Expand Up @@ -116,6 +117,8 @@ func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, nowMS int) (*m.MPD,
period.BaseURLs = append(period.BaseURLs, b)
}

fillContentTypes(a.AssetPath, period)

adaptationSets := orderAdaptationSetsByContentType(period.AdaptationSets)
var refSegEntries segEntries
for i, as := range adaptationSets {
Expand Down Expand Up @@ -693,3 +696,21 @@ func orderAdaptationSetsByContentType(aSets []*m.AdaptationSetType) []*m.Adaptat

return outASets
}

// fillContentTypes fills contentType if not set based on mimeType
func fillContentTypes(assetPath string, period *m.Period) {
for _, as := range period.AdaptationSets {
if as.ContentType == "" {
switch as.MimeType {
case "video/mp4":
as.ContentType = "video"
case "audio/mp4":
as.ContentType = "audio"
case "application/mp4":
as.ContentType = "text"
default:
slog.Warn("no contentType and unknown mimeType", "asset", assetPath, "mimeType", as.MimeType)
}
}
}
}
19 changes: 19 additions & 0 deletions cmd/livesim2/app/livempd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

"github.com/Eyevinn/dash-mpd/mpd"
m "github.com/Eyevinn/dash-mpd/mpd"
"github.com/Eyevinn/dash-mpd/xml"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -933,3 +934,21 @@ func TestFractionalFramerateMPDs(t *testing.T) {
}
}
}

func TestFillContentTypes(t *testing.T) {
p := &m.Period{
AdaptationSets: []*m.AdaptationSetType{
{Id: Ptr(uint32(1)), RepresentationBaseType: m.RepresentationBaseType{MimeType: "video/mp4"}},
{Id: Ptr(uint32(2)), RepresentationBaseType: m.RepresentationBaseType{MimeType: "audio/mp4"}},
{Id: Ptr(uint32(2)), RepresentationBaseType: m.RepresentationBaseType{MimeType: "application/mp4"}},
{Id: Ptr(uint32(4)), ContentType: "audio"},
{Id: Ptr(uint32(4))},
},
}
fillContentTypes("theAsset", p)
assert.Equal(t, mpd.RFC6838ContentTypeType("video"), p.AdaptationSets[0].ContentType)
assert.Equal(t, mpd.RFC6838ContentTypeType("audio"), p.AdaptationSets[1].ContentType)
assert.Equal(t, mpd.RFC6838ContentTypeType("text"), p.AdaptationSets[2].ContentType)
assert.Equal(t, mpd.RFC6838ContentTypeType("audio"), p.AdaptationSets[3].ContentType)
assert.Equal(t, mpd.RFC6838ContentTypeType(""), p.AdaptationSets[4].ContentType)
}

0 comments on commit a6fba5f

Please sign in to comment.