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
|
||||
}
|
||||
|
||||
// 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
|
||||
func (g *flvGenerator) GetInputChan() chan []byte {
|
||||
func (g *flvGenerator) InputChan() chan []byte {
|
||||
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.
|
||||
func (g *flvGenerator) GetOutputChan() chan []byte {
|
||||
func (g *flvGenerator) OutputChan() <-chan []byte {
|
||||
return g.outputChan
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ LICENSE
|
|||
package generator
|
||||
|
||||
type Generator interface {
|
||||
GetInputChan() chan []byte
|
||||
GetOutputChan() chan []byte
|
||||
InputChan() chan []byte
|
||||
OutputChan() <-chan []byte
|
||||
Start()
|
||||
Stop()
|
||||
}
|
||||
|
|
|
@ -86,15 +86,15 @@ type tsGenerator struct {
|
|||
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
|
||||
func (g *tsGenerator) GetInputChan() chan []byte {
|
||||
func (g *tsGenerator) InputChan() chan []byte {
|
||||
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
|
||||
func (g *tsGenerator) GetOutputChan() chan []byte {
|
||||
func (g *tsGenerator) OutputChan() <-chan []byte {
|
||||
return g.outputChan
|
||||
}
|
||||
|
||||
|
|
|
@ -77,22 +77,22 @@ func (p *h264Parser) SetDelay(delay uint) {
|
|||
p.delay = delay
|
||||
}
|
||||
|
||||
// GetInputChan returns a handle to the input channel of the parser
|
||||
func (p *h264Parser) GetInputChan() chan byte {
|
||||
// InputChan returns a handle to the input channel of the parser
|
||||
func (p *h264Parser) InputChan() chan byte {
|
||||
return p.inputChan
|
||||
}
|
||||
|
||||
// GetOutputChan returns a handle to the output chan of the parser
|
||||
func (p *h264Parser) GetOutputChan() chan []byte {
|
||||
// OutputChan returns a handle to the output chan of the parser
|
||||
func (p *h264Parser) OutputChan() <-chan []byte {
|
||||
return p.userOutputChanRef
|
||||
}
|
||||
|
||||
// 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
|
||||
// for packetization.
|
||||
func (p *h264Parser) SetOutputChan(aChan chan []byte) {
|
||||
p.parserOutputChanRef = aChan
|
||||
p.userOutputChanRef = aChan
|
||||
func (p *h264Parser) SetOutputChan(o chan []byte) {
|
||||
p.parserOutputChanRef = o
|
||||
p.userOutputChanRef = o
|
||||
}
|
||||
|
||||
// parse interprets an incoming h264 stream and extracts individual frames
|
||||
|
|
|
@ -57,17 +57,17 @@ func (p *mjpegParser) SetDelay(delay uint) {
|
|||
p.delay = delay
|
||||
}
|
||||
|
||||
func (p *mjpegParser) GetInputChan() chan byte {
|
||||
func (p *mjpegParser) InputChan() chan byte {
|
||||
return p.inputChan
|
||||
}
|
||||
|
||||
func (p *mjpegParser) GetOutputChan() chan []byte {
|
||||
func (p *mjpegParser) OutputChan() <-chan []byte {
|
||||
return p.userOutputChanRef
|
||||
}
|
||||
|
||||
func (p *mjpegParser) SetOutputChan(aChan chan []byte) {
|
||||
p.parserOutputChanRef = aChan
|
||||
p.userOutputChanRef = aChan
|
||||
func (p *mjpegParser) SetOutputChan(o chan []byte) {
|
||||
p.parserOutputChanRef = o
|
||||
p.userOutputChanRef = o
|
||||
}
|
||||
|
||||
func (p *mjpegParser) parse() {
|
||||
|
|
|
@ -43,8 +43,8 @@ var (
|
|||
type Parser interface {
|
||||
Stop()
|
||||
Start()
|
||||
GetInputChan() chan byte
|
||||
GetOutputChan() chan []byte
|
||||
InputChan() chan byte
|
||||
OutputChan() <-chan []byte
|
||||
SetOutputChan(achan chan []byte)
|
||||
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
|
||||
// to perform packetization
|
||||
r.getFrame = r.getFramePacketization
|
||||
r.parser.SetOutputChan(r.generator.GetInputChan())
|
||||
r.parser.SetOutputChan(r.generator.InputChan())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func (r *Revid) getFrameNoPacketization() []byte {
|
|||
// getFramePacketization gets a frame from the generators output chan - the
|
||||
// the generator being an mpegts or flv generator depending on the config
|
||||
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
|
||||
|
@ -312,7 +312,7 @@ func (r *Revid) packClips() {
|
|||
select {
|
||||
// TODO: This is temporary, need to work out how to make this work
|
||||
// for cases when there is not packetisation.
|
||||
case frame := <-r.generator.GetOutputChan():
|
||||
case frame := <-r.generator.OutputChan():
|
||||
lenOfFrame := len(frame)
|
||||
if lenOfFrame > ringBufferElementSize {
|
||||
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!")
|
||||
time.Sleep(cameraRetryPeriod)
|
||||
default:
|
||||
r.parser.GetInputChan() <- data[0]
|
||||
r.parser.InputChan() <- data[0]
|
||||
}
|
||||
}
|
||||
r.Log(Info, "Not trying to read from camera anymore!")
|
||||
|
@ -547,7 +547,7 @@ func (r *Revid) readFile() error {
|
|||
return err
|
||||
}
|
||||
for i := range data {
|
||||
r.parser.GetInputChan() <- data[i]
|
||||
r.parser.InputChan() <- data[i]
|
||||
}
|
||||
r.inputFile.Close()
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue