Skip to content

Commit

Permalink
Merge pull request #64 from ixugo/dev
Browse files Browse the repository at this point in the history
max 包含 lal 统计接口与通知
  • Loading branch information
ZSC714725 authored Apr 12, 2024
2 parents 1adb330 + 54afe36 commit 8e9ac77
Show file tree
Hide file tree
Showing 7 changed files with 538 additions and 49 deletions.
33 changes: 25 additions & 8 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
var defaultConfig Config

type Config struct {
SrtConfig SrtConfig `json:"srt_config"` // srt配置
RtcConfig RtcConfig `json:"rtc_config"` // rtc配置
HttpConfig HttpConfig `json:"http_config"` // http/https配置
HttpFmp4Config HttpFmp4Config `json:"httpfmp4_config"` // http-fmp4配置
HlsConfig HlsConfig `json:"hls_config"` // hls-fmp4/llhls配置
GB28181Config GB28181Config `json:"gb28181_config"` // gb28181配置
OnvifConfig OnvifConfig `json:"onvif_config"` //
LalSvrConfigPath string `json:"lal_config_path"` // lal配置目录
SrtConfig SrtConfig `json:"srt_config"` // srt配置
RtcConfig RtcConfig `json:"rtc_config"` // rtc配置
HttpConfig HttpConfig `json:"http_config"` // http/https配置
HttpFmp4Config HttpFmp4Config `json:"httpfmp4_config"` // http-fmp4配置
HlsConfig HlsConfig `json:"hls_config"` // hls-fmp4/llhls配置
GB28181Config GB28181Config `json:"gb28181_config"` // gb28181配置
OnvifConfig OnvifConfig `json:"onvif_config"` //
ServerId string `json:"server_id"` // http 通知唯一标识
HttpNotifyConfig HttpNotifyConfig `json:"http_notify"` // http 通知配置
LalSvrConfigPath string `json:"lal_config_path"` // lal配置目录
}

