From 1f3c94a8f8aa428b85b6010c987ab2cad66b9dc5 Mon Sep 17 00:00:00 2001 From: notedit Date: Sun, 30 Jun 2019 19:43:37 +0800 Subject: [PATCH] fix streamer session Former-commit-id: dc4810048e0823c75a109ac5df3c8aac1cb7c880 [formerly 772fdbf8a711025cea0d7443bd130f00c5c027fd] [formerly 20657ff858354dd3268b7e1594e5f9d9dd9beb34 [formerly 86c94f0907ea8285dcb36bd5e998a30c3a0db597]] Former-commit-id: e9e373fbef9c0526b8df867a17e835546e4344d1 [formerly 18209748165e7289cc49cf4eff693c173717aa54] Former-commit-id: 297dd6e792897160e45a96a55afc1f047559659d --- streamersession.go | 52 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/streamersession.go b/streamersession.go index 1ab7739..5a033bc 100644 --- a/streamersession.go +++ b/streamersession.go @@ -22,7 +22,7 @@ type StreamerSession struct { onStopListeners []func() } -// NewStreamerSession new StreamerSession +// NewStreamerSession new StreamerSession with auto selectd port func NewStreamerSession(media *sdp.MediaInfo) *StreamerSession { streamerSession := &StreamerSession{} @@ -65,14 +65,58 @@ func NewStreamerSession(media *sdp.MediaInfo) *StreamerSession { return streamerSession } +// NewStreamerSessionWithLocalPort create streamer session with pre selected port +func NewStreamerSessionWithLocalPort(port int, media *sdp.MediaInfo) *StreamerSession { + + streamerSession := &StreamerSession{} + var mediaType native.MediaFrameType = 0 + if strings.ToLower(media.GetType()) == "video" { + mediaType = 1 + } + session := native.NewRTPSessionFacade(mediaType) + + streamerSession.id = uuid.Must(uuid.NewV4()).String() + + properties := native.NewProperties() + + if media != nil { + num := 0 + for _, codec := range media.GetCodecs() { + item := fmt.Sprintf("codecs.%d", num) + properties.SetProperty(item+".codec", codec.GetCodec()) + properties.SetProperty(item+".pt", codec.GetType()) + if codec.HasRTX() { + properties.SetProperty(item+".rtx", codec.GetRTX()) + } + num = num + 1 + } + properties.SetProperty("codecs.length", num) + } + + session.SetLocalPort(port) + + session.Init(properties) + + native.DeleteProperties(properties) + + streamerSession.session = session + + streamerSession.incoming = NewIncomingStreamTrack(media.GetType(), media.GetType(), native.SessionToReceiver(session), map[string]native.RTPIncomingSourceGroup{"": session.GetIncomingSourceGroup()}) + + streamerSession.outgoing = newOutgoingStreamTrack(media.GetType(), media.GetType(), native.SessionToSender(session), session.GetOutgoingSourceGroup()) + + streamerSession.onStopListeners = make([]func(), 0) + + return streamerSession +} + // GetID get id func (s *StreamerSession) GetID() string { return s.id } -func (s *StreamerSession) SetLocalPort(port int) { - - s.session.SetLocalPort(port) +func (s *StreamerSession) GetLocalPort() int { + return s.session.GetLocalPort() } func (s *StreamerSession) SetRemotePort(ip string, port int) {