mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-04 07:16:43 +08:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package formatprocessor
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
|
"github.com/pion/rtp"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/unit"
|
|
)
|
|
|
|
type formatProcessorGeneric struct {
|
|
UDPMaxPayloadSize int
|
|
Format format.Format
|
|
GenerateRTPPackets bool
|
|
}
|
|
|
|
func (t *formatProcessorGeneric) initialize() error {
|
|
if t.GenerateRTPPackets {
|
|
return fmt.Errorf("we don't know how to generate RTP packets of format %T", t.Format)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (t *formatProcessorGeneric) ProcessUnit(_ unit.Unit) error {
|
|
return fmt.Errorf("using a generic unit without RTP is not supported")
|
|
}
|
|
|
|
func (t *formatProcessorGeneric) ProcessRTPPacket(
|
|
pkt *rtp.Packet,
|
|
ntp time.Time,
|
|
pts int64,
|
|
_ bool,
|
|
) (unit.Unit, error) {
|
|
u := &unit.Generic{
|
|
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)
|
|
}
|
|
|
|
return u, nil
|
|
}
|