vidforward: getPipeline handles revid creation and start

It simplifies things if getPipeline handles creation and starting
of the revid pipeline. We don't need to be doing this in multiple
places.

Approved-by: Trek Hopton
This commit is contained in:
Saxon Milton 2023-09-18 23:28:51 +00:00
parent 4087be907a
commit da9ed6d689
2 changed files with 29 additions and 20 deletions

View File

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

View File

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