diff --git a/libs/unimrcp/build/vsprops/unimrcpplugin.vsprops b/libs/unimrcp/build/vsprops/unimrcpplugin.vsprops index 00dcc9ed43..53c6857dfd 100644 --- a/libs/unimrcp/build/vsprops/unimrcpplugin.vsprops +++ b/libs/unimrcp/build/vsprops/unimrcpplugin.vsprops @@ -12,6 +12,6 @@ diff --git a/libs/unimrcp/libs/mpf/include/mpf_codec.h b/libs/unimrcp/libs/mpf/include/mpf_codec.h index 8c9c4b91be..282ab693d8 100644 --- a/libs/unimrcp/libs/mpf/include/mpf_codec.h +++ b/libs/unimrcp/libs/mpf/include/mpf_codec.h @@ -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 */ diff --git a/libs/unimrcp/libs/mpf/include/mpf_codec_manager.h b/libs/unimrcp/libs/mpf/include/mpf_codec_manager.h index 2b14070b52..ec2fdd8d19 100644 --- a/libs/unimrcp/libs/mpf/include/mpf_codec_manager.h +++ b/libs/unimrcp/libs/mpf/include/mpf_codec_manager.h @@ -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); diff --git a/libs/unimrcp/libs/mpf/src/mpf_codec_linear.c b/libs/unimrcp/libs/mpf/src/mpf_codec_linear.c index f2aa0a703b..ceaec016ce 100644 --- a/libs/unimrcp/libs/mpf/src/mpf_codec_linear.c +++ b/libs/unimrcp/libs/mpf/src/mpf_codec_linear.c @@ -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; isize; ) { + 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; isize; ) { + 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; -} diff --git a/libs/unimrcp/libs/mpf/src/mpf_codec_manager.c b/libs/unimrcp/libs/mpf/src/mpf_codec_manager.c index 3492cb23d7..15bda89c51 100644 --- a/libs/unimrcp/libs/mpf/src/mpf_codec_manager.c +++ b/libs/unimrcp/libs/mpf/src/mpf_codec_manager.c @@ -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; diff --git a/libs/unimrcp/libs/mpf/src/mpf_engine.c b/libs/unimrcp/libs/mpf/src/mpf_engine.c index 2c6dca93a7..42aee780fc 100644 --- a/libs/unimrcp/libs/mpf/src/mpf_engine.c +++ b/libs/unimrcp/libs/mpf/src/mpf_engine.c @@ -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); diff --git a/libs/unimrcp/libs/mpf/src/mpf_termination.c b/libs/unimrcp/libs/mpf/src/mpf_termination.c index 2c975442b6..291d92cae3 100644 --- a/libs/unimrcp/libs/mpf/src/mpf_termination.c +++ b/libs/unimrcp/libs/mpf/src/mpf_termination.c @@ -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); } } } diff --git a/libs/unimrcp/plugins/mrcp-cepstral/src/mrcp_swift.c b/libs/unimrcp/plugins/mrcp-cepstral/src/mrcp_swift.c index 51558fd530..d057650369 100644 --- a/libs/unimrcp/plugins/mrcp-cepstral/src/mrcp_swift.c +++ b/libs/unimrcp/plugins/mrcp-cepstral/src/mrcp_swift.c @@ -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); diff --git a/libs/unimrcp/tests/mpftest/src/mpf_suite.c b/libs/unimrcp/tests/mpftest/src/mpf_suite.c index af144b53d1..4075ebb546 100644 --- a/libs/unimrcp/tests/mpftest/src/mpf_suite.c +++ b/libs/unimrcp/tests/mpftest/src/mpf_suite.c @@ -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;