Starting editing files to incorperate new mjpeg functionality

This commit is contained in:
Unknown 2018-01-29 17:04:08 +10:30
parent b0eb07dbe9
commit 4ff3092f4a
5 changed files with 111 additions and 15 deletions

View File

@ -1,7 +1,6 @@
/*
NAME
RtpToTsConverter.go - provides utilities for the conversion of Rtp packets
to equivalent MpegTs packets.
Parser.go
DESCRIPTION
See Readme.md
@ -36,6 +35,7 @@ import (
_"time"
)
// h264 consts
const (
acceptedLength = 1000
)
@ -45,31 +45,47 @@ var (
mutex *sync.Mutex
)
type H264Parser struct {
type Parser interface {
Stop()
Start()
GetInputChan()
GetOutputChan()
}
type h264Parser struct {
inputBuffer []byte
isParsing bool
OutputChan chan<- []byte
InputByteChan chan byte
InputChan chan byte
}
func (p* H264Parser)Stop(){
func NewH264Parser() (p *h264Parser) {
p = new(h264Parser)
p.isParsing = true
p.InputChan = make(chan byte, 10000)
return
}
func (p* h264Parser)Stop(){
p.isParsing = false
}
func (p *H264Parser)Start(){
func (p *h264Parser)Start(){
go p.parse()
}
func (p *h264Parser)GetInput() chan byte {
}
func (p *H264Parser)parse() {
p.isParsing = true
outputBuffer := make([]byte, 0, 10000)
searchingForEnd := false
p.InputByteChan = make(chan byte, 10000)
for p.isParsing {
aByte := <-p.InputByteChan
aByte := <-p.InputChan
outputBuffer = append(outputBuffer, aByte)
for i:=1; aByte == 0x00 && i != 4; i++ {
aByte = <-p.InputByteChan
aByte = <-p.InputChan
outputBuffer = append(outputBuffer, aByte)
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
if searchingForEnd {
@ -78,7 +94,7 @@ func (p *H264Parser)parse() {
outputBuffer = outputBuffer[len(outputBuffer)-1-i:]
searchingForEnd = false
}
aByte = <-p.InputByteChan
aByte = <-p.InputChan
outputBuffer = append(outputBuffer, aByte)
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 {
searchingForEnd = true
@ -87,3 +103,46 @@ func (p *H264Parser)parse() {
}
}
}
type mjpegParser struct {
inputBuffer []byte
isParsing bool
outputChan chan<- []byte
inputChan chan byte
}
func NewMJPEGParser() (p *mjpegParser){
p = new(mjpegParser)
p.isParsing = true
p.InputChan = make(chan byte, 10000)
return
}
func (p *mjpegParser)Stop(){
p.isParsing = false
}
func (p *mjpegParser)Start(){
go p.parse()
}
func (p *mjpegParser)GetInput() chan byte {
return p.inputChan
}
func (p *mjpegParser)parse() {
outputBuffer := make([]byte, 0, 10000)
for p.isParsing {
aByte := <-p.InputChan
outputBuffer = append(outputBuffer, aByte)
if aByte = 0xFF && len(outputBuffer) > 1 {
aByte := <-p.InputChan
outputBuffer = append(outputBuffer, aByte)
if aByte = 0xD8 {
p.OutputChan<-output
outputBuffer = outputBuffer[len(outputBuffer)-1-i:]
}
}
}
}

37
parser/parser_test.go Normal file
View File

@ -0,0 +1,37 @@
package parser
import (
"testing"
)
const (
testInputFileName = "inputFiles/inputFile.avi"
)
func TestMJPEGParser(t *testing.T){
parser := NewMJPEGParser()
// TODO: Find mjpeg file and see if the mjpeg parser can output individual
// jpeg images...
inputFile, err = os.Open(testInputFileName)
if err != nil {
t.Errorf("Should not have got error opening file!")
}
stats, err := inputFile.Stat()
if err != nil {
t.Errorf("Could not get input file stats!")
return
}
data := make([]byte, stats.Size())
_, err = r.inputFile.Read(data)
if err != nil {
t.Errorf("Should not have got read error!")
return
}
for i := range data {
parser.InputByteChan <- data[i]
}
for len(parser.GetOutputByteChan()) > 0 {
}
}

Binary file not shown.

View File

@ -175,7 +175,7 @@ func (r *revidInst) Start() {
return
}
r.Log(Info, "Starting Revid!")
var h264Data []byte
var data []byte
switch r.config.Input {
case Raspivid:
r.Log(Info, "Starting raspivid!")
@ -192,8 +192,8 @@ func (r *revidInst) Start() {
go func() {
r.Log(Info, "Reading camera data!")
for r.isRunning {
h264Data = make([]byte, 1)
_, err := io.ReadFull(r.inputReader, h264Data)
data = make([]byte, 1)
_, err := io.ReadFull(r.inputReader, data)
switch {
case err != nil && err.Error() == "EOF" && r.isRunning:
r.Log(Error, "No data from camera!")
@ -201,7 +201,7 @@ func (r *revidInst) Start() {
case err != nil && r.isRunning:
r.Log(Error, err.Error())
default:
r.h264Parser.InputByteChan <- h264Data[0]
r.parser.GetInput() <-h264Data[0]
}
}
r.Log(Info, "Out of reading routine!")