mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
add new examples
This commit is contained in:
44
examples/client-read-options.go
Normal file
44
examples/client-read-options.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
)
|
||||
|
||||
// This example shows how to
|
||||
// * connect to a RTSP server
|
||||
// * read all tracks on a path
|
||||
|
||||
func main() {
|
||||
// Dialer allows to set additional options
|
||||
dialer := gortsplib.Dialer{
|
||||
// the stream protocol
|
||||
StreamProtocol: gortsplib.StreamProtocolUDP,
|
||||
// timeout of read operations
|
||||
ReadTimeout: 10 * time.Second,
|
||||
// timeout of write operations
|
||||
WriteTimeout: 10 * time.Second,
|
||||
// read buffer count.
|
||||
// If greater than 1, allows to pass buffers to routines different than the one
|
||||
// that is reading frames
|
||||
ReadBufferCount: 1,
|
||||
}
|
||||
|
||||
// connect to the server and start reading all tracks
|
||||
conn, err := dialer.DialRead("rtsp://localhost:8554/mystream")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// read frames from the server
|
||||
readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) {
|
||||
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
|
||||
})
|
||||
|
||||
<-readerDone
|
||||
}
|
Reference in New Issue
Block a user