Merge pull request #10707 from akallabeth/alsa-mic-fix

Alsa mic fix
This commit is contained in:
akallabeth 2024-10-04 21:20:15 +02:00 committed by GitHub
commit 48eb68b53b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 17 deletions

View File

@ -117,11 +117,13 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg)
{
DWORD error = CHANNEL_RC_OK;
BYTE* buffer = NULL;
snd_pcm_t* capture_handle = NULL;
AudinALSADevice* alsa = (AudinALSADevice*)arg;
DWORD status = 0;
WINPR_ASSERT(alsa);
WLog_Print(alsa->log, WLOG_DEBUG, "in");
snd_pcm_t* capture_handle = NULL;
const int rc = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0);
if (rc < 0)
{
@ -149,7 +151,7 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg)
while (1)
{
size_t frames = alsa->frames_per_packet;
status = WaitForSingleObject(alsa->stopEvent, 0);
const DWORD status = WaitForSingleObject(alsa->stopEvent, 0);
if (status == WAIT_FAILED)
{
@ -160,26 +162,32 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg)
}
if (status == WAIT_OBJECT_0)
{
WLog_Print(alsa->log, WLOG_DEBUG, "alsa->stopEvent requests termination");
break;
}
snd_pcm_sframes_t err = snd_pcm_readi(capture_handle, buffer, frames);
snd_pcm_sframes_t framesRead = snd_pcm_readi(capture_handle, buffer, frames);
if (err == 0)
if (framesRead == 0)
continue;
if (err == -EPIPE)
if (framesRead == -EPIPE)
{
snd_pcm_recover(capture_handle, (int)err, 0);
const int rc = snd_pcm_recover(capture_handle, (int)framesRead, 0);
if (rc < 0)
WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_recover (%s)", snd_strerror(rc));
continue;
}
else if (err < 0)
else if (framesRead < 0)
{
WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_readi (%s)", snd_strerror(error));
WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_readi (%s)", snd_strerror(framesRead));
error = ERROR_INTERNAL_ERROR;
break;
}
error = alsa->receive(&alsa->aformat, buffer, (long)error * alsa->bytes_per_frame,
error = alsa->receive(&alsa->aformat, buffer, (long)framesRead * alsa->bytes_per_frame,
alsa->user_data);
if (error)
@ -193,7 +201,11 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg)
free(buffer);
if (capture_handle)
snd_pcm_close(capture_handle);
{
const int rc = snd_pcm_close(capture_handle);
if (rc < 0)
WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_close (%s)", snd_strerror(rc));
}
out:
WLog_Print(alsa->log, WLOG_DEBUG, "out");

View File

@ -941,7 +941,7 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
}
CommandLineSwitchCase(arg, "rate")
{
long val = strtol(arg->Value, NULL, 0);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT32_MAX))
return FALSE;

View File

@ -45,8 +45,11 @@
_Pragma("clang diagnostic ignored \"-Wunused-const-variable\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
_Pragma("clang diagnostic ignored \"-Wformat-security\"")
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
_Pragma("clang diagnostic ignored \"-Wtautological-constant-out-of-range-compare\"")
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
_Pragma("clang diagnostic ignored \"-Wtautological-constant-out-of-range-compare\"") /** @since \
version \
3.9.0 \
*/
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
_Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"") /** @since version 3.9.0 */
#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC /** @since version 3.3.0 */ /* not supported \
@ -77,8 +80,8 @@
_Pragma("GCC diagnostic ignored \"-Wunused-const-variable\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
_Pragma("GCC diagnostic ignored \"-Wformat-security\"")
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
_Pragma("GCC diagnostic ignored \"-Wtautological-constant-out-of-range-compare\"")
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE /* not supported
_Pragma("GCC diagnostic ignored \"-Wtautological-constant-out-of-range-compare\"") */ /** @since version 3.9.0 */
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") /** @since version 3.9.0 */
#if __GNUC__ >= 11
@ -103,7 +106,7 @@
#define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST
#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE
#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE /** @since version 3.9.0 */
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL /** @since version 3.9.0 */
#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC /** @since version 3.3.0 */
#define WINPR_PRAGMA_DIAG_POP