Skip to content

Commit

Permalink
test: more testing for timing sei messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 9, 2024
1 parent 395ec8b commit 15e1b55
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sei/sei136_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package sei

import (
"testing"

"github.com/go-test/deep"
)

func TestSei136Clock(t *testing.T) {
cl := CreateClockTS()
cl.TimeOffsetValue = 1300
cl.NFrames = 5
cl.Hours = 12
cl.Minutes = 30
cl.Seconds = 10
cl.ClockTimeStampFlag = true
cl.UnitsFieldBasedFlag = true
cl.FullTimeStampFlag = false
cl.SecondsFlag = true
cl.MinutesFlag = true
cl.HoursFlag = true
cl.DiscontinuityFlag = false
cl.CntDroppedFlag = false
cl.CountingType = 1
cl.TimeOffsetLength = 11

tc := TimeCodeSEI{}
tc.Clocks = append(tc.Clocks, cl)
tc.Clocks = append(tc.Clocks, cl)
pl := tc.Payload()
str := tc.String()
if str == "" {
t.Error("String() failed")
}
if len(pl) == 0 {
t.Error("Payload() failed")
}

seiData := SEIData{
payloadType: SEITimeCodeType,
payload: pl,
}
sei, err := DecodeTimeCodeSEI(&seiData)
if err != nil {
t.Error(err)
}
tcDec := sei.(*TimeCodeSEI)
decCl := tcDec.Clocks[0]
diff := deep.Equal(cl, decCl)
if diff != nil {
t.Error(diff)
}
}
52 changes: 52 additions & 0 deletions sei/sei1_avc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package sei

import (
"bytes"
"testing"

"github.com/Eyevinn/mp4ff/bits"
"github.com/go-test/deep"
)

func TestSE1AVCCLock(t *testing.T) {
cl := ClockTSAvc{
CtType: 0,
NuitFieldBasedFlag: false,
CountingType: 0,
NFrames: 5,
Hours: 12,
Minutes: 30,
Seconds: 10,
ClockTimeStampFlag: true,
FullTimeStampFlag: false,
SecondsFlag: true,
MinutesFlag: true,
HoursFlag: true,
DiscontinuityFlag: false,
CntDroppedFlag: false,
TimeOffsetLength: 5,
TimeOffsetValue: -15,
}
jsonBytes, err := cl.MarshalJSON()
if err != nil {
t.Error(err)
}
wantedJSON := `{"time":"12:30:10:05","offset":-15}`
if string(jsonBytes) != wantedJSON {
t.Errorf("Got %s but wanted %s", jsonBytes, wantedJSON)
}
size := cl.NrBits()
nrBytes := (size + 7) / 8
sw := bits.NewFixedSliceWriter(nrBytes)
cl.WriteToSliceWriter(sw)
if sw.AccError() != nil {
t.Error(sw.AccError())
}
sw.FlushBits()
r := bytes.NewReader(sw.Bytes())
rd := bits.NewReader(r)
decClock := DecodeClockTSAvc(rd, cl.TimeOffsetLength)
if diff := deep.Equal(cl, decClock); diff != nil {
t.Error(diff)
}
}

0 comments on commit 15e1b55

Please sign in to comment.