mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-05 23:26:51 +08:00
sink hook单独封装
This commit is contained in:
@@ -3,16 +3,12 @@ package stream
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/yangjiechina/avformat/utils"
|
||||
"github.com/yangjiechina/live-server/log"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SinkId interface{}
|
||||
|
||||
type ISink interface {
|
||||
HookHandler
|
||||
|
||||
Id() SinkId
|
||||
|
||||
Input(data []byte) error
|
||||
@@ -191,45 +187,3 @@ func (s *SinkImpl) Close() {
|
||||
func (s *SinkImpl) PrintInfo() string {
|
||||
return fmt.Sprintf("%s-%v source:%s", s.ProtocolStr(), s.Id_, s.SourceId_)
|
||||
}
|
||||
|
||||
func (s *SinkImpl) Play(success func(), failure func(state utils.HookState)) {
|
||||
f := func() {
|
||||
source := SourceManager.Find(s.SourceId())
|
||||
if source == nil {
|
||||
log.Sugar.Infof("添加sink到等待队列 sink:%s-%v source:%s", s.ProtocolStr(), s.Id(), s.SourceId())
|
||||
|
||||
s.SetState(SessionStateWait)
|
||||
AddSinkToWaitingQueue(s.SourceId(), s)
|
||||
} else {
|
||||
log.Sugar.Debugf("发送播放事件 sink:%s-%v source:%s", s.ProtocolStr(), s.Id(), s.SourceId())
|
||||
|
||||
source.AddEvent(SourceEventPlay, s)
|
||||
}
|
||||
}
|
||||
|
||||
if !AppConfig.Hook.EnableOnPlay() {
|
||||
f()
|
||||
success()
|
||||
return
|
||||
}
|
||||
|
||||
err := s.Hook(HookEventPlay, NewPlayHookEventInfo(s.SourceId(), "", s.Protocol()), func(response *http.Response) {
|
||||
f()
|
||||
success()
|
||||
}, func(response *http.Response, err error) {
|
||||
log.Sugar.Errorf("Hook播放事件响应失败 err:%s sink:%s-%v source:%s", err.Error(), s.ProtocolStr(), s.Id(), s.SourceId())
|
||||
|
||||
failure(utils.HookStateFailure)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("Hook播放事件发送失败 err:%s sink:%s-%v source:%s", err.Error(), s.ProtocolStr(), s.Id(), s.SourceId())
|
||||
|
||||
failure(utils.HookStateFailure)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SinkImpl) PlayDone(success func(), failure func(state utils.HookState)) {
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user