web浏览器无插件播放实时音视频技术---WebRTC2SIP(三)

来源:互联网 发布:淘宝如何设置加钱换购 编辑:程序博客网 时间:2024/05/17 08:46

一、WebRTC2SIP概述

WebRTC2SIPRTCWebSIP网络的网关。浏览器通过WebSocket和该网关进行SIP通信,网关将这些数据通过UDPTCP转给SIP终端,从而实现SIP终端和浏览器的多媒体通信。

 

SIPML5是用JAVASCRIPT实现的SIP协议栈,通过这套JS可以很方便的和WebRTC2SIP网关进行SIP通信,数据传输通道使用WebSocket

WebRTC2SIP3大模块组成,SIP代理、RTCWeb BreakerMedia Coder

1.1SIP代理

浏览器通过WebSocketWebRTC2SIP网关进行SIP通信。SIP模块通过UDPTCPSIP终端进行通信。

 

WebSocketHTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术。

WebSocket通信协议于2011年被IETF定为标准RFC 6455WebSocket APIW3C定为标准。

1.2RTCWeb Breaker

 

RTCWeb规范中要求必现支持ICEDTLS/SRTP。大多数SIP终端只是支持RTPRTCPRTCWeb Breaker提供RTPRTCPDTLS/SRTP之间的转换,保证Web ClientSIP终端能够进行音视频通信。

RTCWeb Breaker默认是不启用的。如果需要启用,需要客户端在URI中加入“rtcweb-breaker=yes”来告知WebRTC2SIP启用RTCWeb Breaker模块。

1.3Media Coder

 

RTCWeb的音频编码默认是用的opusg.711,大部分支持WebRTC浏览器使用VP8进行视频编码,如ChromeFirefox

如果SIP终端不支持VP8opus,则双方无法完成音视频通信。

通过启用Media Coder,可以让不支持VP8opusSIP终端能够和Web Client进行音视频通信。

是否启用Media Coder,需要在WebRTC2SIPconfig.xml中进行配置,且必须启用RTCWeb Breaker,默认此模块不启用。


二、WebRTC2SIP环境搭建与源代码编译

http://cgs1999.iteye.com/blog/1972831(这里不做详细介绍)

在编译包的过程中,有一定的依赖关系如下:



三、WebRTC2SIP配置文件

config.xml一般和WebRTC2SIP执行程序在同一目录,通过此文件对WebRTC2SIP进行配置。

<?xml version="1.0"encoding="utf-8" ?>

<config>

  <debug-level>INFO</debug-level>

 

  <transport>udp;*;10060</transport>

  <transport>ws;*;10060</transport>

  <transport>wss;*;10062</transport>

  

  <enable-rtp-symetric>yes</enable-rtp-symetric>

  <enable-100rel>no</enable-100rel>

  <enable-media-coder>no</enable-media-coder>

  <enable-videojb>yes</enable-videojb>

  <video-size-pref>vga</video-size-pref>

  <rtp-buffsize>65535</rtp-buffsize>

  <avpf-tail-length>100;400</avpf-tail-length>

  <srtp-mode>optional</srtp-mode>

  <srtp-type>sdes;dtls</srtp-type>

  <dtmf-type>rfc4733</dtmf-type>

 

  <codecs>opus;pcma;pcmu;gsm;vp8;h264-bp;h264-mp;h263;h263+</codecs>

  <codec-opus-maxrates>48000;48000</ codec-opus-maxrates >

 

  <stun-server>stun.l.google.com;19302;stun-user;stun-password</stun-server>

  <enable-icestun>yes</enable-icestun>

 

  <max-fds>65535</max-fds>

 

  <nameserver>66.66.66.66</nameserver>

  <nameserver>77.77.77.77</nameserver>

 

  <ssl-certificates>

/tmp/priv.pem;

/tmp/pub.pem;

/tmp/cacert.pem;

no

</ssl-certificates>

 

<!-- ***CLICK-TO-CALL SERVICE*** -->

  <transport>c2c;*;10070</transport>

  <transport>c2cs;*;10072</transport>

  <database>sqlite;*</database>

  <account-mail>smtps;*;*;e.org;465;noreply@e.org;noreply@e.org;mysecret</account-mail>

  <account-sip-caller>*;sip:13131313@b.c;13131313;b.c;mysecret</account-sip-caller>

  <account-sip-caller>*;sip:13131313@a.c;13131313;a.c;mysecret</account-sip-caller>

 

</config>

 

<debug-level />

Define the minimum debug-level to display.

Format: debug-level-value

Debug-level-value = INFO | WARN | ERROR | FATAL

 

<transport />

Each entry defines a protocol, local IP address and port to bind to.

Format: proto-value;local-ip-value;local-port-value

proto-value: udp | tcp | tls | ws | wss | c2c | c2cs

“ws” protocol defines WebSocket and “wss” the secure version. At least one WebSocket transport must be added to allow the web browser to connect to the server. The other protocols (tcp, tls and udp) are used to forward the request from the web browser to the SIP-legacy network. “C2c” and “c2cs” are used for the click-to-call service and runs on top of HTTP or HTTPS protocols respectively.

local-ip-value: Any valid IP address. Use star (*) to let the server choose the best local IP address to bind to. Examples: udp;*;5060 or ws;*;5061 or wss;192.168.0.10;5062

local-port-value: Any local free port to bind to. Use star (*) to let the server choose the best free port to bind to. Examples: udp;*;*, ws;*;* or wss;*;5062

 

<enable-rtp-symetric />

Format: enable-rtp-symetric-value

enable-rtp-symetric-value: yes | no

Available since: 2.1.0

This option is used to force symmetric RTP and RTCP streams to help NAT and firewall traversal. It only applies on remote RTP/RTCP as local stream is always symmetric. If both parties (remote and local) have successfully negotiated ICE candidates then, none will be forced to use symmetric RTP/RTCP.

An RTP/RTCP stream is symmetric if the same port is used to send and receive packets. This helps for NAT and firewall traversal as the outgoing packets open a pinhole for the ongoing ones.

Let’s imagine you have a server on public network and a client on private network:

1. Server: Public IP address is 1.1.1.1

2. Client: Private IP address is 2.2.2.2 and public IP address is1.1.1.2

3. The SDP from the client to the sever will contain client’s private IP address (2.2.2.2) which is not reachable

4. The RTP/RTCP packets from the client to the server will be received with source IP address equal to the client’s public IP address (1.1.1.2)

5. If <enable-rtp-symetric /> option is used then, the server will send RTP/RTCP packets to1.1.1.2 (learnt from the received packets) instead of2.2.2.2 which is private.

 

 

<enable-100rel>

Format: enable-100rel-value

enable-100rel-value: yes|no

Indicates whether to enable SIP 100rel extension.

 

<enable-media-coder />

Format: enable-media-coder-value

enable-media-coder-value: yes|no

Indicates whether to enable the Media Coder module or not. This option requires the RTCWeb Breaker to be enabled at the web browser level. When the Media Coder is enabled the gateway acts as a b2bua and both audio and video streams are transcoded if the remote peers don’t share same codecs.

 

<enable-videojb />

Format: enable-videojb-value

enable-videojb-value : yes | no

This option is only useful if the RTCWeb Breaker module is enabled at the web browser side. Enabling video jitter buffer gives better quality and improve smoothness. No RTCP-NACK messages will be sent to request dropped RTP packets if this option is disabled.

 

<video-size-pref />

Format: video-size-pref-value

video-size-pref-value: sqcif | qcif | qvga | cif | hvga | vga | 4cif | svga | 480p | 720p | 16cif | 1080p

Available since: 2.1.0

This option defines the preferred video size to negotiate with the peers. There is no guarantee that the exact size will be used:video size to use = Min (Preferred, Proposed);

 

<rtp-buffsize />

Format: rtp-buffsize-value

rtp-buffsize-value: Any positive 32 bits integer value. Recommended: 65535.

Code usage:

setsockopt(SOL_SOCKET, SO_RCVBUF, rtp-buffsize-value);

setsockopt(SOL_SOCKET, SO_SNDBUF, rtp-buffsize-value);

Defines the internal buffer size to use for RTP sockets. The higher this value is, the lower will be the RTP packet loss. Please note that the maximum value depends on your system (e.g. 65535 on Windows). A very high value could introduce delay on video stream and it’s highly recommended to also enable videojb option.

 

<avpf-tail-length />

Format: avpf-tail-length-min;avpf-tail-length-max

avpf-tail-length-min: Any positive 32 bits integer

avpf-tail-length-max: Any positive 32 bits integer

Defines the minimum and maximum tail length used to honor RTCP-NACK requests. This option require the Media Breaker module to be enabled on the web browser size. The higher this value is, the better will be the video quality. The default length will be equal to the minimum value and it’s up to the server to increase this value depending on the number of unrecoverable packet loss. The final value will be at most equal to the maximum defined in the xml file. Unrecoverable packet loss occurs when the b2bua receives an RTCP-NACK for a sequence number already removed (very common when network RTT is very high or bandwidth very low).

 

<srtp-mode />

Format: srtp-mode-value

srtp-mode-value: none | optional | mandatory

Defines the SRTP mode to use for negotiation when the RTCWeb Breaker is enabled. Please note that onlyoptional andmandatory modes will work when the call is to a WebRTC endpoint.

Based on the mode, the SDP for the outgoing INVITEs will be formed like this:

none: profile = RTP/AVP ||| neither crypto lines or certificate fingerprints

optional: profile = RTP/AVP ||| two crypto lines if<srtp-type /> includes ‘SDES’ plus certificate fingerprints if<srtp-type /> include ‘DTLS’.

mandatory: profile = RTP/SAVP if<srtp-type /> is equal to ‘SDES’ orUDP/TLS/RTP/SAVP if <srtp-type /> is equal to ‘DTLS’ ||| two crypto lines if <srtp-type /> is eaqual to ‘SDES’ or certificate fingerprints if <srtp-type /> is equal to ‘DTLS’

 

<srtp-type />

Format: srtp-type-value; (srtp-type-value)*

srtp-type-value: sdes | dtls

Available since: 2.1.0

Defines the list of all supported SRTP types. Defining multiple values only make sense if the<srtp-mode /> value isoptional which means we want to negotiate the best one.

Please note that DTLS-SRTP requires valid TLS certificates and source code must be compiled with OpenSSL version 1.0.1 or later.

 

<dtmf-type />

Format: dtmf-type-value

dtmf-type-value: rfc4733 | rfc2833

Available since: 2.4.0

Defines the DTMF type to use when relaying the digits. Requires the RTCWeb Breaker to be enabled.rfc4733 will sends the DTMF digits using RTP packets whilerfc2833 uses SIP INFO.

 

<codecs />

Format: codec-name (; codec-name)*

codec-name: opus|pcma|pcmu|amr-nb-be|amr-nb-oa|speex-nb|speex-wb|speex-uwb|g729|gsm|g722|ilbc|h264-bp|h264-mp|vp8|h263|h263+|theora|mp4v-es

Defines the list of all supported codecs. Only G.711 and G.722 are natively supported and all other codecs have to be enabled when building the Doubango IMS Framework source code.

Each codec priority is equal to its position in the list. First codecs have highest priority.

 

<stun-server />

Format: server-fqdn-value; server-port-value; user-name-value;user-password-value

server-fqdn-value: A valid IPv4/v6 address or host name.

server-port: A valid port number.

user-name-value: The login to use for TURN authentication. Use star (*) to ignore.

user-password-value: The password to use for TURN authenetication. Use star (*) to ignore.

Defines the STUN/TURN server to use to gather reflexive addresses for the ICE candidates. If no server is defined then, a default one will be used. The default STUN server is numb.viagenie.ca:3478.

 

<enable-icestun />

Format: enable-icestun-value

enable-ice-stun-value: yes | no

Defines whether to use STUN to gather reflexive addresses or not. This option is useful when the server is on a public network or all peers are on the same local network. Disabling STUN for ICE will speed up the call setup.

 

<codec-opus-maxrates />

Format: maxrate-playback-value; maxrate-capture-value

maxrate-playback-value: 8000|12000|16000|24000|48000

maxrate-capture-value: 8000|12000|16000|24000|48000

Defines the maximum playback and capture rates to negotiate. The final rates to use will be min(offer, answer). Default value = 48000 for both.

The higher this value is, the better will be the voice quality. The bandwidth usage is proportional to the value. In short: high value = high bandwidth usage = good voice quality.

 

max-fds

Format: max-fds-value

Available since: 2.6.0

max-fds-value: Any integer value from 1 to 65535.

Defines the number of file descrriptors (FDs) the process is allowed to open. The FDs include the pipes and sockets only.

Setting this value is like running ulimit –n max-fds-value on Linux.

 

<nameserver />

Format: nameserver-value

nameserver-value: Any IPv4 or IPv6 address.

Defines additional entries for DNS servers to use for SRV and NAPTR queries. Please note that this option is optional and should be used carefully.

On Windows and OS X the server will automatically load these values using APIs provided by the OS. On linux, the values come from /etc/resolv.conf. The port must not be defined and the gateway will always use 53.

 

<ssl-certificates />

Format: private-key-value;public-key-value;cacert-key-value;verify-value

private-key-value: A valid path to a PEM file.

public-key-value: A valid path to a PEM file.

cacert-key-value: A valid path to a certificate autority file. Should be equal to *.

Verify-value: Yes | No. This additional option is only available since version 2.1.0. It indicates whether the connection should fail if the remote peer certificates are missing or do not match.This option only applies to TLS/SIP or WSS and is useless for DTLS-SRTP as certificates are required.

Code usage:

SSL_CTX_use_PrivateKey_file(ssl_ctx, private-key-value, SSL_FILETYPE_PEM);

SSL_CTX_use_certificate_file(ssl_ctx, public-key-value, SSL_FILETYPE_PEM);

SSL_CTX_load_verify_locations(ssl_ctx, cacert-key-value, CaPath);

 

<database />

Format: db-type-value;db-connection-info-value

Available since: 2.3.0

db-type-value: sqlite | mysql. For now only “sqlite” is supported.

db-connection-info-value: A valid path to the database file if an embeded db is used (e.g. sqlite), otherwise it’s an escaped connection string. Use star (*) to let the server use a default value.

 

For now this configuration entry is only used for the click-to-call service.

 

<account-mail />

Format: scheme-value;local-ip-value;local-port-value;smtp-host-value;smtp-port-value;email-value;auth-name-value;auth-pwd-value

Available since: 2.3.0

scheme-value: smtp | smtps

local-ip-value: A valid local host name or IP address to be used by the SMTP client. Use star (*) to let the server use the best value.

local-port-value: A valid local port number to be used by the SMTP client. Use star (*) to let the server use a random value.

smtp-host-value: A valid host name or IP address of the SMTP server.

smtp-port-value: A valid port of the SMTP server.

email-value: Email address used as sender.

auth-name-value: Authorization name used to authenticate to the SMTP server. Most probably same value as your email address (email-value).

auth-pwd-value: Password used to authenticate to the SMTP server.

 

The email account is used to send activation mails to the newly registed users.

 

<account-sip-caller />

Format: displayname-value;impu-value;impi-value;realm-value;password-value

Available since: 2.3.0

displayname-value: SIP account display name. Optional.

impu-value: Public Identity. Must be a valid SIP address (e.g. sip:003@example.org).

impi-value: Private Identity (a.k.a authorization name) for authentication. Most probably the user part of the Public Identity (e.g. 003).

realm-value: SIP domain name (e.g. example.org). Should be same as the domain name in the Public Identity.

password-value: SIP authentication password.

 

The SIP account callers are used to make calls to users by the click-to-call service. The callers in the config.xml file are globals (shared by all users) and are override when a user define one using the JSON API.


四、WebRTC2SIP常见错误

问:Sipml5能够通过WebRTC2SIP注册到SIP网关,但是Invite指令发送不出去?

答:未安装穿透服务器。安装网址:http://blog.csdn.net/zhenzhen2014/article/details/45871397


问:Sipml5报setLocationDescriptionError和setRemoteDesciptionError?

答:WebRTC3SIP的配重文件未配置<ssl-certificates>c:\SSL_priv,pem;c:\SSL_pub.pem;SSL_CA.pem;no,</ssl-certificates>

这三个证书在源码里面找到后放在服务器指定的路径下即可


问:Sipml5连接服务失败,可能的原因及解决方案有那些?
答:根本原因是没有连接上webrtc2sip或FreeSwitch的服务。
可能原因1:网络中断。解决方法:恢复网络连接。
可能原因2:Linux的防火墙阻止了webrtc2sip和FreeSwitch的服务,关闭防火强可以解决此类问题。


问:Sipml5连接无反应,可能的原因及解决方案有那些?
答:可能的原因是webrtc2sip有问题了,重新启动webrtc2sip。


问:Simpl5与Yealink可视电话进行语音通话成功,但是视频通话呼叫方语音进入echo模式,视频不通,可能的原因及解决方案有那些?
答:可能是webrtc2sip的配置中<enable-media-coder>no</enable-media-coder>应该改成yes。


问:webrtc2sip启动自动退出,可能的原因及解决方案有那些?
答:可能是配置中所设置的本地IP地址与服务器的IP地址不一致造成的。修改IP地址可以解决此问题。


问:Chrome浏览器,呼叫时出现“Media stream permission denied”如何解决。
答:
可能原因1:使用本地网页访问时容易出现这样的问题。请使用网址访问网站上的网页。
可能原因2:如果是询问时禁止访问了麦克风和摄像头,请关闭Chrome浏览器,重新启动Chrome浏览器。
如果是chrome for Android,到应用管理里,清除所有数据,可以解决。


问:Chrome浏览器主叫,被叫方隔很长时间才振铃,如何解决。
答:
很有肯能是webrtc2sip所在的服务器,设置了DNS所致,删除DNS就可以解决。

阅读全文
0 1
原创粉丝点击