mirror of https://bitbucket.org/ausocean/av.git
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:
parent
4087be907a
commit
da9ed6d689
|
@ -77,16 +77,6 @@ func (b *Broadcast) UnmarshalJSON(data []byte) error {
|
||||||
b.urls = bm.URLs
|
b.urls = bm.URLs
|
||||||
b.status = bm.Status
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,9 +109,9 @@ func (m *broadcastManager) UnmarshalJSON(data []byte) error {
|
||||||
if b.status == statusSlate {
|
if b.status == statusSlate {
|
||||||
sigCh := make(chan struct{})
|
sigCh := make(chan struct{})
|
||||||
m.slateExitSignals[mac] = sigCh
|
m.slateExitSignals[mac] = sigCh
|
||||||
rv := m.getPipeline(mac)
|
rv, err := m.getPipeline(mac)
|
||||||
if rv == nil {
|
if err != nil {
|
||||||
panic("no pipeline for MAC")
|
return fmt.Errorf("could not get revid pipeline: %v",err)
|
||||||
}
|
}
|
||||||
if !inTest {
|
if !inTest {
|
||||||
err := writeSlateAndCheckErrors(rv, sigCh, m.log)
|
err := writeSlateAndCheckErrors(rv, sigCh, m.log)
|
||||||
|
|
|
@ -261,9 +261,10 @@ func (m *broadcastManager) recv(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rv := m.getPipeline(ma)
|
rv, err := m.getPipeline(ma)
|
||||||
if r == nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("no revid pipeline for mac address: %s", ma))
|
m.errorLogWrite(m.log, w, "could not get revid pipeline","mac",ma,"error",err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, frame := range h264Clip.Frames() {
|
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.
|
// 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()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
v, ok := m.broadcasts[ma]
|
b, ok := m.broadcasts[ma]
|
||||||
if !ok {
|
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.
|
// getStatus gets the broadcast's status corresponding to the provided MAC.
|
||||||
|
|
Loading…
Reference in New Issue