move MaxNALUSize / MaxAccessUnitSize into h264 / aac

This commit is contained in:
aler9
2022-05-10 13:16:39 +02:00
parent 18f7fab361
commit e60809efe1
9 changed files with 17 additions and 21 deletions

View File

@@ -2,6 +2,6 @@
package aac
const (
// i've never seen a 5kbit AU, but anyway....
maxAUSize = 5 * 1024
// MaxAccessUnitSize is the maximum size of an Access Unit (AU).
MaxAccessUnitSize = 5 * 1024
)

View File

@@ -68,8 +68,8 @@ func DecodeADTS(buf []byte) ([]*ADTSPacket, error) {
frameLen := int(((uint16(buf[pos+3])&0x03)<<11)|
(uint16(buf[pos+4])<<3)|
((uint16(buf[pos+5])>>5)&0x07)) - 7
if frameLen > maxAUSize {
return nil, fmt.Errorf("AU size (%d) is too big (maximum is %d)", frameLen, maxAUSize)
if frameLen > MaxAccessUnitSize {
return nil, fmt.Errorf("AU size (%d) is too big (maximum is %d)", frameLen, MaxAccessUnitSize)
}
frameCount := buf[pos+6] & 0x03

View File

@@ -41,8 +41,8 @@ outer:
case 1:
if zeroCount == 2 || zeroCount == 3 {
if (delimStart - start) > maxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", delimStart-start, maxNALUSize)
if (delimStart - start) > MaxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", delimStart-start, MaxNALUSize)
}
nalu := byts[start:delimStart]
@@ -60,8 +60,8 @@ outer:
}
}
if (bl - start) > maxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-start, maxNALUSize)
if (bl - start) > MaxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-start, MaxNALUSize)
}
nalu := byts[start:bl]

View File

@@ -23,8 +23,8 @@ func AVCCDecode(buf []byte) ([][]byte, error) {
return nil, fmt.Errorf("invalid length")
}
if (bl - pos) > maxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-pos, maxNALUSize)
if (bl - pos) > MaxNALUSize {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-pos, MaxNALUSize)
}
ret = append(ret, buf[pos:pos+le])

View File

@@ -2,6 +2,7 @@
package h264
const (
// MaxNALUSize is the maximum size of a NALU.
// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
maxNALUSize = 3 * 1024 * 1024
MaxNALUSize = 3 * 1024 * 1024
)

View File

@@ -153,10 +153,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
}
d.fragmentedSize += int(dataLens[0])
if d.fragmentedSize > maxAUSize {
if d.fragmentedSize > aac.MaxAccessUnitSize {
d.fragmentedParts = d.fragmentedParts[:0]
d.fragmentedMode = false
return nil, 0, fmt.Errorf("AU size (%d) is too big (maximum is %d)", d.fragmentedSize, maxAUSize)
return nil, 0, fmt.Errorf("AU size (%d) is too big (maximum is %d)", d.fragmentedSize, aac.MaxAccessUnitSize)
}
d.fragmentedParts = append(d.fragmentedParts, payload[:dataLens[0]])

View File

@@ -3,7 +3,4 @@ package rtpaac
const (
rtpVersion = 0x02
// i've never seen a 5kbit AU, but anyway....
maxAUSize = 5 * 1024
)

View File

@@ -8,6 +8,7 @@ import (
"github.com/pion/rtp"
"github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/gortsplib/pkg/rtptimedec"
)
@@ -139,10 +140,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
}
d.fragmentedSize += len(pkt.Payload[2:])
if d.fragmentedSize > maxNALUSize {
if d.fragmentedSize > h264.MaxNALUSize {
d.fragmentedParts = d.fragmentedParts[:0]
d.fragmentedMode = false
return nil, 0, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", d.fragmentedSize, maxNALUSize)
return nil, 0, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", d.fragmentedSize, h264.MaxNALUSize)
}
d.fragmentedParts = append(d.fragmentedParts, pkt.Payload[2:])

View File

@@ -4,7 +4,4 @@ package rtph264
const (
rtpVersion = 0x02
rtpClockRate = 90000 // h264 always uses 90khz
// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
maxNALUSize = 3 * 1024 * 1024
)