]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
sndfile tweak
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 27 Dec 2005 19:52:30 +0000 (19:52 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 27 Dec 2005 19:52:30 +0000 (19:52 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@213 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/mod_iaxchan/mod_iaxchan.c
src/mod/mod_playback/mod_playback.c
src/mod/mod_sndfile/mod_sndfile.c
src/mod/mod_xmpp_event/mod_xmpp_event.c

index 7c192da8c3d384ae72457d73af696cb731957fdc..0cd7e78959a0e97fbee8bd2ce966a95885c36470 100644 (file)
@@ -449,7 +449,6 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig)
 
        switch_clear_flag(tech_pvt, TFLAG_IO);
        switch_clear_flag(tech_pvt, TFLAG_VOICE);
-       switch_thread_cond_signal(tech_pvt->cond);
        switch_channel_hangup(channel);
        switch_thread_cond_signal(tech_pvt->cond);
        
index 15454fb2722ad6b1805618d61985d69118606d85..2287c42775be37752945633a2919cbd49965d9e2 100644 (file)
@@ -41,7 +41,7 @@ static const char modname[] = "mod_playback";
 void playback_function(switch_core_session *session, char *data)
 {
        switch_channel *channel;
-       char buf[960];
+       short buf[960];
        char dtmf[128];
        int interval = 0, samples = 0;
        size_t len = 0, ilen = 0;
@@ -59,7 +59,7 @@ void playback_function(switch_core_session *session, char *data)
 
        if (switch_core_file_open(&fh,
                                                          data,
-                                                         SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_RAW,
+                                                         SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
                                                          switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
                switch_channel_hangup(channel);
                return;
@@ -73,14 +73,12 @@ void playback_function(switch_core_session *session, char *data)
     
        switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s\n", data);
        
+       samples = fh.samplerate / 50;
+       len = samples * 2;
        interval = 20;
-       len = 320;
-       samples = 160;
+
        codec_name = "L16";
        
-       write_frame.samples = samples;
-
-       /* You can use zap instead of soft if you have it loaded */
        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);
@@ -89,7 +87,13 @@ void playback_function(switch_core_session *session, char *data)
 
        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, interval, SWITCH_CODEC_FLAG_ENCODE|SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
+       if (switch_core_codec_init(&codec,
+                                                          codec_name,
+                                                          8000,
+                                                          interval,
+                                                          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 {
@@ -100,7 +104,7 @@ void playback_function(switch_core_session *session, char *data)
 
        /* start a thread to absorb incoming audio */
        switch_core_service_session(session, &thread_session);
-       ilen = len;
+       ilen = samples;
        while(switch_channel_get_state(channel) == CS_EXECUTE) {
                int done = 0;
 
@@ -127,7 +131,8 @@ void playback_function(switch_core_session *session, char *data)
                        break;
                }
 
-               write_frame.datalen = ilen;
+               write_frame.datalen = ilen * 2;
+               write_frame.samples = ilen;
 #ifdef SWAP_LINEAR
                switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2);
 #endif
index 1f357094839986e233247b0e0067a2c4fb1374fc..021c62db3f30c74d593728197d0e3bc7da50e406 100644 (file)
@@ -85,22 +85,29 @@ switch_status sndfile_file_open(switch_file_handle *handle, char *path)
        }
 
        if (!strcmp(ext, "r24")) {
-               context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16;
+               context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_24;
                context->sfinfo.channels = 1;
                context->sfinfo.samplerate = 24000;
        }
 
        if (!strcmp(ext, "r32")) {
-               context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16;
+               context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_32;
                context->sfinfo.channels = 1;
                context->sfinfo.samplerate = 32000;
        }
 
+       if (!strcmp(ext, "gsm")) {
+               context->sfinfo.format = SF_FORMAT_RAW |SF_FORMAT_GSM610;
+               context->sfinfo.channels = 1;
+               context->sfinfo.samplerate = 8000;
+       }
+
        if (!(context->handle = sf_open(path, mode, &context->sfinfo))) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle));
                return SWITCH_STATUS_GENERR;
        }
 
+       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
        handle->samples = context->sfinfo.frames;
        handle->samplerate = context->sfinfo.samplerate;
        handle->channels = context->sfinfo.channels;
@@ -213,7 +220,8 @@ static switch_status setup_formats(void)
        char buffer [128] ;
        int format, major_count, subtype_count, m, s ;
        int len,x,skip;
-
+       char *extras[] = {"r8", "r16", "r24", "r32", "gsm"};
+       int exlen = (sizeof(extras) / sizeof(extras[0]));
        buffer [0] = 0 ;
        sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
        if (strlen (buffer) < 1) {
@@ -228,7 +236,7 @@ static switch_status setup_formats(void)
        sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
        
        sfinfo.channels = 1 ;
-       len = (major_count + 5) * sizeof(char *);
+       len = ((major_count + (exlen + 2)) * sizeof(char *));
        *supported_formats = switch_core_permenant_alloc(len);
        memset(supported_formats, 0, len);
 
@@ -260,11 +268,9 @@ static switch_status setup_formats(void)
                }
 
        }
-
-       supported_formats[len++] = "r8";
-       supported_formats[len++] = "r16";
-       supported_formats[len++] = "r24";
-       supported_formats[len++] = "r32";
+       for(m=0; m< exlen; m++) {
+               supported_formats[len++] = extras[m];
+       }
        
 
 
index 76dcb9eca392b31cf907ba02196e1858b9672e1b..622f26402ee0015acf7bc855294d69289305ffcc 100644 (file)
@@ -64,6 +64,10 @@ static void event_handler (switch_event *event)
        iks *msg;
        int loops = 0;
 
+       if (!RUNNING) {
+               return;
+       }
+
        while (!globals.session.authorized) {
                switch_yield(100000);
                if (loops++ > 5) {