diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 87e00faf..937453dc 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -306,7 +306,7 @@ func sendTo(ns *netsender.Sender) error { inputs := netsender.MakePins(ns.GetConfigParam("ip"), "X") for i, pin := range inputs { if pin.Name == "X23" { - inputs[i].Value = int(revidInst.GetBitrate()) + inputs[i].Value = revidInst.Bitrate() } } diff --git a/revid/revid.go b/revid/revid.go index b6428af2..d6d9e26d 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -83,23 +83,23 @@ const ( // Revid provides methods to control a revid session; providing methods // to start, stop and change the state of an instance using the Config struct. type Revid struct { - ffmpegPath string - tempDir string - ringBuffer *ring.Buffer - config Config - isRunning bool - inputFile *os.File - generator generator.Generator - parser parser.Parser - cmd *exec.Cmd - inputReader *bufio.Reader - ffmpegStdin io.WriteCloser - outputChan chan []byte - setupInput func() error - getFrame func() []byte - destination loadSender - rtmpInst rtmp.Session - currentBitrate int64 + ffmpegPath string + tempDir string + ringBuffer *ring.Buffer + config Config + isRunning bool + inputFile *os.File + generator generator.Generator + parser parser.Parser + cmd *exec.Cmd + inputReader *bufio.Reader + ffmpegStdin io.WriteCloser + outputChan chan []byte + setupInput func() error + getFrame func() []byte + destination loadSender + rtmpInst rtmp.Session + bitrate int } // NewRevid returns a pointer to a new Revid with the desired @@ -116,10 +116,9 @@ func New(c Config) (*Revid, error) { return &r, nil } -// Returns the currently saved bitrate from the most recent bitrate check -// check bitrate output delay in consts for this period -func (r *Revid) GetBitrate() int64 { - return r.currentBitrate +// Bitrate returns the result of the most recent bitrate check. +func (r *Revid) Bitrate() int { + return r.bitrate } // GetConfigRef returns a pointer to the revidInst's Config struct object @@ -417,8 +416,9 @@ func (r *Revid) outputClips() { now = time.Now() deltaTime := now.Sub(prevTime) if deltaTime > bitrateTime { - r.currentBitrate = int64(float64(bytes*8) / float64(deltaTime/1e9)) - r.Log(Debug, fmt.Sprintf("Bitrate: %v bits/s\n", r.currentBitrate)) + // FIXME(kortschak): For subsecond deltaTime, this will give infinite bitrate. + r.bitrate = int(float64(bytes*8) / float64(deltaTime/time.Second)) + r.Log(Debug, fmt.Sprintf("Bitrate: %v bits/s\n", r.bitrate)) r.Log(Debug, fmt.Sprintf("Ring buffer size: %v\n", r.ringBuffer.Len())) prevTime = now bytes = 0