]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add channels arg to codec
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 28 Dec 2005 20:06:03 +0000 (20:06 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 28 Dec 2005 20:06:03 +0000 (20:06 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@227 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/mod/mod_exosip/mod_exosip.c
src/mod/mod_iaxchan/mod_iaxchan.c
src/mod/mod_playback/mod_playback.c
src/mod/mod_portaudio/mod_portaudio.c
src/mod/mod_rawaudio/mod_rawaudio.c
src/mod/mod_woomerachan/mod_woomerachan.c
src/switch_core.c

index fdf3e1979580676d76138db721461dacf866eebc..824c8a9c91b10b3a70d4950a61cf798a6981f557 100644 (file)
@@ -101,7 +101,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(sw
 SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session, switch_waitfor_read_hook waitfor_read);
 SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session, switch_waitfor_write_hook waitfor_write);
 SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session, switch_send_dtmf_hook send_dtmf);
-SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool);
+SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, int channels, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool);
 SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
                                                                 switch_codec *other_codec,
                                                                 void *decoded_data,
index ee9e17c30820715df91f4b3349d37477dfaea4b3..59bd5529aedf3e5aff17ff4605b8c46c9a693d00 100644 (file)
@@ -890,6 +890,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
                                                                           dname,
                                                                           rate,
                                                                           globals.codec_ms,
+                                                                          1,
                                                                           SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                                           NULL,
                                                                           switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
@@ -901,6 +902,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
                                                                                   dname,
                                                                                   rate,
                                                                                   globals.codec_ms,
+                                                                                  1,
                                                                                   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                                                   NULL,
                                                                                   switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
@@ -1052,6 +1054,7 @@ static void handle_answer(eXosip_event_t *event)
                                                                   dname,
                                                                   rate,
                                                                   globals.codec_ms,
+                                                                  1,
                                                                   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                                   NULL,
                                                                   switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
@@ -1063,6 +1066,7 @@ static void handle_answer(eXosip_event_t *event)
                                                                           dname,
                                                                           rate,
                                                                           globals.codec_ms,
+                                                                          1,
                                                                           SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
                                                                           NULL,
                                                                           switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
index 24b46dbd626c6b0123b30b5046a34c10601ebdc8..7ddfbc7a814cab1289a556025a77ebc6d35900a7 100644 (file)
@@ -275,6 +275,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
                                                           dname,
                                                           0,
                                                           0,
+                                                          1,
                                                           SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                           NULL,
                                                           switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
@@ -285,6 +286,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
                                                                   dname,
                                                                   0,
                                                                   0,
+                                                                  1,
                                                                   SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, 
                                                                   NULL,
                                                                   switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
index 2287c42775be37752945633a2919cbd49965d9e2..aac2922181e752b9a25028575a824801d7f4569d 100644 (file)
@@ -71,37 +71,41 @@ void playback_function(switch_core_session *session, char *data)
        write_frame.buflen = sizeof(buf);
 
     
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s\n", data);
+       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s %dkhz %d channels\n", data, fh.samplerate, fh.channels);
        
-       samples = fh.samplerate / 50;
-       len = samples * 2;
        interval = 20;
-
+       samples = (fh.samplerate / 50) * fh.channels;
+       len = samples * 2;
+       
        codec_name = "L16";
        
-       if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
-               switch_channel_hangup(channel);
-               return;
-       }
-
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
-
        if (switch_core_codec_init(&codec,
                                                           codec_name,
-                                                          8000,
+                                                          fh.samplerate,
                                                           interval,
+                                                          fh.channels,
                                                           SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                           NULL,
                                                           pool) == SWITCH_STATUS_SUCCESS) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
                write_frame.codec = &codec;
        } else {
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed\n");
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d\n", codec_name, fh.samplerate, interval);
+               switch_core_file_close(&fh);
                switch_channel_hangup(channel);
                return;
        }
 
+       if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
+               switch_core_codec_destroy(&codec);
+               switch_core_file_close(&fh);
+               switch_channel_hangup(channel);
+               return;
+       }
+
+       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
+
        /* start a thread to absorb incoming audio */
        switch_core_service_session(session, &thread_session);
        ilen = samples;
@@ -130,7 +134,7 @@ void playback_function(switch_core_session *session, char *data)
                if (ilen <= 0) {
                        break;
                }
-
+               
                write_frame.datalen = ilen * 2;
                write_frame.samples = ilen;
 #ifdef SWAP_LINEAR
index 1d727e09a494778cdb574b0b7652c4badfd04a63..a784851824dea1125dd6f7ac643cd2b7e9b97534 100644 (file)
@@ -703,6 +703,7 @@ static switch_status engage_device(struct private_object *tech_pvt)
                                                           "L16",
                                                           sample_rate,
                                                           codec_ms,
