-
Notifications
You must be signed in to change notification settings - Fork 84
/
btrt.go
76 lines (66 loc) · 1.7 KB
/
btrt.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
package mp4
import (
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// BtrtBox - BitRateBox - ISO/IEC 14496-12 Section 8.5.2.2
type BtrtBox struct {
BufferSizeDB uint32
MaxBitrate uint32
AvgBitrate uint32
}
// DecodeBtrt - box-specific decode
func DecodeBtrt(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 DecodeBtrtSR(hdr, startPos, sr)
}
// DecodeBtrtSR - box-specific decode
func DecodeBtrtSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
b := &BtrtBox{
BufferSizeDB: sr.ReadUint32(),
MaxBitrate: sr.ReadUint32(),
AvgBitrate: sr.ReadUint32(),
}
return b, sr.AccError()
}
// Type - return box type
func (b *BtrtBox) Type() string {
return "btrt"
}
// Size - return calculated size
func (b *BtrtBox) Size() uint64 {
return 20
}
// Encode - write box to w
func (b *BtrtBox) 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 *BtrtBox) EncodeSW(sw bits.SliceWriter) error {
err := EncodeHeaderSW(b, sw)
if err != nil {
return err
}
sw.WriteUint32(b.BufferSizeDB)
sw.WriteUint32(b.MaxBitrate)
sw.WriteUint32(b.AvgBitrate)
return sw.AccError()
}
// Info - write box-specific information
func (b *BtrtBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
bd := newInfoDumper(w, indent, b, -1, 0)
bd.write(" - bufferSizeDB: %d", b.BufferSizeDB)
bd.write(" - maxBitrate: %d", b.MaxBitrate)
bd.write(" - AvgBitrate: %d", b.AvgBitrate)
return bd.err
}