mirror of
https://github.com/hsnks100/liveflow.git
synced 2025-09-26 20:21:12 +08:00
Use only 2 ports #7
This commit is contained in:
@@ -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.
|
||||
|
||||
|
@@ -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]
|
||||
|
@@ -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"`
|
||||
|
@@ -9,7 +9,6 @@ services:
|
||||
- "~/.store:/app/bin/videos"
|
||||
ports:
|
||||
- "8044:8044"
|
||||
- "5555:5555"
|
||||
- "1930:1930"
|
||||
- "30000-31000:30000-31000/udp"
|
||||
environment:
|
||||
|
38
main.go
38
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,
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user