和声SIP软电话终端SDK手册¶
介绍¶
和声 SIP 软电话终端 SDK 是用于 Microsoft Windows 桌面环境的 SIP 客户端开发包,它主要包括:
- 软电话终端类型库
- 相关文档
- 例子代码
- 授权使用协议
软电话终端类型库是该SDK的核心部分,开发者通过调用该类型库,可实现常见的SIP终端音频通信功能。
目录¶
介绍¶
和声 SIP 软电话终端 SDK 是用于 Microsoft Windows 桌面环境的 SIP 客户端开发包,它主要包括:
- 软电话终端类型库
- 相关文档
- 例子代码
- 授权使用协议
软电话终端类型库是该SDK的核心部分,开发者通过调用该类型库,可实现常见的SIP终端音频通信功能。
安装与使用¶
软电话终端类型库是一个 Microsoft .NET 类型库,由 C++/CLI 语言编写。所以,应用程序开发者必须使用.NET程序对它进行调用。
文件 Hesong.Sipua.dll 包含了软电话的全部代码实现与接口定义。 开发者需要在自己的项目中引用该类型库,并将它发布到目标环境。
发布目录说明:
发布目录 | 说明 |
---|---|
net/2.0/ | 用于 .NET 2.0 的程序包 |
net/4.0/ | 用于 .NET 4.0 Full Pack 的程序包 |
netcp/4.0/ | 用于 .NET 4.0 Client Pack 的程序包 |
系统要求¶
支持的操作系统¶
- Windows XP SP3
- Windows Server 2003 SP2
- Windows Vista SP1 或更高版本
- Windows Server 2008
- Windows 7
- Windows Server 2008 R2
- Windows 7 SP1
- Windows Server 2008 R2 SP1
支持的体系结构¶
x86
- x64
需要Windows 64bit在32bit兼容模式下使用
支持的.Net Framework¶
支持的Visual C++ Redistributable¶
Microsoft Visual C++ 2005 Redistributable Package (x86)
使用 Visual C++ 开发的应用程序所需的 Visual C++ 库的运行时组件。
注意
该组件 必须安装 ,即使使用 .NET 4.0 程序包,也需要该组件。
Visual C++ Redistributable for Visual Studio 2012 Update 4
依赖的第三方类型库¶
该类型库依赖的唯一第三方类型库是 Apache log4net™ 。
发布目录下同一个子目录中的 log4net.dll 与 Hesong.Sipua.dll 对于.NET的版本的要求一致,它们需要一同使用。
目前使用的log4net版本是 1.2.13 。
硬件要求¶
- 建议的最低要求:Pentium 1 GHz 或更快,512 MB RAM 或更大
- 最小磁盘空间:10 MB
- 全双工声卡
- 麦克风
- 头戴式耳机
在 Vistual Studio 中使用¶
Visual Studio 2005
测试通过
Visual Studio 2008
未测试
Visual Studio 2010
未测试
Visual Studio 2012
测试通过
Visual Studio 2013
未测试
API 参考¶
由于本类库使用 C++/CLI 语言实现,所以 API 参考中的接口定义采用了 C++ 语言的书写风格。但是,由于 C++/CLI 与 标准 C++ 的差异性,接口描述可能与实际情况略有不同,请开发者以实际情况为准。
Hesong::Sipua::Lib¶
- class Lib¶
该类是SIP软电话终端的核心。在进行任何其它操作时前,都必须实例化该类。
构造¶
- Lib::Lib()¶
使用默认参数的构造函数。使用该构造函数时,SIP端口为5060,RTP启示端口为4000
- Lib::Lib(unsigned int sip_udp_port, unsigned int rtp_udp_port)¶
参数: - sip_udp_port – 该 SIP UA 所使用的 SIP UDP 端口。0表示自动寻找一个未被占用的端口。建议使用 SIP 协议的默认端口 5060
- rtp_udp_port – 该 SIP UA 所使用的 RTP UDP 端口。0表示自动寻找一个未被占用的端口。建议使用 1024 以上的端口,如 4000。注意 RTCP 会自动占用该RTP端口数值 +1 的端口。
注意
在构造该类的实例时,SIP协议栈所需的全局数据被初始化。所以在进行任何其它操作之前,必须首先新建一个 Lib 实例,且 不可新建多个实例 。
类型¶
AccountList¶
- class Lib::AccountList : public System::Collections::Generic::IList<Account>¶
账户列表类
它是 Lib 类的一个嵌套子类。该类型实现了 .NET 系统框架的 System::Collections::Generic::IList 接口。 这个 List 容器类的元素是 Account 对象。开发者通过增减容器中的元素,来增加或者删除SIP账户。
- void Lib::AccountList::Add(Account* item)¶
参数 item: 账户对象 添加账户
- void Lib::AccountList::Clear()¶
清空账户
- bool Lib::AccountList::Contains(Account* item)¶
参数 item: 账户 返回: 是否存在 是否存在账户
- void Lib::AccountList::CopyTo(array<Account*>* array, int arrayIndex)¶
- int Lib::AccountList::IndexOf(Account* item)¶
- void Lib::AccountList::Insert(int index, Account* item)¶
- bool Lib::AccountList::Remove(Account* item)¶
- void Lib::AccountList::RemoveAt(int index)¶
Hesong::Sipua::Account¶
- class Account¶
SIP账户
构造¶
- Account::Account(String* registerServer, String* project, String* userName, String* password, unsigned int regTimeout, unsigned int regRetry, unsigned int regFirstRetry, String* label)¶
参数: - registerServer – 注册服务器地址。地址格式为: host[:port] 。如果不提供端口,默认使用5060端口。
- project – 项目名称
- userName – 注册用户名
- password – 注册密码
- regTimeout – 注册超时值(秒)
- regRetry – 注册重试时间(秒)
- regFirstRetry – 首次注册重试时间(秒)
- label – 账户标签
- Account::Account(String* registerServer, String* project, String* userName, String* password, unsigned int regTimeout, unsigned int regRetry, unsigned int regFirstRetry)¶
- Account::Account(String* registerServer, String* project, String* userName, unsigned int regTimeout, unsigned int retryInterval, unsigned int firstRetryInterval, String* label)¶
- Account::Account(String* registerServer, String* project, String* userName, unsigned int regTimeout, unsigned int retryInterval, unsigned int firstRetryInterval)¶
- Account::Account(String* registerServer, String* project, String* userName, String* password, String* label)¶
- Account::Account(String* registerServer, String* project, String* userName, String* label)¶
- Account::Account(String* registerServer, String* project, String* userName)¶
方法¶
- int Account::Add()¶
将账户数据添加到全局数据。如果不调用该方法,就无法针对账户实例做出任何呼叫、接听、注册操作。
调用该方法后,本类库会自动的向服务器注册该账户。
注解
一般来说,开发者不需要直接使用该方法,而是通过 Lib::AccountList::Add() 将账户对象加入到列表,此时,本方法会被自动调用。
- void Account::Del()¶
将账户数据从全局数据中删除。一旦调用,此账户将从服务器注销,且该账户的当前通话会断开。
注解
开发者不应直接使用该方法。本类的析构函数会自动完成这一步骤。
- void Account::AnswerCall()¶
接听当前来电
- void Account::AnswerCall(CallInfo* callInfo)¶
接听来电
- void Account::HangupCall()¶
挂断当前通话;拒接当前来电
- void Account::HangupCall(CallInfo* callInfo)¶
挂断通话;拒接来电
- void Account::MakeCall(String* callee)¶
参数 callee: 被叫 发起呼叫
被叫号码直接指定号码/用户名即可, 不要 使用类似 sip:123@host 这样的格式。
- void Account::SendDtmf(String* digits)¶
参数 digits: DTFM 码字符串 在当前通话中发送DTMF码
- void Account::SendDtmf(CallInfo* callInfo, String* digits)¶
参数: - callInfo – 要发送DTMF码的通话
- digits – DTFM 码字符串
发送DTMF码
- void Account::Register()¶
注册
调用后,当前账户将相服务器进行注册。
注解
由于调用 Account::Add() 或者 Lib::AccountList::Add() 都会自动注册账户,所以开发者一般不需要使用该方法。
- void Account::UnRegister()¶
反注册
调用后,本类库将向服务器发送该账户的反注册请求。
- void Account::StartRereg()¶
该方法用于在注册请求返回 488 时,继续尝试注册。开发者请 不要调用 。
- void Account::StopRereg()¶
该方法用于配合 Account::StartRereg() 使用。开发者请 不要调用 。
属性¶
- RegInfo* Account::LastRegInfo¶
最近一次的注册结果信息
- CallInfo* Account::CurrentCallInfo¶
当前正在进行的通话或者来电的信息
- int Account::Id¶
账户ID
注意这个ID不是全局唯一的
- String* Account::UserId¶
账户的用户ID字符串
格式是:
"project_name" <sip:user_name@server_address>
- String* Account::RegUri¶
注册URI
格式是:
sip:host[:port]
- String* Account::Realm¶
领域
- String* Account::Project¶
项目名称
- String* Account::UserName¶
注册用户名
- String* Account::Password¶
注册密码
- String* Account::Label¶
账户标签
- Boolean* Account::ReRegOn488¶
是否在收到 status=488 的注册回复后,仍然尝试重注册。
默认值: false
- Object* Account::tag¶
标签
事件¶
- void Account::OnRegisterStateChanged(RegInfo* regInfo)¶
参数 regInfo: 注册信息对象 账户的注册状态发生变化
- void Account::OnIncomingCall(CallInfo* info)¶
参数 info: 呼叫信息对象 收到来电
参数 info 是一个 CallInfo 对象。开发者可以在该事件的处理函数中:可以调用 CallInfo::Answer() 接听;可以调用 CallInfo::Hangup() 拒接。
开发者也可以直接调用 Account::AnswerCall() 与 Account::HangupCall() 来进行接听与拒接。
- void Account::OnCallStateChanged(CallInfo* regInfo)¶
参数 info: 呼叫信息对象 呼叫状态发生变化
Hesong::Sipua::CallInfo¶
- class CallInfo¶
呼叫信息
这个类用于访问与控制呼叫、通话
方法¶
- void CallInfo::StartRecord()¶
开始录音
调用该方法后,如果已经设置对象的 RecFile 属性为有效的文件名,那么通话录音会被记录到该文件。录音格式是 256kB/s 的 PCM。
- void CallInfo::StopRecord()¶
停止录音
注解
在开始录音之后,开发者不必调用该方法停止录音,因为本类库会在通话结束时自动结束已经开始的录音。
- void CallInfo::Answer()¶
应答
在事件 Account::OnIncomingCall() 中,调用该方法可以接通来电
- void CallInfo::Hangup()¶
挂断
- 在事件 Account::OnIncomingCall() 中,调用该方法可以拒接来电
- 在通话中调用该方法,可结束通话
- void CallInfo::SendDtmf(String* digits)¶
参数 digits: DTFM 码字符串 发送DTMF码
属性¶
- float CallInfo::InputVolume¶
输入音量
输入音量是指:在本机上播放的,来自对端的声音的音量。
其值越大,音量越大。 0 表示静音。
默认值: 2.0 注解
调整本属性不会影响 Windows 操作系统的音量设置。如果 Windows 播放音量很小,那么,即使本属性值很大,最终听到的声音也会很小。同理,如果 Windows 播放被静音,即使本属性值很大,也会无声。
- float CallInfo::OutputVolume¶
输出音量
输出音量是指:在对端播放的,来自本机的声音的音量。
其值越大,音量越大。 0 表示静音。
默认值: 10.0 注解
调整本属性不会影响 Windows 操作系统的音量设置。如果 Windows 采集音量很小,那么,即使本属性值很大,最终听到的声音也会很小。同理,如果 Windows 采集被静音,即使本属性值很大,也会无声。
- int CallInfo::State¶
呼叫状态编码
- String* CallInfo::StateText¶
呼叫状态描述文本
- int CallInfo::LastStatus¶
上次收到的状态码,可以用作 cause code
- String* CallInfo::LastStatusText¶
上次收到的状态码描述文本
- String* CallInfo::RemoteInfo¶
对端信息
- String* CallInfo::RemoteInfoContact¶
对端被叫/主叫/联系人信息
- Boolean CallInfo::IsActive¶
通话是否处于活动状态
- String* CallInfo::RecFile¶
录音文件
只有将本属性设置为一个有效的文件名后,调用 CallInfo::StartRecord() 方可将媒体流写入到录音文件。