mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
re-implement sla barge using eavesdrop backend
This commit is contained in:
@@ -72,6 +72,9 @@ SWITCH_DECLARE(uint32_t) switch_core_media_bug_test_flag(switch_media_bug_t *bug
|
||||
|
||||
SWITCH_DECLARE(uint32_t) switch_core_media_bug_set_flag(switch_media_bug_t *bug, uint32_t flag)
|
||||
{
|
||||
if ((flag & SMBF_PRUNE)) {
|
||||
switch_clear_flag(bug, SMBF_LOCK);
|
||||
}
|
||||
return switch_set_flag(bug, flag);
|
||||
}
|
||||
|
||||
@@ -105,6 +108,11 @@ SWITCH_DECLARE(void) switch_core_media_bug_set_read_replace_frame(switch_media_b
|
||||
bug->read_replace_frame_out = frame;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_core_media_bug_set_read_demux_frame(switch_media_bug_t *bug, switch_frame_t *frame)
|
||||
{
|
||||
bug->read_demux_frame = frame;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *bug)
|
||||
{
|
||||
return bug->user_data;
|
||||
@@ -175,6 +183,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
||||
|
||||
bytes = read_impl.decoded_bytes_per_packet;
|
||||
|
||||
if (0 && bug->session->recur_buffer_len) {
|
||||
frame->datalen = bug->session->recur_buffer_len;
|
||||
frame->samples = bug->session->recur_buffer_len / sizeof(int16_t);
|
||||
frame->rate = read_impl.actual_samples_per_second;
|
||||
frame->codec = NULL;
|
||||
memcpy(frame->data, bug->session->recur_buffer, bug->session->recur_buffer_len);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (frame->buflen < bytes) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "%s frame buffer too small!\n",
|
||||
switch_channel_get_name(bug->session->channel));
|
||||
@@ -363,6 +381,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
|
||||
memcpy(bug->session->recur_buffer, frame->data, frame->datalen);
|
||||
bug->session->recur_buffer_len = frame->datalen;
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -552,6 +573,53 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_recordings(switch
|
||||
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_pop(switch_core_session_t *orig_session, const char *function, switch_media_bug_t **pop)
|
||||
{
|
||||
switch_media_bug_t *bp;
|
||||
|
||||
if (orig_session->bugs) {
|
||||
switch_thread_rwlock_wrlock(orig_session->bug_rwlock);
|
||||
for (bp = orig_session->bugs; bp; bp = bp->next) {
|
||||
if (!strcmp(bp->function, function)) {
|
||||
switch_set_flag(bp, SMBF_LOCK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch_thread_rwlock_unlock(orig_session->bug_rwlock);
|
||||
|
||||
if (bp) {
|
||||
*pop = bp;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else {
|
||||
*pop = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_exec_all(switch_core_session_t *orig_session,
|
||||
const char *function, switch_media_bug_exec_cb_t cb, void *user_data)
|
||||
{
|
||||
switch_media_bug_t *bp;
|
||||
int x = 0;
|
||||
|
||||
switch_assert(cb);
|
||||
|
||||
if (orig_session->bugs) {
|
||||
switch_thread_rwlock_wrlock(orig_session->bug_rwlock);
|
||||
for (bp = orig_session->bugs; bp; bp = bp->next) {
|
||||
if (!switch_test_flag(bp, SMBF_PRUNE) && !switch_test_flag(bp, SMBF_LOCK) && !strcmp(bp->function, function)) {
|
||||
cb(bp, user_data);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
switch_thread_rwlock_unlock(orig_session->bug_rwlock);
|
||||
}
|
||||
|
||||
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_media_bug_t *bp;
|
||||
@@ -579,7 +647,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_sess
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session)
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all_function(switch_core_session_t *session, const char *function)
|
||||
{
|
||||
switch_media_bug_t *bp;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
@@ -587,10 +655,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
|
||||
if (session->bugs) {
|
||||
switch_thread_rwlock_wrlock(session->bug_rwlock);
|
||||
for (bp = session->bugs; bp; bp = bp->next) {
|
||||
if (bp->thread_id && bp->thread_id != switch_thread_self()) {
|
||||
if ((bp->thread_id && bp->thread_id != switch_thread_self()) || switch_test_flag(bp, SMBF_LOCK)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "BUG is thread locked skipping.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!zstr(function) && strcmp(bp->function, function)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (bp->callback) {
|
||||
bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE);
|
||||
@@ -614,7 +687,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t *
|
||||
{
|
||||
switch_media_bug_t *bp = *bug;
|
||||
if (bp) {
|
||||
if (bp->thread_id && bp->thread_id != switch_thread_self()) {
|
||||
if ((bp->thread_id && bp->thread_id != switch_thread_self()) || switch_test_flag(bp, SMBF_LOCK)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(*bug)), SWITCH_LOG_DEBUG, "BUG is thread locked skipping.\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
@@ -637,6 +710,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
|
||||
{
|
||||
switch_media_bug_t *bp = NULL, *last = NULL;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
if (switch_core_media_bug_test_flag(*bug, SMBF_LOCK)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
switch_thread_rwlock_wrlock(session->bug_rwlock);
|
||||
if (session->bugs) {
|
||||
|
||||
Reference in New Issue
Block a user