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 (
@ -60,17 +62,16 @@ func (p* H264Parser)Parse() {
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
@ -81,33 +82,4 @@ func (p* H264Parser)Parse() {
} }
} }
} }
/*
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"
) )
@ -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 {