mirror of
https://github.com/wader/fq.git
synced 2024-12-29 16:42:06 +03:00
34 lines
573 B
Go
34 lines
573 B
Go
package decode
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
// TODO: move?
|
|
// TODO: make generic replace reader? share with id3v2 unsync?
|
|
type NALUnescapeReader struct {
|
|
io.Reader
|
|
lastTwoZeros [2]bool
|
|
}
|
|
|
|
func (r NALUnescapeReader) Read(p []byte) (n int, err error) {
|
|
n, err = r.Reader.Read(p)
|
|
|
|
ni := 0
|
|
for i, b := range p[0:n] {
|
|
if r.lastTwoZeros[0] && r.lastTwoZeros[1] && b == 0x03 {
|
|
n--
|
|
r.lastTwoZeros[0] = false
|
|
r.lastTwoZeros[1] = false
|
|
continue
|
|
} else {
|
|
r.lastTwoZeros[1] = r.lastTwoZeros[0]
|
|
r.lastTwoZeros[0] = b == 0
|
|
}
|
|
p[ni] = p[i]
|
|
ni++
|
|
}
|
|
|
|
return n, err
|
|
}
|