mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-07 23:21:14 +00:00
add record overwrite
This commit is contained in:
parent
e10bc0a965
commit
17ac6ba9c6
@ -1307,7 +1307,8 @@ typedef enum {
|
|||||||
SWITCH_FILE_CALLBACK = (1 << 12),
|
SWITCH_FILE_CALLBACK = (1 << 12),
|
||||||
SWITCH_FILE_DONE = (1 << 13),
|
SWITCH_FILE_DONE = (1 << 13),
|
||||||
SWITCH_FILE_BUFFER_DONE = (1 << 14),
|
SWITCH_FILE_BUFFER_DONE = (1 << 14),
|
||||||
SWITCH_FILE_WRITE_APPEND = (1 << 15)
|
SWITCH_FILE_WRITE_APPEND = (1 << 15),
|
||||||
|
SWITCH_FILE_WRITE_OVER = (1 << 16)
|
||||||
} switch_file_flag_enum_t;
|
} switch_file_flag_enum_t;
|
||||||
typedef uint32_t switch_file_flag_t;
|
typedef uint32_t switch_file_flag_t;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ static switch_status_t native_file_file_open(switch_file_handle_t *handle, const
|
|||||||
|
|
||||||
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
flags |= SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE;
|
flags |= SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE;
|
||||||
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
|
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(handle, SWITCH_FILE_WRITE_OVER)) {
|
||||||
flags |= SWITCH_FOPEN_READ;
|
flags |= SWITCH_FOPEN_READ;
|
||||||
} else {
|
} else {
|
||||||
flags |= SWITCH_FOPEN_TRUNCATE;
|
flags |= SWITCH_FOPEN_TRUNCATE;
|
||||||
|
@ -82,7 +82,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
|
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(handle, SWITCH_FILE_WRITE_OVER)) {
|
||||||
mode += SFM_RDWR;
|
mode += SFM_RDWR;
|
||||||
} else {
|
} else {
|
||||||
mode += SFM_WRITE;
|
mode += SFM_WRITE;
|
||||||
@ -208,6 +208,8 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
|
|||||||
|
|
||||||
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
|
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
|
||||||
handle->pos = sf_seek(context->handle, 0, SEEK_END);
|
handle->pos = sf_seek(context->handle, 0, SEEK_END);
|
||||||
|
} else if (switch_test_flag(handle, SWITCH_FILE_WRITE_OVER)) {
|
||||||
|
handle->pos = sf_seek(context->handle, 0, SEEK_SET);
|
||||||
} else {
|
} else {
|
||||||
sf_count_t frames = 0;
|
sf_count_t frames = 0;
|
||||||
sf_command(context->handle, SFC_FILE_TRUNCATE, &frames, sizeof(frames));
|
sf_command(context->handle, SFC_FILE_TRUNCATE, &frames, sizeof(frames));
|
||||||
|
@ -407,39 +407,56 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
|
SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
|
||||||
{
|
{
|
||||||
size_t bytes = 0;
|
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
|
int ok = 1;
|
||||||
|
|
||||||
switch_assert(fh != NULL);
|
switch_assert(fh != NULL);
|
||||||
switch_assert(fh->file_interface != NULL);
|
switch_assert(fh->file_interface != NULL);
|
||||||
|
|
||||||
if (!switch_test_flag(fh, SWITCH_FILE_OPEN) || !switch_test_flag(fh, SWITCH_FILE_FLAG_READ)) {
|
if (!switch_test_flag(fh, SWITCH_FILE_OPEN) || !fh->file_interface->file_seek) {
|
||||||
return SWITCH_STATUS_FALSE;
|
ok = 0;
|
||||||
|
} else if (switch_test_flag(fh, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
|
if (!(switch_test_flag(fh, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(fh, SWITCH_FILE_WRITE_OVER))) {
|
||||||
|
ok = 0;
|
||||||
|
}
|
||||||
|
} else if (!switch_test_flag(fh, SWITCH_FILE_FLAG_READ)) {
|
||||||
|
ok = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fh->file_interface->file_seek) {
|
if (!ok) {
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fh->buffer) {
|
if (fh->buffer) {
|
||||||
bytes += switch_buffer_inuse(fh->buffer);
|
|
||||||
switch_buffer_zero(fh->buffer);
|
switch_buffer_zero(fh->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fh->pre_buffer) {
|
if (fh->pre_buffer) {
|
||||||
bytes += switch_buffer_inuse(fh->pre_buffer);
|
|
||||||
switch_buffer_zero(fh->pre_buffer);
|
switch_buffer_zero(fh->pre_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whence == SWITCH_SEEK_CUR) {
|
if (whence == SWITCH_SEEK_CUR) {
|
||||||
samples -= bytes / sizeof(int16_t);
|
unsigned int cur = 0;
|
||||||
|
|
||||||
|
if (switch_test_flag(fh, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
|
fh->file_interface->file_seek(fh, &cur, fh->samples_out, SEEK_SET);
|
||||||
|
} else {
|
||||||
|
fh->file_interface->file_seek(fh, &cur, fh->offset_pos, SEEK_SET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_set_flag(fh, SWITCH_FILE_SEEK);
|
switch_set_flag(fh, SWITCH_FILE_SEEK);
|
||||||
status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
|
status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
|
||||||
|
|
||||||
if (samples) {
|
if (samples) {
|
||||||
fh->offset_pos = *cur_pos;
|
fh->offset_pos = *cur_pos;
|
||||||
|
|
||||||
|
if (switch_test_flag(fh, SWITCH_FILE_FLAG_WRITE)) {
|
||||||
|
fh->samples_out = *cur_pos;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +364,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||||||
time_t start = 0;
|
time_t start = 0;
|
||||||
uint32_t org_silence_hits = 0;
|
uint32_t org_silence_hits = 0;
|
||||||
int asis = 0;
|
int asis = 0;
|
||||||
|
int32_t sample_start = 0;
|
||||||
int waste_resources = 0, fill_cng = 0;
|
int waste_resources = 0, fill_cng = 0;
|
||||||
switch_codec_implementation_t read_impl = { 0 };
|
switch_codec_implementation_t read_impl = { 0 };
|
||||||
switch_frame_t write_frame = { 0 };
|
switch_frame_t write_frame = { 0 };
|
||||||
@ -405,6 +406,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||||||
fh->channels = read_impl.number_of_channels;
|
fh->channels = read_impl.number_of_channels;
|
||||||
fh->native_rate = read_impl.actual_samples_per_second;
|
fh->native_rate = read_impl.actual_samples_per_second;
|
||||||
|
|
||||||
|
if (fh->samples > 0) {
|
||||||
|
sample_start = fh->samples;
|
||||||
|
fh->samples = 0;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -497,6 +503,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||||||
file_flags |= SWITCH_FILE_WRITE_APPEND;
|
file_flags |= SWITCH_FILE_WRITE_APPEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_test_flag(fh, SWITCH_FILE_WRITE_OVER) || ((p = switch_channel_get_variable(channel, "RECORD_WRITE_OVER")) && switch_true(p))) {
|
||||||
|
file_flags |= SWITCH_FILE_WRITE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fh->prefix) {
|
if (!fh->prefix) {
|
||||||
fh->prefix = prefix;
|
fh->prefix = prefix;
|
||||||
}
|
}
|
||||||
@ -507,6 +517,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sample_start > 0) {
|
||||||
|
uint32_t pos = 0;
|
||||||
|
switch_core_file_seek(fh, &pos, sample_start, SEEK_SET);
|
||||||
|
switch_clear_flag(fh, SWITCH_FILE_SEEK);
|
||||||
|
fh->samples = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
|
if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
|
||||||
asis = 1;
|
asis = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user