revid: use time.Duration for durations

This commit is contained in:
Dan Kortschak 2018-06-08 12:48:11 +09:30
parent 576815a10f
commit 3da57cbe46
1 changed files with 8 additions and 9 deletions

View File

@ -52,16 +52,16 @@ import (
// Misc constants // Misc constants
const ( const (
clipDuration = 1 // s clipDuration = 1 * time.Second
mp2tPacketSize = 188 // MPEG-TS packet size mp2tPacketSize = 188 // MPEG-TS packet size
mp2tMaxPackets = 2016 * clipDuration // # first multiple of 7 and 8 greater than 2000 mp2tMaxPackets = int(clipDuration * 2016 / time.Second) // # first multiple of 7 and 8 greater than 2000
ringBufferSize = 500 ringBufferSize = 500
ringBufferElementSize = 150000 ringBufferElementSize = 150000
writeTimeout = 10 * time.Millisecond writeTimeout = 10 * time.Millisecond
readTimeout = 10 * time.Millisecond readTimeout = 10 * time.Millisecond
httpTimeOut = 5 // s httpTimeout = 5 * time.Second
packetsPerFrame = 7 packetsPerFrame = 7
bitrateTime = 60 // s bitrateTime = 1 * time.Minute
mjpegParserInChanLen = 100000 mjpegParserInChanLen = 100000
ffmpegPath = "/usr/local/bin/ffmpeg" ffmpegPath = "/usr/local/bin/ffmpeg"
rtmpConnectionTimout = 10 rtmpConnectionTimout = 10
@ -72,7 +72,7 @@ const (
clipSizeThreshold = 11 clipSizeThreshold = 11
rtmpConnectionMaxTries = 5 rtmpConnectionMaxTries = 5
raspividNoOfTries = 3 raspividNoOfTries = 3
sendingWaitTime = time.Duration(5) * time.Millisecond sendingWaitTime = 5 * time.Millisecond
) )
// Log Types // Log Types
@ -446,7 +446,7 @@ func (r *revid) outputClips() {
// Log some information regarding bitrate and ring buffer size if it's time // Log some information regarding bitrate and ring buffer size if it's time
now = time.Now() now = time.Now()
deltaTime := now.Sub(prevTime) deltaTime := now.Sub(prevTime)
if deltaTime > time.Duration(bitrateTime)*time.Second { if deltaTime > bitrateTime {
r.currentBitrate = int64(float64(bytes*8) / float64(deltaTime/1e9)) r.currentBitrate = int64(float64(bytes*8) / float64(deltaTime/1e9))
r.Log(Debug, fmt.Sprintf("Bitrate: %v bits/s\n", r.currentBitrate)) r.Log(Debug, fmt.Sprintf("Bitrate: %v bits/s\n", r.currentBitrate))
r.Log(Debug, fmt.Sprintf("Ring buffer size: %v\n", r.ringBuffer.Len())) r.Log(Debug, fmt.Sprintf("Ring buffer size: %v\n", r.ringBuffer.Len()))
@ -470,8 +470,7 @@ func (r *revid) sendClipToHTTP(clip *ring.Chunk) error {
defer r.sendMutex.Unlock() defer r.sendMutex.Unlock()
r.sendMutex.Lock() r.sendMutex.Lock()
timeout := time.Duration(httpTimeOut * time.Second) client := http.Client{Timeout: httpTimeout}
client := http.Client{Timeout: timeout}
url := r.config.HttpAddress + strconv.Itoa(clip.Len()) url := r.config.HttpAddress + strconv.Itoa(clip.Len())
// FIXME(kortschak): This is necessary because Post takes // FIXME(kortschak): This is necessary because Post takes