Fixed h264 Parser - now to test on pi again

This commit is contained in:
Unknown 2018-01-11 16:43:21 +10:30
parent dd05c13110
commit 86dc14fa7a
3 changed files with 23 additions and 56 deletions

View File

@ -29,9 +29,11 @@ LICENSE
package h264
import (
"bitbucket.org/ausocean/av/itut"
"../itut"
"log"
"sync"
_"fmt"
_"time"
)
const (
@ -55,59 +57,29 @@ func (p* H264Parser)Stop(){
}
func (p* H264Parser)Parse() {
p.isParsing = true
p.isParsing = true
outputBuffer := []byte{}
searchingForEnd := false
searchingForEnd := false
p.InputByteChan = make(chan byte, 10000)
for p.isParsing {
aByte := <-p.InputByteChan
aByte := <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte)
for i:=1; aByte == 0x00 && i != 4; i++ {
aByte = <-p.InputByteChan
aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte)
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
if searchingForEnd {
outputBuffer = outputBuffer[:len(outputBuffer)-(i+1)]
p.OutputChan<-append(append(itut.StartCode1(),itut.AUD()...),outputBuffer...)
outputBuffer = []byte{}
searchingForEnd = false
output := append(append(itut.StartCode1(),itut.AUD()...),outputBuffer[:len(outputBuffer)-(i+1)]...)
p.OutputChan<-output
outputBuffer = outputBuffer[len(outputBuffer)-1-i:]
searchingForEnd = false
}
aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte)
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 {
searchingForEnd = true
searchingForEnd = true
}
}
}
}
/*
for p.isParsing {
aByte := <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte)
for i:=1; aByte == 0x00 && i != 4; i++ {
aByte = <-p.InputByteChan
outputbuffer = append(outputBuffer, aByte)
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte)
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 {
for {
aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer,aByte)
for i := 1; aByte == 0x00; i++ {
aByte = <-p.InputByteChan
outputbuffer = append(outputBuffer, aByte)
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
outputBuffer = outputBuffer[:len(outputBuffer)-(i+1)]
outputChan<-append(append(itut.StartCode1(),itut.AUD()...),outputBuffer...)
outputBuffer = []byte{}
}
}
}
}
}
}
}
*/
}

View File

@ -45,8 +45,8 @@ import (
"time"
"io"
"bitbucket.org/ausocean/av/h264"
"bitbucket.org/ausocean/av/tsgenerator"
"../h264"
"../tsgenerator"
"bitbucket.org/ausocean/av/ringbuffer"
)
@ -85,7 +85,7 @@ type Config struct {
InputCmd string
Output uint8
OutputFileName string
InputFileName string
InputFileName string
}
type RevidInst interface {
@ -154,8 +154,8 @@ func (r *revidInst) input() {
generator := tsgenerator.NewTsGenerator(framesPerSec)
go generator.Generate()
h264Parser := h264.H264Parser{OutputChan: generator.NalInputChan}
// TODO: Need to create constructor for parser otherwise I'm going to break
// something eventuallyl
// TODO: Need to create constructor for parser otherwise I'm going to break
// something eventuallyl
go h264Parser.Parse()
var inputReader *bufio.Reader
switch r.config.Input {
@ -169,8 +169,8 @@ func (r *revidInst) input() {
return
}
case file:
default:
r.Error.Println("Input not valid!")
}
@ -211,15 +211,11 @@ func (r *revidInst) input() {
if err != nil {
r.Error.Println(err.Error())
}
fmt.Println("about to start sending data")
for i := range h264Data {
fmt.Printf("i: %v\n", i)
h264Parser.InputByteChan<-h264Data[i]
}
fmt.Println("all data sent")
}
if clip, err := r.ringBuffer.Get(); err != nil {
r.Error.Println(err.Error())
return
@ -235,7 +231,6 @@ func (r *revidInst) input() {
if err != nil {
fmt.Println(err)
}
fmt.Println("getting ts packet")
tsPacket := <-generator.TsChan
byteSlice, err := tsPacket.ToByteSlice()
if err != nil {

View File

@ -31,10 +31,10 @@ package tsgenerator
import (
_ "fmt"
_"os"
"bitbucket.org/ausocean/av/mpegts"
"bitbucket.org/ausocean/av/pes"
"bitbucket.org/ausocean/av/tools"
"bitbucket.org/ausocean/av/rtp"
"../mpegts"
"../pes"
"../tools"
"../rtp"
)
type TsGenerator interface {