Skip to content

Commit

Permalink
Add stream producer speed (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjooiopa authored Nov 5, 2024
1 parent 394acbf commit d543bb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/streams/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions internal/streams/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/rtsp"
)

type state byte
Expand All @@ -34,6 +35,9 @@ type Producer struct {
state state
mu sync.Mutex
workerID int

// custom
speed string
}

const SourceTemplate = "{input}"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit d543bb0

Please sign in to comment.