Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "libs/libwsc"]
path = libs/libwsc
url = https://github.com/voxcom-us/libwsc
url = https://github.com/voiceip/libwsc
320 changes: 210 additions & 110 deletions audio_streamer_glue.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions audio_streamer_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ switch_status_t stream_session_send_text(switch_core_session_t *session, char *t
switch_status_t stream_session_pauseresume(switch_core_session_t *session, int pause);
switch_status_t stream_session_init(switch_core_session_t *session, responseHandler_t responseHandler, uint32_t samples_per_second, char *wsUri, int wsSampling, int channels, char *metadata, void **ppUserData);
switch_status_t stream_session_write_thread_init(switch_core_session_t *session, void *pUserData);
switch_status_t stream_session_read_thread_init(switch_core_session_t *session, void *pUserData);
switch_bool_t stream_frame(switch_media_bug_t *bug);
switch_status_t stream_session_cleanup(switch_core_session_t *session, char *text, int channelIsClosing);

Expand Down
2 changes: 1 addition & 1 deletion libs/libwsc
5 changes: 5 additions & 0 deletions mod_audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ static switch_status_t start_capture(switch_core_session_t *session,
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error initializing stream session write thread.\n");
return SWITCH_STATUS_FALSE;
}
if (SWITCH_STATUS_FALSE == stream_session_read_thread_init(session, pUserData))
{
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error initializing stream session read thread.\n");
return SWITCH_STATUS_FALSE;
}
Comment on lines +117 to +121
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Resource leak if read thread initialization fails.

If stream_session_read_thread_init fails, the write thread (started at line 112) and the media bug (added at line 106) are not cleaned up. This leaves orphaned resources.

Consider calling cleanup on failure:

     if (SWITCH_STATUS_FALSE == stream_session_read_thread_init(session, pUserData))
     {
         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error initializing stream session read thread.\n");
+        stream_session_cleanup(session, NULL, 0);
         return SWITCH_STATUS_FALSE;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (SWITCH_STATUS_FALSE == stream_session_read_thread_init(session, pUserData))
{
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error initializing stream session read thread.\n");
return SWITCH_STATUS_FALSE;
}
if (SWITCH_STATUS_FALSE == stream_session_read_thread_init(session, pUserData))
{
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "error initializing stream session read thread.\n");
stream_session_cleanup(session, NULL, 0);
return SWITCH_STATUS_FALSE;
}
🤖 Prompt for AI Agents
In mod_audio_stream.c around lines 106 to 121, if
stream_session_read_thread_init fails the previously started write thread
(started at ~line 112) and the media bug (added at ~line 106) are not cleaned
up, leaking resources; modify the failure path to perform cleanup before
returning: stop and join the write thread, remove and free the media bug, and
release any session-related resources (or call the existing session cleanup
function used on normal teardown) so the write thread and media bug are properly
cleaned up, then return SWITCH_STATUS_FALSE.

return SWITCH_STATUS_SUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions mod_audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ struct private_data
switch_buffer_t *read_sbuffer;
switch_buffer_t *write_sbuffer;
switch_mutex_t *write_mutex;
switch_mutex_t *read_mutex;
switch_thread_t *write_thread;
switch_thread_t *read_thread;
int rtp_packets;
};

Expand Down