diff --git a/README.md b/README.md index b3e9bfce..c6da654b 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,11 @@ Features: * Compute and provide SSRC, RTP-Info to clients * Generate RTCP sender reports * Utilities - * Parse RTSP elements ([pkg/base](pkg/base), [pkg/headers](pkg/headers)) - * Encode/decode format-specific frames into/from RTP packets ([pkg/formatdecenc](pkg/formatdecenc)). The following formats are supported: + * Parse RTSP elements + * Encode/decode format-specific frames into/from RTP packets. The following formats are supported: * Video: H264, H265, M-JPEG, VP8, VP9 * Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG4 Audio (AAC), Opus - * Parse codec-specific elements ([pkg/codecs](pkg/codecs)). The following codecs are supported: + * Parse codec-specific elements. The following codecs are supported: * Video: H264, H265, M-JPEG * Audio: MPEG4 Audio (AAC) diff --git a/examples/client-publish-format-g711/main.go b/examples/client-publish-format-g711/main.go index 62bafb8a..bf7a5ca9 100644 --- a/examples/client-publish-format-g711/main.go +++ b/examples/client-publish-format-g711/main.go @@ -36,15 +36,15 @@ func main() { log.Println("stream connected") // create a media that contains a G711 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.G711{}}, - }} + } c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -59,7 +59,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-g722/main.go b/examples/client-publish-format-g722/main.go index ac1b1784..28a1a125 100644 --- a/examples/client-publish-format-g722/main.go +++ b/examples/client-publish-format-g722/main.go @@ -36,15 +36,15 @@ func main() { log.Println("stream connected") // create a media that contains a G722 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.G722{}}, - }} + } c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -59,7 +59,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-h264/main.go b/examples/client-publish-format-h264/main.go index 4c82c147..603ec53f 100644 --- a/examples/client-publish-format-h264/main.go +++ b/examples/client-publish-format-h264/main.go @@ -37,17 +37,17 @@ func main() { log.Println("stream connected") // create a media that contains a H264 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -62,7 +62,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-h265/main.go b/examples/client-publish-format-h265/main.go index 8187d690..cc389392 100644 --- a/examples/client-publish-format-h265/main.go +++ b/examples/client-publish-format-h265/main.go @@ -37,16 +37,16 @@ func main() { log.Println("stream connected") // create a media that contains a H265 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H265{ PayloadTyp: 96, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -61,7 +61,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-lpcm/main.go b/examples/client-publish-format-lpcm/main.go index 07bf28a4..c189895e 100644 --- a/examples/client-publish-format-lpcm/main.go +++ b/examples/client-publish-format-lpcm/main.go @@ -36,7 +36,7 @@ func main() { log.Println("stream connected") // create a media that contains a LPCM format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.LPCM{ PayloadTyp: 96, @@ -44,12 +44,12 @@ func main() { SampleRate: 44100, ChannelCount: 1, }}, - }} + } c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -64,7 +64,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-mjpeg/main.go b/examples/client-publish-format-mjpeg/main.go index bc20f0bd..dd11d847 100644 --- a/examples/client-publish-format-mjpeg/main.go +++ b/examples/client-publish-format-mjpeg/main.go @@ -36,14 +36,14 @@ func main() { log.Println("stream connected") // create a media that contains a M-JPEG format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.MJPEG{}}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -58,7 +58,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-mpeg4audio/main.go b/examples/client-publish-format-mpeg4audio/main.go index 9dc40086..d916046b 100644 --- a/examples/client-publish-format-mpeg4audio/main.go +++ b/examples/client-publish-format-mpeg4audio/main.go @@ -37,7 +37,7 @@ func main() { log.Println("stream connected") // create a media that contains a MPEG4-audio format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.MPEG4Audio{ PayloadTyp: 96, @@ -50,11 +50,11 @@ func main() { IndexLength: 3, IndexDeltaLength: 3, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -69,7 +69,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-opus/main.go b/examples/client-publish-format-opus/main.go index ad9e3916..99caef55 100644 --- a/examples/client-publish-format-opus/main.go +++ b/examples/client-publish-format-opus/main.go @@ -36,19 +36,19 @@ func main() { log.Println("stream connected") // create a media that contains a Opus format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.Opus{ PayloadTyp: 96, SampleRate: 48000, ChannelCount: 2, }}, - }} + } c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -63,7 +63,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-vp8/main.go b/examples/client-publish-format-vp8/main.go index 03ef567f..4df755e9 100644 --- a/examples/client-publish-format-vp8/main.go +++ b/examples/client-publish-format-vp8/main.go @@ -37,16 +37,16 @@ func main() { log.Println("stream connected") // create a media that contains a VP8 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.VP8{ PayloadTyp: 96, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -61,7 +61,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-vp9/main.go b/examples/client-publish-format-vp9/main.go index d1fcb002..a557cbc9 100644 --- a/examples/client-publish-format-vp9/main.go +++ b/examples/client-publish-format-vp9/main.go @@ -37,16 +37,16 @@ func main() { log.Println("stream connected") // create a media that contains a VP9 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.VP9{ PayloadTyp: 96, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -61,7 +61,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-options/main.go b/examples/client-publish-options/main.go index 751c22c7..0e063b76 100644 --- a/examples/client-publish-options/main.go +++ b/examples/client-publish-options/main.go @@ -38,13 +38,13 @@ func main() { log.Println("stream connected") // create a media that contains a H264 media - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - }} + } // Client allows to set additional client options c := &gortsplib.Client{ @@ -57,7 +57,7 @@ func main() { } // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -72,7 +72,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medias[0], &pkt) + err = c.WritePacketRTP(medi, &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-pause/main.go b/examples/client-publish-pause/main.go index 3ffea479..240f53f6 100644 --- a/examples/client-publish-pause/main.go +++ b/examples/client-publish-pause/main.go @@ -39,17 +39,17 @@ func main() { log.Println("stream connected") // create a media that contains a H264 format - medias := media.Medias{&media.Media{ + medi := &media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - }} + } // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", medias) + err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi}) if err != nil { panic(err) } @@ -66,7 +66,7 @@ func main() { } // route RTP packet to the server - c.WritePacketRTP(medias[0], &pkt) + c.WritePacketRTP(medi, &pkt) // read another RTP packet from source n, _, err = pc.ReadFrom(buf) diff --git a/examples/client-read-format-g711/main.go b/examples/client-read-format-g711/main.go index 147e9213..76414032 100644 --- a/examples/client-read-format-g711/main.go +++ b/examples/client-read-format-g711/main.go @@ -43,10 +43,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode a G711 packet from the RTP packet + // extract G711 frames from RTP packets op, _, err := rtpDec.Decode(pkt) if err != nil { log.Printf("ERR: %v", err) diff --git a/examples/client-read-format-g722/main.go b/examples/client-read-format-g722/main.go index 2e2f4356..55ddbac0 100644 --- a/examples/client-read-format-g722/main.go +++ b/examples/client-read-format-g722/main.go @@ -43,10 +43,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode a G722 packet from the RTP packet + // extract G722 frames from RTP packets op, _, err := rtpDec.Decode(pkt) if err != nil { log.Printf("ERR: %v", err) diff --git a/examples/client-read-format-h264-convert-to-jpeg/main.go b/examples/client-read-format-h264-convert-to-jpeg/main.go index 098f259a..c43024d2 100644 --- a/examples/client-read-format-h264-convert-to-jpeg/main.go +++ b/examples/client-read-format-h264-convert-to-jpeg/main.go @@ -90,7 +90,7 @@ func main() { h264RawDec.decode(pps) } - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -99,7 +99,7 @@ func main() { // called when a RTP packet arrives saveCount := 0 c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // convert RTP packets into NALUs + // extract NALUs from RTP packets nalus, _, err := rtpDec.Decode(pkt) if err != nil { if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded { diff --git a/examples/client-read-format-h264-save-to-disk/main.go b/examples/client-read-format-h264-save-to-disk/main.go index 6ed7cf8a..60d1f959 100644 --- a/examples/client-read-format-h264-save-to-disk/main.go +++ b/examples/client-read-format-h264-save-to-disk/main.go @@ -53,7 +53,7 @@ func main() { panic(err) } - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -61,7 +61,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // convert RTP packets into NALUs + // extract NALUs from RTP packets // DecodeUntilMarker is necessary for the DTS extractor to work nalus, pts, err := rtpDec.DecodeUntilMarker(pkt) if err != nil { diff --git a/examples/client-read-format-h264/main.go b/examples/client-read-format-h264/main.go index 156d8b97..43807351 100644 --- a/examples/client-read-format-h264/main.go +++ b/examples/client-read-format-h264/main.go @@ -67,7 +67,7 @@ func main() { h264RawDec.decode(pps) } - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -75,7 +75,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // convert RTP packets into NALUs + // extract NALUs from RTP packets nalus, pts, err := rtpDec.Decode(pkt) if err != nil { if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded { diff --git a/examples/client-read-format-h265/main.go b/examples/client-read-format-h265/main.go index 7e8469b6..e5a7755b 100644 --- a/examples/client-read-format-h265/main.go +++ b/examples/client-read-format-h265/main.go @@ -47,7 +47,7 @@ func main() { // setup RTP/H265->H265 decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -55,7 +55,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // convert RTP packets into NALUs + // extract NALUs from RTP packets nalus, pts, err := rtpDec.Decode(pkt) if err != nil { if err != rtph265.ErrNonStartingPacketAndNoPrevious && err != rtph265.ErrMorePacketsNeeded { diff --git a/examples/client-read-format-lpcm/main.go b/examples/client-read-format-lpcm/main.go index 6a757943..ad020736 100644 --- a/examples/client-read-format-lpcm/main.go +++ b/examples/client-read-format-lpcm/main.go @@ -43,10 +43,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode LPCM samples from the RTP packet + // extract LPCM samples from RTP packets op, _, err := rtpDec.Decode(pkt) if err != nil { log.Printf("ERR: %v", err) diff --git a/examples/client-read-format-mjpeg/main.go b/examples/client-read-format-mjpeg/main.go index 1c644e71..22036861 100644 --- a/examples/client-read-format-mjpeg/main.go +++ b/examples/client-read-format-mjpeg/main.go @@ -47,10 +47,10 @@ func main() { panic("media not found") } - // setup RTP/M-JPEG->M-JPEG decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -58,7 +58,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // convert RTP packets into JPEG images + // extract JPEG images from RTP packets enc, pts, err := rtpDec.Decode(pkt) if err != nil { if err != rtpmjpeg.ErrNonStartingPacketAndNoPrevious && err != rtpmjpeg.ErrMorePacketsNeeded { diff --git a/examples/client-read-format-mpeg4audio/main.go b/examples/client-read-format-mpeg4audio/main.go index 76cbdc85..b355d7c6 100644 --- a/examples/client-read-format-mpeg4audio/main.go +++ b/examples/client-read-format-mpeg4audio/main.go @@ -43,10 +43,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode MPEG4-audio AUs from the RTP packet + // extract access units from RTP packets aus, _, err := rtpDec.Decode(pkt) if err != nil { log.Printf("ERR: %v", err) diff --git a/examples/client-read-format-opus/main.go b/examples/client-read-format-opus/main.go index a8a9dbcd..c9861744 100644 --- a/examples/client-read-format-opus/main.go +++ b/examples/client-read-format-opus/main.go @@ -43,10 +43,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -54,7 +54,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode an Opus packet from the RTP packet + // extract Opus packets from RTP packets op, _, err := rtpDec.Decode(pkt) if err != nil { log.Printf("ERR: %v", err) diff --git a/examples/client-read-format-vp8/main.go b/examples/client-read-format-vp8/main.go index df0c83d0..1df33340 100644 --- a/examples/client-read-format-vp8/main.go +++ b/examples/client-read-format-vp8/main.go @@ -44,10 +44,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -55,7 +55,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode a VP8 frame from the RTP packet + // extract VP8 frames from RTP packets vf, _, err := rtpDec.Decode(pkt) if err != nil { if err != rtpvp8.ErrNonStartingPacketAndNoPrevious && err != rtpvp8.ErrMorePacketsNeeded { diff --git a/examples/client-read-format-vp9/main.go b/examples/client-read-format-vp9/main.go index 65568f7b..cf821909 100644 --- a/examples/client-read-format-vp9/main.go +++ b/examples/client-read-format-vp9/main.go @@ -44,10 +44,10 @@ func main() { panic("media not found") } - // setup decoder + // create decoder rtpDec := forma.CreateDecoder() - // setup the chosen media only + // setup a single media _, err = c.Setup(medi, baseURL, 0, 0) if err != nil { panic(err) @@ -55,7 +55,7 @@ func main() { // called when a RTP packet arrives c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { - // decode a VP9 frame from the RTP packet + // extract VP9 frames from RTP packets vf, _, err := rtpDec.Decode(pkt) if err != nil { if err != rtpvp9.ErrNonStartingPacketAndNoPrevious && err != rtpvp9.ErrMorePacketsNeeded { diff --git a/examples/client-read-republish/main.go b/examples/client-read-republish/main.go index 6db71117..17c82f84 100644 --- a/examples/client-read-republish/main.go +++ b/examples/client-read-republish/main.go @@ -39,7 +39,7 @@ func main() { log.Printf("republishing %d medias", len(medias)) // setup all medias - // this must be called before StartRecording(), that overrides the control attribute. + // this must be called before StartRecording(), since it overrides the control attribute. err = reader.SetupAll(medias, baseURL) if err != nil { panic(err) @@ -53,7 +53,7 @@ func main() { } defer publisher.Close() - // read RTP packets from reader and write them to publisher + // read RTP packets from the reader and route them to the publisher reader.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) { publisher.WritePacketRTP(medi, pkt) })