change timing for media bug recording *yet again*
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14143 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4f6f7d285b
commit
0907bbbc63
|
@ -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
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue