2018-02-10 09:59:56 +03:00
|
|
|
package parser
|
|
|
|
|
2018-02-12 10:58:29 +03:00
|
|
|
import (
|
|
|
|
//"bitbucket.org/ausocean/av/itut"
|
|
|
|
_"fmt"
|
|
|
|
)
|
|
|
|
|
2018-02-10 09:59:56 +03:00
|
|
|
type mjpegParser struct {
|
|
|
|
inputBuffer []byte
|
|
|
|
isParsing bool
|
|
|
|
parserOutputChanRef chan []byte
|
|
|
|
userOutputChanRef chan []byte
|
|
|
|
inputChan chan byte
|
2018-02-19 08:06:13 +03:00
|
|
|
delay uint
|
2018-02-10 09:59:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2018-02-19 08:06:13 +03:00
|
|
|
func (p *mjpegParser)SetDelay(delay uint){
|
|
|
|
p.delay = delay
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-10 09:59:56 +03:00
|
|
|
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:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|