diff --git a/app/lal/config.go b/app/lal/config.go index a340dc7..e579393 100644 --- a/app/lal/config.go +++ b/app/lal/config.go @@ -6,12 +6,12 @@ import ( ) type Config struct { - SubIdleTimeout int64 `json:"sub_idle_timeout"` - GOPCacheNum int `json:"gop_cache_number"` + RTMP RTMP `json:"rtmp"` - HTTPFlv HTTPFlv `json:"httpflv"` - RTMP RTMP `json:"rtmp"` - Pull Pull `json:"pull"` + SubIdleTimeout int64 `json:"sub_idle_timeout"` + GOPCacheNum int `json:"gop_cache_number"` + HTTPFlv HTTPFlv `json:"httpflv"` + Pull Pull `json:"pull"` } type HTTPFlv struct { diff --git a/app/lal/main.go b/app/lal/main.go index 8fc72f8..4c094ff 100644 --- a/app/lal/main.go +++ b/app/lal/main.go @@ -8,7 +8,8 @@ import ( "net/http" _ "net/http/pprof" "os" - "time" + "os/signal" + "syscall" ) var sm *ServerManager @@ -20,11 +21,11 @@ func main() { config := loadConf(confFile) sm = NewServerManager(config) - go sm.RunLoop() - //shutdownAfter(60 * time.Second) + go runWebPProf() + go runSignalHandler() - startWebPProf() + sm.RunLoop() } func parseFlag() string { @@ -67,18 +68,18 @@ func loadConf(confFile string) *Config { return config } -func startWebPProf() { +func runWebPProf() { + log.Info("start web pprof listen. addr=:10001") if err := http.ListenAndServe("0.0.0.0:10001", nil); err != nil { log.Error(err) return } - log.Info("start pprof listen. addr=:10001") } -// TODO chef: 添加优雅退出信号处理 -func shutdownAfter(d time.Duration) { - go func() { - time.Sleep(d) - sm.Dispose() - }() +func runSignalHandler() { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGUSR1, syscall.SIGUSR2) + s := <-c + log.Infof("recv signal. s=%+v", s) + sm.Dispose() } diff --git a/app/lal/server_manager.go b/app/lal/server_manager.go index 949dc67..0a848e5 100644 --- a/app/lal/server_manager.go +++ b/app/lal/server_manager.go @@ -70,7 +70,9 @@ func (sm *ServerManager) RunLoop() { func (sm *ServerManager) Dispose() { log.Debug("Dispose manager.") - sm.httpFlvServer.Dispose() + if sm.httpFlvServer != nil { + sm.httpFlvServer.Dispose() + } sm.rtmpServer.Dispose() sm.exitChan <- true sm.mutex.Lock() diff --git a/pkg/aac/aac_test.go b/pkg/aac/aac_test.go index ea1137d..e7d6cb5 100644 --- a/pkg/aac/aac_test.go +++ b/pkg/aac/aac_test.go @@ -12,4 +12,4 @@ func TestCaptureAAC(t *testing.T) { CaptureAAC(b, []byte{0xaf, 0x1, 0x21, 0x2b, 0x94, 0xa5, 0xb6, 0xa, 0xe1, 0x63, 0x21, 0x88, 0xa2, 0x10, 0x4b, 0xdf, 0x9, 0x25, 0xb4, 0xd6, 0xe3, 0x4a, 0xd, 0xe3, 0xa3, 0x64, 0x8d, 0x1, 0x31, 0x80, 0x98, 0x8b, 0xdc, 0x79, 0x3e, 0x2d, 0xd8, 0xed, 0x68, 0xe0, 0xe5, 0xb2, 0x44, 0x13, 0x4, 0x53, 0xbf, 0x28, 0x92, 0xe5, 0xfa, 0x7d, 0x86, 0x78, 0x40, 0x78, 0x4c, 0xb5, 0xe, 0x15, 0x21, 0xc3, 0x57, 0x1a, 0x63, 0x8d, 0xe, 0xc, 0x69, 0xb5, 0x91, 0xd0, 0x52, 0xe, 0x1, 0xa8, 0x67, 0x3e, 0xf9, 0x4e, 0xa2, 0xdb, 0x8b, 0x4a, 0x52, 0x4a, 0xd0, 0x7d, 0x34, 0x4, 0x4f, 0x8d, 0x11, 0xd3, 0xd, 0x20, 0x98, 0x55, 0x86, 0x9, 0xfb, 0xe5, 0xdd, 0x28, 0xd9, 0x4c, 0xde, 0x40, 0x89, 0x26, 0x0, 0xd4, 0x14, 0xcb, 0x6a, 0xc5, 0x91, 0x48, 0xb5, 0xcf, 0x20, 0x6b, 0xbb, 0x16, 0x1b, 0x6b, 0xf4, 0x65, 0x32, 0x5a, 0x8d, 0x1a, 0xe0, 0xa9, 0xf2, 0xf4, 0x71, 0x7e, 0xb8, 0x6f, 0x93, 0xbc, 0x2, 0xf1, 0x36, 0x2b, 0x4e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2, 0x6a, 0x58, 0x88, 0x68, 0xa4, 0xc2, 0x17, 0xdd, 0x5a, 0xf1, 0xd1, 0xe3, 0xc7, 0x3e, 0x76, 0x2e, 0x65, 0xc5, 0xc9, 0x3, 0x80} assert.Equal(t, expected, b.Bytes()) -} \ No newline at end of file +} diff --git a/pkg/avc/avc_test.go b/pkg/avc/avc_test.go index 9ee3610..962c124 100644 --- a/pkg/avc/avc_test.go +++ b/pkg/avc/avc_test.go @@ -24,4 +24,4 @@ func TestCorner(t *testing.T) { err = CaptureAVC(b, []byte{0x17, 0x0, 0x1}) assert.Equal(t, nil, b.Bytes()) assert.Equal(t, err, avcErr) -} \ No newline at end of file +} diff --git a/pkg/rtmp/server_session.go b/pkg/rtmp/server_session.go index 2c2a330..176baa3 100644 --- a/pkg/rtmp/server_session.go +++ b/pkg/rtmp/server_session.go @@ -114,14 +114,14 @@ func (s *ServerSession) AsyncWrite(msg []byte) error { return nil } -func (s *ServerSession) ReadableType()string { +func (s *ServerSession) ReadableType() string { switch s.t { case ServerSessionTypePub: return "PUB" case ServerSessionTypeSub: return "SUB" } - return "UNKNOWN" + return "UNKNOWN" } func (s *ServerSession) runReadLoop() error {