summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-03-16 19:03:07 +0000
committerBenny Prijono <bennylp@teluu.com>2006-03-16 19:03:07 +0000
commit7e823acd1c44aa1f9f03d4a3de962c08c683d806 (patch)
treec1e2f3682b1d070e072c2ea734adc6a183d93c2a
parenta069e683724dba8caa58c8079b40999e21f64190 (diff)
Support for stereo audio (or N audio channels, for that matter)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@322 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/conference.h6
-rw-r--r--pjmedia/include/pjmedia/null_port.h2
-rw-r--r--pjmedia/src/pjmedia/conference.c12
-rw-r--r--pjmedia/src/pjmedia/file_port.c2
-rw-r--r--pjmedia/src/pjmedia/null_port.c2
-rw-r--r--pjmedia/src/pjmedia/stream.c1
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c2
7 files changed, 25 insertions, 2 deletions
diff --git a/pjmedia/include/pjmedia/conference.h b/pjmedia/include/pjmedia/conference.h
index d6500a14..f822260f 100644
--- a/pjmedia/include/pjmedia/conference.h
+++ b/pjmedia/include/pjmedia/conference.h
@@ -75,6 +75,11 @@ enum pjmedia_conf_option
* @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 channel_count Number of channels in the PCM stream. Normally
+ * the value will be 1 for mono, but application may
+ * specify a value of 2 for stereo. Note that all
+ * ports that will be connected to the bridge MUST
+ * have the same number of channels as the bridge.
* @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
@@ -90,6 +95,7 @@ enum pjmedia_conf_option
PJ_DECL(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
unsigned max_slots,
unsigned sampling_rate,
+ unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
unsigned options,
diff --git a/pjmedia/include/pjmedia/null_port.h b/pjmedia/include/pjmedia/null_port.h
index c4f7c071..36509181 100644
--- a/pjmedia/include/pjmedia/null_port.h
+++ b/pjmedia/include/pjmedia/null_port.h
@@ -33,6 +33,7 @@ PJ_BEGIN_DECL
* Create Null port.
*
* @param sampling_rate Sampling rate of the port.
+ * @param channel_count Number of channels.
* @param samples_per_frame Number of samples per frame.
* @param bits_per_sample Number of bits per sample.
* @param p_port Pointer to receive the port instance.
@@ -41,6 +42,7 @@ PJ_BEGIN_DECL
*/
PJ_DECL(pj_status_t) pjmedia_null_port_create( pj_pool_t *pool,
unsigned sampling_rate,
+ unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_port **p_port );
diff --git a/pjmedia/src/pjmedia/conference.c b/pjmedia/src/pjmedia/conference.c
index 4c4eba6f..ddeb837c 100644
--- a/pjmedia/src/pjmedia/conference.c
+++ b/pjmedia/src/pjmedia/conference.c
@@ -136,7 +136,8 @@ struct pjmedia_conf
pj_mutex_t *mutex; /**< Conference mutex. */
struct conf_port **ports; /**< Array of ports. */
pj_uint16_t *uns_buf; /**< Buf for unsigned conversion */
- unsigned clock_rate; /**< Sampling rate. */
+ unsigned clock_rate; /**< Sampling rate. */
+ unsigned channel_count;/**< Number of channels (1=mono). */
unsigned samples_per_frame; /**< Samples per frame. */
unsigned bits_per_sample; /**< Bits per sample. */
};
@@ -322,6 +323,7 @@ on_error:
PJ_DEF(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
unsigned max_ports,
unsigned clock_rate,
+ unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
unsigned options,
@@ -493,6 +495,14 @@ PJ_DEF(pj_status_t) pjmedia_conf_add_port( pjmedia_conf *conf,
PJ_ASSERT_RETURN(conf && pool && strm_port && port_name, PJ_EINVAL);
+ /* For this version of PJMEDIA, port MUST have the same number of
+ * PCM channels.
+ */
+ if (strm_port->info.channel_count != conf->channel_count) {
+ pj_assert(!"Number of channels mismatch");
+ return PJMEDIA_ENCCHANNEL;
+ }
+
pj_mutex_lock(conf->mutex);
if (conf->port_cnt >= conf->max_ports) {
diff --git a/pjmedia/src/pjmedia/file_port.c b/pjmedia/src/pjmedia/file_port.c
index 1d82d208..573637be 100644
--- a/pjmedia/src/pjmedia/file_port.c
+++ b/pjmedia/src/pjmedia/file_port.c
@@ -200,7 +200,6 @@ PJ_DEF(pj_status_t) pjmedia_file_player_port_create( pj_pool_t *pool,
}
if (wave_hdr.fmt_hdr.fmt_tag != 1 ||
- wave_hdr.fmt_hdr.nchan != 1 ||
wave_hdr.fmt_hdr.bits_per_sample != 16 ||
wave_hdr.fmt_hdr.block_align != 2)
{
@@ -224,6 +223,7 @@ PJ_DEF(pj_status_t) pjmedia_file_player_port_create( pj_pool_t *pool,
fport->base.user_data = user_data;
/* Update port info. */
+ fport->base.info.channel_count = wave_hdr.fmt_hdr.nchan;
fport->base.info.sample_rate = wave_hdr.fmt_hdr.sample_rate;
fport->base.info.bits_per_sample = wave_hdr.fmt_hdr.bits_per_sample;
fport->base.info.samples_per_frame = fport->base.info.sample_rate *
diff --git a/pjmedia/src/pjmedia/null_port.c b/pjmedia/src/pjmedia/null_port.c
index 55faaf4b..c97b606f 100644
--- a/pjmedia/src/pjmedia/null_port.c
+++ b/pjmedia/src/pjmedia/null_port.c
@@ -32,6 +32,7 @@ static pj_status_t null_on_destroy(pjmedia_port *this_port);
PJ_DEF(pj_status_t) pjmedia_null_port_create( pj_pool_t *pool,
unsigned sampling_rate,
+ unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_port **p_port )
@@ -52,6 +53,7 @@ PJ_DEF(pj_status_t) pjmedia_null_port_create( pj_pool_t *pool,
port->info.pt = 0xFF;
port->info.sample_rate = sampling_rate;
port->info.samples_per_frame = samples_per_frame;
+ port->info.channel_count = channel_count;
port->info.signature = 0x2411;
port->info.type = PJMEDIA_TYPE_AUDIO;
diff --git a/pjmedia/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c
index 4c06f19f..128c990b 100644
--- a/pjmedia/src/pjmedia/stream.c
+++ b/pjmedia/src/pjmedia/stream.c
@@ -659,6 +659,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt,
stream->port.info.need_info = 0;
stream->port.info.pt = info->fmt.pt;
pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name);
+ stream->port.info.channel_count = 1;
stream->port.info.sample_rate = info->fmt.sample_rate;
stream->port.user_data = stream;
stream->port.put_frame = &put_frame;
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 85fe70f1..1dd4ca08 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -760,6 +760,7 @@ static pj_status_t init_media(void)
status = pjmedia_conf_create(pjsua.pool,
pjsua.max_calls+PJSUA_CONF_MORE_PORTS,
pjsua.clock_rate,
+ 1, /* mono */
pjsua.clock_rate * 20 / 1000, 16,
options,
&pjsua.mconf);
@@ -773,6 +774,7 @@ static pj_status_t init_media(void)
/* Add NULL port to the bridge. */
status = pjmedia_null_port_create( pjsua.pool, pjsua.clock_rate,
+ 1, /* mono */
pjsua.clock_rate * 20 / 1000, 16,
&pjsua.null_port);
pjmedia_conf_add_port( pjsua.mconf, pjsua.pool, pjsua.null_port,