修改包引入路径

This commit is contained in:
dexter
2022-02-27 18:39:54 +08:00
parent 2c03cc7263
commit 16575235a1
3 changed files with 28 additions and 28 deletions

2
go.mod
View File

@@ -1,4 +1,4 @@
module github.com/Monibuca/plugin-hdl/v4 module m7s.live/plugin/hdl/v4
go 1.18 go 1.18

42
main.go
View File

@@ -1,4 +1,4 @@
package hdl package hdl // import "m7s.live/plugin/hdl/v4"
import ( import (
"bytes" "bytes"
@@ -8,13 +8,13 @@ import (
"strings" "strings"
"time" "time"
. "github.com/Monibuca/engine/v4"
"github.com/Monibuca/engine/v4/codec"
"github.com/Monibuca/engine/v4/config"
"github.com/Monibuca/engine/v4/util"
. "github.com/logrusorgru/aurora" . "github.com/logrusorgru/aurora"
amf "github.com/zhangpeihao/goamf" amf "github.com/zhangpeihao/goamf"
"go.uber.org/zap" "go.uber.org/zap"
. "m7s.live/engine/v4"
"m7s.live/engine/v4/codec"
"m7s.live/engine/v4/config"
"m7s.live/engine/v4/util"
) )
type HDLConfig struct { type HDLConfig struct {
@@ -34,18 +34,17 @@ func (c *HDLConfig) OnEvent(event any) {
plugin.Info(Green("HDL start reuse engine port").String()) plugin.Info(Green("HDL start reuse engine port").String())
} }
case PullerPromise: case PullerPromise:
puller := v.Value
client := &HDLPuller{ client := &HDLPuller{
Puller: puller, Puller: v.Value,
} }
err := client.connect() err := client.connect()
if err == nil { if err == nil {
if err = plugin.Publish(puller.StreamPath, client); err == nil { if err = plugin.Publish(client.StreamPath, client); err == nil {
v.Resolve(util.Null) v.Resolve(util.Null)
break break
} }
} }
client.Error(puller.RemoteURL, zap.Error(err)) client.Error(client.RemoteURL, zap.Error(err))
v.Reject(err) v.Reject(err)
} }
} }
@@ -73,14 +72,16 @@ func (sub *HDLSubscriber) OnEvent(event any) {
switch v := event.(type) { switch v := event.(type) {
case HaveFLV: case HaveFLV:
flvTag := v.GetFLV() flvTag := v.GetFLV()
flvTag.WriteTo(sub) if _, err := flvTag.WriteTo(sub); err != nil {
sub.Stop()
}
default: default:
sub.Subscriber.OnEvent(event) sub.Subscriber.OnEvent(event)
} }
} }
func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
streamPath := strings.TrimPrefix(r.URL.Path, "/hls") streamPath := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/hdl/"), ".flv")
w.Header().Set("Transfer-Encoding", "chunked") w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Set("Content-Type", "video/x-flv") w.Header().Set("Content-Type", "video/x-flv")
sub := &HDLSubscriber{} sub := &HDLSubscriber{}
@@ -113,22 +114,19 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var flags byte var flags byte
if hasAudio { if hasAudio {
flags |= (1 << 2) flags |= (1 << 2)
}
if hasVideo {
flags |= 1
}
w.Write([]byte{'F', 'L', 'V', 0x01, flags, 0, 0, 0, 9, 0, 0, 0, 0})
if hasVideo {
metaData["videocodecid"] = int(vt.CodecID)
metaData["width"] = vt.SPSInfo.Width
metaData["height"] = vt.SPSInfo.Height
}
if hasVideo {
metaData["audiocodecid"] = int(at.CodecID) metaData["audiocodecid"] = int(at.CodecID)
metaData["audiosamplerate"] = at.SampleRate metaData["audiosamplerate"] = at.SampleRate
metaData["audiosamplesize"] = at.SampleSize metaData["audiosamplesize"] = at.SampleSize
metaData["stereo"] = at.Channels == 2 metaData["stereo"] = at.Channels == 2
} }
if hasVideo {
flags |= 1
metaData["videocodecid"] = int(vt.CodecID)
metaData["width"] = vt.SPSInfo.Width
metaData["height"] = vt.SPSInfo.Height
}
// 写入FLV头
w.Write([]byte{'F', 'L', 'V', 0x01, flags, 0, 0, 0, 9, 0, 0, 0, 0})
codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_SCRIPT, 0, net.Buffers{buffer.Bytes()}) codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_SCRIPT, 0, net.Buffers{buffer.Bytes()})
sub.PlayBlock(sub) sub.PlayBlock(sub)
} else { } else {

12
pull.go
View File

@@ -7,11 +7,11 @@ import (
"os" "os"
"strings" "strings"
. "github.com/Monibuca/engine/v4"
"github.com/Monibuca/engine/v4/codec"
"github.com/Monibuca/engine/v4/log"
"github.com/Monibuca/engine/v4/util"
"go.uber.org/zap" "go.uber.org/zap"
. "m7s.live/engine/v4"
"m7s.live/engine/v4/codec"
"m7s.live/engine/v4/log"
"m7s.live/engine/v4/util"
) )
func (puller *HDLPuller) connect() (err error) { func (puller *HDLPuller) connect() (err error) {
@@ -36,7 +36,9 @@ func (puller *HDLPuller) connect() (err error) {
func (puller *HDLPuller) pull() { func (puller *HDLPuller) pull() {
var err error var err error
defer func() { defer func() {
puller.Closer.Close() if puller.Closer != nil {
puller.Closer.Close()
}
if !puller.Stream.IsClosed() { if !puller.Stream.IsClosed() {
if err = puller.connect(); err == nil { if err = puller.connect(); err == nil {
go puller.pull() go puller.pull()