mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-04 15:22:48 +08:00
switch to gortsplib/v4 (#2244)
This commit is contained in:
@@ -4,55 +4,75 @@ package formatprocessor
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v3/pkg/formats"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/logger"
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
// avoid an int64 overflow and preserve resolution by splitting division into two parts:
|
||||
// first add the integer part, then the decimal part.
|
||||
func multiplyAndDivide(v, m, d time.Duration) time.Duration {
|
||||
secs := v / d
|
||||
dec := v % d
|
||||
return (secs*m + dec*m/d)
|
||||
}
|
||||
|
||||
func setTimestamp(newPackets []*rtp.Packet, oldPackets []*rtp.Packet, clockRate int, pts time.Duration) {
|
||||
if oldPackets != nil { // get timestamp from old packets
|
||||
for _, pkt := range newPackets {
|
||||
pkt.Timestamp = oldPackets[0].Timestamp
|
||||
}
|
||||
} else { // get timestamp from PTS
|
||||
for _, pkt := range newPackets {
|
||||
pkt.Timestamp = uint32(multiplyAndDivide(pts, time.Duration(clockRate), time.Second))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Processor cleans and normalizes streams.
|
||||
type Processor interface {
|
||||
// cleans and normalizes a data unit.
|
||||
Process(unit.Unit, bool) error
|
||||
|
||||
// wraps a RTP packet into a Unit.
|
||||
UnitForRTPPacket(pkt *rtp.Packet, ntp time.Time) unit.Unit
|
||||
UnitForRTPPacket(pkt *rtp.Packet, ntp time.Time, pts time.Duration) Unit
|
||||
}
|
||||
|
||||
// New allocates a Processor.
|
||||
func New(
|
||||
udpMaxPayloadSize int,
|
||||
forma formats.Format,
|
||||
forma format.Format,
|
||||
generateRTPPackets bool,
|
||||
log logger.Writer,
|
||||
) (Processor, error) {
|
||||
switch forma := forma.(type) {
|
||||
case *formats.H264:
|
||||
case *format.H264:
|
||||
return newH264(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.H265:
|
||||
case *format.H265:
|
||||
return newH265(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.VP8:
|
||||
case *format.VP8:
|
||||
return newVP8(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.VP9:
|
||||
case *format.VP9:
|
||||
return newVP9(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.AV1:
|
||||
case *format.AV1:
|
||||
return newAV1(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.MPEG1Audio:
|
||||
case *format.MPEG1Audio:
|
||||
return newMPEG1Audio(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.MPEG4AudioGeneric:
|
||||
case *format.MPEG4AudioGeneric:
|
||||
return newMPEG4AudioGeneric(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.MPEG4AudioLATM:
|
||||
case *format.MPEG4AudioLATM:
|
||||
return newMPEG4AudioLATM(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
case *formats.Opus:
|
||||
case *format.Opus:
|
||||
return newOpus(udpMaxPayloadSize, forma, generateRTPPackets, log)
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user