mirror of
https://github.com/aler9/gortsplib
synced 2025-10-13 02:43:53 +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://goreportcard.com/report/github.com/aler9/gortsplib)
|
||||||
[](https://pkg.go.dev/github.com/aler9/gortsplib?tab=doc)
|
[](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:
|
Features:
|
||||||
* Read streams with TCP or UDP
|
* Read streams with TCP or UDP
|
||||||
* Publish 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
|
## Examples
|
||||||
|
|
||||||
* [read-tcp](examples/read-tcp.go)
|
* [client-read-tcp](examples/client-read-tcp.go)
|
||||||
* [read-udp](examples/read-udp.go)
|
* [client-read-udp](examples/client-read-udp.go)
|
||||||
* [publish-tcp](examples/publish-tcp.go)
|
* [client-publish-tcp](examples/client-publish-tcp.go)
|
||||||
* [publish-udp](examples/publish-udp.go)
|
* [client-publish-udp](examples/client-publish-udp.go)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
@@ -698,7 +698,7 @@ func (c *ConnClient) Play(u *url.URL) (*Response, error) {
|
|||||||
|
|
||||||
c.state = connClientStateReading
|
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 {
|
if *c.streamProtocol == StreamProtocolUDP {
|
||||||
for trackId := range c.udpRtpListeners {
|
for trackId := range c.udpRtpListeners {
|
||||||
c.udpRtpListeners[trackId].write(
|
c.udpRtpListeners[trackId].write(
|
||||||
|
@@ -105,7 +105,7 @@ func (s *ConnServer) WriteResponse(res *Response) error {
|
|||||||
return res.Write(s.bw)
|
return res.Write(s.bw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteFrame writes an InterleavedFrame.
|
// WriteFrameTCP writes an InterleavedFrame.
|
||||||
func (s *ConnServer) WriteFrameTCP(frame *InterleavedFrame) error {
|
func (s *ConnServer) WriteFrameTCP(frame *InterleavedFrame) error {
|
||||||
s.conf.Conn.SetWriteDeadline(time.Now().Add(s.conf.WriteTimeout))
|
s.conf.Conn.SetWriteDeadline(time.Now().Add(s.conf.WriteTimeout))
|
||||||
return frame.Write(s.bw)
|
return frame.Write(s.bw)
|
||||||
|
@@ -11,7 +11,11 @@ import (
|
|||||||
"github.com/pion/rtp"
|
"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 sps []byte
|
||||||
var pps []byte
|
var pps []byte
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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")
|
pc, err := net.ListenPacket("udp4", "127.0.0.1:9000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -63,8 +67,8 @@ func main() {
|
|||||||
"gst-launch-1.0 filesrc location=video.mp4 ! qtdemux ! video/x-h264" +
|
"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")
|
" ! h264parse config-interval=1 ! rtph264pay ! udpsink host=127.0.0.1 port=9000")
|
||||||
|
|
||||||
// wait for RTP frames
|
// wait for RTP/H264 frames
|
||||||
sps, pps, err := getH264SPSandPPS(pc)
|
sps, pps, err := getRtpH264SPSandPPS(pc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a track
|
// create a H264 track
|
||||||
track := gortsplib.NewTrackH264(0, sps, pps)
|
track := gortsplib.NewTrackH264(0, sps, pps)
|
||||||
|
|
||||||
// announce the track
|
// announce the track
|
||||||
@@ -118,7 +122,7 @@ func main() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// write frames
|
// write frames to the server
|
||||||
err = conn.WriteFrameTCP(&gortsplib.InterleavedFrame{
|
err = conn.WriteFrameTCP(&gortsplib.InterleavedFrame{
|
||||||
TrackId: track.Id,
|
TrackId: track.Id,
|
||||||
StreamType: gortsplib.StreamTypeRtp,
|
StreamType: gortsplib.StreamTypeRtp,
|
@@ -11,7 +11,11 @@ import (
|
|||||||
"github.com/pion/rtp"
|
"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 sps []byte
|
||||||
var pps []byte
|
var pps []byte
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ func getH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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")
|
pc, err := net.ListenPacket("udp4", "127.0.0.1:9000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -63,8 +67,8 @@ func main() {
|
|||||||
"gst-launch-1.0 filesrc location=video.mp4 ! qtdemux ! video/x-h264" +
|
"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")
|
" ! h264parse config-interval=1 ! rtph264pay ! udpsink host=127.0.0.1 port=9000")
|
||||||
|
|
||||||
// wait for RTP frames
|
// wait for RTP/H264 frames
|
||||||
sps, pps, err := getH264SPSandPPS(pc)
|
sps, pps, err := getRtpH264SPSandPPS(pc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a track
|
// create a H264 track
|
||||||
track := gortsplib.NewTrackH264(0, sps, pps)
|
track := gortsplib.NewTrackH264(0, sps, pps)
|
||||||
|
|
||||||
// announce the track
|
// announce the track
|
||||||
@@ -118,7 +122,7 @@ func main() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// write frames
|
// write frames to the server
|
||||||
err = conn.WriteFrameUDP(track, gortsplib.StreamTypeRtp, buf[:n])
|
err = conn.WriteFrameUDP(track, gortsplib.StreamTypeRtp, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
@@ -9,6 +9,9 @@ import (
|
|||||||
"github.com/aler9/gortsplib"
|
"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() {
|
func main() {
|
||||||
// parse url
|
// parse url
|
||||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
@@ -10,6 +10,9 @@ import (
|
|||||||
"github.com/aler9/gortsplib"
|
"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() {
|
func main() {
|
||||||
// parse url
|
// parse url
|
||||||
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
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"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamCast is the cast of a stream.
|
// StreamCast is the cast method of a stream.
|
||||||
type StreamCast int
|
type StreamCast int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Unicast means that the stream will be unicasted
|
// StreamUnicast means that the stream will be unicasted
|
||||||
StreamUnicast StreamCast = iota
|
StreamUnicast StreamCast = iota
|
||||||
|
|
||||||
// Multicast means that the stream will be multicasted
|
// StreamMulticast means that the stream will be multicasted
|
||||||
StreamMulticast
|
StreamMulticast
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func (sc StreamCast) String() string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamType is the type of a stream.
|
// StreamType is the stream type.
|
||||||
type StreamType int
|
type StreamType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Reference in New Issue
Block a user