From 0a4cbdabcbbed7468491312abb7ec86ac92f375f Mon Sep 17 00:00:00 2001 From: notedit Date: Sun, 30 Jun 2019 19:07:03 +0800 Subject: [PATCH] fix streamer session Former-commit-id: b2ae94b3105d16d6f253d99547e4cd56a1bdb1ea [formerly a84bab8ca45798c358665cc0e7c6cd916bbf483d] [formerly 1f1b42e680cd0c2dc4b8ef93901af25e377b07f6 [formerly 635d028cc4a2ab56ea9e1b3d4cb23694d46f5612]] Former-commit-id: 14f5860026a3d9e8b1ee8b884a087808ecffa6b0 [formerly aa535fe0376bce9649be0a3961e238cf62f0964b] Former-commit-id: 2cdd6f97567c6e9f7b93cada6dce076f964040e7 --- streamer.go | 48 ---------------------------------------------- streamersession.go | 16 ++++++++++------ 2 files changed, 10 insertions(+), 54 deletions(-) delete mode 100644 streamer.go diff --git a/streamer.go b/streamer.go deleted file mode 100644 index 85f4ede..0000000 --- a/streamer.go +++ /dev/null @@ -1,48 +0,0 @@ -package mediaserver - -import ( - "sync" - - "github.com/notedit/sdp" -) - -// Streamer -type Streamer struct { - sessions map[string]*StreamerSession - sync.Mutex -} - -// NewStreamer create a streamer -func NewStreamer() *Streamer { - streamer := &Streamer{} - streamer.sessions = make(map[string]*StreamerSession) - return streamer -} - -// CreateSession -func (s *Streamer) CreateSession(local bool, ip string, port int, media *sdp.MediaInfo) *StreamerSession { - - session := NewStreamerSession(local, ip, port, media) - - s.Lock() - s.sessions[session.id] = session - s.Unlock() - - return session -} - -// RemoveSession remove a session -func (s *Streamer) RemoveSession(session *StreamerSession) { - s.Lock() - delete(s.sessions, session.id) - s.Unlock() -} - -// Stop stop all sessions -func (s *Streamer) Stop() { - - for _, session := range s.sessions { - session.Stop() - } - s.sessions = nil -} diff --git a/streamersession.go b/streamersession.go index e6260a4..1ab7739 100644 --- a/streamersession.go +++ b/streamersession.go @@ -23,7 +23,7 @@ type StreamerSession struct { } // NewStreamerSession new StreamerSession -func NewStreamerSession(local bool, ip string, port int, media *sdp.MediaInfo) *StreamerSession { +func NewStreamerSession(media *sdp.MediaInfo) *StreamerSession { streamerSession := &StreamerSession{} var mediaType native.MediaFrameType = 0 @@ -31,11 +31,6 @@ func NewStreamerSession(local bool, ip string, port int, media *sdp.MediaInfo) * mediaType = 1 } session := native.NewRTPSessionFacade(mediaType) - if local { - session.SetLocalPort(port) - } else { - session.SetRemotePort(ip, port) - } streamerSession.id = uuid.Must(uuid.NewV4()).String() @@ -75,6 +70,15 @@ func (s *StreamerSession) GetID() string { return s.id } +func (s *StreamerSession) SetLocalPort(port int) { + + s.session.SetLocalPort(port) +} + +func (s *StreamerSession) SetRemotePort(ip string, port int) { + s.session.SetRemotePort(ip, port) +} + // GetIncomingStreamTrack get asso incoming track, func (s *StreamerSession) GetIncomingStreamTrack() *IncomingStreamTrack { return s.incoming