From 7e823acd1c44aa1f9f03d4a3de962c08c683d806 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 16 Mar 2006 19:03:07 +0000 Subject: 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 --- pjmedia/include/pjmedia/conference.h | 6 ++++++ pjmedia/include/pjmedia/null_port.h | 2 ++ pjmedia/src/pjmedia/conference.c | 12 +++++++++++- pjmedia/src/pjmedia/file_port.c | 2 +- pjmedia/src/pjmedia/null_port.c | 2 ++ pjmedia/src/pjmedia/stream.c | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) (limited to 'pjmedia') 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; -- cgit v1.2.3