From a276809ec99ceb04a49f36cb85cfd196ef35438f Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Tue, 13 Feb 2018 20:16:21 +1030 Subject: [PATCH] Ready for debugging tomorrow --- revid/Config.go | 19 ++++++++++++------- revid/RevidInstance.go | 26 ++++++++++++++++++++++---- revid/revid_test.go | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/revid/Config.go b/revid/Config.go index ac3b5d9b..e63c6c47 100644 --- a/revid/Config.go +++ b/revid/Config.go @@ -21,6 +21,7 @@ type Config struct { RtmpEncodingMethod uint8 FramesPerClip int RtmpUrl string + RtmpMethod uint8 Bitrate string OutputFileName string InputFileName string @@ -51,6 +52,7 @@ const ( Ffmpeg = 11 Revid = 12 Flv = 13 + LibRtmp = 14 ) // Default config settings @@ -108,13 +110,6 @@ func (config *Config) Validate(r *revidInst) error { case Http: case File: case Rtmp: - switch config.RtmpEncodingMethod { - case Revid: - case Ffmpeg: - case NothingDefined: - r.Log(Warning, "No RTMP encoding method defined, defautling to ffmpeg!") - config.RtmpEncodingMethod = Ffmpeg - } if config.RtmpUrl == "" { return errors.New("Bad RTMP URL") } @@ -125,6 +120,16 @@ func (config *Config) Validate(r *revidInst) error { return errors.New("Bad output type defined in config!") } + switch config.RtmpMethod { + case LibRtmp: + case Ffmpeg: + case NothingDefined: + r.Log(Warning, "No RTMP encoding method defined, defautling to ffmpeg!") + config.RtmpEncodingMethod = Ffmpeg + default: + return errors.New("Bad rtmp method defined in config!") + } + switch config.Packetization { case None: case Mpegts: diff --git a/revid/RevidInstance.go b/revid/RevidInstance.go index 17d30633..3cc1e344 100644 --- a/revid/RevidInstance.go +++ b/revid/RevidInstance.go @@ -41,6 +41,7 @@ import ( "os/exec" "strconv" "time" + "rtmp" //"bitbucket.org/ausocean/av/parser" //"bitbucket.org/ausocean/av/tsgenerator" @@ -50,6 +51,7 @@ import ( //"bitbucket.org/ausocean/av/ringbuffer" //"bitbucket.org/ausocean/utils/smartLogger" "../ringbuffer" + "../rtmp" ) // Misc constants @@ -108,6 +110,7 @@ type revidInst struct { getFrame func() []byte flushData func() sendClip func(clip []byte) error + rtmpSession rtmp.RTMPSession } // NewRevidInstance returns a pointer to a new revidInst with the desired @@ -147,8 +150,14 @@ func (r *revidInst) ChangeState(config Config) error { r.sendClip = r.sendClipToFile r.setupOutput = r.setupOutputForFile case Rtmp: - r.setupOutput = r.setupOutputForRtmp - r.sendClip = r.sendClipToRtmp + switch r.config.RtmpMethod { + case Ffmpeg: + r.setupOutput = r.setupOutputForFfmpegRtmp + r.sendClip = r.sendClipToFfmpegRtmp + case LibRtmp: + r.setupOutput = r.setupOutputForLibRtmp + r.sendClip = r.sendClipToLibRtmp + } case Http: r.sendClip = r.sendClipToHTTP } @@ -368,7 +377,7 @@ func (r *revidInst) sendClipToHTTP(clip []byte) error { // Start invokes a revidInst to start processing video from a defined input // and packetising to a defined output. -func (r *revidInst) sendClipToRtmp(clip []byte) error { +func (r *revidInst) sendClipToFfmpegRtmp(clip []byte) error { fmt.Println("Outputting!") _, err := r.ffmpegStdin.Write(clip) if err != nil { @@ -377,9 +386,13 @@ func (r *revidInst) sendClipToRtmp(clip []byte) error { return nil } +func (r *revidInst) sendClipToLibRtmp(clip []byte) error { + return r.rtmpSession.WriteFrame(clip,len(clip)) +} + // Start invokes a revidInst to start processing video from a defined input // and packetising to a defined output. -func (r *revidInst) setupOutputForRtmp() error { +func (r *revidInst) setupOutputForFfmpegRtmp() error { r.ffmpegCmd = exec.Command(ffmpegPath, "-f", "h264", "-r", r.config.FrameRate, @@ -411,6 +424,11 @@ func (r *revidInst) setupOutputForRtmp() error { return nil } +func (r *revidInst) setupOutputForLibRtmp() error { + r.rtmpSession = NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout) + return rtmp.StartSession() +} + func (r *revidInst) setupOutputForFile() (err error) { r.outputFile, err = os.Create(r.config.OutputFileName) return diff --git a/revid/revid_test.go b/revid/revid_test.go index 80a38506..bad00af4 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -144,3 +144,25 @@ func TestFlvOutputFile(t *testing.T) { revidInst.Stop() } */ + +// Test h264 inputfile to flv format into rtmp using librtmp c wrapper +func TestRtmpOutputUsingLibRtmp(t *testing.T){ + config := Config{ + Input: File, + InputFileName: "testInput.h264", + InputCodec: H264, + Output: Rtmp, + RtmpMethod: LibRtmp, + RtmpUrl: "", + 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(30*time.Second) + revidInst.Stop() +}