update mediacommon

This commit is contained in:
aler9
2023-08-05 13:51:01 +02:00
committed by Alessandro Ros
parent ebf023260f
commit 4e789ff6b9
11 changed files with 59 additions and 23 deletions

View File

@@ -44,8 +44,9 @@ type Decoder struct {
annexBMode bool
// for DecodeUntilMarker()
frameBuffer [][]byte
frameBufferLen int
frameBuffer [][]byte
frameBufferLen int
frameBufferSize int
}
// Init initializes the decoder.
@@ -102,9 +103,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
}
d.fragmentsSize += len(pkt.Payload[2:])
if d.fragmentsSize > h264.MaxNALUSize {
if d.fragmentsSize > h264.MaxAccessUnitSize {
d.fragments = d.fragments[:0]
return nil, 0, fmt.Errorf("NALU size (%d) is too big, maximum is %d", d.fragmentsSize, h264.MaxNALUSize)
return nil, 0, fmt.Errorf("NALU size (%d) is too big, maximum is %d", d.fragmentsSize, h264.MaxAccessUnitSize)
}
d.fragments = append(d.fragments, pkt.Payload[2:])
@@ -181,12 +183,28 @@ func (d *Decoder) DecodeUntilMarker(pkt *rtp.Packet) ([][]byte, time.Duration, e
if (d.frameBufferLen + l) > h264.MaxNALUsPerAccessUnit {
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return nil, 0, fmt.Errorf("NALU count exceeds maximum allowed (%d)",
h264.MaxNALUsPerAccessUnit)
}
addSize := 0
for _, nalu := range nalus {
addSize += len(nalu)
}
if (d.frameBufferSize + addSize) > h264.MaxAccessUnitSize {
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return nil, 0, fmt.Errorf("access unit size (%d) is too big, maximum is %d",
d.frameBufferSize+addSize, h264.MaxAccessUnitSize)
}
d.frameBuffer = append(d.frameBuffer, nalus...)
d.frameBufferLen += l
d.frameBufferSize += addSize
if !pkt.Marker {
return nil, 0, ErrMorePacketsNeeded
@@ -197,6 +215,7 @@ func (d *Decoder) DecodeUntilMarker(pkt *rtp.Packet) ([][]byte, time.Duration, e
// do not reuse frameBuffer to avoid race conditions
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return ret, pts, nil
}