From fd730a5235a982c684d18f9580652850fb91a9ba Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Wed, 4 Jul 2018 00:12:44 +0930 Subject: [PATCH] need to update remote --- parser/parser_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index c23e85e6..f79454ec 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -8,9 +8,63 @@ import ( ) const ( - testInputFileName = "testInput/testInput.avi" + mjpegInputFileName = "testInput/testInput.avi" + h264InputFileName = "bitbucket.org/ausocean/test/test-data/av/input/betterInput.h264" ) +func TestH264Parser(t *testing.T) { + fmt.Println("Opening input file!") + // Open the input file + inputFile, err := os.Open(h264InputFileName) + if err != nil { + t.Errorf("Should not have got error opening file!") + } + fmt.Println("Getting file stats!") + stats, err := inputFile.Stat() + if err != nil { + t.Errorf("Could not get input file stats!") + return + } + fmt.Println("Creating space for file data!") + data := make([]byte, stats.Size()) + _, err = inputFile.Read(data) + if err != nil { + t.Errorf("Should not have got read error!") + return + } + fmt.Println("Creating parser!") + parser := NewH264Parser(len(data) + 1) + parser.SetOutputChan(make(chan []byte, 10000)) + parser.Start() + fmt.Printf("len(data): %v\n", len(data)) + + count := 0 + for i := range data { + parser.GetInputChan() <- data[i] + select { + case frame:=<-parser.GetOutputChan() + outputFile, err := os.Create("") + count++ + if count > 4 { + return + } + default: + } + } + for i := 0; len(parser.GetOutputChan()) > 0; i++ { + // Open a new output file + outputFile, err := os.Create("testOutput/image" + strconv.Itoa(i) + ".jpeg") + if err != nil { + t.Errorf("Should not have got error creating output file!") + return + } + outputFile.Write(<-parser.GetOutputChan()) + outputFile.Close() + } +} + + +/* func TestMJPEGParser(t *testing.T) { fmt.Println("Opening input file!") // Open the input file @@ -51,3 +105,4 @@ func TestMJPEGParser(t *testing.T) { outputFile.Close() } } +*/