Merged in revidTestingImrpovement (pull request #38)

RevidTestingImrpovement

Approved-by: saxon.milton@gmail.com <saxon.milton@gmail.com>
This commit is contained in:
saxon.milton@gmail.com 2018-07-05 00:42:53 +00:00
commit c9b162cc0b
6 changed files with 157 additions and 37 deletions

View File

@ -130,7 +130,7 @@ func (p *H264) parse() {
return return
} }
outputBuffer = append(outputBuffer, aByte) outputBuffer = append(outputBuffer, aByte)
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 || nalType == 8 { if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 || nalType == 8 || nalType == 7 {
searchingForEnd = true searchingForEnd = true
} }
} }

View File

@ -1,53 +1,127 @@
/*
NAME
parser_test.go
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon@ausocean.org>
LICENSE
parser_test.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
package parser package parser
import ( import (
"fmt" "fmt"
"io/ioutil"
"log"
"os" "os"
"strconv" "strconv"
"testing" "testing"
) )
const ( const (
testInputFileName = "testInput/testInput.avi" mjpegInputFileName = "testInput/testInput.avi"
h264fName = "../../test/test-data/av/input/betterInput.h264"
nOfFrames = 4
outChanSize = 100
) )
func TestH264Parser(t *testing.T) {
log.SetOutput(os.Stderr)
log.Println("Opening input file!")
inputFile, err := os.Open(h264fName)
if err != nil {
t.Errorf("Should not have got error opening file!")
return
}
log.Println("Reading data from file!")
data, err := ioutil.ReadAll(inputFile)
if err != nil {
t.Errorf("Should not have got read error!")
return
}
// Create 'parser' and start it up
log.Println("Creating parser!")
parser := NewH264Parser()
parser.SetOutputChan(make(chan []byte, outChanSize))
parser.Start()
for i, n := 0, 0; n <= nOfFrames; i++ {
select {
case parser.InputChan() <- data[i]:
case frame := <-parser.OutputChan():
path := fmt.Sprintf("testOutput/" + strconv.Itoa(n) + "h264_frame")
out, err := os.Create(path)
if err != nil {
t.Errorf("Unexpected error creating %q: %v", path, err)
return
}
out.Write(frame)
out.Close()
n++
default:
}
}
}
/*
func TestMJPEGParser(t *testing.T) { func TestMJPEGParser(t *testing.T) {
fmt.Println("Opening input file!") log.Println("Opening input file!")
// Open the input file // Open the input file
inputFile, err := os.Open(testInputFileName) inputFile, err := os.Open(testInputFileName)
if err != nil { if err != nil {
t.Errorf("Should not have got error opening file!") t.Errorf("Should not have got error opening file!")
} }
fmt.Println("Getting file stats!") log.Println("Getting file stats!")
stats, err := inputFile.Stat() stats, err := inputFile.Stat()
if err != nil { if err != nil {
t.Errorf("Could not get input file stats!") t.Errorf("Could not get input file stats!")
return return
} }
fmt.Println("Creating space for file data!") log.Println("Creating space for file data!")
data := make([]byte, stats.Size()) data := make([]byte, stats.Size())
_, err = inputFile.Read(data) _, 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
} }
fmt.Println("Creating parser!") log.Println("Creating parser!")
parser := NewMJPEGParser(len(data) + 1) parser := NewMJPEGParser(len(data) + 1)
parser.SetOutputChan(make(chan []byte, 10000)) parser.SetOutputChan(make(chan []byte, 10000))
parser.Start() parser.Start()
fmt.Printf("len(data): %v\n", len(data)) log.Printf("len(data): %v\n", len(data))
for i := range data { for i := range data {
parser.GetInputChan() <- data[i] parser.GetInputChan() <- data[i]
} }
fmt.Println("Writing jpegs to files!") log.Println("Writing jpegs to files!")
for i := 0; len(parser.GetOutputChan()) > 0; i++ { for i := 0; len(parser.GetOutputChan()) > 0; i++ {
// Open a new output file // Open a new output file
outputFile, err := os.Create("testOutput/image" + strconv.Itoa(i) + ".jpeg") out, err := os.Create("testOutput/image" + strconv.Itoa(i) + ".jpeg")
if err != nil { if err != nil {
t.Errorf("Should not have got error creating output file!") t.Errorf("Should not have got error creating output file!")
return return
} }
outputFile.Write(<-parser.GetOutputChan()) out.Write(<-parser.GetOutputChan())
outputFile.Close() out.Close()
} }
} }
*/

Binary file not shown.

View File

@ -0,0 +1,71 @@
/*
NAME
main.go
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon@ausocean.org>
LICENSE
main.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
package main
import (
"flag"
"log"
"time"
"bitbucket.org/ausocean/av/revid"
)
const (
inputFile = "../../../../test/test-data/av/input/betterInput.h264"
frameRate = "25"
runDuration = 120 * time.Second
)
// Test h264 inputfile to flv format into rtmp using librtmp c wrapper
func main() {
// Get the rtmp url from a cmd flag
rtmpUrlPtr := flag.String("rtmpUrl", "", "The rtmp url you would like to stream to.")
flag.Parse()
if *rtmpUrlPtr == "" {
log.Println("No RTMP url passed!")
return
}
config := revid.Config{
Input: revid.File,
InputFileName: inputFile,
InputCodec: revid.H264,
Output: revid.Rtmp,
RtmpMethod: revid.LibRtmp,
RtmpUrl: *rtmpUrlPtr,
Packetization: revid.Flv,
}
revidInst, err := revid.New(config, nil)
if err != nil {
log.Printf("Should not of have got an error!: %v\n", err.Error())
return
}
revidInst.Start()
time.Sleep(runDuration)
revidInst.Stop()
}

View File

@ -96,31 +96,6 @@ func TestRaspividMJPEGInput(t *testing.T){
// Test revidInst with rtmp output
func TestRtmpOutput(t *testing.T){
config := Config{
Input: File,
InputFileName: "testInput.h264",
InputCodec: H264,
Output: Rtmp,
RtmpUrl: "rtmp://a.rtmp.youtube.com/live2/w44c-mkuu-aezg-ceb1",
Width: "1280",
Height: "720",
FrameRate: "25",
Packetization: None,
FramesPerClip: 1,
}
revidInst, err := NewRevidInstance(config)
if err != nil {
t.Errorf("Should not of have got an error!: %v\n", err.Error())
return
}
revidInst.Start()
time.Sleep(120*time.Second)
revidInst.Stop()
}
// Test h264 inputfile to flv output files // Test h264 inputfile to flv output files
func TestFlvOutputFile(t *testing.T) { func TestFlvOutputFile(t *testing.T) {

View File

@ -30,7 +30,7 @@ package rtmp
/* /*
#cgo CFLAGS: -I/usr/local/include/librtmp #cgo CFLAGS: -I/usr/local/include/librtmp
#cgo LDFLAGS: -lrtmp -lz #cgo LDFLAGS: -lrtmp -lz -Wl,-rpath=/usr/local/lib
#include <stdlib.h> #include <stdlib.h>
#include <rtmp.h> #include <rtmp.h>