]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Added LPCM (16-bit linear PCM) codec, which is used internally in host order;
authorMichael Jerris <mike@jerris.com>
Fri, 19 Jun 2009 03:57:04 +0000 (03:57 +0000)
committerMichael Jerris <mike@jerris.com>
Fri, 19 Jun 2009 03:57:04 +0000 (03:57 +0000)
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

libs/unimrcp/build/vsprops/unimrcpplugin.vsprops
libs/unimrcp/libs/mpf/include/mpf_codec.h
libs/unimrcp/libs/mpf/include/mpf_codec_manager.h
libs/unimrcp/libs/mpf/src/mpf_codec_linear.c
libs/unimrcp/libs/mpf/src/mpf_codec_manager.c
libs/unimrcp/libs/mpf/src/mpf_engine.c
libs/unimrcp/libs/mpf/src/mpf_termination.c
libs/unimrcp/plugins/mrcp-cepstral/src/mrcp_swift.c
libs/unimrcp/tests/mpftest/src/mpf_suite.c

index 00dcc9ed432960f42bdb4207dd0b1e18bb5b3ee7..53c6857dfdf7f3b99bc8376f8974f95555170cf7 100644 (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>
index 8c9c4b91be9d25f6bd3b13ed53ae8f5f91f8a55f..282ab693d8c6edc1de5c019c0d11972429aa7755 100644 (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
  */
index 2b14070b529f51b75e0c0dbc39a936acd8617e18..ec2fdd8d19bd0bc445656bf31d260a3f4266e5dd 100644 (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);
 
index f2aa0a703b2c6f48be9085e73aac9296977cc830..ceaec016ce93cc1384550a8673f181d4e9b964c7 100644 (file)
 
 #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 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_vtable_t l16_vtable = {
+       l16_open,
+       l16_close,
+       l16_encode,
+       l16_decode,
        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_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_t* mpf_codec_l16_create(apr_pool_t *pool)
+mpf_codec_descriptor_t* mpf_codec_lpcm_descriptor_create(apr_uint16_t sampling_rate, apr_byte_t channel_count, apr_pool_t *pool)
 {
-       return mpf_codec_create(&l16_vtable,&l16_attribs,NULL,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);
 }
 
-const mpf_codec_descriptor_t* l16_descriptor_get()
+mpf_codec_t* mpf_codec_l16_create(apr_pool_t *pool)
 {
-       return &l16_descriptor;
+       return mpf_codec_create(&l16_vtable,&l16_attribs,NULL,pool);
 }
index 3492cb23d7241180bba7c2627cf28f7123e64462..15bda89c51601e324c77ef9add5cd42aad6fd934 100644 (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;
index 2c6dca93a70c46bde0b3824f4fc571bc03cc8860..42aee780fc1cdeda876eceea899c65ddf4551f80 100644 (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);
 
index 2c975442b6f32843f95efad6851222c026359272..291d92cae3a2b7df9dd79646453714bcd7adde98 100644 (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);
                        }
                }
        }
index 51558fd530af3ca9b52ea0e340cc85ef275bc370..d057650369ad30f78234b4a4d0d8adc9389c6403 100644 (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);
index af144b53d1b27cb3fcc3ac6dd2ada317aa784892..4075ebb546dde9fa102a8bda3bc0ca75de12bf5e 100644 (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;