Skip to content

Commit

Permalink
feat: extension of CreateHdlr
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 10, 2024
1 parent c5251fd commit 94f55d5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CreatePrftBox now takes flags parameter
- PrftBox Info output
- Removed ReplaceChild method of StsdBox
- CreateHdlr name for timed metadata

### Added

- NTP64 struct with methods to convert to time.Time
- Constants for PrftBox flags
- Unittest to all commands and examples


### Fixed

- Allow missing optional DecoderSpecificInfo
Expand Down
11 changes: 6 additions & 5 deletions mp4/hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (
// Contained in: Media Box (mdia) or Meta Box (meta)
//
// This box describes the type of data contained in the trak.
// HandlerType can be : "vide" (video track), "soun" (audio track), "subt" (subtitle track)
// Other types are: "hint" (hint track), "meta" (timed Metadata track), "auxv" (auxiliary video track).
// clcp (Closed Captions (QuickTime))
// Most common hnadler types are: "vide" (video track), "soun" (audio track), "subt" (subtitle track),
// "text" (text track). "meta" (timed Metadata track), clcp (Closed Captions (QuickTime))
type HdlrBox struct {
Version byte
Flags uint32
Expand All @@ -40,16 +39,18 @@ func CreateHdlr(mediaOrHdlrType string) (*HdlrBox, error) {
case "text", "wvtt":
hdlr.HandlerType = "text"
hdlr.Name = "mp4ff text handler"
case "meta":
hdlr.HandlerType = "meta"
hdlr.Name = "mp4ff timed metadata handler"
case "clcp":
hdlr.HandlerType = "subt"
hdlr.Name = "mp4ff closed captions handler"
default:
if len(mediaOrHdlrType) != 4 {
return nil, fmt.Errorf("unknown media or hdlr type %s", mediaOrHdlrType)
return nil, fmt.Errorf("handler type is not four characters: %s", mediaOrHdlrType)
}
hdlr.HandlerType = mediaOrHdlrType
hdlr.Name = fmt.Sprintf("mp4ff %s handler", mediaOrHdlrType)

}
return hdlr, nil
}
Expand Down
48 changes: 38 additions & 10 deletions mp4/hdlr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,47 @@ import (
)

func TestHdlr(t *testing.T) {
mediaTypes := []string{"video", "audio", "subtitle"}

for _, m := range mediaTypes {
hdlr, err := CreateHdlr(m)
assertNoError(t, err)
boxDiffAfterEncodeAndDecode(t, hdlr)
cases := []struct {
mediaType string
handlerType string
handlerName string
expectedError string
}{
{"video", "vide", "mp4ff video handler", ""},
{"vide", "vide", "mp4ff video handler", ""},
{"audio", "soun", "mp4ff audio handler", ""},
{"soun", "soun", "mp4ff audio handler", ""},
{"subtitle", "subt", "mp4ff subtitle handler", ""},
{"text", "text", "mp4ff text handler", ""},
{"wvtt", "text", "mp4ff text handler", ""},
{"meta", "meta", "mp4ff timed metadata handler", ""},
{"clcp", "subt", "mp4ff closed captions handler", ""},
{"roses", "", "", "handler type is not four characters: roses"},
{"auxv", "auxv", "mp4ff auxv handler", ""},
}

for _, m := range mediaTypes {
hdlr, err := CreateHdlr(m)
hdlr.LacksNullTermination = true
assertNoError(t, err)
boxDiffAfterEncodeAndDecode(t, hdlr)
for _, c := range cases {
t.Run(c.mediaType, func(t *testing.T) {
hdlr, err := CreateHdlr(c.mediaType)
if c.expectedError != "" {
if err == nil {
t.Errorf("Expected error %s, but got nil", c.expectedError)
} else if err.Error() != c.expectedError {
t.Errorf("Expected error %s, but got %s", c.expectedError, err.Error())
}
return
}
if hdlr.HandlerType != c.handlerType {
t.Errorf("Expected handler type %s, but got %s", c.handlerType, hdlr.HandlerType)
}
if hdlr.Name != c.handlerName {
t.Errorf("Expected handler name %s, but got %s", c.handlerName, hdlr.Name)
}
boxDiffAfterEncodeAndDecode(t, hdlr)
hdlr.LacksNullTermination = true
boxDiffAfterEncodeAndDecode(t, hdlr)
})
}
}

Expand Down

0 comments on commit 94f55d5

Please sign in to comment.