PJSUA-API Media Manipulation 媒体操作api
2015-04-01 12:50
253 查看
PJSUA-API Media Manipulation
[PJSUA API - High Level Softphone API]
Media manipulation. More...
Detailed Description
PJSUA has rather powerful media features, which are built around the PJMEDIA conference bridge. Basically, all media "ports" (such as calls, W*** players, W*** playlist, file recorders, sound device, tone generators, etc) are terminated in the conference bridge,and application can manipulate the interconnection between these terminations freely.
PJSUA具备丰富的媒体特征,这都建立在 PJMESIA 会议桥基础上,基本上所有的"端口"(例如呼叫,wav播放,wav播放列表,文件录音,声音设备,双音频产生等等)都挂接在会议桥上,应用程序就可以自由操作互联这些挂接
The conference bridge provides powerful switching and mixing functionality for application. With the conference bridge, each conference slot (e.g. a call) can transmit to multiple destinations, and one destination can receive from multiple sources. If more
than one media terminations are terminated in the same slot, the conference bridge will mix the signal automatically.
会议桥提供丰富的交换和混音功能,利用会议桥,每个会议槽(例如一个呼叫)可以传输到多个目的路由,并且一个目的路由可以接收多个源路由。如果不止一个媒体流端口挂接到相同的会议槽上,那么会议桥将会自动将其混音
Application connects one media termination/slot to another by calling pjsua_conf_connect() function.
This will establish unidirectional media flow from the source termination to the sink termination. To establish bidirectional media flow, application wound need to make another call to pjsua_conf_connect(),
this time inverting the source and destination slots in the parameter.
应用程序使用pjsua_conf_connect()函数将媒体端口挂接的会议槽与其它会议槽相连接,这将建立从源端口挂接会议槽到接收槽的单向媒体流。如果需要建立双向媒体流则需要同时在调用一次pjsua_conf_connect()函数,但参数中的源和目的槽需要反向
For example, to stream a W*** file to remote call, application may use the following steps:
例如播放一个wav声音文件给一个呼叫,需要下面步骤:
<a target=_blank class="codeRef" href="http://www.pjsip.org/pjlib/docs/html/group__PJ__BASIC.htm#gab43ba3167bd2a2ab4580509dbf79200e" style="color: rgb(51, 102, 153); text-decoration: none;">pj_status_t</a> stream_to_call( <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__BASE.htm#gad4eb99a78c98ddbd83aecf7e933fc684" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_call_id</a> call_id ) { <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__BASE.htm#ga266a56483961431df7a5ebae457b9f3f" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_player_id</a> player_id; status = <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__MEDIA.htm#ga90a2ec9c8516b5ad13b061a46ae1d07a" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_player_create</a>(<span class="stringliteral">"mysong.wav"</span>, 0, NULL, &player_id); <span class="keywordflow">if</span> (status != PJ_SUCCESS) <span class="keywordflow">return</span> status; status = <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__MEDIA.htm#ga3451304d677e013130dfb9e6b37e3ee6" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_conf_connect</a>( <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__MEDIA.htm#ga4b7a4ad09c9edad41ae516cea468819c" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_player_get_conf_port</a>(), <a target=_blank class="code" href="http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__CALL.htm#ga90c100b6e00d146ba824145fe6861aef" style="color: rgb(51, 102, 153); text-decoration: none;">pjsua_call_get_conf_port</a>() ); }
Other features of PJSUA media: 其它特性
efficient N to M interconnections between media terminations. 媒体端口会议槽上的高效连接
media termination can be connected to itself to create loopback media. 通过环回媒体可以连接自己
the media termination may have different clock rates, and resampling will be done automatically by conference bridge. 媒体可能有不同的时钟速率,会议桥可以自动重采样
media terminations may also have different frame time; the conference bridge will perform the necessary bufferring to adjust the difference between terminations. 媒体可能有不同的帧时间,会议桥可以进行必要的缓冲来调整不同的帧时间
interconnections are removed automatically when media termination is removed from the bridge.媒体端口从桥中移除的时候,连接会自动移除
sound device may be changed even when there are active media interconnections. 即使有激活的媒体桥接,声音设备也可以改变
correctly report call's media quality (in pjsua_call_dump())
from RTCP packet exchange.用pjsua_call_dump来输出RTCP包交换的媒体质量的报表
Define Documentation
#define PJSUA_MAX_CONF_PORTS 254 |
会议桥的最大端口数
#define PJSUA_DEFAULT_CLOCK_RATE 16000 |
会议桥缺省的时钟速率
#define PJSUA_DEFAULT_AUDIO_FRAME_PTIME 20 |
会议桥缺省的帧长度
#define PJSUA_DEFAULT_CODEC_QUALITY 8 |
缺省编码质量设定
#define PJSUA_DEFAULT_ILBC_MODE 30 |
缺省的iLBC编码模式
#define PJSUA_DEFAULT_EC_TAIL_LEN 200 |
缺省的回音消除尾长
#define PJSUA_MAX_PLAYERS 32 |
#define PJSUA_MAX_RECORDERS 32 |
Function Documentation
void pjsua_media_config_default | ( | pjsua_media_config * | cfg | ) |
Parameters:
cfg | The media config to be initialized. |
unsigned pjsua_conf_get_max_ports | ( | void | ) |
Returns:Maximum number of ports in the conference bridge.
unsigned pjsua_conf_get_active_ports | ( | void | ) |
Returns:The number.
pj_status_t pjsua_enum_conf_ports | ( | pjsua_conf_port_id | id[], | |
unsigned * | count | |||
) |
Parameters:
id | Array of conference port ID to be initialized. | |
count | On input, specifies max elements in the array. On return, it contains actual number of elements that have been initialized. |
pj_status_t pjsua_conf_get_port_info | ( | pjsua_conf_port_id | port_id, | |
pjsua_conf_port_info * | info | |||
) |
Parameters:
port_id | Port identification. | |
info | Pointer to store the port info. |
pj_status_t pjsua_conf_add_port | ( | pj_pool_t * | pool, | |
pjmedia_port * | port, | |||
pjsua_conf_port_id * | p_id | |||
) |
the port to the bridge.
增加任意媒体端口到会议桥,应用程序可以使用该函数增加已经创建的媒体端口,创建端口使用PJSUA-LIB(例如呼叫,媒体播放,媒体录音等),PJSUA-LIB自动增加端口到桥
Parameters:
pool | Pool to use. | |
port | Media port to be added to the bridge. | |
p_id | Optional pointer to receive the conference slot id. |
pj_status_t pjsua_conf_remove_port | ( | pjsua_conf_port_id | port_id | ) |
从会议桥删除任意会议槽,该函数仅在使用pjsua_conf_add_port()手动添加端口时使用
Parameters:
port_id | The slot id of the port to be removed. |
pj_status_t pjsua_conf_connect | ( | pjsua_conf_port_id | source, | |
pjsua_conf_port_id | sink | |||
) |
looping the media.
If bidirectional media flow is desired, application needs to call this function twice, with the second one having the arguments reversed.
建立从源端口到接收端口单向的媒体流,一个源端口可以传输到多个目的(接收)端口。多个源端口也可以传输到相同的接收端口,此时将产生混音,源端口和接收端口相同则为环回媒体效果
双向媒体流的建立,需要再次调用该函数,并将源端口和目的端口反向
Parameters:
source | Port ID of the source media/transmitter. | |
sink | Port ID of the destination media/received. |
pj_status_t pjsua_conf_disconnect | ( | pjsua_conf_port_id | source, | |
pjsua_conf_port_id | sink | |||
) |
中断媒体流
Parameters:
source | Port ID of the source media/transmitter. | |
sink | Port ID of the destination media/received. |
pj_status_t pjsua_conf_adjust_tx_level | ( | pjsua_conf_port_id | slot, | |
float | level | |||
) |
调发送端信号能量级别,使其增大或减小音量
Parameters:
slot | The conference bridge slot number. | |
level | Signal level adjustment. Value 1.0 means no level adjustment, while value 0 means to mute the port. |
pj_status_t pjsua_conf_adjust_rx_level | ( | pjsua_conf_port_id | slot, | |
float | level | |||
) |
调节接收端信号能量级别,使其增大或减小音量
Parameters:
slot | The conference bridge slot number. | |
level | Signal level adjustment. Value 1.0 means no level adjustment, while value 0 means to mute the port. |
pj_status_t pjsua_conf_get_signal_level | ( | pjsua_conf_port_id | slot, | |
unsigned * | tx_level, | |||
unsigned * | rx_level | |||
) |
获得发送端或接收端信号能量级别,信号量是从0-255的整形,0为静音,255为最大音量
Parameters:
slot | The conference bridge slot number. | |
tx_level | Optional argument to receive the level of signal transmitted to the specified port (i.e. the direction is from the bridge to the port). | |
rx_level | Optional argument to receive the level of signal received from the port (i.e. the direction is from the port to the bridge). |
pj_status_t pjsua_player_create | ( | const pj_str_t * | filename, | |
unsigned | options, | |||
pjsua_player_id * | p_id | |||
) |
创建媒体播放,自动添加到会议桥
Parameters:
filename | The filename to be played. Currently only W*** files are supported, and the W*** file MUST be formatted as 16bit PCM mono/single channel (any clock rate is supported). 播放的声音文件,当前仅支持wav格式,而且必须是16bit的PCM格式,单声道,任何时钟速度都可以 | |
options | Optional option flag. Application may specify PJMEDIA_FILE_NO_LOOP to prevent playback loop. 可选项,可用于防止循环播放 | |
p_id | Pointer to receive player ID. |
pj_status_t pjsua_playlist_create | ( | const pj_str_t | file_names[], | |
unsigned | file_count, | |||
const pj_str_t * | label, | |||
unsigned | options, | |||
pjsua_player_id * | p_id | |||
) |
创建媒体播放列表端口,自动添加到会议桥
Parameters:
file_names | Array of file names to be added to the play list. Note that the files must have the same clock rate, number of channels, and number of bits per sample. 播放文件列表名称的数组,所有文件必须相同的时钟速率,声道数和比特率,采样数等 | |
file_count | Number of files in the array. 文件数量 | |
label | Optional label to be set for the media port. | |
options | Optional option flag. Application may specify PJMEDIA_FILE_NO_LOOP to prevent looping. | |
p_id | Optional pointer to receive player ID. |
pjsua_conf_port_id pjsua_player_get_conf_port | ( | pjsua_player_id | id | ) |
获得分配给播放(列表或单个文件)的会议桥端口id
Parameters:
id | The file player ID. |
pj_status_t pjsua_player_get_port | ( | pjsua_player_id | id, | |
pjmedia_port ** | p_port | |||
) |
Parameters:
id | The player ID. | |
p_port | The media port associated with the player. |
pj_status_t pjsua_player_set_pos | ( | pjsua_player_id | id, | |
pj_uint32_t | samples | |||
) |
Parameters:
id | The file player ID. | |
samples | The playback position, in samples. Application can specify zero to re-start the playback. |
pj_status_t pjsua_player_destroy | ( | pjsua_player_id | id | ) |
Parameters:
id | The file player ID. |
pj_status_t pjsua_recorder_create | ( | const pj_str_t * | filename, | |
unsigned | enc_type, | |||
void * | enc_param, | |||
pj_ssize_t | max_size, | |||
unsigned | options, | |||
pjsua_recorder_id * | p_id | |||
) |
创建一个录音文件。自动连接该录音到会议桥,录音当前支持wav格式,录音类型用于检测文件扩展名
Parameters:
filename | Output file name. The function will determine the default format to be used based on the file extension. Currently ".wav" is supported on all platforms. 输出文件名,函数会检测默认格式用于文件扩展名,.wav支持所有平台 | |
enc_type | Optionally specify the type of encoder to be used to compress the media, if the file can support different encodings. This value must be zero for now. 可选的,如果文件支持不同编码,指定用于压缩媒体的编码格式。该值设置为0 | |
enc_param | Optionally specify codec specific parameter to be passed to the file writer. For .W*** recorder, this value must be NULL. | |
max_size | Maximum file size. Specify zero or -1 to remove size limitation. This value must be zero or -1 for now. 文件大小,0或者-1不限制 | |
options | Optional options. | |
p_id | Pointer to receive the recorder instance. |
pjsua_conf_port_id pjsua_recorder_get_conf_port | ( | pjsua_recorder_id | id | ) |
获得分配到录音的会议端口id
Parameters:
id | The recorder ID. |
pj_status_t pjsua_recorder_get_port | ( | pjsua_recorder_id | id, | |
pjmedia_port ** | p_port | |||
) |
获得录音的媒体端口
Parameters:
id | The recorder ID. | |
p_port | The media port associated with the recorder. |
pj_status_t pjsua_recorder_destroy | ( | pjsua_recorder_id | id | ) |
销毁录音(将完成录音)
Parameters:
id | The recorder ID. |
pj_status_t pjsua_enum_aud_devs | ( | pjmedia_aud_dev_info | info[], | |
unsigned * | count | |||
) |
枚举所有安装在系统的音频设备
Parameters:
info | Array of info to be initialized. | |
count | On input, specifies max elements in the array. On return, it contains actual number of elements that have been initialized. |
pj_status_t pjsua_enum_snd_devs | ( | pjmedia_snd_dev_info | info[], | |
unsigned * | count | |||
) |
枚举所有声音设备(老api)
Parameters:
info | Array of info to be initialized. | |
count | On input, specifies max elements in the array. On return, it contains actual number of elements that have been initialized. |
pj_status_t pjsua_get_snd_dev | ( | int * | capture_dev, | |
int * | playback_dev | |||
) |
not called), it is possible that the function returns PJ_SUCCESS with -1 as device IDs.
获得当前激活的声音设备,如果声音设备没有被创建(例如当pjsua_start()没有调用之前),函数可能会返回PJ_SUCCESS和设备id为-1
Parameters:
capture_dev | On return it will be filled with device ID of the capture device. | |
playback_dev | On return it will be filled with device ID of the device ID of the playback device. |
pj_status_t pjsua_set_snd_dev | ( | int | capture_dev, | |
int | playback_dev | |||
) |
选择或改变声音设备,应用程序可以在任何时候调用该函数改变当前声音设备
Parameters:
capture_dev | Device ID of the capture device. | |
playback_dev | Device ID of the playback device. |
pj_status_t pjsua_set_null_snd_dev | ( | void | ) |
设置为不用声音设备,用于为会议桥提供时钟,从而不启用硬件
Returns:PJ_SUCCESS on success, or the appropriate error code.
pjmedia_port* pjsua_set_no_snd_dev | ( | void | ) |
将主会议桥与声音设备断掉,让程序用自己的声音设备和主端口连接会议桥
Returns:The port interface of the conference bridge, so that application can connect this to it's own sound device or master port.
pj_status_t pjsua_set_ec | ( | unsigned | tail_ms, | |
unsigned | options | |||
) |
The behavior of this function depends on whether the sound device is currently active, and if it is, whether device or software AEC is being used.
If the sound device is currently active, and if the device supports AEC, this function will forward the change request to the device and it will be up to the device on whether support the request. If software AEC is being used (the software EC will be used
if the device does not support AEC), this function will change the software EC settings. In all cases, the setting will be saved for future opening of the sound device.
If the sound device is not currently active, this will only change the default AEC settings and the setting will be applied next time the sound device is opened.
改变回音消除设置
函数的该行为依赖于声音设备当前是否激活,如果激活,设备或软件的声音回音消除将被使用。
如果声音设备当前激活,并且设备支持回音消除,函数将会传递修改请求给硬件,并且在支持回音消除的设备上生效。如果使用软件回音消除(硬件不支持回音消除的时候,软件回音消除才使用),该函数将修改软件回音消除设置。2种方法中,设置都会保存以便下次使用设置打开声音设备。
如果当前设备没有激活,将会修改默认的回音消除设置,在下次设备打开时应用。
Parameters:
tail_ms | The tail length, in miliseconds. Set to zero to disable AEC. | |
options | Options to be passed to pjmedia_echo_create(). Normally the value should be zero. |
pj_status_t pjsua_get_ec_tail | ( | unsigned * | p_tail_ms | ) |
Parameters:
p_tail_ms | Pointer to receive the tail length, in miliseconds. If AEC is disabled, the value will be zero. |
pj_bool_t pjsua_snd_is_active | ( | void | ) |
or if null sound device or no sound device has been configured via the pjsua_set_no_snd_dev() function.
检查声音设备是否激活,如果程序设置了自动关闭特征为0(在pjsua_media_config中的snd_auto_close_time)那么声音设备或许不会激活,亦或没有声音设备,或者通过pjsua_set_no_snd_dev()函数配置没有声音设备
pj_status_t pjsua_snd_set_setting | ( | pjmedia_aud_dev_cap | cap, | |
const void * | pval, | |||
pj_bool_t | keep | |||
) |
The setting will be saved for future opening of the sound device, if the "keep" argument is set to non-zero. If the sound device is currently inactive, and the "keep" argument is false, this function will return error.
Note that in case the setting is kept for future use, it will be applied to any devices, even when application has changed the sound device to be used.
Note also that the echo cancellation setting should be set with pjsua_set_ec() API
instead.
See also pjmedia_aud_stream_set_cap() for more
information about setting an audio device capability.
Parameters:
cap | The sound device setting to change. | |
pval | Pointer to value. Please see pjmedia_aud_dev_cap documentation about the type of value to be supplied for each setting. | |
keep | Specify whether the setting is to be kept for future use. |
pj_status_t pjsua_snd_get_setting | ( | pjmedia_aud_dev_cap | cap, | |
void * | pval | |||
) |
setting will be returned. Otherwise, this function will return error.
Note that echo cancellation settings should be retrieved with pjsua_get_ec_tail() API
instead.
检索声音设备设置。
Parameters:
cap | The sound device setting to retrieve. | |
pval | Pointer to receive the value. Please see pjmedia_aud_dev_cap documentation about the type of value to be supplied for each setting. |
pj_status_t pjsua_enum_codecs | ( | pjsua_codec_info | id[], | |
unsigned * | count | |||
) |
枚举所有系统支持的编码格式
Parameters:
id | Array of ID to be initialized. | |
count | On input, specifies max elements in the array. On return, it contains actual number of elements that have been initialized. |
pj_status_t pjsua_codec_set_priority | ( | const pj_str_t * | codec_id, | |
pj_uint8_t | priority | |||
) |
改变编码优先级
Parameters:
codec_id | Codec ID, which is a string that uniquely identify the codec (such as "speex/8000"). Please see pjsua manual or pjmedia codec reference for details. | |
priority | Codec priority, 0-255, where zero means to disable the codec. |
pj_status_t pjsua_codec_get_param | ( | const pj_str_t * | codec_id, | |
pjmedia_codec_param * | param | |||
) |
获得编码参数
Parameters:
codec_id | Codec ID. | |
param | Structure to receive codec parameters. |
pj_status_t pjsua_codec_set_param | ( | const pj_str_t * | codec_id, | |
const pjmedia_codec_param * | param | |||
) |
设置编码参数
Parameters:
codec_id | Codec ID. | |
param | Codec parameter to set. Set to NULL to reset codec parameter to library default settings. |
pj_status_t pjsua_media_transports_create | ( | const pjsua_transport_config * | cfg | ) |
为所有呼叫创建UDP媒体传输。
Parameters:
cfg | Media transport configuration. The "port" field in the configuration is used as the start port to bind the sockets. |
pj_status_t pjsua_media_transports_attach | ( | pjsua_media_transport | tp[], | |
unsigned | count, | |||
pj_bool_t | auto_delete | |||
) |
注册自定义的呼叫媒体传输模式,呼叫必须有足够的传输模式
Parameters:
tp | The media transport array. | |
count | Number of elements in the array. This number MUST match the number of maximum calls configured when pjsua is created. | |
auto_delete | Flag to indicate whether the transports should be destroyed when pjsua is shutdown. |
相关文章推荐
- Android API Guide for Media Apps(四)—— 构建媒体浏览器服务(Building a Media Browser Service)
- Android API Guide for Media and Camera(四)—— 媒体与相机(媒体路由)
- Android API Guide for Media Apps(五)——构建媒体浏览客户端(Building a Media Browser Client)
- PhoneGap API帮助文档翻译—Media(媒体)
- Android API Guide for Media Apps(二)——媒体会话的使用(Working with a Mession)
- Android API Guide for Media Apps(六)——媒体会话的回调(Media Session Callbacks)
- 媒体和相机:媒体路由器:Media Route Provider API
- PhoneGap API帮助文档翻译—Media(媒体)
- PJSUA2开发文档--第十章 媒体质量(MEDIA QUALITY)
- PhoneGap API中文帮助文档——Media(媒体)
- Android API Guide for Media Apps(九)——媒体会话的回调(Media Session Callbacks)
- Android API Guide for Media and Camera(五)—— 媒体与相机(Camera API)
- Android API Guide for Media and Camera(一)—— 媒体与相机(媒体播放器)
- Android API Guide for Media and Camera(二)—— 媒体与相机(媒体记录器)
- Android API Guide for Media and Camera(三)—— 媒体与相机(ExoPlayer)
- 媒体和相机:媒体路由器:MediaRouter API
- Android API Guide for Media Apps —— 媒体应用
- Android 操作串口 (android serial port api)
- Javascript操作DOM常用API总结
- AxWindowsMediaPlayer媒体文件主要方法属性