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 package h264
import ( import (
"bitbucket.org/ausocean/av/itut" "../itut"
"log" "log"
"sync" "sync"
_"fmt"
_"time"
) )
const ( const (
@ -55,59 +57,29 @@ func (p* H264Parser)Stop(){
} }
func (p* H264Parser)Parse() { func (p* H264Parser)Parse() {
p.isParsing = true p.isParsing = true
outputBuffer := []byte{} outputBuffer := []byte{}
searchingForEnd := false searchingForEnd := false
p.InputByteChan = make(chan byte, 10000) p.InputByteChan = make(chan byte, 10000)
for p.isParsing { for p.isParsing {
aByte := <-p.InputByteChan aByte := <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte) outputBuffer = append(outputBuffer, aByte)
for i:=1; aByte == 0x00 && i != 4; i++ { for i:=1; aByte == 0x00 && i != 4; i++ {
aByte = <-p.InputByteChan aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte) outputBuffer = append(outputBuffer, aByte)
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) { if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
if searchingForEnd { if searchingForEnd {
outputBuffer = outputBuffer[:len(outputBuffer)-(i+1)] output := append(append(itut.StartCode1(),itut.AUD()...),outputBuffer[:len(outputBuffer)-(i+1)]...)
p.OutputChan<-append(append(itut.StartCode1(),itut.AUD()...),outputBuffer...) p.OutputChan<-output
outputBuffer = []byte{} outputBuffer = outputBuffer[len(outputBuffer)-1-i:]
searchingForEnd = false searchingForEnd = false
} }
aByte = <-p.InputByteChan aByte = <-p.InputByteChan
outputBuffer = append(outputBuffer, aByte) outputBuffer = append(outputBuffer, aByte)
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 { 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" "time"
"io" "io"
"bitbucket.org/ausocean/av/h264" "../h264"
"bitbucket.org/ausocean/av/tsgenerator" "../tsgenerator"
"bitbucket.org/ausocean/av/ringbuffer" "bitbucket.org/ausocean/av/ringbuffer"
) )
@ -85,7 +85,7 @@ type Config struct {
InputCmd string InputCmd string
Output uint8 Output uint8
OutputFileName string OutputFileName string
InputFileName string InputFileName string
} }
type RevidInst interface { type RevidInst interface {
@ -154,8 +154,8 @@ func (r *revidInst) input() {
generator := tsgenerator.NewTsGenerator(framesPerSec) generator := tsgenerator.NewTsGenerator(framesPerSec)
go generator.Generate() go generator.Generate()
h264Parser := h264.H264Parser{OutputChan: generator.NalInputChan} h264Parser := h264.H264Parser{OutputChan: generator.NalInputChan}
// TODO: Need to create constructor for parser otherwise I'm going to break // TODO: Need to create constructor for parser otherwise I'm going to break
// something eventuallyl // something eventuallyl
go h264Parser.Parse() go h264Parser.Parse()
var inputReader *bufio.Reader var inputReader *bufio.Reader
switch r.config.Input { switch r.config.Input {
@ -169,8 +169,8 @@ func (r *revidInst) input() {
return return
} }
case file: case file:
default: default:
r.Error.Println("Input not valid!") r.Error.Println("Input not valid!")
} }
@ -211,15 +211,11 @@ func (r *revidInst) input() {
if err != nil { if err != nil {
r.Error.Println(err.Error()) r.Error.Println(err.Error())
} }
fmt.Println("about to start sending data")
for i := range h264Data { for i := range h264Data {
fmt.Printf("i: %v\n", i)
h264Parser.InputByteChan<-h264Data[i] h264Parser.InputByteChan<-h264Data[i]
} }
fmt.Println("all data sent")
} }
if clip, err := r.ringBuffer.Get(); err != nil { if clip, err := r.ringBuffer.Get(); err != nil {
r.Error.Println(err.Error()) r.Error.Println(err.Error())
return return
@ -235,7 +231,6 @@ func (r *revidInst) input() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
fmt.Println("getting ts packet")
tsPacket := <-generator.TsChan tsPacket := <-generator.TsChan
byteSlice, err := tsPacket.ToByteSlice() byteSlice, err := tsPacket.ToByteSlice()
if err != nil { if err != nil {

View File

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