From d543bb080dd1a759d4b6a5fec23ac35d2f381a18 Mon Sep 17 00:00:00 2001 From: Kittisak Phormraksa Date: Tue, 5 Nov 2024 13:50:25 +0700 Subject: [PATCH] Add stream producer speed (#13) --- internal/streams/custom.go | 2 ++ internal/streams/producer.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/streams/custom.go b/internal/streams/custom.go index 05e6bb30..492470c4 100644 --- a/internal/streams/custom.go +++ b/internal/streams/custom.go @@ -41,6 +41,8 @@ func apiStreamsSpeed(w http.ResponseWriter, r *http.Request) { } for _, producer := range stream.producers { + producer.speed = speedStr + if conn, ok := producer.conn.(*rtsp.Conn); ok { conn.Connection.Speed = speedStr err := conn.Play() diff --git a/internal/streams/producer.go b/internal/streams/producer.go index 09e2dcc5..5695aba5 100644 --- a/internal/streams/producer.go +++ b/internal/streams/producer.go @@ -8,6 +8,7 @@ import ( "time" "github.com/AlexxIT/go2rtc/pkg/core" + "github.com/AlexxIT/go2rtc/pkg/rtsp" ) type state byte @@ -34,6 +35,9 @@ type Producer struct { state state mu sync.Mutex workerID int + + // custom + speed string } const SourceTemplate = "{input}" @@ -136,6 +140,9 @@ func (p *Producer) MarshalJSON() ([]byte, error) { return json.Marshal(conn) } info := map[string]string{"url": p.url} + if p.speed != "" { + info["speed"] = p.speed + } return json.Marshal(info) } @@ -154,6 +161,12 @@ func (p *Producer) start() { p.state = stateStart p.workerID++ + if p.speed != "" { + if conn, ok := p.conn.(*rtsp.Conn); ok { + conn.Connection.Speed = p.speed + } + } + go p.worker(p.conn, p.workerID) }