Fix closer for ivideon source

This commit is contained in:
Alexey Khit
2023-01-13 13:32:48 +03:00
parent d92b0f29af
commit eee70c07b7
2 changed files with 16 additions and 6 deletions
+15 -5
View File
@@ -14,6 +14,7 @@ import (
"io"
"net/http"
"strings"
"sync"
"time"
)
@@ -26,12 +27,11 @@ type Client struct {
medias []*streamer.Media
tracks map[byte]*streamer.Track
closed bool
msg *message
t0 time.Time
buffer chan []byte
mu sync.Mutex
}
func NewClient(id string) *Client {
@@ -87,7 +87,11 @@ func (c *Client) Handle() error {
track := c.tracks[c.msg.Track]
if track != nil {
c.buffer <- data
c.mu.Lock()
if c.buffer != nil {
c.buffer <- data
}
c.mu.Unlock()
}
// we have one unprocessed msg after getTracks
@@ -114,7 +118,11 @@ func (c *Client) Handle() error {
track = c.tracks[msg.Track]
if track != nil {
c.buffer <- data
c.mu.Lock()
if c.buffer != nil {
c.buffer <- data
}
c.mu.Unlock()
}
default:
@@ -127,10 +135,12 @@ func (c *Client) Close() error {
if c.conn == nil {
return nil
}
c.mu.Lock()
if c.buffer != nil {
close(c.buffer)
c.buffer = nil
}
c.closed = true
c.mu.Unlock()
return c.conn.Close()
}
+1 -1
View File
@@ -20,7 +20,7 @@ func (c *Client) GetTrack(media *streamer.Media, codec *streamer.Codec) *streame
func (c *Client) Start() error {
err := c.Handle()
if c.closed {
if c.buffer == nil {
return nil
}
return err