This commit is contained in:
Ingo Oppermann 2024-05-30 22:38:34 +02:00
parent 09a60de368
commit 4341d71645

View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"net" "net"
"os"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -12,7 +13,6 @@ import (
"github.com/datarhei/joy4/av/pktque" "github.com/datarhei/joy4/av/pktque"
"github.com/datarhei/joy4/av/pubsub" "github.com/datarhei/joy4/av/pubsub"
"github.com/datarhei/joy4/format" "github.com/datarhei/joy4/format"
"github.com/datarhei/joy4/format/flv/flvio"
"github.com/datarhei/joy4/format/rtmp" "github.com/datarhei/joy4/format/rtmp"
) )
@ -22,7 +22,6 @@ func init() {
type channel struct { type channel struct {
que *pubsub.Queue que *pubsub.Queue
metadata flvio.AMFMap
hasAudio bool hasAudio bool
hasVideo bool hasVideo bool
} }
@ -65,7 +64,7 @@ func New(config Config) (Server, error) {
Addr: config.Addr, Addr: config.Addr,
MaxProbePacketCount: 40, MaxProbePacketCount: 40,
DebugChunks: func(_ net.Conn) bool { DebugChunks: func(_ net.Conn) bool {
return false return true
}, },
ConnectionIdleTimeout: 10 * time.Second, ConnectionIdleTimeout: 10 * time.Second,
} }
@ -122,8 +121,6 @@ func (s *server) handlePlay(conn *rtmp.Conn) {
s.lock.RUnlock() s.lock.RUnlock()
if ch != nil { if ch != nil {
//conn.SetMetaData(ch.metadata)
s.log("PLAY", "START", conn.URL.Path, "", client) s.log("PLAY", "START", conn.URL.Path, "", client)
cursor := ch.que.Oldest() cursor := ch.que.Oldest()
@ -140,8 +137,8 @@ func (s *server) handlePlay(conn *rtmp.Conn) {
Demuxer: cursor, Demuxer: cursor,
} }
avutil.CopyFile(conn, demuxer) err := avutil.CopyFile(conn, demuxer)
s.log("PLAY", "STOP", conn.URL.Path, "", client) s.log("PLAY", "STOP", conn.URL.Path, err.Error(), client)
} else { } else {
s.log("PLAY", "NOTFOUND", conn.URL.Path, "", client) s.log("PLAY", "NOTFOUND", conn.URL.Path, "", client)
} }
@ -232,13 +229,17 @@ func main() {
var cert string var cert string
var key string var key string
flag.StringVar(&addr, "addr", "", "Address to listen on") flag.StringVar(&addr, "addr", ":1935", "Address to listen on")
flag.StringVar(&cert, "cert", "", "Path to the certifacate file") flag.StringVar(&cert, "cert", "", "Path to the certifacate file")
flag.StringVar(&key, "key", "", "Path to the key file") flag.StringVar(&key, "key", "", "Path to the key file")
//flag.BoolVar(&help, "h", false, "Show options")
flag.Parse() flag.Parse()
if len(addr) == 0 {
fmt.Printf("invalid address\n")
os.Exit(1)
}
config := Config{ config := Config{
Addr: addr, Addr: addr,
} }