]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Mar 2007 22:49:58 +0000 (22:49 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Mar 2007 22:49:58 +0000 (22:49 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4613 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/mod/applications/mod_conference/mod_conference.c
src/switch_core.c

index 3a545ff68e1513d466773cab97042dc751e239cc..14fecdd7b9c31bf3b3dcddc333cd42eef9eb8e61 100644 (file)
@@ -732,6 +732,7 @@ SWITCH_FILE_DATA_RAW =          (1 <<  7) - Read data as is
 SWITCH_FILE_PAUSE =             (1 <<  8) - Pause
 SWITCH_FILE_NATIVE =            (1 <<  9) - File is in native format (no transcoding)
 SWITCH_FILE_SEEK =                             (1 << 10) - File has done a seek
+SWITCH_FILE_OPEN =              (1 << 11) - File is open
 </pre>
  */
 typedef enum {
@@ -745,7 +746,8 @@ typedef enum {
        SWITCH_FILE_DATA_RAW =                  (1 <<  7),
        SWITCH_FILE_PAUSE =                             (1 <<  8),
        SWITCH_FILE_NATIVE =                    (1 <<  9),
-       SWITCH_FILE_SEEK =                              (1 << 10)
+       SWITCH_FILE_SEEK =                              (1 << 10),
+       SWITCH_FILE_OPEN =                              (1 << 11)
 } switch_file_flag_t;
 
 typedef enum {
index 4f06508f0d2e49bb5c51a64fb66cda963e57ee46..ac0fc4209af8498343cc7b5e3dc9e4ef1530c1b9 100644 (file)
@@ -1724,22 +1724,30 @@ static void conference_loop_output(conference_member_t *member)
 /* Sub-Routine called by a record entity inside a conference */
 static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, void *obj)
 {
-       switch_frame_t write_frame = {0};
        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
        switch_file_handle_t fh = {0};
        conference_member_t smember = {0}, *member;
        conference_record_t *rec = (conference_record_t *) obj;
        conference_obj_t *conference = rec->conference;
        uint32_t samples = switch_bytes_per_frame(conference->rate, conference->interval);
-       uint32_t bytes = samples * 2;
-       uint32_t mux_used;
+       //uint32_t bytes = samples * 2;
+       uint32_t low_count = 0, mux_used;
        char *vval;
+       switch_timer_t timer = {0};
+       uint32_t rlen;
 
        if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
                return NULL;
        }
 
+       if (switch_core_timer_init(&timer, conference->timer_name, conference->interval, samples, rec->pool) == SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success interval: %u  samples: %u\n", conference->interval, samples);      
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");      
+               return NULL;
+       }
+       
        switch_mutex_lock(globals.hash_mutex);
        globals.threads++;
        switch_mutex_unlock(globals.hash_mutex);                
@@ -1748,9 +1756,6 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
 
        member->flags = MFLAG_CAN_HEAR | MFLAG_NOCHANNEL | MFLAG_RUNNING;
 
-       write_frame.data = data;
-       write_frame.buflen = sizeof(data);
-
        member->conference = conference;
        member->native_rate = conference->rate;
        member->rec_path = rec->path;
@@ -1796,29 +1801,45 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
        }
 
        while(switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
-               if ((mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer)) >= bytes) {
+               mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
+
+               if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
+                       if (mux_used) {
+                               switch_mutex_lock(member->audio_out_mutex);
+                               switch_buffer_zero(member->mux_buffer);
+                               switch_mutex_unlock(member->audio_out_mutex);
+                               mux_used = 0;
+                       }
+                       switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
+               }
+
+               if (mux_used) {
                        /* Flush the output buffer and write all the data (presumably muxed) to the file */
                        switch_mutex_lock(member->audio_out_mutex);
-                       write_frame.data = data;
-                       while ((write_frame.datalen = (uint32_t)switch_buffer_read(member->mux_buffer, write_frame.data, mux_used))) {
+                       low_count = 0;
+                       
+                       if ((rlen = (uint32_t)switch_buffer_read(member->mux_buffer, data, sizeof(data)))) {
                                if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
-                                       switch_size_t len = (switch_size_t) mux_used / 2;
-                                       switch_core_file_write(&fh, write_frame.data, &len);
+                                       switch_size_t len = (switch_size_t) rlen / sizeof(int16_t);
+                                       if (switch_core_file_write(&fh, data, &len) != SWITCH_STATUS_SUCCESS) {
+                                               goto end;
+                                       }
                                }
                        }
                        switch_mutex_unlock(member->audio_out_mutex);
                } else {
-                       switch_yield(20000);
+                       switch_core_timer_next(&timer);
                }
        } /* Rinse ... Repeat */
 
  end:
 
+       switch_core_timer_destroy(&timer);
        conference_del_member(conference, member);
        switch_buffer_destroy(&member->audio_buffer);
        switch_buffer_destroy(&member->mux_buffer);
        switch_clear_flag_locked(member, MFLAG_RUNNING);
-       if (fh.fd) {
+       if (switch_test_flag((&fh), SWITCH_FILE_OPEN)) {
                switch_core_file_close(&fh);
        }
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recording Stopped\n");
@@ -2293,7 +2314,6 @@ static void conference_list(conference_obj_t *conference, switch_stream_handle_t
         uint32_t count = 0;
 
         if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "continue\n");
             continue;
         }
 
index e7624372abcfd0ee53d035b0ccc335eb45ad9d3c..770c01e93ca22ecdb2789f3b447452144212baf5 100644 (file)
@@ -1025,7 +1025,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh,
        switch_status_t status;
        char stream_name[128] = "";
        char *rhs = NULL;
-
+       
        if ((rhs = strstr(file_path, SWITCH_URL_SEPARATOR))) {
                switch_copy_string(stream_name, file_path, (rhs+1) - file_path);
                ext = stream_name;
@@ -1069,7 +1069,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh,
                fh->channels = 1;
        }
 
-       return fh->file_interface->file_open(fh, file_path);
+       if ((status = fh->file_interface->file_open(fh, file_path)) == SWITCH_STATUS_SUCCESS) {
+               switch_set_flag(fh, SWITCH_FILE_OPEN);
+       }
+
+       return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh, void *data, switch_size_t *len)
@@ -1113,7 +1117,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
 {
+       switch_clear_flag(fh, SWITCH_FILE_OPEN);
        return fh->file_interface->file_close(fh);
+
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_directory_open(switch_directory_handle_t *dh,