diff --git a/pkg/aac/aac.go b/pkg/aac/aac.go index 2d8892aa..74eb09f2 100644 --- a/pkg/aac/aac.go +++ b/pkg/aac/aac.go @@ -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 ) diff --git a/pkg/aac/adts.go b/pkg/aac/adts.go index df89b1f2..6ff41aec 100644 --- a/pkg/aac/adts.go +++ b/pkg/aac/adts.go @@ -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 diff --git a/pkg/h264/annexb.go b/pkg/h264/annexb.go index d1f61eb2..952bb6ea 100644 --- a/pkg/h264/annexb.go +++ b/pkg/h264/annexb.go @@ -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] diff --git a/pkg/h264/avcc.go b/pkg/h264/avcc.go index a0e792a5..58cf6c7c 100644 --- a/pkg/h264/avcc.go +++ b/pkg/h264/avcc.go @@ -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]) diff --git a/pkg/h264/h264.go b/pkg/h264/h264.go index 8171a309..85d8cb74 100644 --- a/pkg/h264/h264.go +++ b/pkg/h264/h264.go @@ -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 ) diff --git a/pkg/rtpaac/decoder.go b/pkg/rtpaac/decoder.go index 9f5e3680..1d93066b 100644 --- a/pkg/rtpaac/decoder.go +++ b/pkg/rtpaac/decoder.go @@ -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]]) diff --git a/pkg/rtpaac/rtpaac.go b/pkg/rtpaac/rtpaac.go index 01d95928..a7e48e64 100644 --- a/pkg/rtpaac/rtpaac.go +++ b/pkg/rtpaac/rtpaac.go @@ -3,7 +3,4 @@ package rtpaac const ( rtpVersion = 0x02 - - // i've never seen a 5kbit AU, but anyway.... - maxAUSize = 5 * 1024 ) diff --git a/pkg/rtph264/decoder.go b/pkg/rtph264/decoder.go index db1dd69c..561654e9 100644 --- a/pkg/rtph264/decoder.go +++ b/pkg/rtph264/decoder.go @@ -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:]) diff --git a/pkg/rtph264/rtph264.go b/pkg/rtph264/rtph264.go index d0eab52c..cbf81d60 100644 --- a/pkg/rtph264/rtph264.go +++ b/pkg/rtph264/rtph264.go @@ -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 )