Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEL-6238 Add logs to track the address of codec_read_mutex #354

Merged
merged 8 commits into from
Jan 22, 2025
10 changes: 9 additions & 1 deletion src/switch_core_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t
switch_mutex_t *mutex = NULL;

switch_mutex_lock(session->codec_read_mutex);
if (session->read_codec) mutex = session->read_codec->mutex;
if (session->read_codec) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Read codec addr: %p is set to NULL\n", (void *)&session->read_codec);
mutex = session->read_codec->mutex;
}
if (mutex) switch_mutex_lock(mutex);
session->real_read_codec = session->read_codec = NULL;
session->raw_read_frame.codec = session->read_codec;
Expand Down Expand Up @@ -112,6 +115,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_c
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec set to %s:%d\n",
switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode);
session->read_codec = session->real_read_codec = codec;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Read codec addr: %p\n", (void *)&session->read_codec);
changed_read_codec = 1;
if (codec->implementation) {
session->read_impl = *codec->implementation;
Expand Down Expand Up @@ -724,6 +728,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec

implementation->init(codec, flags, codec_settings);
switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec mutex addr: %p\n", (void *)&codec->mutex);

switch_set_flag(codec, SWITCH_CODEC_FLAG_READY);
return SWITCH_STATUS_SUCCESS;
} else {
Expand Down Expand Up @@ -941,6 +947,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)

if (mutex) switch_mutex_unlock(mutex);

switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec read mutex addr: %p has been set to NULL\n", (void *)&mutex);

if (free_pool) {
switch_core_destroy_memory_pool(&pool);
}
Expand Down
7 changes: 7 additions & 0 deletions src/switch_core_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi

switch_os_yield();

switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Codec read mutex addr: %p\n", (void *)&session->codec_read_mutex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this log since we are logging the address upon creating this mutex

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd rather leave it here, since we know that locking the mutex here works, so we can compare the address later. your choice.


if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(session->codec_read_mutex);
} else {
Expand Down Expand Up @@ -186,8 +188,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);
if ((status = session->endpoint_interface->io_routines->read_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Codec read mutex addr: %p\n", (void *)&session->codec_read_mutex);
for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Codec read mutex addr: %p\n", (void *)&session->codec_read_mutex);
if ((status = ptr->read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Codec read mutex addr: %p\n", (void *)&session->codec_read_mutex);
break;
}
}
Expand Down Expand Up @@ -988,6 +993,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi

even_more_done:

switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Read codec addr: %p, codec read mutex addr: %p\n", (void *)&session->read_codec, (void *)&session->codec_read_mutex);

if (!*frame ||
(!switch_test_flag(*frame, SFF_PROXY_PACKET) &&
(!(*frame)->codec || !(*frame)->codec->implementation || !switch_core_codec_ready((*frame)->codec)))) {
Expand Down
2 changes: 2 additions & 0 deletions src/switch_core_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,8 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_

switch_channel_set_variable_printf(session->channel, "session_id", "%u", session->id);

switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Codec read mutex addr: %p\n", (void *)&session->codec_read_mutex);

return session;
}

Expand Down