mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
allow setting additional properties of streams through description.Stream
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user