[vlc-devel] [PATCH 3/4] aout: winstore: fix C++ compilation
Steve Lhomme
robux4 at ycbcr.xyz
Wed Jun 24 14:26:56 CEST 2020
And make better use of C++ features.
Use WRL::ComPtr smart pointer to handle COM.
---
modules/audio_output/winstore.cpp | 107 +++++++++++++++---------------
1 file changed, 53 insertions(+), 54 deletions(-)
diff --git a/modules/audio_output/winstore.cpp b/modules/audio_output/winstore.cpp
index 6482bd41726..66ce3721dfb 100644
--- a/modules/audio_output/winstore.cpp
+++ b/modules/audio_output/winstore.cpp
@@ -1,5 +1,5 @@
/*****************************************************************************
- * mmdevice.c : Windows Multimedia Device API audio output plugin for VLC
+ * winstore.cpp : Windows Multimedia Device API audio output plugin for VLC
*****************************************************************************
* Copyright (C) 2012 RĂ©mi Denis-Courmont
*
@@ -23,10 +23,8 @@
#endif
#define INITGUID
-#define COBJMACROS
-#include <stdlib.h>
-#include <assert.h>
+#include <cassert>
#include <audiopolicy.h>
#include <vlc_common.h>
@@ -35,12 +33,16 @@
#include <vlc_modules.h>
#include "audio_output/mmdevice.h"
+#include <wrl.h>
+#include <wrl/client.h>
+using namespace Microsoft::WRL;
+
DEFINE_GUID (GUID_VLC_AUD_OUT, 0x4533f59d, 0x59ee, 0x00c6,
0xad, 0xb2, 0xc6, 0x8b, 0x50, 0x1a, 0x66, 0x55);
static void EnterMTA(void)
{
- HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+ HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (unlikely(FAILED(hr)))
abort();
}
@@ -63,18 +65,18 @@ static void ResetInvalidated(audio_output_t *aout, HRESULT hr)
if (unlikely(hr == AUDCLNT_E_DEVICE_INVALIDATED ||
hr == AUDCLNT_E_RESOURCES_INVALIDATED))
{
- aout_sys_t* sys = aout->sys;
- sys->client = NULL;
+ aout_sys_t* sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ sys->client = nullptr;
}
}
static int VolumeSet(audio_output_t *aout, float vol)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return VLC_EGENERIC;
HRESULT hr;
- ISimpleAudioVolume *pc_AudioVolume = NULL;
+ ComPtr<ISimpleAudioVolume> pc_AudioVolume;
float gain = 1.f;
vol = vol * vol * vol; /* ISimpleAudioVolume is tapered linearly. */
@@ -87,14 +89,14 @@ static int VolumeSet(audio_output_t *aout, float vol)
aout_GainRequest(aout, gain);
- hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, (void**)&pc_AudioVolume);
+ hr = sys->client->GetService(IID_ISimpleAudioVolume, (void**)pc_AudioVolume.GetAddressOf() );
if (FAILED(hr))
{
msg_Err(aout, "cannot get volume service (error 0x%lX)", hr);
goto done;
}
- hr = ISimpleAudioVolume_SetMasterVolume(pc_AudioVolume, vol, NULL);
+ hr = pc_AudioVolume->SetMasterVolume(vol, nullptr);
if (FAILED(hr))
{
msg_Err(aout, "cannot set volume (error 0x%lX)", hr);
@@ -102,27 +104,26 @@ static int VolumeSet(audio_output_t *aout, float vol)
}
done:
- ISimpleAudioVolume_Release(pc_AudioVolume);
return SUCCEEDED(hr) ? 0 : -1;
}
static int MuteSet(audio_output_t *aout, bool mute)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return VLC_EGENERIC;
HRESULT hr;
- ISimpleAudioVolume *pc_AudioVolume = NULL;
+ ComPtr<ISimpleAudioVolume> pc_AudioVolume;
- hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, (void**)&pc_AudioVolume);
+ hr = sys->client->GetService(IID_ISimpleAudioVolume, (void**)pc_AudioVolume.GetAddressOf() );
if (FAILED(hr))
{
msg_Err(aout, "cannot get volume service (error 0x%lX)", hr);
goto done;
}
- hr = ISimpleAudioVolume_SetMute(pc_AudioVolume, mute, NULL);
+ hr = pc_AudioVolume->SetMute(mute, nullptr);
if (FAILED(hr))
{
msg_Err(aout, "cannot set mute (error 0x%lX)", hr);
@@ -130,15 +131,14 @@ static int MuteSet(audio_output_t *aout, bool mute)
}
done:
- ISimpleAudioVolume_Release(pc_AudioVolume);
return SUCCEEDED(hr) ? 0 : -1;
}
static int TimeGet(audio_output_t *aout, vlc_tick_t *restrict delay)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return VLC_EGENERIC;
HRESULT hr;
@@ -151,8 +151,8 @@ static int TimeGet(audio_output_t *aout, vlc_tick_t *restrict delay)
static void Play(audio_output_t *aout, block_t *block, vlc_tick_t date)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return;
EnterMTA();
@@ -165,8 +165,8 @@ static void Play(audio_output_t *aout, block_t *block, vlc_tick_t date)
static void Pause(audio_output_t *aout, bool paused, vlc_tick_t date)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return;
EnterMTA();
@@ -179,8 +179,8 @@ static void Pause(audio_output_t *aout, bool paused, vlc_tick_t date)
static void Flush(audio_output_t *aout)
{
- aout_sys_t *sys = aout->sys;
- if( unlikely( sys->client == NULL ) )
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
+ if( unlikely( sys->client == nullptr ) )
return;
EnterMTA();
@@ -193,14 +193,13 @@ static void Flush(audio_output_t *aout)
static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
void **restrict pv)
{
- IAudioClient *client = opaque;
+ IAudioClient *client = reinterpret_cast<IAudioClient*>(opaque);
- if (!IsEqualIID(iid, &IID_IAudioClient))
+ if (iid != IID_IAudioClient)
return E_NOINTERFACE;
- if (actparms != NULL || client == NULL )
+ if (actparms != nullptr || client == nullptr )
return E_INVALIDARG;
-
- IAudioClient_AddRef(client);
+ client->AddRef();
*pv = opaque;
return S_OK;
@@ -208,7 +207,7 @@ static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
static int aout_stream_Start(void *func, bool forced, va_list ap)
{
- aout_stream_start_t start = func;
+ aout_stream_start_t start = (aout_stream_start_t)func;
aout_stream_t *s = va_arg(ap, aout_stream_t *);
audio_sample_format_t *fmt = va_arg(ap, audio_sample_format_t *);
HRESULT *hr = va_arg(ap, HRESULT *);
@@ -220,58 +219,58 @@ static int aout_stream_Start(void *func, bool forced, va_list ap)
static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
{
- aout_sys_t *sys = aout->sys;
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
HRESULT hr;
- aout_stream_t *s = vlc_object_create(aout, sizeof (*s));
- if (unlikely(s == NULL))
+ aout_stream_t *s = (aout_stream_t*)vlc_object_create(aout, sizeof (*s));
+ if (unlikely(s == nullptr))
return -1;
s->owner.device = sys->client;
s->owner.activate = ActivateDevice;
EnterMTA();
- sys->module = vlc_module_load(s, "aout stream", NULL, false,
+ sys->module = vlc_module_load(vlc_object_logger(&s->obj), "aout stream", nullptr, false,
aout_stream_Start, s, fmt, &hr);
LeaveMTA();
- if (sys->module == NULL)
+ if (sys->module == nullptr)
{
- vlc_object_delete(s);
+ vlc_object_delete(&s->obj);
return -1;
}
- assert (sys->stream == NULL);
+ assert (sys->stream == nullptr);
sys->stream = s;
return 0;
}
static void Stop(audio_output_t *aout)
{
- aout_sys_t *sys = aout->sys;
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
- assert (sys->stream != NULL);
+ assert (sys->stream != nullptr);
EnterMTA();
aout_stream_Stop(sys->stream);
LeaveMTA();
- vlc_object_delete(sys->stream);
- sys->stream = NULL;
+ vlc_object_delete(&sys->stream->obj);
+ sys->stream = nullptr;
}
static int DeviceSelect(audio_output_t *aout, const char* psz_device)
{
- if( psz_device == NULL )
+ if( psz_device == nullptr )
return VLC_EGENERIC;
char* psz_end;
- aout_sys_t* sys = aout->sys;
+ aout_sys_t* sys = reinterpret_cast<aout_sys_t*>(aout->sys);
intptr_t ptr = strtoll( psz_device, &psz_end, 16 );
if ( *psz_end != 0 )
return VLC_EGENERIC;
- if (sys->client == (IAudioClient*)ptr)
+ if (sys->client == reinterpret_cast<IAudioClient*>(ptr))
return VLC_SUCCESS;
- sys->client = (IAudioClient*)ptr;
+ sys->client = reinterpret_cast<IAudioClient*>(ptr);
var_SetAddress( vlc_object_parent(aout), "winstore-client", sys->client );
aout_RestartRequest( aout, AOUT_RESTART_OUTPUT );
return VLC_SUCCESS;
@@ -281,14 +280,14 @@ static int Open(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
- aout_sys_t *sys = malloc(sizeof (*sys));
- if (unlikely(sys == NULL))
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(malloc(sizeof (*sys)));
+ if (unlikely(sys == nullptr))
return VLC_ENOMEM;
aout->sys = sys;
- sys->stream = NULL;
- sys->client = var_CreateGetAddress( vlc_object_parent(aout), "winstore-client" );
- if (sys->client != NULL)
+ sys->stream = nullptr;
+ sys->client = reinterpret_cast<IAudioClient*>(var_CreateGetAddress( vlc_object_parent(aout), "winstore-client" ));
+ if (sys->client != nullptr)
msg_Dbg( aout, "Reusing previous client: %p", sys->client );
aout->start = Start;
aout->stop = Stop;
@@ -305,7 +304,7 @@ static int Open(vlc_object_t *obj)
static void Close(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
- aout_sys_t *sys = aout->sys;
+ aout_sys_t *sys = reinterpret_cast<aout_sys_t*>(aout->sys);
free(sys);
}
--
2.26.2
More information about the vlc-devel
mailing list