diff --git a/go.mod b/go.mod index 4ca6461..b955994 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/Monibuca/plugin-hdl/v3 go 1.13 require ( - github.com/Monibuca/engine/v3 v3.0.0-alpha7 - github.com/Monibuca/utils/v3 v3.0.0-alpha5 + github.com/Monibuca/engine/v3 v3.0.0-beta5 + github.com/Monibuca/utils/v3 v3.0.0-beta github.com/logrusorgru/aurora v2.0.3+incompatible - github.com/pion/rtp v1.6.2 // indirect + github.com/pion/rtp v1.6.5 // indirect github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8 - golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b // indirect + golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 // indirect ) diff --git a/go.sum b/go.sum index 905b130..70e02fc 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,16 @@ github.com/Monibuca/engine/v3 v3.0.0-alpha6 h1:USZa+JDVJd13rb9wmX06ZxjRCrqYTAPe5 github.com/Monibuca/engine/v3 v3.0.0-alpha6/go.mod h1:V0/kfen6K5O/RLXHPsZj4DF/LboDZ0OqfeCfn35bWMo= github.com/Monibuca/engine/v3 v3.0.0-alpha7 h1:ohlsdFQCUS8i6eux+etFxLKo/IyQUgqlsNAgTIR9mDQ= github.com/Monibuca/engine/v3 v3.0.0-alpha7/go.mod h1:eonu3UFn3W7NpHzSrACipxdAyOBCUwzlFUe1R7JjttE= +github.com/Monibuca/engine/v3 v3.0.0-beta3 h1:/co+L2qCRZUq55S0LtYpY9xzOJiUUG3VGytYGFf1RD4= +github.com/Monibuca/engine/v3 v3.0.0-beta3/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk= +github.com/Monibuca/engine/v3 v3.0.0-beta5 h1:b27ZQDfvf5dBMZbCSIUXItUwVIFs95fpkAV4xjN7BNE= +github.com/Monibuca/engine/v3 v3.0.0-beta5/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk= github.com/Monibuca/utils/v3 v3.0.0-alpha4 h1:pecYA89kWmtGOeY6R99d4T1epPJ1wc+jFrrJY13VD04= github.com/Monibuca/utils/v3 v3.0.0-alpha4/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c= github.com/Monibuca/utils/v3 v3.0.0-alpha5 h1:IOyW/KJSRdRg+TPcgwkHLBynqfNQOV6p3iP7LgXEMFc= github.com/Monibuca/utils/v3 v3.0.0-alpha5/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c= +github.com/Monibuca/utils/v3 v3.0.0-beta h1:z4p/BSH5J9Ja/gwoDmj1RyN+b0q28Nmn/fqXiwq2hGY= +github.com/Monibuca/utils/v3 v3.0.0-beta/go.mod h1:mQYP/OMox1tkWP6Qut7pBfARr1TXSRkK662dexQl6kI= github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0= github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo= github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg= @@ -24,8 +30,12 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/rtp v1.6.2 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U= github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= +github.com/pion/rtp v1.6.5 h1:o2cZf8OascA5HF/b0PAbTxRKvOWxTQxWYt7SlToxFGI= +github.com/pion/rtp v1.6.5/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY= +github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0= github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8 h1:r1JUI0wuHlgRb8jNd3zPBBkjUdrjpVKr8SdJWc8ntg8= github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= @@ -39,3 +49,5 @@ golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhS golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b h1:ggRgirZABFolTmi3sn6Ivd9SipZwLedQ5wR0aAKnFxU= golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 h1:faDu4veV+8pcThn4fewv6TVlNCezafGoC1gM/mxQLbQ= +golang.org/x/sys v0.0.0-20210611083646-a4fc73990273/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/main.go b/main.go index 8728add..e4f5300 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,6 @@ func run() { } func HDLHandler(w http.ResponseWriter, r *http.Request) { - sign := r.URL.Query().Get("sign") // if err := AuthHooks.Trigger(sign); err != nil { // w.WriteHeader(403) // return @@ -58,16 +57,17 @@ func HDLHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Transfer-Encoding", "chunked") w.Header().Set("Content-Type", "video/x-flv") w.Write(codec.FLVHeader) - sub := Subscriber{Sign: sign, ID: r.RemoteAddr, Type: "FLV", Ctx2: r.Context()} + sub := Subscriber{ByteStreamFormat: true, ID: r.RemoteAddr, Type: "FLV", Ctx2: r.Context()} if err := sub.Subscribe(stringPath); err == nil { + vt, at := sub.WaitVideoTrack(), sub.WaitAudioTrack() var buffer bytes.Buffer if _, err := amf.WriteString(&buffer, "onMetaData"); err != nil { return } metaData := amf.Object{ "MetaDataCreator": "m7s", - "hasVideo": sub.OriginVideoTrack != nil, - "hasAudio": sub.OriginAudioTrack != nil, + "hasVideo": vt != nil, + "hasAudio": at != nil, "hasMatadata": true, "canSeekToEnd": false, "duration": 0, @@ -76,37 +76,32 @@ func HDLHandler(w http.ResponseWriter, r *http.Request) { "videodatarate": 0, "filesize": 0, } - if sub.OriginVideoTrack != nil { - metaData["videocodecid"] = int(sub.OriginVideoTrack.CodecID) - metaData["width"] = sub.OriginVideoTrack.SPSInfo.Width - metaData["height"] = sub.OriginVideoTrack.SPSInfo.Height - codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_VIDEO, 0, sub.OriginVideoTrack.RtmpTag) + if vt != nil { + metaData["videocodecid"] = int(vt.CodecID) + metaData["width"] = vt.SPSInfo.Width + metaData["height"] = vt.SPSInfo.Height + codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_VIDEO, 0, vt.ExtraData.Payload) sub.OnVideo = func(pack VideoPack) { - payload := pack.ToRTMPTag() - defer utils.RecycleSlice(payload) - codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_VIDEO, pack.Timestamp, payload) + codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_VIDEO, pack.Timestamp, pack.Payload) } } - if sub.OriginAudioTrack != nil { - metaData["audiocodecid"] = int(sub.OriginAudioTrack.SoundFormat) - metaData["audiosamplerate"] = sub.OriginAudioTrack.SoundRate - metaData["audiosamplesize"] = int(sub.OriginAudioTrack.SoundSize) - metaData["stereo"] = sub.OriginAudioTrack.Channels == 2 - if sub.OriginAudioTrack.SoundFormat == 10 { - codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_AUDIO, 0, sub.OriginAudioTrack.RtmpTag) + if at != nil { + metaData["audiocodecid"] = int(at.CodecID) + metaData["audiosamplerate"] = at.SoundRate + metaData["audiosamplesize"] = int(at.SoundSize) + metaData["stereo"] = at.Channels == 2 + if at.CodecID == 10 { + codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_AUDIO, 0, at.ExtraData) } - tag0 := sub.OriginAudioTrack.RtmpTag[0] sub.OnAudio = func(pack AudioPack) { - payload := pack.ToRTMPTag(tag0) - defer utils.RecycleSlice(payload) - codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_AUDIO, pack.Timestamp, payload) + codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_AUDIO, pack.Timestamp, pack.Payload) } } if _, err := WriteEcmaArray(&buffer, metaData); err != nil { return } codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_SCRIPT, 0, buffer.Bytes()) - sub.Play(sub.OriginAudioTrack, sub.OriginVideoTrack) + sub.Play(at, vt) } } func WriteEcmaArray(w amf.Writer, o amf.Object) (n int, err error) {