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