-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathcdat.go
72 lines (62 loc) · 1.6 KB
/
cdat.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
package mp4
import (
"encoding/hex"
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// CdatBox - Closed Captioning Sample Data according to QuickTime spec:
// https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-SW87
type CdatBox struct {
Data []byte
}
// DecodeCdat - box-specific decode
func DecodeCdat(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) {
data, err := readBoxBody(r, hdr)
if err != nil {
return nil, err
}
b := &CdatBox{
Data: data,
}
return b, nil
}
// DecodeCdat - box-specific decode
func DecodeCdatSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
b := &CdatBox{
Data: sr.ReadBytes(hdr.payloadLen()),
}
return b, sr.AccError()
}
// Type - box type
func (b *CdatBox) Type() string {
return "cdat"
}
// Size - calculated size of box
func (b *CdatBox) Size() uint64 {
return uint64(boxHeaderSize + len(b.Data))
}
// Encode - write box to w
func (b *CdatBox) Encode(w io.Writer) error {
sw := bits.NewFixedSliceWriter(int(b.Size()))
err := b.EncodeSW(sw)
if err != nil {
return err
}
_, err = w.Write(sw.Bytes())
return err
}
// EncodeSW - box-specific encode to slicewriter
func (b *CdatBox) EncodeSW(sw bits.SliceWriter) error {
err := EncodeHeaderSW(b, sw)
if err != nil {
return err
}
sw.WriteBytes(b.Data)
return sw.AccError()
}
// Info - write specific box information
func (b *CdatBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
bd := newInfoDumper(w, indent, b, -1, 0)
bd.write(" - data: %s", hex.EncodeToString(b.Data))
return bd.err
}