From 16c399aabfae536e4c2ca3de7722c9b8b9eb80d2 Mon Sep 17 00:00:00 2001 From: Jack Richardson Date: Wed, 17 Jan 2018 14:18:47 +1030 Subject: [PATCH] Fixed start/stop bug --- mpegts/MpegTs.go | 2 ++ revid/RevidInstance.go | 4 ++-- tsgenerator/TsGenerator.go | 12 ++---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mpegts/MpegTs.go b/mpegts/MpegTs.go index 50fd8362..b66fb209 100644 --- a/mpegts/MpegTs.go +++ b/mpegts/MpegTs.go @@ -31,6 +31,7 @@ package mpegts import ( "bitbucket.org/ausocean/av/tools" "errors" + //"fmt" ) const ( @@ -135,6 +136,7 @@ func (p *MpegTsPacket) FillPayload(channel chan byte){ currentPktLength := 6 + int(tools.BoolToByte(p.PCRF))*6+int(tools.BoolToByte(p.OPCRF))*6+ int(tools.BoolToByte(p.SPF))*1+int(tools.BoolToByte(p.TPDF))*1+len(p.TPD) for (currentPktLength+len(p.Payload)) < 188 { + //fmt.Printf("len(channel): %v\n", len(channel)) select { case nextByte := <-channel: p.Payload = append(p.Payload,nextByte) diff --git a/revid/RevidInstance.go b/revid/RevidInstance.go index 22f0eddb..df919c99 100644 --- a/revid/RevidInstance.go +++ b/revid/RevidInstance.go @@ -148,6 +148,7 @@ func NewRevidInstance(config Config) (r *revidInst, err error) { // something eventuallyl go r.h264Parser.Parse() go r.input() + go r.generator.Generate() return } @@ -159,7 +160,6 @@ func (r *revidInst) ChangeState(newConfig Config) error { func (r *revidInst) Start() { r.isRunning = true - go r.generator.Generate() switch r.config.Input { case Raspivid: cmd = exec.Command("raspivid", "-o", "-", "-n", "-t", "0", "-b", @@ -214,7 +214,6 @@ func (r *revidInst) Start() { func (r *revidInst) Stop() { if r.isRunning { r.isRunning = false - r.generator.Stop() cmd.Process.Kill() } } @@ -267,6 +266,7 @@ func (r *revidInst) output() { case HttpOut: for err := sendClipToHTTP(clip, r.config.HttpAddress); err != nil; { err = sendClipToHTTP(clip, r.config.HttpAddress) + time.Sleep(5*time.Second) } default: r.Error.Println("No output?") diff --git a/tsgenerator/TsGenerator.go b/tsgenerator/TsGenerator.go index 25013290..e9496b99 100644 --- a/tsgenerator/TsGenerator.go +++ b/tsgenerator/TsGenerator.go @@ -29,7 +29,7 @@ LICENSE package tsgenerator import ( - "fmt" + _"fmt" _"os" "bitbucket.org/ausocean/av/mpegts" "bitbucket.org/ausocean/av/pes" @@ -56,7 +56,6 @@ type TsGenerator interface { Generate() GetNalInputChan() chan<- []byte GetTsOutputChan() <-chan *mpegts.MpegTsPacket - Stop() } type tsGenerator struct { @@ -72,7 +71,6 @@ type tsGenerator struct { currentPtsTime float64 currentPcrTime float64 fps uint - isGenerating bool pesPktChan chan []byte ccMap map[int]int } @@ -122,14 +120,9 @@ func (g *tsGenerator) genPcr()(pcr uint64){ return } -func (g *tsGenerator) Stop(){ - g.isGenerating = false -} - func (g *tsGenerator) Generate() { - g.isGenerating = true var rtpBuffer [](*rtp.RtpPacket) - for g.isGenerating { + for { select { case rtpPacket := <-g.inputChan: rtpBuffer = append(rtpBuffer, &rtpPacket) @@ -270,7 +263,6 @@ func (g *tsGenerator) Generate() { } } } - fmt.Println("\n\n\nGetting out of generate!\n\n\n") } func (g *tsGenerator) getCC(pid int) int {