mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 00:00:44 +00:00
reset codecs after media bugs
This commit is contained in:
parent
ba46088e68
commit
27fc3518bd
@ -94,7 +94,11 @@ typedef enum {
|
|||||||
SSF_WARN_TRANSCODE = (1 << 1),
|
SSF_WARN_TRANSCODE = (1 << 1),
|
||||||
SSF_HANGUP = (1 << 2),
|
SSF_HANGUP = (1 << 2),
|
||||||
SSF_THREAD_STARTED = (1 << 3),
|
SSF_THREAD_STARTED = (1 << 3),
|
||||||
SSF_THREAD_RUNNING = (1 << 4)
|
SSF_THREAD_RUNNING = (1 << 4),
|
||||||
|
SSF_READ_TRANSCODE = (1 << 5),
|
||||||
|
SSF_WRITE_TRANSCODE = (1 << 6),
|
||||||
|
SSF_READ_CODEC_RESET = (1 << 7),
|
||||||
|
SSF_WRITE_CODEC_RESET = (1 << 8)
|
||||||
} switch_session_flag_t;
|
} switch_session_flag_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1329,6 +1329,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec,
|
|||||||
uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool);
|
uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool);
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool);
|
SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool);
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Encode data using a codec handle
|
\brief Encode data using a codec handle
|
||||||
|
@ -455,6 +455,17 @@ SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_write_codec(switc
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec)
|
||||||
|
{
|
||||||
|
switch_assert(codec != NULL);
|
||||||
|
|
||||||
|
codec->implementation->destroy(codec);
|
||||||
|
codec->implementation->init(codec, codec->flags, NULL);
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool)
|
SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool)
|
||||||
{
|
{
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
|
@ -214,8 +214,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||||||
|
|
||||||
if (session->read_codec->implementation->impl_id != codec_impl.impl_id) {
|
if (session->read_codec->implementation->impl_id != codec_impl.impl_id) {
|
||||||
need_codec = TRUE;
|
need_codec = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codec_impl.actual_samples_per_second != session->read_impl.actual_samples_per_second) {
|
if (codec_impl.actual_samples_per_second != session->read_impl.actual_samples_per_second) {
|
||||||
do_resample = 1;
|
do_resample = 1;
|
||||||
}
|
}
|
||||||
@ -225,9 +225,34 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||||||
need_codec = 1;
|
need_codec = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_variable(switch_core_session_get_channel(session), SWITCH_SIGNAL_BOND_VARIABLE);
|
||||||
|
switch_clear_flag(session, SSF_READ_TRANSCODE);
|
||||||
|
|
||||||
|
if (uuid && (other_session = switch_core_session_locate(uuid))) {
|
||||||
|
switch_set_flag(other_session, SSF_READ_CODEC_RESET);
|
||||||
|
switch_set_flag(other_session, SSF_READ_CODEC_RESET);
|
||||||
|
switch_set_flag(other_session, SSF_WRITE_CODEC_RESET);
|
||||||
|
switch_core_session_rwunlock(other_session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_test_flag(session, SSF_READ_CODEC_RESET)) {
|
||||||
|
switch_core_codec_reset(session->read_codec);
|
||||||
|
switch_clear_flag(session, SSF_READ_CODEC_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (status == SWITCH_STATUS_SUCCESS && need_codec) {
|
if (status == SWITCH_STATUS_SUCCESS && need_codec) {
|
||||||
switch_frame_t *enc_frame, *read_frame = *frame;
|
switch_frame_t *enc_frame, *read_frame = *frame;
|
||||||
|
|
||||||
|
switch_set_flag(session, SSF_READ_TRANSCODE);
|
||||||
|
|
||||||
if (!switch_test_flag(session, SSF_WARN_TRANSCODE)) {
|
if (!switch_test_flag(session, SSF_WARN_TRANSCODE)) {
|
||||||
switch_core_session_message_t msg = { 0 };
|
switch_core_session_message_t msg = { 0 };
|
||||||
|
|
||||||
@ -640,6 +665,26 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||||||
do_resample = TRUE;
|
do_resample = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_test_flag(session, SSF_WRITE_TRANSCODE) && !need_codec && switch_core_codec_ready(session->write_codec)) {
|
||||||
|
switch_core_session_t *other_session;
|
||||||
|
const char *uuid = switch_channel_get_variable(switch_core_session_get_channel(session), SWITCH_SIGNAL_BOND_VARIABLE);
|
||||||
|
|
||||||
|
if (uuid && (other_session = switch_core_session_locate(uuid))) {
|
||||||
|
switch_set_flag(other_session, SSF_READ_CODEC_RESET);
|
||||||
|
switch_set_flag(other_session, SSF_READ_CODEC_RESET);
|
||||||
|
switch_set_flag(other_session, SSF_WRITE_CODEC_RESET);
|
||||||
|
switch_core_session_rwunlock(other_session);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_clear_flag(session, SSF_WRITE_TRANSCODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (switch_test_flag(session, SSF_WRITE_CODEC_RESET)) {
|
||||||
|
switch_core_codec_reset(session->write_codec);
|
||||||
|
switch_clear_flag(session, SSF_WRITE_CODEC_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
if (!need_codec) {
|
if (!need_codec) {
|
||||||
do_write = TRUE;
|
do_write = TRUE;
|
||||||
write_frame = frame;
|
write_frame = frame;
|
||||||
|
@ -47,6 +47,11 @@ static void switch_core_media_bug_destroy(switch_media_bug_t *bug)
|
|||||||
switch_buffer_destroy(&bug->raw_write_buffer);
|
switch_buffer_destroy(&bug->raw_write_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_core_codec_ready(&bug->session->bug_codec)) {
|
||||||
|
switch_core_codec_destroy(&bug->session->bug_codec);
|
||||||
|
memset(&bug->session->bug_codec, 0, sizeof(bug->session->bug_codec));
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_STOP) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_STOP) == 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-Function", "%s", bug->function);
|
||||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bug->target);
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bug->target);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user