Skip to content

Commit

Permalink
feat: improved prft
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Sep 27, 2024
1 parent 63e41f5 commit 3c403c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- CreatePrftBox now takes flags parameter
- PrftBox Info output

### Added

- NTP64 struct with methods to convert to time.Time
- Constants for PrftBox flags

### Fixed

- Allow missing optional DecoderSpecificInfo
Expand Down
31 changes: 29 additions & 2 deletions mp4/prft.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import (
"github.com/Eyevinn/mp4ff/bits"
)

const (
PrftTimeEncoderInput = 0
PrftTimeEncoderOutput = 1
PrftTimeMoofFinalized = 2
PrftTimeMoofWritten = 4
PrftTimeArbitraryConsitent = 8
PrftTimeCaptured = 24
)

var PrftFlagsInterpretation = map[uint32]string{
PrftTimeEncoderInput: "time_encoder_input",
PrftTimeEncoderOutput: "time_encoder_output",
PrftTimeMoofFinalized: "time_moof_finalized",
PrftTimeMoofWritten: "time_moof_written",
PrftTimeArbitraryConsitent: "time_arbitrary_consistent",
PrftTimeCaptured: "time_captured",
}

// PrftBox - Producer Reference Box (prft)
//
// Contained in File before moof box
Expand All @@ -18,10 +36,10 @@ type PrftBox struct {
}

// CreatePrftBox creates a new PrftBox.
func CreatePrftBox(version byte, refTrackID uint32, ntp NTP64, mediatime uint64) *PrftBox {
func CreatePrftBox(version byte, flags, refTrackID uint32, ntp NTP64, mediatime uint64) *PrftBox {
return &PrftBox{
Version: version,
Flags: 0,
Flags: flags,
ReferenceTrackID: refTrackID,
NTPTimestamp: ntp,
MediaTime: mediatime,
Expand Down Expand Up @@ -105,7 +123,16 @@ func (b *PrftBox) EncodeSW(sw bits.SliceWriter) error {
func (b *PrftBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
bd := newInfoDumper(w, indent, b, int(b.Version), b.Flags)
bd.write(" - referenceTrackID: %d", b.ReferenceTrackID)
bd.write(" - type: %s", b.InterpretFlags())
bd.write(" - ntpTimestamp: %s (%d)", b.NTPTimestamp, b.NTPTimestamp)
bd.write(" - mediaTime: %d", b.MediaTime)
return bd.err
}

// InterpretFlags - return string representation of flags.
func (b *PrftBox) InterpretFlags() string {
if interpretation, ok := PrftFlagsInterpretation[b.Flags]; ok {
return interpretation
}
return "unknown"
}
4 changes: 2 additions & 2 deletions mp4/prft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

func TestPrft(t *testing.T) {
prfts := []*PrftBox{
CreatePrftBox(0, 1, 8998, 98),
CreatePrftBox(1, 2, 8998, 98),
CreatePrftBox(0, PrftTimeCaptured, 1, 8998, 98),
CreatePrftBox(1, PrftTimeEncoderOutput, 2, 8998, 98),
}
for _, prft := range prfts {
boxDiffAfterEncodeAndDecode(t, prft)
Expand Down

0 comments on commit 3c403c5

Please sign in to comment.