mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
move MaxNALUSize / MaxAccessUnitSize into h264 / aac
This commit is contained in:
@@ -2,6 +2,6 @@
|
|||||||
package aac
|
package aac
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// i've never seen a 5kbit AU, but anyway....
|
// MaxAccessUnitSize is the maximum size of an Access Unit (AU).
|
||||||
maxAUSize = 5 * 1024
|
MaxAccessUnitSize = 5 * 1024
|
||||||
)
|
)
|
||||||
|
@@ -68,8 +68,8 @@ func DecodeADTS(buf []byte) ([]*ADTSPacket, error) {
|
|||||||
frameLen := int(((uint16(buf[pos+3])&0x03)<<11)|
|
frameLen := int(((uint16(buf[pos+3])&0x03)<<11)|
|
||||||
(uint16(buf[pos+4])<<3)|
|
(uint16(buf[pos+4])<<3)|
|
||||||
((uint16(buf[pos+5])>>5)&0x07)) - 7
|
((uint16(buf[pos+5])>>5)&0x07)) - 7
|
||||||
if frameLen > maxAUSize {
|
if frameLen > MaxAccessUnitSize {
|
||||||
return nil, fmt.Errorf("AU size (%d) is too big (maximum is %d)", frameLen, maxAUSize)
|
return nil, fmt.Errorf("AU size (%d) is too big (maximum is %d)", frameLen, MaxAccessUnitSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
frameCount := buf[pos+6] & 0x03
|
frameCount := buf[pos+6] & 0x03
|
||||||
|
@@ -41,8 +41,8 @@ outer:
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if zeroCount == 2 || zeroCount == 3 {
|
if zeroCount == 2 || zeroCount == 3 {
|
||||||
if (delimStart - start) > maxNALUSize {
|
if (delimStart - start) > MaxNALUSize {
|
||||||
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", delimStart-start, maxNALUSize)
|
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", delimStart-start, MaxNALUSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
nalu := byts[start:delimStart]
|
nalu := byts[start:delimStart]
|
||||||
@@ -60,8 +60,8 @@ outer:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bl - start) > maxNALUSize {
|
if (bl - start) > MaxNALUSize {
|
||||||
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-start, maxNALUSize)
|
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-start, MaxNALUSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
nalu := byts[start:bl]
|
nalu := byts[start:bl]
|
||||||
|
@@ -23,8 +23,8 @@ func AVCCDecode(buf []byte) ([][]byte, error) {
|
|||||||
return nil, fmt.Errorf("invalid length")
|
return nil, fmt.Errorf("invalid length")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bl - pos) > maxNALUSize {
|
if (bl - pos) > MaxNALUSize {
|
||||||
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", 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])
|
ret = append(ret, buf[pos:pos+le])
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
package h264
|
package h264
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// MaxNALUSize is the maximum size of a NALU.
|
||||||
// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
|
// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
|
||||||
maxNALUSize = 3 * 1024 * 1024
|
MaxNALUSize = 3 * 1024 * 1024
|
||||||
)
|
)
|
||||||
|
@@ -153,10 +153,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.fragmentedSize += int(dataLens[0])
|
d.fragmentedSize += int(dataLens[0])
|
||||||
if d.fragmentedSize > maxAUSize {
|
if d.fragmentedSize > aac.MaxAccessUnitSize {
|
||||||
d.fragmentedParts = d.fragmentedParts[:0]
|
d.fragmentedParts = d.fragmentedParts[:0]
|
||||||
d.fragmentedMode = false
|
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]])
|
d.fragmentedParts = append(d.fragmentedParts, payload[:dataLens[0]])
|
||||||
|
@@ -3,7 +3,4 @@ package rtpaac
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
rtpVersion = 0x02
|
rtpVersion = 0x02
|
||||||
|
|
||||||
// i've never seen a 5kbit AU, but anyway....
|
|
||||||
maxAUSize = 5 * 1024
|
|
||||||
)
|
)
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib/pkg/h264"
|
||||||
"github.com/aler9/gortsplib/pkg/rtptimedec"
|
"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:])
|
d.fragmentedSize += len(pkt.Payload[2:])
|
||||||
if d.fragmentedSize > maxNALUSize {
|
if d.fragmentedSize > h264.MaxNALUSize {
|
||||||
d.fragmentedParts = d.fragmentedParts[:0]
|
d.fragmentedParts = d.fragmentedParts[:0]
|
||||||
d.fragmentedMode = false
|
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:])
|
d.fragmentedParts = append(d.fragmentedParts, pkt.Payload[2:])
|
||||||
|
@@ -4,7 +4,4 @@ package rtph264
|
|||||||
const (
|
const (
|
||||||
rtpVersion = 0x02
|
rtpVersion = 0x02
|
||||||
rtpClockRate = 90000 // h264 always uses 90khz
|
rtpClockRate = 90000 // h264 always uses 90khz
|
||||||
|
|
||||||
// with a 250 Mbps H264 video, the maximum NALU size is 2.2MB
|
|
||||||
maxNALUSize = 3 * 1024 * 1024
|
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user