revid: move initialisation of revids netsender up higher in New so that we don't get nil pointer deference

This commit is contained in:
saxon 2018-09-25 17:10:35 +09:30
parent e6d0ee035e
commit 0c2ccf55fa
3 changed files with 2 additions and 9 deletions

View File

@ -99,7 +99,7 @@ const (
defaultFramesPerClip = 1
defaultVerticalFlip = No
defaultHorizontalFlip = No
httpFramesPerClip = 25
httpFramesPerClip = 7
defaultInputCodec = H264
defaultVerbosity = No
)

View File

@ -31,7 +31,6 @@ package revid
import (
"errors"
"fmt"
"io"
"os"
"os/exec"
@ -116,13 +115,13 @@ type Revid struct {
// an error if construction of the new instance was not successful.
func New(c Config, ns *netsender.Sender) (*Revid, error) {
var r Revid
r.ns = ns
err := r.reset(c)
if err != nil {
return nil, err
}
r.ringBuffer = ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)
r.outputChan = make(chan []byte, outputChanSize)
r.ns = ns
return &r, nil
}
@ -297,7 +296,6 @@ func (r *Revid) packClips() {
// TODO: This is temporary, need to work out how to make this work
// for cases when there is not packetisation.
case frame := <-r.encoder.Stream():
fmt.Println("got frame")
lenOfFrame := len(frame)
if lenOfFrame > ringBufferElementSize {
r.config.Logger.Log(smartlogger.Warning, pkg+"frame was too big", "frame size", lenOfFrame)
@ -316,7 +314,6 @@ func (r *Revid) packClips() {
packetCount++
clipSize += lenOfFrame
if packetCount >= r.config.FramesPerClip {
fmt.Println("flushing buffer")
r.ringBuffer.Flush()
clipSize = 0
packetCount = 0

View File

@ -29,7 +29,6 @@ LICENSE
package revid
import (
"fmt"
"io"
"os"
"os/exec"
@ -123,7 +122,6 @@ func (s *httpSender) load(c *ring.Chunk) error {
func (s *httpSender) send() error {
if s.chunk == nil {
fmt.Println("chunk is nil")
// Do not retry with httpSender,
// so just return without error
// if the chunk has been cleared.
@ -135,7 +133,6 @@ func (s *httpSender) send() error {
pins := netsender.MakePins(ip, "V")
for i, pin := range pins {
if pin.Name == "V0" {
fmt.Println("pin is V0")
send = true
pins[i].Value = s.chunk.Len()
pins[i].Data = s.chunk.Bytes()
@ -145,7 +142,6 @@ func (s *httpSender) send() error {
}
var err error
if send {
fmt.Println("sending")
_, _, err = s.client.Send(netsender.RequestPoll, pins)
}
// We will not retry, so release