type SrtConfig struct {
Expand Down Expand Up @@ -75,6 +77,21 @@ type OnvifConfig struct {
Enable bool `json:"enable"`
}

type HttpNotifyConfig struct {
Enable bool `json:"enable"`
UpdateIntervalSec int `json:"update_interval_sec"`
OnServerStart string `json:"on_server_start"`
OnUpdate string `json:"on_update"`
OnPubStart string `json:"on_pub_start"`
OnPubStop string `json:"on_pub_stop"`
OnSubStart string `json:"on_sub_start"`
OnSubStop string `json:"on_sub_stop"`
OnRelayPullStart string `json:"on_relay_pull_start"`
OnRelayPullStop string `json:"on_relay_pull_stop"`
OnRtmpConnect string `json:"on_rtmp_connect"`
OnHlsMakeTs string `json:"on_hls_make_ts"`
}

func Open(filepath string) error {
data, err := ioutil.ReadFile(filepath)
if err != nil {
Expand Down
94 changes: 54 additions & 40 deletions conf/lalmax.conf.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,57 @@
{
"srt_config": {
"enable": true,
"addr": ":6001"
"srt_config": {
"enable": true,
"addr": ":6001"
},
"rtc_config": {
"enable": true,
"iceHostNatToIps": [],
"iceUdpMuxPort": 4888,
"iceTcpMuxPort": 4888
},
"http_config": {
"http_listen_addr": ":1290",
"enable_https": true,
"https_listen_addr": ":1233",
"https_cert_file": "./conf/cert.pem",
"https_key_file": "./conf/key.pem"
},
"httpfmp4_config": {
"enable": true
},
"hls_config": {
"enable": true
},
"gb28181_config": {
"enable": true,
"serial": "34020000002000000001",
"realm": "3402000000",
"sipIp": "192.168.254.165",
"sipPort": 5060,
"sipNetwork": "udp",
"username": "",
"media_config": {
"mediaIp": "192.168.254.165"
},
"rtc_config": {
"enable": true,
"iceHostNatToIps": [],
"iceUdpMuxPort": 4888,
"iceTcpMuxPort": 4888
},
"http_config": {
"http_listen_addr": ":1290",
"enable_https": true,
"https_listen_addr": ":1233",
"https_cert_file": "./conf/cert.pem",
"https_key_file": "./conf/key.pem"
},
"httpfmp4_config": {
"enable": true
},
"hls_config":{
"enable": true
},
"gb28181_config":{
"enable": true,
"serial": "34020000002000000001",
"realm": "3402000000",
"sipIp": "192.168.254.165",
"sipPort": 5060,
"sipNetwork": "udp",
"username": "",
"media_config": {
"mediaIp": "192.168.254.165"
},
"quickLogin": true
},
"onvif_config": {
"enable": true
},
"lal_config_path:":"./conf/lalserver.conf.json"
"quickLogin": true
},
"onvif_config": {
"enable": true
},
"server_id": "1",
"http_notify": {
"enable": false,
"update_interval_sec": 5,
"on_update": "http://127.0.0.1:10101/on_update",
"on_pub_start": "http://127.0.0.1:10101/on_pub_start",
"on_pub_stop": "http://127.0.0.1:10101/on_pub_stop",
"on_sub_start": "http://127.0.0.1:10101/on_sub_start",
"on_sub_stop": "http://127.0.0.1:10101/on_sub_stop",
"on_relay_pull_start": "http://127.0.0.1:10101/on_relay_pull_start",
"on_relay_pull_stop": "http://127.0.0.1:10101/on_relay_pull_stop",
"on_rtmp_connect": "http://127.0.0.1:10101/on_rtmp_connect",
"on_server_start": "http://127.0.0.1:10101/on_server_start",
"on_hls_make_ts": "http://127.0.0.1:10101/on_hls_make_ts"
},
"lal_config_path:": "./conf/lalserver.conf.json"
}

62 changes: 62 additions & 0 deletions hook/hooksession.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package hook
import (
"lalmax/fmp4/hls"
"sync"
"time"

"github.com/q191201771/lal/pkg/base"
"github.com/q191201771/naza/pkg/nazalog"
)

var _ base.ISession = (*consumerInfo)(nil)

type IHookSessionSubscriber interface {
OnMsg(msg base.RtmpMsg)
OnStop()
Expand All @@ -25,6 +28,47 @@ type HookSession struct {
type consumerInfo struct {
subscriber IHookSessionSubscriber
hasSendVideo bool

base.StatSession
}

// AppName implements base.ISession.
func (c *consumerInfo) AppName() string {
return c.SessionId
}

// GetStat implements base.ISession.
func (c *consumerInfo) GetStat() base.StatSession {
return c.StatSession
}

// IsAlive implements base.ISession.
func (c *consumerInfo) IsAlive() (readAlive bool, writeAlive bool) {
return true, true
}

// RawQuery implements base.ISession.
func (c *consumerInfo) RawQuery() string {
return ""
}

// StreamName implements base.ISession.
func (c *consumerInfo) StreamName() string {
return c.SessionId
}

// UniqueKey implements base.ISession.
func (c *consumerInfo) UniqueKey() string {
return c.SessionId
}

// UpdateStat implements base.ISession.
func (c *consumerInfo) UpdateStat(intervalSec uint32) {
}

// Url implements base.ISession.
func (*consumerInfo) Url() string {
return ""
}

func NewHookSession(uniqueKey, streamName string, hlssvr *hls.HlsServer) *HookSession {
Expand Down Expand Up @@ -112,12 +156,30 @@ func (session *HookSession) AddConsumer(consumerId string, subscriber IHookSessi

info := &consumerInfo{
subscriber: subscriber,
StatSession: base.StatSession{
SessionId: consumerId,
StartTime: time.Now().Format(time.DateTime),
// Protocol: , TODO: (xugo)需要传递更多的参数来填充数据
},
}

nazalog.Info("AddConsumer, consumerId:", consumerId)
session.consumers.Store(consumerId, info)
}

func (session *HookSession) GetAllConsumer() []base.StatSub {
out := make([]base.StatSub, 0, 10)
session.consumers.Range(func(key, value any) bool {
v, ok := value.(*consumerInfo)
if ok {
// TODO: (xugo)先简单实现,此处需要优化数据准确性
out = append(out, base.Session2StatSub(v))
}
return true
})
return out
}

func (session *HookSession) RemoveConsumer(consumerId string) {
_, ok := session.consumers.Load(consumerId)
if ok {
Expand Down
Loading

0 comments on commit 8e9ac77

Please sign in to comment.