-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctts.go
81 lines (69 loc) · 1.92 KB
/
ctts.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package bmff
import (
"encoding/binary"
"log"
)
// CompositionOffset provides the offset between decoding time and composition time.
type CompositionOffset struct {
*fullbox
Entries []CompositionOffsetEntry
}
// CompositionOffsetEntry represents a single entry
type CompositionOffsetEntry interface {
Samples() uint32
Offset() int32
}
// CompositionOffsetEntryV0 represents a V0 entry, offset is unsigned
type CompositionOffsetEntryV0 struct {
sampleCount uint32
sampleOffset uint32
}
// Samples returns the number of samples
func (e CompositionOffsetEntryV0) Samples() uint32 {
return e.sampleCount
}
// Offset returns the offset
func (e CompositionOffsetEntryV0) Offset() int32 {
return int32(e.sampleOffset)
}
// CompositionOffsetEntryV1 represents a V1 entry, offset is signed
type CompositionOffsetEntryV1 struct {
sampleCount uint32
sampleOffset int32
}
// Samples returns the number of samples
func (e CompositionOffsetEntryV1) Samples() uint32 {
return e.sampleCount
}
// Offset returns the offset
func (e CompositionOffsetEntryV1) Offset() int32 {
return e.sampleOffset
}
func (b *CompositionOffset) parse() error {
entryCount := binary.BigEndian.Uint32(b.raw[0:4])
offset := 4
b.Entries = make([]CompositionOffsetEntry, 0, entryCount)
switch b.version {
case 0:
for i := 0; uint32(i) < entryCount; i++ {
entry := CompositionOffsetEntryV0{
sampleCount: binary.BigEndian.Uint32(b.raw[offset : offset+4]),
sampleOffset: binary.BigEndian.Uint32(b.raw[offset+4 : offset+8]),
}
b.Entries = append(b.Entries, entry)
offset += 8
}
case 1:
for i := 0; uint32(i) < entryCount; i++ {
entry := CompositionOffsetEntryV1{
sampleCount: binary.BigEndian.Uint32(b.raw[offset : offset+4]),
sampleOffset: int32(binary.BigEndian.Uint32(b.raw[offset+4 : offset+8])),
}
b.Entries = append(b.Entries, entry)
}
default:
log.Fatal("unknown ctts version: ", b.version)
}
b.raw = nil
return nil
}