Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway: fix stream-status route #3316

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions server/ai_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ func startAIServer(lp *lphttp) error {
lp.transRPC.Handle("/live-video-to-video", oapiReqValidator(lp.StartLiveVideoToVideo()))
// Additionally, there is the '/aiResults' endpoint registered in server/rpc.go

// This endpoint is used to get the latest status of a live-video-to-video stream
lp.transRPC.HandleFunc("/stream-status/{streamID}", lp.handleStreamStatus())

return nil
}

Expand Down Expand Up @@ -804,33 +801,3 @@ func parseMultiPartResult(body io.Reader, boundary string, pipeline string) core

return wkrResult
}

// handleStreamStatus returns the latest available status of a live-video-to-video stream
func (h *lphttp) handleStreamStatus() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}

streamID := strings.TrimPrefix(r.URL.Path, "/stream-status/")
if streamID == "" {
respondWithError(w, "stream ID is required", http.StatusBadRequest)
return
}

// Get status for specific stream
status, exists := StreamStatusStore.Get(streamID)
if !exists {
respondWithError(w, "Stream status not found", http.StatusNotFound)
return
}

jsonData, err := json.Marshal(status)
if err != nil {
respondWithError(w, "Failed to marshal status", http.StatusInternalServerError)
return
}
respondJsonOk(w, jsonData)
}
}
30 changes: 30 additions & 0 deletions server/ai_mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func startAIMediaServer(ls *LivepeerServer) error {
ls.HTTPMux.Handle("/live/video-to-video/{prefix}/{stream}/start", ls.StartLiveVideo())
ls.HTTPMux.Handle("/live/video-to-video/{stream}/update", ls.UpdateLiveVideo())

// Stream status
ls.HTTPMux.Handle("/live/video-to-video/{streamId}/status", ls.GetLiveVideoToVideoStatus())

return nil
}

Expand Down Expand Up @@ -581,6 +584,33 @@ func (ls *LivepeerServer) UpdateLiveVideo() http.Handler {
})
}

func (ls *LivepeerServer) GetLiveVideoToVideoStatus() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
streamId := r.PathValue("streamId")
if streamId == "" {
http.Error(w, "stream id is required", http.StatusBadRequest)
return
}

ctx := r.Context()
ctx = clog.AddVal(ctx, "stream", streamId)

// Get status for specific stream
status, exists := StreamStatusStore.Get(streamId)
if !exists {
http.Error(w, "Stream not found", http.StatusNotFound)
return
}

w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(status); err != nil {
clog.Errorf(ctx, "Failed to encode stream status err=%v", err)
http.Error(w, "Failed to encode status", http.StatusInternalServerError)
return
}
})
}

func (ls *LivepeerServer) cleanupLive(stream string) {
ls.LivepeerNode.LiveMu.Lock()
pub, ok := ls.LivepeerNode.LivePipelines[stream]
Expand Down
Loading