]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3147 --resolve I finally tracked this down to the actual recordings generated...
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 31 Mar 2011 00:17:54 +0000 (19:17 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 31 Mar 2011 00:17:54 +0000 (19:17 -0500)
src/mod/applications/mod_conference/mod_conference.c

index ef3000d287bfb185e58631fa44b49bff22333292..e198d8aa74d14413207432f11e6231667b144b71 100644 (file)
@@ -2823,6 +2823,9 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
        uint32_t rlen;
        switch_size_t data_buf_len;
        switch_event_t *event;
+       int no_data = 0;
+       int lead_in = 20;
+       switch_size_t len = 0;
 
        data_buf_len = samples * sizeof(int16_t);
 
@@ -2910,9 +2913,15 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
                switch_event_fire(&event);
        }
 
-
        while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
-               switch_size_t len = 0;
+
+               len = 0;
+
+               if (lead_in) {
+                       lead_in--;
+                       goto loop;
+               }
+               
                mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
 
                if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
@@ -2925,36 +2934,64 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
                        switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
                }
 
+       again:
+
                if (switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
                        switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
-               } else {
-                       if (mux_used) {
-                               /* Flush the output buffer and write all the data (presumably muxed) to the file */
-                               switch_mutex_lock(member->audio_out_mutex);
-                               low_count = 0;
+                       goto loop;
+               }
 
-                               if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) {
-                                       len = (switch_size_t) rlen / sizeof(int16_t);
-                               }
-                               switch_mutex_unlock(member->audio_out_mutex);
+               if (mux_used >= data_buf_len) {
+                       /* Flush the output buffer and write all the data (presumably muxed) to the file */
+                       switch_mutex_lock(member->audio_out_mutex);
+                       low_count = 0;
+
+                       if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) {
+                               len = (switch_size_t) rlen / sizeof(int16_t);
+                               no_data = 0;
                        }
+                       switch_mutex_unlock(member->audio_out_mutex);
+               }
 
-                       if (len < (switch_size_t) samples) {
-                               memset(data_buf + (len * sizeof(int16_t)), 255, ((switch_size_t) samples - len) * sizeof(int16_t));
-                               len = (switch_size_t) samples;
+               if (len == 0) {
+                       mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
+                               
+                       if (mux_used >= data_buf_len) {
+                               goto again;
                        }
 
-                       if (!len || switch_core_file_write(&fh, data_buf, &len) != SWITCH_STATUS_SUCCESS) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write Failed\n");
-                               switch_clear_flag_locked(member, MFLAG_RUNNING);
+                       if (++no_data < 2) {
+                               goto loop;
                        }
+
+                       memset(data_buf, 255, (switch_size_t) data_buf_len);
+                       len = (switch_size_t) samples;
+               }
+
+               if (!len || switch_core_file_write(&fh, data_buf, &len) != SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write Failed\n");
+                       switch_clear_flag_locked(member, MFLAG_RUNNING);
                }
+               
+       loop:
 
                switch_core_timer_next(&timer);
        }                                                       /* Rinse ... Repeat */
 
   end:
 
+       for(;;) {
+               switch_mutex_lock(member->audio_out_mutex);                                                                                    
+               if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) {
+                       len = (switch_size_t) rlen / sizeof(int16_t);
+                       switch_core_file_write(&fh, data_buf, &len);
+               } else {
+                       break;
+               }                                                                                                                                         
+               switch_mutex_unlock(member->audio_out_mutex);
+       }
+
+
        switch_safe_free(data_buf);
        switch_core_timer_destroy(&timer);
        conference_del_member(conference, member);