switch_assert(session != NULL);
+ tap_only = switch_test_flag(session, SSF_MEDIA_BUG_TAP_ONLY);
switch_os_yield();
goto done;
}
-
- if (session->bugs && !((*frame)->flags & SFF_NOT_AUDIO) && !((*frame)->flags & SFF_CNG)) {
+ if (session->bugs && !((*frame)->flags & SFF_CNG) && !((*frame)->flags & SFF_NOT_AUDIO)) {
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
- tap_only = 1;
-
switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
}
if (bp->ready) {
- if (!switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) {
- printf("FUCKER\n\n\n");
- tap_only = 0;
- }
-
if (switch_test_flag(bp, SMBF_TAP_NATIVE_READ)) {
if (bp->callback) {
bp->native_read_frame = *frame;
do_resample = 1;
}
- if (session->bugs && !need_codec) {
+ if (tap_only) {
+ switch_media_bug_t *bp;
+ switch_bool_t ok = SWITCH_TRUE;
+ int prune = 0;
+
+ need_codec = 0;
+ do_resample = 0;
+ do_bugs = 0;
+
+ if (session->bugs && switch_test_flag(*frame, SFF_CNG)) {
+ switch_thread_rwlock_rdlock(session->bug_rwlock);
+ for (bp = session->bugs; bp; bp = bp->next) {
+ if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) {
+ continue;
+ }
+
+ if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) {
+ continue;
+ }
+ if (switch_test_flag(bp, SMBF_PRUNE)) {
+ prune++;
+ continue;
+ }
+
+ if (bp->ready && (*frame)->codec && (*frame)->codec->implementation && (*frame)->codec->implementation->encoded_bytes_per_packet) {
+ if (switch_test_flag(bp, SMBF_TAP_NATIVE_READ)) {
+ if (bp->callback) {
+ switch_frame_t tmp_frame = {0};
+ unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
+
+ tmp_frame.codec = (*frame)->codec;
+ tmp_frame.datalen = (*frame)->codec->implementation->encoded_bytes_per_packet;
+ tmp_frame.samples = (*frame)->codec->implementation->samples_per_packet;
+ tmp_frame.data = data;
+
+ bp->native_read_frame = &tmp_frame;
+ ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_TAP_NATIVE_READ);
+ bp->native_read_frame = NULL;
+ }
+ }
+ }
+
+ if ((bp->stop_time && bp->stop_time <= switch_epoch_time_now(NULL)) || ok == SWITCH_FALSE) {
+ switch_set_flag(bp, SMBF_PRUNE);
+ prune++;
+ }
+ }
+ switch_thread_rwlock_unlock(session->bug_rwlock);
+
+ if (prune) {
+ switch_core_media_bug_prune(session);
+ }
+
+
+ }
+
+
+ goto done;
+ } else if (session->bugs && !need_codec) {
do_bugs = 1;
need_codec = 1;
}
switch_core_session_t *other_session = NULL;
if (switch_channel_test_flag(switch_core_session_get_channel(session), CF_BRIDGED) &&
switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
- if (other_session->bugs) {
+ if (other_session->bugs && !switch_test_flag(other_session, SSF_MEDIA_BUG_TAP_ONLY)) {
other_session_bugs = 1;
}
switch_core_session_rwunlock(other_session);
need_codec = 0;
}
- if (tap_only) {
- need_codec = 0;
- do_resample = 0;
- do_bugs = 0;
- goto done;
- }
-
-
if (switch_test_flag(session, SSF_READ_TRANSCODE) && !need_codec && switch_core_codec_ready(session->read_codec)) {
switch_core_session_t *other_session;
const char *uuid = switch_channel_get_partner_uuid(switch_core_session_get_channel(session));
}
-
-
-
-
if (status == SWITCH_STATUS_SUCCESS && need_codec) {
switch_frame_t *enc_frame, *read_frame = *frame;
goto done;
}
}
-
+
if (perfect || switch_buffer_inuse(session->raw_read_buffer) >= session->read_impl.decoded_bytes_per_packet) {
if (perfect) {
enc_frame = read_frame;
need_codec = TRUE;
}
- if (session->bugs && !need_codec) {
- switch_media_bug_t *bp;
- int tap_only = 1;
-
- switch_thread_rwlock_rdlock(session->bug_rwlock);
- for (bp = session->bugs; bp; bp = bp->next) {
- if (bp->ready) {
- if (!switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) {
- tap_only = 0;
- break;
- }
- }
- }
- switch_thread_rwlock_unlock(session->bug_rwlock);
-
- if (!tap_only) {
- do_bugs = TRUE;
- need_codec = TRUE;
- }
+ if (session->bugs && !need_codec && !switch_test_flag(session, SSF_MEDIA_BUG_TAP_ONLY)) {
+ do_bugs = TRUE;
+ need_codec = TRUE;
}
if (frame->codec->implementation->actual_samples_per_second != session->write_impl.actual_samples_per_second) {
switch_media_bug_flag_t flags,
switch_media_bug_t **new_bug)
{
- switch_media_bug_t *bug; //, *bp;
+ switch_media_bug_t *bug, *bp;
switch_size_t bytes;
switch_event_t *event;
+ int tap_only = 1;
const char *p;
switch_thread_rwlock_wrlock(session->bug_rwlock);
bug->next = session->bugs;
session->bugs = bug;
+
+ for(bp = session->bugs; bp; bp = bp->next) {
+ if (bp->ready && !switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) {
+ tap_only = 0;
+ }
+ }
+
switch_thread_rwlock_unlock(session->bug_rwlock);
*new_bug = bug;
+
+ if (tap_only) {
+ switch_set_flag(session, SSF_MEDIA_BUG_TAP_ONLY);
+ } else {
+ switch_clear_flag(session, SSF_MEDIA_BUG_TAP_ONLY);
+ }
+
if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_START) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Function", "%s", bug->function);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bug->target);
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session_t *session, switch_media_bug_t **bug)
{
- switch_media_bug_t *bp = NULL, *last = NULL;
+ switch_media_bug_t *bp = NULL, *bp2 = NULL, *last = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
-
+ int tap_only = 0;
+
if (switch_core_media_bug_test_flag(*bug, SMBF_LOCK)) {
return status;
}
switch_core_codec_destroy(&session->bug_codec);
}
+ if (session->bugs) {
+ for(bp2 = session->bugs; bp2; bp2 = bp2->next) {
+ if (bp2->ready && !switch_test_flag(bp2, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp2, SMBF_TAP_NATIVE_WRITE)) {
+ tap_only = 0;
+ }
+ }
+ }
+
+ if (tap_only) {
+ switch_set_flag(session, SSF_MEDIA_BUG_TAP_ONLY);
+ } else {
+ switch_clear_flag(session, SSF_MEDIA_BUG_TAP_ONLY);
+ }
+
switch_thread_rwlock_unlock(session->bug_rwlock);
if (bp) {