mirror of
https://github.com/aler9/gortsplib
synced 2025-11-02 11:24:05 +08:00
ConnClient: new methods DialRead and DialPublish
This commit is contained in:
@@ -5,7 +5,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
"github.com/pion/rtp"
|
||||
@@ -74,48 +73,19 @@ func main() {
|
||||
}
|
||||
fmt.Println("stream connected")
|
||||
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// connect to the server
|
||||
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// get allowed commands
|
||||
_, err = conn.Options(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a H264 track
|
||||
track, err := gortsplib.NewTrackH264(0, sps, pps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// announce the track
|
||||
_, err = conn.Announce(u, gortsplib.Tracks{track})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup the track with TCP
|
||||
_, err = conn.SetupTCP(u, gortsplib.SetupModeRecord, track)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// start publishing
|
||||
_, err = conn.Record(u)
|
||||
// connect to the server and start publishing the track
|
||||
conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream",
|
||||
gortsplib.StreamProtocolTCP, gortsplib.Tracks{track})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
for {
|
||||
|
@@ -5,7 +5,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
"github.com/pion/rtp"
|
||||
@@ -74,48 +73,19 @@ func main() {
|
||||
}
|
||||
fmt.Println("stream connected")
|
||||
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// connect to the server
|
||||
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// get allowed commands
|
||||
_, err = conn.Options(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a H264 track
|
||||
track, err := gortsplib.NewTrackH264(0, sps, pps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// announce the track
|
||||
_, err = conn.Announce(u, gortsplib.Tracks{track})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup the track with UDP
|
||||
_, err = conn.SetupUDP(u, gortsplib.SetupModeRecord, track, 0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// start publishing
|
||||
_, err = conn.Record(u)
|
||||
// connect to the server and start publishing the track
|
||||
conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream",
|
||||
gortsplib.StreamProtocolUDP, gortsplib.Tracks{track})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
for {
|
||||
|
@@ -4,54 +4,21 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
)
|
||||
|
||||
// This example shows how to create a RTSP client, connect to a server, list
|
||||
// and read tracks with the TCP protocol.
|
||||
// This example shows how to create a RTSP client, connect to a server and
|
||||
// read all tracks with the TCP protocol.
|
||||
|
||||
func main() {
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// connect to the server
|
||||
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
|
||||
// connect to the server and start reading all tracks
|
||||
conn, _, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolTCP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// get allowed commands
|
||||
_, err = conn.Options(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// list tracks published on the path
|
||||
tracks, _, err := conn.Describe(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup tracks with TCP
|
||||
for _, track := range tracks {
|
||||
_, err := conn.SetupTCP(u, gortsplib.SetupModePlay, track)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// start reading
|
||||
_, err = conn.Play(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for {
|
||||
// read frames
|
||||
frame, err := conn.ReadFrameTCP()
|
||||
|
@@ -4,55 +4,22 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
)
|
||||
|
||||
// This example shows how to create a RTSP client, connect to a server, list
|
||||
// and read tracks with the UDP protocol.
|
||||
// This example shows how to create a RTSP client, connect to a server and
|
||||
// read all tracks with the UDP protocol.
|
||||
|
||||
func main() {
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// connect to the server
|
||||
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
|
||||
// connect to the server and start reading all tracks
|
||||
conn, tracks, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolUDP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// get allowed commands
|
||||
_, err = conn.Options(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// list tracks published on the path
|
||||
tracks, _, err := conn.Describe(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup tracks with UDP
|
||||
for _, track := range tracks {
|
||||
_, err := conn.SetupUDP(u, gortsplib.SetupModePlay, track, 0, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// start reading
|
||||
_, err = conn.Play(u)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
defer conn.CloseUDPListeners()
|
||||
@@ -89,6 +56,6 @@ func main() {
|
||||
}(track)
|
||||
}
|
||||
|
||||
err = conn.LoopUDP(u)
|
||||
err = conn.LoopUDP()
|
||||
fmt.Println("connection is closed (%s)", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user