mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
update mediacommon
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user