mirror of
https://github.com/Monibuca/plugin-ts.git
synced 2025-10-30 02:11:58 +08:00
跟随engine修改
This commit is contained in:
22
main.go
22
main.go
@@ -35,14 +35,12 @@ func init() {
|
|||||||
Run: func() {
|
Run: func() {
|
||||||
http.HandleFunc("/ts/list", listTsDir)
|
http.HandleFunc("/ts/list", listTsDir)
|
||||||
http.HandleFunc("/ts/publish", publishTsDir)
|
http.HandleFunc("/ts/publish", publishTsDir)
|
||||||
onSubscribe := make(chan interface{}, 0)
|
AddHook(HOOK_SUBSCRIBE, func(x interface{}) {
|
||||||
AddHook(HOOK_SUBSCRIBE, onSubscribe)
|
|
||||||
for x := range onSubscribe {
|
|
||||||
s := x.(*Subscriber)
|
s := x.(*Subscriber)
|
||||||
if config.AutoPublish && s.Publisher == nil {
|
if config.AutoPublish && s.Publisher == nil {
|
||||||
go new(TS).PublishDir(s.StreamPath)
|
new(TS).PublishDir(s.StreamPath)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -69,10 +67,16 @@ func (ts *TS) run() {
|
|||||||
totalBuffer := cap(ts.TsPesPktChan)
|
totalBuffer := cap(ts.TsPesPktChan)
|
||||||
var at *AudioTrack
|
var at *AudioTrack
|
||||||
vt := NewVideoTrack()
|
vt := NewVideoTrack()
|
||||||
defer ts.Dispose()
|
needClose := true
|
||||||
|
defer func() {
|
||||||
|
if needClose {
|
||||||
|
ts.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ts.Done():
|
case <-ts.Done():
|
||||||
|
needClose = false
|
||||||
return
|
return
|
||||||
case tsPesPkt, ok := <-ts.TsPesPktChan:
|
case tsPesPkt, ok := <-ts.TsPesPktChan:
|
||||||
ts.BufferLength = len(ts.TsPesPktChan)
|
ts.BufferLength = len(ts.TsPesPktChan)
|
||||||
@@ -98,8 +102,7 @@ func (ts *TS) run() {
|
|||||||
at.SoundType = ((payload[2] & 0x1) << 2) | ((payload[3] & 0xc0) >> 6)
|
at.SoundType = ((payload[2] & 0x1) << 2) | ((payload[3] & 0xc0) >> 6)
|
||||||
at.RtmpTag = codec.ADTSToAudioSpecificConfig(payload)
|
at.RtmpTag = codec.ADTSToAudioSpecificConfig(payload)
|
||||||
at.Push(uint32(tsPesPkt.PesPkt.Header.Pts/90), payload[7:])
|
at.Push(uint32(tsPesPkt.PesPkt.Header.Pts/90), payload[7:])
|
||||||
ts.OriginAudioTrack = at
|
ts.SetOriginAT(at)
|
||||||
ts.AddAudioTrack("aac", at)
|
|
||||||
} else {
|
} else {
|
||||||
utils.Println("audio codec not support yet,want aac")
|
utils.Println("audio codec not support yet,want aac")
|
||||||
return
|
return
|
||||||
@@ -147,8 +150,7 @@ func (ts *TS) run() {
|
|||||||
}
|
}
|
||||||
if vt.RtmpTag != nil && ts.OriginVideoTrack == nil {
|
if vt.RtmpTag != nil && ts.OriginVideoTrack == nil {
|
||||||
vt.CodecID = 7
|
vt.CodecID = 7
|
||||||
ts.OriginVideoTrack = vt
|
ts.SetOriginVT(vt)
|
||||||
ts.AddVideoTrack("h264", vt)
|
|
||||||
}
|
}
|
||||||
if utils.MayBeError(err) {
|
if utils.MayBeError(err) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user