diff --git a/server/internal/capture/pipelines.go b/server/internal/capture/pipelines.go index 6f352b7b..19e8a4ab 100644 --- a/server/internal/capture/pipelines.go +++ b/server/internal/capture/pipelines.go @@ -47,7 +47,7 @@ func NewBroadcastPipeline(device string, display string, pipelineSrc string, url // replace display pipelineStr = strings.Replace(pipelineStr, "{display}", display, -1) } else { - pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! x264enc bitrate=%d bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", url, audio, video, 6000) + pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! x264enc bitrate=%d bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", url, audio, video, 8000) } return pipelineStr, nil diff --git a/upstream/client.go b/upstream/client.go index 31a384db..10874bf8 100644 --- a/upstream/client.go +++ b/upstream/client.go @@ -48,9 +48,6 @@ type Client struct { } func (c *Client) readPump() { - defer func() { - c.hub.unregister <- c - }() c.conn.SetReadLimit(maxMessageSize) c.conn.SetReadDeadline(time.Now().Add(pongWait)) c.conn.SetPongHandler(func(string) error { @@ -64,8 +61,7 @@ func (c *Client) readPump() { if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) { log.Printf("error: %v", err) } - c.hub.unregister <- c - break + return } c.hub.broadcast <- raw } @@ -77,18 +73,13 @@ func (c *Client) writePump() { ticker.Stop() c.hub.unregister <- c close(c.send) + c.conn.Close() }() for { select { - case raw, ok := <-c.send: + case raw := <-c.send: c.conn.SetWriteDeadline(time.Now().Add(writeWait)) - if !ok { - // The hub closed the channel. - c.conn.WriteMessage(websocket.CloseMessage, []byte{}) - c.conn.Close() - return - } if err := c.conn.WriteMessage(websocket.BinaryMessage, raw); err != nil { log.Printf("Error writing message: %v", err)