[channels,audin] assertions and warning fixes

This commit is contained in:
Armin Novak 2023-07-27 10:01:39 +02:00 committed by akallabeth
parent 70e437dbeb
commit 3612948bad
2 changed files with 97 additions and 68 deletions

View File

@ -106,8 +106,6 @@ static BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args
static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStream* out,
BOOL freeStream)
{
UINT error;
if (!callback || !out)
return ERROR_INVALID_PARAMETER;
@ -116,8 +114,8 @@ static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStre
Stream_SealLength(out);
WINPR_ASSERT(Stream_Length(out) <= ULONG_MAX);
error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out),
Stream_Buffer(out), NULL);
const UINT error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out),
Stream_Buffer(out), NULL);
if (freeStream)
Stream_Free(out, TRUE);
@ -132,9 +130,8 @@ static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStre
*/
static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
{
wStream* out;
const UINT32 ClientVersion = SNDIN_VERSION;
UINT32 ServerVersion;
UINT32 ServerVersion = 0;
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
return ERROR_INVALID_DATA;
@ -154,7 +151,7 @@ static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
}
audin->version = ServerVersion;
out = Stream_New(NULL, 5);
wStream* out = Stream_New(NULL, 5);
if (!out)
{
@ -189,11 +186,12 @@ static UINT audin_send_incoming_data_pdu(AUDIN_CHANNEL_CALLBACK* callback)
*/
static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
{
UINT32 i;
UINT error;
wStream* out;
UINT32 NumFormats;
UINT32 cbSizeFormatsPacket;
UINT error = ERROR_INTERNAL_ERROR;
UINT32 NumFormats = 0;
UINT32 cbSizeFormatsPacket = 0;
WINPR_ASSERT(audin);
WINPR_ASSERT(callback);
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
return ERROR_INVALID_DATA;
@ -216,7 +214,7 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
return ERROR_INVALID_DATA;
}
out = Stream_New(NULL, 9);
wStream* out = Stream_New(NULL, 9);
if (!out)
{
@ -228,7 +226,7 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
Stream_Seek(out, 9);
/* SoundFormats (variable) */
for (i = 0; i < NumFormats; i++)
for (UINT32 i = 0; i < NumFormats; i++)
{
AUDIO_FORMAT format = { 0 };
@ -298,6 +296,9 @@ out:
static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
UINT32 NewFormat)
{
WINPR_ASSERT(audin);
WINPR_ASSERT(callback);
wStream* out = Stream_New(NULL, 5);
if (!out)
@ -319,6 +320,9 @@ static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALL
static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
UINT32 Result)
{
WINPR_ASSERT(audin);
WINPR_ASSERT(callback);
wStream* out = Stream_New(NULL, 5);
if (!out)
@ -340,15 +344,15 @@ static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBAC
static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data, size_t size,
void* user_data)
{
UINT error;
BOOL compatible;
AUDIN_PLUGIN* audin;
WINPR_ASSERT(format);
UINT error = ERROR_INTERNAL_ERROR;
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data;
if (!callback)
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
audin = (AUDIN_PLUGIN*)callback->plugin;
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
if (!audin)
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
@ -363,7 +367,7 @@ static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data
Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA);
compatible = audio_format_compatible(format, audin->format);
const BOOL compatible = audio_format_compatible(format, audin->format);
if (compatible && audin->device->FormatSupported(audin->device, audin->format))
{
if (!Stream_EnsureRemainingCapacity(audin->data, size))
@ -397,14 +401,14 @@ static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data
static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback)
{
UINT error = ERROR_INTERNAL_ERROR;
BOOL supported;
AUDIO_FORMAT format;
AUDIO_FORMAT format = { 0 };
if (!audin || !audin->device)
return FALSE;
format = *audin->format;
supported = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
const BOOL supported =
IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
WLog_Print(audin->log, WLOG_DEBUG, "microphone uses %s codec",
audio_format_get_tag_string(format.wFormatTag));
@ -413,16 +417,14 @@ static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callb
/* Default sample rates supported by most backends. */
const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 };
BOOL test = FALSE;
size_t x;
format.wFormatTag = WAVE_FORMAT_PCM;
format.wBitsPerSample = 16;
format.cbSize = 0;
for (x = 0; x < ARRAYSIZE(samplerates); x++)
for (size_t x = 0; x < ARRAYSIZE(samplerates); x++)
{
size_t y;
format.nSamplesPerSec = samplerates[x];
for (y = audin->format->nChannels; y > 0; y--)
for (UINT16 y = audin->format->nChannels; y > 0; y--)
{
format.nChannels = y;
format.nBlockAlign = 2 * format.nChannels;
@ -458,6 +460,7 @@ static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callb
return TRUE;
}
/**
* Function description
*
@ -465,8 +468,8 @@ static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callb
*/
static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
{
UINT32 initialFormat;
UINT32 FramesPerPacket;
UINT32 initialFormat = 0;
UINT32 FramesPerPacket = 0;
UINT error = CHANNEL_RC_OK;
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
@ -510,7 +513,7 @@ static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* call
static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
wStream* s)
{
UINT32 NewFormat;
UINT32 NewFormat = 0;
UINT error = CHANNEL_RC_OK;
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
@ -555,15 +558,14 @@ static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLB
*/
static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
{
UINT error;
BYTE MessageId;
AUDIN_PLUGIN* audin;
UINT error = 0;
BYTE MessageId = 0;
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
if (!callback || !data)
return ERROR_INVALID_PARAMETER;
audin = (AUDIN_PLUGIN*)callback->plugin;
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
if (!audin)
return ERROR_INTERNAL_ERROR;
@ -609,7 +611,11 @@ static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback)
{
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
WINPR_ASSERT(callback);
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
WINPR_ASSERT(audin);
UINT error = CHANNEL_RC_OK;
WLog_Print(audin->log, WLOG_TRACE, "...");
@ -636,16 +642,15 @@ static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallb
IWTSVirtualChannel* pChannel, BYTE* Data,
BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback)
{
AUDIN_CHANNEL_CALLBACK* callback;
AUDIN_PLUGIN* audin;
GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback;
if (!listener_callback || !listener_callback->plugin)
return ERROR_INTERNAL_ERROR;
audin = (AUDIN_PLUGIN*)listener_callback->plugin;
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)listener_callback->plugin;
WLog_Print(audin->log, WLOG_TRACE, "...");
callback = (AUDIN_CHANNEL_CALLBACK*)calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK));
AUDIN_CHANNEL_CALLBACK* callback =
(AUDIN_CHANNEL_CALLBACK*)calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK));
if (!callback)
{
@ -669,7 +674,6 @@ static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallb
*/
static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
{
UINT rc;
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
if (!audin)
@ -697,8 +701,8 @@ static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManag
audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection;
audin->listener_callback->plugin = pPlugin;
audin->listener_callback->channel_mgr = pChannelMgr;
rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
&audin->listener_callback->iface, &audin->listener);
const UINT rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
&audin->listener_callback->iface, &audin->listener);
audin->initialized = rc == CHANNEL_RC_OK;
return rc;
@ -782,6 +786,8 @@ static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* devi
{
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
WINPR_ASSERT(audin);
if (audin->device)
{
WLog_Print(audin->log, WLOG_ERROR, "existing device, abort.");
@ -800,8 +806,10 @@ static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* devi
*/
static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, const ADDIN_ARGV* args)
{
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints;
UINT error;
WINPR_ASSERT(audin);
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints = { 0 };
UINT error = ERROR_INTERNAL_ERROR;
const PFREERDP_AUDIN_DEVICE_ENTRY entry =
(const PFREERDP_AUDIN_DEVICE_ENTRY)freerdp_load_channel_addin_entry("audin", name, NULL, 0);
@ -835,6 +843,8 @@ static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, cons
*/
static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, const char* subsystem)
{
WINPR_ASSERT(audin);
free(audin->subsystem);
audin->subsystem = _strdup(subsystem);
@ -854,6 +864,8 @@ static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, const char* subsystem)
*/
static UINT audin_set_device_name(AUDIN_PLUGIN* audin, const char* device_name)
{
WINPR_ASSERT(audin);
free(audin->device_name);
audin->device_name = _strdup(device_name);
@ -868,10 +880,6 @@ static UINT audin_set_device_name(AUDIN_PLUGIN* audin, const char* device_name)
BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
{
int status;
DWORD flags;
const COMMAND_LINE_ARGUMENT_A* arg;
UINT error;
COMMAND_LINE_ARGUMENT_A audin_args[] = {
{ "sys", COMMAND_LINE_VALUE_REQUIRED, "<subsystem>", NULL, NULL, -1, NULL, "subsystem" },
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "device" },
@ -884,15 +892,15 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
if (!args || args->argc == 1)
return TRUE;
flags =
const DWORD flags =
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
status =
const int status =
CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL);
if (status != 0)
return FALSE;
arg = audin_args;
const COMMAND_LINE_ARGUMENT_A* arg = audin_args;
errno = 0;
do
@ -902,7 +910,8 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "sys")
{
if ((error = audin_set_subsystem(audin, arg->Value)))
const UINT error = audin_set_subsystem(audin, arg->Value);
if (error != CHANNEL_RC_OK)
{
WLog_Print(audin->log, WLOG_ERROR,
"audin_set_subsystem failed with error %" PRIu32 "!", error);
@ -911,7 +920,8 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
}
CommandLineSwitchCase(arg, "dev")
{
if ((error = audin_set_device_name(audin, arg->Value)))
const UINT error = audin_set_device_name(audin, arg->Value);
if (error != CHANNEL_RC_OK)
{
WLog_Print(audin->log, WLOG_ERROR,
"audin_set_device_name failed with error %" PRIu32 "!", error);
@ -925,7 +935,7 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
if ((errno != 0) || (val > UINT16_MAX))
return FALSE;
audin->fixed_format->wFormatTag = val;
audin->fixed_format->wFormatTag = (UINT16)val;
}
CommandLineSwitchCase(arg, "rate")
{
@ -940,8 +950,8 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
{
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val < UINT16_MAX))
audin->fixed_format->nChannels = val;
if ((errno != 0) || (val <= UINT16_MAX))
audin->fixed_format->nChannels = (UINT16)val;
}
CommandLineSwitchDefault(arg)
{
@ -965,8 +975,6 @@ UINT audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
char* device;
};
UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
const ADDIN_ARGV* args;
AUDIN_PLUGIN* audin;
struct SubsystemEntry entries[] =
{
#if defined(WITH_PULSE)
@ -998,7 +1006,7 @@ UINT audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
struct SubsystemEntry* entry = &entries[0];
WINPR_ASSERT(pEntryPoints);
WINPR_ASSERT(pEntryPoints->GetPlugin);
audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "audin");
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "audin");
if (audin != NULL)
return CHANNEL_RC_ALREADY_INITIALIZED;
@ -1033,7 +1041,8 @@ UINT audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
audin->iface.Terminated = audin_plugin_terminated;
audin->iface.Attached = audin_plugin_attached;
audin->iface.Detached = audin_plugin_detached;
args = pEntryPoints->GetPluginData(pEntryPoints);
const ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints);
audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints);
if (args)

