mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
improve example comments
This commit is contained in:
@@ -61,13 +61,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read frames from the source
|
// read RTP frames from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write track frames
|
// write RTP frames
|
||||||
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -57,13 +57,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read frames from the source
|
// read RTP frames from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// write track frames
|
// write RTP frames
|
||||||
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
@@ -49,13 +49,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read frames from the source
|
// read RTP frames from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write track frames
|
// write RTP frames
|
||||||
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -37,14 +37,16 @@ func main() {
|
|||||||
// instantiate a decoder
|
// instantiate a decoder
|
||||||
dec := rtph264.NewDecoder()
|
dec := rtph264.NewDecoder()
|
||||||
|
|
||||||
// get H264 NALUs of that track
|
// read RTP frames
|
||||||
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||||
if trackID == h264Track {
|
if trackID == h264Track {
|
||||||
|
// convert RTP frames into H264 NALUs
|
||||||
nts, err := dec.Decode(buf)
|
nts, err := dec.Decode(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print NALUs
|
||||||
for _, nt := range nts {
|
for _, nt := range nts {
|
||||||
fmt.Printf("received H264 NALU of size %d\n", len(nt.NALU))
|
fmt.Printf("received H264 NALU of size %d\n", len(nt.NALU))
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read track frames
|
// read RTP frames
|
||||||
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||||
})
|
})
|
||||||
|
@@ -35,8 +35,8 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range tracks {
|
|
||||||
// start reading only video tracks, skipping audio or application tracks
|
// start reading only video tracks, skipping audio or application tracks
|
||||||
|
for _, t := range tracks {
|
||||||
if t.Media.MediaName.Media == "video" {
|
if t.Media.MediaName.Media == "video" {
|
||||||
_, err := conn.Setup(headers.TransportModePlay, t, 0, 0)
|
_, err := conn.Setup(headers.TransportModePlay, t, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,12 +45,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// play setupped tracks
|
||||||
_, err = conn.Play()
|
_, err = conn.Play()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read track frames
|
// read RTP frames
|
||||||
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||||
})
|
})
|
||||||
|
@@ -22,7 +22,7 @@ func main() {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// read track frames
|
// read RTP frames
|
||||||
done := conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
done := conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||||
})
|
})
|
||||||
|
@@ -17,7 +17,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read track frames
|
// read RTP frames
|
||||||
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
err = <-conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user