allow setting additional properties of streams through description.Stream

This commit is contained in:
aler9
2023-08-16 19:02:49 +02:00
committed by Alessandro Ros
parent 4e000eb2dd
commit cdbecb1f5d
54 changed files with 943 additions and 893 deletions

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -35,16 +35,18 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a G711 format
medi := &media.Media{
Type: media.TypeAudio,
Formats: []format.Format{&format.G711{}},
// create a description that contains a G711 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.G711{}},
}},
}
c := gortsplib.Client{}
// connect to the server and start recording the media
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
// connect to the server and start recording
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -59,7 +61,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -35,16 +35,18 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a G722 format
medi := &media.Media{
Type: media.TypeAudio,
Formats: []format.Format{&format.G722{}},
// create a description that contains a G722 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.G722{}},
}},
}
c := gortsplib.Client{}
// connect to the server and start recording the media
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
// connect to the server and start recording
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -59,7 +61,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -37,18 +37,20 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a H264 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
// create a stream description that contains a H264 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -63,7 +65,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -36,17 +36,19 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a H265 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.H265{
PayloadTyp: 96,
// create a description that contains a H265 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H265{
PayloadTyp: 96,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -61,7 +63,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -35,21 +35,23 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a LPCM format
medi := &media.Media{
Type: media.TypeAudio,
Formats: []format.Format{&format.LPCM{
PayloadTyp: 96,
BitDepth: 16,
SampleRate: 44100,
ChannelCount: 1,
// create a description that contains a LPCM format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.LPCM{
PayloadTyp: 96,
BitDepth: 16,
SampleRate: 44100,
ChannelCount: 1,
}},
}},
}
c := gortsplib.Client{}
// connect to the server and start recording the media
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
// connect to the server and start recording
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -64,7 +66,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -35,15 +35,17 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a M-JPEG format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.MJPEG{}},
// create a description that contains a M-JPEG format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.MJPEG{}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -58,7 +60,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio"
"github.com/pion/rtp"
)
@@ -36,25 +36,27 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a MPEG-4 audio format
medi := &media.Media{
Type: media.TypeAudio,
Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 96,
Config: &mpeg4audio.Config{
Type: mpeg4audio.ObjectTypeAACLC,
SampleRate: 48000,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
// create a description that contains a MPEG-4 audio format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 96,
Config: &mpeg4audio.Config{
Type: mpeg4audio.ObjectTypeAACLC,
SampleRate: 48000,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -69,7 +71,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -35,19 +35,20 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a Opus format
medi := &media.Media{
Type: media.TypeAudio,
Formats: []format.Format{&format.Opus{
PayloadTyp: 96,
IsStereo: false,
// create a description that contains a Opus format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.Opus{
PayloadTyp: 96,
IsStereo: false,
}},
}},
}
// connect to the server and start recording
c := gortsplib.Client{}
// connect to the server and start recording the media
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -62,7 +63,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -36,17 +36,19 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a VP8 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.VP8{
PayloadTyp: 96,
// create a description that contains a VP8 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.VP8{
PayloadTyp: 96,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -61,7 +63,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"net"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -36,17 +36,19 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a VP9 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.VP9{
PayloadTyp: 96,
// create a description that contains a VP9 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.VP9{
PayloadTyp: 96,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -61,7 +63,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -6,8 +6,8 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -37,12 +37,14 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a H264 media
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
// create a stream description that contains a H264 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}},
}},
}
@@ -56,8 +58,8 @@ func main() {
WriteTimeout: 10 * time.Second,
}
// connect to the server and start recording the media
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
// connect to the server and start recording
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -72,7 +74,7 @@ func main() {
}
// route RTP packet to the server
err = c.WritePacketRTP(medi, &pkt)
err = c.WritePacketRTP(desc.Medias[0], &pkt)
if err != nil {
panic(err)
}

View File

@@ -6,8 +6,8 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/pion/rtp"
)
@@ -38,18 +38,20 @@ func main() {
}
log.Println("stream connected")
// create a media that contains a H264 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
// create a stream description that contains a H264 format
desc := &description.Session{
Medias: []*description.Media{{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}},
}},
}
// connect to the server and start recording the media
// connect to the server and start recording
c := gortsplib.Client{}
err = c.StartRecording("rtsp://localhost:8554/mystream", media.Medias{medi})
err = c.StartRecording("rtsp://localhost:8554/mystream", desc)
if err != nil {
panic(err)
}
@@ -66,7 +68,7 @@ func main() {
}
// route RTP packet to the server
c.WritePacketRTP(medi, &pkt)
c.WritePacketRTP(desc.Medias[0], &pkt)
// read another RTP packet from source
n, _, err = pc.ReadFrom(buf)

View File

@@ -25,10 +25,10 @@ func main() {
}
defer c.Close()
medias, _, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
log.Printf("available medias: %v\n", medias)
log.Printf("available medias: %v\n", desc.Medias)
}

View File

@@ -31,14 +31,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the G711 media and format
var forma *format.G711
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -50,7 +50,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -31,14 +31,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the G722 media and format
var forma *format.G722
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -50,7 +50,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -58,14 +58,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the H264 media and format
var forma *format.H264
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -92,7 +92,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -32,14 +32,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the H264 media and format
var forma *format.H264
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -57,7 +57,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -35,14 +35,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the H264 media and format
var forma *format.H264
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -69,7 +69,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -32,14 +32,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the H265 media and format
var forma *format.H265
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -51,7 +51,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -31,14 +31,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the LPCM media and format
var forma *format.LPCM
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -50,7 +50,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -35,14 +35,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the M-JPEG media and format
var forma *format.MJPEG
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -54,7 +54,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -11,7 +11,7 @@ import (
// This example shows how to
// 1. connect to a RTSP server
// 2. check if there's an MPEG4-audio media
// 2. check if there's an MPEG-4 audio media
// 3. save the content of the media into a file in MPEG-TS format
func main() {
@@ -31,32 +31,32 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the MPEG4-audio media and format
// find the MPEG-4 audio media and format
var forma *format.MPEG4Audio
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
// setup RTP/MPEG4-audio -> MPEG4-audio decoder
// setup RTP/MPEG-4 audio -> MPEG-4 audio decoder
rtpDec, err := forma.CreateDecoder()
if err != nil {
panic(err)
}
// setup MPEG4-audio -> MPEG-TS muxer
// setup MPEG-4 audio -> MPEG-TS muxer
mpegtsMuxer, err := newMPEGTSMuxer(forma.Config)
if err != nil {
panic(err)
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -31,14 +31,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the MPEG4-audio media and format
var forma *format.MPEG4Audio
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -50,7 +50,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -31,14 +31,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the Opus media and format
var forma *format.Opus
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -50,7 +50,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -32,14 +32,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the VP8 media and format
var forma *format.VP8
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -51,7 +51,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -32,14 +32,14 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the VP9 media and format
var forma *format.VP9
medi := medias.FindFormat(&forma)
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
@@ -51,7 +51,7 @@ func main() {
}
// setup a single media
_, err = c.Setup(baseURL, medi, 0, 0)
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}

View File

@@ -5,8 +5,8 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/url"
"github.com/pion/rtcp"
"github.com/pion/rtp"
@@ -41,24 +41,24 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// setup all medias
err = c.SetupAll(baseURL, medias)
err = c.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
panic(err)
}
// called when a RTP packet arrives
c.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
c.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
log.Printf("RTP packet from media %v\n", medi)
})
// called when a RTCP packet arrives
c.OnPacketRTCPAny(func(medi *media.Media, pkt rtcp.Packet) {
c.OnPacketRTCPAny(func(medi *description.Media, pkt rtcp.Packet) {
log.Printf("RTCP packet from media %v, type %T\n", medi, pkt)
})

View File

@@ -5,8 +5,8 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/url"
"github.com/pion/rtcp"
"github.com/pion/rtp"
@@ -35,24 +35,24 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// setup all medias
err = c.SetupAll(baseURL, medias)
err = c.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
panic(err)
}
// called when a RTP packet arrives
c.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
c.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
log.Printf("RTP packet from media %v\n", medi)
})
// called when a RTCP packet arrives
c.OnPacketRTCPAny(func(medi *media.Media, pkt rtcp.Packet) {
c.OnPacketRTCPAny(func(medi *description.Media, pkt rtcp.Packet) {
log.Printf("RTCP packet from media %v, type %T\n", medi, pkt)
})

View File

@@ -4,8 +4,8 @@ import (
"log"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/url"
"github.com/pion/rtp"
)
@@ -31,31 +31,31 @@ func main() {
defer reader.Close()
// find published medias
medias, baseURL, _, err := reader.Describe(sourceURL)
desc, _, err := reader.Describe(sourceURL)
if err != nil {
panic(err)
}
log.Printf("republishing %d medias", len(medias))
log.Printf("republishing %d medias", len(desc.Medias))
// setup all medias
// this must be called before StartRecording(), since it overrides the control attribute.
err = reader.SetupAll(baseURL, medias)
err = reader.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
panic(err)
}
// connect to the server and start recording the same medias
publisher := gortsplib.Client{}
err = publisher.StartRecording("rtsp://localhost:8554/mystream2", medias)
err = publisher.StartRecording("rtsp://localhost:8554/mystream2", desc)
if err != nil {
panic(err)
}
defer publisher.Close()
// 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)
reader.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
publisher.WritePacketRTP(desc.Medias[0], pkt)
})
// start playing

View File

@@ -4,8 +4,8 @@ import (
"log"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/url"
"github.com/pion/rtcp"
"github.com/pion/rtp"
@@ -32,24 +32,24 @@ func main() {
defer c.Close()
// find published medias
medias, baseURL, _, err := c.Describe(u)
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// setup all medias
err = c.SetupAll(baseURL, medias)
err = c.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
panic(err)
}
// called when a RTP packet arrives
c.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
c.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
log.Printf("RTP packet from media %v\n", medi)
})
// called when a RTCP packet arrives
c.OnPacketRTCPAny(func(medi *media.Media, pkt rtcp.Packet) {
c.OnPacketRTCPAny(func(medi *description.Media, pkt rtcp.Packet) {
log.Printf("RTCP packet from media %v, type %T\n", medi, pkt)
})

View File

@@ -5,8 +5,8 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/url"
"github.com/pion/rtp"
)
@@ -57,24 +57,24 @@ func (c *client) read() error {
defer rc.Close()
// find published medias
medias, baseURL, _, err := rc.Describe(u)
desc, _, err := rc.Describe(u)
if err != nil {
return err
}
// setup all medias
err = rc.SetupAll(baseURL, medias)
err = rc.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
return err
}
stream := c.s.setStreamReady(medias)
stream := c.s.setStreamReady(desc)
defer c.s.setStreamUnready()
log.Printf("stream is ready and can be read from the server at rtsp://localhost:8554/stream\n")
// called when a RTP packet arrives
rc.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
rc.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
// route incoming packets to the server stream
stream.WritePacketRTP(medi, pkt)
})

View File

@@ -6,7 +6,7 @@ import (
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/media"
"github.com/bluenviron/gortsplib/v4/pkg/description"
)
type server struct {
@@ -99,10 +99,10 @@ func (s *server) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response,
}, nil
}
func (s *server) setStreamReady(medias media.Medias) *gortsplib.ServerStream {
func (s *server) setStreamReady(desc *description.Session) *gortsplib.ServerStream {
s.mutex.Lock()
defer s.mutex.Unlock()
s.stream = gortsplib.NewServerStream(s.s, medias)
s.stream = gortsplib.NewServerStream(s.s, desc)
return s.stream
}

View File

@@ -9,9 +9,9 @@ import (
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/format/rtph264"
"github.com/bluenviron/gortsplib/v4/pkg/media"
)
// This example shows how to
@@ -23,7 +23,7 @@ type serverHandler struct {
s *gortsplib.Server
mutex sync.Mutex
publisher *gortsplib.ServerSession
media *media.Media
media *description.Media
format *format.H264
rtpDec *rtph264.Decoder
mpegtsMuxer *mpegtsMuxer
@@ -69,7 +69,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
// find the H264 media and format
var forma *format.H264
medi := ctx.Medias.FindFormat(&forma)
medi := ctx.Description.FindFormat(&forma)
if medi == nil {
return &base.Response{
StatusCode: base.StatusBadRequest,

View File

@@ -9,8 +9,8 @@ import (
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
)
// This example shows how to
@@ -89,7 +89,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
}
// create the stream and save the publisher
sh.stream = gortsplib.NewServerStream(sh.s, ctx.Medias)
sh.stream = gortsplib.NewServerStream(sh.s, ctx.Description)
sh.publisher = ctx.Session
return &base.Response{
@@ -127,7 +127,7 @@ func (sh *serverHandler) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*bas
log.Printf("record request")
// called when receiving a RTP packet
ctx.Session.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
ctx.Session.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
// route the RTP packet to all readers
sh.stream.WritePacketRTP(medi, pkt)
})

View File

@@ -8,8 +8,8 @@ import (
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/media"
)
// This example shows how to
@@ -88,7 +88,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
}
// create the stream and save the publisher
sh.stream = gortsplib.NewServerStream(sh.s, ctx.Medias)
sh.stream = gortsplib.NewServerStream(sh.s, ctx.Description)
sh.publisher = ctx.Session
return &base.Response{
@@ -126,7 +126,7 @@ func (sh *serverHandler) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*bas
log.Printf("record request")
// called when receiving a RTP packet
ctx.Session.OnPacketRTPAny(func(medi *media.Media, forma format.Format, pkt *rtp.Packet) {
ctx.Session.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
// route the RTP packet to all readers
sh.stream.WritePacketRTP(medi, pkt)
})