mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-09 20:02:01 -08:00
support publishing, reading, proxying with SRT (#2068)
This commit is contained in:
parent
d696a782f7
commit
b4e3033ea3
22 changed files with 2184 additions and 213 deletions
|
|
@ -180,6 +180,12 @@ type apiWebRTCManager interface {
|
|||
apiSessionsKick(uuid.UUID) error
|
||||
}
|
||||
|
||||
type apiSRTServer interface {
|
||||
apiConnsList() (*apiSRTConnsList, error)
|
||||
apiConnsGet(uuid.UUID) (*apiSRTConn, error)
|
||||
apiConnsKick(uuid.UUID) error
|
||||
}
|
||||
|
||||
type apiParent interface {
|
||||
logger.Writer
|
||||
apiConfigSet(conf *conf.Conf)
|
||||
|
|
@ -194,6 +200,7 @@ type api struct {
|
|||
rtmpsServer apiRTMPServer
|
||||
hlsManager apiHLSManager
|
||||
webRTCManager apiWebRTCManager
|
||||
srtServer apiSRTServer
|
||||
parent apiParent
|
||||
|
||||
httpServer *httpserv.WrappedServer
|
||||
|
|
@ -211,6 +218,7 @@ func newAPI(
|
|||
rtmpsServer apiRTMPServer,
|
||||
hlsManager apiHLSManager,
|
||||
webRTCManager apiWebRTCManager,
|
||||
srtServer apiSRTServer,
|
||||
parent apiParent,
|
||||
) (*api, error) {
|
||||
a := &api{
|
||||
|
|
@ -222,6 +230,7 @@ func newAPI(
|
|||
rtmpsServer: rtmpsServer,
|
||||
hlsManager: hlsManager,
|
||||
webRTCManager: webRTCManager,
|
||||
srtServer: srtServer,
|
||||
parent: parent,
|
||||
}
|
||||
|
||||
|
|
@ -280,6 +289,12 @@ func newAPI(
|
|||
group.POST("/v2/webrtcsessions/kick/:id", a.onWebRTCSessionsKick)
|
||||
}
|
||||
|
||||
if !interfaceIsEmpty(a.srtServer) {
|
||||
group.GET("/v2/srtconns/list", a.onSRTConnsList)
|
||||
group.GET("/v2/srtconns/get/:id", a.onSRTConnsGet)
|
||||
group.POST("/v2/srtconns/kick/:id", a.onSRTConnsKick)
|
||||
}
|
||||
|
||||
network, address := restrictNetwork("tcp", address)
|
||||
|
||||
var err error
|
||||
|
|
@ -853,6 +868,56 @@ func (a *api) onWebRTCSessionsKick(ctx *gin.Context) {
|
|||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
func (a *api) onSRTConnsList(ctx *gin.Context) {
|
||||
data, err := a.srtServer.apiConnsList()
|
||||
if err != nil {
|
||||
ctx.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data.ItemCount = len(data.Items)
|
||||
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
data.PageCount = pageCount
|
||||
|
||||
ctx.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (a *api) onSRTConnsGet(ctx *gin.Context) {
|
||||
uuid, err := uuid.Parse(ctx.Param("id"))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := a.srtServer.apiConnsGet(uuid)
|
||||
if err != nil {
|
||||
abortWithError(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (a *api) onSRTConnsKick(ctx *gin.Context) {
|
||||
uuid, err := uuid.Parse(ctx.Param("id"))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = a.srtServer.apiConnsKick(uuid)
|
||||
if err != nil {
|
||||
abortWithError(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// confReload is called by core.
|
||||
func (a *api) confReload(conf *conf.Conf) {
|
||||
a.mutex.Lock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue