forked from godeep/mp4
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmhd.go
50 lines (44 loc) · 929 Bytes
/
smhd.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
package mp4
import (
"encoding/binary"
"io"
)
// Sound Media Header Box (smhd - mandatory for sound tracks)
//
// Contained in : Media Information Box (minf)
//
// Status: decoded
type SmhdBox struct {
Version byte
Flags [3]byte
Balance uint16 // should be int16
}
func DecodeSmhd(r io.Reader) (Box, error) {
data, err := readAllO(r)
if err != nil {
return nil, err
}
return &SmhdBox{
Version: data[0],
Flags: [3]byte{data[1], data[2], data[3]},
Balance: binary.BigEndian.Uint16(data[4:6]),
}, nil
}
func (b *SmhdBox) Type() string {
return "smhd"
}
func (b *SmhdBox) Size() int {
return BoxHeaderSize + 8
}
func (b *SmhdBox) 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]
binary.BigEndian.PutUint16(buf[4:], b.Balance)
_, err = w.Write(buf)
return err
}