diff --git a/README.md b/README.md index e17b7c11..843135d5 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,9 @@ Features: ## Examples * [client-query](examples/client-query.go) -* [client-read-udp](examples/client-read-udp.go) -* [client-read-tcp](examples/client-read-tcp.go) +* [client-read](examples/client-read.go) * [client-read-pause](examples/client-read-pause.go) -* [client-publish-udp](examples/client-publish-udp.go) -* [client-publish-tcp](examples/client-publish-tcp.go) +* [client-publish](examples/client-publish.go) ## Documentation diff --git a/examples/client-publish-tcp.go b/examples/client-publish-tcp.go deleted file mode 100644 index c224f49a..00000000 --- a/examples/client-publish-tcp.go +++ /dev/null @@ -1,69 +0,0 @@ -// +build ignore - -package main - -import ( - "fmt" - "net" - - "github.com/aler9/gortsplib" - "github.com/aler9/gortsplib/pkg/rtph264" -) - -// This example shows how to -// * generate RTP/H264 frames from a file with Gstreamer -// * connect to a RTSP server, announce a H264 track -// * write the frames with the TCP protocol - -func main() { - // open a listener to receive RTP/H264 frames - pc, err := net.ListenPacket("udp4", "127.0.0.1:9000") - if err != nil { - panic(err) - } - defer pc.Close() - - fmt.Println("Waiting for a rtp/h264 stream on port 9000 - you can send one with gstreamer:\n" + - "gst-launch-1.0 filesrc location=video.mp4 ! qtdemux ! video/x-h264" + - " ! h264parse config-interval=1 ! rtph264pay ! udpsink host=127.0.0.1 port=9000") - - // wait for RTP/H264 frames - decoder := rtph264.NewDecoderFromPacketConn(pc) - sps, pps, err := decoder.ReadSPSPPS() - if err != nil { - panic(err) - } - fmt.Println("stream connected") - - // create a H264 track - track, err := gortsplib.NewTrackH264(0, sps, pps) - if err != nil { - panic(err) - } - - // connect to the server and start publishing the track - dialer := gortsplib.Dialer{ - StreamProtocol: gortsplib.StreamProtocolTCP, - } - conn, err := dialer.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) - if err != nil { - panic(err) - } - defer conn.Close() - - buf := make([]byte, 2048) - for { - // read frames from the source - n, _, err := pc.ReadFrom(buf) - if err != nil { - break - } - - // write frames to the server - err = conn.WriteFrame(track.Id, gortsplib.StreamTypeRtp, buf[:n]) - if err != nil { - fmt.Printf("connection is closed (%s)\n", err) - break - } - } -} diff --git a/examples/client-publish-udp.go b/examples/client-publish.go similarity index 100% rename from examples/client-publish-udp.go rename to examples/client-publish.go diff --git a/examples/client-read-tcp.go b/examples/client-read-tcp.go deleted file mode 100644 index ef7289b2..00000000 --- a/examples/client-read-tcp.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build ignore - -package main - -import ( - "fmt" - - "github.com/aler9/gortsplib" -) - -// This example shows how to -// * connect to a RTSP server -// * read all tracks with the TCP protocol - -func main() { - // connect to the server and start reading all tracks - dialer := gortsplib.Dialer{ - StreamProtocol: gortsplib.StreamProtocolTCP, - } - conn, err := dialer.DialRead("rtsp://localhost:8554/mystream") - if err != nil { - panic(err) - } - defer conn.Close() - - // read frames from the server - done := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) { - fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf) - }) - - <-done -} diff --git a/examples/client-read-udp.go b/examples/client-read.go similarity index 100% rename from examples/client-read-udp.go rename to examples/client-read.go