mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-06 02:22:56 +00:00
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_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
|
\brief Obtain private data from a media bug
|
||||||
\param bug the bug to get the data from
|
\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_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;
|
switch_size_t bytes = 0, datalen = 0, ttl = 0;
|
||||||
@ -130,13 +149,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
|||||||
frame->flags = 0;
|
frame->flags = 0;
|
||||||
frame->datalen = 0;
|
frame->datalen = 0;
|
||||||
|
|
||||||
|
if (!switch_buffer_inuse(bug->raw_read_buffer)) {
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
switch_mutex_lock(bug->read_mutex);
|
switch_mutex_lock(bug->read_mutex);
|
||||||
frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, bytes);
|
frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, bytes);
|
||||||
ttl += frame->datalen;
|
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);
|
switch_mutex_unlock(bug->read_mutex);
|
||||||
|
|
||||||
if (switch_test_flag(bug, SMBF_WRITE_STREAM)) {
|
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_clear_flag(session, SSF_WARN_TRANSCODE);
|
||||||
switch_ivr_deactivate_unicast(session);
|
switch_ivr_deactivate_unicast(session);
|
||||||
switch_channel_clear_flag(channel, CF_BREAK);
|
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;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LEAD_IN 25
|
|
||||||
struct record_helper {
|
struct record_helper {
|
||||||
char *file;
|
char *file;
|
||||||
switch_file_handle_t *fh;
|
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)
|
static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
|
||||||
@ -449,20 +449,17 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
|
|||||||
switch_size_t len;
|
switch_size_t len;
|
||||||
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
||||||
switch_frame_t frame = { 0 };
|
switch_frame_t frame = { 0 };
|
||||||
int cnt = LEAD_IN;
|
|
||||||
|
|
||||||
frame.data = data;
|
frame.data = data;
|
||||||
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
||||||
|
|
||||||
for (; cnt; cnt--) {
|
while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
|
||||||
if (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
len = (switch_size_t) frame.datalen / 2;
|
len = (switch_size_t) frame.datalen / 2;
|
||||||
switch_core_file_write(rh->fh, data, &len);
|
if (len) switch_core_file_write(rh->fh, data, &len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_core_file_close(rh->fh);
|
switch_core_file_close(rh->fh);
|
||||||
if (rh->fh->samples_out < read_impl.samples_per_second * 3) {
|
if (rh->fh->samples_out < read_impl.samples_per_second * 3) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
|
||||||
@ -472,10 +469,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SWITCH_ABC_TYPE_READ_PING:
|
case SWITCH_ABC_TYPE_READ:
|
||||||
if (rh->lead_in) {
|
|
||||||
rh->lead_in--;
|
|
||||||
} else
|
|
||||||
|
|
||||||
if (rh->fh) {
|
if (rh->fh) {
|
||||||
switch_size_t len;
|
switch_size_t len;
|
||||||
@ -486,16 +480,12 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
|
|||||||
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
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)) {
|
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;
|
len = (switch_size_t) frame.datalen / 2;
|
||||||
switch_core_file_write(rh->fh, data, &len);
|
if (len) switch_core_file_write(rh->fh, data, &len);
|
||||||
if (switch_test_flag((&frame), SFF_CNG)) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rh->lead_in = LEAD_IN;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SWITCH_ABC_TYPE_WRITE:
|
case SWITCH_ABC_TYPE_WRITE:
|
||||||
default:
|
default:
|
||||||
@ -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 = switch_core_session_alloc(session, sizeof(*rh));
|
||||||
rh->fh = fh;
|
rh->fh = fh;
|
||||||
rh->file = switch_core_session_strdup(session, file);
|
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"))) {
|
if ((vval = switch_channel_get_variable(channel, "record_sample_rate"))) {
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user