mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
improve examples in order not to skip first RTP packet
This commit is contained in:
@@ -27,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
// wait for first packet
|
// wait for first packet
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
_, _, err = pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,8 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := gortsplib.Client{}
|
|
||||||
|
|
||||||
// connect to the server and start publishing the track
|
// connect to the server and start publishing the track
|
||||||
|
c := gortsplib.Client{}
|
||||||
err = c.StartPublishing("rtsp://localhost:8554/mystream",
|
err = c.StartPublishing("rtsp://localhost:8554/mystream",
|
||||||
gortsplib.Tracks{track})
|
gortsplib.Tracks{track})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -49,25 +48,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
buf = make([]byte, 2048)
|
|
||||||
var pkt rtp.Packet
|
var pkt rtp.Packet
|
||||||
for {
|
for {
|
||||||
// read RTP packets from the source
|
// parse RTP packet
|
||||||
n, _, err := pc.ReadFrom(buf)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse RTP packets
|
|
||||||
err = pkt.Unmarshal(buf[:n])
|
err = pkt.Unmarshal(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// route RTP packets to the server
|
// route RTP packet to the server
|
||||||
err = c.WritePacketRTP(0, &pkt)
|
err = c.WritePacketRTP(0, &pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read another RTP packet from source
|
||||||
|
n, _, err = pc.ReadFrom(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,9 +42,8 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := gortsplib.Client{}
|
|
||||||
|
|
||||||
// connect to the server and start publishing the track
|
// connect to the server and start publishing the track
|
||||||
|
c := gortsplib.Client{}
|
||||||
err = c.StartPublishing("rtsp://localhost:8554/mystream",
|
err = c.StartPublishing("rtsp://localhost:8554/mystream",
|
||||||
gortsplib.Tracks{track})
|
gortsplib.Tracks{track})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -27,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
// wait for first packet
|
// wait for first packet
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
_, _, err = pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -49,25 +49,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
buf = make([]byte, 2048)
|
|
||||||
var pkt rtp.Packet
|
var pkt rtp.Packet
|
||||||
for {
|
for {
|
||||||
// read RTP packets from the source
|
// parse RTP packet
|
||||||
n, _, err := pc.ReadFrom(buf)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse RTP packets
|
|
||||||
err = pkt.Unmarshal(buf[:n])
|
err = pkt.Unmarshal(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// route RTP packets to the server
|
// route RTP packet to the server
|
||||||
err = c.WritePacketRTP(0, &pkt)
|
err = c.WritePacketRTP(0, &pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read another RTP packet from source
|
||||||
|
n, _, err = pc.ReadFrom(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
// wait for first packet
|
// wait for first packet
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
_, _, err = pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -46,25 +46,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
buf = make([]byte, 2048)
|
|
||||||
var pkt rtp.Packet
|
var pkt rtp.Packet
|
||||||
for {
|
for {
|
||||||
// read RTP packets from the source
|
// parse RTP packet
|
||||||
n, _, err := pc.ReadFrom(buf)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse RTP packets
|
|
||||||
err = pkt.Unmarshal(buf[:n])
|
err = pkt.Unmarshal(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// route RTP packets to the server
|
// route RTP packet to the server
|
||||||
err = c.WritePacketRTP(0, &pkt)
|
err = c.WritePacketRTP(0, &pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read another RTP packet from source
|
||||||
|
n, _, err = pc.ReadFrom(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user