From 2818f308df5efcc307423769efcb529b2f16520c Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 25 Feb 2019 18:26:20 +1030 Subject: [PATCH 1/2] revid: defaulting to Mpegts packetization if output is Http or Rtp and Defaulting to Flv packetization if output is Rtmp --- revid/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/revid/config.go b/revid/config.go index 6f682028..1fff08bd 100644 --- a/revid/config.go +++ b/revid/config.go @@ -186,15 +186,18 @@ func (c *Config) Validate(r *Revid) error { c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out", "framesPerClip", defaultFramesPerClip) c.FramesPerClip = defaultFramesPerClip + c.Packetization = Flv case NothingDefined: c.Logger.Log(logger.Warning, pkg+"no output defined, defaulting", "output", defaultOutput) c.Outputs[i] = defaultOutput + c.Packetization = defaultPacketization fallthrough case Http, Rtp: c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", "framesPerClip", httpFramesPerClip) c.FramesPerClip = httpFramesPerClip + c.Packetization = Mpegts default: return errors.New("bad output type defined in config") } From 7d3d8c33740629a5c19f78b5ae45cf69fac74dc8 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 25 Feb 2019 18:36:39 +1030 Subject: [PATCH 2/2] revid: change ring buffer size depending on output type --- revid/revid.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index a5efa44d..8297f87a 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -51,10 +51,12 @@ import ( // Ring buffer sizes and read/write timeouts. const ( - ringBufferSize = 100 - ringBufferElementSize = 150000 - writeTimeout = 10 * time.Millisecond - readTimeout = 10 * time.Millisecond + mtsRbSize = 100 + mtsRbElementSize = 150000 + flvRbSize = 1000 + flvRbElementSize = 10000 + writeTimeout = 10 * time.Millisecond + readTimeout = 10 * time.Millisecond ) // RTMP connection properties. @@ -141,11 +143,6 @@ type packer struct { // are deemed to be successful, although a successful // write may include a dropped frame. func (p *packer) Write(frame []byte) (int, error) { - if len(frame) > ringBufferElementSize { - p.owner.config.Logger.Log(logger.Warning, pkg+"frame was too big", "frame size", len(frame)) - return len(frame), nil - } - if len(p.owner.destination) != 0 { n, err := p.owner.buffer.Write(frame) if err != nil { @@ -229,7 +226,14 @@ func (r *Revid) reset(config Config) error { } r.config = config - r.buffer = ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout) + // NB: currently we use two outputs that require the same packetization method + // so we only need to check first output, but this may change later. + switch r.config.Outputs[0] { + case Rtmp, FfmpegRtmp: + r.buffer = ring.NewBuffer(flvRbSize, flvRbElementSize, writeTimeout) + case Http, Rtp: + r.buffer = ring.NewBuffer(mtsRbSize, mtsRbElementSize, writeTimeout) + } r.destination = r.destination[:0] for _, typ := range r.config.Outputs {