-
Notifications
You must be signed in to change notification settings - Fork 84
/
frma.go
69 lines (59 loc) · 1.54 KB
/
frma.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
package mp4
import (
"fmt"
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// FrmaBox - Original Format Box
type FrmaBox struct {
DataFormat string // uint32 - original box type
}
// DecodeFrma - box-specific decode
func DecodeFrma(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) {
data, err := readBoxBody(r, hdr)
if err != nil {
return nil, err
}
sr := bits.NewFixedSliceReader(data)
return DecodeFrmaSR(hdr, startPos, sr)
}
// DecodeFrmaSR - box-specific decode
func DecodeFrmaSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
if hdr.payloadLen() != 4 {
return nil, fmt.Errorf("frma content length is not 4")
}
return &FrmaBox{DataFormat: string(sr.ReadFixedLengthString(4))}, sr.AccError()
}
// Type - return box type
func (b *FrmaBox) Type() string {
return "frma"
}
// Size - return calculated size
func (b *FrmaBox) Size() uint64 {
return 12
}
// Encode - write box to w
func (b *FrmaBox) 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 *FrmaBox) EncodeSW(sw bits.SliceWriter) error {
err := EncodeHeaderSW(b, sw)
if err != nil {
return err
}
sw.WriteString(b.DataFormat, false)
return sw.AccError()
}
// Info - write box info to w
func (b *FrmaBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) (err error) {
bd := newInfoDumper(w, indent, b, -1, 0)
bd.write(" - dataFormat: %s", b.DataFormat)
return bd.err
}