mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-06 09:06:52 +08:00
rtp包使用v2版本
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp/v2"
|
||||||
"m7s.live/engine/v4/codec"
|
"m7s.live/engine/v4/codec"
|
||||||
"m7s.live/engine/v4/log"
|
"m7s.live/engine/v4/log"
|
||||||
)
|
)
|
||||||
|
6
go.mod
6
go.mod
@@ -4,9 +4,10 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cnotch/ipchub v1.1.0
|
github.com/cnotch/ipchub v1.1.0
|
||||||
|
github.com/gobwas/ws v1.1.0
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||||
github.com/pion/rtp v1.7.4
|
github.com/pion/rtp/v2 v2.0.0-20220302185659-b3d10fc096b0
|
||||||
github.com/q191201771/naza v0.19.1
|
github.com/q191201771/naza v0.19.1
|
||||||
github.com/shirou/gopsutil/v3 v3.22.1
|
github.com/shirou/gopsutil/v3 v3.22.1
|
||||||
go.uber.org/zap v1.21.0
|
go.uber.org/zap v1.21.0
|
||||||
@@ -24,9 +25,12 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
github.com/pion/randutil v0.1.0 // indirect
|
github.com/pion/randutil v0.1.0 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.8.1 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.9 // indirect
|
github.com/tklauser/go-sysconf v0.3.9 // indirect
|
||||||
github.com/tklauser/numcpus v0.3.0 // indirect
|
github.com/tklauser/numcpus v0.3.0 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
|
8
go.sum
8
go.sum
@@ -17,6 +17,9 @@ github.com/emitter-io/address v1.0.0/go.mod h1:GfZb5+S/o8694B1GMGK2imUYQyn2skszM
|
|||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
|
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||||
|
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||||
|
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||||
@@ -45,8 +48,7 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
|
|||||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
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/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||||
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||||
github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA=
|
github.com/pion/rtp/v2 v2.0.0-20220302185659-b3d10fc096b0 h1:zyOGxHutZ6IhksQSMtwf3OFXB29W5R18yFQWOQJYWjU=
|
||||||
github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
|
||||||
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
|
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@@ -56,8 +58,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF
|
|||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
|
github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
|
||||||
github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
|
github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
|
||||||
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
|
|
||||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
|
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
||||||
github.com/shirou/gopsutil/v3 v3.22.1 h1:33y31Q8J32+KstqPfscvFwBlNJ6xLaBy4xqBXzlYV5w=
|
github.com/shirou/gopsutil/v3 v3.22.1 h1:33y31Q8J32+KstqPfscvFwBlNJ6xLaBy4xqBXzlYV5w=
|
||||||
github.com/shirou/gopsutil/v3 v3.22.1/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY=
|
github.com/shirou/gopsutil/v3 v3.22.1/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY=
|
||||||
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A=
|
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A=
|
||||||
|
63
log/log.go
63
log/log.go
@@ -3,6 +3,7 @@ package log
|
|||||||
import (
|
import (
|
||||||
// . "github.com/logrusorgru/aurora"
|
// . "github.com/logrusorgru/aurora"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
// "github.com/mattn/go-colorable"
|
// "github.com/mattn/go-colorable"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -12,14 +13,45 @@ import (
|
|||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger *zap.SugaredLogger
|
var sugaredLogger *zap.SugaredLogger
|
||||||
|
var logger *zap.Logger
|
||||||
|
|
||||||
// var levelColors = []func(any) Value{Red, Red, Red, Yellow, Blue, Green, White}
|
// var levelColors = []func(any) Value{Red, Red, Red, Yellow, Blue, Green, White}
|
||||||
|
|
||||||
// type LogWriter func(*log.Entry) string
|
// type LogWriter func(*log.Entry) string
|
||||||
|
|
||||||
// var colorableStdout = colorable.NewColorableStdout()
|
// var colorableStdout = colorable.NewColorableStdout()
|
||||||
|
type MultipleWriter []io.Writer
|
||||||
|
|
||||||
|
func (m *MultipleWriter) Write(p []byte) (n int, err error) {
|
||||||
|
for _, w := range *m {
|
||||||
|
n, err = w.Write(p)
|
||||||
|
if err != nil {
|
||||||
|
m.Delete(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
func (m *MultipleWriter) Delete(writer io.Writer) {
|
||||||
|
for i, w := range *m {
|
||||||
|
if w == writer {
|
||||||
|
*m = append((*m)[:i], (*m)[i+1:]...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *MultipleWriter) Add(writer io.Writer) {
|
||||||
|
*m = append(*m, writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
var multipleWriter = &MultipleWriter{os.Stdout}
|
||||||
|
|
||||||
|
func AddWriter(writer io.Writer) {
|
||||||
|
multipleWriter.Add(writer)
|
||||||
|
}
|
||||||
|
func DeleteWriter(writer io.Writer) {
|
||||||
|
multipleWriter.Delete(writer)
|
||||||
|
}
|
||||||
func init() {
|
func init() {
|
||||||
config := zap.NewDevelopmentConfig()
|
config := zap.NewDevelopmentConfig()
|
||||||
config.EncoderConfig.NewReflectedEncoder = func(w io.Writer) zapcore.ReflectedEncoder {
|
config.EncoderConfig.NewReflectedEncoder = func(w io.Writer) zapcore.ReflectedEncoder {
|
||||||
@@ -27,8 +59,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||||
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("15:04:05")
|
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("15:04:05")
|
||||||
l, _ := config.Build(zap.WithCaller(false))
|
|
||||||
logger = l.Sugar()
|
logger = zap.New(
|
||||||
|
zapcore.NewCore(zapcore.NewConsoleEncoder(config.EncoderConfig), zapcore.AddSync(multipleWriter), config.Level),
|
||||||
|
)
|
||||||
|
sugaredLogger = logger.Sugar()
|
||||||
// std.SetOutput(colorableStdout)
|
// std.SetOutput(colorableStdout)
|
||||||
// std.SetFormatter(LogWriter(defaultFormatter))
|
// std.SetFormatter(LogWriter(defaultFormatter))
|
||||||
}
|
}
|
||||||
@@ -42,52 +77,52 @@ type Zap interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func With(fields ...zap.Field) *zap.Logger {
|
func With(fields ...zap.Field) *zap.Logger {
|
||||||
return logger.Desugar().With(fields...)
|
return logger.With(fields...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug(args ...any) {
|
func Debug(args ...any) {
|
||||||
logger.Debug(args...)
|
sugaredLogger.Debug(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Info(args ...any) {
|
func Info(args ...any) {
|
||||||
logger.Info(args...)
|
sugaredLogger.Info(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warn(args ...any) {
|
func Warn(args ...any) {
|
||||||
logger.Warn(args...)
|
sugaredLogger.Warn(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error(args ...any) {
|
func Error(args ...any) {
|
||||||
logger.Error(args...)
|
sugaredLogger.Error(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debugf(format string, args ...interface{}) {
|
func Debugf(format string, args ...interface{}) {
|
||||||
logger.Debugf(format, args...)
|
sugaredLogger.Debugf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs a message at level Info on the standard logger.
|
// Infof logs a message at level Info on the standard logger.
|
||||||
func Infof(format string, args ...interface{}) {
|
func Infof(format string, args ...interface{}) {
|
||||||
logger.Infof(format, args...)
|
sugaredLogger.Infof(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a message at level Warn on the standard logger.
|
// Warnf logs a message at level Warn on the standard logger.
|
||||||
func Warnf(format string, args ...interface{}) {
|
func Warnf(format string, args ...interface{}) {
|
||||||
logger.Warnf(format, args...)
|
sugaredLogger.Warnf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs a message at level Error on the standard logger.
|
// Errorf logs a message at level Error on the standard logger.
|
||||||
func Errorf(format string, args ...interface{}) {
|
func Errorf(format string, args ...interface{}) {
|
||||||
logger.Errorf(format, args...)
|
sugaredLogger.Errorf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panicf logs a message at level Panic on the standard logger.
|
// Panicf logs a message at level Panic on the standard logger.
|
||||||
func Panicf(format string, args ...interface{}) {
|
func Panicf(format string, args ...interface{}) {
|
||||||
logger.Panicf(format, args...)
|
sugaredLogger.Panicf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
|
// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
|
||||||
func Fatalf(format string, args ...interface{}) {
|
func Fatalf(format string, args ...interface{}) {
|
||||||
logger.Fatalf(format, args...)
|
sugaredLogger.Fatalf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func defaultFormatter(entry *log.Entry) string {
|
// func defaultFormatter(entry *log.Entry) string {
|
||||||
|
@@ -18,6 +18,10 @@ type HaveAVCC interface {
|
|||||||
GetAVCC() net.Buffers
|
GetAVCC() net.Buffers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HaveRTP interface {
|
||||||
|
GetRTP() []*RTPFrame
|
||||||
|
}
|
||||||
|
|
||||||
type AudioFrame AVFrame[AudioSlice]
|
type AudioFrame AVFrame[AudioSlice]
|
||||||
type VideoFrame AVFrame[NALUSlice]
|
type VideoFrame AVFrame[NALUSlice]
|
||||||
type AudioDeConf DecoderConfiguration[AudioSlice]
|
type AudioDeConf DecoderConfiguration[AudioSlice]
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp/v2"
|
||||||
. "m7s.live/engine/v4/common"
|
. "m7s.live/engine/v4/common"
|
||||||
"m7s.live/engine/v4/config"
|
"m7s.live/engine/v4/config"
|
||||||
"m7s.live/engine/v4/util"
|
"m7s.live/engine/v4/util"
|
||||||
|
@@ -1,22 +1,14 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"m7s.live/engine/v4/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TCPListener interface {
|
|
||||||
context.Context
|
|
||||||
Process(*net.TCPConn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReturnJson[T any](fetch func() T, tickDur time.Duration, rw http.ResponseWriter, r *http.Request) {
|
func ReturnJson[T any](fetch func() T, tickDur time.Duration, rw http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Query().Get("json") != "" {
|
if r.URL.Query().Get("json") != "" {
|
||||||
if err := json.NewEncoder(rw).Encode(fetch()); err != nil {
|
if err := json.NewEncoder(rw).Encode(fetch()); err != nil {
|
||||||
@@ -56,17 +48,17 @@ func ReturnJson[T any](fetch func() T, tickDur time.Duration, rw http.ResponseWr
|
|||||||
func ListenUDP(address string, networkBuffer int) (*net.UDPConn, error) {
|
func ListenUDP(address string, networkBuffer int) (*net.UDPConn, error) {
|
||||||
addr, err := net.ResolveUDPAddr("udp", address)
|
addr, err := net.ResolveUDPAddr("udp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("udp server ResolveUDPAddr :%s error, %v", address, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
conn, err := net.ListenUDP("udp", addr)
|
conn, err := net.ListenUDP("udp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("udp server ListenUDP :%s error, %v", address, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = conn.SetReadBuffer(networkBuffer); err != nil {
|
if err = conn.SetReadBuffer(networkBuffer); err != nil {
|
||||||
log.Errorf("udp server video conn set read buffer error, %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = conn.SetWriteBuffer(networkBuffer); err != nil {
|
if err = conn.SetWriteBuffer(networkBuffer); err != nil {
|
||||||
log.Errorf("udp server video conn set write buffer error, %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
return conn, err
|
return conn, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user