forked from livekit/server-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_timestamp_h264_parser_test.go
More file actions
45 lines (37 loc) · 1.03 KB
/
user_timestamp_h264_parser_test.go
File metadata and controls
45 lines (37 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package lksdk
import (
"encoding/binary"
"testing"
)
func TestParseH264SEIUserTimestamp_UUIDValidation(t *testing.T) {
const wantTS = int64(1234567890)
var tsBuf [8]byte
binary.BigEndian.PutUint64(tsBuf[:], uint64(wantTS))
buildNAL := func(uuid [16]byte) []byte {
// NAL header for SEI (nal_unit_type = 6).
nal := []byte{0x06}
// payloadType = 5 (user_data_unregistered)
// payloadSize = 24 (16-byte UUID + 8-byte timestamp)
nal = append(nal, 0x05, 0x18)
nal = append(nal, uuid[:]...)
nal = append(nal, tsBuf[:]...)
return nal
}
t.Run("accepts matching UUID", func(t *testing.T) {
gotTS, ok := parseH264SEIUserTimestamp(buildNAL(userTimestampSEIUUID))
if !ok {
t.Fatalf("expected ok=true")
}
if gotTS != wantTS {
t.Fatalf("timestamp mismatch: got %d want %d", gotTS, wantTS)
}
})
t.Run("rejects non-matching UUID", func(t *testing.T) {
badUUID := userTimestampSEIUUID
badUUID[0] ^= 0xff
_, ok := parseH264SEIUserTimestamp(buildNAL(badUUID))
if ok {
t.Fatalf("expected ok=false")
}
})
}