forked from AlexxIT/go2rtc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control RTSP speed
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package streams | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/AlexxIT/go2rtc/pkg/rtsp" | ||
) | ||
|
||
// only support RTSP sources | ||
func apiStreamsSpeed(w http.ResponseWriter, r *http.Request) { | ||
query := r.URL.Query() | ||
streamName := query.Get("name") | ||
|
||
if streamName == "" { | ||
http.Error(w, "name required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
switch r.Method { | ||
case "PUT": | ||
streamsMu.RLock() | ||
stream := Get(streamName) | ||
defer streamsMu.RUnlock() | ||
|
||
if stream == nil { | ||
http.Error(w, "", http.StatusNotFound) | ||
return | ||
} | ||
|
||
speedStr := query.Get("speed") | ||
if speedStr == "" { | ||
http.Error(w, "speed required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
_, err := strconv.ParseFloat(speedStr, 64) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
for _, producer := range stream.producers { | ||
if conn, ok := producer.conn.(*rtsp.Conn); ok { | ||
conn.Connection.Speed = speedStr | ||
err := conn.Play() | ||
if err != nil { | ||
log.Error().Msgf("[stream] conn.Play(): %+v\n", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
http.Error(w, "", http.StatusNotFound) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters