]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: [mod_fsv] fix fsv sample_count and mux of channels
authorSeven Du <dujinfang@gmail.com>
Wed, 29 Aug 2012 03:35:32 +0000 (11:35 +0800)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:46:41 +0000 (12:46 -0500)
src/mod/applications/mod_fsv/mod_fsv.c

index f95db036a224d1c0bee1c5c2b855c60f124baf54..78b61297a5c3cfa1ecb93915a86a856048f609b2 100644 (file)
@@ -561,8 +561,8 @@ static switch_status_t fsv_file_open(switch_file_handle_t *handle, const char *p
        }
 
        handle->samples = 0;
-       handle->samplerate = 8000;
-       handle->channels = 1;
+       // handle->samplerate = 8000;
+       // handle->channels = 1;
        handle->format = 0;
        handle->sections = 0;
        handle->seekable = 0;
@@ -690,19 +690,33 @@ end:
 
 static switch_status_t fsv_file_write(switch_file_handle_t *handle, void *data, size_t *len)
 {
-       size_t datalen = *len * 2;
+       uint32_t datalen = *len * sizeof(int16_t);
        size_t size;
        switch_status_t status;
+       int16_t *xdata = data;
+       int max_datasize = handle->samplerate / 8000 * 160;
 
        fsv_file_context *context = handle->private_info;
 
-       /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "writing: %ld\n", (long)(*len)); */
+       /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "writing: %ld %d %x\n", (long)(*len), handle->channels, handle->flags); */
 
-       if (*len > 160) { /* when sample rate is 8000 */
+       if (*len > max_datasize) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You are asking to write %d bytes of data which is not supported. Please set enable_file_write_buffering=false to use .fsv format\n", (int)(*len));
                return SWITCH_STATUS_GENERR;
        }
 
+       if (handle->channels > 1) {
+               int i, j;
+               int32_t mixed = 0;
+               for (i=0; i<*len; i++) {
+                       for (j = 0; j < handle->channels; j++) {
+                               mixed += xdata[i * handle->channels + j];
+                       }
+                       switch_normalize_to_16bit(mixed);
+                       xdata[i] = (uint16_t)mixed;
+               }
+       }
+
        switch_mutex_lock(context->mutex);
 
        size = sizeof(datalen);
@@ -715,6 +729,8 @@ static switch_status_t fsv_file_write(switch_file_handle_t *handle, void *data,
        status =  switch_file_write(context->fd, data, len);
        switch_mutex_unlock(context->mutex);
 
+       handle->sample_count += *len / sizeof(int16_t);
+
        return status;
 }
 
@@ -740,6 +756,9 @@ static switch_status_t fsv_file_write_video(switch_file_handle_t *handle, void *
        status =  switch_file_write(context->fd, data, len);
        switch_mutex_unlock(context->mutex);
 
+       *len /= 2;
+       handle->sample_count += *len;
+
        return status;
 }