Added options to disable microphone device, usefull for streaming server (some systems only have sound player)
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@312 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
51f5bd5bc9
commit
8e3344c41d
|
@ -40,29 +40,68 @@ typedef struct pjmedia_conf pjmedia_conf;
|
|||
*/
|
||||
typedef struct pjmedia_conf_port_info
|
||||
{
|
||||
unsigned slot;
|
||||
pj_str_t name;
|
||||
pjmedia_port_op tx_setting;
|
||||
pjmedia_port_op rx_setting;
|
||||
pj_bool_t *listener;
|
||||
unsigned clock_rate;
|
||||
unsigned samples_per_frame;
|
||||
unsigned slot; /**< Slot number. */
|
||||
pj_str_t name; /**< Port name. */
|
||||
pjmedia_port_op tx_setting; /**< Transmit settings. */
|
||||
pjmedia_port_op rx_setting; /**< Receive settings. */
|
||||
pj_bool_t *listener; /**< Array of listeners. */
|
||||
unsigned clock_rate; /**< Clock rate of the port. */
|
||||
unsigned samples_per_frame; /**< Samples per frame */
|
||||
} pjmedia_conf_port_info;
|
||||
|
||||
|
||||
/**
|
||||
* Create conference bridge.
|
||||
* Conference port options. The values here can be combined in bitmask to
|
||||
* be specified when the conference bridge is created.
|
||||
*/
|
||||
enum pjmedia_conf_option
|
||||
{
|
||||
PJMEDIA_CONF_NO_MIC = 1, /**< Disable audio streams from the
|
||||
microphone device. */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create conference bridge. This normally will also create instances of
|
||||
* sound device to be attached to the port zero of the bridge.
|
||||
*
|
||||
* @param pool Pool to use to allocate the bridge and
|
||||
* additional buffers for the sound device.
|
||||
* @param max_slots Maximum number of slots/ports to be created in
|
||||
* the bridge. Note that the bridge internally uses
|
||||
* one port for the sound device, so the actual
|
||||
* maximum number of ports will be less one than
|
||||
* this value.
|
||||
* @param sampling_rate Set the sampling rate of the bridge. This value
|
||||
* is also used to set the sampling rate of the
|
||||
* sound device.
|
||||
* @param samples_per_frame Set the number of samples per frame. This value
|
||||
* is also used to set the sound device.
|
||||
* @param bits_per_sample Set the number of bits per sample. This value
|
||||
* is also used to set the sound device. Currently
|
||||
* only 16bit per sample is supported.
|
||||
* @param options Bitmask options to be set for the bridge. The
|
||||
* options are constructed from #pjmedia_conf_option
|
||||
* enumeration.
|
||||
* @param p_conf Pointer to receive the conference bridge instance.
|
||||
*
|
||||
* @return PJ_SUCCESS if conference bridge can be created.
|
||||
*/
|
||||
PJ_DECL(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
|
||||
unsigned max_slots,
|
||||
unsigned sampling_rate,
|
||||
unsigned samples_per_frame,
|
||||
unsigned bits_per_sample,
|
||||
unsigned options,
|
||||
pjmedia_conf **p_conf );
|
||||
|
||||
|
||||
/**
|
||||
* Destroy conference bridge.
|
||||
*
|
||||
* @param conf The conference bridge.
|
||||
*
|
||||
* @return PJ_SUCCESS on success.
|
||||
*/
|
||||
PJ_DECL(pj_status_t) pjmedia_conf_destroy( pjmedia_conf *conf );
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ struct conf_port
|
|||
*/
|
||||
struct pjmedia_conf
|
||||
{
|
||||
unsigned options; /**< Bitmask options. */
|
||||
unsigned max_ports; /**< Maximum ports. */
|
||||
unsigned port_cnt; /**< Current number of ports. */
|
||||
unsigned connect_cnt; /**< Total number of connections */
|
||||
|
@ -333,6 +334,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
|
|||
unsigned clock_rate,
|
||||
unsigned samples_per_frame,
|
||||
unsigned bits_per_sample,
|
||||
unsigned options,
|
||||
pjmedia_conf **p_conf )
|
||||
{
|
||||
pjmedia_conf *conf;
|
||||
|
@ -351,6 +353,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
|
|||
conf->ports = pj_pool_zalloc(pool, max_ports*sizeof(void*));
|
||||
PJ_ASSERT_RETURN(conf->ports, PJ_ENOMEM);
|
||||
|
||||
conf->options = options;
|
||||
conf->max_ports = max_ports;
|
||||
conf->clock_rate = clock_rate;
|
||||
conf->samples_per_frame = samples_per_frame;
|
||||
|
@ -385,16 +388,21 @@ PJ_DEF(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
|
|||
*/
|
||||
static pj_status_t create_sound( pjmedia_conf *conf )
|
||||
{
|
||||
/* Open recorder. */
|
||||
conf->snd_rec = pj_snd_open_recorder(-1 ,&conf->snd_info, &rec_cb, conf);
|
||||
if (conf->snd_rec == NULL) {
|
||||
return -1;
|
||||
/* Open recorder only if mic is not disabled. */
|
||||
if ((conf->options & PJMEDIA_CONF_NO_MIC) == 0) {
|
||||
conf->snd_rec = pj_snd_open_recorder(-1 ,&conf->snd_info,
|
||||
&rec_cb, conf);
|
||||
if (conf->snd_rec == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open player */
|
||||
conf->snd_player = pj_snd_open_player(-1, &conf->snd_info, &play_cb, conf);
|
||||
if (conf->snd_player == NULL) {
|
||||
pj_snd_stream_close(conf->snd_rec);
|
||||
if (conf->snd_rec) {
|
||||
pj_snd_stream_close(conf->snd_rec);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -425,7 +433,7 @@ static pj_status_t resume_sound( pjmedia_conf *conf )
|
|||
char errmsg[PJ_ERR_MSG_SIZE];
|
||||
pj_status_t status;
|
||||
|
||||
if (conf->snd_rec == NULL) {
|
||||
if (conf->snd_player == NULL) {
|
||||
status = create_sound(conf);
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
|
|
@ -182,6 +182,7 @@ struct pjsua
|
|||
unsigned clock_rate; /**< Internal clock rate. */
|
||||
pjmedia_conf *mconf; /**< Media conference. */
|
||||
pj_bool_t null_audio; /**< Null audio flag. */
|
||||
pj_bool_t no_mic; /**< Disable microphone. */
|
||||
char *wav_file; /**< WAV file name to play. */
|
||||
unsigned wav_slot; /**< WAV player slot in bridge */
|
||||
pj_bool_t auto_play; /**< Auto play file for calls? */
|
||||
|
|
|
@ -611,7 +611,7 @@ int pjsua_find_account_for_outgoing(const pj_str_t *url)
|
|||
*/
|
||||
static pj_status_t init_media(void)
|
||||
{
|
||||
|
||||
unsigned options;
|
||||
pj_status_t status;
|
||||
|
||||
/* If user doesn't specify any codecs, register all of them. */
|
||||
|
@ -732,12 +732,18 @@ static pj_status_t init_media(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Init options for conference bridge. */
|
||||
options = 0;
|
||||
if (pjsua.no_mic)
|
||||
options |= PJMEDIA_CONF_NO_MIC;
|
||||
|
||||
/* Init conference bridge. */
|
||||
|
||||
status = pjmedia_conf_create(pjsua.pool,
|
||||
pjsua.max_calls+PJSUA_CONF_MORE_PORTS,
|
||||
pjsua.clock_rate,
|
||||
pjsua.clock_rate * 20 / 1000, 16,
|
||||
options,
|
||||
&pjsua.mconf);
|
||||
if (status != PJ_SUCCESS) {
|
||||
pj_caching_pool_destroy(&pjsua.cp);
|
||||
|
|
|
@ -86,6 +86,7 @@ static void usage(void)
|
|||
puts (" --wb Enable wideband codecs and set clock-rate to 16KHz");
|
||||
puts (" --uwb Enable ultra-wideband codecs and set clock-rate to 32KHz");
|
||||
puts (" --null-audio Use NULL audio device");
|
||||
puts (" --no-mic Disable microphone device");
|
||||
puts (" --play-file=file Play WAV file in conference bridge");
|
||||
puts (" --auto-play Automatically play the file (to incoming calls only)");
|
||||
puts (" --auto-loop Automatically loop incoming RTP to outgoing RTP");
|
||||
|
@ -217,7 +218,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[])
|
|||
int c;
|
||||
int option_index;
|
||||
enum { OPT_CONFIG_FILE, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL,
|
||||
OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO,
|
||||
OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_NO_MIC,
|
||||
OPT_LOCAL_PORT, OPT_PROXY, OPT_OUTBOUND_PROXY, OPT_REGISTRAR,
|
||||
OPT_REG_TIMEOUT, OPT_ID, OPT_CONTACT,
|
||||
OPT_REALM, OPT_USERNAME, OPT_PASSWORD,
|
||||
|
@ -240,6 +241,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[])
|
|||
{ "wb", 0, 0, OPT_WB},
|
||||
{ "uwb", 0, 0, OPT_UWB},
|
||||
{ "null-audio", 0, 0, OPT_NULL_AUDIO},
|
||||
{ "no-mic", 0, 0, OPT_NO_MIC},
|
||||
{ "local-port", 1, 0, OPT_LOCAL_PORT},
|
||||
{ "proxy", 1, 0, OPT_PROXY},
|
||||
{ "outbound", 1, 0, OPT_OUTBOUND_PROXY},
|
||||
|
@ -343,6 +345,10 @@ pj_status_t pjsua_parse_args(int argc, char *argv[])
|
|||
pjsua.null_audio = 1;
|
||||
break;
|
||||
|
||||
case OPT_NO_MIC:
|
||||
pjsua.no_mic = 1;
|
||||
break;
|
||||
|
||||
case OPT_WB:
|
||||
pjsua.clock_rate = 16000;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue