Added LPCM (16-bit linear PCM) codec, which is used internally in host order;

while L16 is RFC3551 defined 16-bit linear PCM codec in network order.

Using LPCM to specify linear PCM codec in host byte order

Merged upstream revisions through r991



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13859 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-06-19 03:57:04 +00:00
parent aa5c392779
commit 2607240b74
9 changed files with 110 additions and 38 deletions

View File

@ -12,6 +12,6 @@
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(SolutionDir)$(ConfigurationName)\bin&quot;"
AdditionalDependencies="mrcpengine.lib mrcp.lib mpf.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib"
AdditionalDependencies="mrcpengine.lib mrcp.lib mpf.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib ws2_32.lib"
/>
</VisualStudioPropertySheet>

View File

@ -82,7 +82,7 @@ static APR_INLINE mpf_codec_t* mpf_codec_create(
}
/**
* Close codec.
* Clone codec.
* @param src_codec the source (original) codec to clone
* @param pool the pool to allocate memory from
*/

View File

@ -39,6 +39,9 @@ MPF_DECLARE(apt_bool_t) mpf_codec_manager_codec_register(mpf_codec_manager_t *co
/** Get (allocate) codec by codec descriptor */
MPF_DECLARE(mpf_codec_t*) mpf_codec_manager_codec_get(const mpf_codec_manager_t *codec_manager, mpf_codec_descriptor_t *descriptor, apr_pool_t *pool);
/** Get (allocate) default codec */
MPF_DECLARE(mpf_codec_t*) mpf_codec_manager_default_codec_get(const mpf_codec_manager_t *codec_manager, apr_pool_t *pool);
/** Get (allocate) list of available codecs */
MPF_DECLARE(apt_bool_t) mpf_codec_manager_codec_list_get(const mpf_codec_manager_t *codec_manager, mpf_codec_list_t *codec_list, apr_pool_t *pool);

View File

@ -16,20 +16,75 @@
#include "mpf_codec.h"
/* linear 16-bit PCM (host horder) */
#define LPCM_CODEC_NAME "LPCM"
#define LPCM_CODEC_NAME_LENGTH (sizeof(LPCM_CODEC_NAME)-1)
/* linear 16-bit PCM (RFC3551) */
#define L16_CODEC_NAME "L16"
#define L16_CODEC_NAME_LENGTH (sizeof(L16_CODEC_NAME)-1)
static const mpf_codec_vtable_t l16_vtable = {
static apt_bool_t l16_open(mpf_codec_t *codec)
{
return TRUE;
}
static apt_bool_t l16_close(mpf_codec_t *codec)
{
return TRUE;
}
static apt_bool_t l16_encode(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out)
{
apr_uint32_t i;
const short *buf_in = frame_in->buffer;
short *buf_out = frame_out->buffer;
frame_out->size = frame_in->size;
for(i=0; i<frame_in->size; ) {
buf_out[i] = htons(buf_in[i]);
i += sizeof(short);
}
return TRUE;
}
static apt_bool_t l16_decode(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out)
{
apr_uint32_t i;
const short *buf_in = frame_in->buffer;
short *buf_out = frame_out->buffer;
frame_out->size = frame_in->size;
for(i=0; i<frame_in->size; ) {
buf_out[i] = ntohs(buf_in[i]);
i += sizeof(short);
}
return TRUE;
}
static const mpf_codec_vtable_t lpcm_vtable = {
NULL
};
static const mpf_codec_descriptor_t l16_descriptor = {
96, /* not specified */
{L16_CODEC_NAME, L16_CODEC_NAME_LENGTH},
8000,
1,
NULL,
TRUE
static const mpf_codec_vtable_t l16_vtable = {
l16_open,
l16_close,
l16_encode,
l16_decode,
NULL
};
static const mpf_codec_attribs_t lpcm_attribs = {
{LPCM_CODEC_NAME, LPCM_CODEC_NAME_LENGTH}, /* codec name */
16, /* bits per sample */
MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000 /* sampling rates */
};
static const mpf_codec_attribs_t l16_attribs = {
@ -38,12 +93,24 @@ static const mpf_codec_attribs_t l16_attribs = {
MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000 /* sampling rates */
};
mpf_codec_descriptor_t* mpf_codec_lpcm_descriptor_create(apr_uint16_t sampling_rate, apr_byte_t channel_count, apr_pool_t *pool)
{
mpf_codec_descriptor_t *descriptor = apr_palloc(pool,sizeof(mpf_codec_descriptor_t));
mpf_codec_descriptor_init(descriptor);
descriptor->payload_type = 96;
descriptor->name.buf = LPCM_CODEC_NAME;
descriptor->name.length = LPCM_CODEC_NAME_LENGTH;
descriptor->sampling_rate = sampling_rate;
descriptor->channel_count = channel_count;
return descriptor;
}
mpf_codec_t* mpf_codec_lpcm_create(apr_pool_t *pool)
{
return mpf_codec_create(&lpcm_vtable,&lpcm_attribs,NULL,pool);
}
mpf_codec_t* mpf_codec_l16_create(apr_pool_t *pool)
{
return mpf_codec_create(&l16_vtable,&l16_attribs,NULL,pool);
}
const mpf_codec_descriptor_t* l16_descriptor_get()
{
return &l16_descriptor;
}

View File

@ -28,6 +28,8 @@ struct mpf_codec_manager_t {
};
mpf_codec_descriptor_t* mpf_codec_lpcm_descriptor_create(apr_uint16_t sampling_rate, apr_byte_t channel_count, apr_pool_t *pool);
MPF_DECLARE(mpf_codec_manager_t*) mpf_codec_manager_create(apr_size_t codec_count, apr_pool_t *pool)
{
mpf_codec_manager_t *codec_manager = apr_palloc(pool,sizeof(mpf_codec_manager_t));
@ -93,6 +95,14 @@ MPF_DECLARE(mpf_codec_t*) mpf_codec_manager_codec_get(const mpf_codec_manager_t
return ret_codec;
}
MPF_DECLARE(mpf_codec_t*) mpf_codec_manager_default_codec_get(const mpf_codec_manager_t *codec_manager, apr_pool_t *pool)
{
mpf_codec_t *codec;
mpf_codec_descriptor_t *descriptor = mpf_codec_lpcm_descriptor_create(8000,1,pool);
codec = mpf_codec_manager_codec_get(codec_manager,descriptor,pool);
return codec;
}
MPF_DECLARE(apt_bool_t) mpf_codec_manager_codec_list_get(const mpf_codec_manager_t *codec_manager, mpf_codec_list_t *codec_list, apr_pool_t *pool)
{
const mpf_codec_descriptor_t *static_descriptor;

View File

@ -48,6 +48,7 @@ static apt_bool_t mpf_engine_msg_process(apt_task_t *task, apt_task_msg_t *msg);
static apt_bool_t mpf_engine_contexts_destroy(mpf_engine_t *engine);
mpf_codec_t* mpf_codec_lpcm_create(apr_pool_t *pool);
mpf_codec_t* mpf_codec_l16_create(apr_pool_t *pool);
mpf_codec_t* mpf_codec_g711u_create(apr_pool_t *pool);
mpf_codec_t* mpf_codec_g711a_create(apr_pool_t *pool);
@ -287,6 +288,9 @@ MPF_DECLARE(mpf_codec_manager_t*) mpf_engine_codec_manager_create(apr_pool_t *po
mpf_codec_manager_t *codec_manager = mpf_codec_manager_create(3,pool);
if(codec_manager) {
mpf_codec_t *codec;
codec = mpf_codec_lpcm_create(pool);
mpf_codec_manager_codec_register(codec_manager,codec);
codec = mpf_codec_g711u_create(pool);
mpf_codec_manager_codec_register(codec_manager,codec);

View File

@ -18,8 +18,6 @@
#include "mpf_stream.h"
#include "mpf_codec_manager.h"
const mpf_codec_descriptor_t* l16_descriptor_get();
MPF_DECLARE(mpf_termination_t*) mpf_termination_base_create(
mpf_termination_factory_t *termination_factory,
void *obj,
@ -69,20 +67,6 @@ MPF_DECLARE(apt_bool_t) mpf_termination_modify(mpf_termination_t *termination, v
return TRUE;
}
static mpf_codec_t* mpf_termination_default_codec_create(mpf_termination_t *termination)
{
mpf_codec_t *codec;
const mpf_codec_descriptor_t *default_descriptor = l16_descriptor_get();
mpf_codec_descriptor_t *descriptor = apr_palloc(termination->pool,sizeof(mpf_codec_descriptor_t));
mpf_codec_descriptor_init(descriptor);
*descriptor = *default_descriptor;
codec = mpf_codec_manager_codec_get(
termination->codec_manager,
descriptor,
termination->pool);
return codec;
}
MPF_DECLARE(apt_bool_t) mpf_termination_validate(mpf_termination_t *termination)
{
mpf_audio_stream_t *audio_stream;
@ -96,12 +80,16 @@ MPF_DECLARE(apt_bool_t) mpf_termination_validate(mpf_termination_t *termination)
}
if((audio_stream->mode & STREAM_MODE_RECEIVE) == STREAM_MODE_RECEIVE) {
if(!audio_stream->rx_codec) {
audio_stream->rx_codec = mpf_termination_default_codec_create(termination);
audio_stream->rx_codec = mpf_codec_manager_default_codec_get(
termination->codec_manager,
termination->pool);
}
}
if((audio_stream->mode & STREAM_MODE_SEND) == STREAM_MODE_SEND) {
if(!audio_stream->tx_codec) {
audio_stream->tx_codec = mpf_termination_default_codec_create(termination);
audio_stream->tx_codec = mpf_codec_manager_default_codec_get(
termination->codec_manager,
termination->pool);
}
}
}

View File

@ -195,7 +195,7 @@ static mrcp_engine_channel_t* mrcp_swift_engine_channel_create(mrcp_resource_eng
mpf_codec_descriptor_init(codec_descriptor);
codec_descriptor->channel_count = 1;
codec_descriptor->payload_type = 96;
apt_string_set(&codec_descriptor->name,"L16");
apt_string_set(&codec_descriptor->name,"LPCM");
codec_descriptor->sampling_rate = 8000;
params = swift_params_new(NULL);

View File

@ -348,8 +348,8 @@ static mpf_audio_file_descriptor_t* mpf_file_reader_descriptor_create(mpf_suite_
descriptor->write_handle = NULL;
codec_descriptor = &descriptor->codec_descriptor;
codec_descriptor->payload_type = 11;
apt_string_set(&codec_descriptor->name,"L16");
codec_descriptor->payload_type = 96;
apt_string_set(&codec_descriptor->name,"LPCM");
codec_descriptor->sampling_rate = 8000;
codec_descriptor->channel_count = 1;
return descriptor;
@ -366,8 +366,8 @@ static mpf_audio_file_descriptor_t* mpf_file_writer_descriptor_create(mpf_suite_
descriptor->read_handle = NULL;
codec_descriptor = &descriptor->codec_descriptor;
codec_descriptor->payload_type = 11;
apt_string_set(&codec_descriptor->name,"L16");
codec_descriptor->payload_type = 96;
apt_string_set(&codec_descriptor->name,"LPCM");
codec_descriptor->sampling_rate = 8000;
codec_descriptor->channel_count = 1;
return descriptor;