Skip to content

Commit

Permalink
update mediacommon
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 6, 2023
1 parent 926a452 commit e1c5f0d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v3
go 1.18

require (
github.com/bluenviron/mediacommon v0.7.1-0.20230805234008-34d20294a26b
github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f
github.com/google/uuid v1.3.0
github.com/pion/rtcp v1.2.10
github.com/pion/rtp v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.12.0 h1:BiefTgVEyPgEB8nT6J+Sys/uxE4H/a04SW/aedpOpPc=
github.com/asticode/go-astits v1.12.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/bluenviron/mediacommon v0.7.1-0.20230805234008-34d20294a26b h1:/csYQQDmZyXw0CVATJSPBkwT3JYap418W7LLX7mscxw=
github.com/bluenviron/mediacommon v0.7.1-0.20230805234008-34d20294a26b/go.mod h1:LR4w8cpvzo2ZcmBwXcentvBj7ZlyF9g9xP4dDbt8uJw=
github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f h1:hVo5b6WSVT0+p43GpYv0e4cLtmpkhJp3kD6Ef83jzUM=
github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f/go.mod h1:LR4w8cpvzo2ZcmBwXcentvBj7ZlyF9g9xP4dDbt8uJw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
30 changes: 24 additions & 6 deletions pkg/formats/rtpav1/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type Decoder struct {
fragments [][]byte

// for DecodeUntilMarker()
frameBuffer [][]byte
frameBufferLen int
frameBuffer [][]byte
frameBufferLen int
frameBufferSize int
}

// Init initializes the decoder.
Expand Down Expand Up @@ -76,10 +77,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
}

d.fragmentsSize += len(av1header.OBUElements[0])
if d.fragmentsSize > av1.MaxOBUSize {
if d.fragmentsSize > av1.MaxTemporalUnitSize {
d.fragments = d.fragments[:0]
d.fragmentsSize = 0
return nil, 0, fmt.Errorf("OBU size (%d) is too big, maximum is %d", d.fragmentsSize, av1.MaxOBUSize)
return nil, 0, fmt.Errorf("OBU size (%d) is too big, maximum is %d", d.fragmentsSize, av1.MaxTemporalUnitSize)
}

d.fragments = append(d.fragments, av1header.OBUElements[0])
Expand All @@ -101,10 +102,10 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
elementCount := len(av1header.OBUElements)

d.fragmentsSize += len(av1header.OBUElements[elementCount-1])
if d.fragmentsSize > av1.MaxOBUSize {
if d.fragmentsSize > av1.MaxTemporalUnitSize {
d.fragments = d.fragments[:0]
d.fragmentsSize = 0
return nil, 0, fmt.Errorf("OBU size (%d) is too big, maximum is %d", d.fragmentsSize, av1.MaxOBUSize)
return nil, 0, fmt.Errorf("OBU size (%d) is too big, maximum is %d", d.fragmentsSize, av1.MaxTemporalUnitSize)
}

d.fragments = append(d.fragments, av1header.OBUElements[elementCount-1])
Expand Down Expand Up @@ -138,12 +139,28 @@ func (d *Decoder) DecodeUntilMarker(pkt *rtp.Packet) ([][]byte, time.Duration, e
if (d.frameBufferLen + l) > av1.MaxOBUsPerTemporalUnit {
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return nil, 0, fmt.Errorf("OBU count exceeds maximum allowed (%d)",
av1.MaxOBUsPerTemporalUnit)
}

addSize := 0

for _, obu := range obus {
addSize += len(obu)
}

if (d.frameBufferSize + addSize) > av1.MaxOBUsPerTemporalUnit {
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return nil, 0, fmt.Errorf("temporal unit size (%d) is too big, maximum is %d",
d.frameBufferSize+addSize, av1.MaxOBUsPerTemporalUnit)
}

d.frameBuffer = append(d.frameBuffer, obus...)
d.frameBufferLen += l
d.frameBufferSize += addSize

if !pkt.Marker {
return nil, 0, ErrMorePacketsNeeded
Expand All @@ -154,6 +171,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
}

0 comments on commit e1c5f0d

Please sign in to comment.