mirror of https://bitbucket.org/ausocean/av.git
Creating config getter
This commit is contained in:
parent
6663656a63
commit
62f7f5ba9d
|
@ -102,7 +102,8 @@ type Config struct {
|
|||
type RevidInst interface {
|
||||
Start()
|
||||
Stop()
|
||||
ChangeState(newConfiguration Config) error
|
||||
ChangeState(newconfig Config) error
|
||||
GetConfigRef() *Config
|
||||
}
|
||||
|
||||
type revidInst struct {
|
||||
|
@ -113,7 +114,7 @@ type revidInst struct {
|
|||
ffmpegPath string
|
||||
tempDir string
|
||||
ringBuffer ringbuffer.RingBuffer
|
||||
Configuration Config
|
||||
config Config
|
||||
isRunning bool
|
||||
Error *log.Logger
|
||||
outputFile *os.File
|
||||
|
@ -122,24 +123,28 @@ type revidInst struct {
|
|||
h264Parser h264.H264Parser
|
||||
}
|
||||
|
||||
func NewRevidInstance(Configuration Config) (r *revidInst, err error) {
|
||||
func (r *revidInst) GetConfigRef(){
|
||||
return &r.config
|
||||
}
|
||||
|
||||
func NewRevidInstance(config Config) (r *revidInst, err error) {
|
||||
r = new(revidInst)
|
||||
r.ringBuffer = ringbuffer.NewRingBuffer(bufferSize, mp2tPacketSize*mp2tMaxPackets)
|
||||
r.Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
r.expectCC = -1
|
||||
r.dumpCC = -1
|
||||
r.dumpPCRBase = 0
|
||||
r.ChangeState(Configuration)
|
||||
switch r.Configuration.Output {
|
||||
r.ChangeState(config)
|
||||
switch r.config.Output {
|
||||
case File:
|
||||
r.outputFile, err = os.Create(r.Configuration.OutputFileName)
|
||||
r.outputFile, err = os.Create(r.config.OutputFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
switch r.Configuration.Input {
|
||||
switch r.config.Input {
|
||||
case File:
|
||||
r.inputFile, err = os.Open(r.Configuration.InputFileName)
|
||||
r.inputFile, err = os.Open(r.config.InputFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -152,29 +157,29 @@ func NewRevidInstance(Configuration Config) (r *revidInst, err error) {
|
|||
go r.h264Parser.Parse()
|
||||
go r.input()
|
||||
go r.generator.Generate()
|
||||
r.ErrOut("New revid instance created! Configuration is:")
|
||||
r.ErrOut(fmt.Sprintf("%v",r.Configuration))
|
||||
r.ErrOut("New revid instance created! config is:")
|
||||
r.ErrOut(fmt.Sprintf("%v",r.config))
|
||||
return
|
||||
}
|
||||
|
||||
func (r *revidInst) ChangeState(newConfiguration Config) error {
|
||||
// TODO: check that the Configuration is G
|
||||
r.Configuration = newConfiguration
|
||||
func (r *revidInst) ChangeState(newconfig Config) error {
|
||||
// TODO: check that the config is G
|
||||
r.config = newconfig
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *revidInst) ErrOut(m string){
|
||||
if r.Configuration.Debug {
|
||||
r.Configuration.Logger.Log("Debug",m)
|
||||
if r.config.Debug {
|
||||
r.config.Logger.Log("Debug",m)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *revidInst) Start() {
|
||||
switch r.Configuration.Input {
|
||||
switch r.config.Input {
|
||||
case Raspivid:
|
||||
r.ErrOut("Starting raspivid!")
|
||||
cmd = exec.Command("raspivid", "-o", "-", "-n", "-t", "0", "-b",
|
||||
r.Configuration.Bitrate,"-qp", r.Configuration.Quantization, "-w", r.Configuration.Width, "-h", r.Configuration.Height, "-fps", r.Configuration.FrameRate, "-ih", "-g", "100")
|
||||
r.config.Bitrate,"-qp", r.config.Quantization, "-w", r.config.Width, "-h", r.config.Height, "-fps", r.config.FrameRate, "-ih", "-g", "100")
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
err := cmd.Start()
|
||||
inputReader = bufio.NewReader(stdout)
|
||||
|
@ -188,7 +193,7 @@ func (r *revidInst) Start() {
|
|||
}
|
||||
r.isRunning = true
|
||||
var h264Data []byte
|
||||
switch r.Configuration.Input {
|
||||
switch r.config.Input {
|
||||
case Raspivid:
|
||||
go func() {
|
||||
r.ErrOut("Reading camera data!")
|
||||
|
@ -289,14 +294,14 @@ func (r *revidInst) output() {
|
|||
if clip, err := r.ringBuffer.Read(); err == nil {
|
||||
r.ErrOut(fmt.Sprintf("Delay is: %v\n", delay))
|
||||
r.ErrOut(fmt.Sprintf("Ring buffer size: %v\n", r.ringBuffer.GetNoOfElements()))
|
||||
switch r.Configuration.Output {
|
||||
switch r.config.Output {
|
||||
case File:
|
||||
r.outputFile.Write(clip)
|
||||
case HttpOut:
|
||||
bytes += len(clip)
|
||||
for err := r.sendClipToHTTP(clip, r.Configuration.HttpAddress); err != nil; {
|
||||
for err := r.sendClipToHTTP(clip, r.config.HttpAddress); err != nil; {
|
||||
r.ErrOut("Post failed trying again!")
|
||||
err = r.sendClipToHTTP(clip, r.Configuration.HttpAddress)
|
||||
err = r.sendClipToHTTP(clip, r.config.HttpAddress)
|
||||
}
|
||||
default:
|
||||
r.ErrOut("No output defined!")
|
||||
|
@ -306,7 +311,7 @@ func (r *revidInst) output() {
|
|||
}
|
||||
now = time.Now()
|
||||
deltaTime := now.Sub(prevTime)
|
||||
if r.Configuration.Debug && deltaTime > time.Duration(bitrateTime)*time.Second {
|
||||
if r.config.Debug && deltaTime > time.Duration(bitrateTime)*time.Second {
|
||||
fmt.Printf("Bitrate: %v bytes/s\n", int64(float64(bytes) / float64(deltaTime/1e9)))
|
||||
prevTime = now
|
||||
bytes = 0
|
||||
|
@ -322,7 +327,7 @@ func (r *revidInst)sendClipToHTTP(clip []byte, output string) error {
|
|||
Timeout: timeout,
|
||||
}
|
||||
url := output + strconv.Itoa(len(clip))
|
||||
if r.Configuration.Debug {
|
||||
if r.config.Debug {
|
||||
fmt.Printf("Posting %s (%d bytes)\n", url, len(clip))
|
||||
}
|
||||
resp, err := client.Post(url, "video/mp2t", bytes.NewReader(clip)) // lighter than NewBuffer
|
||||
|
@ -331,7 +336,7 @@ func (r *revidInst)sendClipToHTTP(clip []byte, output string) error {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err == nil && r.Configuration.Debug {
|
||||
if err == nil && r.config.Debug {
|
||||
fmt.Printf("%s\n", body)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue