mirror of
https://github.com/lkmio/lkm.git
synced 2025-09-27 03:26:01 +08:00
fix: rtc拉流等待时, 取消http请求未关闭sink问题
This commit is contained in:
18
api.go
18
api.go
@@ -18,7 +18,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -320,8 +319,7 @@ func (api *ApiServer) onRtc(sourceId string, w http.ResponseWriter, r *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group := sync.WaitGroup{}
|
done := make(chan struct{})
|
||||||
group.Add(1)
|
|
||||||
sink := rtc.NewSink(api.generateSinkID(r.RemoteAddr), sourceId, v.SDP, func(sdp string) {
|
sink := rtc.NewSink(api.generateSinkID(r.RemoteAddr), sourceId, v.SDP, func(sdp string) {
|
||||||
response := struct {
|
response := struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
@@ -338,8 +336,7 @@ func (api *ApiServer) onRtc(sourceId string, w http.ResponseWriter, r *http.Requ
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(marshal)
|
w.Write(marshal)
|
||||||
|
close(done)
|
||||||
group.Done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Sugar.Infof("rtc拉流请求 source: %s sink: %s sdp:%v", sourceId, sink.String(), v.SDP)
|
log.Sugar.Infof("rtc拉流请求 source: %s sink: %s sdp:%v", sourceId, sink.String(), v.SDP)
|
||||||
@@ -348,10 +345,17 @@ func (api *ApiServer) onRtc(sourceId string, w http.ResponseWriter, r *http.Requ
|
|||||||
if utils.HookStateOK != ok {
|
if utils.HookStateOK != ok {
|
||||||
log.Sugar.Warnf("rtc拉流失败 source: %s sink: %s", sourceId, sink.String())
|
log.Sugar.Warnf("rtc拉流失败 source: %s sink: %s", sourceId, sink.String())
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
group.Done()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group.Wait()
|
select {
|
||||||
|
case <-r.Context().Done():
|
||||||
|
log.Sugar.Infof("rtc拉流请求取消 source: %s sink: %s", sourceId, stream.SinkID2String(sink.GetID()))
|
||||||
|
sink.Close()
|
||||||
|
break
|
||||||
|
case <-done:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *ApiServer) OnSourceList(w http.ResponseWriter, r *http.Request) {
|
func (api *ApiServer) OnSourceList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
Reference in New Issue
Block a user