Skip to content

Commit

Permalink
fix streamer session
Browse files Browse the repository at this point in the history
Former-commit-id: dc4810048e0823c75a109ac5df3c8aac1cb7c880 [formerly 772fdbf8a711025cea0d7443bd130f00c5c027fd] [formerly 20657ff858354dd3268b7e1594e5f9d9dd9beb34 [formerly 86c94f0]]
Former-commit-id: e9e373fbef9c0526b8df867a17e835546e4344d1 [formerly 18209748165e7289cc49cf4eff693c173717aa54]
Former-commit-id: 297dd6e792897160e45a96a55afc1f047559659d
  • Loading branch information
notedit committed Jun 30, 2019
1 parent 0a4cbda commit 1f3c94a
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions streamersession.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1f3c94a

Please sign in to comment.