mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-24 20:11:56 -08:00
update gortsplib (#2390)
This commit is contained in:
parent
e4df14a447
commit
d07ba5983e
17 changed files with 49 additions and 271 deletions
|
|
@ -11,19 +11,19 @@ import (
|
|||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
type formatProcessorMPEG4AudioGeneric struct {
|
||||
type formatProcessorMPEG4Audio struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG4Audio
|
||||
encoder *rtpmpeg4audio.Encoder
|
||||
decoder *rtpmpeg4audio.Decoder
|
||||
}
|
||||
|
||||
func newMPEG4AudioGeneric(
|
||||
func newMPEG4Audio(
|
||||
udpMaxPayloadSize int,
|
||||
forma *format.MPEG4Audio,
|
||||
generateRTPPackets bool,
|
||||
) (*formatProcessorMPEG4AudioGeneric, error) {
|
||||
t := &formatProcessorMPEG4AudioGeneric{
|
||||
) (*formatProcessorMPEG4Audio, error) {
|
||||
t := &formatProcessorMPEG4Audio{
|
||||
udpMaxPayloadSize: udpMaxPayloadSize,
|
||||
format: forma,
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ func newMPEG4AudioGeneric(
|
|||
return t, nil
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioGeneric) createEncoder() error {
|
||||
func (t *formatProcessorMPEG4Audio) createEncoder() error {
|
||||
t.encoder = &rtpmpeg4audio.Encoder{
|
||||
PayloadMaxSize: t.udpMaxPayloadSize - 12,
|
||||
PayloadType: t.format.PayloadTyp,
|
||||
|
|
@ -49,8 +49,8 @@ func (t *formatProcessorMPEG4AudioGeneric) createEncoder() error {
|
|||
return t.encoder.Init()
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioGeneric) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
||||
u := uu.(*unit.MPEG4AudioGeneric)
|
||||
func (t *formatProcessorMPEG4Audio) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
||||
u := uu.(*unit.MPEG4Audio)
|
||||
|
||||
pkts, err := t.encoder.Encode(u.AUs)
|
||||
if err != nil {
|
||||
|
|
@ -67,13 +67,13 @@ func (t *formatProcessorMPEG4AudioGeneric) ProcessUnit(uu unit.Unit) error { //n
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioGeneric) ProcessRTPPacket( //nolint:dupl
|
||||
func (t *formatProcessorMPEG4Audio) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
hasNonRTSPReaders bool,
|
||||
) (Unit, error) {
|
||||
u := &unit.MPEG4AudioGeneric{
|
||||
u := &unit.MPEG4Audio{
|
||||
Base: unit.Base{
|
||||
RTPPackets: []*rtp.Packet{pkt},
|
||||
NTP: ntp,
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
package formatprocessor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg4audiolatm"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
type formatProcessorMPEG4AudioLATM struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG4AudioLATM
|
||||
encoder *rtpmpeg4audiolatm.Encoder
|
||||
decoder *rtpmpeg4audiolatm.Decoder
|
||||
}
|
||||
|
||||
func newMPEG4AudioLATM(
|
||||
udpMaxPayloadSize int,
|
||||
forma *format.MPEG4AudioLATM,
|
||||
generateRTPPackets bool,
|
||||
) (*formatProcessorMPEG4AudioLATM, error) {
|
||||
t := &formatProcessorMPEG4AudioLATM{
|
||||
udpMaxPayloadSize: udpMaxPayloadSize,
|
||||
format: forma,
|
||||
}
|
||||
|
||||
if generateRTPPackets {
|
||||
err := t.createEncoder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioLATM) createEncoder() error {
|
||||
t.encoder = &rtpmpeg4audiolatm.Encoder{
|
||||
PayloadType: t.format.PayloadTyp,
|
||||
}
|
||||
return t.encoder.Init()
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioLATM) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
||||
u := uu.(*unit.MPEG4AudioLATM)
|
||||
|
||||
pkts, err := t.encoder.Encode(u.AU)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ts := uint32(multiplyAndDivide(u.PTS, time.Duration(t.format.ClockRate()), time.Second))
|
||||
for _, pkt := range pkts {
|
||||
pkt.Timestamp += ts
|
||||
}
|
||||
|
||||
u.RTPPackets = pkts
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *formatProcessorMPEG4AudioLATM) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
hasNonRTSPReaders bool,
|
||||
) (Unit, error) {
|
||||
u := &unit.MPEG4AudioLATM{
|
||||
Base: unit.Base{
|
||||
RTPPackets: []*rtp.Packet{pkt},
|
||||
NTP: ntp,
|
||||
PTS: pts,
|
||||
},
|
||||
}
|
||||
|
||||
// remove padding
|
||||
pkt.Header.Padding = false
|
||||
pkt.PaddingSize = 0
|
||||
|
||||
if pkt.MarshalSize() > t.udpMaxPayloadSize {
|
||||
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
|
||||
pkt.MarshalSize(), t.udpMaxPayloadSize)
|
||||
}
|
||||
|
||||
// decode from RTP
|
||||
if hasNonRTSPReaders || t.decoder != nil {
|
||||
if t.decoder == nil {
|
||||
var err error
|
||||
t.decoder, err = t.format.CreateDecoder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
au, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmpeg4audiolatm.ErrMorePacketsNeeded {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u.AU = au
|
||||
}
|
||||
|
||||
// route packet as is
|
||||
return u, nil
|
||||
}
|
||||
|
|
@ -63,11 +63,8 @@ func New(
|
|||
case *format.Opus:
|
||||
return newOpus(udpMaxPayloadSize, forma, generateRTPPackets)
|
||||
|
||||
case *format.MPEG4AudioGeneric:
|
||||
return newMPEG4AudioGeneric(udpMaxPayloadSize, forma, generateRTPPackets)
|
||||
|
||||
case *format.MPEG4AudioLATM:
|
||||
return newMPEG4AudioLATM(udpMaxPayloadSize, forma, generateRTPPackets)
|
||||
case *format.MPEG4Audio:
|
||||
return newMPEG4Audio(udpMaxPayloadSize, forma, generateRTPPackets)
|
||||
|
||||
case *format.MPEG1Audio:
|
||||
return newMPEG1Audio(udpMaxPayloadSize, forma, generateRTPPackets)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue