From fce0937810642f8eab4f0f9fdd89b7565f386e2d Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 18 Nov 2018 18:13:38 +1030 Subject: [PATCH] rtp: wrote some code so that config validated udp and rtp stuff as well --- cmd/revid-cli/main.go | 4 ++-- revid/config.go | 4 ++++ revid/revid.go | 1 - revid/senders.go | 5 ++++- stream/rtp/encoder.go | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 2423898a..b776e6aa 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -195,8 +195,8 @@ func handleFlags() { } switch *configFlags[inputCodecPtr] { - case "H264Codec": - config.InputCodec = revid.H264Codec + case "H264": + config.InputCodec = revid.H264 case "": default: logger.Log(smartlogger.Error, pkg+"bad input codec argument") diff --git a/revid/config.go b/revid/config.go index d0cfa9a4..93d46c33 100644 --- a/revid/config.go +++ b/revid/config.go @@ -136,6 +136,7 @@ func (c *Config) Validate(r *Revid) error { switch c.Input { case Raspivid: case File: + c.Logger.Log(smartlogger.Info, pkg+"Using file input", "input") case NothingDefined: c.Logger.Log(smartlogger.Warning, pkg+"no input type defined, defaulting", "input", defaultInput) @@ -159,6 +160,7 @@ func (c *Config) Validate(r *Revid) error { return errors.New("bad bitrate and quantization combination for H264 input") } } + c.Logger.Log(smartlogger.Info, pkg+"Reading h264 codec", "inputCodec") case Mjpeg: if c.Quantization != "" { quantization, err := strconv.Atoi(c.Quantization) @@ -182,6 +184,7 @@ func (c *Config) Validate(r *Revid) error { switch c.Output { case File: + case Udp: case Rtmp, FfmpegRtmp: if c.RtmpUrl == "" { c.Logger.Log(smartlogger.Info, pkg+"no RTMP URL: falling back to HTTP") @@ -208,6 +211,7 @@ func (c *Config) Validate(r *Revid) error { case None: case Mpegts: case Flv: + case Rtp: case NothingDefined: c.Logger.Log(smartlogger.Warning, pkg+"no packetization option defined, defaulting", "packetization", defaultPacketization) diff --git a/revid/revid.go b/revid/revid.go index 8f18ec32..11b7482e 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -487,7 +487,6 @@ func (r *Revid) setupInputForFile() error { return err } defer f.Close() - // TODO(kortschak): Maybe we want a context.Context-aware parser that we can stop. return r.lexTo(r.encoder, f, delay) } diff --git a/revid/senders.go b/revid/senders.go index 8a7466ab..940a9c14 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -321,6 +321,9 @@ func (s *udpSender) send() error { return err } -func (s *udpSender) release() {} +func (s *udpSender) release() { + s.chunk.Close() + s.chunk = nil +} func (s *udpSender) close() error { return nil } diff --git a/stream/rtp/encoder.go b/stream/rtp/encoder.go index 315f66e8..68384fd4 100644 --- a/stream/rtp/encoder.go +++ b/stream/rtp/encoder.go @@ -50,11 +50,11 @@ type Encoder struct { // NewEncoder returns a new Encoder type given an io.Writer - the destination // after encoding and the desired fps -func NewEncoder(dst io.Writer, fps float64) *Encoder { +func NewEncoder(dst io.Writer, fps int) *Encoder { return &Encoder{ dst: dst, ssrc: rand.Uint32(), - frameInterval: time.Duration(float64(time.Second) / fps), + frameInterval: time.Duration(float64(time.Second) / float64(fps)), } }