Test stream forwarding, but disable it while the project structure is not clean, ie. to avoid that forwarding is a dependency to srt

This commit is contained in:
Yohann D'ANELLO 2020-10-01 11:20:34 +02:00
parent cc4c556f2c
commit dc7a3fef9f
2 changed files with 101 additions and 7 deletions

View File

@ -1 +1,96 @@
package forwarding
import (
"bufio"
"gitlab.crans.org/nounous/ghostream/stream/srt"
"log"
"os/exec"
"testing"
"time"
)
// TestServeSRT Serve a SRT server, stream content during 5 seconds and ensure that it is well received
func TestForwardStream(t *testing.T) {
which := exec.Command("which", "ffmpeg")
if err := which.Start(); err != nil {
t.Fatal("Error while checking if ffmpeg got installed:", err)
}
state, err := which.Process.Wait()
if err != nil {
t.Fatal("Error while checking if ffmpeg got installed:", err)
}
if state.ExitCode() != 0 {
// FFMPEG is not installed
t.Skip("WARNING: FFMPEG is not installed. Skipping stream test")
}
forwardedFfmpeg := exec.Command("ffmpeg",
"-f", "flv", "-listen", "1", "-i", "rtmp://127.0.0.1:1936/live/app", "-c", "copy", "/dev/null")
forwardingOutput, err := forwardedFfmpeg.StdoutPipe()
forwardingErrOutput, err := forwardedFfmpeg.StderrPipe()
if err != nil {
t.Fatal("Error while querying ffmpeg forwardingOutput:", err)
}
if err := forwardedFfmpeg.Start(); err != nil {
t.Fatal("Error while starting forwarding stream ffmpeg instance:", err)
}
go func() {
scanner := bufio.NewScanner(forwardingOutput)
for scanner.Scan() {
log.Printf("[FFMPEG FORWARD TEST] %s", scanner.Text())
}
}()
go func() {
scanner := bufio.NewScanner(forwardingErrOutput)
for scanner.Scan() {
log.Printf("[FFMPEG FORWARD ERR TEST] %s", scanner.Text())
}
}()
forwardingList := make(map[string][]string)
forwardingList["demo"] = []string{"rtmp://127.0.0.1:1936/live/app"}
// Register forwarding stream list
New(forwardingList)
// Serve HTTP Server
go srt.Serve(&srt.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 forwardingOutput:", 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
if ffmpegInputStreams["demo"] == nil {
t.Errorf("Stream forwarding does not appear to be working")
}
// TODO Check that the stream ran
}

View File

@ -6,7 +6,6 @@ import (
"strconv"
"github.com/haivision/srtgo"
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
)
// Options holds web package configuration
@ -60,10 +59,10 @@ func Serve(cfg *Options) {
// Setup stream forwarding
// FIXME: demo should be replaced by stream name
if err := forwarding.RegisterStream("demo"); err != nil {
/* if err := forwarding.RegisterStream("demo"); err != nil {
log.Println("Error occurred during forward stream init:", err)
break
}
} */
// Read RTP packets forever and send them to the WebRTC Client
for {
@ -79,18 +78,18 @@ func Serve(cfg *Options) {
break
}
log.Printf("Received %d bytes", n)
// log.Printf("Received %d bytes", n)
// Send raw packet to other streams
forwarding.SendPacket("demo", buff[:n])
// forwarding.SendPacket("demo", buff[:n])
// TODO: Send to WebRTC
// See https://github.com/ebml-go/webm/blob/master/reader.go
//err := videoTrack.WriteSample(media.Sample{Data: data, Samples: uint32(sampleCount)})
}
if err := forwarding.CloseConnection("demo"); err != nil {
/* if err := forwarding.CloseConnection("demo"); err != nil {
log.Printf("Failed to close forward stream: %s", err)
}
} */
}
}