diff --git a/clientconf_test.go b/clientconf_test.go index 68363e24..372212e4 100644 --- a/clientconf_test.go +++ b/clientconf_test.go @@ -101,7 +101,7 @@ func TestDialRead(t *testing.T) { var firstFrame int32 frameRecv := make(chan struct{}) - done := conn.OnFrame(func(id int, typ StreamType, content []byte) { + done := conn.ReadFrames(func(id int, typ StreamType, content []byte) { if atomic.SwapInt32(&firstFrame, 1) == 0 { close(frameRecv) } @@ -111,7 +111,7 @@ func TestDialRead(t *testing.T) { conn.Close() <-done - done = conn.OnFrame(func(id int, typ StreamType, content []byte) { + done = conn.ReadFrames(func(id int, typ StreamType, content []byte) { t.Error("should not happen") }) <-done @@ -149,7 +149,7 @@ func TestDialReadAutomaticProtocol(t *testing.T) { var firstFrame int32 frameRecv := make(chan struct{}) - done := conn.OnFrame(func(id int, typ StreamType, content []byte) { + done := conn.ReadFrames(func(id int, typ StreamType, content []byte) { if atomic.SwapInt32(&firstFrame, 1) == 0 { close(frameRecv) } @@ -192,7 +192,7 @@ func TestDialReadRedirect(t *testing.T) { var firstFrame int32 frameRecv := make(chan struct{}) - done := conn.OnFrame(func(id int, typ StreamType, content []byte) { + done := conn.ReadFrames(func(id int, typ StreamType, content []byte) { if atomic.SwapInt32(&firstFrame, 1) == 0 { close(frameRecv) } @@ -245,7 +245,7 @@ func TestDialReadPause(t *testing.T) { firstFrame := int32(0) frameRecv := make(chan struct{}) - done := conn.OnFrame(func(id int, typ StreamType, content []byte) { + done := conn.ReadFrames(func(id int, typ StreamType, content []byte) { if atomic.SwapInt32(&firstFrame, 1) == 0 { close(frameRecv) } @@ -261,7 +261,7 @@ func TestDialReadPause(t *testing.T) { firstFrame = int32(0) frameRecv = make(chan struct{}) - done = conn.OnFrame(func(id int, typ StreamType, content []byte) { + done = conn.ReadFrames(func(id int, typ StreamType, content []byte) { if atomic.SwapInt32(&firstFrame, 1) == 0 { close(frameRecv) } diff --git a/clientconnread.go b/clientconnread.go index daa47b19..efbc5860 100644 --- a/clientconnread.go +++ b/clientconnread.go @@ -208,10 +208,10 @@ func (c *ClientConn) backgroundPlayTCP(done chan error) { } } -// OnFrame sets a callback that is called when a frame is received. +// ReadFrames starts reading frames. // it returns a channel that is written when the reading stops. // This can be called only after Play(). -func (c *ClientConn) OnFrame(onFrame func(int, StreamType, []byte)) chan error { +func (c *ClientConn) ReadFrames(onFrame func(int, StreamType, []byte)) chan error { // channel is buffered, since listening to it is not mandatory done := make(chan error, 1) diff --git a/examples/client-read-options.go b/examples/client-read-options.go index 58aa718d..100aecbe 100644 --- a/examples/client-read-options.go +++ b/examples/client-read-options.go @@ -33,11 +33,11 @@ func main() { defer conn.Close() // read track frames - readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) { + done := conn.ReadFrames(func(id int, typ gortsplib.StreamType, buf []byte) { fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf) }) // catch any error - err = <-readerDone + err = <-done panic(err) } diff --git a/examples/client-read-partial.go b/examples/client-read-partial.go index ca03b4b3..4bbd1a36 100644 --- a/examples/client-read-partial.go +++ b/examples/client-read-partial.go @@ -53,11 +53,11 @@ func main() { } // read track frames - readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) { + done := conn.ReadFrames(func(id int, typ gortsplib.StreamType, buf []byte) { fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf) }) // catch any error - err = <-readerDone + err = <-done panic(err) } diff --git a/examples/client-read-pause.go b/examples/client-read-pause.go index 9bf4572c..025827aa 100644 --- a/examples/client-read-pause.go +++ b/examples/client-read-pause.go @@ -25,7 +25,7 @@ func main() { for { // read track frames - readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) { + done := conn.ReadFrames(func(id int, typ gortsplib.StreamType, buf []byte) { fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf) }) @@ -39,7 +39,7 @@ func main() { } // join reader - <-readerDone + <-done // wait time.Sleep(5 * time.Second) diff --git a/examples/client-read.go b/examples/client-read.go index e80b6dba..c72f819e 100644 --- a/examples/client-read.go +++ b/examples/client-read.go @@ -21,11 +21,11 @@ func main() { defer conn.Close() // read track frames - readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) { + done := conn.ReadFrames(func(id int, typ gortsplib.StreamType, buf []byte) { fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf) }) // catch any error - err = <-readerDone + err = <-done panic(err) } diff --git a/serverconn.go b/serverconn.go index d9b70b06..14c9be4e 100644 --- a/serverconn.go +++ b/serverconn.go @@ -130,7 +130,7 @@ outer: done <- errRet } -// Read starts reading requests and frames from the connection. +// Read starts reading requests and frames. // it returns a channel that is written when the reading stops. func (sc *ServerConn) Read( onRequest func(req *base.Request) (*base.Response, error),