forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder_latm.go
55 lines (44 loc) · 1.25 KB
/
decoder_latm.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
package rtpmpeg4audio
import (
"fmt"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio"
"github.com/pion/rtp"
)
func (d *Decoder) decodeLATM(pkt *rtp.Packet) ([][]byte, error) {
var au []byte
buf := pkt.Payload
if len(d.fragments) == 0 {
pl, n, err := payloadLengthInfoDecode(buf)
if err != nil {
return nil, err
}
buf = buf[n:]
bl := len(buf)
if pl <= bl {
au = buf[:pl]
// there could be other data, due to otherDataPresent. Ignore it.
} else {
if pl > mpeg4audio.MaxAccessUnitSize {
d.fragments = d.fragments[:0] // discard pending fragments
return nil, fmt.Errorf("access unit size (%d) is too big, maximum is %d",
pl, mpeg4audio.MaxAccessUnitSize)
}
d.fragments = append(d.fragments, buf)
d.fragmentsSize = pl
d.fragmentsExpected = pl - bl
return nil, ErrMorePacketsNeeded
}
} else {
bl := len(buf)
if d.fragmentsExpected > bl {
d.fragments = append(d.fragments, buf)
d.fragmentsExpected -= bl
return nil, ErrMorePacketsNeeded
}
d.fragments = append(d.fragments, buf[:d.fragmentsExpected])
// there could be other data, due to otherDataPresent. Ignore it.
au = joinFragments(d.fragments, d.fragmentsSize)
d.fragments = d.fragments[:0]
}
return [][]byte{au}, nil
}