revid: change ring buffer size depending on output type

This commit is contained in:
Saxon 2019-02-25 18:36:39 +10:30
parent 2818f308df
commit 7d3d8c3374
1 changed files with 14 additions and 10 deletions

View File

@ -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 {