mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-09-27 01:15:52 +08:00
feat: move moov to front
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,4 +8,5 @@ dump
|
||||
record
|
||||
bin
|
||||
.DS_Store
|
||||
.db
|
||||
.db
|
||||
!plugin/record
|
12
device.go
Normal file
12
device.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package m7s
|
||||
|
||||
import "m7s.live/m7s/v5/pkg/task"
|
||||
|
||||
type (
|
||||
Device struct {
|
||||
task.Work
|
||||
}
|
||||
DeviceManager struct {
|
||||
task.Manager[uint32, *Device]
|
||||
}
|
||||
)
|
@@ -1,5 +1,5 @@
|
||||
global:
|
||||
loglevel: debug
|
||||
loglevel: trace
|
||||
flv:
|
||||
path: record
|
||||
gb28181:
|
||||
|
7
example/default/device.yaml
Normal file
7
example/default/device.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
global:
|
||||
device:
|
||||
- name: default
|
||||
description: Example device
|
||||
stream:
|
||||
- rtsp://xxx.xxx.xxx.xxx:554/live/test
|
||||
|
@@ -12,11 +12,11 @@ import (
|
||||
_ "m7s.live/m7s/v5/plugin/monitor"
|
||||
_ "m7s.live/m7s/v5/plugin/mp4"
|
||||
_ "m7s.live/m7s/v5/plugin/preview"
|
||||
_ "m7s.live/m7s/v5/plugin/record"
|
||||
_ "m7s.live/m7s/v5/plugin/rtmp"
|
||||
_ "m7s.live/m7s/v5/plugin/rtsp"
|
||||
_ "m7s.live/m7s/v5/plugin/stress"
|
||||
_ "m7s.live/m7s/v5/plugin/transcode"
|
||||
//_ "m7s.live/m7s/v5/plugin/vmlog"
|
||||
_ "m7s.live/m7s/v5/plugin/webrtc"
|
||||
)
|
||||
|
||||
|
7
example/default/record.yaml
Normal file
7
example/default/record.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
record:
|
||||
# db:
|
||||
# dbtype: duckdb
|
||||
onpub:
|
||||
record:
|
||||
.+:
|
||||
filepath: record/$0
|
@@ -4,5 +4,4 @@ flv:
|
||||
onpub:
|
||||
record:
|
||||
.+:
|
||||
filepath: record/$0
|
||||
fragment: 10s
|
||||
filepath: record/$0
|
30
go.mod
30
go.mod
@@ -10,7 +10,6 @@ require (
|
||||
github.com/cloudwego/goref v0.0.0-20240724113447-685d2a9523c8
|
||||
github.com/deepch/vdk v0.0.27
|
||||
github.com/emiago/sipgo v0.22.0
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/go-delve/delve v1.23.0
|
||||
github.com/gobwas/ws v1.3.2
|
||||
github.com/google/gopacket v1.1.19
|
||||
@@ -18,19 +17,20 @@ require (
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8
|
||||
github.com/icholy/digest v0.1.22
|
||||
github.com/mcuadros/go-defaults v1.2.0
|
||||
github.com/ncruces/go-sqlite3 v0.18.1
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.18.0
|
||||
github.com/pion/interceptor v0.1.29
|
||||
github.com/pion/logging v0.2.2
|
||||
github.com/pion/rtcp v1.2.14
|
||||
github.com/pion/rtp v1.8.6
|
||||
github.com/pion/sdp/v3 v3.0.9
|
||||
github.com/pion/webrtc/v3 v3.2.12
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/quic-go/quic-go v0.43.1
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/samber/slog-common v0.17.1
|
||||
github.com/vishvananda/netlink v1.1.0
|
||||
github.com/yapingcat/gomedia v0.0.0-20240601043430-920523f8e5c7
|
||||
golang.org/x/text v0.16.0
|
||||
golang.org/x/text v0.17.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
@@ -42,28 +42,32 @@ require (
|
||||
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
|
||||
github.com/VictoriaMetrics/metrics v1.35.1 // indirect
|
||||
github.com/VictoriaMetrics/metricsql v0.76.0 // indirect
|
||||
github.com/c0deltin/duckdb-driver v0.1.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/chromedp/cdproto v0.0.0-20240202021202-6d0b6a386732 // indirect
|
||||
github.com/chromedp/sysutil v1.0.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/glebarez/go-sqlite v1.21.2 // 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/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/marcboeker/go-duckdb v1.0.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/pion/datachannel v1.5.6 // indirect
|
||||
github.com/pion/dtls/v2 v2.2.11 // indirect
|
||||
github.com/pion/ice/v2 v2.3.9 // indirect
|
||||
@@ -83,6 +87,7 @@ require (
|
||||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
@@ -94,12 +99,15 @@ require (
|
||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/arch v0.6.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
|
||||
modernc.org/libc v1.41.0 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.7.2 // indirect
|
||||
modernc.org/sqlite v1.29.5 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/sqlite v1.32.0 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -107,17 +115,17 @@ require (
|
||||
github.com/bluenviron/mediacommon v1.9.2
|
||||
github.com/chromedp/chromedp v0.9.5
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
||||
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
|
||||
github.com/gorilla/websocket v1.5.1
|
||||
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
|
||||
github.com/phsym/console-slog v0.3.1
|
||||
github.com/shirou/gopsutil/v3 v3.24.3
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
golang.org/x/crypto v0.25.0 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 // indirect
|
||||
golang.org/x/mod v0.19.0 // indirect
|
||||
golang.org/x/net v0.27.0
|
||||
golang.org/x/sys v0.22.0
|
||||
golang.org/x/sys v0.24.0
|
||||
golang.org/x/tools v0.23.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
59
go.sum
59
go.sum
@@ -19,6 +19,8 @@ github.com/asavie/xdp v0.3.3 h1:b5Aa3EkMJYBeUO5TxPTIAa4wyUqYcsQr2s8f6YLJXhE=
|
||||
github.com/asavie/xdp v0.3.3/go.mod h1:Vv5p+3mZiDh7ImdSvdon3E78wXyre7df5V58ATdIYAY=
|
||||
github.com/bluenviron/mediacommon v1.9.2 h1:EHcvoC5YMXRcFE010bTNf07ZiSlB/e/AdZyG7GsEYN0=
|
||||
github.com/bluenviron/mediacommon v1.9.2/go.mod h1:lt8V+wMyPw8C69HAqDWV5tsAwzN9u2Z+ca8B6C//+n0=
|
||||
github.com/c0deltin/duckdb-driver v0.1.0 h1:g/RAwwNDFd2HmrnqF0oPE0aY7W6F6uFJbf1+zs285eM=
|
||||
github.com/c0deltin/duckdb-driver v0.1.0/go.mod h1:wkHe/zl2ERZDFN/G+ZGVe9Ip+QWPwbsI4dXrRixBRc4=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
@@ -49,10 +51,6 @@ github.com/emiago/sipgo v0.22.0/go.mod h1:a77FgPEEjJvfYWYfP3p53u+dNhWEMb/VGVS6gu
|
||||
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
|
||||
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
|
||||
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
|
||||
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
|
||||
github.com/go-delve/delve v1.23.0 h1:jYgZISZ14KAO3ys8kD07kjrowrygE9F9SIwnpz9xXys=
|
||||
github.com/go-delve/delve v1.23.0/go.mod h1:S3SLuEE2mn7wipKilTvk1p9HdTMnXXElcEpiZ+VcuqU=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
@@ -99,6 +97,8 @@ github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF
|
||||
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
|
||||
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d h1:um9/pc7tKMINFfP1eE7Wv6PRGXlcCSJkVajF7KJw3uQ=
|
||||
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
@@ -108,6 +108,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0Q
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
|
||||
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
|
||||
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8 h1:4Jk58quTZmzJcTrLlbB5L1Q6qXu49EIjCReWxcBFWKo=
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8/go.mod h1:medl9/CfYoQlqAXtAARmMW5dAX2UOdwwkhaszYPk0AM=
|
||||
@@ -135,6 +137,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/marcboeker/go-duckdb v1.0.5 h1:zIfyrCAJfY9FmXWOZ6jE3DkmWpwK4rlY12zqf9LD2mU=
|
||||
github.com/marcboeker/go-duckdb v1.0.5/go.mod h1:wm91jO2GNKa6iO9NTcjXIRsW+/ykPoJbQcHSXhdAl28=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
@@ -144,10 +148,18 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
||||
github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc=
|
||||
github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY=
|
||||
github.com/miekg/dns v1.1.35/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/ncruces/go-sqlite3 v0.18.1 h1:iN8IMZV5EMxpH88NUac9vId23eTKNFUhP7jgY0EBbNc=
|
||||
github.com/ncruces/go-sqlite3 v0.18.1/go.mod h1:eEOyZnW1dGTJ+zDpMuzfYamEUBtdFz5zeYhqLBtHxvM=
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.18.0 h1:KqP9a9wlX/Ba+yG+aeVX4pnNBNdaSO6xHdNDWzPxPnk=
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.18.0/go.mod h1:RXeT1hknrz3A0tBDL6IfluDHuNkHdJeImn5TBMQg9zc=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
|
||||
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
@@ -219,7 +231,6 @@ github.com/pion/turn/v2 v2.1.2/go.mod h1:1kjnPkBcex3dhCU2Am+AAmxDcGhLX3WnMfmkNpv
|
||||
github.com/pion/webrtc/v3 v3.2.12 h1:pVqz5NdtTqyhKIhMcXR8bPp709kCf9blyAhDjoVRLvA=
|
||||
github.com/pion/webrtc/v3 v3.2.12/go.mod h1:/Oz6K95CGWaN+3No+Z0NYvgOPOr3aY8UyTlMm/dec3A=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
@@ -271,6 +282,8 @@ github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
|
||||
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
|
||||
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||
@@ -311,8 +324,8 @@ golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98y
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
|
||||
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
@@ -350,8 +363,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -390,8 +403,8 @@ golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -417,8 +430,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -471,11 +484,19 @@ gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
|
||||
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
||||
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
|
||||
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
|
||||
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/sqlite v1.29.5 h1:8l/SQKAjDtZFo9lkJLdk8g9JEOeYRG4/ghStDCCTiTE=
|
||||
modernc.org/sqlite v1.29.5/go.mod h1:S02dvcmm7TnTRvGhv8IGYyLnIt7AS2KPaB1F/71p75U=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
|
||||
modernc.org/sqlite v1.32.0 h1:6BM4uGza7bWypsw4fdLRsLxut6bHe4c58VeqjRgST8s=
|
||||
modernc.org/sqlite v1.32.0/go.mod h1:UqoylwmTb9F+IqXERT8bW9zzOWN8qwAIcLdzeBZs4hA=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
|
@@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
const (
|
||||
SUBMODE_REAL = iota
|
||||
SUBMODE_NOJUMP
|
||||
SUBMODE_RECORD
|
||||
SUBMODE_BUFFER
|
||||
SUBMODE_WAITKEY
|
||||
)
|
||||
@@ -81,7 +81,7 @@ func (r *AVRingReader) ReadFrame(conf *config.Subscribe) (err error) {
|
||||
} else {
|
||||
r.State = READSTATE_NORMAL
|
||||
}
|
||||
case SUBMODE_NOJUMP:
|
||||
case SUBMODE_RECORD:
|
||||
r.State = READSTATE_NORMAL
|
||||
case SUBMODE_BUFFER:
|
||||
for {
|
||||
@@ -137,12 +137,12 @@ func (r *AVRingReader) ReadFrame(conf *config.Subscribe) (err error) {
|
||||
if err = r.readFrame(conf.SubMode); err != nil {
|
||||
return
|
||||
}
|
||||
if conf.SubMode != SUBMODE_REAL {
|
||||
// 防止过快消费
|
||||
if fast := r.Value.Timestamp - r.FirstTs - time.Since(r.startTime); fast > 0 && fast < time.Second {
|
||||
time.Sleep(fast)
|
||||
}
|
||||
}
|
||||
// if conf.SubMode == SUBMODE_NOJUMP {
|
||||
// // 防止过快消费
|
||||
// if fast := r.Value.Timestamp - r.FirstTs - time.Since(r.startTime); fast > 0 && fast < time.Second {
|
||||
// time.Sleep(fast)
|
||||
// }
|
||||
// }
|
||||
case READSTATE_WAITKEY:
|
||||
r.Info("wait key frame", "seq", r.Value.Sequence)
|
||||
for {
|
||||
|
@@ -26,6 +26,10 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (ctx *AudioCtx) GetRecord() []byte {
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
func (ctx *AudioCtx) GetSampleRate() int {
|
||||
return ctx.SampleRate
|
||||
}
|
||||
@@ -54,6 +58,9 @@ func (ctx *AACCtx) GetSampleRate() int {
|
||||
func (ctx *AACCtx) GetBase() ICodecCtx {
|
||||
return ctx
|
||||
}
|
||||
func (ctx *AACCtx) GetRecord() []byte {
|
||||
return ctx.ConfigBytes
|
||||
}
|
||||
func (ctx *AACCtx) GetInfo() string {
|
||||
return fmt.Sprintf("sample rate: %d, channels: %d, object type: %d", ctx.SampleRate(), ctx.GetChannels(), ctx.Config.ObjectType)
|
||||
}
|
||||
@@ -64,7 +71,9 @@ func (*PCMUCtx) FourCC() FourCC {
|
||||
func (*PCMACtx) FourCC() FourCC {
|
||||
return FourCC_ALAW
|
||||
}
|
||||
|
||||
func (*PCMACtx) GetRecord() []byte {
|
||||
return []byte{} //TODO
|
||||
}
|
||||
func (ctx *PCMACtx) GetBase() ICodecCtx {
|
||||
return ctx
|
||||
}
|
||||
@@ -72,7 +81,9 @@ func (ctx *PCMACtx) GetBase() ICodecCtx {
|
||||
func (ctx *PCMUCtx) GetBase() ICodecCtx {
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (*PCMUCtx) GetRecord() []byte {
|
||||
return []byte{} //TODO
|
||||
}
|
||||
func (*AACCtx) FourCC() FourCC {
|
||||
return FourCC_MP4A
|
||||
}
|
||||
@@ -96,3 +107,8 @@ func (ctx *OPUSCtx) GetSampleRate() int {
|
||||
func (ctx *OPUSCtx) GetInfo() string {
|
||||
return fmt.Sprintf("sample rate: %d, channels: %d", ctx.SampleRate(), ctx.ChannelLayout().Count())
|
||||
}
|
||||
|
||||
func (ctx *OPUSCtx) GetRecord() []byte {
|
||||
// TODO: 需要实现
|
||||
return FourCC_OPUS[:]
|
||||
}
|
||||
|
@@ -37,3 +37,7 @@ func (ctx *AV1Ctx) Height() int {
|
||||
func (*AV1Ctx) FourCC() FourCC {
|
||||
return FourCC_AV1
|
||||
}
|
||||
|
||||
func (ctx *AV1Ctx) GetRecord() []byte {
|
||||
return ctx.ConfigOBUs
|
||||
}
|
||||
|
@@ -122,3 +122,7 @@ func (ctx *H264Ctx) GetInfo() string {
|
||||
func (h264 *H264Ctx) GetBase() ICodecCtx {
|
||||
return h264
|
||||
}
|
||||
|
||||
func (ctx *H264Ctx) GetRecord() []byte {
|
||||
return ctx.Record
|
||||
}
|
||||
|
@@ -32,3 +32,7 @@ func (*H265Ctx) FourCC() FourCC {
|
||||
func (h265 *H265Ctx) GetBase() ICodecCtx {
|
||||
return h265
|
||||
}
|
||||
|
||||
func (h265 *H265Ctx) GetRecord() []byte {
|
||||
return h265.Record
|
||||
}
|
||||
|
@@ -4,4 +4,5 @@ type ICodecCtx interface {
|
||||
FourCC() FourCC
|
||||
GetInfo() string
|
||||
GetBase() ICodecCtx
|
||||
GetRecord() []byte
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Regexp struct {
|
||||
@@ -46,3 +48,13 @@ func (r *Regexp) UnmarshalJSON(b []byte) error {
|
||||
r.Regexp = regexp.MustCompile(string(b))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Regexp) Replace(source, target string) string {
|
||||
if group := r.FindStringSubmatch(source); group != nil {
|
||||
for i, g := range group {
|
||||
target = strings.ReplaceAll(target, fmt.Sprintf("$%d", i), g)
|
||||
}
|
||||
return target
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
9
pkg/db/duckdb.go
Normal file
9
pkg/db/duckdb.go
Normal file
@@ -0,0 +1,9 @@
|
||||
//go:build duckdb
|
||||
|
||||
package db
|
||||
|
||||
import "github.com/c0deltin/duckdb-driver/duckdb"
|
||||
|
||||
func init() {
|
||||
Factory["duckdb"] = duckdb.Open
|
||||
}
|
11
pkg/db/sqlite-cgo.go
Normal file
11
pkg/db/sqlite-cgo.go
Normal file
@@ -0,0 +1,11 @@
|
||||
//go:build sqliteCGO
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
sqlite "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Factory["sqlite"] = sqlite.Open
|
||||
}
|
@@ -3,9 +3,11 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/glebarez/sqlite"
|
||||
//"github.com/glebarez/sqlite"
|
||||
_ "github.com/ncruces/go-sqlite3/embed"
|
||||
"github.com/ncruces/go-sqlite3/gormlite"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Factory["sqlite"] = sqlite.Open
|
||||
Factory["sqlite"] = gormlite.Open
|
||||
}
|
||||
|
51
plugin.go
51
plugin.go
@@ -367,20 +367,14 @@ func (p *Plugin) OnPublish(pub *Publisher) {
|
||||
onPublish := p.config.OnPub
|
||||
if p.Meta.Pusher != nil {
|
||||
for r, pushConf := range onPublish.Push {
|
||||
if group := r.FindStringSubmatch(pub.StreamPath); group != nil {
|
||||
for i, g := range group {
|
||||
pushConf.URL = strings.Replace(pushConf.URL, fmt.Sprintf("$%d", i), g, -1)
|
||||
}
|
||||
if pushConf.URL = r.Replace(pub.StreamPath, pushConf.URL); pushConf.URL != "" {
|
||||
p.Push(pub.StreamPath, pushConf)
|
||||
}
|
||||
}
|
||||
}
|
||||
if p.Meta.Recorder != nil {
|
||||
for r, recConf := range onPublish.Record {
|
||||
if group := r.FindStringSubmatch(pub.StreamPath); group != nil {
|
||||
for i, g := range group {
|
||||
recConf.FilePath = strings.Replace(recConf.FilePath, fmt.Sprintf("$%d", i), g, -1)
|
||||
}
|
||||
if recConf.FilePath = r.Replace(pub.StreamPath, recConf.FilePath); recConf.FilePath != "" {
|
||||
p.Record(pub.StreamPath, recConf)
|
||||
}
|
||||
}
|
||||
@@ -390,7 +384,7 @@ func (p *Plugin) OnPublish(pub *Publisher) {
|
||||
if group := r.FindStringSubmatch(pub.StreamPath); group != nil {
|
||||
for j, to := range tranConf.Output {
|
||||
for i, g := range group {
|
||||
to.Target = strings.Replace(to.Target, fmt.Sprintf("$%d", i), g, -1)
|
||||
to.Target = strings.ReplaceAll(to.Target, fmt.Sprintf("$%d", i), g)
|
||||
}
|
||||
targetUrl, err := url.Parse(to.Target)
|
||||
if err == nil {
|
||||
@@ -403,6 +397,45 @@ func (p *Plugin) OnPublish(pub *Publisher) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func (p *Plugin) OnSubscribe(sub *Subscriber) {
|
||||
// var avoidTrans bool
|
||||
//AVOID:
|
||||
// for trans := range server.Transforms.Range {
|
||||
// for _, output := range trans.Config.Output {
|
||||
// if output.StreamPath == s.StreamPath {
|
||||
// avoidTrans = true
|
||||
// break AVOID
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for reg, conf := range p.config.OnSub.Pull {
|
||||
if p.Meta.Puller != nil {
|
||||
if group := reg.FindStringSubmatch(sub.StreamPath); group != nil {
|
||||
for i, value := range group {
|
||||
conf.URL = strings.Replace(conf.URL, fmt.Sprintf("$%d", i), value, -1)
|
||||
}
|
||||
}
|
||||
p.handler.Pull(sub.StreamPath, conf)
|
||||
}
|
||||
}
|
||||
//if !avoidTrans {
|
||||
// for reg, conf := range plugin.GetCommonConf().OnSub.Transform {
|
||||
// if plugin.Meta.Transformer != nil {
|
||||
// if reg.MatchString(s.StreamPath) {
|
||||
// if group := reg.FindStringSubmatch(s.StreamPath); group != nil {
|
||||
// for j, c := range conf.Output {
|
||||
// for i, value := range group {
|
||||
// c.Target = strings.Replace(c.Target, fmt.Sprintf("$%d", i), value, -1)
|
||||
// }
|
||||
// conf.Output[j] = c
|
||||
// }
|
||||
// }
|
||||
// plugin.handler.Transform(s.StreamPath, conf)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
func (p *Plugin) PublishWithConfig(ctx context.Context, streamPath string, conf config.Publish) (publisher *Publisher, err error) {
|
||||
publisher = createPublisher(p, streamPath, conf)
|
||||
if p.config.EnableAuth {
|
||||
|
@@ -16,7 +16,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (plugin *FLVPlugin) Download(w http.ResponseWriter, r *http.Request) {
|
||||
func (plugin *FLVPlugin) Download_(w http.ResponseWriter, r *http.Request) {
|
||||
streamPath := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/download/"), ".flv")
|
||||
singleFile := filepath.Join(plugin.Path, streamPath+".flv")
|
||||
query := r.URL.Query()
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package plugin_flv
|
||||
|
||||
import (
|
||||
"m7s.live/m7s/v5/pkg/util"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
@@ -9,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"m7s.live/m7s/v5/pkg/util"
|
||||
|
||||
"m7s.live/m7s/v5"
|
||||
|
||||
. "m7s.live/m7s/v5/plugin/flv/pkg"
|
||||
|
@@ -2,8 +2,9 @@ package flv
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"m7s.live/m7s/v5/pkg/util"
|
||||
rtmp "m7s.live/m7s/v5/plugin/rtmp/pkg"
|
||||
)
|
||||
@@ -26,18 +27,22 @@ func NewFlvWriter(w io.Writer) *FlvWriter {
|
||||
return &FlvWriter{Writer: w}
|
||||
}
|
||||
|
||||
func (w *FlvWriter) WriteHeader(hasAudio, hasVideo bool) (err error) {
|
||||
var flags byte
|
||||
if hasAudio {
|
||||
flags |= 0x04
|
||||
}
|
||||
if hasVideo {
|
||||
flags |= 0x01
|
||||
}
|
||||
_, err = w.Write([]byte{'F', 'L', 'V', 0x01, flags, 0, 0, 0, 9, 0, 0, 0, 0})
|
||||
return
|
||||
}
|
||||
|
||||
func (w *FlvWriter) WriteTag(t byte, ts, dataSize uint32, payload ...[]byte) (err error) {
|
||||
WriteFLVTagHead(t, ts, dataSize, w.buf[:])
|
||||
if _, err = w.Write(w.buf[:11]); err != nil {
|
||||
return
|
||||
}
|
||||
for _, p := range payload {
|
||||
if _, err = w.Write(p); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
binary.BigEndian.PutUint32(w.buf[11:], dataSize+11)
|
||||
_, err = w.Write(w.buf[11:])
|
||||
var buffers net.Buffers = append(append(net.Buffers{w.buf[:11]}, payload...), util.PutBE(w.buf[11:], dataSize+11))
|
||||
_, err = buffers.WriteTo(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -9,11 +9,12 @@ import (
|
||||
)
|
||||
|
||||
type Live struct {
|
||||
b [15]byte
|
||||
Subscriber *m7s.Subscriber
|
||||
WriteFlvTag func(net.Buffers) error
|
||||
}
|
||||
|
||||
func (task *Live) WriteFlvHeader() (flv net.Buffers) {
|
||||
func (task *Live) WriteFlvHeader() (err error) {
|
||||
at, vt := &task.Subscriber.Publisher.AudioTrack, &task.Subscriber.Publisher.VideoTrack
|
||||
hasAudio, hasVideo := at.AVTrack != nil && task.Subscriber.SubAudio, vt.AVTrack != nil && task.Subscriber.SubVideo
|
||||
var amf rtmp.AMF
|
||||
@@ -47,27 +48,37 @@ func (task *Live) WriteFlvHeader() (flv net.Buffers) {
|
||||
metaData["height"] = ctx.Height()
|
||||
}
|
||||
var data = amf.Marshal(metaData)
|
||||
var b [15]byte
|
||||
WriteFLVTagHead(FLV_TAG_TYPE_SCRIPT, 0, uint32(len(data)), b[:])
|
||||
flv = append(flv, []byte{'F', 'L', 'V', 0x01, flags, 0, 0, 0, 9, 0, 0, 0, 0}, b[:11], data, b[11:])
|
||||
binary.BigEndian.PutUint32(b[11:], uint32(len(data))+11)
|
||||
return
|
||||
WriteFLVTagHead(FLV_TAG_TYPE_SCRIPT, 0, uint32(len(data)), task.b[4:])
|
||||
defer binary.BigEndian.PutUint32(task.b[:4], uint32(len(data))+11)
|
||||
return task.WriteFlvTag(net.Buffers{[]byte{'F', 'L', 'V', 0x01, flags, 0, 0, 0, 9, 0, 0, 0, 0}, task.b[4:], data})
|
||||
}
|
||||
|
||||
func (task *Live) rtmpData2FlvTag(t byte, data *rtmp.RTMPData) error {
|
||||
WriteFLVTagHead(t, data.Timestamp, uint32(data.Size), task.b[4:])
|
||||
defer binary.BigEndian.PutUint32(task.b[:4], uint32(data.Size)+11)
|
||||
return task.WriteFlvTag(append(net.Buffers{task.b[:]}, data.Memory.Buffers...))
|
||||
}
|
||||
|
||||
func (task *Live) WriteAudioTag(data *rtmp.RTMPAudio) error {
|
||||
return task.rtmpData2FlvTag(FLV_TAG_TYPE_AUDIO, &data.RTMPData)
|
||||
}
|
||||
|
||||
func (task *Live) WriteVideoTag(data *rtmp.RTMPVideo) error {
|
||||
return task.rtmpData2FlvTag(FLV_TAG_TYPE_VIDEO, &data.RTMPData)
|
||||
}
|
||||
|
||||
func (task *Live) Run() (err error) {
|
||||
var b [15]byte
|
||||
flv := task.WriteFlvHeader()
|
||||
copy(b[:4], flv[3])
|
||||
err = task.WriteFlvTag(flv[:3])
|
||||
rtmpData2FlvTag := func(t byte, data *rtmp.RTMPData) error {
|
||||
WriteFLVTagHead(t, data.Timestamp, uint32(data.Size), b[4:])
|
||||
defer binary.BigEndian.PutUint32(b[:4], uint32(data.Size)+11)
|
||||
return task.WriteFlvTag(append(net.Buffers{b[:]}, data.Memory.Buffers...))
|
||||
err = task.WriteFlvHeader()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = m7s.PlayBlock(task.Subscriber, func(audio *rtmp.RTMPAudio) error {
|
||||
return rtmpData2FlvTag(FLV_TAG_TYPE_AUDIO, &audio.RTMPData)
|
||||
return task.WriteAudioTag(audio)
|
||||
}, func(video *rtmp.RTMPVideo) error {
|
||||
return rtmpData2FlvTag(FLV_TAG_TYPE_VIDEO, &video.RTMPData)
|
||||
return task.WriteVideoTag(video)
|
||||
})
|
||||
return task.WriteFlvTag(net.Buffers{b[:4]})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return task.WriteFlvTag(net.Buffers{task.b[:4]})
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"m7s.live/m7s/v5"
|
||||
@@ -154,7 +155,11 @@ func (r *Recorder) Run() (err error) {
|
||||
suber := ctx.Subscriber
|
||||
noFragment := ctx.Fragment == 0 || ctx.Append
|
||||
if noFragment {
|
||||
if file, err = os.OpenFile(ctx.FilePath, os.O_CREATE|os.O_RDWR|util.Conditoinal(ctx.Append, os.O_APPEND, os.O_TRUNC), 0666); err != nil {
|
||||
filePath := ctx.FilePath
|
||||
if !strings.HasSuffix(filePath, ".flv") {
|
||||
filePath += ".flv"
|
||||
}
|
||||
if file, err = os.OpenFile(filePath, os.O_CREATE|os.O_RDWR|util.Conditoinal(ctx.Append, os.O_APPEND, os.O_TRUNC), 0666); err != nil {
|
||||
return
|
||||
}
|
||||
defer writeMetaTag(file, suber, filepositions, times, &duration)
|
||||
@@ -187,7 +192,7 @@ func (r *Recorder) Run() (err error) {
|
||||
offset, err = file.Seek(0, io.SeekEnd)
|
||||
}
|
||||
} else if ctx.Fragment == 0 {
|
||||
file.Write(FLVHead)
|
||||
_, err = file.Write(FLVHead)
|
||||
} else {
|
||||
if file, err = os.OpenFile(filepath.Join(ctx.FilePath, fmt.Sprintf("%d.flv", time.Now().Unix())), os.O_CREATE|os.O_RDWR, 0666); err != nil {
|
||||
return
|
||||
|
40
plugin/record/index.go
Normal file
40
plugin/record/index.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package plugin_record
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"m7s.live/m7s/v5"
|
||||
record "m7s.live/m7s/v5/plugin/record/pkg"
|
||||
)
|
||||
|
||||
type (
|
||||
RecordPlugin struct {
|
||||
m7s.Plugin
|
||||
Path string `default:"record"`
|
||||
}
|
||||
)
|
||||
|
||||
var defaultYaml m7s.DefaultYaml = `subscribe:
|
||||
submode: 1
|
||||
`
|
||||
|
||||
var _ = m7s.InstallPlugin[RecordPlugin](defaultYaml, record.NewRecorder)
|
||||
|
||||
func (plugin *RecordPlugin) RegisterHandler() map[string]http.HandlerFunc {
|
||||
return map[string]http.HandlerFunc{
|
||||
"/vod/flv/{streamPath...}": plugin.vodFLV,
|
||||
"/vod/mp4/{streamPath...}": plugin.vodMP4,
|
||||
}
|
||||
}
|
||||
|
||||
func (plugin *RecordPlugin) OnInit() (err error) {
|
||||
if plugin.DB == nil {
|
||||
return fmt.Errorf("db not found")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (plugin *RecordPlugin) vodMP4(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
116
plugin/record/pkg/record.go
Normal file
116
plugin/record/pkg/record.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"m7s.live/m7s/v5"
|
||||
"m7s.live/m7s/v5/pkg"
|
||||
"m7s.live/m7s/v5/pkg/db"
|
||||
)
|
||||
|
||||
func NewRecorder() m7s.IRecorder {
|
||||
return &Recorder{}
|
||||
}
|
||||
|
||||
type Recorder struct {
|
||||
m7s.DefaultRecorder
|
||||
DB *gorm.DB
|
||||
file *os.File
|
||||
stream *RecordStream
|
||||
}
|
||||
|
||||
func (r *Recorder) Start() (err error) {
|
||||
recordJob := &r.RecordJob
|
||||
plugin := recordJob.Plugin
|
||||
if plugin.DB == nil {
|
||||
return fmt.Errorf("db not found")
|
||||
}
|
||||
err = recordJob.Subscribe()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sub := recordJob.Subscriber
|
||||
var newStream RecordStream
|
||||
r.stream = &newStream
|
||||
newStream.StreamPath = sub.StreamPath
|
||||
newStream.StartTime = sub.StartTime
|
||||
if sub.Publisher.HasAudioTrack() {
|
||||
newStream.AudioCodec = sub.Publisher.AudioTrack.ICodecCtx.FourCC().String()
|
||||
newStream.AudioConfig = sub.Publisher.AudioTrack.ICodecCtx.GetRecord()
|
||||
}
|
||||
if sub.Publisher.HasVideoTrack() {
|
||||
newStream.VideoCodec = sub.Publisher.VideoTrack.ICodecCtx.FourCC().String()
|
||||
newStream.VideoConfig = sub.Publisher.VideoTrack.ICodecCtx.GetRecord()
|
||||
}
|
||||
err = plugin.DB.AutoMigrate(r.stream)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
plugin.DB.Save(r.stream)
|
||||
dbType := plugin.GetCommonConf().DBType
|
||||
if factory, ok := db.Factory[dbType]; ok {
|
||||
_ = os.MkdirAll(recordJob.FilePath, 0755)
|
||||
r.file, err = os.Create(filepath.Join(recordJob.FilePath, fmt.Sprintf("%d.rec", newStream.ID)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
r.DB, err = gorm.Open(factory(filepath.Join(recordJob.FilePath, fmt.Sprintf("%d.db", newStream.ID))), &gorm.Config{})
|
||||
if err != nil {
|
||||
r.Error("failed to connect database", "error", err, "dsn", recordJob.FilePath, "type", dbType)
|
||||
return
|
||||
}
|
||||
if err = r.DB.AutoMigrate(&Sample{}); err != nil {
|
||||
return fmt.Errorf("failed to migrate Frame: %w", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("db type not found %s", dbType)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Recorder) Run() (err error) {
|
||||
recordJob := &r.RecordJob
|
||||
sub := recordJob.Subscriber
|
||||
return m7s.PlayBlock(sub, func(audio *pkg.RawAudio) (err error) {
|
||||
var sample Sample
|
||||
sample.Type = FRAME_TYPE_AUDIO
|
||||
sample.Timestamp = audio.Timestamp.Milliseconds()
|
||||
sample.Length = uint(audio.Size)
|
||||
data := slices.Clone(audio.Buffers)
|
||||
sample.Offset, err = r.file.Seek(0, io.SeekCurrent)
|
||||
_, err = data.WriteTo(r.file)
|
||||
r.DB.Save(&sample)
|
||||
return
|
||||
}, func(video *pkg.H26xFrame) (err error) {
|
||||
var sample Sample
|
||||
sample.Type = FRAME_TYPE_VIDEO
|
||||
if sub.VideoReader.Value.IDR {
|
||||
sample.Type = FRAME_TYPE_VIDEO_KEY_FRAME
|
||||
}
|
||||
sample.Timestamp = video.Timestamp.Milliseconds()
|
||||
sample.CTS = video.CTS.Milliseconds()
|
||||
sample.Offset, err = r.file.Seek(0, io.SeekCurrent)
|
||||
for _, nalu := range video.Nalus {
|
||||
sample.Length += uint(nalu.Size) + 4
|
||||
avcc := append(net.Buffers{[]byte{byte(nalu.Size >> 24), byte(nalu.Size >> 16), byte(nalu.Size >> 8), byte(nalu.Size)}}, nalu.Buffers...)
|
||||
_, err = avcc.WriteTo(r.file)
|
||||
}
|
||||
r.DB.Save(&sample)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Recorder) Dispose() {
|
||||
r.stream.EndTime = time.Now()
|
||||
r.RecordJob.Plugin.DB.Save(r.stream)
|
||||
if db, err := r.DB.DB(); err == nil {
|
||||
db.Close()
|
||||
}
|
||||
}
|
27
plugin/record/pkg/schema.go
Normal file
27
plugin/record/pkg/schema.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package record
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
FRAME_TYPE_AUDIO = iota + 1
|
||||
FRAME_TYPE_VIDEO_KEY_FRAME
|
||||
FRAME_TYPE_VIDEO
|
||||
)
|
||||
|
||||
type (
|
||||
RecordStream struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
StartTime, EndTime time.Time
|
||||
StreamPath string
|
||||
AudioCodec, VideoCodec string
|
||||
AudioConfig, VideoConfig []byte
|
||||
}
|
||||
Sample struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
Type byte
|
||||
Timestamp int64
|
||||
CTS int64
|
||||
Offset int64
|
||||
Length uint
|
||||
}
|
||||
)
|
103
plugin/record/vod-flv.go
Normal file
103
plugin/record/vod-flv.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package plugin_record
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"m7s.live/m7s/v5/pkg/codec"
|
||||
"m7s.live/m7s/v5/pkg/db"
|
||||
"m7s.live/m7s/v5/pkg/util"
|
||||
flv "m7s.live/m7s/v5/plugin/flv/pkg"
|
||||
record "m7s.live/m7s/v5/plugin/record/pkg"
|
||||
)
|
||||
|
||||
func (plugin *RecordPlugin) vodFLV(w http.ResponseWriter, r *http.Request) {
|
||||
streamPath := r.PathValue("streamPath")
|
||||
query := r.URL.Query()
|
||||
speedStr := query.Get("speed")
|
||||
speed, err := strconv.ParseFloat(speedStr, 64)
|
||||
if err != nil {
|
||||
speed = 1
|
||||
}
|
||||
beginTime := time.Now()
|
||||
var startTimestamp int64
|
||||
speedControl := func(ts int64) {
|
||||
targetTime := time.Duration(float64(time.Since(beginTime)) * speed)
|
||||
sleepTime := time.Duration(ts-startTimestamp)*time.Millisecond - targetTime
|
||||
fmt.Println("sleepTime", sleepTime)
|
||||
// if sleepTime > 0 {
|
||||
// time.Sleep(sleepTime)
|
||||
// }
|
||||
}
|
||||
if startTime, err := util.TimeQueryParse(query.Get("start")); err == nil {
|
||||
var streams []*record.RecordStream
|
||||
tx := plugin.DB.Find(&streams, "end_time>? AND stream_path=?", startTime, streamPath)
|
||||
if tx.Error != nil {
|
||||
http.Error(w, tx.Error.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if tx.RowsAffected <= 0 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "video/x-flv")
|
||||
w.Header().Set("Transfer-Encoding", "identity")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
var flvWriter = flv.NewFlvWriter(w)
|
||||
flvWriter.WriteHeader(true, true)
|
||||
for _, stream := range streams {
|
||||
dbType := plugin.GetCommonConf().DBType
|
||||
if factory, ok := db.Factory[dbType]; ok {
|
||||
var streamDB *gorm.DB
|
||||
streamDB, err = gorm.Open(factory(filepath.Join(plugin.Path, stream.StreamPath, fmt.Sprintf("%d.db", stream.ID))), &gorm.Config{})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
startTimestamp = startTime.Sub(stream.StartTime).Milliseconds()
|
||||
hasAudio, hasVideo := stream.AudioCodec != "", stream.VideoCodec != ""
|
||||
var startId uint
|
||||
if hasAudio && stream.AudioCodec == codec.FourCC_MP4A.String() {
|
||||
flvWriter.WriteTag(flv.FLV_TAG_TYPE_AUDIO, 0, uint32(len(stream.AudioConfig))+2, append([]byte{0xaf, 0x00}, stream.AudioConfig...))
|
||||
}
|
||||
if hasVideo {
|
||||
var avccConfig []byte
|
||||
if stream.VideoCodec == codec.FourCC_H264.String() {
|
||||
avccConfig = append([]byte{0x17, 0x00, 0x00, 0x00, 0x00}, stream.VideoConfig...)
|
||||
} else if stream.VideoCodec == codec.FourCC_H265.String() {
|
||||
avccConfig = append([]byte{0x40, 0x01, 0x00, 0x00, 0x00}, stream.VideoConfig...)
|
||||
}
|
||||
flvWriter.WriteTag(flv.FLV_TAG_TYPE_VIDEO, 0, uint32(len(avccConfig)), avccConfig)
|
||||
streamDB.Last(&record.Sample{}, "type=? AND timestamp<=?", record.FRAME_TYPE_VIDEO_KEY_FRAME, startTimestamp).Scan(&startId)
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
rows, err := streamDB.Model(&record.Sample{}).Where("id>=? ", startId).Rows()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
var frame record.Sample
|
||||
streamDB.ScanRows(rows, &frame)
|
||||
switch frame.Type {
|
||||
case record.FRAME_TYPE_AUDIO:
|
||||
flvWriter.WriteTag(flv.FLV_TAG_TYPE_AUDIO, uint32(frame.Timestamp), uint32(len(frame.Data)), frame.Data)
|
||||
case record.FRAME_TYPE_VIDEO, record.FRAME_TYPE_VIDEO_KEY_FRAME:
|
||||
flvWriter.WriteTag(flv.FLV_TAG_TYPE_VIDEO, uint32(frame.Timestamp), uint32(len(frame.Data)), frame.Data)
|
||||
}
|
||||
speedControl(frame.Timestamp)
|
||||
}
|
||||
rows.Close()
|
||||
} else {
|
||||
http.Error(w, fmt.Sprintf("db type not found %s", dbType), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
plugin/transcode/pkg/pull.go
Normal file
20
plugin/transcode/pkg/pull.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package transcode
|
||||
|
||||
import (
|
||||
"m7s.live/m7s/v5"
|
||||
"m7s.live/m7s/v5/pkg/task"
|
||||
)
|
||||
|
||||
func NewPuller() m7s.IPuller {
|
||||
return &Puller{}
|
||||
}
|
||||
|
||||
type Puller struct {
|
||||
task.Task
|
||||
PullJob m7s.PullJob
|
||||
}
|
||||
|
||||
func (p *Puller) GetPullJob() *m7s.PullJob {
|
||||
return &p.PullJob
|
||||
|
||||
}
|
@@ -75,9 +75,6 @@ func (p *RecordJob) Start() (err error) {
|
||||
}
|
||||
dir := p.FilePath
|
||||
if p.Fragment == 0 || p.Append {
|
||||
if filepath.Ext(p.FilePath) == "" {
|
||||
p.FilePath += ".flv"
|
||||
}
|
||||
dir = filepath.Dir(p.FilePath)
|
||||
}
|
||||
p.Description["filePath"] = p.FilePath
|
||||
|
98
server.go
98
server.go
@@ -33,7 +33,7 @@ import (
|
||||
|
||||
var (
|
||||
Version = "v5.0.0"
|
||||
MergeConfigs = []string{"Publish", "Subscribe", "HTTP", "PublicIP", "LogLevel", "EnableAuth", "DB"}
|
||||
MergeConfigs = [...]string{"Publish", "Subscribe", "HTTP", "PublicIP", "PublicIPv6", "LogLevel", "EnableAuth", "DB"}
|
||||
ExecPath = os.Args[0]
|
||||
ExecDir = filepath.Dir(ExecPath)
|
||||
serverMeta = PluginMeta{
|
||||
@@ -45,47 +45,58 @@ var (
|
||||
defaultLogHandler = console.NewHandler(os.Stdout, &console.HandlerOptions{TimeFormat: "15:04:05.000000"})
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
EnableSubEvent bool `default:"true" desc:"启用订阅事件,禁用可以提高性能"` //启用订阅事件,禁用可以提高性能
|
||||
SettingDir string `default:".m7s" desc:""`
|
||||
FatalDir string `default:"fatal" desc:""`
|
||||
EventBusSize int `default:"10" desc:"事件总线大小"` //事件总线大小
|
||||
PulseInterval time.Duration `default:"5s" desc:"心跳事件间隔"` //心跳事件间隔
|
||||
DisableAll bool `default:"false" desc:"禁用所有插件"` //禁用所有插件
|
||||
}
|
||||
|
||||
type WaitStream struct {
|
||||
*slog.Logger
|
||||
StreamPath string
|
||||
SubscriberCollection
|
||||
baseTsAudio, baseTsVideo time.Duration
|
||||
}
|
||||
type (
|
||||
ServerConfig struct {
|
||||
EnableSubEvent bool `default:"true" desc:"启用订阅事件,禁用可以提高性能"` //启用订阅事件,禁用可以提高性能
|
||||
SettingDir string `default:".m7s" desc:""`
|
||||
FatalDir string `default:"fatal" desc:""`
|
||||
PulseInterval time.Duration `default:"5s" desc:"心跳事件间隔"` //心跳事件间隔
|
||||
DisableAll bool `default:"false" desc:"禁用所有插件"` //禁用所有插件
|
||||
StreamAlias map[config.Regexp]string `desc:"流别名"`
|
||||
}
|
||||
WaitStream struct {
|
||||
*slog.Logger
|
||||
StreamPath string
|
||||
SubscriberCollection
|
||||
baseTsAudio, baseTsVideo time.Duration
|
||||
}
|
||||
Server struct {
|
||||
pb.UnimplementedGlobalServer
|
||||
Plugin
|
||||
ServerConfig
|
||||
Plugins util.Collection[string, *Plugin]
|
||||
Streams task.Manager[string, *Publisher]
|
||||
Waiting util.Collection[string, *WaitStream]
|
||||
Pulls task.Manager[string, *PullJob]
|
||||
Pushs task.Manager[string, *PushJob]
|
||||
Records task.Manager[string, *RecordJob]
|
||||
Transforms Transforms
|
||||
Devices DeviceManager
|
||||
Subscribers SubscriberCollection
|
||||
LogHandler MultiLogHandler
|
||||
apiList []string
|
||||
grpcServer *grpc.Server
|
||||
grpcClientConn *grpc.ClientConn
|
||||
lastSummaryTime time.Time
|
||||
lastSummary *pb.SummaryResponse
|
||||
conf any
|
||||
}
|
||||
CheckSubWaitTimeout struct {
|
||||
task.TickTask
|
||||
s *Server
|
||||
}
|
||||
GRPCServer struct {
|
||||
task.Task
|
||||
s *Server
|
||||
tcpTask *config.ListenTCPWork
|
||||
}
|
||||
RawConfig = map[string]map[string]any
|
||||
)
|
||||
|
||||
func (w *WaitStream) GetKey() string {
|
||||
return w.StreamPath
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
pb.UnimplementedGlobalServer
|
||||
Plugin
|
||||
ServerConfig
|
||||
Plugins util.Collection[string, *Plugin]
|
||||
Streams task.Manager[string, *Publisher]
|
||||
Waiting util.Collection[string, *WaitStream]
|
||||
Pulls task.Manager[string, *PullJob]
|
||||
Pushs task.Manager[string, *PushJob]
|
||||
Records task.Manager[string, *RecordJob]
|
||||
Transforms Transforms
|
||||
Subscribers SubscriberCollection
|
||||
LogHandler MultiLogHandler
|
||||
apiList []string
|
||||
grpcServer *grpc.Server
|
||||
grpcClientConn *grpc.ClientConn
|
||||
lastSummaryTime time.Time
|
||||
lastSummary *pb.SummaryResponse
|
||||
conf any
|
||||
}
|
||||
|
||||
func NewServer(conf any) (s *Server) {
|
||||
s = &Server{
|
||||
conf: conf,
|
||||
@@ -108,8 +119,6 @@ func Run(ctx context.Context, conf any) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type RawConfig = map[string]map[string]any
|
||||
|
||||
func exit() {
|
||||
for _, meta := range plugins {
|
||||
if meta.OnExit != nil {
|
||||
@@ -252,11 +261,6 @@ func (s *Server) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type CheckSubWaitTimeout struct {
|
||||
task.TickTask
|
||||
s *Server
|
||||
}
|
||||
|
||||
func (c *CheckSubWaitTimeout) GetTickInterval() time.Duration {
|
||||
return c.s.PulseInterval
|
||||
}
|
||||
@@ -273,12 +277,6 @@ func (c *CheckSubWaitTimeout) Tick(any) {
|
||||
}
|
||||
}
|
||||
|
||||
type GRPCServer struct {
|
||||
task.Task
|
||||
s *Server
|
||||
tcpTask *config.ListenTCPWork
|
||||
}
|
||||
|
||||
func (gRPC *GRPCServer) Dispose() {
|
||||
gRPC.s.Stop(gRPC.StopReason())
|
||||
}
|
||||
|
@@ -85,48 +85,26 @@ func (s *Subscriber) Start() (err error) {
|
||||
if publisher, ok := server.Streams.Get(s.StreamPath); ok {
|
||||
publisher.AddSubscriber(s)
|
||||
return publisher.WaitTrack()
|
||||
} else if waitStream, ok := server.Waiting.Get(s.StreamPath); ok {
|
||||
waitStream.Add(s)
|
||||
} else {
|
||||
server.createWait(s.StreamPath).Add(s)
|
||||
// var avoidTrans bool
|
||||
//AVOID:
|
||||
// for trans := range server.Transforms.Range {
|
||||
// for _, output := range trans.Config.Output {
|
||||
// if output.StreamPath == s.StreamPath {
|
||||
// avoidTrans = true
|
||||
// break AVOID
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for plugin := range server.Plugins.Range {
|
||||
for reg, conf := range plugin.GetCommonConf().OnSub.Pull {
|
||||
if plugin.Meta.Puller != nil {
|
||||
if group := reg.FindStringSubmatch(s.StreamPath); group != nil {
|
||||
for i, value := range group {
|
||||
conf.URL = strings.Replace(conf.URL, fmt.Sprintf("$%d", i), value, -1)
|
||||
}
|
||||
}
|
||||
plugin.handler.Pull(s.StreamPath, conf)
|
||||
for reg, streamPath := range server.StreamAlias {
|
||||
if g := reg.FindStringSubmatch(s.StreamPath); len(g) > 0 {
|
||||
for i, gg := range g {
|
||||
streamPath = strings.ReplaceAll(streamPath, fmt.Sprintf("$%d", i), gg)
|
||||
}
|
||||
if publisher, ok = server.Streams.Get(streamPath); ok {
|
||||
s.Description["alias"] = streamPath
|
||||
publisher.AddSubscriber(s)
|
||||
return publisher.WaitTrack()
|
||||
}
|
||||
}
|
||||
//if !avoidTrans {
|
||||
// for reg, conf := range plugin.GetCommonConf().OnSub.Transform {
|
||||
// if plugin.Meta.Transformer != nil {
|
||||
// if reg.MatchString(s.StreamPath) {
|
||||
// if group := reg.FindStringSubmatch(s.StreamPath); group != nil {
|
||||
// for j, c := range conf.Output {
|
||||
// for i, value := range group {
|
||||
// c.Target = strings.Replace(c.Target, fmt.Sprintf("$%d", i), value, -1)
|
||||
// }
|
||||
// conf.Output[j] = c
|
||||
// }
|
||||
// }
|
||||
// plugin.handler.Transform(s.StreamPath, conf)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
if waitStream, ok := server.Waiting.Get(s.StreamPath); ok {
|
||||
waitStream.Add(s)
|
||||
} else {
|
||||
server.createWait(s.StreamPath).Add(s)
|
||||
for plugin := range server.Plugins.Range {
|
||||
plugin.OnSubscribe(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
Reference in New Issue
Block a user