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"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"bitbucket.org/ausocean/av/stream/flv"
|
||||||
|
"bitbucket.org/ausocean/av/stream/lex"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -44,7 +48,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// debug enables extra logging
|
// debug enables extra logging
|
||||||
var testDebug bool
|
var testDebug = true
|
||||||
|
|
||||||
// testKey is the RTMP key required for YouTube streaming (RTMP_TEST_KEY env var)
|
// testKey is the RTMP key required for YouTube streaming (RTMP_TEST_KEY env var)
|
||||||
var testKey string
|
var testKey string
|
||||||
|
@ -81,7 +85,7 @@ func testLog(level int8, msg string, params ...interface{}) {
|
||||||
|
|
||||||
func TestKey(t *testing.T) {
|
func TestKey(t *testing.T) {
|
||||||
testLog(0, "TestKey")
|
testLog(0, "TestKey")
|
||||||
testKey := os.Getenv("RTMP_TEST_KEY")
|
testKey = os.Getenv("RTMP_TEST_KEY")
|
||||||
if testKey == "" {
|
if testKey == "" {
|
||||||
t.Errorf("RTMP_TEST_KEY environment variable not defined")
|
t.Errorf("RTMP_TEST_KEY environment variable not defined")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -134,28 +138,43 @@ func TestOpenClose(t *testing.T) {
|
||||||
|
|
||||||
func TestFromFile(t *testing.T) {
|
func TestFromFile(t *testing.T) {
|
||||||
testLog(0, "TestFromFile")
|
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)
|
s := NewSession(testBaseURL+testKey, testTimeout, testLog)
|
||||||
err := s.Open()
|
err := s.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Session.Open failed with error: %v", err)
|
t.Errorf("Session.Open failed with error: %v", err)
|
||||||
}
|
}
|
||||||
video, err := ioutil.ReadFile(testFile)
|
|
||||||
if err != nil {
|
// This read from a h264 file
|
||||||
t.Errorf("Cannot open video file: %v", testFile)
|
if true {
|
||||||
}
|
// Open file
|
||||||
// ToDo: rate limit writing
|
f, err := os.Open("../../test/test-data/av/input/betterInput.h264")
|
||||||
n, err := s.Write(video)
|
if err != nil {
|
||||||
if err != nil {
|
t.Errorf("Cannot open video file: %v", testFile)
|
||||||
t.Errorf("Session.Write failed with error: %v", err)
|
}
|
||||||
}
|
defer f.Close()
|
||||||
if n != len(video) {
|
|
||||||
t.Errorf("Session.Write retuned wrong length")
|
// 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()
|
err = s.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Session.Close failed with error: %v", err)
|
t.Errorf("Session.Close failed with error: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue