mirror of https://bitbucket.org/ausocean/av.git
generator,parser: remove Get prefix from read accessors
Also make user-facing chan exposure a little safer.
This commit is contained in:
parent
b66abcbfec
commit
ca5eefa4c3
|
@ -62,15 +62,15 @@ type flvGenerator struct {
|
||||||
isGenerating bool
|
isGenerating bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInputChan returns the input channel to the generator. This is where the
|
// InputChan returns the input channel to the generator. This is where the
|
||||||
// raw data frames are entered into the generator
|
// raw data frames are entered into the generator
|
||||||
func (g *flvGenerator) GetInputChan() chan []byte {
|
func (g *flvGenerator) InputChan() chan []byte {
|
||||||
return g.inputChan
|
return g.inputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOutputChan retuns the output chan of the generator - this is where the
|
// OutputChan retuns the output chan of the generator - this is where the
|
||||||
// flv packets (more specifically tags) are outputted.
|
// flv packets (more specifically tags) are outputted.
|
||||||
func (g *flvGenerator) GetOutputChan() chan []byte {
|
func (g *flvGenerator) OutputChan() <-chan []byte {
|
||||||
return g.outputChan
|
return g.outputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ LICENSE
|
||||||
package generator
|
package generator
|
||||||
|
|
||||||
type Generator interface {
|
type Generator interface {
|
||||||
GetInputChan() chan []byte
|
InputChan() chan []byte
|
||||||
GetOutputChan() chan []byte
|
OutputChan() <-chan []byte
|
||||||
Start()
|
Start()
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,15 +86,15 @@ type tsGenerator struct {
|
||||||
isGenerating bool
|
isGenerating bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// getInputChan returns a handle to the nalInputChan (inputChan) so that nal units
|
// InputChan returns a handle to the nalInputChan (inputChan) so that nal units
|
||||||
// can be passed to the generator and processed
|
// can be passed to the generator and processed
|
||||||
func (g *tsGenerator) GetInputChan() chan []byte {
|
func (g *tsGenerator) InputChan() chan []byte {
|
||||||
return g.nalInputChan
|
return g.nalInputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOutputChan returns a handle to the generator output chan where the mpegts
|
// OutputChan returns a handle to the generator output chan where the mpegts
|
||||||
// packets will show up once ready to go
|
// packets will show up once ready to go
|
||||||
func (g *tsGenerator) GetOutputChan() chan []byte {
|
func (g *tsGenerator) OutputChan() <-chan []byte {
|
||||||
return g.outputChan
|
return g.outputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,22 +77,22 @@ func (p *h264Parser) SetDelay(delay uint) {
|
||||||
p.delay = delay
|
p.delay = delay
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInputChan returns a handle to the input channel of the parser
|
// InputChan returns a handle to the input channel of the parser
|
||||||
func (p *h264Parser) GetInputChan() chan byte {
|
func (p *h264Parser) InputChan() chan byte {
|
||||||
return p.inputChan
|
return p.inputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOutputChan returns a handle to the output chan of the parser
|
// OutputChan returns a handle to the output chan of the parser
|
||||||
func (p *h264Parser) GetOutputChan() chan []byte {
|
func (p *h264Parser) OutputChan() <-chan []byte {
|
||||||
return p.userOutputChanRef
|
return p.userOutputChanRef
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOutputChan sets the parser output chan to the passed output chan. This is
|
// SetOutputChan sets the parser output chan to the passed output chan. This is
|
||||||
// useful if we want the parser output to go directly to a generator of some sort
|
// useful if we want the parser output to go directly to a generator of some sort
|
||||||
// for packetization.
|
// for packetization.
|
||||||
func (p *h264Parser) SetOutputChan(aChan chan []byte) {
|
func (p *h264Parser) SetOutputChan(o chan []byte) {
|
||||||
p.parserOutputChanRef = aChan
|
p.parserOutputChanRef = o
|
||||||
p.userOutputChanRef = aChan
|
p.userOutputChanRef = o
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse interprets an incoming h264 stream and extracts individual frames
|
// parse interprets an incoming h264 stream and extracts individual frames
|
||||||
|
|
|
@ -57,17 +57,17 @@ func (p *mjpegParser) SetDelay(delay uint) {
|
||||||
p.delay = delay
|
p.delay = delay
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mjpegParser) GetInputChan() chan byte {
|
func (p *mjpegParser) InputChan() chan byte {
|
||||||
return p.inputChan
|
return p.inputChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mjpegParser) GetOutputChan() chan []byte {
|
func (p *mjpegParser) OutputChan() <-chan []byte {
|
||||||
return p.userOutputChanRef
|
return p.userOutputChanRef
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mjpegParser) SetOutputChan(aChan chan []byte) {
|
func (p *mjpegParser) SetOutputChan(o chan []byte) {
|
||||||
p.parserOutputChanRef = aChan
|
p.parserOutputChanRef = o
|
||||||
p.userOutputChanRef = aChan
|
p.userOutputChanRef = o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mjpegParser) parse() {
|
func (p *mjpegParser) parse() {
|
||||||
|
|
|
@ -43,8 +43,8 @@ var (
|
||||||
type Parser interface {
|
type Parser interface {
|
||||||
Stop()
|
Stop()
|
||||||
Start()
|
Start()
|
||||||
GetInputChan() chan byte
|
InputChan() chan byte
|
||||||
GetOutputChan() chan []byte
|
OutputChan() <-chan []byte
|
||||||
SetOutputChan(achan chan []byte)
|
SetOutputChan(achan chan []byte)
|
||||||
SetDelay(delay uint)
|
SetDelay(delay uint)
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ func (r *Revid) reset(config Config) error {
|
||||||
// We have packetization of some sort, so we want to send data to Generator
|
// We have packetization of some sort, so we want to send data to Generator
|
||||||
// to perform packetization
|
// to perform packetization
|
||||||
r.getFrame = r.getFramePacketization
|
r.getFrame = r.getFramePacketization
|
||||||
r.parser.SetOutputChan(r.generator.GetInputChan())
|
r.parser.SetOutputChan(r.generator.InputChan())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ func (r *Revid) getFrameNoPacketization() []byte {
|
||||||
// getFramePacketization gets a frame from the generators output chan - the
|
// getFramePacketization gets a frame from the generators output chan - the
|
||||||
// the generator being an mpegts or flv generator depending on the config
|
// the generator being an mpegts or flv generator depending on the config
|
||||||
func (r *Revid) getFramePacketization() []byte {
|
func (r *Revid) getFramePacketization() []byte {
|
||||||
return <-r.generator.GetOutputChan()
|
return <-r.generator.OutputChan()
|
||||||
}
|
}
|
||||||
|
|
||||||
// packClips takes data segments; whether that be tsPackets or mjpeg frames and
|
// packClips takes data segments; whether that be tsPackets or mjpeg frames and
|
||||||
|
@ -312,7 +312,7 @@ func (r *Revid) packClips() {
|
||||||
select {
|
select {
|
||||||
// TODO: This is temporary, need to work out how to make this work
|
// TODO: This is temporary, need to work out how to make this work
|
||||||
// for cases when there is not packetisation.
|
// for cases when there is not packetisation.
|
||||||
case frame := <-r.generator.GetOutputChan():
|
case frame := <-r.generator.OutputChan():
|
||||||
lenOfFrame := len(frame)
|
lenOfFrame := len(frame)
|
||||||
if lenOfFrame > ringBufferElementSize {
|
if lenOfFrame > ringBufferElementSize {
|
||||||
r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame))
|
r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame))
|
||||||
|
@ -518,7 +518,7 @@ func (r *Revid) readCamera() {
|
||||||
r.Log(Error, "No data from camera!")
|
r.Log(Error, "No data from camera!")
|
||||||
time.Sleep(cameraRetryPeriod)
|
time.Sleep(cameraRetryPeriod)
|
||||||
default:
|
default:
|
||||||
r.parser.GetInputChan() <- data[0]
|
r.parser.InputChan() <- data[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.Log(Info, "Not trying to read from camera anymore!")
|
r.Log(Info, "Not trying to read from camera anymore!")
|
||||||
|
@ -547,7 +547,7 @@ func (r *Revid) readFile() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := range data {
|
for i := range data {
|
||||||
r.parser.GetInputChan() <- data[i]
|
r.parser.InputChan() <- data[i]
|
||||||
}
|
}
|
||||||
r.inputFile.Close()
|
r.inputFile.Close()
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue