improve examples

This commit is contained in:
aler9
2023-01-07 11:46:00 +01:00
parent bf12e12afd
commit 441a90a519
26 changed files with 85 additions and 85 deletions

View File

@@ -45,11 +45,11 @@ Features:
* Compute and provide SSRC, RTP-Info to clients * Compute and provide SSRC, RTP-Info to clients
* Generate RTCP sender reports * Generate RTCP sender reports
* Utilities * Utilities
* Parse RTSP elements ([pkg/base](pkg/base), [pkg/headers](pkg/headers)) * Parse RTSP elements
* Encode/decode format-specific frames into/from RTP packets ([pkg/formatdecenc](pkg/formatdecenc)). The following formats are supported: * Encode/decode format-specific frames into/from RTP packets. The following formats are supported:
* Video: H264, H265, M-JPEG, VP8, VP9 * Video: H264, H265, M-JPEG, VP8, VP9
* Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG4 Audio (AAC), Opus * 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 * Video: H264, H265, M-JPEG
* Audio: MPEG4 Audio (AAC) * Audio: MPEG4 Audio (AAC)

View File

@@ -36,15 +36,15 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a G711 format // create a media that contains a G711 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeAudio, Type: media.TypeAudio,
Formats: []format.Format{&format.G711{}}, Formats: []format.Format{&format.G711{}},
}} }
c := gortsplib.Client{} c := gortsplib.Client{}
// connect to the server and start recording the media // 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 { if err != nil {
panic(err) panic(err)
} }
@@ -59,7 +59,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -36,15 +36,15 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a G722 format // create a media that contains a G722 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeAudio, Type: media.TypeAudio,
Formats: []format.Format{&format.G722{}}, Formats: []format.Format{&format.G722{}},
}} }
c := gortsplib.Client{} c := gortsplib.Client{}
// connect to the server and start recording the media // 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 { if err != nil {
panic(err) panic(err)
} }
@@ -59,7 +59,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -37,17 +37,17 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a H264 format // create a media that contains a H264 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.H264{ Formats: []format.Format{&format.H264{
PayloadTyp: 96, PayloadTyp: 96,
PacketizationMode: 1, PacketizationMode: 1,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -62,7 +62,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -37,16 +37,16 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a H265 format // create a media that contains a H265 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.H265{ Formats: []format.Format{&format.H265{
PayloadTyp: 96, PayloadTyp: 96,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -61,7 +61,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -36,7 +36,7 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a LPCM format // create a media that contains a LPCM format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeAudio, Type: media.TypeAudio,
Formats: []format.Format{&format.LPCM{ Formats: []format.Format{&format.LPCM{
PayloadTyp: 96, PayloadTyp: 96,
@@ -44,12 +44,12 @@ func main() {
SampleRate: 44100, SampleRate: 44100,
ChannelCount: 1, ChannelCount: 1,
}}, }},
}} }
c := gortsplib.Client{} c := gortsplib.Client{}
// connect to the server and start recording the media // 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 { if err != nil {
panic(err) panic(err)
} }
@@ -64,7 +64,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -36,14 +36,14 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a M-JPEG format // create a media that contains a M-JPEG format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.MJPEG{}}, Formats: []format.Format{&format.MJPEG{}},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -58,7 +58,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -37,7 +37,7 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a MPEG4-audio format // create a media that contains a MPEG4-audio format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeAudio, Type: media.TypeAudio,
Formats: []format.Format{&format.MPEG4Audio{ Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 96, PayloadTyp: 96,
@@ -50,11 +50,11 @@ func main() {
IndexLength: 3, IndexLength: 3,
IndexDeltaLength: 3, IndexDeltaLength: 3,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -69,7 +69,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -36,19 +36,19 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a Opus format // create a media that contains a Opus format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeAudio, Type: media.TypeAudio,
Formats: []format.Format{&format.Opus{ Formats: []format.Format{&format.Opus{
PayloadTyp: 96, PayloadTyp: 96,
SampleRate: 48000, SampleRate: 48000,
ChannelCount: 2, ChannelCount: 2,
}}, }},
}} }
c := gortsplib.Client{} c := gortsplib.Client{}
// connect to the server and start recording the media // 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 { if err != nil {
panic(err) panic(err)
} }
@@ -63,7 +63,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -37,16 +37,16 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a VP8 format // create a media that contains a VP8 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.VP8{ Formats: []format.Format{&format.VP8{
PayloadTyp: 96, PayloadTyp: 96,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -61,7 +61,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -37,16 +37,16 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a VP9 format // create a media that contains a VP9 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.VP9{ Formats: []format.Format{&format.VP9{
PayloadTyp: 96, PayloadTyp: 96,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -61,7 +61,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -38,13 +38,13 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a H264 media // create a media that contains a H264 media
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.H264{ Formats: []format.Format{&format.H264{
PayloadTyp: 96, PayloadTyp: 96,
PacketizationMode: 1, PacketizationMode: 1,
}}, }},
}} }
// Client allows to set additional client options // Client allows to set additional client options
c := &gortsplib.Client{ c := &gortsplib.Client{
@@ -57,7 +57,7 @@ func main() {
} }
// connect to the server and start recording the media // 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 { if err != nil {
panic(err) panic(err)
} }
@@ -72,7 +72,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
err = c.WritePacketRTP(medias[0], &pkt) err = c.WritePacketRTP(medi, &pkt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -39,17 +39,17 @@ func main() {
log.Println("stream connected") log.Println("stream connected")
// create a media that contains a H264 format // create a media that contains a H264 format
medias := media.Medias{&media.Media{ medi := &media.Media{
Type: media.TypeVideo, Type: media.TypeVideo,
Formats: []format.Format{&format.H264{ Formats: []format.Format{&format.H264{
PayloadTyp: 96, PayloadTyp: 96,
PacketizationMode: 1, PacketizationMode: 1,
}}, }},
}} }
// connect to the server and start recording the media // connect to the server and start recording the media
c := gortsplib.Client{} c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", medias) err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -66,7 +66,7 @@ func main() {
} }
// route RTP packet to the server // route RTP packet to the server
c.WritePacketRTP(medias[0], &pkt) c.WritePacketRTP(medi, &pkt)
// read another RTP packet from source // read another RTP packet from source
n, _, err = pc.ReadFrom(buf) n, _, err = pc.ReadFrom(buf)

