修改设置父级Context和IO的方式

This commit is contained in:
dexter
2022-02-27 18:59:37 +08:00
parent 16575235a1
commit 99f0214e91
2 changed files with 4 additions and 4 deletions

View File

@@ -86,8 +86,8 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "video/x-flv")
sub := &HDLSubscriber{}
sub.ID = r.RemoteAddr
sub.OnEvent(r.Context()) //注入父级Context
sub.OnEvent(w) //注入Writer
sub.SetParentCtx(r.Context())
sub.SetIO(w)
if err := plugin.Subscribe(streamPath, sub); err == nil {
at, vt := sub.AudioTrack, sub.VideoTrack
hasVideo := at != nil

View File

@@ -20,12 +20,12 @@ func (puller *HDLPuller) connect() (err error) {
if strings.HasPrefix(puller.RemoteURL, "http") {
var res *http.Response
if res, err = http.Get(puller.RemoteURL); err == nil {
puller.OnEvent(res.Body)
puller.SetIO(res.Body)
}
} else {
var res *os.File
if res, err = os.Open(puller.RemoteURL); err == nil {
puller.OnEvent(res)
puller.SetIO(res)
}
}
if err != nil {