Using ReadAll for reding instead of just read

This commit is contained in:
saxon 2018-07-04 22:05:38 +09:30
parent eda6fc54bd
commit b3a57557e2
1 changed files with 9 additions and 15 deletions

View File

@ -28,6 +28,7 @@ LICENSE
package parser package parser
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
"strconv" "strconv"
@ -37,6 +38,8 @@ import (
const ( const (
mjpegInputFileName = "testInput/testInput.avi" mjpegInputFileName = "testInput/testInput.avi"
h264fName = "../../test/test-data/av/input/betterInput.h264" h264fName = "../../test/test-data/av/input/betterInput.h264"
nOfFrames = 4
outChanSize = 100
) )
func TestH264Parser(t *testing.T) { func TestH264Parser(t *testing.T) {
@ -48,16 +51,8 @@ func TestH264Parser(t *testing.T) {
return return
} }
log.Println("Getting file stats!") log.Println("Reading data from file!")
stats, err := inputFile.Stat() data, err := ioutil.ReadAll(inputFile)
if err != nil {
t.Errorf("Could not get input file stats!")
return
}
log.Println("Creating space for file data and reading!")
data := make([]byte, stats.Size())
_, err = inputFile.Read(data)
if err != nil { if err != nil {
t.Errorf("Should not have got read error!") t.Errorf("Should not have got read error!")
return return
@ -66,7 +61,7 @@ func TestH264Parser(t *testing.T) {
// Create 'parser' and start it up // Create 'parser' and start it up
log.Println("Creating parser!") log.Println("Creating parser!")
parser := NewH264Parser() parser := NewH264Parser()
parser.SetOutputChan(make(chan []byte, 10000)) parser.SetOutputChan(make(chan []byte, outChanSize))
parser.Start() parser.Start()
count := 0 count := 0
@ -84,7 +79,7 @@ func TestH264Parser(t *testing.T) {
outputFile.Write(frame) outputFile.Write(frame)
outputFile.Close() outputFile.Close()
count++ count++
if count > 4 { if count > nOfFrames {
return return
} }
default: default:
@ -92,7 +87,6 @@ func TestH264Parser(t *testing.T) {
} }
} }
/* /*
func TestMJPEGParser(t *testing.T) { func TestMJPEGParser(t *testing.T) {
log.Println("Opening input file!") log.Println("Opening input file!")