diff --git a/revid/config.go b/revid/config.go new file mode 100644 index 00000000..76bc77c4 --- /dev/null +++ b/revid/config.go @@ -0,0 +1,46 @@ +/* +NAME + RtpToTsConverter.go - provides utilities for the conversion of Rtp packets + to equivalent MpegTs packets. + +DESCRIPTION + See Readme.md + +AUTHOR + Saxon Nelson-Milton + +LICENSE + RtpToTsConverter.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) + + It is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses). +*/ + +package revid + +const ( + // input types + raspivid = 0 + rtp = 1 + // input format + h264 = 2 + rtp = 3 + // output types + file = 4 + http = 5 +) + +type Config struct { + input uint8 + output uint8 +} diff --git a/revid/revid_test.go b/revid/revid_test.go index ff1525b7..7f68cab9 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -139,5 +139,15 @@ func TestRTP(t *testing.T) { Testing use with raspivid */ func TestRaspividInput(t *testing.T){ - + config := Config{ + Input: raspivid, + Output: file, + } + revidInst, err := NewRevidInstance(config) + if err != nil { + t.Errorf("Should not have got an error!") + } + revidInst.Run() + time.Sleep(5*time.Second) + revidInst.Stop() } diff --git a/revid/revidinstance.go b/revid/revidinstance.go index 1df058e6..f401ac40 100644 --- a/revid/revidinstance.go +++ b/revid/revidinstance.go @@ -91,25 +91,7 @@ type RevidInst interface { ChangeState(newConfig Config) err } -const ( - // input types - raspivid = 0 - rtp = 1 - // input format - h264 = 2 - rtp = 3 - // output types - file = 4 - http = 5 -) - -type Config struct { - input uint8 - output uint8 -} - type revidInst struct { - clipCount int expectCC int dumpCC int dumpPCRBase uint64 @@ -124,7 +106,10 @@ type revidInst struct { func NewRevidInstance(config Config)(r *revid, err error){ ringBuffer = ringbuffer.NewRingBuffer(bufferSize, mp2tPacketSize*mp2tMaxPackets) - Error = log.New(os.Stderr, "ERROR: ",log.Ldat|log.Ltime|log.Lshortfile) + r.Error = log.New(os.Stderr, "ERROR: ",log.Ldat|log.Ltime|log.Lshortfile) + r.expectCC = -1 + r.dumpCC = -1 + r.dumpPCRBase = 0 } func(r *revidInst) Run(){ @@ -140,10 +125,9 @@ func(r *revidInst) Stop(){ // input handles the reading from the specified input func (r *revid)input(input string, output string) { // (re)initialize globals - clipCount = 0 - expectCC = -1 - dumpCC = -1 - dumpPCRBase = 0 + r.expectCC = -1 + r.dumpCC = -1 + r.dumpPCRBase = 0 converter := tscreator.NewTsCreator(framesPerSec) go converter.Convert() @@ -190,7 +174,6 @@ func (r *revid)input(input string, output string) { now = time.Now() if (packetCount == mp2tMaxPackets) || (now.Sub(prevTime) > clipDuration*time.Second && packetCount%packetsPerFrame == 0) { - clipCount++ if err := ringBuffer.DoneWriting(clipSize); err != nil { r.Error.Println(err.Error()) return @@ -223,12 +206,7 @@ func (r *revid)output(output string) { // sendClipToFile writes a video clip to a /tmp file. func sendClipToFile(clip []byte, _ string, _ net.Conn) error { - filename := fmt.Sprintf(tempDir+"vid%03d.ts", clipCount) - fmt.Printf("Writing %s (%d bytes)\n", filename, len(clip)) - err := ioutil.WriteFile(filename, clip, 0644) - if err != nil { - return fmt.Errorf("Error writing file %s: %s", filename, err) - } + return nil } @@ -266,6 +244,3 @@ func sendClipToUDP(clip []byte, _ string, conn net.Conn) error { } return nil } -} - } -}