Fixed callback parameter checks.

This commit is contained in:
Armin Novak 2018-07-30 11:22:11 +02:00
parent 3b187ef321
commit 033abe93d4
5 changed files with 76 additions and 1 deletions

View File

@ -215,7 +215,10 @@ out:
static UINT audin_alsa_free(IAudinDevice* device)
{
AudinALSADevice* alsa = (AudinALSADevice*) device;
free(alsa->device_name);
if (alsa)
free(alsa->device_name);
free(alsa);
return CHANNEL_RC_OK;
}
@ -223,6 +226,9 @@ static UINT audin_alsa_free(IAudinDevice* device)
static BOOL audin_alsa_format_supported(IAudinDevice* device,
const AUDIO_FORMAT* format)
{
if (!device || !format)
return FALSE;
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
@ -256,6 +262,10 @@ static UINT audin_alsa_set_format(IAudinDevice* device, const AUDIO_FORMAT* form
UINT32 FramesPerPacket)
{
AudinALSADevice* alsa = (AudinALSADevice*) device;
if (!alsa || !format)
return ERROR_INVALID_PARAMETER;
alsa->aformat = *format;
alsa->frames_per_packet = FramesPerPacket;
@ -274,6 +284,10 @@ static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive,
void* user_data)
{
AudinALSADevice* alsa = (AudinALSADevice*) device;
if (!device || !receive || !user_data)
return ERROR_INVALID_PARAMETER;
alsa->receive = receive;
alsa->user_data = user_data;
@ -307,6 +321,9 @@ static UINT audin_alsa_close(IAudinDevice* device)
UINT error = CHANNEL_RC_OK;
AudinALSADevice* alsa = (AudinALSADevice*) device;
if (!alsa)
return ERROR_INVALID_PARAMETER;
if (alsa->stopEvent)
{
SetEvent(alsa->stopEvent);

View File

@ -696,6 +696,13 @@ static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallb
static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
{
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
if (!audin)
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
if (!pChannelMgr)
return ERROR_INVALID_PARAMETER;
WLog_Print(audin->log, WLOG_TRACE, "...");
audin->listener_callback = (AUDIN_LISTENER_CALLBACK*) calloc(1, sizeof(AUDIN_LISTENER_CALLBACK));
@ -721,6 +728,10 @@ static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
{
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
UINT error = CHANNEL_RC_OK;
if (!audin)
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
WLog_Print(audin->log, WLOG_TRACE, "...");
if (audin->device)

View File

@ -145,6 +145,10 @@ out:
static UINT audin_opensles_free(IAudinDevice* device)
{
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
if (!opensles)
return ERROR_INVALID_PARAMETER;
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*) device);
/* The function may have been called out of order,
@ -163,6 +167,10 @@ static BOOL audin_opensles_format_supported(IAudinDevice* device,
const AUDIO_FORMAT* format)
{
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
if (!opensles || !format)
return FALSE;
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p", (void*) opensles, (void*) format);
assert(format);
@ -198,6 +206,10 @@ static UINT audin_opensles_set_format(IAudinDevice* device,
const AUDIO_FORMAT* format, UINT32 FramesPerPacket)
{
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
if (!opensles || !format)
return ERROR_INVALID_PARAMETER;
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p, FramesPerPacket=%"PRIu32"",
(void*) device, (void*) format, FramesPerPacket);
assert(format);
@ -255,6 +267,10 @@ static UINT audin_opensles_open(IAudinDevice* device, AudinReceive receive,
void* user_data)
{
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
if (!opensles || !receive || !user_data)
return ERROR_INVALID_PARAMETER;
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, receive=%p, user_data=%p", (void*) device,
(void*) receive,
(void*) user_data);

View File

@ -178,6 +178,9 @@ static BOOL audin_pulse_format_supported(IAudinDevice* device, const AUDIO_FORMA
{
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
if (!pulse || !format)
return FALSE;
if (!pulse->context)
return 0;
@ -224,6 +227,9 @@ static UINT audin_pulse_set_format(IAudinDevice* device, const AUDIO_FORMAT* for
pa_sample_spec sample_spec = { 0 };
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
if (!pulse || !format)
return ERROR_INVALID_PARAMETER;
if (!pulse->context)
return ERROR_INVALID_PARAMETER;
@ -317,6 +323,9 @@ static UINT audin_pulse_close(IAudinDevice* device)
{
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
if (!pulse)
return ERROR_INVALID_PARAMETER;
if (pulse->stream)
{
pa_threaded_mainloop_lock(pulse->mainloop);
@ -342,6 +351,9 @@ static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u
pa_buffer_attr buffer_attr = { 0 };
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
if (!pulse || !receive || !user_data)
return ERROR_INVALID_PARAMETER;
if (!pulse->context)
return ERROR_INVALID_PARAMETER;

View File

@ -242,6 +242,9 @@ static UINT audin_winmm_free(IAudinDevice* device)
UINT32 i;
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
if (!winmm)
return ERROR_INVALID_PARAMETER;
for (i = 0; i < winmm->cFormats; i++)
{
free(winmm->ppwfx[i]);
@ -263,6 +266,10 @@ static UINT audin_winmm_close(IAudinDevice* device)
DWORD status;
UINT error = CHANNEL_RC_OK;
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
if (!winmm)
return ERROR_INVALID_PARAMETER;
SetEvent(winmm->stopEvent);
status = WaitForSingleObject(winmm->thread, INFINITE);
@ -292,6 +299,10 @@ static UINT audin_winmm_set_format(IAudinDevice* device, const AUDIO_FORMAT* for
{
UINT32 i;
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
if (!winmm || !format)
return ERROR_INVALID_PARAMETER;
winmm->frames_per_packet = FramesPerPacket;
for (i = 0; i < winmm->cFormats; i++)
@ -313,6 +324,10 @@ static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMA
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
PWAVEFORMATEX pwfx;
BYTE* data;
if (!winmm || !format)
return FALSE;
pwfx = (PWAVEFORMATEX)malloc(sizeof(WAVEFORMATEX) + format->cbSize);
if (!pwfx)
@ -362,6 +377,10 @@ static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMA
static UINT audin_winmm_open(IAudinDevice* device, AudinReceive receive, void* user_data)
{
AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
if (!winmm || !receive || !user_data)
return ERROR_INVALID_PARAMETER;
winmm->receive = receive;
winmm->user_data = user_data;