mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
rename ClientConn.OnFrame into ReadFrames
This commit is contained in:
@@ -101,7 +101,7 @@ func TestDialRead(t *testing.T) {
|
|||||||
|
|
||||||
var firstFrame int32
|
var firstFrame int32
|
||||||
frameRecv := make(chan struct{})
|
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 {
|
if atomic.SwapInt32(&firstFrame, 1) == 0 {
|
||||||
close(frameRecv)
|
close(frameRecv)
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func TestDialRead(t *testing.T) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
<-done
|
<-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")
|
t.Error("should not happen")
|
||||||
})
|
})
|
||||||
<-done
|
<-done
|
||||||
@@ -149,7 +149,7 @@ func TestDialReadAutomaticProtocol(t *testing.T) {
|
|||||||
|
|
||||||
var firstFrame int32
|
var firstFrame int32
|
||||||
frameRecv := make(chan struct{})
|
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 {
|
if atomic.SwapInt32(&firstFrame, 1) == 0 {
|
||||||
close(frameRecv)
|
close(frameRecv)
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ func TestDialReadRedirect(t *testing.T) {
|
|||||||
|
|
||||||
var firstFrame int32
|
var firstFrame int32
|
||||||
frameRecv := make(chan struct{})
|
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 {
|
if atomic.SwapInt32(&firstFrame, 1) == 0 {
|
||||||
close(frameRecv)
|
close(frameRecv)
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ func TestDialReadPause(t *testing.T) {
|
|||||||
|
|
||||||
firstFrame := int32(0)
|
firstFrame := int32(0)
|
||||||
frameRecv := make(chan struct{})
|
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 {
|
if atomic.SwapInt32(&firstFrame, 1) == 0 {
|
||||||
close(frameRecv)
|
close(frameRecv)
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ func TestDialReadPause(t *testing.T) {
|
|||||||
|
|
||||||
firstFrame = int32(0)
|
firstFrame = int32(0)
|
||||||
frameRecv = make(chan struct{})
|
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 {
|
if atomic.SwapInt32(&firstFrame, 1) == 0 {
|
||||||
close(frameRecv)
|
close(frameRecv)
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
// it returns a channel that is written when the reading stops.
|
||||||
// This can be called only after Play().
|
// 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
|
// channel is buffered, since listening to it is not mandatory
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
|
|
||||||
|
@@ -33,11 +33,11 @@ func main() {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read track frames
|
// 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)
|
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
|
||||||
})
|
})
|
||||||
|
|
||||||
// catch any error
|
// catch any error
|
||||||
err = <-readerDone
|
err = <-done
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -53,11 +53,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read track frames
|
// 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)
|
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
|
||||||
})
|
})
|
||||||
|
|
||||||
// catch any error
|
// catch any error
|
||||||
err = <-readerDone
|
err = <-done
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ func main() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// read track frames
|
// 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)
|
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// join reader
|
// join reader
|
||||||
<-readerDone
|
<-done
|
||||||
|
|
||||||
// wait
|
// wait
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
@@ -21,11 +21,11 @@ func main() {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read track frames
|
// 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)
|
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
|
||||||
})
|
})
|
||||||
|
|
||||||
// catch any error
|
// catch any error
|
||||||
err = <-readerDone
|
err = <-done
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -130,7 +130,7 @@ outer:
|
|||||||
done <- errRet
|
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.
|
// it returns a channel that is written when the reading stops.
|
||||||
func (sc *ServerConn) Read(
|
func (sc *ServerConn) Read(
|
||||||
onRequest func(req *base.Request) (*base.Response, error),
|
onRequest func(req *base.Request) (*base.Response, error),
|
||||||
|
Reference in New Issue
Block a user