mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-25 04:22:00 -08:00
34 lines
734 B
Go
34 lines
734 B
Go
package serverudpl
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/aler9/gortsplib"
|
|
"github.com/aler9/rtsp-simple-server/internal/logger"
|
|
)
|
|
|
|
// Parent is implemented by program.
|
|
type Parent interface {
|
|
Log(logger.Level, string, ...interface{})
|
|
}
|
|
|
|
// New allocates a gortsplib.ServerUDPListener.
|
|
func New(port int,
|
|
streamType gortsplib.StreamType,
|
|
parent Parent) (*gortsplib.ServerUDPListener, error) {
|
|
|
|
listener, err := gortsplib.NewServerUDPListener(":" + strconv.FormatInt(int64(port), 10))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
label := func() string {
|
|
if streamType == gortsplib.StreamTypeRTP {
|
|
return "RTP"
|
|
}
|
|
return "RTCP"
|
|
}()
|
|
parent.Log(logger.Info, "[UDP/"+label+" listener] opened on :%d", port)
|
|
|
|
return listener, nil
|
|
}
|