From a1159049a1e1923b990418f7f13dd5ce3c5084a4 Mon Sep 17 00:00:00 2001 From: backkem Date: Thu, 21 Feb 2019 17:53:33 +0100 Subject: [PATCH] Move RTPSender and RTPReceiver to API Relates to #379 --- peerconnection.go | 4 ++-- rtpreceiver.go | 15 ++++++++++----- rtpsender.go | 6 +++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/peerconnection.go b/peerconnection.go index 51ee52d57f2..faba5d72fbe 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -921,7 +921,7 @@ func (pc *PeerConnection) openSRTP() { for i := range incomingSSRCes { go func(ssrc uint32, codecType RTPCodecType) { - receiver := NewRTPReceiver(codecType, pc.dtlsTransport) + receiver := pc.api.NewRTPReceiver(codecType, pc.dtlsTransport) <-receiver.Receive(RTPReceiveParameters{ encodings: RTPDecodingParameters{ RTPCodingParameters{SSRC: ssrc}, @@ -1138,7 +1138,7 @@ func (pc *PeerConnection) AddTrack(track *Track) (*RTPSender, error) { return nil, err } } else { - sender := NewRTPSender(track, pc.dtlsTransport) + sender := pc.api.NewRTPSender(track, pc.dtlsTransport) transceiver = pc.newRTPTransceiver( nil, sender, diff --git a/rtpreceiver.go b/rtpreceiver.go index 16d2acc61f6..acfae4e77b3 100644 --- a/rtpreceiver.go +++ b/rtpreceiver.go @@ -23,26 +23,31 @@ type RTPReceiver struct { rtpOut chan *rtp.Packet rtpReadStream *srtp.ReadStreamSRTP - rtpOutDone chan bool + rtpOutDone chan struct{} rtcpOut chan rtcp.Packet rtcpReadStream *srtp.ReadStreamSRTCP - rtcpOutDone chan bool + rtcpOutDone chan struct{} + + // A reference to the associated api object + api *API } // NewRTPReceiver constructs a new RTPReceiver -func NewRTPReceiver(kind RTPCodecType, transport *DTLSTransport) *RTPReceiver { +func (api *API) NewRTPReceiver(kind RTPCodecType, transport *DTLSTransport) *RTPReceiver { return &RTPReceiver{ kind: kind, transport: transport, rtpOut: make(chan *rtp.Packet, 15), - rtpOutDone: make(chan bool), + rtpOutDone: make(chan struct{}), rtcpOut: make(chan rtcp.Packet, 15), - rtcpOutDone: make(chan bool), + rtcpOutDone: make(chan struct{}), hasRecv: make(chan bool), + + api: api, } } diff --git a/rtpsender.go b/rtpsender.go index 70d3c171d45..9c71f119ae8 100644 --- a/rtpsender.go +++ b/rtpsender.go @@ -13,13 +13,17 @@ type RTPSender struct { Track *Track transport *DTLSTransport + + // A reference to the associated api object + api *API } // NewRTPSender constructs a new RTPSender -func NewRTPSender(track *Track, transport *DTLSTransport) *RTPSender { +func (api *API) NewRTPSender(track *Track, transport *DTLSTransport) *RTPSender { r := &RTPSender{ Track: track, transport: transport, + api: api, } r.Track.sampleInput = make(chan media.Sample, 15) // Is the buffering needed?