mirror of https://bitbucket.org/ausocean/av.git
rtmp: added streaming from file testing
This commit is contained in:
parent
076a9c030a
commit
d9c98a0341
|
@ -33,6 +33,10 @@ import (
|
|||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/av/stream/flv"
|
||||
"bitbucket.org/ausocean/av/stream/lex"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -44,7 +48,7 @@ const (
|
|||
)
|
||||
|
||||
// debug enables extra logging
|
||||
var testDebug bool
|
||||
var testDebug = true
|
||||
|
||||
// testKey is the RTMP key required for YouTube streaming (RTMP_TEST_KEY env var)
|
||||
var testKey string
|
||||
|
@ -81,7 +85,7 @@ func testLog(level int8, msg string, params ...interface{}) {
|
|||
|
||||
func TestKey(t *testing.T) {
|
||||
testLog(0, "TestKey")
|
||||
testKey := os.Getenv("RTMP_TEST_KEY")
|
||||
testKey = os.Getenv("RTMP_TEST_KEY")
|
||||
if testKey == "" {
|
||||
t.Errorf("RTMP_TEST_KEY environment variable not defined")
|
||||
os.Exit(1)
|
||||
|
@ -134,28 +138,43 @@ func TestOpenClose(t *testing.T) {
|
|||
|
||||
func TestFromFile(t *testing.T) {
|
||||
testLog(0, "TestFromFile")
|
||||
testFile := os.Getenv("RTMP_TEST_FILE")
|
||||
if testKey == "" {
|
||||
t.Errorf("RTMP_TEST_FILE environment variable not defined")
|
||||
os.Exit(1)
|
||||
}
|
||||
s := NewSession(testBaseURL+testKey, testTimeout, testLog)
|
||||
err := s.Open()
|
||||
if err != nil {
|
||||
t.Errorf("Session.Open failed with error: %v", err)
|
||||
}
|
||||
video, err := ioutil.ReadFile(testFile)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot open video file: %v", testFile)
|
||||
}
|
||||
// ToDo: rate limit writing
|
||||
n, err := s.Write(video)
|
||||
if err != nil {
|
||||
t.Errorf("Session.Write failed with error: %v", err)
|
||||
}
|
||||
if n != len(video) {
|
||||
t.Errorf("Session.Write retuned wrong length")
|
||||
|
||||
// This read from a h264 file
|
||||
if true {
|
||||
// Open file
|
||||
f, err := os.Open("../../test/test-data/av/input/betterInput.h264")
|
||||
if err != nil {
|
||||
t.Errorf("Cannot open video file: %v", testFile)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Passing rtmp session, true for audio, true for video, and 25 fps
|
||||
flvEncoder := flv.NewEncoder(s, true, true, 25)
|
||||
err = lex.H264(flvEncoder, f, time.Second/time.Duration(25))
|
||||
if err != nil {
|
||||
t.Errorf("Lexing and encoding failed with error: %v", err)
|
||||
}
|
||||
|
||||
// This reads a single h264 frame and sends
|
||||
} else {
|
||||
b, err := ioutil.ReadFile("/home/saxon/Downloads/ausoceanFrame.h264") // b has type []byte
|
||||
if err != nil {
|
||||
t.Errorf("Could not read file, failed with error: %v", err)
|
||||
}
|
||||
flvEncoder := flv.NewEncoder(s, true, true, 25)
|
||||
for i := 0; i < 10000; i++ {
|
||||
err := flvEncoder.Encode(b)
|
||||
if err != nil {
|
||||
t.Errorf("Encoding failed!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Session.Close failed with error: %v", err)
|
||||
|
|
Loading…
Reference in New Issue