fix recording timing issue
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14128 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
d85f73d1dd
commit
3f55e02c44
|
@ -104,7 +104,7 @@ SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
|
|||
|
||||
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;
|
||||
switch_size_t bytes = 0, datalen = 0, ttl = 0;
|
||||
int16_t *dp, *fp;
|
||||
uint32_t x;
|
||||
size_t rlen = 0;
|
||||
|
@ -127,10 +127,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
|||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
frame->flags = 0;
|
||||
frame->datalen = 0;
|
||||
|
||||
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;
|
||||
|
@ -141,6 +143,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
|||
switch_assert(bug->raw_write_buffer);
|
||||
switch_mutex_lock(bug->write_mutex);
|
||||
datalen = (uint32_t) switch_buffer_read(bug->raw_write_buffer, bug->data, bytes);
|
||||
ttl += datalen;
|
||||
if (fill && datalen < bytes) {
|
||||
memset(((unsigned char *)bug->data) + datalen, 0, bytes - datalen);
|
||||
datalen = bytes;
|
||||
|
@ -192,6 +195,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
|||
}
|
||||
}
|
||||
|
||||
if (!ttl) {
|
||||
switch_set_flag(frame, SFF_CNG);
|
||||
}
|
||||
|
||||
frame->datalen = bytes;
|
||||
frame->samples = bytes / sizeof(int16_t);
|
||||
frame->rate = read_impl.actual_samples_per_second;
|
||||
|
|
|
@ -486,11 +486,12 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
|
|||
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)) {
|
||||
int loops = LEAD_IN;
|
||||
while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && frame.datalen) {
|
||||
len = (switch_size_t) frame.datalen / 2;
|
||||
switch_core_file_write(rh->fh, data, &len);
|
||||
if (!--loops) break;
|
||||
if (switch_test_flag((&frame), SFF_CNG)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rh->lead_in = LEAD_IN;
|
||||
|
|
Loading…
Reference in New Issue