View File

@@ -43,10 +43,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -54,7 +54,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) op, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
log.Printf("ERR: %v", err) log.Printf("ERR: %v", err)

View File

@@ -43,10 +43,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -54,7 +54,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) op, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
log.Printf("ERR: %v", err) log.Printf("ERR: %v", err)

View File

@@ -90,7 +90,7 @@ func main() {
h264RawDec.decode(pps) h264RawDec.decode(pps)
} }
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -99,7 +99,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
saveCount := 0 saveCount := 0
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) {
// convert RTP packets into NALUs // extract NALUs from RTP packets
nalus, _, err := rtpDec.Decode(pkt) nalus, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded { if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded {

View File

@@ -53,7 +53,7 @@ func main() {
panic(err) panic(err)
} }
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -61,7 +61,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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 // DecodeUntilMarker is necessary for the DTS extractor to work
nalus, pts, err := rtpDec.DecodeUntilMarker(pkt) nalus, pts, err := rtpDec.DecodeUntilMarker(pkt)
if err != nil { if err != nil {

View File

@@ -67,7 +67,7 @@ func main() {
h264RawDec.decode(pps) h264RawDec.decode(pps)
} }
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -75,7 +75,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) {
// convert RTP packets into NALUs // extract NALUs from RTP packets
nalus, pts, err := rtpDec.Decode(pkt) nalus, pts, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded { if err != rtph264.ErrNonStartingPacketAndNoPrevious && err != rtph264.ErrMorePacketsNeeded {

View File

@@ -47,7 +47,7 @@ func main() {
// setup RTP/H265->H265 decoder // setup RTP/H265->H265 decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -55,7 +55,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) {
// convert RTP packets into NALUs // extract NALUs from RTP packets
nalus, pts, err := rtpDec.Decode(pkt) nalus, pts, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtph265.ErrNonStartingPacketAndNoPrevious && err != rtph265.ErrMorePacketsNeeded { if err != rtph265.ErrNonStartingPacketAndNoPrevious && err != rtph265.ErrMorePacketsNeeded {

View File

@@ -43,10 +43,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -54,7 +54,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) op, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
log.Printf("ERR: %v", err) log.Printf("ERR: %v", err)

View File

@@ -47,10 +47,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup RTP/M-JPEG->M-JPEG decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -58,7 +58,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) enc, pts, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtpmjpeg.ErrNonStartingPacketAndNoPrevious && err != rtpmjpeg.ErrMorePacketsNeeded { if err != rtpmjpeg.ErrNonStartingPacketAndNoPrevious && err != rtpmjpeg.ErrMorePacketsNeeded {

View File

@@ -43,10 +43,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -54,7 +54,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) aus, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
log.Printf("ERR: %v", err) log.Printf("ERR: %v", err)

View File

@@ -43,10 +43,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -54,7 +54,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) op, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
log.Printf("ERR: %v", err) log.Printf("ERR: %v", err)

View File

@@ -44,10 +44,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -55,7 +55,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) vf, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtpvp8.ErrNonStartingPacketAndNoPrevious && err != rtpvp8.ErrMorePacketsNeeded { if err != rtpvp8.ErrNonStartingPacketAndNoPrevious && err != rtpvp8.ErrMorePacketsNeeded {

View File

@@ -44,10 +44,10 @@ func main() {
panic("media not found") panic("media not found")
} }
// setup decoder // create decoder
rtpDec := forma.CreateDecoder() rtpDec := forma.CreateDecoder()
// setup the chosen media only // setup a single media
_, err = c.Setup(medi, baseURL, 0, 0) _, err = c.Setup(medi, baseURL, 0, 0)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -55,7 +55,7 @@ func main() {
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) { 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) vf, _, err := rtpDec.Decode(pkt)
if err != nil { if err != nil {
if err != rtpvp9.ErrNonStartingPacketAndNoPrevious && err != rtpvp9.ErrMorePacketsNeeded { if err != rtpvp9.ErrNonStartingPacketAndNoPrevious && err != rtpvp9.ErrMorePacketsNeeded {

View File

@@ -39,7 +39,7 @@ func main() {
log.Printf("republishing %d medias", len(medias)) log.Printf("republishing %d medias", len(medias))
// setup all 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) err = reader.SetupAll(medias, baseURL)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -53,7 +53,7 @@ func main() {
} }
defer publisher.Close() 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) { reader.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
publisher.WritePacketRTP(medi, pkt) publisher.WritePacketRTP(medi, pkt)
}) })