From ec796bd9ae81a3c6e24e0877aead8e635dc44283 Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Sun, 11 Feb 2018 17:04:52 +1030 Subject: [PATCH] fixing bugs and wrote test file... need to build and see my errors now --- generator/MPEGTSGenerator.go | 4 ++-- revid/RevidInstance.go | 19 ++++++++++++------- revid/revid_test.go | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/generator/MPEGTSGenerator.go b/generator/MPEGTSGenerator.go index aa483a7a..c3dea21f 100644 --- a/generator/MPEGTSGenerator.go +++ b/generator/MPEGTSGenerator.go @@ -29,11 +29,11 @@ type tsGenerator struct { ccMap map[int]int } -func (g *tsGenerator)GetNalInputChan() chan []byte { +func (g *tsGenerator)GetInputChan() chan []byte { return g.nalInputChan } -func (g *tsGenerator)GetTsOutputChan() <-chan *mpegts.MpegTsPacket { +func (g *tsGenerator)GetOutputChan() <-chan *mpegts.MpegTsPacket { return g.TsChan } diff --git a/revid/RevidInstance.go b/revid/RevidInstance.go index 1730e1d5..2eab9c3f 100644 --- a/revid/RevidInstance.go +++ b/revid/RevidInstance.go @@ -164,16 +164,21 @@ func (r *revidInst) ChangeState(config Config) error { r.Log(Info, "Using MJPEG parser!") r.parser = parser.NewMJPEGParser(mjpegParserInChanLen) } - switch r.config.Packetization { - case None: + if r.config.Packetization == None { r.parser.SetOutputChan(r.outputChan) getFrame = getFrameForNoPacketization - case Mpegts: - frameRateAsInt, _ := strconv.Atoi(r.config.FrameRate) - r.generator = tsgenerator.NewTsGenerator(uint(frameRateAsInt)) - r.parser.SetOutputChan(r.generator.GetNalInputChan()) + } else { + switch r.config.Packetization { + case Mpegts: + frameRateAsInt, _ := strconv.Atoi(r.config.FrameRate) + r.generator = tsgenerator.NewTsGenerator(uint(frameRateAsInt)) + case Flv: + frameRateAsInt, _ := strconv.Atoi(r.config.FrameRate) + r.generator = flvGenerator.NewFlvGenerator(uint(frameRateAsInt)) + } + getFrame = getFrameForPacketization + r.parser.SetOutputChan(r.generator.GetInputChan()) r.generator.Start() - getFrame = getFrameForMpegtsPacketization } r.config = config return nil diff --git a/revid/revid_test.go b/revid/revid_test.go index 93aaa484..756a580a 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -96,6 +96,7 @@ func TestRaspividMJPEGInput(t *testing.T){ } */ +/* // Test revidInst with rtmp output func TestRtmpOutput(t *testing.T){ config := Config{ @@ -119,3 +120,25 @@ func TestRtmpOutput(t *testing.T){ time.Sleep(120*time.Second) revidInst.Stop() } +*/ + +// Test h264 inputfile to flv output files +func TestFlvOutputFile(t *testing.T){ + config := Config{ + Input: File, + InputFileName: "testInput.h264", + InputCodec: H264, + Output: File, + OutputFileName: "testOutput.flv", + Packetization: Flv, + FrameRate: "25", + } + revidInst, err := NewRevidInstance(config) + if err != nil { + t.Errorf("Should not of have got an error!: %v\n", err.Error()) + return + } + revidInst.Start() + time.Sleep(5*time.Second) + revidInst.Stop() +}