av/parser/MJPEGParser.go

59 lines
1.2 KiB
Go

package parser
import (
//"bitbucket.org/ausocean/av/itut"
_"fmt"
)
type mjpegParser struct {
inputBuffer []byte
isParsing bool
parserOutputChanRef chan []byte
userOutputChanRef chan []byte
inputChan chan byte
}
func NewMJPEGParser(inputChanLen int) (p *mjpegParser){
p = new(mjpegParser)
p.isParsing = true
p.inputChan = make(chan byte, inputChanLen )
return
}
func (p *mjpegParser)Stop(){
p.isParsing = false
}
func (p *mjpegParser)Start(){
go p.parse()
}
func (p *mjpegParser)GetInputChan() chan byte {
return p.inputChan
}
func (p *mjpegParser)GetOutputChan() chan []byte {
return p.userOutputChanRef
}
func (p *mjpegParser)SetOutputChan(aChan chan []byte){
p.parserOutputChanRef = aChan
p.userOutputChanRef = aChan
}
func (p *mjpegParser)parse() {
var outputBuffer []byte
for p.isParsing {
aByte := <-p.inputChan
outputBuffer = append(outputBuffer, aByte)
if aByte == 0xFF && len(outputBuffer) != 0 {
aByte := <-p.inputChan
outputBuffer = append(outputBuffer, aByte)
if aByte == 0xD8 {
p.parserOutputChanRef<-outputBuffer[:len(outputBuffer)-2]
outputBuffer = outputBuffer[len(outputBuffer)-2:]
}
}
}
}