mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-26 21:39:16 -08:00
this allows to apply features that were previously implemented for single codecs (like RTP packet resizing), to any codec, and simplifies future development.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package stream
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/bluenviron/gortsplib/v5/pkg/description"
|
|
"github.com/bluenviron/gortsplib/v5/pkg/format"
|
|
"github.com/bluenviron/mediamtx/internal/errordumper"
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
|
"github.com/pion/rtp"
|
|
)
|
|
|
|
type streamMedia struct {
|
|
media *description.Media
|
|
useRTPPackets bool
|
|
rtpMaxPayloadSize int
|
|
replaceNTP bool
|
|
onBytesReceived func(uint64)
|
|
onBytesSent func(uint64)
|
|
writeRTSP func(*description.Media, []*rtp.Packet, time.Time)
|
|
processingErrors *errordumper.Dumper
|
|
parent logger.Writer
|
|
|
|
formats map[format.Format]*streamFormat
|
|
}
|
|
|
|
func (sm *streamMedia) initialize() error {
|
|
sm.formats = make(map[format.Format]*streamFormat)
|
|
|
|
for _, forma := range sm.media.Formats {
|
|
sf := &streamFormat{
|
|
format: forma,
|
|
media: sm.media,
|
|
useRTPPackets: sm.useRTPPackets,
|
|
rtpMaxPayloadSize: sm.rtpMaxPayloadSize,
|
|
replaceNTP: sm.replaceNTP,
|
|
processingErrors: sm.processingErrors,
|
|
onBytesReceived: sm.onBytesReceived,
|
|
onBytesSent: sm.onBytesSent,
|
|
writeRTSP: sm.writeRTSP,
|
|
parent: sm.parent,
|
|
}
|
|
err := sf.initialize()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sm.formats[forma] = sf
|
|
}
|
|
|
|
return nil
|
|
}
|