Merged in improve-defaulting (pull request #153)

Improve defaulting

Approved-by: Alan Noble <anoble@gmail.com>
This commit is contained in:
Saxon Milton 2019-03-02 07:41:17 +00:00 committed by Alan Noble
commit 95eaf0fca7
2 changed files with 17 additions and 10 deletions

View File

@ -186,15 +186,18 @@ func (c *Config) Validate(r *Revid) error {
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out", c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out",
"framesPerClip", defaultFramesPerClip) "framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip c.FramesPerClip = defaultFramesPerClip
c.Packetization = Flv
case NothingDefined: case NothingDefined:
c.Logger.Log(logger.Warning, pkg+"no output defined, defaulting", "output", c.Logger.Log(logger.Warning, pkg+"no output defined, defaulting", "output",
defaultOutput) defaultOutput)
c.Outputs[i] = defaultOutput c.Outputs[i] = defaultOutput
c.Packetization = defaultPacketization
fallthrough fallthrough
case Http, Rtp: case Http, Rtp:
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out",
"framesPerClip", httpFramesPerClip) "framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip c.FramesPerClip = httpFramesPerClip
c.Packetization = Mpegts
default: default:
return errors.New("bad output type defined in config") return errors.New("bad output type defined in config")
} }

View File

@ -51,10 +51,12 @@ import (
// Ring buffer sizes and read/write timeouts. // Ring buffer sizes and read/write timeouts.
const ( const (
ringBufferSize = 1000 mtsRbSize = 100
ringBufferElementSize = 150000 mtsRbElementSize = 150000
writeTimeout = 10 * time.Millisecond flvRbSize = 1000
readTimeout = 10 * time.Millisecond flvRbElementSize = 10000
writeTimeout = 10 * time.Millisecond
readTimeout = 10 * time.Millisecond
) )
// RTMP connection properties. // RTMP connection properties.
@ -141,11 +143,6 @@ type packer struct {
// are deemed to be successful, although a successful // are deemed to be successful, although a successful
// write may include a dropped frame. // write may include a dropped frame.
func (p *packer) Write(frame []byte) (int, error) { 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 { if len(p.owner.destination) != 0 {
n, err := p.owner.buffer.Write(frame) n, err := p.owner.buffer.Write(frame)
if err != nil { if err != nil {
@ -226,7 +223,14 @@ func (r *Revid) reset(config Config) error {
} }
r.config = config 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] r.destination = r.destination[:0]
for _, typ := range r.config.Outputs { for _, typ := range r.config.Outputs {