diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h index 34e169d127af66aa8ff0a0836e8b0d236e4a594f..259207960bd190c09e0bcef786045c67b363e23a 100644 --- a/src/sip/sipcall.h +++ b/src/sip/sipcall.h @@ -21,8 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __SIPCALL_H__ -#define __SIPCALL_H__ +#pragma once #ifdef HAVE_CONFIG_H #include "config.h" @@ -62,221 +61,204 @@ class Controller; */ class SIPCall : public Call { - public: - static const char* const LINK_TYPE; - - protected: - /** - * Constructor (protected) - * @param id The call identifier - * @param type The type of the call. Could be Incoming - * Outgoing - */ - SIPCall(SIPAccountBase& account, const std::string& id, Call::CallType type); - - public: - /** - * Destructor - */ - ~SIPCall(); - - /** - * Return the SDP's manager of this call - */ - Sdp& getSDP() { - return *sdp_; - } - - const char* getLinkType() const override { - return LINK_TYPE; - } - - /** - * Returns a pointer to the AudioRtpSession object - */ - AudioRtpSession& getAVFormatRTP() const { - return *avformatrtp_; - } +public: + static const char* const LINK_TYPE; + + /** + * Destructor + */ + ~SIPCall(); + +protected: + /** + * Constructor (protected) + * @param id The call identifier + * @param type The type of the call. Could be Incoming or Outgoing + */ + SIPCall(SIPAccountBase& account, const std::string& id, Call::CallType type); + +public: // overridden + const char* getLinkType() const override { + return LINK_TYPE; + } + void answer() override; + void hangup(int reason) override; + void refuse() override; + void transfer(const std::string& to) override; + bool attendedTransfer(const std::string& to) override; + bool onhold() override; + bool offhold() override; + void switchInput(const std::string& resource) override; + void peerHungup() override; + void carryingDTMFdigits(char code) override; + void sendTextMessage(const std::map<std::string, std::string>& messages, + const std::string& from) override; + void removeCall() override; + void muteMedia(const std::string& mediaType, bool isMuted) override; + void restartMediaSender() override; + void restartMediaReceiver() override; + bool useVideoCodec(const AccountVideoCodecInfo* codec) const override; + virtual std::map<std::string, std::string> getDetails() const override; + bool initIceTransport(bool master, unsigned channel_num=4) override; + +public: // SIP related + /** + * Return the SDP's manager of this call + */ + Sdp& getSDP() { + return *sdp_; + } + + /** + * Tell the user that the call is ringing + * @param + */ + void onPeerRinging(); + + /** + * Tell the user that the call was answered + * @param + */ + void onAnswered(); + + /** + * To call in case of server/internal error + * @param cause Optionnal error code + */ + void onFailure(signed cause=0); + + /** + * Peer close the connection + * @param + */ + void onClosed(); + + void onReceiveOffer(const pjmedia_sdp_session *offer); + + void onMediaUpdate(); + + void setContactHeader(pj_str_t *contact); + + void setTransport(const std::shared_ptr<SipTransport>& t); + + inline SipTransport* getTransport() { + return transport_.get(); + } + + void sendSIPInfo(const char *const body, const char *const subtype); + + SIPAccountBase& getSIPAccount() const; + + void updateSDPFromSTUN(); + + void setupLocalSDPFromIce(); + + /** + * Give peer SDP to the call for handling + * @param sdp pointer on PJSIP sdp structure, could be nullptr (acts as no-op in such case) + */ + void setRemoteSdp(const pjmedia_sdp_session* sdp); + + void terminateSipSession(int status); + + /** + * The invite session to be reused in case of transfer + */ + struct InvSessionDeleter { + void operator()(pjsip_inv_session*) const noexcept; + }; + + std::unique_ptr<pjsip_inv_session, InvSessionDeleter> inv; + +public: // NOT SIP RELATED (good candidates to be moved elsewhere) + /** + * Returns a pointer to the AudioRtpSession object + */ + AudioRtpSession& getAVFormatRTP() const { + return *avformatrtp_; + } #ifdef RING_VIDEO - /** - * Returns a pointer to the VideoRtp object - */ - video::VideoRtpSession& getVideoRtp () { - return *videortp_; - } + /** + * Returns a pointer to the VideoRtp object + */ + video::VideoRtpSession& getVideoRtp () { + return *videortp_; + } #endif - /** - * The invite session to be reused in case of transfer - */ - struct InvSessionDeleter { - void operator()(pjsip_inv_session*) const noexcept; - }; + void setSecure(bool sec); - std::unique_ptr<pjsip_inv_session, InvSessionDeleter> inv; + bool isSecure() const { + return srtpEnabled_; + } - void setSecure(bool sec); + void setCallMediaLocal(const pj_sockaddr& localIP); - bool isSecure() const { - return srtpEnabled_; - } + void generateMediaPorts(); - void setCallMediaLocal(const pj_sockaddr& localIP); + bool startIce(); - void generateMediaPorts(); + void startAllMedia(); - void setContactHeader(pj_str_t *contact); + void openPortsUPnP(); - void setTransport(const std::shared_ptr<SipTransport>& t); + void setPeerRegistredName(const std::string& name) { + peerRegistredName_ = name; + } - inline SipTransport* getTransport() { - return transport_.get(); - } +private: + NON_COPYABLE(SIPCall); - void sendSIPInfo(const char *const body, const char *const subtype); + void waitForIceAndStartMedia(); - void answer() override; + void stopAllMedia(); - void hangup(int reason) override; + /** + * Transfer method used for both type of transfer + */ + bool transferCommon(pj_str_t *dst); - void refuse() override; + bool internalOffHold(const std::function<void()> &SDPUpdateFunc); - void transfer(const std::string& to) override; + int SIPSessionReinvite(); - bool attendedTransfer(const std::string& to) override; + std::vector<IceCandidate> getAllRemoteCandidates(); - bool onhold() override; + void merge(Call& call) override; // not public - only called by Call - bool offhold() override; - - void switchInput(const std::string& resource) override; - - void peerHungup() override; - - void carryingDTMFdigits(char code) override; - - void sendTextMessage(const std::map<std::string, std::string>& messages, - const std::string& from) override; - - void removeCall() override; - - SIPAccountBase& getSIPAccount() const; - - void updateSDPFromSTUN(); - - /** - * Tell the user that the call is ringing - * @param - */ - void onPeerRinging(); - - /** - * Tell the user that the call was answered - * @param - */ - void onAnswered(); - - /** - * To call in case of server/internal error - * @param cause Optionnal error code - */ - void onFailure(signed cause=0); - - /** - * Peer close the connection - * @param - */ - void onClosed(); - - void setupLocalSDPFromIce(); - - bool startIce(); - - void startAllMedia(); - - void onMediaUpdate(); - - void onReceiveOffer(const pjmedia_sdp_session *offer); - - void openPortsUPnP(); - - void muteMedia(const std::string& mediaType, bool isMuted) override; - - void restartMediaSender() override; - - void restartMediaReceiver() override; - - bool useVideoCodec(const AccountVideoCodecInfo* codec) const override; - - virtual std::map<std::string, std::string> getDetails() const override; - - bool initIceTransport(bool master, unsigned channel_num=4) override; - - void terminateSipSession(int status); - - void setPeerRegistredName(const std::string& name) { - peerRegistredName_ = name; - } - - /** - * Give peer SDP to the call for handling - * @param sdp pointer on PJSIP sdp structure, could be nullptr (acts as no-op in such case) - */ - void setRemoteSdp(const pjmedia_sdp_session* sdp); - - private: - NON_COPYABLE(SIPCall); - - void waitForIceAndStartMedia(); - - void stopAllMedia(); - - /** - * Transfer method used for both type of transfer - */ - bool transferCommon(pj_str_t *dst); - - bool internalOffHold(const std::function<void()> &SDPUpdateFunc); - - int SIPSessionReinvite(); - - void merge(Call& call) override; // only called by Call - - std::vector<IceCandidate> getAllRemoteCandidates(); - - std::unique_ptr<AudioRtpSession> avformatrtp_; + std::unique_ptr<AudioRtpSession> avformatrtp_; #ifdef RING_VIDEO - /** - * Video Rtp Session factory - */ - std::unique_ptr<video::VideoRtpSession> videortp_; + /** + * Video Rtp Session factory + */ + std::unique_ptr<video::VideoRtpSession> videortp_; - std::string videoInput_; + std::string videoInput_; #endif - bool srtpEnabled_ {false}; + bool srtpEnabled_ {false}; - /** - * Hold the transport used for SIP communication. - * Will be different from the account registration transport for - * non-IP2IP calls. - */ - std::shared_ptr<SipTransport> transport_ {}; + /** + * Hold the transport used for SIP communication. + * Will be different from the account registration transport for + * non-IP2IP calls. + */ + std::shared_ptr<SipTransport> transport_ {}; - /** - * The SDP session - */ - std::unique_ptr<Sdp> sdp_; - bool peerHolding_ {false}; + /** + * The SDP session + */ + std::unique_ptr<Sdp> sdp_; + bool peerHolding_ {false}; - std::string peerRegistredName_ {}; + std::string peerRegistredName_ {}; - char contactBuffer_[PJSIP_MAX_URL_SIZE] {}; - pj_str_t contactHeader_ {contactBuffer_, 0}; + char contactBuffer_[PJSIP_MAX_URL_SIZE] {}; + pj_str_t contactHeader_ {contactBuffer_, 0}; - std::unique_ptr<ring::upnp::Controller> upnp_; + std::unique_ptr<ring::upnp::Controller> upnp_; }; // Helpers @@ -290,5 +272,3 @@ inline std::shared_ptr<SIPCall> getPtr(SIPCall& call) } } // namespace ring - -#endif // __SIPCALL_H__