123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- /*
- * telephone.h
- *
- * Created on: 2021年12月13日
- * Author: zkswe
- */
- #ifndef JNI_VOIP_TELEPHONE_H_
- #define JNI_VOIP_TELEPHONE_H_
- #include <string>
- #include <map>
- #include <functional>
- #include "acoustic_echo_cancellater.h"
- #include "audio_process_chain.h"
- namespace voip {
- enum State {
- STATE_CALL_CALLING, //正在拨号
- STATE_CALL_EARLY, //正在响铃
- STATE_CALL_INCOMING, //来电
- STATE_CALL_CONNECTING,//正在连接
- STATE_CALL_CONFIRMED, //接通
- STATE_CALL_DISCONNECTED, //结束
- };
- enum SIPStatusCode {
- SIP_STATUS_CODE_RINGING = 180,
- SIP_STATUS_CODE_PROGRESS = 183,
- SIP_STATUS_CODE_OK = 200,
- SIP_STATUS_CODE_TEMPORARILY_UNAVAILABLE = 480,
- SIP_STATUS_CODE_BUSY_HERE = 486,
- SIP_STATUS_CODE_DECLINE = 603,
- };
- enum SIPTranstorpType {
- SIP_TRANSPORT_UDP = 1,
- SIP_TRANSPORT_TCP,
- };
- struct RtcpStreamStat {
- /**
- * 上次更新时间
- */
- int64_t last_updated_at = 0;
- /**
- * 接收的包总数
- */
- int64_t number_of_packets = 0;
- };
- struct RtcpStat {
- RtcpStreamStat rx;
- };
- struct MediaStreamStat {
- RtcpStat audio;
- RtcpStat video;
- };
- enum DtmfMethod {
- /**
- * Send DTMF using RFC2833.
- */
- DTMF_METHOD_RFC2833,
- /**
- * Send DTMF using SIP INFO.
- */
- DTMF_METHOD_SIP_INFO
- };
- enum RingtonePolicy {
- /**
- * 默认的铃声策略,自动响铃
- */
- RINGTONE_POLICY_DEFAULT,
- /**
- * 没有任何铃声
- */
- RINGTONE_POLICY_NONE = 100,
- };
- struct CallInfo {
- /**
- * Call ID
- * 小于0无效
- */
- int id;
- /**
- * 当前状态
- */
- State state;
- /**
- * 对方地址
- */
- std::string remote_uri;
- /**
- * 对方联系人
- */
- std::string remote_contact;
- /**
- * 已通话时长,未接通时为0
- * 单位 毫秒
- */
- int duration;
- CallInfo();
- };
- typedef std::map<std::string, std::string> HeaderList;
- struct CallSetting {
- /**
- * 自定义 Contact display-name字段
- */
- std::string display_name;
- /**
- * 是否启用视频
- * 默认true
- */
- bool enable_video;
- /**
- * 自定义 Header
- */
- HeaderList headers;
- CallSetting();
- };
- struct Configuration {
- /**
- * sip:name@domain
- */
- std::string id_uri;
- /**
- * sip:domain:port
- */
- std::string server_uri;
- std::string user_name;
- std::string password;
- std::string user_agent;
- /**
- * 注册时自定义的Header
- */
- HeaderList headers;
- /**
- * 本地账号使用的端口号
- * 默认 5060
- */
- int local_port;
- /**
- * 是否启用本地账号
- * true 启用; false 关闭
- * 默认启用
- */
- bool enable_local_account;
- /**
- * 传输协议类型
- */
- SIPTranstorpType transtorp_type;
- /**
- * 通话时,自动发送演示视频画面到对方
- * 默认 false
- */
- bool auto_transmit_video_to_remote;
- /**
- * 启用ICE
- */
- bool enable_ice;
- std::string turn_server;
- std::string stun_server;
- std::string outbound_proxy;
- Configuration();
- };
- class Telephone {
- public:
- Telephone(const Configuration& conf);
- virtual ~Telephone();
- /**
- * 拨号
- */
- int MakeCall(const std::string& uri);
- /**
- * 拨号
- */
- int MakeCall(const std::string& uri, const CallSetting& setting);
- /**
- * 接听
- */
- int Answer();
- /**
- * 接听
- *
- * status_code (100~699)
- */
- int Answer(int call_id, int status_code);
- /**
- * 挂断
- */
- int Hangup();
- /**
- * 挂断
- *
- * status_code (100~699)
- */
- int Hangup(int call_id, int status_code);
- /**
- * 获得通话信息
- */
- CallInfo GetCallInfo();
- /**
- * 获得指定通话信息
- */
- CallInfo GetCallInfo(int call_id);
- /**
- * 获得当前电话数量
- * @return
- */
- int GetCallCount();
- typedef void (*CallStateListener)(Telephone*, int call_id, State state);
- /**
- * 监听电话状态
- */
- void AddCallStateListener(CallStateListener listener);
- void RemoveCallStateListener(CallStateListener listener);
- typedef void (*RegisteredStateListener)(Telephone* telephone, int code);
- void AddRegisteredStateListener(RegisteredStateListener listener);
- void RemoveRegisteredStateListener(RegisteredStateListener listener);
- /**
- * 获取SIP注册状态码
- * @return
- */
- int GetRegistrationStatusCode();
- /**
- * 设置视频显示位置 (暂未实现)
- * 默认全屏显示
- * 若要显示视频,需要创建一个充满屏幕的视频控件,可参考call.ftu的配置
- */
- void SetVideoRect(int x, int y, int w, int h);
- /**
- * 发送即时消息,忽略对方应答
- * @param to
- * @param target_uri
- * @param text
- * @return 如果target_uri为空,则发送到to。正常发送返回0
- */
- int SendInstantMessage(const std::string& to,
- const std::string& target_uri, const std::string& text);
- /**
- * 发送即时消息,并等待对方应答
- * @param to
- * @param target_uri 如果target_uri为空,则发送到to
- * @param content 发送的内容
- * @param timeout 等待响应的毫秒数,最大30000ms
- * @return 状态码, 常规情况下,成功应答返回200,未收到应答返回0或者408,
- * 其他值的含义参考sip协议
- */
- int SendInstantMessageAndWait(const std::string& to,
- const std::string& target_uri, const std::string& content, int timeout);
- /**
- * 使用 SIP INFO 方式 发送 DTMF
- * @param ch
- * @return
- */
- int SendDtmf(const std::string& ch);
- /**
- * 使用指定方式发送DTMF
- * @param method 发送DTMF的方式
- * @param ch 发送内容
- * @return 0 成功
- */
- int SendDtmf(DtmfMethod method, const std::string& ch);
- int SendMessageRequest(const std::string& from,
- const std::string& to,
- const std::string& text);
- /**
- * 设置铃声策略
- * @param policy
- */
- void SetRingtonePolicy(RingtonePolicy policy);
- /**
- * 获取媒体流状态
- * @param call_id
- * @param stat
- * @return
- */
- int GetMediaStreamStat(int call_id, MediaStreamStat* stat);
- /**
- * 设置录音的消回音、音频处理链路参数
- * 通话时设置无效,设置成功后,下次通话生效
- * @param conf
- */
- int SetInputAecApcConfig(
- const base::AcousticEchoCancellater::Configuration& aec,
- const base::AudioProcessChain::Configuration& apc);
- /**
- * 设置经过aec、apc处理后的声音的增益
- * @param size 增益倍数1~10
- */
- int SetInputPcmGainSize(float size);
- private:
- class Impl;
- Impl* impl_;
- };
- } /* namespace voip */
- #endif /* JNI_VOIP_TELEPHONE_H_ */
|