Commit b708fd23 authored by Guillaume Roguez's avatar Guillaume Roguez

Move local ports management from Call to SIPCall class

Call class is an ABC and not supposed to know and even more handles
how it's connected to the peer.
This is the purpose of concrete classes as SIPCall.

To respect this design local ports members and related API,
used for medias, are removed from Call and re-implemented
into SIPCall.

Notice the removal of mutex use, not required as read and write are
done in the same calling flow, and also the better RING_VIDEO define
checks around localVideoPort_.

Change-Id: I1feefe20a45f6b89b2eab448be78cd525e7a28c7
parent fe186bee
......@@ -291,20 +291,6 @@ Call::getStateStr() const
}
}
unsigned int
Call::getLocalAudioPort() const
{
std::lock_guard<std::recursive_mutex> lock(callMutex_);
return localAudioPort_;
}
unsigned int
Call::getLocalVideoPort() const
{
std::lock_guard<std::recursive_mutex> lock(callMutex_);
return localVideoPort_;
}
bool
Call::toggleRecording()
{
......@@ -515,8 +501,6 @@ Call::merge(Call& subcall)
if (peerNumber_.empty())
peerNumber_ = std::move(subcall.peerNumber_);
peerDisplayName_ = std::move(subcall.peerDisplayName_);
localAudioPort_ = subcall.localAudioPort_;
localVideoPort_ = subcall.localVideoPort_;
setState(subcall.getState(), subcall.getConnectionState());
}
......
......@@ -260,34 +260,6 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> {
void addSubCall(Call& call);
public: // media management
/**
* Set local audio port, as seen by me [not protected]
* @param port The local audio port
*/
void setLocalAudioPort(unsigned int port) {
localAudioPort_ = port;
}
/**
* Set local video port, as seen by me [not protected]
* @param port The local video port
*/
void setLocalVideoPort(unsigned int port) {
localVideoPort_ = port;
}
/**
* Return port used locally (for my machine) [mutex protected]
* @return unsigned int The local audio port
*/
unsigned int getLocalAudioPort() const;
/**
* Return port used locally (for my machine) [mutex protected]
* @return unsigned int The local video port
*/
unsigned int getLocalVideoPort() const;
virtual bool toggleRecording();
virtual void switchInput(const std::string&) {};
......@@ -381,14 +353,6 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> {
std::vector<std::function<void(CallState, ConnectionState, int)>> stateChangedListeners_ {};
// Informations about call socket / audio
/** Local audio port, as seen by me. */
unsigned int localAudioPort_ {0};
/** Local video port, as seen by me. */
unsigned int localVideoPort_ {0};
/** Unique ID of the call */
std::string id_;
......
......@@ -136,9 +136,9 @@ SIPCall::getSIPAccount() const
void
SIPCall::setCallMediaLocal(const pj_sockaddr& localIP)
{
if (getLocalAudioPort() == 0
if (localAudioPort_ == 0
#ifdef RING_VIDEO
|| getLocalVideoPort() == 0
|| localVideoPort_ == 0
#endif
)
generateMediaPorts();
......@@ -152,19 +152,19 @@ SIPCall::generateMediaPorts()
// Reference: http://www.cs.columbia.edu/~hgs/rtp/faq.html#ports
// We only want to set ports to new values if they haven't been set
const unsigned callLocalAudioPort = account.generateAudioPort();
if (getLocalAudioPort() != 0)
account.releasePort(getLocalAudioPort());
setLocalAudioPort(callLocalAudioPort);
if (localAudioPort_ != 0)
account.releasePort(localAudioPort_);
localAudioPort_ = callLocalAudioPort;
sdp_->setLocalPublishedAudioPort(callLocalAudioPort);
#ifdef RING_VIDEO
// https://projects.savoirfairelinux.com/issues/17498
const unsigned int callLocalVideoPort = account.generateVideoPort();
if (getLocalVideoPort() != 0)
account.releasePort(getLocalVideoPort());
if (localVideoPort_ != 0)
account.releasePort(localVideoPort_);
// this should already be guaranteed by SIPAccount
assert(getLocalAudioPort() != callLocalVideoPort);
setLocalVideoPort(callLocalVideoPort);
assert(localAudioPort_ != callLocalVideoPort);
localVideoPort_ = callLocalVideoPort;
sdp_->setLocalPublishedVideoPort(callLocalVideoPort);
#endif
}
......@@ -1128,6 +1128,8 @@ SIPCall::merge(Call& call)
upnp_ = std::move(subcall.upnp_);
std::copy_n(subcall.contactBuffer_, PJSIP_MAX_URL_SIZE, contactBuffer_);
pj_strcpy(&contactHeader_, &subcall.contactHeader_);
localAudioPort_ = subcall.localAudioPort_;
localVideoPort_ = subcall.localVideoPort_;
Call::merge(subcall);
......
......@@ -259,6 +259,12 @@ private:
pj_str_t contactHeader_ {contactBuffer_, 0};
std::unique_ptr<ring::upnp::Controller> upnp_;
/** Local audio port, as seen by me. */
unsigned int localAudioPort_ {0};
/** Local video port, as seen by me. */
unsigned int localVideoPort_ {0};
};
// Helpers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment