mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-30 06:51:59 -08:00
route original timestamps without converting to durations (#3839)
This improves timestamp precision.
This commit is contained in:
parent
54c0737074
commit
23002d9f5f
43 changed files with 475 additions and 400 deletions
|
|
@ -1,24 +1,33 @@
|
|||
package formatprocessor
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpac3"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
func randUint32() (uint32, error) {
|
||||
var b [4]byte
|
||||
_, err := rand.Read(b[:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]), nil
|
||||
}
|
||||
|
||||
type formatProcessorAC3 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.AC3
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpac3.Encoder
|
||||
decoder *rtpac3.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newAC3(
|
||||
|
|
@ -37,10 +46,7 @@ func newAC3(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -65,9 +71,8 @@ func (t *formatProcessorAC3) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -76,7 +81,7 @@ func (t *formatProcessorAC3) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorAC3) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.AC3{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpav1"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -23,9 +22,9 @@ var (
|
|||
type formatProcessorAV1 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.AV1
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpav1.Encoder
|
||||
decoder *rtpav1.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newAV1(
|
||||
|
|
@ -44,10 +43,7 @@ func newAV1(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -73,9 +69,8 @@ func (t *formatProcessorAV1) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -84,7 +79,7 @@ func (t *formatProcessorAV1) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorAV1) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.AV1{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtplpcm"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -15,9 +14,9 @@ import (
|
|||
type formatProcessorG711 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.G711
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtplpcm.Encoder
|
||||
decoder *rtplpcm.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newG711(
|
||||
|
|
@ -36,10 +35,7 @@ func newG711(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -67,9 +63,8 @@ func (t *formatProcessorG711) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -78,7 +73,7 @@ func (t *formatProcessorG711) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorG711) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.G711{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func (t *formatProcessorGeneric) ProcessUnit(_ unit.Unit) error {
|
|||
func (t *formatProcessorGeneric) ProcessRTPPacket(
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
_ bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.Generic{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtph264"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/h264"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
|
|
@ -85,9 +84,9 @@ func rtpH264ExtractParams(payload []byte) ([]byte, []byte) {
|
|||
type formatProcessorH264 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.H264
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtph264.Encoder
|
||||
decoder *rtph264.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newH264(
|
||||
|
|
@ -106,10 +105,7 @@ func newH264(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -246,9 +242,8 @@ func (t *formatProcessorH264) ProcessUnit(uu unit.Unit) error {
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -258,7 +253,7 @@ func (t *formatProcessorH264) ProcessUnit(uu unit.Unit) error {
|
|||
func (t *formatProcessorH264) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.H264{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtph265"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/h265"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
|
|
@ -105,9 +104,9 @@ func rtpH265ExtractParams(payload []byte) ([]byte, []byte, []byte) {
|
|||
type formatProcessorH265 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.H265
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtph265.Encoder
|
||||
decoder *rtph265.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newH265(
|
||||
|
|
@ -126,10 +125,7 @@ func newH265(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -278,9 +274,8 @@ func (t *formatProcessorH265) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,7 +285,7 @@ func (t *formatProcessorH265) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorH265) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.H265{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtplpcm"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -15,9 +14,9 @@ import (
|
|||
type formatProcessorLPCM struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.LPCM
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtplpcm.Encoder
|
||||
decoder *rtplpcm.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newLPCM(
|
||||
|
|
@ -36,10 +35,7 @@ func newLPCM(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -67,9 +63,8 @@ func (t *formatProcessorLPCM) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -78,7 +73,7 @@ func (t *formatProcessorLPCM) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorLPCM) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.LPCM{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmjpeg"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorMJPEG struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MJPEG
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpmjpeg.Encoder
|
||||
decoder *rtpmjpeg.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newMJPEG(
|
||||
|
|
@ -37,10 +36,7 @@ func newMJPEG(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -66,9 +62,8 @@ func (t *formatProcessorMJPEG) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -77,7 +72,7 @@ func (t *formatProcessorMJPEG) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorMJPEG) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.MJPEG{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg1audio"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorMPEG1Audio struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG1Audio
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpmpeg1audio.Encoder
|
||||
decoder *rtpmpeg1audio.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newMPEG1Audio(
|
||||
|
|
@ -37,10 +36,7 @@ func newMPEG1Audio(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -65,9 +61,8 @@ func (t *formatProcessorMPEG1Audio) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -76,7 +71,7 @@ func (t *formatProcessorMPEG1Audio) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
func (t *formatProcessorMPEG1Audio) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.MPEG1Audio{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg1video"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -25,9 +24,9 @@ var (
|
|||
type formatProcessorMPEG1Video struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG1Video
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpmpeg1video.Encoder
|
||||
decoder *rtpmpeg1video.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newMPEG1Video(
|
||||
|
|
@ -46,10 +45,7 @@ func newMPEG1Video(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -75,9 +71,8 @@ func (t *formatProcessorMPEG1Video) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -86,7 +81,7 @@ func (t *formatProcessorMPEG1Video) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
func (t *formatProcessorMPEG1Video) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.MPEG1Video{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg4audio"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorMPEG4Audio struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG4Audio
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpmpeg4audio.Encoder
|
||||
decoder *rtpmpeg4audio.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newMPEG4Audio(
|
||||
|
|
@ -37,10 +36,7 @@ func newMPEG4Audio(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -69,9 +65,8 @@ func (t *formatProcessorMPEG4Audio) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -80,7 +75,7 @@ func (t *formatProcessorMPEG4Audio) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
func (t *formatProcessorMPEG4Audio) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.MPEG4Audio{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpmpeg4video"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4video"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
|
|
@ -30,9 +29,9 @@ var (
|
|||
type formatProcessorMPEG4Video struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.MPEG4Video
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpmpeg4video.Encoder
|
||||
decoder *rtpmpeg4video.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newMPEG4Video(
|
||||
|
|
@ -51,10 +50,7 @@ func newMPEG4Video(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -115,9 +111,8 @@ func (t *formatProcessorMPEG4Video) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
return err
|
||||
}
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
u.RTPPackets = pkts
|
||||
|
|
@ -129,7 +124,7 @@ func (t *formatProcessorMPEG4Video) ProcessUnit(uu unit.Unit) error { //nolint:d
|
|||
func (t *formatProcessorMPEG4Video) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.MPEG4Video{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpsimpleaudio"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/bluenviron/mediacommon/pkg/codecs/opus"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorOpus struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.Opus
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpsimpleaudio.Encoder
|
||||
decoder *rtpsimpleaudio.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newOpus(
|
||||
|
|
@ -37,10 +36,7 @@ func newOpus(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -69,11 +65,10 @@ func (t *formatProcessorOpus) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
return err
|
||||
}
|
||||
|
||||
ts := t.timeEncoder.Encode(pts)
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(pts)
|
||||
|
||||
rtpPackets = append(rtpPackets, pkt)
|
||||
pts += opus.PacketDuration(packet)
|
||||
pts += int64(opus.PacketDuration(packet)) * int64(t.format.ClockRate()) / int64(time.Second)
|
||||
}
|
||||
|
||||
u.RTPPackets = rtpPackets
|
||||
|
|
@ -84,7 +79,7 @@ func (t *formatProcessorOpus) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorOpus) ProcessRTPPacket(
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.Opus{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ type Processor interface {
|
|||
ProcessRTPPacket(
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpvp8"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorVP8 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.VP8
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpvp8.Encoder
|
||||
decoder *rtpvp8.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newVP8(
|
||||
|
|
@ -37,10 +36,7 @@ func newVP8(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -66,9 +62,8 @@ func (t *formatProcessorVP8) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -77,7 +72,7 @@ func (t *formatProcessorVP8) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorVP8) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.VP8{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpvp9"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
|
|
@ -16,9 +15,9 @@ import (
|
|||
type formatProcessorVP9 struct {
|
||||
udpMaxPayloadSize int
|
||||
format *format.VP9
|
||||
timeEncoder *rtptime.Encoder
|
||||
encoder *rtpvp9.Encoder
|
||||
decoder *rtpvp9.Decoder
|
||||
randomStart uint32
|
||||
}
|
||||
|
||||
func newVP9(
|
||||
|
|
@ -37,10 +36,7 @@ func newVP9(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
t.timeEncoder = &rtptime.Encoder{
|
||||
ClockRate: forma.ClockRate(),
|
||||
}
|
||||
err = t.timeEncoder.Initialize()
|
||||
t.randomStart, err = randUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -66,9 +62,8 @@ func (t *formatProcessorVP9) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
}
|
||||
u.RTPPackets = pkts
|
||||
|
||||
ts := t.timeEncoder.Encode(u.PTS)
|
||||
for _, pkt := range u.RTPPackets {
|
||||
pkt.Timestamp += ts
|
||||
pkt.Timestamp += t.randomStart + uint32(u.PTS)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -77,7 +72,7 @@ func (t *formatProcessorVP9) ProcessUnit(uu unit.Unit) error { //nolint:dupl
|
|||
func (t *formatProcessorVP9) ProcessRTPPacket( //nolint:dupl
|
||||
pkt *rtp.Packet,
|
||||
ntp time.Time,
|
||||
pts time.Duration,
|
||||
pts int64,
|
||||
hasNonRTSPReaders bool,
|
||||
) (unit.Unit, error) {
|
||||
u := &unit.VP9{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue