Compare commits

..

3 Commits

Author SHA1 Message Date
Dave Horton 3459188bb6 use trylock on mutex (#85) 2024-07-01 08:16:31 -06:00
Dave Horton d6e246d84c fix: discard incoming binary or text frame if we are shutting down to avoid deadlock (#84) 2024-06-28 07:28:35 -04:00
Hoan Luu Huu de676ddc81 append null to ostringstream will make c_str return part of a string. (#83)
* append null to ostringstream will make c_str return part of a string.

* fixed review comment

Signed-off-by: Quan HL <quan.luuhoang8@gmail.com>

* fixed review comment

Signed-off-by: Quan HL <quan.luuhoang8@gmail.com>

* fixed review comment

Signed-off-by: Quan HL <quan.luuhoang8@gmail.com>

---------

Signed-off-by: Quan HL <quan.luuhoang8@gmail.com>
2024-06-28 07:08:40 -04:00
3 changed files with 34 additions and 32 deletions
+5
View File
@@ -141,6 +141,11 @@ int AudioPipe::lws_callback(struct lws *wsi,
return 0; return 0;
} }
if (ap->m_state == LWS_CLIENT_DISCONNECTING) {
lwsl_notice("AudioPipe::lws_service_thread race condition: got incoming message while closing the connection.\n");
return 0;
}
if (lws_frame_is_binary(wsi)) { if (lws_frame_is_binary(wsi)) {
if (ap->is_bidirectional_audio_stream()) { if (ap->is_bidirectional_audio_stream()) {
ap->m_callback(ap->m_uuid.c_str(), ap->m_bugname.c_str(), AudioPipe::BINARY, NULL, (char *) in, len); ap->m_callback(ap->m_uuid.c_str(), ap->m_bugname.c_str(), AudioPipe::BINARY, NULL, (char *) in, len);
+5 -4
View File
@@ -38,7 +38,6 @@ namespace {
static uint32_t playCount = 0; static uint32_t playCount = 0;
switch_status_t processIncomingBinary(private_t* tech_pvt, switch_core_session_t* session, const char* message, size_t dataLength) { switch_status_t processIncomingBinary(private_t* tech_pvt, switch_core_session_t* session, const char* message, size_t dataLength) {
CircularBuffer_t *cBuffer = (CircularBuffer_t *) tech_pvt->circularBuffer;
uint8_t* data = reinterpret_cast<uint8_t*>(const_cast<char*>(message)); uint8_t* data = reinterpret_cast<uint8_t*>(const_cast<char*>(message));
uint16_t* data_uint16 = reinterpret_cast<uint16_t*>(data); uint16_t* data_uint16 = reinterpret_cast<uint16_t*>(data);
std::vector<uint16_t> pcm_data(data_uint16, data_uint16 + dataLength / sizeof(uint16_t)); std::vector<uint16_t> pcm_data(data_uint16, data_uint16 + dataLength / sizeof(uint16_t));
@@ -70,7 +69,9 @@ namespace {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
switch_mutex_lock(tech_pvt->mutex); if (nullptr != tech_pvt->mutex && switch_mutex_trylock(tech_pvt->mutex) == SWITCH_STATUS_SUCCESS) {
//switch_mutex_lock(tech_pvt->mutex);
CircularBuffer_t *cBuffer = (CircularBuffer_t *) tech_pvt->circularBuffer;
try { try {
// Resize the buffer if necessary // Resize the buffer if necessary
@@ -92,10 +93,10 @@ namespace {
switch_mutex_unlock(tech_pvt->mutex); switch_mutex_unlock(tech_pvt->mutex);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
switch_mutex_unlock(tech_pvt->mutex); switch_mutex_unlock(tech_pvt->mutex);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
} }
void processIncomingMessage(private_t* tech_pvt, switch_core_session_t* session, const char* message) { void processIncomingMessage(private_t* tech_pvt, switch_core_session_t* session, const char* message) {
+6 -10
View File
@@ -382,22 +382,18 @@ private:
const char* endpoint = switch_channel_get_variable(channel, "AZURE_SERVICE_ENDPOINT"); const char* endpoint = switch_channel_get_variable(channel, "AZURE_SERVICE_ENDPOINT");
const char* endpointId = switch_channel_get_variable(channel, "AZURE_SERVICE_ENDPOINT_ID"); const char* endpointId = switch_channel_get_variable(channel, "AZURE_SERVICE_ENDPOINT_ID");
configuration_stream << configuration_stream << (endpoint ? endpoint : "") << ";"
endpoint << ";" << << (endpointId ? endpointId : "") << ";";
endpointId << ";";
if (switch_true(switch_channel_get_variable(channel, "AZURE_USE_OUTPUT_FORMAT_DETAILED"))) { if (switch_true(switch_channel_get_variable(channel, "AZURE_USE_OUTPUT_FORMAT_DETAILED"))) {
configuration_stream << "output_format_detailed;"; configuration_stream << "output_format_detailed;";
} }
if (switch_true(switch_channel_get_variable(channel, "AZURE_AUDIO_LOGGING"))) { if (switch_true(switch_channel_get_variable(channel, "AZURE_AUDIO_LOGGING"))) {
configuration_stream << "audio_logging;"; configuration_stream << "audio_logging;";
} }
if (nullptr != proxyIP && nullptr != proxyPort) { configuration_stream << (proxyIP ? proxyIP : "") << ";"
configuration_stream << << (proxyPort ? proxyPort : "") << ";"
proxyIP << ";" << << (proxyUsername ? proxyUsername : "") << ";"
proxyPort << ";" << << (proxyPassword ? proxyPassword : "") << ";";
proxyUsername << ";" <<
proxyPassword << ";";
}
const char* var; const char* var;
if (var = switch_channel_get_variable(channel, "AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES")) { if (var = switch_channel_get_variable(channel, "AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES")) {
configuration_stream << var << ";"; configuration_stream << var << ";";