]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
set the variable RECORD_STEREO=true to make record_session create stereo files with...
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 1 Oct 2007 16:34:28 +0000 (16:34 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 1 Oct 2007 16:34:28 +0000 (16:34 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5772 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_core_media_bug.c
src/switch_ivr_async.c

index 051f746186c3e148d92acaf099b3212564775480..f02eaeb09c54528259feeb40533f5da2dc9171e2 100644 (file)
@@ -786,7 +786,8 @@ typedef enum {
        SMBF_READ_STREAM = (1 << 0),
        SMBF_WRITE_STREAM = (1 << 1),
        SMBF_WRITE_REPLACE = (1 << 2),
-       SMBF_READ_REPLACE = (1 << 3)
+       SMBF_READ_REPLACE = (1 << 3),
+       SMBF_STEREO = (1 << 4)
 } switch_media_bug_flag_t;
 
 /*!
index e5610a95d853e17656a0d53845783e8af640c7df..2c56240fc59e87d7c39e15f4d3e95ae07bdd36ab 100644 (file)
@@ -119,32 +119,49 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
 
 
        bytes = (datalen > frame->datalen) ? datalen : frame->datalen;
-
+       
        if (bytes) {
+               int16_t tmp[960], *tp = tmp;
+               
                dp = (int16_t *) data;
                fp = (int16_t *) frame->data;
-
                rlen = frame->datalen / 2;
                wlen = datalen / 2;
                blen = bytes / 2;
 
-               for (x = 0; x < blen; x++) {
-                       int32_t z = 0;
-
-                       if (x < rlen) {
-                               z += (int32_t) *(fp + x);
+               if (switch_test_flag(bug, SMBF_STEREO)) {
+                       for (x = 0; x < blen; x++) {
+                               if (x < rlen) {
+                                       *(tp++) = *(fp + x);
+                               } else {
+                                       *(tp++) = 0;
+                               }
+                               if (x < wlen) {
+                                       *(tp++) = *(dp + x);
+                               } else {
+                                       *(tp++) = 0;
+                               }
                        }
-                       if (x < wlen) {
-                               z += (int32_t) *(dp + x);
+                       memcpy(frame->data, tmp, bytes * 2);
+               } else {
+                       for (x = 0; x < blen; x++) {
+                               int32_t z = 0;
+
+                               if (x < rlen) {
+                                       z += (int32_t) *(fp + x);
+                               }
+                               if (x < wlen) {
+                                       z += (int32_t) *(dp + x);
+                               }
+                               switch_normalize_to_16bit(z);
+                               *(fp + x) = (int16_t) z;
                        }
-                       switch_normalize_to_16bit(z);
-                       *(fp + x) = (int16_t) z;
                }
 
                frame->datalen = bytes;
                frame->samples = bytes / sizeof(int16_t);
                frame->rate = read_codec->implementation->samples_per_second;
-
+               
                return SWITCH_STATUS_SUCCESS;
        }
 
index 10c5387c4848fa77e95ae46f1433fc164309038a..ac571f80ca67d074f84e61d12c158f22148c9e9c 100644 (file)
@@ -302,7 +302,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
        switch_media_bug_t *bug;
        switch_status_t status;
        time_t to = 0;
-
+       switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM;
+       int channels;
        channel = switch_core_session_get_channel(session);
        assert(channel != NULL);
 
@@ -317,19 +318,26 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
                }
        }
 
-
        read_codec = switch_core_session_get_read_codec(session);
        assert(read_codec != NULL);
 
-       fh->channels = read_codec->implementation->number_of_channels;
+       channels = read_codec->implementation->number_of_channels;
+
+       if ((p = switch_channel_get_variable(channel, "RECORD_STEREO")) && switch_true(p)) {
+               flags |= SMBF_STEREO;
+               channels = 2;
+       }
+       
+       fh->channels = channels;
        fh->samplerate = read_codec->implementation->samples_per_second;
 
 
        if (switch_core_file_open(fh,
                                                          file,
-                                                         read_codec->implementation->number_of_channels,
+                                                         channels,
                                                          read_codec->implementation->samples_per_second,
                                                          SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", file);
                switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
                switch_core_session_reset(session);
                return SWITCH_STATUS_GENERR;
@@ -376,8 +384,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
        if (limit) {
                to = time(NULL) + limit;
        }
-
-       if ((status = switch_core_media_bug_add(session, record_callback, fh, to, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) {
+       
+       if ((status = switch_core_media_bug_add(session, record_callback, fh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error adding media bug for file %s\n", file);
                switch_core_file_close(fh);
                return status;
        }