mirror of https://bitbucket.org/ausocean/av.git
Using ReadAll for reding instead of just read
This commit is contained in:
parent
eda6fc54bd
commit
b3a57557e2
|
@ -28,6 +28,7 @@ LICENSE
|
|||
package parser
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
|
@ -37,6 +38,8 @@ import (
|
|||
const (
|
||||
mjpegInputFileName = "testInput/testInput.avi"
|
||||
h264fName = "../../test/test-data/av/input/betterInput.h264"
|
||||
nOfFrames = 4
|
||||
outChanSize = 100
|
||||
)
|
||||
|
||||
func TestH264Parser(t *testing.T) {
|
||||
|
@ -48,16 +51,8 @@ func TestH264Parser(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Println("Getting file stats!")
|
||||
stats, err := inputFile.Stat()
|
||||
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)
|
||||
log.Println("Reading data from file!")
|
||||
data, err := ioutil.ReadAll(inputFile)
|
||||
if err != nil {
|
||||
t.Errorf("Should not have got read error!")
|
||||
return
|
||||
|
@ -66,7 +61,7 @@ func TestH264Parser(t *testing.T) {
|
|||
// Create 'parser' and start it up
|
||||
log.Println("Creating parser!")
|
||||
parser := NewH264Parser()
|
||||
parser.SetOutputChan(make(chan []byte, 10000))
|
||||
parser.SetOutputChan(make(chan []byte, outChanSize))
|
||||
parser.Start()
|
||||
|
||||
count := 0
|
||||
|
@ -75,7 +70,7 @@ func TestH264Parser(t *testing.T) {
|
|||
// nothing
|
||||
select {
|
||||
case parser.InputChan() <- data[i]:
|
||||
case frame:=<-parser.OutputChan():
|
||||
case frame := <-parser.OutputChan():
|
||||
outputFile, err := os.Create("testOutput/" + strconv.Itoa(count) + ".h264_frame")
|
||||
if err != nil {
|
||||
t.Errorf("Should not have got error creating output file!")
|
||||
|
@ -84,7 +79,7 @@ func TestH264Parser(t *testing.T) {
|
|||
outputFile.Write(frame)
|
||||
outputFile.Close()
|
||||
count++
|
||||
if count > 4 {
|
||||
if count > nOfFrames {
|
||||
return
|
||||
}
|
||||
default:
|
||||
|
@ -92,7 +87,6 @@ func TestH264Parser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
func TestMJPEGParser(t *testing.T) {
|
||||
log.Println("Opening input file!")
|
||||
|
|
Loading…
Reference in New Issue