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

@@ -37,7 +37,6 @@ func newMPEGTSMuxer(sps []byte, pps []byte) (*mpegtsMuxer, error) {
b := bufio.NewWriter(f)
track := &mpegts.Track{
PID: 256,
Codec: &mpegts.CodecH264{},
}

View File

@@ -32,7 +32,6 @@ func newMPEGTSMuxer(config *mpeg4audio.Config) (*mpegtsMuxer, error) {
b := bufio.NewWriter(f)
track := &mpegts.Track{
PID: 256,
Codec: &mpegts.CodecMPEG4Audio{
Config: *config,
},

View File

@@ -37,7 +37,6 @@ func newMPEGTSMuxer(sps []byte, pps []byte) (*mpegtsMuxer, error) {
b := bufio.NewWriter(f)
track := &mpegts.Track{
PID: 256,
Codec: &mpegts.CodecH264{},
}

4
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v3
go 1.18
require (
github.com/bluenviron/mediacommon v0.7.1-0.20230730144331-10b74a4f6eda
github.com/bluenviron/mediacommon v0.7.1-0.20230805114828-bee33f3b286d
github.com/google/uuid v1.3.0
github.com/pion/rtcp v1.2.10
github.com/pion/rtp v1.8.1
@@ -14,7 +14,7 @@ require (
require (
github.com/asticode/go-astikit v0.30.0 // indirect
github.com/asticode/go-astits v1.11.1-0.20230727094110-0df190a2dd87 // indirect
github.com/asticode/go-astits v1.12.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect

8
go.sum
View File

@@ -1,9 +1,9 @@
github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflxkRsZA=
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.11.1-0.20230727094110-0df190a2dd87 h1:SCAqalLhgKGDghGz03yYVWr8TavHluP/i7IwshKU9yA=
github.com/asticode/go-astits v1.11.1-0.20230727094110-0df190a2dd87/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/bluenviron/mediacommon v0.7.1-0.20230730144331-10b74a4f6eda h1:+ungCWRNDjsy/CVL1l/UjAj4vYL4+NIJQoJJWbR3Xw8=
github.com/bluenviron/mediacommon v0.7.1-0.20230730144331-10b74a4f6eda/go.mod h1:tfk0qGPhqnOxVCrElu8ct3LKQn6Cj4Tpu3zbbJBTKj4=
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.20230805114828-bee33f3b286d h1:ye0ze/XtVq23NwgxV/PWcjtagcZXTKZq+V6ZBT0HoTY=
github.com/bluenviron/mediacommon v0.7.1-0.20230805114828-bee33f3b286d/go.mod h1:8Y0rvMJDUCgqDegYrUxG1rbumB6DV0TZ98Rw9mowIrA=
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=

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
}

View File

@@ -42,8 +42,9 @@ type Decoder struct {
fragments [][]byte
// for DecodeUntilMarker()
frameBuffer [][]byte
frameBufferLen int
frameBuffer [][]byte
frameBufferLen int
frameBufferSize int
}
// Init initializes the decoder.
@@ -132,9 +133,9 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
}
d.fragmentsSize += len(pkt.Payload[3:])
if d.fragmentsSize > h265.MaxNALUSize {
if d.fragmentsSize > h265.MaxAccessUnitSize {
d.fragments = d.fragments[:0]
return nil, 0, fmt.Errorf("NALU size (%d) is too big, maximum is %d", d.fragmentsSize, h265.MaxNALUSize)
return nil, 0, fmt.Errorf("NALU size (%d) is too big, maximum is %d", d.fragmentsSize, h265.MaxAccessUnitSize)
}
d.fragments = append(d.fragments, pkt.Payload[3:])
@@ -173,12 +174,28 @@ func (d *Decoder) DecodeUntilMarker(pkt *rtp.Packet) ([][]byte, time.Duration, e
if (d.frameBufferLen + l) > h265.MaxNALUsPerAccessUnit {
d.frameBuffer = nil
d.frameBufferLen = 0
d.frameBufferSize = 0
return nil, 0, fmt.Errorf("NALU count exceeds maximum allowed (%d)",
h265.MaxNALUsPerAccessUnit)
}
addSize := 0
for _, nalu := range nalus {
addSize += len(nalu)
}
if (d.frameBufferSize + addSize) > h265.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, h265.MaxAccessUnitSize)
}
d.frameBuffer = append(d.frameBuffer, nalus...)
d.frameBufferLen += l
d.frameBufferSize += addSize
if !pkt.Marker {
return nil, 0, ErrMorePacketsNeeded
@@ -189,6 +206,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
}

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg2audio"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg1audio"
"github.com/pion/rtp"
"github.com/bluenviron/gortsplib/v3/pkg/rtptime"
@@ -72,7 +72,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
buf := pkt.Payload[4:]
for {
var h mpeg2audio.FrameHeader
var h mpeg1audio.FrameHeader
err := h.Unmarshal(buf)
if err != nil {
return nil, 0, err

View File

@@ -4,7 +4,7 @@ import (
"crypto/rand"
"time"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg2audio"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg1audio"
"github.com/pion/rtp"
"github.com/bluenviron/gortsplib/v3/pkg/rtptime"
@@ -105,7 +105,7 @@ func (e *Encoder) Encode(frames [][]byte, pts time.Duration) ([]*rtp.Packet, err
rets = append(rets, pkts...)
for _, frame := range batch {
var h mpeg2audio.FrameHeader
var h mpeg1audio.FrameHeader
err := h.Unmarshal(frame)
if err != nil {
return nil, err

View File

@@ -124,7 +124,8 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
d.fragmentsSize += int(dataLens[0])
if d.fragmentsSize > mpeg4audio.MaxAccessUnitSize {
d.fragments = d.fragments[:0] // discard pending fragments
return nil, 0, fmt.Errorf("AU size (%d) is too big, maximum is %d", d.fragmentsSize, mpeg4audio.MaxAccessUnitSize)
return nil, 0, fmt.Errorf("access unit size (%d) is too big, maximum is %d",
d.fragmentsSize, mpeg4audio.MaxAccessUnitSize)
}
d.fragments = append(d.fragments, payload[:dataLens[0]])

View File

@@ -66,7 +66,8 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
} else {
if pl > mpeg4audio.MaxAccessUnitSize {
d.fragments = d.fragments[:0] // discard pending fragments
return nil, 0, fmt.Errorf("AU size (%d) is too big, maximum is %d", pl, mpeg4audio.MaxAccessUnitSize)
return nil, 0, fmt.Errorf("access unit size (%d) is too big, maximum is %d",
pl, mpeg4audio.MaxAccessUnitSize)
}
d.fragments = append(d.fragments, buf)