diff --git a/examples/client-publish-aac/main.go b/examples/client-publish-aac/main.go index e9b87fe2..a1f17f5b 100644 --- a/examples/client-publish-aac/main.go +++ b/examples/client-publish-aac/main.go @@ -27,7 +27,7 @@ func main() { // wait for first packet buf := make([]byte, 2048) - _, _, err = pc.ReadFrom(buf) + n, _, err := pc.ReadFrom(buf) if err != nil { panic(err) } @@ -39,9 +39,8 @@ func main() { panic(err) } - c := gortsplib.Client{} - // connect to the server and start publishing the track + c := gortsplib.Client{} err = c.StartPublishing("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { @@ -49,25 +48,24 @@ func main() { } defer c.Close() - buf = make([]byte, 2048) var pkt rtp.Packet for { - // read RTP packets from the source - n, _, err := pc.ReadFrom(buf) - if err != nil { - panic(err) - } - - // parse RTP packets + // parse RTP packet err = pkt.Unmarshal(buf[:n]) if err != nil { panic(err) } - // route RTP packets to the server + // route RTP packet to the server err = c.WritePacketRTP(0, &pkt) if err != nil { panic(err) } + + // read another RTP packet from source + n, _, err = pc.ReadFrom(buf) + if err != nil { + panic(err) + } } } diff --git a/examples/client-publish-h264/main.go b/examples/client-publish-h264/main.go index 0e813dc9..f6639ba2 100644 --- a/examples/client-publish-h264/main.go +++ b/examples/client-publish-h264/main.go @@ -42,9 +42,8 @@ func main() { panic(err) } - c := gortsplib.Client{} - // connect to the server and start publishing the track + c := gortsplib.Client{} err = c.StartPublishing("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { diff --git a/examples/client-publish-opus/main.go b/examples/client-publish-opus/main.go index 43482722..123b47f6 100644 --- a/examples/client-publish-opus/main.go +++ b/examples/client-publish-opus/main.go @@ -27,7 +27,7 @@ func main() { // wait for first packet buf := make([]byte, 2048) - _, _, err = pc.ReadFrom(buf) + n, _, err := pc.ReadFrom(buf) if err != nil { panic(err) } @@ -49,25 +49,24 @@ func main() { } defer c.Close() - buf = make([]byte, 2048) var pkt rtp.Packet for { - // read RTP packets from the source - n, _, err := pc.ReadFrom(buf) - if err != nil { - panic(err) - } - - // parse RTP packets + // parse RTP packet err = pkt.Unmarshal(buf[:n]) if err != nil { panic(err) } - // route RTP packets to the server + // route RTP packet to the server err = c.WritePacketRTP(0, &pkt) if err != nil { panic(err) } + + // read another RTP packet from source + n, _, err = pc.ReadFrom(buf) + if err != nil { + panic(err) + } } } diff --git a/examples/client-publish-pcmu/main.go b/examples/client-publish-pcmu/main.go index 1c02530e..baa9c3a8 100644 --- a/examples/client-publish-pcmu/main.go +++ b/examples/client-publish-pcmu/main.go @@ -27,7 +27,7 @@ func main() { // wait for first packet buf := make([]byte, 2048) - _, _, err = pc.ReadFrom(buf) + n, _, err := pc.ReadFrom(buf) if err != nil { panic(err) } @@ -46,25 +46,24 @@ func main() { } defer c.Close() - buf = make([]byte, 2048) var pkt rtp.Packet for { - // read RTP packets from the source - n, _, err := pc.ReadFrom(buf) - if err != nil { - panic(err) - } - - // parse RTP packets + // parse RTP packet err = pkt.Unmarshal(buf[:n]) if err != nil { panic(err) } - // route RTP packets to the server + // route RTP packet to the server err = c.WritePacketRTP(0, &pkt) if err != nil { panic(err) } + + // read another RTP packet from source + n, _, err = pc.ReadFrom(buf) + if err != nil { + panic(err) + } } }