From ead135496acc8c98e06df316605b6d5a65448ed0 Mon Sep 17 00:00:00 2001 From: scruzin Date: Sat, 2 Feb 2019 12:23:20 +1030 Subject: [PATCH 1/4] rtmp: Use a net.Conn interface instead of *net.TCPConn. --- rtmp/conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtmp/conn.go b/rtmp/conn.go index 3864df98..7e1b3b15 100644 --- a/rtmp/conn.go +++ b/rtmp/conn.go @@ -76,7 +76,7 @@ type link struct { protocol int32 timeout uint port uint16 - conn *net.TCPConn + conn net.Conn } // method represents an RTMP method. From e0471d5e2c467356853106c4ffabf674ac887b7b Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 8 Mar 2019 17:45:38 +1030 Subject: [PATCH 2/4] Initial revision. --- revid/revid_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 revid/revid_test.go diff --git a/revid/revid_test.go b/revid/revid_test.go new file mode 100644 index 00000000..692633e5 --- /dev/null +++ b/revid/revid_test.go @@ -0,0 +1,60 @@ +package revid + +import ( + "fmt" + "os" + "runtime" + "testing" + + "bitbucket.org/ausocean/iot/pi/netsender" +) + +// Supress all test logging, except for t.Errorf output. +var silent bool + +func TestRaspivid(t *testing.T) { + var logger testLogger + ns, err := netsender.New(&logger, nil, nil, nil) + if err != nil { + t.Errorf("netsender.New failed with error %v", err) + } + + var c Config + c.Logger = &logger + c.Input = Raspivid + c.Outputs = make([]uint8, 1) + + rv, err := New(c, ns) + if err != nil { + t.Errorf("revid.New failed with error %v", err) + } + + err = rv.Start() + if err != nil { + t.Errorf("revid.Start failed with error %v", err) + } +} + +// testLogger implements a netsender.Logger. +type testLogger struct {} + +func (tl *testLogger) SetLevel(level int8) { +} + +// Log requests the Logger to write a message at the given level. +func (tl *testLogger) Log(level int8, msg string, params ...interface{}) { + logLevels := [...]string{"Debug", "Info", "Warn", "Error", "", "", "Fatal"} + if level < -1 || level > 5 { + panic("Invalid log level") + } + if !silent { + fmt.Printf("%s: %s\n", logLevels[level+1], msg) + } + if level >= 4 { + // Error or Fatal + buf := make([]byte, 1<<16) + size := runtime.Stack(buf, true) + fmt.Printf("%s\n", string(buf[:size])) + os.Exit(1) + } +} From db265404eb6b2e760254f19837cbb6c2395b648e Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 8 Mar 2019 20:43:01 +1030 Subject: [PATCH 3/4] Skip if raspivid not present. --- revid/revid_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/revid/revid_test.go b/revid/revid_test.go index 692633e5..6f2fd6df 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -5,20 +5,26 @@ import ( "os" "runtime" "testing" - + "bitbucket.org/ausocean/iot/pi/netsender" ) -// Supress all test logging, except for t.Errorf output. +const raspividPath = "/usr/local/bin/raspivid" + +// Suppress all test logging, except for t.Errorf output. var silent bool func TestRaspivid(t *testing.T) { + if _, err := os.Stat(raspividPath); os.IsNotExist(err) { + t.Skip("Skipping TestRaspivid since no raspivid found.") + } + var logger testLogger ns, err := netsender.New(&logger, nil, nil, nil) if err != nil { t.Errorf("netsender.New failed with error %v", err) } - + var c Config c.Logger = &logger c.Input = Raspivid @@ -28,7 +34,7 @@ func TestRaspivid(t *testing.T) { if err != nil { t.Errorf("revid.New failed with error %v", err) } - + err = rv.Start() if err != nil { t.Errorf("revid.Start failed with error %v", err) @@ -36,7 +42,7 @@ func TestRaspivid(t *testing.T) { } // testLogger implements a netsender.Logger. -type testLogger struct {} +type testLogger struct{} func (tl *testLogger) SetLevel(level int8) { } From 437470b53ff13a085a3d0504c6e60549ee84f558 Mon Sep 17 00:00:00 2001 From: scruzin Date: Sat, 9 Mar 2019 06:57:55 +1030 Subject: [PATCH 4/4] Only dump stack for Fatal log messages. --- revid/revid_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/revid/revid_test.go b/revid/revid_test.go index 6f2fd6df..d88e4e9a 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -14,6 +14,8 @@ const raspividPath = "/usr/local/bin/raspivid" // Suppress all test logging, except for t.Errorf output. var silent bool +// TestRaspivid tests that raspivid starts correctly. +// It is intended to be run on a Raspberry Pi. func TestRaspivid(t *testing.T) { if _, err := os.Stat(raspividPath); os.IsNotExist(err) { t.Skip("Skipping TestRaspivid since no raspivid found.") @@ -44,6 +46,7 @@ func TestRaspivid(t *testing.T) { // testLogger implements a netsender.Logger. type testLogger struct{} +// SetLevel normally sets the logging level, but it is a no-op in our case. func (tl *testLogger) SetLevel(level int8) { } @@ -56,8 +59,7 @@ func (tl *testLogger) Log(level int8, msg string, params ...interface{}) { if !silent { fmt.Printf("%s: %s\n", logLevels[level+1], msg) } - if level >= 4 { - // Error or Fatal + if level == 5 { buf := make([]byte, 1<<16) size := runtime.Stack(buf, true) fmt.Printf("%s\n", string(buf[:size]))