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

fix: derive and set contentType from mimeType if absent #154

Merged
merged 1 commit into from
Jan 30, 2024
Merged
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
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)
}
Loading