Added bitrate and vad info in pjmedia_format, and changed audio route to use enumeration rather than boolean

git-svn-id: https://svn.pjsip.org/repos/pjproject/branches/projects/aps-direct@2457 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2009-02-17 15:19:45 +00:00
parent 83457d5937
commit f863ca3f77
8 changed files with 72 additions and 44 deletions

View File

@ -275,7 +275,7 @@ typedef struct pjmedia_codec_param
equal to decoder ptime. */
pj_uint8_t pcm_bits_per_sample; /**< Bits/sample in the PCM side */
pj_uint8_t pt; /**< Payload type. */
pjmedia_format format; /**< Source format, it's format of
pjmedia_format_id fmt_id; /**< Source format, it's format of
encoder input and decoder
output. */
} info;

View File

@ -92,6 +92,22 @@ typedef struct pjmedia_snd_stream_info
unsigned play_latency; /**< Playback latency, in samples. */
} pjmedia_snd_stream_info;
/**
* Audio routing destination.
*/
typedef enum pjmedia_snd_route
{
/** Route to default destination */
PJMEDIA_SND_ROUTE_DEFAULT,
/** Route to loudspeaker */
PJMEDIA_SND_ROUTE_LOUDSPEAKER,
/** Route to earpiece */
PJMEDIA_SND_ROUTE_EARPIECE,
} pjmedia_snd_route;
/**
* Stream setting for opening sound device with non-PCM data.
@ -99,13 +115,9 @@ typedef struct pjmedia_snd_stream_info
typedef struct pjmedia_snd_setting
{
pjmedia_format format; /**< Format. */
pj_uint32_t bitrate; /**< Bitrate (bps). */
pj_uint32_t mode; /**< Mode, e.g: iLBC format has
20ms or 30ms frame size. */
pj_bool_t plc; /**< PLC enabled/disabled. */
pj_bool_t vad; /**< VAD enabled/disabled. */
pj_bool_t cng; /**< CNG enabled/disabled. */
pj_bool_t loudspk; /**< Audio routed to loudspeaker. */
pjmedia_snd_route route; /**< Audio routing. */
} pjmedia_snd_setting;

View File