+                                                          1,
                                                           SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                           NULL,
                                                           switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
@@ -713,6 +714,7 @@ static switch_status engage_device(struct private_object *tech_pvt)
                                                                           "L16",
                                                                           sample_rate,
                                                                           codec_ms,
+                                                                          1,
                                                                           SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
                                                                           NULL,
                                                                           switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
index ca67c03b57eff5f0d68bf6626b403856c884c04e..cf6923c84f0b78dc1e5f902f934745f10a84b434 100644 (file)
@@ -59,6 +59,7 @@ static switch_status switch_raw_encode(switch_codec *codec,
           TBD look at other_codec to determine the original format of the data and determine if we need to resample
           in the event the audio is the same format but different implementations.
        */
+       printf("encode %d %d->%d\n", decoded_data_len, other_codec->implementation->bytes_per_frame, codec->implementation->bytes_per_frame);
 
        return SWITCH_STATUS_NOOP;
 }
@@ -72,7 +73,8 @@ static switch_status switch_raw_decode(switch_codec *codec,
                                                                 unsigned int *flag) 
 {
 
-       //printf("decode %d %d->%d\n", encoded_data_len, other_codec->implementation->bytes_per_frame, codec->implementation->bytes_per_frame);
+       printf("decode %d %d->%d\n", encoded_data_len, other_codec->implementation->bytes_per_frame, codec->implementation->bytes_per_frame);
+
        return SWITCH_STATUS_NOOP;
 }
 
@@ -132,6 +134,23 @@ static const switch_codec_implementation raw_32k_implementation = {
        /*.destroy = */ switch_raw_destroy
 };
 
+static const switch_codec_implementation raw_22k_implementation = {
+       /*.samples_per_second = */ 22050,
+       /*.bits_per_second = */ 352800,
+       /*.microseconds_per_frame = */ 20000,
+       /*.samples_per_frame = */ 441,
+       /*.bytes_per_frame = */ 882,
+       /*.encoded_bytes_per_frame = */ 882,
+       /*.number_of_channels = */ 1,
+       /*.pref_frames_per_packet = */ 1,
+       /*.max_frames_per_packet = */ 1,
+       /*.init = */ switch_raw_init,
+       /*.encode = */ switch_raw_encode,
+       /*.decode = */ switch_raw_decode,
+       /*.destroy = */ switch_raw_destroy,
+       /*.next = */ &raw_32k_implementation
+};
+
 static const switch_codec_implementation raw_16k_implementation = {
        /*.samples_per_second = */ 16000,
        /*.bits_per_second = */ 256000,
@@ -146,7 +165,7 @@ static const switch_codec_implementation raw_16k_implementation = {
        /*.encode = */ switch_raw_encode,
        /*.decode = */ switch_raw_decode,
        /*.destroy = */ switch_raw_destroy,
-       /*.next = */ &raw_32k_implementation
+       /*.next = */ &raw_22k_implementation
 };
 
 static const switch_codec_implementation raw_8k_implementation = {
index d7ec4ca4815afe7fe7e3d2adf49b039c466e5777..ce4679934c3ce843fbb6e049cffbd00315e1cd68 100644 (file)
@@ -207,13 +207,13 @@ static switch_status woomerachan_on_init(switch_core_session *session)
 
        tech_pvt->frame.data = tech_pvt->databuf;
 
-       if (switch_core_codec_init(&tech_pvt->read_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+       if (switch_core_codec_init(&tech_pvt->read_codec, "L16", 8000, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
                switch_channel_hangup(channel);
                return SWITCH_STATUS_FALSE;
        }
 
-       if (switch_core_codec_init(&tech_pvt->write_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+       if (switch_core_codec_init(&tech_pvt->write_codec, "L16", 8000, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
                switch_channel_hangup(channel);
                return SWITCH_STATUS_FALSE;
index 81fa0864019811bd8527c0ad92d4b8ac3000fd14..ccb9c58d64e6ad41ea5072e0b37091b8567a3ba8 100644 (file)
@@ -202,7 +202,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_write_codec(switch_core_se
        return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool)
+SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, int channels, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool)
 {
        const switch_codec_interface *codec_interface;
        const switch_codec_implementation *iptr, *implementation = NULL;
@@ -218,7 +218,9 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
        }
 
        for(iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
-               if ((!rate || rate == iptr->samples_per_second) && (!ms || ms == (iptr->microseconds_per_frame / 1000))) {
+               if ((!rate || rate == iptr->samples_per_second) && 
+                       (!ms || ms == (iptr->microseconds_per_frame / 1000)) && 
+                       (!channels || channels == iptr->number_of_channels)) {
                        implementation = iptr;
                        break;
                }