View File

@ -60,7 +60,7 @@ typedef struct
DWORD SessionId;
AUDIO_FORMAT* audin_server_formats;
size_t audin_n_server_formats;
UINT32 audin_n_server_formats;
AUDIO_FORMAT* audin_negotiated_format;
UINT32 audin_client_format_idx;
wLog* log;
@ -142,7 +142,15 @@ static UINT audin_server_recv_formats(audin_server_context* context, wStream* s,
WLog_Print(audin->log, WLOG_WARN,
"cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size",
pdu.cbSizeFormatsPacket, Stream_GetPosition(s));
pdu.cbSizeFormatsPacket = Stream_GetPosition(s);
const size_t pos = Stream_GetPosition(s);
if (pos > UINT32_MAX)
{
WLog_Print(audin->log, WLOG_ERROR, "Stream too long, %" PRIuz " exceeds UINT32_MAX",
pos);
error = ERROR_INVALID_PARAMETER;
goto fail;
}
pdu.cbSizeFormatsPacket = (UINT32)pos;
}
pdu.ExtraDataSize = Stream_GetRemainingLength(s);
@ -152,6 +160,7 @@ static UINT audin_server_recv_formats(audin_server_context* context, wStream* s,
WLog_Print(audin->log, WLOG_ERROR, "context->ReceiveFormats failed with error %" PRIu32 "",
error);
fail:
audio_formats_free(pdu.SoundFormats, pdu.NumFormats);
return error;
@ -559,8 +568,12 @@ static UINT audin_server_packet_send(audin_server_context* context, wStream* s)
WINPR_ASSERT(context);
WINPR_ASSERT(s);
if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR)Stream_Buffer(s),
Stream_GetPosition(s), &written))
const size_t pos = Stream_GetPosition(s);
if (pos > UINT32_MAX)
return ERROR_INVALID_PARAMETER;
if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR)Stream_Buffer(s), (UINT32)pos,
&written))
{
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelWrite failed!");
error = ERROR_INTERNAL_ERROR;
@ -598,7 +611,7 @@ static UINT audin_server_send_formats(audin_server_context* context, const SNDIN
{
audin_server* audin = (audin_server*)context;
WINPR_ASSERT(context);
WINPR_ASSERT(audin);
WINPR_ASSERT(formats);
wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS);
@ -626,7 +639,7 @@ static UINT audin_server_send_formats(audin_server_context* context, const SNDIN
static UINT audin_server_send_open(audin_server_context* context, const SNDIN_OPEN* open)
{
audin_server* audin = (audin_server*)context;
WINPR_ASSERT(context);
WINPR_ASSERT(audin);
WINPR_ASSERT(open);
wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN);
@ -745,7 +758,7 @@ static UINT audin_server_receive_formats_default(audin_server_context* context,
return ERROR_INVALID_DATA;
}
for (size_t i = 0; i < audin->audin_n_server_formats; ++i)
for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i)
{
for (UINT32 j = 0; j < formats->NumFormats; ++j)
{
@ -863,14 +876,20 @@ BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
audin->audin_negotiated_format = NULL;
if (count < 0)
audin->audin_n_server_formats = server_audin_get_formats(&audin->audin_server_formats);
{
const size_t audin_n_server_formats =
server_audin_get_formats(&audin->audin_server_formats);
WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX);
audin->audin_n_server_formats = (UINT32)audin_n_server_formats;
}
else
{
AUDIO_FORMAT* audin_server_formats = audio_formats_new(count);
if (!audin_server_formats)
return count == 0;
for (size_t x = 0; x < count; x++)
for (SSIZE_T x = 0; x < count; x++)
{
if (!audio_format_copy(&formats[x], &audin_server_formats[x]))
{
@ -879,8 +898,9 @@ BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
}
}
WINPR_ASSERT(count <= UINT32_MAX);
audin->audin_server_formats = audin_server_formats;
audin->audin_n_server_formats = count;
audin->audin_n_server_formats = (UINT32)count;
}
return audin->audin_n_server_formats > 0;
}