forked from godeep/mp4
-
Notifications
You must be signed in to change notification settings - Fork 6
/
stsd.go
52 lines (46 loc) · 964 Bytes
/
stsd.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
package mp4
import (
"io"
"io/ioutil"
)
// Sample Description Box (stsd - manatory)
//
// Contained in : Sample Table box (stbl)
//
// Status: not decoded
//
// This box contains information that describes how the data can be decoded.
type StsdBox struct {
Version byte
Flags [3]byte
notDecoded []byte
}
func DecodeStsd(r io.Reader) (Box, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return &StsdBox{
Version: data[0],
Flags: [3]byte{data[1], data[2], data[3]},
notDecoded: data[4:],
}, nil
}
func (b *StsdBox) Type() string {
return "stsd"
}
func (b *StsdBox) Size() int {
return BoxHeaderSize + 4 + len(b.notDecoded)
}
func (b *StsdBox) Encode(w io.Writer) error {
err := EncodeHeader(b, w)
if err != nil {
return err
}
buf := makebuf(b)
buf[0] = b.Version
buf[1], buf[2], buf[3] = b.Flags[0], b.Flags[1], b.Flags[2]
copy(buf[4:], b.notDecoded)
_, err = w.Write(buf)
return err
}