@@ -50,13 +50,16 @@ var AC3BitrateCodesKbps = []uint16{
50
50
}
51
51
52
52
// Dac3Box - AC3SpecificBox from ETSI TS 102 366 V1.4.1 F.4 (2017)
53
+ // Extra b
53
54
type Dac3Box struct {
54
- FSCod byte
55
- BSID byte
56
- BSMod byte
57
- ACMod byte
58
- LFEOn byte
59
- BitRateCode byte
55
+ FSCod byte
56
+ BSID byte
57
+ BSMod byte
58
+ ACMod byte
59
+ LFEOn byte
60
+ BitRateCode byte
61
+ Reserved byte
62
+ InitialZeroes byte // Should be zero
60
63
}
61
64
62
65
// DecodeDac3 - box-specific decode
@@ -78,20 +81,25 @@ func DecodeDac3SR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, err
78
81
}
79
82
80
83
func decodeDac3FromData (data []byte ) (Box , error ) {
81
- if len (data ) != 3 {
82
- return nil , fmt .Errorf ("not 3 bytes payload in dac3 box" )
84
+ b := Dac3Box {}
85
+ if len (data ) > 3 {
86
+ b .InitialZeroes = byte (len (data ) - 3 )
83
87
}
84
88
buf := bytes .NewBuffer (data )
85
89
br := bits .NewReader (buf )
86
- b := Dac3Box {}
90
+ for i := 0 ; i < int (b .InitialZeroes ); i ++ {
91
+ if zero := br .Read (8 ); zero != 0 {
92
+ return nil , fmt .Errorf ("dac3 box, extra initial bytes are not zero" )
93
+ }
94
+ }
87
95
b .FSCod = byte (br .Read (2 ))
88
96
b .BSID = byte (br .Read (5 ))
89
97
b .BSMod = byte (br .Read (3 ))
90
98
b .ACMod = byte (br .Read (3 ))
91
99
b .LFEOn = byte (br .Read (1 ))
92
100
b .BitRateCode = byte (br .Read (5 ))
93
101
// 5 bits reserved follows
94
- _ = br .Read (5 )
102
+ b . Reserved = byte ( br .Read (5 ) )
95
103
return & b , nil
96
104
}
97
105
@@ -102,7 +110,7 @@ func (b *Dac3Box) Type() string {
102
110
103
111
// Size - calculated size of box
104
112
func (b * Dac3Box ) Size () uint64 {
105
- return uint64 (boxHeaderSize + 3 )
113
+ return uint64 (boxHeaderSize + 3 + uint ( b . InitialZeroes ) )
106
114
}
107
115
108
116
// Encode - write box to w
@@ -122,13 +130,16 @@ func (b *Dac3Box) EncodeSW(sw bits.SliceWriter) error {
122
130
if err != nil {
123
131
return err
124
132
}
133
+ for i := 0 ; i < int (b .InitialZeroes ); i ++ {
134
+ sw .WriteBits (0 , 8 )
135
+ }
125
136
sw .WriteBits (uint (b .FSCod ), 2 )
126
137
sw .WriteBits (uint (b .BSID ), 5 )
127
138
sw .WriteBits (uint (b .BSMod ), 3 )
128
139
sw .WriteBits (uint (b .ACMod ), 3 )
129
140
sw .WriteBits (uint (b .LFEOn ), 1 )
130
141
sw .WriteBits (uint (b .BitRateCode ), 5 )
131
- sw .WriteBits (0 , 5 ) // 5-bits padding
142
+ sw .WriteBits (uint ( b . Reserved ) , 5 ) // 5-bits reserved
132
143
return sw .AccError ()
133
144
}
134
145
@@ -154,6 +165,12 @@ func (b *Dac3Box) Info(w io.Writer, specificBoxLevels, indent, indentStep string
154
165
bd .write (" - bitRateCode=%d => bitrate=%dkbps" , b .BitRateCode , AC3BitrateCodesKbps [b .BitRateCode ])
155
166
nrChannels , chanmap := b .ChannelInfo ()
156
167
bd .write (" - nrChannels=%d, chanmap=%04x" , nrChannels , chanmap )
168
+ if b .Reserved != 0 {
169
+ bd .write (" - reserved=%d" , b .Reserved )
170
+ }
171
+ if b .InitialZeroes > 0 {
172
+ bd .write (" - weird initial zero bytes=%d" , b .InitialZeroes )
173
+ }
157
174
return bd .err
158
175
}
159
176
0 commit comments