fix(core): fix coding style on many files, remove useless includes...

This commit is contained in:
Ronan Abhamon 2017-09-26 11:56:49 +02:00
parent 113dee4b8d
commit e75404cbd8
29 changed files with 311 additions and 210 deletions

View file

@ -136,6 +136,13 @@ inline const Object *getPublicHelper (const T *object, const ObjectPrivate *) {
return *this; \
}
// -----------------------------------------------------------------------------
// Wrapper public.
// -----------------------------------------------------------------------------
#define L_DECL_C_STRUCT(STRUCT) typedef struct _ ## STRUCT STRUCT;
#define L_DECL_C_STRUCT_PREFIX_LESS(STRUCT) typedef struct STRUCT STRUCT;
#endif
LINPHONE_END_NAMESPACE

View file

@ -56,4 +56,4 @@ private:
LINPHONE_END_NAMESPACE
#endif
#endif // ifndef _ADDRESS_P_H_

View file

@ -17,14 +17,11 @@
*/
#include "linphone/utils/utils.h"
#include "sal/sal.h"
#include "address-p.h"
#include "c-wrapper/c-wrapper.h"
#include "logger/logger.h"
#include "address.h"
// =============================================================================
using namespace std;

View file

@ -19,8 +19,6 @@
#ifndef _ADDRESS_H_
#define _ADDRESS_H_
#include <string>
#include "enums.h"
#include "object/clonable-object.h"

View file

@ -19,12 +19,9 @@
#ifndef _CALL_P_H_
#define _CALL_P_H_
#include <memory>
#include "object/object-p.h"
#include "call.h"
#include "conference/conference.h"
#include "object/object-p.h"
#include "private.h"
@ -70,7 +67,6 @@ private:
void onFirstVideoFrameDecoded () override;
void onResetFirstVideoFrameDecoded () override;
private:
LinphoneCall *lcall = nullptr;
LinphoneCore *core = nullptr;

View file

@ -17,23 +17,20 @@
*/
#include "call-p.h"
#include "conference/participant-p.h"
#include "conference/session/media-session-p.h"
#include "call.h"
#include "conference/local-conference.h"
#include "conference/participant-p.h"
#include "conference/remote-conference.h"
#include "conference/session/media-session.h"
#include "conference/session/media-session-p.h"
#include "logger/logger.h"
#include "private.h"
#include "call.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// =============================================================================
CallPrivate::CallPrivate (LinphoneCall *call, LinphoneCore *core, LinphoneCallDir direction, const Address &from, const Address &to,
LinphoneProxyConfig *cfg, SalOp *op, const MediaSessionParams *msp) : lcall(call), core(core) {
nextVideoFrameDecoded._func = nullptr;

View file

@ -19,12 +19,9 @@
#ifndef _CALL_CALL_H_
#define _CALL_CALL_H_
#include "linphone/types.h"
#include "object/object.h"
#include "address/address.h"
#include "call/call-listener.h"
#include "conference/params/media-session-params.h"
#include "object/object.h"
// =============================================================================
@ -39,8 +36,16 @@ class Call : public Object {
friend class MediaSessionPrivate;
public:
Call (LinphoneCall *call, LinphoneCore *core, LinphoneCallDir direction, const Address &from, const Address &to,
LinphoneProxyConfig *cfg, SalOp *op, const MediaSessionParams *msp);
Call (
LinphoneCall *call,
LinphoneCore *core,
LinphoneCallDir direction,
const Address &from,
const Address &to,
LinphoneProxyConfig *cfg,
SalOp *op,
const MediaSessionParams *msp
);
LinphoneStatus accept (const MediaSessionParams *msp = nullptr);
LinphoneStatus acceptEarlyMedia (const MediaSessionParams *msp = nullptr);
@ -52,8 +57,8 @@ public:
void sendVfuRequest ();
void startRecording ();
void stopRecording ();
LinphoneStatus takePreviewSnapshot (const std::string& file);
LinphoneStatus takeVideoSnapshot (const std::string& file);
LinphoneStatus takePreviewSnapshot (const std::string &file);
LinphoneStatus takeVideoSnapshot (const std::string &file);
LinphoneStatus terminate (const LinphoneErrorInfo *ei = nullptr);
LinphoneStatus update (const MediaSessionParams *msp = nullptr);
void zoomVideo (float zoomFactor, float *cx, float *cy);
@ -65,36 +70,36 @@ public:
void enableEchoCancellation (bool value);
void enableEchoLimiter (bool value);
bool getAllMuted () const;
LinphoneCallStats * getAudioStats () const;
LinphoneCallStats *getAudioStats () const;
std::string getAuthenticationToken () const;
bool getAuthenticationTokenVerified () const;
float getAverageQuality () const;
LinphoneCore * getCore () const;
const MediaSessionParams * getCurrentParams () const;
LinphoneCore *getCore () const;
const MediaSessionParams *getCurrentParams () const;
float getCurrentQuality () const;
LinphoneCallDir getDirection () const;
int getDuration () const;
const LinphoneErrorInfo * getErrorInfo () const;
LinphoneCallLog * getLog () const;
RtpTransport * getMetaRtcpTransport (int streamIndex) const;
RtpTransport * getMetaRtpTransport (int streamIndex) const;
const LinphoneErrorInfo *getErrorInfo () const;
LinphoneCallLog *getLog () const;
RtpTransport *getMetaRtcpTransport (int streamIndex) const;
RtpTransport *getMetaRtpTransport (int streamIndex) const;
float getMicrophoneVolumeGain () const;
void * getNativeVideoWindowId () const;
const MediaSessionParams * getParams () const;
void *getNativeVideoWindowId () const;
const MediaSessionParams *getParams () const;
float getPlayVolume () const;
LinphoneReason getReason () const;
float getRecordVolume () const;
const Address& getRemoteAddress () const;
const Address &getRemoteAddress () const;
std::string getRemoteAddressAsString () const;
std::string getRemoteContact () const;
const MediaSessionParams * getRemoteParams () const;
const MediaSessionParams *getRemoteParams () const;
float getSpeakerVolumeGain () const;
LinphoneCallState getState () const;
LinphoneCallStats * getStats (LinphoneStreamType type) const;
LinphoneCallStats *getStats (LinphoneStreamType type) const;
int getStreamCount () const;
MSFormatType getStreamType (int streamIndex) const;
LinphoneCallStats * getTextStats () const;
LinphoneCallStats * getVideoStats () const;
LinphoneCallStats *getTextStats () const;
LinphoneCallStats *getVideoStats () const;
bool mediaInProgress () const;
void setAuthenticationTokenVerified (bool value);
void setMicrophoneVolumeGain (float value);

View file

@ -19,8 +19,6 @@
#ifndef _CALL_SESSION_P_H_
#define _CALL_SESSION_P_H_
#include <memory>
#include "object/object-p.h"
#include "call-session.h"

View file

@ -29,9 +29,6 @@
#include "nat/stun-client.h"
#include "linphone/call_stats.h"
#include "sal/sal.h"
#include "private.h"
// =============================================================================
@ -63,30 +60,53 @@ public:
void prepareStreamsForIceGathering (bool hasVideo);
void stopStreamsForIceGathering ();
int getAf () const { return af; }
bool getAudioMuted () const { return audioMuted; }
LinphoneCore * getCore () const { return core; }
IceSession * getIceSession () const { return iceAgent->getIceSession(); }
SalMediaDescription * getLocalDesc () const { return localDesc; }
MediaStream * getMediaStream (LinphoneStreamType type) const;
LinphoneNatPolicy * getNatPolicy () const { return natPolicy; }
int getAf () const {
return af;
}
bool getAudioMuted () const {
return audioMuted;
}
LinphoneCore *getCore () const {
return core;
}
IceSession *getIceSession () const {
return iceAgent->getIceSession();
}
SalMediaDescription *getLocalDesc () const {
return localDesc;
}
MediaStream *getMediaStream (LinphoneStreamType type) const;
LinphoneNatPolicy *getNatPolicy () const {
return natPolicy;
}
int getRtcpPort (LinphoneStreamType type) const;
int getRtpPort (LinphoneStreamType type) const;
LinphoneCallStats * getStats (LinphoneStreamType type) const;
LinphoneCallStats *getStats (LinphoneStreamType type) const;
int getStreamIndex (LinphoneStreamType type) const;
int getStreamIndex (MediaStream *ms) const;
SalOp * getOp () const { return op; }
void setAudioMuted (bool value) { audioMuted = value; }
SalOp *getOp () const {
return op;
}
void setAudioMuted (bool value) {
audioMuted = value;
}
private:
static OrtpJitterBufferAlgorithm jitterBufferNameToAlgo (const std::string &name);
#ifdef VIDEO_ENABLED
static void videoStreamEventCb (void *userData, const MSFilter *f, const unsigned int eventId, const void *args);
#endif
#ifdef TEST_EXT_RENDERER
static void extRendererCb (void *userData, const MSPicture *local, const MSPicture *remote);
#endif
#ifdef VIDEO_ENABLED
static void videoStreamEventCb (void *userData, const MSFilter *f, const unsigned int eventId, const void *args);
#endif // ifdef VIDEO_ENABLED
#ifdef TEST_EXT_RENDERER
static void extRendererCb (void *userData, const MSPicture *local, const MSPicture *remote);
#endif // ifdef TEST_EXT_RENDERER
static void realTimeTextCharacterReceived (void *userData, MSFilter *f, unsigned int id, void *arg);
static float aggregateQualityRatings (float audioRating, float videoRating);
@ -103,9 +123,9 @@ private:
void initStats (LinphoneCallStats *stats, LinphoneStreamType type);
void notifyStatsUpdated (int streamIndex) const;
OrtpEvQueue * getEventQueue (int streamIndex) const;
MediaStream * getMediaStream (int streamIndex) const;
MSWebCam * getVideoDevice () const;
OrtpEvQueue *getEventQueue (int streamIndex) const;
MediaStream *getMediaStream (int streamIndex) const;
MSWebCam *getVideoDevice () const;
void fillMulticastMediaAddresses ();
int selectFixedPort (int streamIndex, std::pair<int, int> portRange);
@ -149,7 +169,7 @@ private:
int getIdealAudioBandwidth (const SalMediaDescription *md, const SalStreamDescription *desc);
int getVideoBandwidth (const SalMediaDescription *md, const SalStreamDescription *desc);
RtpProfile * makeProfile (const SalMediaDescription *md, const SalStreamDescription *desc, int *usedPt);
RtpProfile *makeProfile (const SalMediaDescription *md, const SalStreamDescription *desc, int *usedPt);
void unsetRtpProfile (int streamIndex);
void updateAllocatedAudioBandwidth (const PayloadType *pt, int maxbw);
@ -159,8 +179,8 @@ private:
void configureAdaptiveRateControl (MediaStream *ms, const OrtpPayloadType *pt, bool videoWillBeUsed);
void configureRtpSessionForRtcpFb (const SalStreamDescription *stream);
void configureRtpSessionForRtcpXr (SalStreamType type);
RtpSession * createAudioRtpIoSession ();
RtpSession * createVideoRtpIoSession ();
RtpSession *createAudioRtpIoSession ();
RtpSession *createVideoRtpIoSession ();
void freeResources ();
void handleIceEvents (OrtpEvent *ev);
void handleStreamEvents (int streamIndex);
@ -224,9 +244,9 @@ private:
void accept (const MediaSessionParams *params);
LinphoneStatus acceptUpdate (const CallSessionParams *csp, LinphoneCallState nextState, const std::string &stateInfo) override;
#ifdef VIDEO_ENABLED
void videoStreamEventCb (const MSFilter *f, const unsigned int eventId, const void *args);
#endif
#ifdef VIDEO_ENABLED
void videoStreamEventCb (const MSFilter *f, const unsigned int eventId, const void *args);
#endif // ifdef VIDEO_ENABLED
void realTimeTextCharacterReceived (MSFilter *f, unsigned int id, void *arg);
void stunAuthRequestedCb (const char *realm, const char *nonce, const char **username, const char **password, const char **ha1);
@ -265,11 +285,16 @@ private:
StunClient *stunClient = nullptr;
IceAgent *iceAgent = nullptr;
int af; /* The address family to prefer for RTP path, guessed from signaling path */
// The address family to prefer for RTP path, guessed from signaling path.
int af;
std::string mediaLocalIp;
PortConfig mediaPorts[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
bool needMediaLocalIpRefresh = false;
MSMediaStreamSessions sessions[SAL_MEDIA_DESCRIPTION_MAX_STREAMS]; /* The rtp, srtp, zrtp contexts for each stream */
// The rtp, srtp, zrtp contexts for each stream.
MSMediaStreamSessions sessions[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
SalMediaDescription *localDesc = nullptr;
int localDescChanged = 0;
SalMediaDescription *biggestDesc = nullptr;
@ -283,8 +308,12 @@ private:
std::string dtlsCertificateFingerprint;
unsigned int nbMediaStarts = 0;
int upBandwidth = 0; /* Upload bandwidth setting at the time the call is started. Used to detect if it changes during a call */
int audioBandwidth = 0; /* Upload bandwidth used by audio */
// Upload bandwidth setting at the time the call is started. Used to detect if it changes during a call.
int upBandwidth = 0;
// Upload bandwidth used by audio.
int audioBandwidth = 0;
bool allMuted = false;
bool audioMuted = false;

View file

@ -19,8 +19,6 @@
#ifndef _CONTENT_TYPE_H_
#define _CONTENT_TYPE_H_
#include <string>
#include "object/clonable-object.h"
// =============================================================================

View file

@ -19,11 +19,9 @@
#ifndef _CONTENT_H_
#define _CONTENT_H_
#include <string>
#include <vector>
#include "content-type.h"
#include "object/clonable-object.h"
// =============================================================================

View file

@ -20,8 +20,6 @@
#include "db/provider/db-session-provider.h"
#include "logger/logger.h"
#include "abstract-db.h"
// =============================================================================
using namespace std;

View file

@ -42,12 +42,12 @@ class EventsDbPrivate : public AbstractDbPrivate {};
EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
#ifdef SOCI_ENABLED
// -----------------------------------------------------------------------------
// Soci backend.
// -----------------------------------------------------------------------------
#ifdef SOCI_ENABLED
template<typename T>
struct EnumToSql {
T first;
@ -169,10 +169,18 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
*session <<
"CREATE TABLE IF NOT EXISTS dialog ("
" id" + primaryKeyAutoIncrementStr() + ","
" local_sip_address_id INT UNSIGNED NOT NULL," // Sip address used to communicate.
" remote_sip_address_id INT UNSIGNED NOT NULL," // Server (for conference) or user sip address.
" creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date.
" last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...).
// Sip address used to communicate.
" local_sip_address_id INT UNSIGNED NOT NULL,"
// Server (for conference) or user sip address.
" remote_sip_address_id INT UNSIGNED NOT NULL,"
// Dialog creation date.
" creation_timestamp TIMESTAMP NOT NULL,"
// Last event timestamp (call, message...).
" last_update_timestamp TIMESTAMP NOT NULL,"
" FOREIGN KEY (local_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE,"
@ -189,11 +197,19 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
" state_id TINYINT UNSIGNED NOT NULL,"
" direction_id TINYINT UNSIGNED NOT NULL,"
" sender_sip_address_id INT UNSIGNED NOT NULL,"
" imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3
// See: https://tools.ietf.org/html/rfc5438#section-6.3
" imdn_message_id VARCHAR(255) NOT NULL,"
" is_secured BOOLEAN NOT NULL,"
" content_type VARCHAR(255) NOT NULL," // Content type of text. (Html or text for example.)
// Content type of text. (Html or text for example.)
" content_type VARCHAR(255) NOT NULL,"
" text TEXT,"
" app_data VARCHAR(2048)," // App user data.
// App user data.
" app_data VARCHAR(2048),"
" FOREIGN KEY (event_id)"
" REFERENCES event(id)"
" ON DELETE CASCADE,"
@ -215,10 +231,18 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
"CREATE TABLE IF NOT EXISTS message_file_info ("
" id" + primaryKeyAutoIncrementStr() + ","
" message_id INT UNSIGNED NOT NULL,"
" content_type VARCHAR(255) NOT NULL," // File content type.
" name VARCHAR(255) NOT NULL," // File name.
" size INT UNSIGNED NOT NULL," // File size.
" url VARCHAR(255) NOT NULL," // File url.
// File content type.
" content_type VARCHAR(255) NOT NULL,"
// File name.
" name VARCHAR(255) NOT NULL,"
// File size.
" size INT UNSIGNED NOT NULL,"
// File url.
" url VARCHAR(255) NOT NULL,"
" key VARCHAR(4096),"
" key_size INT UNSIGNED,"
" FOREIGN KEY (message_id)"

View file

@ -20,7 +20,6 @@
#define _EVENTS_DB_H_
#include <list>
#include <memory>
#include "abstract/abstract-db.h"
@ -53,8 +52,17 @@ public:
// Messages, calls and conferences.
int getMessagesCount (const std::string &remoteAddress = "") const;
int getUnreadMessagesCount (const std::string &remoteAddress = "") const;
std::list<std::shared_ptr<EventLog> > getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter) const;
std::list<std::shared_ptr<EventLog> > getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter) const;
std::list<std::shared_ptr<EventLog>> getHistory (
const std::string &remoteAddress,
int nLast,
FilterMask mask = NoFilter
) const;
std::list<std::shared_ptr<EventLog>> getHistory (
const std::string &remoteAddress,
int begin,
int end,
FilterMask mask = NoFilter
) const;
void cleanHistory (const std::string &remoteAddress = "");
protected:

View file

@ -28,8 +28,6 @@
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
class DbSessionPrivate : public ClonableObjectPrivate {
friend class DbSessionProvider;

View file

@ -18,8 +18,6 @@
#include "db-session-p.h"
#include "db-session.h"
// =============================================================================
using namespace std;

View file

@ -16,9 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "event-log-p.h"
#include "call-event.h"
#include "event-log-p.h"
// =============================================================================

View file

@ -16,9 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "event-log-p.h"
#include "chat-message-event.h"
#include "event-log-p.h"
// =============================================================================
@ -45,7 +44,7 @@ ChatMessageEvent::ChatMessageEvent (const ChatMessageEvent &src) : ChatMessageEv
ChatMessageEvent &ChatMessageEvent::operator= (const ChatMessageEvent &src) {
L_D(ChatMessageEvent);
if (this != &src) {
EventLog::operator= (src);
EventLog::operator=(src);
d->chatMessage = src.getPrivate()->chatMessage;
}

View file

@ -21,7 +21,6 @@
#include "address/address.h"
#include "conference-event.h"
#include "event-log-p.h"
// =============================================================================

View file

@ -19,8 +19,6 @@
#include "address/address.h"
#include "conference-event-p.h"
#include "conference-event.h"
// =============================================================================
using namespace std;

View file

@ -18,7 +18,6 @@
#include "address/address.h"
#include "conference-event-p.h"
#include "conference-participant-event.h"
// =============================================================================

View file

@ -18,14 +18,10 @@
#include "event-log-p.h"
#include "event-log.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
EventLog::EventLog () : ClonableObject(*new EventLogPrivate) {}
EventLog::EventLog (const EventLog &) : ClonableObject(*new EventLogPrivate) {}

View file

@ -18,17 +18,19 @@
#include "linphone/core.h"
#include "private.h"
#include "conference/session/media-session-p.h"
#include "logger/logger.h"
#include "ice-agent.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
bool IceAgent::candidatesGathered () const {
if (!iceSession)
return false;
@ -36,14 +38,21 @@ bool IceAgent::candidatesGathered () const {
}
void IceAgent::checkSession (IceRole role, bool isReinvite) {
// Already created.
if (iceSession)
return; /* Already created */
return;
LinphoneConfig *config = linphone_core_get_config(mediaSession.getPrivate()->getCore());
if (isReinvite && (lp_config_get_int(config, "net", "allow_late_ice", 0) == 0))
return;
iceSession = ice_session_new();
/* For backward compatibility purposes, shall be enabled by default in the future */
ice_session_enable_message_integrity_check(iceSession, !!lp_config_get_int(config, "net", "ice_session_enable_message_integrity_check", 1));
// For backward compatibility purposes, shall be enabled by default in the future.
ice_session_enable_message_integrity_check(
iceSession,
!!lp_config_get_int(config, "net", "ice_session_enable_message_integrity_check", 1)
);
if (lp_config_get_int(config, "net", "dont_default_to_stun_candidates", 0)) {
IceCandidateType types[ICT_CandidateTypeMax];
types[0] = ICT_HostCandidate;
@ -57,6 +66,7 @@ void IceAgent::checkSession (IceRole role, bool isReinvite) {
void IceAgent::deleteSession () {
if (!iceSession)
return;
ice_session_destroy(iceSession);
iceSession = nullptr;
mediaSession.getPrivate()->deactivateIce();
@ -68,11 +78,13 @@ void IceAgent::gatheringFinished () {
clearUnusedIceCandidates(mediaSession.getPrivate()->getLocalDesc(), rmd);
if (!iceSession)
return;
ice_session_compute_candidates_foundations(iceSession);
ice_session_eliminate_redundant_candidates(iceSession);
ice_session_choose_default_candidates(iceSession);
int pingTime = ice_session_average_gathering_round_trip_time(iceSession);
if (pingTime >=0) {
if (pingTime >= 0) {
mediaSession.getPrivate()->setPingTime(pingTime);
}
}
@ -86,7 +98,7 @@ int IceAgent::getNbLosingPairs () const {
bool IceAgent::hasCompleted () const {
if (!iceSession)
return false;
return (ice_session_state(iceSession) == IS_Completed);
return ice_session_state(iceSession) == IS_Completed;
}
bool IceAgent::hasCompletedCheckList () const {
@ -104,7 +116,7 @@ bool IceAgent::hasCompletedCheckList () const {
bool IceAgent::isControlling () const {
if (!iceSession)
return false;
return (ice_session_role(iceSession) == IR_Controlling);
return ice_session_role(iceSession) == IR_Controlling;
}
bool IceAgent::prepare (const SalMediaDescription *localDesc, bool incomingOffer) {
@ -115,7 +127,8 @@ bool IceAgent::prepare (const SalMediaDescription *localDesc, bool incomingOffer
bool hasVideo = false;
if (incomingOffer) {
remoteDesc = sal_call_get_remote_media_description(mediaSession.getPrivate()->getOp());
hasVideo = linphone_core_video_enabled(mediaSession.getPrivate()->getCore()) && linphone_core_media_description_contains_video_stream(remoteDesc);
hasVideo = linphone_core_video_enabled(mediaSession.getPrivate()->getCore()) &&
linphone_core_media_description_contains_video_stream(remoteDesc);
} else
hasVideo = mediaSession.getMediaParams()->videoEnabled();
@ -124,14 +137,16 @@ bool IceAgent::prepare (const SalMediaDescription *localDesc, bool incomingOffer
prepareIceForStream(mediaSession.getPrivate()->getMediaStream(LinphoneStreamTypeVideo), true);
if (mediaSession.getMediaParams()->realtimeTextEnabled())
prepareIceForStream(mediaSession.getPrivate()->getMediaStream(LinphoneStreamTypeText), true);
/* Start ICE gathering */
// Start ICE gathering.
if (incomingOffer)
updateFromRemoteMediaDescription(localDesc, remoteDesc, true); /* This may delete the ice session */
// This may delete the ice session.
updateFromRemoteMediaDescription(localDesc, remoteDesc, true);
if (iceSession && !ice_session_candidates_gathered(iceSession)) {
mediaSession.getPrivate()->prepareStreamsForIceGathering(hasVideo);
int err = gatherIceCandidates();
if (err == 0) {
/* Ice candidates gathering wasn't started, but we can proceed with the call anyway. */
// Ice candidates gathering wasn't started, but we can proceed with the call anyway.
mediaSession.getPrivate()->stopStreamsForIceGathering();
return false;
} else if (err == -1) {
@ -147,6 +162,7 @@ bool IceAgent::prepare (const SalMediaDescription *localDesc, bool incomingOffer
void IceAgent::prepareIceForStream (MediaStream *ms, bool createChecklist) {
if (!iceSession)
return;
int streamIndex = mediaSession.getPrivate()->getStreamIndex(ms);
rtp_session_set_pktinfo(ms->sessions.rtp_session, true);
IceCheckList *cl = ice_session_check_list(iceSession, streamIndex);
@ -186,20 +202,25 @@ void IceAgent::stopIceForInactiveStreams (SalMediaDescription *desc) {
updateIceStateInCallStats();
}
void IceAgent::updateFromRemoteMediaDescription (const SalMediaDescription *localDesc, const SalMediaDescription *remoteDesc, bool isOffer) {
void IceAgent::updateFromRemoteMediaDescription (
const SalMediaDescription *localDesc,
const SalMediaDescription *remoteDesc,
bool isOffer
) {
if (!iceSession)
return;
if (!iceParamsFoundInRemoteMediaDescription(remoteDesc)) {
/* Response from remote does not contain mandatory ICE attributes, delete the session */
// Response from remote does not contain mandatory ICE attributes, delete the session.
deleteSession();
mediaSession.getPrivate()->enableSymmetricRtp(linphone_core_symmetric_rtp_enabled(mediaSession.getPrivate()->getCore()));
return;
}
/* Check for ICE restart and set remote credentials */
// Check for ICE restart and set remote credentials.
bool iceRestarted = checkForIceRestartAndSetRemoteCredentials(remoteDesc, isOffer);
/* Create ICE check lists if needed and parse ICE attributes */
// Create ICE check lists if needed and parse ICE attributes.
createIceCheckListsAndParseIceAttributes(remoteDesc, iceRestarted);
for (int i = 0; i < remoteDesc->nb_streams; i++) {
const SalStreamDescription *stream = &remoteDesc->streams[i];
@ -259,9 +280,9 @@ void IceAgent::updateIceStateInCallStats () {
if (textCheckList && mediaSession.getMediaParams()->realtimeTextEnabled())
_linphone_call_stats_set_ice_state(textStats, LinphoneIceStateFailed);
}
lInfo() << "CallSession [" << &mediaSession << "] New ICE state: audio: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(audioStats))
<< "] video: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(videoStats))
<< "] text: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(textStats)) << "]";
lInfo() << "CallSession [" << &mediaSession << "] New ICE state: audio: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(audioStats)) <<
"] video: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(videoStats)) <<
"] text: [" << linphone_ice_state_to_string(linphone_call_stats_get_ice_state(textStats)) << "]";
}
void IceAgent::updateLocalMediaDescriptionFromIce (SalMediaDescription *desc) {
@ -297,9 +318,9 @@ void IceAgent::updateLocalMediaDescriptionFromIce (SalMediaDescription *desc) {
if (!sal_stream_description_active(stream) || !cl)
continue;
if (ice_check_list_state(cl) == ICL_Completed) {
/* Set this to false once flexisip are updated everywhere, let's say in December 2016 */
LinphoneConfig *config = linphone_core_get_config(mediaSession.getPrivate()->getCore());
bool useNoRtpProxy = lp_config_get_int(config, "sip", "ice_uses_nortpproxy", true);
// TODO: Remove `ice_uses_nortpproxy` option, let's say in December 2018.
bool useNoRtpProxy = lp_config_get_int(config, "sip", "ice_uses_nortpproxy", false);
if (useNoRtpProxy)
stream->set_nortpproxy = true;
result = ice_check_list_selected_valid_local_candidate(ice_session_check_list(iceSession, i), &rtpCandidate, &rtcpCandidate);
@ -343,9 +364,11 @@ void IceAgent::updateLocalMediaDescriptionFromIce (SalMediaDescription *desc) {
continue;
if (defaultAddr[0] == '\0')
defaultAddr = desc->addr;
/* Only include the candidates matching the default destination for each component of the stream if the state is Completed as specified in RFC5245 section 9.1.2.2. */
if ((ice_check_list_state(cl) == ICL_Completed)
&& !((iceCandidate->taddr.port == defaultPort) && (strlen(iceCandidate->taddr.ip) == strlen(defaultAddr)) && (strcmp(iceCandidate->taddr.ip, defaultAddr) == 0)))
// Only include the candidates matching the default destination for each component of the stream if the state is Completed as specified in RFC5245 section 9.1.2.2.
if (
ice_check_list_state(cl) == ICL_Completed &&
!((iceCandidate->taddr.port == defaultPort) && (strlen(iceCandidate->taddr.ip) == strlen(defaultAddr)) && (strcmp(iceCandidate->taddr.ip, defaultAddr) == 0))
)
continue;
strncpy(salCandidate->foundation, iceCandidate->foundation, sizeof(salCandidate->foundation));
salCandidate->componentID = iceCandidate->componentID;
@ -441,7 +464,7 @@ bool IceAgent::checkForIceRestartAndSetRemoteCredentials (const SalMediaDescript
if (cl && (stream->ice_pwd[0] != '\0') && (stream->ice_ufrag[0] != '\0')) {
if (ice_check_list_remote_credentials_changed(cl, stream->ice_ufrag, stream->ice_pwd)) {
if (!iceRestarted && ice_check_list_get_remote_ufrag(cl) && ice_check_list_get_remote_pwd(cl)) {
/* Restart only if remote ufrag/paswd was already set */
// Restart only if remote ufrag/paswd was already set.
ice_session_restart(iceSession, isOffer ? IR_Controlled : IR_Controlling);
iceRestarted = true;
}
@ -515,8 +538,11 @@ void IceAgent::createIceCheckListsAndParseIceAttributes (const SalMediaDescripti
int componentID = j + 1;
if (remoteCandidate->addr[0] == '\0') break;
getIceDefaultAddrAndPort(static_cast<uint16_t>(componentID), md, stream, &addr, &port);
if (j == 0) /* If we receive a re-invite and we finished ICE processing on our side, use the candidates given by the remote. */
// If we receive a re-invite and we finished ICE processing on our side, use the candidates given by the remote.
if (j == 0)
ice_check_list_unselect_valid_pairs(cl);
int remoteFamily = AF_INET;
if (strchr(remoteCandidate->addr, ':'))
remoteFamily = AF_INET6;
@ -560,7 +586,7 @@ int IceAgent::gatherIceCandidates () {
ice_session_enable_forced_relay(iceSession, core->forced_ice_relay);
ice_session_enable_short_turn_refresh(iceSession, core->short_turn_refresh);
/* Gather local host candidates. */
// Gather local host candidates.
char localAddr[64];
if (mediaSession.getPrivate()->getAf() == AF_INET6) {
if (linphone_core_get_local_ip_for(AF_INET6, nullptr, localAddr) < 0) {
@ -579,7 +605,7 @@ int IceAgent::gatherIceCandidates () {
if (ai && natPolicy && linphone_nat_policy_stun_server_activated(natPolicy)) {
string server = linphone_nat_policy_get_stun_server(natPolicy);
lInfo() << "ICE: gathering candidates from [" << server << "] using " << (linphone_nat_policy_turn_enabled(natPolicy) ? "TURN" : "STUN");
/* Gather local srflx candidates */
// Gather local srflx candidates.
ice_session_enable_turn(iceSession, linphone_nat_policy_turn_enabled(natPolicy));
ice_session_set_stun_auth_requested_cb(iceSession, MediaSessionPrivate::stunAuthRequestedCb, &mediaSession);
return ice_session_gather_candidates(iceSession, ai->ai_addr, (socklen_t)ai->ai_addrlen) ? 1 : 0;
@ -592,7 +618,13 @@ int IceAgent::gatherIceCandidates () {
return 0;
}
void IceAgent::getIceDefaultAddrAndPort (uint16_t componentID, const SalMediaDescription *md, const SalStreamDescription *stream, const char **addr, int *port) {
void IceAgent::getIceDefaultAddrAndPort (
uint16_t componentID,
const SalMediaDescription *md,
const SalStreamDescription *stream,
const char **addr,
int *port
) {
if (componentID == 1) {
*addr = stream->rtp_addr;
*port = stream->rtp_port;
@ -609,8 +641,8 @@ void IceAgent::getIceDefaultAddrAndPort (uint16_t componentID, const SalMediaDes
* the DNS resolution returned. If a NAT64 address is present, use it, otherwise if an IPv4 address
* is present, use it, otherwise use an IPv6 address if it is present.
*/
const struct addrinfo * IceAgent::getIcePreferredStunServerAddrinfo (const struct addrinfo *ai) {
/* Search for NAT64 addrinfo */
const struct addrinfo *IceAgent::getIcePreferredStunServerAddrinfo (const struct addrinfo *ai) {
// Search for NAT64 addrinfo.
const struct addrinfo *it = ai;
while (it) {
if (it->ai_family == AF_INET6) {
@ -623,7 +655,7 @@ const struct addrinfo * IceAgent::getIcePreferredStunServerAddrinfo (const struc
}
const struct addrinfo *preferredAi = it;
if (!preferredAi) {
/* Search for IPv4 addrinfo */
// Search for IPv4 addrinfo.
it = ai;
while (it) {
if (it->ai_family == AF_INET)
@ -635,7 +667,7 @@ const struct addrinfo * IceAgent::getIcePreferredStunServerAddrinfo (const struc
preferredAi = it;
}
if (!preferredAi) {
/* Search for IPv6 addrinfo */
// Search for IPv6 addrinfo.
it = ai;
while (it) {
if (it->ai_family == AF_INET6)
@ -667,25 +699,28 @@ bool IceAgent::iceParamsFoundInRemoteMediaDescription (const SalMediaDescription
}
void IceAgent::updateIceStateInCallStatsForStream (LinphoneCallStats *stats, IceCheckList *cl) {
if (ice_check_list_state(cl) == ICL_Completed) {
switch (ice_check_list_selected_valid_candidate_type(cl)) {
case ICT_HostCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateHostConnection);
break;
case ICT_ServerReflexiveCandidate:
case ICT_PeerReflexiveCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateReflexiveConnection);
break;
case ICT_RelayedCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateRelayConnection);
break;
case ICT_CandidateInvalid:
case ICT_CandidateTypeMax:
/* Shall not happen */
break;
}
} else
if (ice_check_list_state(cl) != ICL_Completed) {
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateFailed);
return;
}
switch (ice_check_list_selected_valid_candidate_type(cl)) {
case ICT_HostCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateHostConnection);
break;
case ICT_ServerReflexiveCandidate:
case ICT_PeerReflexiveCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateReflexiveConnection);
break;
case ICT_RelayedCandidate:
_linphone_call_stats_set_ice_state(stats, LinphoneIceStateRelayConnection);
break;
case ICT_CandidateInvalid:
case ICT_CandidateTypeMax:
// Shall not happen.
L_ASSERT(false);
break;
}
}
LINPHONE_END_NAMESPACE

View file

@ -22,14 +22,18 @@
#include <mediastreamer2/ice.h>
#include <ortp/event.h>
#include "linphone/types.h"
#include "linphone/utils/general.h"
#include "sal/sal.h"
#include "conference/session/media-session.h"
// =============================================================================
L_DECL_C_STRUCT_PREFIX_LESS(SalMediaDescription);
L_DECL_C_STRUCT_PREFIX_LESS(SalStreamDescription);
L_DECL_C_STRUCT(LinphoneCallStats);
L_DECL_C_STRUCT(LinphoneCore);
L_DECL_C_STRUCT(MediaStream);
class MediaSession;
LINPHONE_BEGIN_NAMESPACE
class IceAgent {
@ -41,10 +45,16 @@ public:
void deleteSession ();
void gatheringFinished ();
int getNbLosingPairs () const;
IceSession * getIceSession () const { return iceSession; }
IceSession *getIceSession () const {
return iceSession;
}
bool hasCompleted () const;
bool hasCompletedCheckList () const;
bool hasSession () const { return iceSession; }
bool hasSession () const {
return iceSession;
}
bool isControlling () const;
bool prepare (const SalMediaDescription *localDesc, bool incomingOffer);
void prepareIceForStream (MediaStream *ms, bool createChecklist);
@ -62,7 +72,7 @@ private:
void createIceCheckListsAndParseIceAttributes (const SalMediaDescription *md, bool iceRestarted);
int gatherIceCandidates ();
void getIceDefaultAddrAndPort (uint16_t componentID, const SalMediaDescription *md, const SalStreamDescription *stream, const char **addr, int *port);
const struct addrinfo * getIcePreferredStunServerAddrinfo (const struct addrinfo *ai);
const struct addrinfo *getIcePreferredStunServerAddrinfo (const struct addrinfo *ai);
bool iceParamsFoundInRemoteMediaDescription (const SalMediaDescription *md);
void updateIceStateInCallStatsForStream (LinphoneCallStats *stats, IceCheckList *cl);

View file

@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/core.h"
#include "private.h"
#include "logger/logger.h"
@ -113,31 +111,28 @@ int StunClient::run (int audioPort, int videoPort, int textPort) {
break;
}
loops++;
} while (!(gotAudio && (gotVideo || (sockVideo == -1)) && (gotText || (sockText == -1))));
} while (!(gotAudio && (gotVideo || sockVideo == -1) && (gotText || sockText == -1)));
if (ret == 0)
ret = (int)elapsed;
if (!gotAudio)
lError() << "No STUN server response for audio port";
else {
if (!coneAudio)
lInfo() << "NAT is symmetric for audio port";
}
else if (!coneAudio)
lInfo() << "NAT is symmetric for audio port";
if (sockVideo != -1) {
if (!gotVideo)
lError() << "No STUN server response for video port";
else {
if (!coneVideo)
lInfo() << "NAT is symmetric for video port";
}
else if (!coneVideo)
lInfo() << "NAT is symmetric for video port";
}
if (sockText != -1) {
if (!gotText)
lError() << "No STUN server response for text port";
else {
if (!coneText)
lInfo() << "NAT is symmetric for text port";
}
else if (!coneText)
lInfo() << "NAT is symmetric for text port";
}
close_socket(sockAudio);
@ -150,16 +145,22 @@ void StunClient::updateMediaDescription (SalMediaDescription *md) const {
for (int i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) {
if (!sal_stream_description_active(&md->streams[i]))
continue;
if ((md->streams[i].type == SalAudio) && (audioCandidate.port != 0)) {
if (md->streams[i].type == SalAudio && audioCandidate.port != 0) {
strncpy(md->streams[i].rtp_addr, audioCandidate.address.c_str(), sizeof(md->streams[i].rtp_addr));
md->streams[i].rtp_port = audioCandidate.port;
if ((!audioCandidate.address.empty() && !videoCandidate.address.empty() && (audioCandidate.address == videoCandidate.address))
|| (sal_media_description_get_nb_active_streams(md) == 1))
if (
(
!audioCandidate.address.empty() &&
!videoCandidate.address.empty() &&
audioCandidate.address == videoCandidate.address
) ||
sal_media_description_get_nb_active_streams(md) == 1
)
strncpy(md->addr, audioCandidate.address.c_str(), sizeof(md->addr));
} else if ((md->streams[i].type == SalVideo) && (videoCandidate.port != 0)) {
} else if (md->streams[i].type == SalVideo && videoCandidate.port != 0) {
strncpy(md->streams[i].rtp_addr, videoCandidate.address.c_str(), sizeof(md->streams[i].rtp_addr));
md->streams[i].rtp_port = videoCandidate.port;
} else if ((md->streams[i].type == SalText) && (textCandidate.port != 0)) {
} else if (md->streams[i].type == SalText && textCandidate.port != 0) {
strncpy(md->streams[i].rtp_addr, textCandidate.address.c_str(), sizeof(md->streams[i].rtp_addr));
md->streams[i].rtp_port = textCandidate.port;
}
@ -187,13 +188,13 @@ ortp_socket_t StunClient::createStunSocket (int localPort) {
return -1;
}
int optval = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (SOCKET_OPTION_VALUE)&optval, sizeof (optval)) < 0)
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (SOCKET_OPTION_VALUE)&optval, sizeof(optval)) < 0)
lWarning() << "Fail to set SO_REUSEADDR";
set_non_blocking_socket(sock);
return sock;
}
int StunClient::recvStunResponse(ortp_socket_t sock, Candidate &candidate, int &id) {
int StunClient::recvStunResponse (ortp_socket_t sock, Candidate &candidate, int &id) {
char buf[MS_STUN_MAX_MESSAGE_SIZE];
int len = MS_STUN_MAX_MESSAGE_SIZE;
@ -223,7 +224,13 @@ int StunClient::recvStunResponse(ortp_socket_t sock, Candidate &candidate, int &
return len;
}
int StunClient::sendStunRequest(ortp_socket_t sock, const struct sockaddr *server, socklen_t addrlen, int id, bool changeAddr) {
int StunClient::sendStunRequest (
ortp_socket_t sock,
const struct sockaddr *server,
socklen_t addrlen,
int id,
bool changeAddr
) {
MSStunMessage *req = ms_stun_binding_request_create();
UInt96 trId = ms_stun_message_get_tr_id(req);
trId.octet[0] = static_cast<unsigned char>(id);

View file

@ -19,18 +19,20 @@
#ifndef _STUN_CLIENT_H_
#define _STUN_CLIENT_H_
#include <string>
#include <ortp/port.h>
#include "linphone/types.h"
#include "linphone/utils/general.h"
#include "sal/sal.h"
// =============================================================================
L_DECL_C_STRUCT_PREFIX_LESS(SalMediaDescription);
L_DECL_C_STRUCT(LinphoneCore);
LINPHONE_BEGIN_NAMESPACE
class StunClient {
struct Candidate {
std::string address;
int port;
@ -42,14 +44,21 @@ public:
int run (int audioPort, int videoPort, int textPort);
void updateMediaDescription (SalMediaDescription *md) const;
const Candidate & getAudioCandidate () const { return audioCandidate; }
const Candidate & getVideoCandidate () const { return videoCandidate; }
const Candidate & getTextCandidate () const { return textCandidate; }
const Candidate &getAudioCandidate () const {
return audioCandidate;
}
const Candidate &getVideoCandidate () const {
return videoCandidate;
}
const Candidate &getTextCandidate () const {
return textCandidate;
}
private:
ortp_socket_t createStunSocket (int localPort);
int recvStunResponse(ortp_socket_t sock, Candidate &candidate, int &id);
int sendStunRequest(ortp_socket_t sock, const struct sockaddr *server, socklen_t addrlen, int id, bool changeAddr);
int recvStunResponse (ortp_socket_t sock, Candidate &candidate, int &id);
int sendStunRequest (ortp_socket_t sock, const struct sockaddr *server, socklen_t addrlen, int id, bool changeAddr);
private:
LinphoneCore *core = nullptr;

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>
#include <cmath>
#include "private.h"
@ -294,7 +294,7 @@ bctbx_list_t *PayloadTypeHandler::makeCodecsList (SalStreamType type, int bandwi
if (bandwidthLimit > 0 && !isPayloadTypeUsableForBandwidth(pt, bandwidthLimit)) {
lInfo() << "Codec " << pt->mime_type << "/" << pt->clock_rate << " eliminated because of audio bandwidth constraint of " <<
bandwidthLimit << " kbit/s";
bandwidthLimit << " kbit/s";
continue;
}

View file

@ -19,17 +19,18 @@
#ifndef _PAYLOAD_TYPE_HANDLER_H_
#define _PAYLOAD_TYPE_HANDLER_H_
#include "linphone/core.h"
#include "linphone/utils/general.h"
#include "sal/sal.h" /* SalStreamType. */
// =============================================================================
#include "sal/sal.h"
#define PAYLOAD_TYPE_ENABLED PAYLOAD_TYPE_USER_FLAG_0
#define PAYLOAD_TYPE_BITRATE_OVERRIDE PAYLOAD_TYPE_USER_FLAG_3
#define PAYLOAD_TYPE_FROZEN_NUMBER PAYLOAD_TYPE_USER_FLAG_4
// =============================================================================
L_DECL_C_STRUCT(LinphoneCore);
LINPHONE_BEGIN_NAMESPACE
struct VbrCodecBitrate {

View file

@ -171,7 +171,7 @@ Variant::Variant (float value) : Variant(Float) {
d->value.f = value;
}
Variant::Variant (const std::string &value) : Variant(String) {
Variant::Variant (const string &value) : Variant(String) {
L_D(Variant);
*d->value.str = value;
}