codec/h265: removed unnecessary allocation in handle fragmentation

This commit is contained in:
Saxon 2019-05-19 21:14:41 +09:30
parent abd41d9f01
commit 0567a81757
1 changed files with 15 additions and 10 deletions

View File

@ -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