diff --git a/README.md b/README.md index fe406be..82b9e5c 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ The system architecture can be visualized as follows: Start streaming by choosing from the following broadcast options: -### **WHIP Broadcast** -- **Server:** `http://127.0.0.1:5555/whip` +### **WHIP Broadcast (OBS >= 30.x)** +- **Server:** `http://127.0.0.1:8044/whip` - **Bearer Token:** `test` ### **RTMP Broadcast** @@ -74,7 +74,7 @@ Start streaming by choosing from the following broadcast options: - URL: `http://127.0.0.1:8044/hls/test/master.m3u8` - **WHEP:** - - URL: `http://127.0.0.1:5555/` + - URL: `http://127.0.0.1:8044/` - Bearer Token: `test` - Click the **Subscribe** button. diff --git a/config.toml b/config.toml index 8dcf84d..bbfd96d 100644 --- a/config.toml +++ b/config.toml @@ -1,11 +1,7 @@ -[monitor] -port = 6060 -[whep] -port = 5555 +[service] +port = 8044 [rtmp] port = 1930 -[hls] -port = 8044 llhls = false disk_ram = true [docker] diff --git a/config/config.go b/config/config.go index 2f1f2a8..1356200 100644 --- a/config/config.go +++ b/config/config.go @@ -2,26 +2,16 @@ package config // Struct to hold the configuration type Config struct { - Monitor Monitor `mapstructure:"monitor"` - Whep Whep `mapstructure:"whep"` RTMP RTMP `mapstructure:"rtmp"` - HLS HLS `mapstructure:"hls"` + Service Service `mapstructure:"service"` Docker DockerConfig `mapstructure:"docker"` } -type Monitor struct { - Port int `mapstructure:"port"` -} - type RTMP struct { Port int `mapstructure:"port"` } -type Whep struct { - Port int `mapstructure:"port"` -} - -type HLS struct { +type Service struct { Port int `mapstructure:"port"` LLHLS bool `mapstructure:"llhls"` DiskRam bool `mapstructure:"disk_ram"` diff --git a/docker-compose.yaml b/docker-compose.yaml index ea74de6..154d723 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,6 @@ services: - "~/.store:/app/bin/videos" ports: - "8044:8044" - - "5555:5555" - "1930:1930" - "30000-31000:30000-31000/udp" environment: diff --git a/main.go b/main.go index 87e713a..b6cdb7d 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "liveflow/media/streamer/egress/record/mp4" "liveflow/media/streamer/egress/record/webm" "liveflow/media/streamer/egress/whep" + "liveflow/media/streamer/ingress/whip" "net/http" "strconv" @@ -24,10 +25,9 @@ import ( "liveflow/media/hlshub" "liveflow/media/hub" "liveflow/media/streamer/ingress/rtmp" - "liveflow/media/streamer/ingress/whip" ) -// RTMP 받으면 자동으로 HLS 서비스 동작, 녹화 서비스까지~? +// RTMP 받으면 자동으로 Service 서비스 동작, 녹화 서비스까지~? func main() { ctx := context.Background() viper.SetConfigName("config") // name of config file (without extension) @@ -44,13 +44,6 @@ func main() { panic(fmt.Errorf("failed to unmarshal config: %w", err)) } fmt.Printf("Config: %+v\n", conf) - - go func() { - statsEcho := echo.New() - statsEcho.GET("/prometheus", echo.WrapHandler(promhttp.Handler())) - statsEcho.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) - statsEcho.Start(":" + strconv.Itoa(conf.Monitor.Port)) - }() log.Init() //log.SetCaller(ctx, true) //log.SetFormatter(ctx, &logrus.JSONFormatter{ @@ -70,13 +63,23 @@ func main() { api.HideBanner = true hlsHub := hlshub.NewHLSHub() hlsHandler := httpsrv.NewHandler(hlsHub) + api.GET("/prometheus", echo.WrapHandler(promhttp.Handler())) + api.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) api.GET("/hls/:streamID/master.m3u8", hlsHandler.HandleMasterM3U8) api.GET("/hls/:streamID/:playlistName/stream.m3u8", hlsHandler.HandleM3U8) api.GET("/hls/:streamID/:playlistName/:resourceName", hlsHandler.HandleM3U8) + whipServer := whip.NewWHIP(whip.WHIPArgs{ + Hub: hub, + Tracks: tracks, + DockerMode: conf.Docker.Mode, + Echo: api, + }) + whipServer.RegisterRoute() go func() { - api.Start("0.0.0.0:" + strconv.Itoa(conf.HLS.Port)) + fmt.Println("----------------", conf.Service.Port) + api.Start("0.0.0.0:" + strconv.Itoa(conf.Service.Port)) }() - // ingress 의 rtmp, whip 서비스로부터 streamID를 받아 HLS, ContainerMP4, WHEP 서비스 시작 + // ingress 의 rtmp, whip 서비스로부터 streamID를 받아 Service, ContainerMP4, WHEP 서비스 시작 for source := range hub.SubscribeToStreamID() { log.Infof(ctx, "New streamID received: %s", source.StreamID()) mp4 := mp4.NewMP4(mp4.MP4Args{ @@ -96,9 +99,9 @@ func main() { hls := hls.NewHLS(hls.HLSArgs{ Hub: hub, HLSHub: hlsHub, - Port: conf.HLS.Port, - LLHLS: conf.HLS.LLHLS, - DiskRam: conf.HLS.DiskRam, + Port: conf.Service.Port, + LLHLS: conf.Service.LLHLS, + DiskRam: conf.Service.DiskRam, }) err := hls.Start(ctx, source) if err != nil { @@ -115,13 +118,6 @@ func main() { } }() - whipServer := whip.NewWHIP(whip.WHIPArgs{ - Hub: hub, - Tracks: tracks, - DockerMode: conf.Docker.Mode, - Port: conf.Whep.Port, - }) - go whipServer.Serve() rtmpServer := rtmp.NewRTMP(rtmp.RTMPArgs{ Hub: hub, Port: conf.RTMP.Port, diff --git a/media/streamer/ingress/whip/serve.go b/media/streamer/ingress/whip/serve.go index 9bb0919..80ffade 100644 --- a/media/streamer/ingress/whip/serve.go +++ b/media/streamer/ingress/whip/serve.go @@ -6,7 +6,6 @@ import ( "io" "liveflow/log" "net/http" - "strconv" "strings" "github.com/labstack/echo/v4" @@ -36,14 +35,14 @@ type WHIP struct { hub *hub.Hub tracks map[string][]*webrtc.TrackLocalStaticRTP dockerMode bool - port int + echo *echo.Echo } type WHIPArgs struct { Hub *hub.Hub Tracks map[string][]*webrtc.TrackLocalStaticRTP DockerMode bool - Port int + Echo *echo.Echo } func NewWHIP(args WHIPArgs) *WHIP { @@ -51,18 +50,15 @@ func NewWHIP(args WHIPArgs) *WHIP { hub: args.Hub, tracks: args.Tracks, dockerMode: args.DockerMode, - port: args.Port, + echo: args.Echo, } } -func (r *WHIP) Serve() { - whipServer := echo.New() - whipServer.HideBanner = true +func (r *WHIP) RegisterRoute() { + whipServer := r.echo whipServer.Static("/", ".") whipServer.POST("/whip", r.whipHandler) whipServer.POST("/whep", r.whepHandler) - //whipServer.PATCH("/whip", whipHandler) - whipServer.Start(":" + strconv.Itoa(r.port)) } func (r *WHIP) bearerToken(c echo.Context) (string, error) {