]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
change timing for media bug recording *yet again*
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 6 Jul 2009 22:21:45 +0000 (22:21 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 6 Jul 2009 22:21:45 +0000 (22:21 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14143 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/switch_core_media_bug.c
src/switch_core_session.c
src/switch_ivr_async.c

index 2f987ef3b4fcc26cd34f73722136982a35c3cc12..9a576a2591ab2813f3f77afd1f6d0d3e33583dea 100644 (file)
@@ -156,6 +156,8 @@ SWITCH_DECLARE(void) switch_core_media_bug_pause(switch_core_session_t *session)
 */
 SWITCH_DECLARE(void) switch_core_media_bug_resume(switch_core_session_t *session);
 
+SWITCH_DECLARE(void) switch_core_media_bug_inuse(switch_media_bug_t *bug, switch_size_t *readp, switch_size_t *writep);
+
 /*!
   \brief Obtain private data from a media bug
   \param bug the bug to get the data from
index 6d47806f41b09b921160e2102ad2512b7e6ea25a..7ef931c004ea42d00168f736ba2f9e47dbe4921f 100644 (file)
@@ -102,6 +102,25 @@ SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
        }
 }
 
+SWITCH_DECLARE(void) switch_core_media_bug_inuse(switch_media_bug_t *bug, switch_size_t *readp, switch_size_t *writep)
+{
+       if (switch_test_flag(bug, SMBF_READ_STREAM)) {
+               switch_mutex_lock(bug->read_mutex);
+               *readp = bug->raw_read_buffer ? switch_buffer_inuse(bug->raw_read_buffer) : 0;
+               switch_mutex_unlock(bug->read_mutex);
+       } else {
+               *readp = 0;
+       }
+
+       if (switch_test_flag(bug, SMBF_WRITE_STREAM)) {
+               switch_mutex_lock(bug->write_mutex);
+               *writep = bug->raw_write_buffer ? switch_buffer_inuse(bug->raw_write_buffer) : 0;
+               switch_mutex_unlock(bug->write_mutex);
+       } else {
+               *writep = 0;
+       }
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame, switch_bool_t fill)
 {
        switch_size_t bytes = 0, datalen = 0, ttl = 0;
@@ -129,14 +148,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
 
        frame->flags = 0;
        frame->datalen = 0;
-       
+
+       if (!switch_buffer_inuse(bug->raw_read_buffer)) {
+               return SWITCH_STATUS_FALSE;
+       }
+
        switch_mutex_lock(bug->read_mutex);
        frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, bytes);
        ttl += frame->datalen;
-       if (fill && frame->datalen < bytes) {
-               memset(((unsigned char *)frame->data) + frame->datalen, 0, bytes - frame->datalen);
-               frame->datalen = bytes;
-       }
        switch_mutex_unlock(bug->read_mutex);
        
        if (switch_test_flag(bug, SMBF_WRITE_STREAM)) {
index a924966e2644e23f177287c5b8f2622b307b407d..e266d2035c9b3e4a6e9b61fe9346ddbcd1e5d049 100644 (file)
@@ -898,7 +898,6 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
        switch_clear_flag(session, SSF_WARN_TRANSCODE);
        switch_ivr_deactivate_unicast(session);
        switch_channel_clear_flag(channel, CF_BREAK);
-       switch_core_media_bug_flush_all(session);
 }
 
 
index 6dfbe5624f32b84b66787e3d7a35e74c060799ed..b540868bee13233a8cebcc829ed2691eb9807ec8 100644 (file)
@@ -420,11 +420,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define LEAD_IN 25
+
 struct record_helper {
        char *file;
        switch_file_handle_t *fh;
-       int lead_in;
+       uint32_t packet_len;
 };
 
 static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
@@ -449,18 +449,15 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
                                        switch_size_t len;
                                        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
                                        switch_frame_t frame = { 0 };
-                                       int cnt = LEAD_IN;
+                                       
                                        
                                        frame.data = data;
                                        frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
                                        
-                                       for (; cnt; cnt--) {
-                                               if (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
-                                                       len = (switch_size_t) frame.datalen / 2;
-                                                       switch_core_file_write(rh->fh, data, &len);
-                                               } 
+                                       while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
+                                               len = (switch_size_t) frame.datalen / 2;
+                                               if (len) switch_core_file_write(rh->fh, data, &len);
                                        }
-                                                  
                                }
 
                                switch_core_file_close(rh->fh);
@@ -472,29 +469,22 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
                }
 
                break;
-       case SWITCH_ABC_TYPE_READ_PING:
-               if (rh->lead_in) {
-                       rh->lead_in--;
-               } else
-
+       case SWITCH_ABC_TYPE_READ:
+               
                if (rh->fh) {
                        switch_size_t len;
                        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
                        switch_frame_t frame = { 0 };
-                       
+
                        frame.data = data;
                        frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
+                       
                        if (switch_channel_test_flag(channel, CF_ANSWERED) || !switch_core_media_bug_test_flag(bug, SMBF_RECORD_ANSWER_REQ)) {
-                               while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && frame.datalen) {
+                               while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
                                        len = (switch_size_t) frame.datalen / 2;
-                                       switch_core_file_write(rh->fh, data, &len);
-                                       if (switch_test_flag((&frame), SFF_CNG)) {
-                                               break;
-                                       }
+                                       if (len) switch_core_file_write(rh->fh, data, &len);
                                }
                        }
-                       rh->lead_in = LEAD_IN;
                }
                break;
        case SWITCH_ABC_TYPE_WRITE:
@@ -890,7 +880,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
        }
 
        channels = read_impl.number_of_channels;
-
+       
        if ((bug = switch_channel_get_private(channel, file))) {
                return switch_ivr_stop_record_session(session, file);
        }
@@ -905,7 +895,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
                flags |= SMBF_STEREO;
                channels = 2;
        }
-
+               
        if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) {
                flags |= SMBF_RECORD_ANSWER_REQ;
        }
@@ -968,8 +958,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
        rh = switch_core_session_alloc(session, sizeof(*rh));
        rh->fh = fh;
        rh->file = switch_core_session_strdup(session, file);
-       rh->lead_in = LEAD_IN;
-
+       rh->packet_len = read_impl.decoded_bytes_per_packet;
 
        if ((vval = switch_channel_get_variable(channel, "record_sample_rate"))) {
                int tmp = 0;