@ -178,14 +178,6 @@ typedef struct pjmedia_sock_info
} pjmedia_sock_info;
/**
* Declaration of format.
*/
typedef union pjmedia_format {
pj_uint32_t u32;
char c[4];
} pjmedia_format;
/**
* Macro for packing format.
@ -193,14 +185,35 @@ typedef union pjmedia_format {
#define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 )
/**
* Format identifier definitions.
* Format identifier definition.
*/
#define PJMEDIA_FORMAT_L16 0
#define PJMEDIA_FORMAT_PCMA PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W')
#define PJMEDIA_FORMAT_PCMU PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W')
#define PJMEDIA_FORMAT_AMR PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R')
#define PJMEDIA_FORMAT_G729 PJMEDIA_FORMAT_PACK('G', '7', '2', '9')
#define PJMEDIA_FORMAT_ILBC PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
typedef enum pjmedia_format_id
{
PJMEDIA_FORMAT_L16 = 0,
PJMEDIA_FORMAT_PCMA = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'),
PJMEDIA_FORMAT_PCMU = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'),
PJMEDIA_FORMAT_AMR = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'),
PJMEDIA_FORMAT_G729 = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'),
PJMEDIA_FORMAT_ILBC = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
} pjmedia_format_id;
/**
* Media format information.
*/
typedef struct pjmedia_format
{
/** Format ID */
pjmedia_format_id fmt_id;
/** Bitrate. */
pj_uint32_t bitrate;
/** Flag to indicate whether VAD is enabled */
pj_bool_t vad;
} pjmedia_format;
/**

View File

@ -155,7 +155,7 @@ static struct codec_desc {
int enabled; /* Is this codec enabled? */
const char *name; /* Codec name. */
pj_uint8_t pt; /* Payload type. */
pjmedia_format format; /* Source format. */
pjmedia_format_id fmt_id; /* Source format. */
unsigned clock_rate; /* Codec's clock rate. */
unsigned channel_count; /* Codec's channel count. */
unsigned samples_per_frame; /* Codec's samples count. */
@ -172,7 +172,7 @@ static struct codec_desc {
codec_desc[] =
{
# if PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR
{1, "AMR", PJMEDIA_RTP_PT_AMR, {PJMEDIA_FORMAT_AMR},
{1, "AMR", PJMEDIA_RTP_PT_AMR, PJMEDIA_FORMAT_AMR,
8000, 1, 160,
7400, 12200, 2, 1, 1,
&parse_amr, &pack_amr
@ -181,14 +181,14 @@ codec_desc[] =
# endif
# if PJMEDIA_HAS_PASSTHROUGH_CODEC_G729
{1, "G729", PJMEDIA_RTP_PT_G729, {PJMEDIA_FORMAT_G729},
{1, "G729", PJMEDIA_RTP_PT_G729, PJMEDIA_FORMAT_G729,
8000, 1, 80,
8000, 8000, 2, 1, 1
},
# endif
# if PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC
{1, "iLBC", PJMEDIA_RTP_PT_ILBC, {PJMEDIA_FORMAT_ILBC},
{1, "iLBC", PJMEDIA_RTP_PT_ILBC, PJMEDIA_FORMAT_ILBC,
8000, 1, 240,
13333, 15200, 1, 1, 1,
NULL, NULL,
@ -197,14 +197,14 @@ codec_desc[] =
# endif
# if PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU
{1, "PCMU", PJMEDIA_RTP_PT_PCMU, {PJMEDIA_FORMAT_PCMU},
{1, "PCMU", PJMEDIA_RTP_PT_PCMU, PJMEDIA_FORMAT_PCMU,
8000, 1, 80,
64000, 64000, 2, 1, 1
},
# endif
# if PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA
{1, "PCMA", PJMEDIA_RTP_PT_PCMA, {PJMEDIA_FORMAT_PCMA},
{1, "PCMA", PJMEDIA_RTP_PT_PCMA, PJMEDIA_FORMAT_PCMA,
8000, 1, 80,
64000, 64000, 2, 1, 1
},
@ -449,7 +449,7 @@ static pj_status_t default_attr ( pjmedia_codec_factory *factory,
(codec_desc[i].samples_per_frame * 1000 /
codec_desc[i].channel_count /
codec_desc[i].clock_rate);
attr->info.format = codec_desc[i].format;
attr->info.fmt_id = codec_desc[i].fmt_id;
/* Default flags. */
attr->setting.frm_per_pkt = codec_desc[i].frm_per_pkt;

View File

@ -588,7 +588,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_connect_port( pjmedia_conf *conf,
dst_port = conf->ports[sink_slot];
/* Source and sink format must match. */
if (src_port->info->format.u32 != dst_port->info->format.u32) {
if (src_port->info->format.fmt_id != dst_port->info->format.fmt_id) {
pj_mutex_unlock(conf->mutex);
return PJMEDIA_ENOTCOMPATIBLE;
}
@ -951,7 +951,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_adjust_rx_level( pjmedia_conf *conf,
conf_port = conf->ports[slot];
/* Level adjustment is applicable only for ports that work with raw PCM. */
PJ_ASSERT_RETURN(conf_port->info->format.u32 == PJMEDIA_FORMAT_L16,
PJ_ASSERT_RETURN(conf_port->info->format.fmt_id == PJMEDIA_FORMAT_L16,
PJ_EIGNORED);
/* Set normalized adjustment level. */
@ -985,7 +985,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_adjust_tx_level( pjmedia_conf *conf,
conf_port = conf->ports[slot];
/* Level adjustment is applicable only for ports that work with raw PCM. */
PJ_ASSERT_RETURN(conf_port->info->format.u32 == PJMEDIA_FORMAT_L16,
PJ_ASSERT_RETURN(conf_port->info->format.fmt_id == PJMEDIA_FORMAT_L16,
PJ_EIGNORED);
/* Set normalized adjustment level. */
@ -1110,7 +1110,7 @@ static pj_status_t write_frame(struct conf_port *cport_dst,
/* Check port format. */
if (cport_dst->port &&
cport_dst->port->info.format.u32 == PJMEDIA_FORMAT_L16)
cport_dst->port->info.format.fmt_id == PJMEDIA_FORMAT_L16)
{
/* When there is already some samples in listener's TX buffer,
* pad the buffer with "zero samples".

View File

@ -289,7 +289,7 @@ static pj_status_t play_cb_ext(/* in */ void *user_data,
void (*decoder)(pj_int16_t*, const pj_uint8_t*, pj_size_t) = NULL;
unsigned i, size_decoded;
switch (snd_port->setting.format.u32) {
switch (snd_port->setting.format.fmt_id) {
case PJMEDIA_FORMAT_PCMA:
decoder = &pjmedia_alaw_decode;
break;
@ -298,7 +298,7 @@ static pj_status_t play_cb_ext(/* in */ void *user_data,
break;
default:
PJ_LOG(1,(THIS_FILE, "Unsupported format %d",
snd_port->setting.format.u32));
snd_port->setting.format.fmt_id));
goto no_frame;
}
@ -391,7 +391,7 @@ static pj_status_t rec_cb_ext(/* in */ void *user_data,
fx->base.type = PJMEDIA_FRAME_TYPE_EXTENDED;
fx->base.timestamp.u32.lo = timestamp;
switch (snd_port->setting.format.u32) {
switch (snd_port->setting.format.fmt_id) {
case PJMEDIA_FORMAT_PCMA:
encoder = &pjmedia_alaw_encode;
break;
@ -400,7 +400,7 @@ static pj_status_t rec_cb_ext(/* in */ void *user_data,
break;
default:
PJ_LOG(1,(THIS_FILE, "Unsupported format %d",
snd_port->setting.format.u32));
snd_port->setting.format.fmt_id));
return PJ_SUCCESS;
}
@ -434,7 +434,7 @@ static pj_status_t start_sound_device( pj_pool_t *pool,
snd_port->dir == PJMEDIA_DIR_CAPTURE_PLAYBACK,
PJ_EBUG);
if (snd_port->setting.format.u32 == PJMEDIA_FORMAT_L16) {
if (snd_port->setting.format.fmt_id == PJMEDIA_FORMAT_L16) {
snd_rec_cb = &rec_cb;
snd_play_cb = &play_cb;
} else {
@ -715,7 +715,7 @@ PJ_DEF(pj_status_t) pjmedia_snd_port_create2(pj_pool_t *pool,
#if !defined(PJMEDIA_SND_SUPPORT_OPEN2) || PJMEDIA_SND_SUPPORT_OPEN2==0
/* For devices that doesn't support open2(), enable simulation */
if (snd_port->setting.format.u32 != PJMEDIA_FORMAT_L16) {
if (snd_port->setting.format.fmt_id != PJMEDIA_FORMAT_L16) {
snd_port->frm_buf_size = sizeof(pjmedia_frame_ext) +
(samples_per_frame << 1) +
16 * sizeof(pjmedia_frame_ext_subframe);

View File

@ -867,7 +867,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port,
*/
} else if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO &&
frame->buf == NULL &&
stream->port.info.format.u32 == PJMEDIA_FORMAT_L16 &&
stream->port.info.format.fmt_id == PJMEDIA_FORMAT_L16 &&
(stream->dir & PJMEDIA_DIR_ENCODING) &&
stream->codec_param.info.frm_ptime *
stream->codec_param.info.channel_cnt *
@ -1605,9 +1605,11 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt,
pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name);
stream->port.info.clock_rate = info->fmt.clock_rate;
stream->port.info.channel_count = info->fmt.channel_cnt;
stream->port.info.format = info->param->info.format;
stream->port.info.format.fmt_id = info->param->info.fmt_id;
stream->port.info.format.bitrate = info->param->info.avg_bps;
stream->port.info.format.vad = (info->param->setting.vad != 0);
stream->port.port_data.pdata = stream;
if (stream->port.info.format.u32 == PJMEDIA_FORMAT_L16) {
if (stream->port.info.format.fmt_id == PJMEDIA_FORMAT_L16) {
stream->port.put_frame = &put_frame;
stream->port.get_frame = &get_frame;
} else {

View File

@ -2433,6 +2433,7 @@ static void on_call_stream_created(pjsua_call_id call_id,
{
pjmedia_port *conf;
pjmedia_session_info sess_info;
pjmedia_port *port;
pjmedia_stream_info *strm_info;
pjmedia_snd_setting setting;
unsigned samples_per_frame;
@ -2445,12 +2446,12 @@ static void on_call_stream_created(pjsua_call_id call_id,
pjmedia_session_get_info(sess, &sess_info);
strm_info = &sess_info.stream_info[stream_idx];
pjmedia_session_get_port(sess, stream_idx, &port);
/* Init sound device setting based on stream info. */
pj_bzero(&setting, sizeof(setting));
setting.format = strm_info->param->info.format;
setting.bitrate = strm_info->param->info.avg_bps;
setting.format = port->info.format;
setting.cng = strm_info->param->setting.cng;
setting.vad = strm_info->param->setting.vad;
setting.plc = strm_info->param->setting.plc;
/* Close sound device and get the conference port. */