diff --git a/codec/h265/lex.go b/codec/h265/lex.go index 84d9222a..6e81b167 100644 --- a/codec/h265/lex.go +++ b/codec/h265/lex.go @@ -63,7 +63,8 @@ type Lexer struct { func NewLexer(donl bool) *Lexer { return &Lexer{ donl: donl, - buf: bytes.NewBuffer(make([]byte, 0, maxAUSize))} + buf: bytes.NewBuffer(make([]byte, 0, maxAUSize)), + } } // Lex continually reads RTP packets from the io.Reader src and lexes into @@ -150,21 +151,25 @@ func (l *Lexer) handleFragmentation(d []byte) { start := d[2]&0x80 != 0 end := d[2]&0x40 != 0 - var head []byte + old := d if start { - head = []byte{(d[0] & 0x81) | ((d[2] & 0x3f) << 1), d[1]} - } - - d = d[3:] - if l.donl { - d = d[2:] + d = d[1:] + if l.donl { + d = d[2:] + } + d[0] = (old[0] & 0x81) | ((old[2] & 0x3f) << 1) + d[1] = old[1] + } else { + d = d[3:] + if l.donl { + d = d[2:] + } } switch { case start && !end: l.frag = true - _d := append(head, d...) - l.writeWithPrefix(_d) + l.writeWithPrefix(d) case !start && end: l.frag = false fallthrough