mirror of
https://github.com/aler9/gortsplib
synced 2025-10-16 04:00:46 +08:00
update docs
This commit is contained in:
14
README.md
14
README.md
@@ -5,19 +5,21 @@
|
||||
[](https://goreportcard.com/report/github.com/aler9/gortsplib)
|
||||
[](https://pkg.go.dev/github.com/aler9/gortsplib?tab=doc)
|
||||
|
||||
RTSP 1.0 library for the Go programming language, written for [rtsp-simple-server](https://github.com/aler9/rtsp-simple-server).
|
||||
RTSP 1.0 client and server library for the Go programming language, written for [rtsp-simple-server](https://github.com/aler9/rtsp-simple-server).
|
||||
|
||||
Features:
|
||||
* Read streams with TCP or UDP
|
||||
* Publish streams with TCP or UDP
|
||||
* Provides primitives, a class for building clients (`ConnClient`) and a class for building servers (`ConnServer`)
|
||||
* Provides primitives
|
||||
* Provides a class for building clients (`ConnClient`)
|
||||
* Provides a class for building servers (`ConnServer`)
|
||||
|
||||
## Examples
|
||||
|
||||
* [read-tcp](examples/read-tcp.go)
|
||||
* [read-udp](examples/read-udp.go)
|
||||
* [publish-tcp](examples/publish-tcp.go)
|
||||
* [publish-udp](examples/publish-udp.go)
|
||||
* [client-read-tcp](examples/client-read-tcp.go)
|
||||
* [client-read-udp](examples/client-read-udp.go)
|
||||
* [client-publish-tcp](examples/client-publish-tcp.go)
|
||||
* [client-publish-udp](examples/client-publish-udp.go)
|
||||
|
||||
## Documentation
|
||||
|
||||
|
@@ -698,7 +698,7 @@ func (c *ConnClient) Play(u *url.URL) (*Response, error) {
|
||||
|
||||
c.state = connClientStateReading
|
||||
|
||||
// open the firewall by sending packets to every channel
|
||||
// open the firewall by sending packets to the counterpart
|
||||
if *c.streamProtocol == StreamProtocolUDP {
|
||||
for trackId := range c.udpRtpListeners {
|
||||
c.udpRtpListeners[trackId].write(
|
||||
|
@@ -105,7 +105,7 @@ func (s *ConnServer) WriteResponse(res *Response) error {
|
||||
return res.Write(s.bw)
|
||||
}
|
||||
|
||||
// WriteFrame writes an InterleavedFrame.
|
||||
// WriteFrameTCP writes an InterleavedFrame.
|
||||
func (s *ConnServer) WriteFrameTCP(frame *InterleavedFrame) error {
|
||||
s.conf.Conn.SetWriteDeadline(time.Now().Add(s.conf.WriteTimeout))
|
||||
return frame.Write(s.bw)
|
||||
|
@@ -11,7 +11,11 @@ import (
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
// This example shows how to generate RTP/H264 frames from a file with Gstreamer,
|
||||
// create a RTSP client, connect to a server, announce a H264 track and write
|
||||
// the frames with the TCP protocol.
|
||||
|
||||
func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
var sps []byte
|
||||
var pps []byte
|
||||
|
||||
@@ -52,7 +56,7 @@ func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// open a listener to receive RTP frames
|
||||
// open a listener to receive RTP/H264 frames
|
||||
pc, err := net.ListenPacket("udp4", "127.0.0.1:9000")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -63,8 +67,8 @@ func main() {
|
||||
"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 frames
|
||||
sps, pps, err := getH264SPSandPPS(pc)
|
||||
// wait for RTP/H264 frames
|
||||
sps, pps, err := getRtpH264SPSandPPS(pc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -89,7 +93,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a track
|
||||
// create a H264 track
|
||||
track := gortsplib.NewTrackH264(0, sps, pps)
|
||||
|
||||
// announce the track
|
||||
@@ -118,7 +122,7 @@ func main() {
|
||||
break
|
||||
}
|
||||
|
||||
// write frames
|
||||
// write frames to the server
|
||||
err = conn.WriteFrameTCP(&gortsplib.InterleavedFrame{
|
||||
TrackId: track.Id,
|
||||
StreamType: gortsplib.StreamTypeRtp,
|
@@ -11,7 +11,11 @@ import (
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
// This example shows how to generate RTP/H264 frames from a file with Gstreamer,
|
||||
// create a RTSP client, connect to a server, announce a H264 track and write
|
||||
// the frames with the UDP protocol.
|
||||
|
||||
func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
var sps []byte
|
||||
var pps []byte
|
||||
|
||||
@@ -52,7 +56,7 @@ func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// open a listener to receive RTP frames
|
||||
// open a listener to receive RTP/H264 frames
|
||||
pc, err := net.ListenPacket("udp4", "127.0.0.1:9000")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -63,8 +67,8 @@ func main() {
|
||||
"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 frames
|
||||
sps, pps, err := getH264SPSandPPS(pc)
|
||||
// wait for RTP/H264 frames
|
||||
sps, pps, err := getRtpH264SPSandPPS(pc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -89,7 +93,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a track
|
||||
// create a H264 track
|
||||
track := gortsplib.NewTrackH264(0, sps, pps)
|
||||
|
||||
// announce the track
|
||||
@@ -118,7 +122,7 @@ func main() {
|
||||
break
|
||||
}
|
||||
|
||||
// write frames
|
||||
// write frames to the server
|
||||
err = conn.WriteFrameUDP(track, gortsplib.StreamTypeRtp, buf[:n])
|
||||
if err != nil {
|
||||
break
|
@@ -9,6 +9,9 @@ import (
|
||||
"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.
|
||||
|
||||
func main() {
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
@@ -10,6 +10,9 @@ import (
|
||||
"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.
|
||||
|
||||
func main() {
|
||||
// parse url
|
||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
8
utils.go
8
utils.go
@@ -34,14 +34,14 @@ func (sp StreamProtocol) String() string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// StreamCast is the cast of a stream.
|
||||
// StreamCast is the cast method of a stream.
|
||||
type StreamCast int
|
||||
|
||||
const (
|
||||
// Unicast means that the stream will be unicasted
|
||||
// StreamUnicast means that the stream will be unicasted
|
||||
StreamUnicast StreamCast = iota
|
||||
|
||||
// Multicast means that the stream will be multicasted
|
||||
// StreamMulticast means that the stream will be multicasted
|
||||
StreamMulticast
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func (sc StreamCast) String() string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// StreamType is the type of a stream.
|
||||
// StreamType is the stream type.
|
||||
type StreamType int
|
||||
|
||||
const (
|
||||
|
Reference in New Issue
Block a user