diff --git a/cmd/vidforward/file.go b/cmd/vidforward/file.go index f026da09..ad189e7d 100644 --- a/cmd/vidforward/file.go +++ b/cmd/vidforward/file.go @@ -77,16 +77,6 @@ func (b *Broadcast) UnmarshalJSON(data []byte) error { b.urls = bm.URLs b.status = bm.Status - b.rv, err = newRevid(global.GetLogger(), b.urls) - if err != nil { - return fmt.Errorf("could not populate RV field: %w", err) - } - - err = b.rv.Start() - if err != nil { - return fmt.Errorf("could not start revid pipeline: %w", err) - } - return nil } @@ -119,9 +109,9 @@ func (m *broadcastManager) UnmarshalJSON(data []byte) error { if b.status == statusSlate { sigCh := make(chan struct{}) m.slateExitSignals[mac] = sigCh - rv := m.getPipeline(mac) - if rv == nil { - panic("no pipeline for MAC") + rv, err := m.getPipeline(mac) + if err != nil { + return fmt.Errorf("could not get revid pipeline: %v",err) } if !inTest { err := writeSlateAndCheckErrors(rv, sigCh, m.log) diff --git a/cmd/vidforward/main.go b/cmd/vidforward/main.go index 9f538cf6..d87f9768 100644 --- a/cmd/vidforward/main.go +++ b/cmd/vidforward/main.go @@ -261,9 +261,10 @@ func (m *broadcastManager) recv(w http.ResponseWriter, r *http.Request) { return } - rv := m.getPipeline(ma) - if r == nil { - panic(fmt.Sprintf("no revid pipeline for mac address: %s", ma)) + rv, err := m.getPipeline(ma) + if err != nil { + m.errorLogWrite(m.log, w, "could not get revid pipeline","mac",ma,"error",err) + return } for i, frame := range h264Clip.Frames() { @@ -363,14 +364,32 @@ func (m *broadcastManager) processRequest(w http.ResponseWriter, r *http.Request } // getPipeline gets the revid pipeline corresponding to a provided device MAC. -func (m *broadcastManager) getPipeline(ma MAC) *revid.Revid { +// If it hasn't been created yet, it's created, and if it hasn't been started yet +// (or just created) then it is started. +func (m *broadcastManager) getPipeline(ma MAC) (*revid.Revid, error) { m.mu.Lock() defer m.mu.Unlock() - v, ok := m.broadcasts[ma] + b, ok := m.broadcasts[ma] if !ok { - return nil + panic("shouldn't be getting pipeline if this mac isn't registered") } - return v.rv + + var err error + if b.rv == nil { + b.rv, err = newRevid(m.log, b.urls) + if err != nil { + return nil, fmt.Errorf("could not create new revid: %v",err) + } + } + + if !b.rv.Running() { + err = b.rv.Start() + if err != nil { + return nil, fmt.Errorf("could not start revid pipeline: %v",err) + } + } + + return b.rv, nil } // getStatus gets the broadcast's status corresponding to the provided MAC.