mediamtx/internal/formatprocessor/generic.go

62 lines
1.2 KiB
Go
Raw Normal View History

package formatprocessor
import (
"fmt"
"time"
2023-04-01 16:39:12 +00:00
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/pion/rtp"
2023-05-16 14:14:20 +00:00
"github.com/bluenviron/mediamtx/internal/logger"
)
2023-03-10 11:44:59 +00:00
// UnitGeneric is a generic data unit.
type UnitGeneric struct {
BaseUnit
}
type formatProcessorGeneric struct {
udpMaxPayloadSize int
}
func newGeneric(
udpMaxPayloadSize int,
2023-04-01 16:39:12 +00:00
forma formats.Format,
generateRTPPackets bool,
2023-05-28 15:18:16 +00:00
_ logger.Writer,
) (*formatProcessorGeneric, error) {
if generateRTPPackets {
return nil, fmt.Errorf("we don't know how to generate RTP packets of format %+v", forma)
}
return &formatProcessorGeneric{
udpMaxPayloadSize: udpMaxPayloadSize,
}, nil
}
2023-05-28 15:18:16 +00:00
func (t *formatProcessorGeneric) Process(unit Unit, _ bool) error {
2023-03-10 11:44:59 +00:00
tunit := unit.(*UnitGeneric)
2023-03-10 11:44:59 +00:00
pkt := tunit.RTPPackets[0]
// remove padding
pkt.Header.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.udpMaxPayloadSize {
return fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.udpMaxPayloadSize)
}
return nil
}
func (t *formatProcessorGeneric) UnitForRTPPacket(pkt *rtp.Packet, ntp time.Time) Unit {
return &UnitGeneric{
BaseUnit: BaseUnit{
RTPPackets: []*rtp.Packet{pkt},
NTP: ntp,
},
}
}