mirror of
https://github.com/aler9/gortsplib
synced 2025-10-15 19:50:45 +08:00
add MPEG4Video.SafeParams(), MPEG4Video.SafeSetParams() (#395)
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v4
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/bluenviron/mediacommon v1.0.1
|
||||
github.com/bluenviron/mediacommon v1.0.2-0.20230901160448-b7b4863d6096
|
||||
github.com/google/uuid v1.3.1
|
||||
github.com/pion/rtcp v1.2.10
|
||||
github.com/pion/rtp v1.8.1
|
||||
|
4
go.sum
4
go.sum
@@ -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.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
|
||||
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
|
||||
github.com/bluenviron/mediacommon v1.0.1 h1:+Wiy0OmNxnIqJQ9MUcvldbTtJRmdjoxeyeSdDkSCExI=
|
||||
github.com/bluenviron/mediacommon v1.0.1/go.mod h1:/vlOVSebDwzdRtQONOKLua0fOSJg1tUDHpP+h9a0uqM=
|
||||
github.com/bluenviron/mediacommon v1.0.2-0.20230901160448-b7b4863d6096 h1:quTSEtdDapDQilHCiVeV4Un7NcWby4hVIiJAjqf+XXk=
|
||||
github.com/bluenviron/mediacommon v1.0.2-0.20230901160448-b7b4863d6096/go.mod h1:/vlOVSebDwzdRtQONOKLua0fOSJg1tUDHpP+h9a0uqM=
|
||||
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=
|
||||
|
@@ -5,7 +5,9 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4video"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg4video"
|
||||
@@ -20,6 +22,8 @@ type MPEG4VideoES struct {
|
||||
PayloadTyp uint8
|
||||
ProfileLevelID int
|
||||
Config []byte
|
||||
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (f *MPEG4VideoES) unmarshal(ctx *unmarshalContext) error {
|
||||
@@ -42,6 +46,11 @@ func (f *MPEG4VideoES) unmarshal(ctx *unmarshalContext) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid config: %v", val)
|
||||
}
|
||||
|
||||
err = mpeg4video.IsValidConfig(f.Config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid config: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +81,10 @@ func (f *MPEG4VideoES) RTPMap() string {
|
||||
func (f *MPEG4VideoES) FMTP() map[string]string {
|
||||
fmtp := map[string]string{
|
||||
"profile-level-id": strconv.FormatInt(int64(f.ProfileLevelID), 10),
|
||||
"config": strings.ToUpper(hex.EncodeToString(f.Config)),
|
||||
}
|
||||
|
||||
if f.Config != nil {
|
||||
fmtp["config"] = strings.ToUpper(hex.EncodeToString(f.Config))
|
||||
}
|
||||
|
||||
return fmtp
|
||||
@@ -108,3 +120,17 @@ func (f *MPEG4VideoES) CreateEncoder() (*rtpmpeg4video.Encoder, error) {
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// SafeSetParams sets the codec parameters.
|
||||
func (f *MPEG4VideoES) SafeSetParams(config []byte) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
f.Config = config
|
||||
}
|
||||
|
||||
// SafeParams returns the codec parameters.
|
||||
func (f *MPEG4VideoES) SafeParams() []byte {
|
||||
f.mutex.RLock()
|
||||
defer f.mutex.RUnlock()
|
||||
return f.Config
|
||||
}
|
||||
|
@@ -5,15 +5,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4video"
|
||||
)
|
||||
|
||||
// ErrMorePacketsNeeded is returned when more packets are needed.
|
||||
var ErrMorePacketsNeeded = errors.New("need more packets")
|
||||
|
||||
const (
|
||||
maxFrameSize = 1 * 1024 * 1024
|
||||
)
|
||||
|
||||
func joinFragments(fragments [][]byte, size int) []byte {
|
||||
ret := make([]byte, size)
|
||||
n := 0
|
||||
@@ -49,9 +47,9 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
||||
}
|
||||
} else {
|
||||
d.fragmentsSize += len(pkt.Payload)
|
||||
if d.fragmentsSize > maxFrameSize {
|
||||
if d.fragmentsSize > mpeg4video.MaxFrameSize {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
return nil, fmt.Errorf("frame size (%d) is too big, maximum is %d", d.fragmentsSize, maxFrameSize)
|
||||
return nil, fmt.Errorf("frame size (%d) is too big, maximum is %d", d.fragmentsSize, mpeg4video.MaxFrameSize)
|
||||
}
|
||||
|
||||
d.fragments = append(d.fragments, pkt.Payload)
|
||||
|
3
pkg/format/testdata/fuzz/FuzzUnmarshalH264/def20bf5816007f3
vendored
Normal file
3
pkg/format/testdata/fuzz/FuzzUnmarshalH264/def20bf5816007f3
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
go test fuzz v1
|
||||
string(",")
|
||||
string("0")
|
5
pkg/format/testdata/fuzz/FuzzUnmarshalH265/85fd1a8f82a0e5c4
vendored
Normal file
5
pkg/format/testdata/fuzz/FuzzUnmarshalH265/85fd1a8f82a0e5c4
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
go test fuzz v1
|
||||
string("0")
|
||||
string("\x00")
|
||||
string("")
|
||||
string("0\xa5")
|
3
pkg/format/testdata/fuzz/FuzzUnmarshalMPEG4VideoES/85649d45641911d0
vendored
Normal file
3
pkg/format/testdata/fuzz/FuzzUnmarshalMPEG4VideoES/85649d45641911d0
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
go test fuzz v1
|
||||
string("0")
|
||||
string("")
|
Reference in New Issue
Block a user