]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7654 #resolve (BACK PORT TO 1.4)
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 13 Jun 2015 04:55:24 +0000 (23:55 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 13 Jun 2015 05:00:15 +0000 (00:00 -0500)
Conflicts:
src/switch_core_io.c
src/switch_ivr_async.c

src/include/switch_resample.h
src/switch_core_io.c
src/switch_ivr_async.c
src/switch_resample.c

index 1d2f6c694b2e8c5964e69258bcfbc4b39cefe20f..c899246f772acec98907a5160a632db3cb378da5 100644 (file)
@@ -171,8 +171,8 @@ SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, i
 SWITCH_DECLARE(void) switch_change_sln_volume_granular(int16_t *data, uint32_t samples, int32_t vol);
 ///\}
 
-SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples);
-SWITCH_DECLARE(uint32_t) switch_unmerge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples);
+SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels);
+SWITCH_DECLARE(uint32_t) switch_unmerge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels);
 SWITCH_DECLARE(void) switch_mux_channels(int16_t *data, switch_size_t samples, uint32_t orig_channels, uint32_t channels);
 
 SWITCH_END_EXTERN_C
index 4c39bbbb425f5db50feca0ad0cd2e8070cc287a2..4d5ffb7c70a6ed51f621d7960295f228390459fe 100644 (file)
@@ -570,6 +570,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                                                                                          session->read_impl.actual_samples_per_second,
                                                                                                          session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate, 
                                                                                                          &read_frame->flags);
+
+                                       session->raw_read_frame.samples = session->raw_read_frame.datalen / 2;
+                                       session->raw_read_frame.channels = codec->implementation->number_of_channels;
                                        codec->cur_frame = NULL;
                                        session->read_codec->cur_frame = NULL;
                                        switch_thread_rwlock_unlock(session->bug_rwlock);
@@ -600,14 +603,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                        }
 
                        /* mux or demux to match */
-                       if (session->read_impl.number_of_channels != read_frame->codec->implementation->number_of_channels) {
-                               uint32_t rlen = session->raw_read_frame.datalen / 2 / read_frame->codec->implementation->number_of_channels;
-                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s MUX READ\n", switch_channel_get_name(session->channel));
-                               switch_mux_channels((int16_t *) session->raw_read_frame.data, rlen, 
-                                                                       read_frame->codec->implementation->number_of_channels, session->read_impl.number_of_channels);
-                               session->raw_write_frame.datalen = rlen * 2 * session->read_impl.number_of_channels;
+                       if (session->raw_read_frame.channels != session->read_impl.number_of_channels) {
+                               uint32_t rlen = session->raw_read_frame.datalen / 2 / session->raw_read_frame.channels;
+                               switch_mux_channels((int16_t *) session->raw_read_frame.data, rlen, session->raw_read_frame.channels, session->read_impl.number_of_channels);
+                               session->raw_read_frame.datalen = rlen * 2 * session->read_impl.number_of_channels;
+                               session->raw_read_frame.samples = session->raw_read_frame.datalen / 2;
+                               session->raw_read_frame.channels = session->read_impl.number_of_channels;
                        }
 
+
                        switch (status) {
                        case SWITCH_STATUS_RESAMPLE:
                                if (!session->read_resampler) {
@@ -788,11 +792,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                        switch_mutex_lock(bp->read_mutex);
                                        if (bp->read_demux_frame) {
                                                uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-                                               int bytes = read_frame->datalen / 2;
+                                               int bytes = read_frame->datalen;
+                                               uint32_t datalen = 0;
+                                               uint32_t samples = bytes / 2 / bp->read_demux_frame->channels;
 
                                                memcpy(data, read_frame->data, read_frame->datalen);
-                                               switch_unmerge_sln((int16_t *)data, bytes, bp->read_demux_frame->data, bytes);
-                                               switch_buffer_write(bp->raw_read_buffer, data, read_frame->datalen);
+                                               datalen = switch_unmerge_sln((int16_t *)data, samples, 
+                                                                                                        bp->read_demux_frame->data, samples, 
+                                                                                                        bp->read_demux_frame->channels) * 2 * bp->read_demux_frame->channels;
+
+                                               switch_buffer_write(bp->raw_read_buffer, data, datalen);
                                        } else {
                                                switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
                                        }
index bc4d724a504d2fdd0bc0d028ac03c7e574d39d61..37f1168ea0b2e5bedd0278a0a71c4adfdba4456a 100644 (file)
@@ -1553,6 +1553,9 @@ struct eavesdrop_pvt {
        switch_core_session_t *eavesdropper;
        uint32_t flags;
        switch_frame_t demux_frame;
+       int errs;
+       switch_codec_implementation_t read_impl;
+       switch_codec_implementation_t tread_impl;
        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
 };
 
@@ -1599,18 +1602,21 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
                                        switch_buffer_lock(ep->r_buffer);
                                        bytes = (uint32_t) switch_buffer_read(ep->r_buffer, ep->data, rframe->datalen);
 
-                                       rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) ep->data, bytes / 2) * 2;
+                                       memcpy(rframe->data, ep->data, rframe->datalen);
+                                       rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) ep->data, bytes / 2, rframe->channels) * 2 * rframe->channels;
                                        rframe->samples = rframe->datalen / 2;
 
                                        ep->demux_frame.data = ep->data;
                                        ep->demux_frame.datalen = bytes;
                                        ep->demux_frame.samples = bytes / 2;
-                                       
+                                       ep->demux_frame.channels = rframe->channels;
+
                                        switch_buffer_unlock(ep->r_buffer);
                                        switch_core_media_bug_set_read_replace_frame(bug, rframe);
                                        switch_core_media_bug_set_read_demux_frame(bug, &ep->demux_frame);
                                }
                        }
+
                }
                break;
 
@@ -1624,7 +1630,7 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
                                        switch_buffer_lock(ep->w_buffer);
                                        bytes = (uint32_t) switch_buffer_read(ep->w_buffer, data, rframe->datalen);
 
-                                       rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) data, bytes / 2) * 2;
+                                       rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) data, bytes / 2, rframe->channels) * 2 * rframe->channels;
                                        rframe->samples = rframe->datalen / 2;
 
                                        switch_buffer_unlock(ep->w_buffer);
@@ -1759,6 +1765,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                switch_caller_profile_t *cp = NULL;
                uint32_t sanity = 600;
                switch_media_bug_flag_t read_flags = 0, write_flags = 0;
+               int buf_size;
 
                if (!switch_channel_media_up(channel)) {
                        goto end;
@@ -1840,6 +1847,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                        goto end;
                }
 
+               switch_core_session_get_read_impl(session, &read_impl);
+
+               ep->read_impl = read_impl;
+               ep->tread_impl = tread_impl;
+
                codec_initialized = 1;
 
                switch_core_session_set_read_codec(session, &codec);
@@ -1847,24 +1859,26 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                write_frame.data = buf;
                write_frame.buflen = sizeof(buf);
                write_frame.rate = codec.implementation->actual_samples_per_second;
-
+               
                /* Make sure that at least one leg is bridged, default to both */
                if (! (flags & (ED_BRIDGE_READ | ED_BRIDGE_WRITE))) {
                        flags |= ED_BRIDGE_READ | ED_BRIDGE_WRITE;
                }
 
+               buf_size = codec.implementation->decoded_bytes_per_packet * 10;
+
                ep->eavesdropper = session;
                ep->flags = flags;
                switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
-               switch_buffer_create_dynamic(&ep->buffer, 2048, 2048, 8192);
+               switch_buffer_create_dynamic(&ep->buffer, buf_size, buf_size, buf_size);
                switch_buffer_add_mutex(ep->buffer, ep->mutex);
 
                switch_mutex_init(&ep->w_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
-               switch_buffer_create_dynamic(&ep->w_buffer, 2048, 2048, 8192);
+               switch_buffer_create_dynamic(&ep->w_buffer, buf_size, buf_size, buf_size);
                switch_buffer_add_mutex(ep->w_buffer, ep->w_mutex);
 
                switch_mutex_init(&ep->r_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
-               switch_buffer_create_dynamic(&ep->r_buffer, 2048, 2048, 8192);
+               switch_buffer_create_dynamic(&ep->r_buffer, buf_size, buf_size, buf_size);
                switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex);
 
 
@@ -2008,6 +2022,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
                                        write_frame.datalen = (uint32_t) switch_buffer_read(ep->buffer, buf, len);
                                        write_frame.samples = write_frame.datalen / 2;
 
+                                       if (ep->tread_impl.number_of_channels != ep->read_impl.number_of_channels) {
+                                               uint32_t rlen = write_frame.datalen / 2 / ep->tread_impl.number_of_channels;
+                                               switch_mux_channels((int16_t *) write_frame.data, rlen, ep->tread_impl.number_of_channels, ep->read_impl.number_of_channels);
+                                               write_frame.datalen = rlen * 2 * ep->read_impl.number_of_channels;
+                                               write_frame.samples = write_frame.datalen / 2;
+                                       }
+                                       
                                        if ((status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0)) != SWITCH_STATUS_SUCCESS) {
                                                break;
                                        }
index ed584e39af57ba886d0bbf026ea6f788f57961d6..2f12c1cadeedf188d45cbbe289f2075717a49dc0 100644 (file)
@@ -215,18 +215,20 @@ SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples
        }
 }
 
-SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples)
+SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels)
 {
        int i;
        int32_t x, z;
 
+       if (channels == 0) channels = 1;
+
        if (samples > other_samples) {
                x = other_samples;
        } else {
                x = samples;
        }
 
-       for (i = 0; i < x; i++) {
+       for (i = 0; i < x * channels; i++) {
                z = data[i] + other_data[i];
                switch_normalize_to_16bit(z);
                data[i] = (int16_t) z;
@@ -236,18 +238,20 @@ SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16
 }
 
 
-SWITCH_DECLARE(uint32_t) switch_unmerge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples)
+SWITCH_DECLARE(uint32_t) switch_unmerge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels)
 {
        int i;
        int32_t x;
 
+       if (channels == 0) channels = 1;
+
        if (samples > other_samples) {
                x = other_samples;
        } else {
                x = samples;
        }
 
-       for (i = 0; i < x; i++) {
+       for (i = 0; i < x * channels; i++) {
                data[i] -= other_data[i];
        }