mirror of https://bitbucket.org/ausocean/av.git
65 lines
1.3 KiB
Go
65 lines
1.3 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
|
|
delay uint
|
|
}
|
|
|
|
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)SetDelay(delay uint){
|
|
p.delay = delay
|
|
}
|
|
|
|
|
|
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:]
|
|
}
|
|
}
|
|
}
|
|
}
|