1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 18:32:19 +00:00

Try to test serving SRT server

This commit is contained in:
Yohann D'ANELLO 2020-09-30 16:53:15 +02:00
parent 2096643ab4
commit ddd8be155e
3 changed files with 53 additions and 1 deletions

View File

@ -82,6 +82,10 @@ func RegisterStream(name string) error {
// SendPacket forward data to all FFMpeg instances related to the stream name // SendPacket forward data to all FFMpeg instances related to the stream name
func SendPacket(name string, data []byte) { func SendPacket(name string, data []byte) {
stdin := ffmpegInputStreams[name] stdin := ffmpegInputStreams[name]
if stdin == nil {
// Don't need to forward stream
return
}
_, err := (*stdin).Write(data) _, err := (*stdin).Write(data)
if err != nil { if err != nil {
log.Printf("Error while sending a packet to external streaming server for key %s: %s", name, err) log.Printf("Error while sending a packet to external streaming server for key %s: %s", name, err)
@ -91,6 +95,10 @@ func SendPacket(name string, data []byte) {
// CloseConnection When the stream is ended, close FFMPEG instances // CloseConnection When the stream is ended, close FFMPEG instances
func CloseConnection(name string) error { func CloseConnection(name string) error {
ffmpeg := ffmpegInstances[name] ffmpeg := ffmpegInstances[name]
if ffmpeg == nil {
// No stream to close
return nil
}
if err := ffmpeg.Process.Kill(); err != nil { if err := ffmpeg.Process.Kill(); err != nil {
return err return err
} }

View File

@ -40,7 +40,9 @@ func Serve(cfg *Options) {
log.Printf("SRT server listening on %s", cfg.ListenAddress) log.Printf("SRT server listening on %s", cfg.ListenAddress)
host, port := splitHostPort(cfg.ListenAddress) host, port := splitHostPort(cfg.ListenAddress)
sck := srtgo.NewSrtSocket(host, uint16(port), options) sck := srtgo.NewSrtSocket(host, uint16(port), options)
sck.Listen(cfg.MaxClients) if err := sck.Listen(cfg.MaxClients); err != nil {
log.Fatal("Unable to listen to SRT clients:", err)
}
// FIXME: See srtgo.SocketOptions and value, err := s.GetSockOptString to get parameters // FIXME: See srtgo.SocketOptions and value, err := s.GetSockOptString to get parameters
// http://ffmpeg.org/ffmpeg-protocols.html#srt // http://ffmpeg.org/ffmpeg-protocols.html#srt

View File

@ -1,9 +1,14 @@
package srt package srt
import ( import (
"bufio"
"log"
"os/exec"
"testing" "testing"
"time"
) )
// TestSplitHostPort Try to split a host like 127.0.0.1:1234 in host, port (127.0.0.1, 1234à
func TestSplitHostPort(t *testing.T) { func TestSplitHostPort(t *testing.T) {
host, port := splitHostPort("127.0.0.1:1234") host, port := splitHostPort("127.0.0.1:1234")
if host != "127.0.0.1" || port != 1234 { if host != "127.0.0.1" || port != 1234 {
@ -15,3 +20,40 @@ func TestSplitHostPort(t *testing.T) {
t.Errorf("splitHostPort returned %v:%d != 0.0.0.0:1234", host, port) t.Errorf("splitHostPort returned %v:%d != 0.0.0.0:1234", host, port)
} }
} }
// TestServeSRT Serve a SRT server, stream content during 5 seconds and ensure that it is well received
func TestServeSRT(t *testing.T) {
go Serve(&Options{ListenAddress: ":9711", MaxClients: 2})
ffmpeg := exec.Command("ffmpeg",
"-i", "http://ftp.crans.org/events/Blender%20OpenMovies/big_buck_bunny_480p_stereo.ogg",
"-f", "flv", "srt://127.0.0.1:9711")
output, err := ffmpeg.StdoutPipe()
errOutput, err := ffmpeg.StderrPipe()
if err != nil {
t.Fatal("Error while querying ffmpeg output:", err)
}
if err := ffmpeg.Start(); err != nil {
t.Fatal("Error while starting ffmpeg:", err)
}
go func() {
scanner := bufio.NewScanner(output)
for scanner.Scan() {
log.Printf("[FFMPEG TEST] %s", scanner.Text())
}
}()
go func() {
scanner := bufio.NewScanner(errOutput)
for scanner.Scan() {
log.Printf("[FFMPEG ERR TEST] %s", scanner.Text())
}
}()
time.Sleep(5000000000) // Delay is in nanoseconds, here 5s
// TODO Check that the stream ran
}