mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
fix client-publish-udp example
This commit is contained in:
@@ -15,6 +15,13 @@ import (
|
||||
// the frames with the UDP protocol.
|
||||
|
||||
func main() {
|
||||
var writerDone chan struct{}
|
||||
defer func() {
|
||||
if writerDone != nil {
|
||||
<-writerDone
|
||||
}
|
||||
}()
|
||||
|
||||
// open a listener to receive RTP/H264 frames
|
||||
pc, err := net.ListenPacket("udp4", "127.0.0.1:9000")
|
||||
if err != nil {
|
||||
@@ -48,20 +55,26 @@ func main() {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
for {
|
||||
// read frames from the source
|
||||
n, _, err := pc.ReadFrom(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
writerDone = make(chan struct{})
|
||||
|
||||
// write frames to the server
|
||||
err = conn.WriteFrameUDP(track.Id, gortsplib.StreamTypeRtp, buf[:n])
|
||||
if err != nil {
|
||||
break
|
||||
go func() {
|
||||
defer close(writerDone)
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
for {
|
||||
// read frames from the source
|
||||
n, _, err := pc.ReadFrom(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// write frames to the server
|
||||
err = conn.WriteFrameUDP(track.Id, gortsplib.StreamTypeRtp, buf[:n])
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// wait until the connection is closed
|
||||
err = conn.LoopUDP()
|
||||
|
Reference in New Issue
Block a user