wasapi2client: Run gst-indent

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2177>
This commit is contained in:
Seungha Yang 2021-04-20 18:48:18 +09:00 committed by GStreamer Marge Bot
parent bc817f340c
commit 6b7e08df90

View file

@ -41,6 +41,7 @@
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
/* *INDENT-OFF* */
using namespace ABI::Windows::ApplicationModel::Core; using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections; using namespace ABI::Windows::Foundation::Collections;
@ -57,11 +58,14 @@ GST_DEBUG_CATEGORY_EXTERN (gst_wasapi2_client_debug);
#define GST_CAT_DEFAULT gst_wasapi2_client_debug #define GST_CAT_DEFAULT gst_wasapi2_client_debug
G_END_DECLS G_END_DECLS
/* *INDENT-ON* */
static void static void
gst_wasapi2_client_on_device_activated (GstWasapi2Client * client, gst_wasapi2_client_on_device_activated (GstWasapi2Client * client,
IAudioClient3 * audio_client); IAudioClient3 * audio_client);
/* *INDENT-OFF* */
class GstWasapiDeviceActivator class GstWasapiDeviceActivator
: public RuntimeClass<RuntimeClassFlags<ClassicCom>, FtmBase, : public RuntimeClass<RuntimeClassFlags<ClassicCom>, FtmBase,
IActivateAudioInterfaceCompletionHandler> IActivateAudioInterfaceCompletionHandler>
@ -205,7 +209,7 @@ private:
GWeakRef listener_; GWeakRef listener_;
ComPtr<ICoreDispatcher> dispatcher_; ComPtr<ICoreDispatcher> dispatcher_;
}; };
/* *INDENT-ON* */
typedef enum typedef enum
{ {
GST_WASAPI2_CLIENT_ACTIVATE_FAILED = -1, GST_WASAPI2_CLIENT_ACTIVATE_FAILED = -1,
@ -305,8 +309,7 @@ static gboolean
gst_wasapi2_client_main_loop_running_cb (GstWasapi2Client * self); gst_wasapi2_client_main_loop_running_cb (GstWasapi2Client * self);
#define gst_wasapi2_client_parent_class parent_class #define gst_wasapi2_client_parent_class parent_class
G_DEFINE_TYPE (GstWasapi2Client, G_DEFINE_TYPE (GstWasapi2Client, gst_wasapi2_client, GST_TYPE_OBJECT);
gst_wasapi2_client, GST_TYPE_OBJECT);
static void static void
gst_wasapi2_client_class_init (GstWasapi2ClientClass * klass) gst_wasapi2_client_class_init (GstWasapi2ClientClass * klass)
@ -371,7 +374,9 @@ static void
gst_wasapi2_client_constructed (GObject * object) gst_wasapi2_client_constructed (GObject * object)
{ {
GstWasapi2Client *self = GST_WASAPI2_CLIENT (object); GstWasapi2Client *self = GST_WASAPI2_CLIENT (object);
/* *INDENT-OFF* */
ComPtr<GstWasapiDeviceActivator> activator; ComPtr<GstWasapiDeviceActivator> activator;
/* *INDENT-ON* */
/* Create a new thread to ensure that COM thread can be MTA thread. /* Create a new thread to ensure that COM thread can be MTA thread.
* We cannot ensure whether CoInitializeEx() was called outside of here for * We cannot ensure whether CoInitializeEx() was called outside of here for
@ -520,7 +525,7 @@ gst_wasapi2_client_on_device_activated (GstWasapi2Client * self,
g_mutex_lock (&self->init_lock); g_mutex_lock (&self->init_lock);
if (audio_client) { if (audio_client) {
audio_client->AddRef(); audio_client->AddRef ();
self->audio_client = audio_client; self->audio_client = audio_client;
self->activate_state = GST_WASAPI2_CLIENT_ACTIVATE_DONE; self->activate_state = GST_WASAPI2_CLIENT_ACTIVATE_DONE;
} else { } else {
@ -531,6 +536,7 @@ gst_wasapi2_client_on_device_activated (GstWasapi2Client * self,
g_mutex_unlock (&self->init_lock); g_mutex_unlock (&self->init_lock);
} }
/* *INDENT-OFF* */
static std::string static std::string
convert_wstring_to_string (const std::wstring &wstr) convert_wstring_to_string (const std::wstring &wstr)
{ {
@ -573,17 +579,20 @@ gst_wasapi2_client_get_default_device_id (GstWasapi2Client * self)
return ret; return ret;
} }
/* *INDENT-ON* */
static gboolean static gboolean
gst_wasapi2_client_activate_async (GstWasapi2Client * self, gst_wasapi2_client_activate_async (GstWasapi2Client * self,
GstWasapiDeviceActivator * activator) GstWasapiDeviceActivator * activator)
{ {
HRESULT hr; /* *INDENT-OFF* */
ComPtr<IDeviceInformationStatics> device_info_static; ComPtr<IDeviceInformationStatics> device_info_static;
ComPtr<IAsyncOperation<DeviceInformationCollection*>> async_op; ComPtr<IAsyncOperation<DeviceInformationCollection*>> async_op;
ComPtr<IVectorView<DeviceInformation*>> device_list; ComPtr<IVectorView<DeviceInformation*>> device_list;
HStringReference hstr_device_info = HStringReference hstr_device_info =
HStringReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation); HStringReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation);
/* *INDENT-ON* */
HRESULT hr;
DeviceClass device_class; DeviceClass device_class;
unsigned int count = 0; unsigned int count = 0;
gint device_index = 0; gint device_index = 0;
@ -596,8 +605,9 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
GST_INFO_OBJECT (self, GST_INFO_OBJECT (self,
"requested device info, device-class: %s, device: %s, device-index: %d", "requested device info, device-class: %s, device: %s, device-index: %d",
self->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE ? "capture" : self->device_class ==
"render", GST_STR_NULL (self->device_id), self->device_index); GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE ? "capture" : "render",
GST_STR_NULL (self->device_id), self->device_index);
if (self->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE) { if (self->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE) {
device_class = DeviceClass::DeviceClass_AudioCapture; device_class = DeviceClass::DeviceClass_AudioCapture;
@ -624,7 +634,7 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
* See https://docs.microsoft.com/en-us/windows/win32/coreaudio/automatic-stream-routing * See https://docs.microsoft.com/en-us/windows/win32/coreaudio/automatic-stream-routing
*/ */
if (self->device_id && if (self->device_id &&
g_ascii_strcasecmp (self->device_id, default_device_id.c_str()) == 0) { g_ascii_strcasecmp (self->device_id, default_device_id.c_str ()) == 0) {
GST_DEBUG_OBJECT (self, "Default device was requested"); GST_DEBUG_OBJECT (self, "Default device was requested");
use_default_device = TRUE; use_default_device = TRUE;
} else if (self->device_index < 0 && !self->device_id) { } else if (self->device_index < 0 && !self->device_id) {
@ -646,7 +656,7 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
goto activate; goto activate;
} }
hr = GetActivationFactory (hstr_device_info.Get(), &device_info_static); hr = GetActivationFactory (hstr_device_info.Get (), &device_info_static);
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
goto failed; goto failed;
@ -655,7 +665,9 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
goto failed; goto failed;
/* *INDENT-OFF* */
hr = SyncWait<DeviceInformationCollection*>(async_op.Get ()); hr = SyncWait<DeviceInformationCollection*>(async_op.Get ());
/* *INDENT-ON* */
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
goto failed; goto failed;
@ -686,7 +698,9 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
/* zero is for default device */ /* zero is for default device */
device_index = 1; device_index = 1;
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
/* *INDENT-OFF* */
ComPtr<IDeviceInformation> device_info; ComPtr<IDeviceInformation> device_info;
/* *INDENT-ON* */
HString id; HString id;
HString name; HString name;
boolean b_value; boolean b_value;
@ -709,16 +723,16 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
/* To ensure device id and device name are available, /* To ensure device id and device name are available,
* will query this later again once target device is determined */ * will query this later again once target device is determined */
hr = device_info->get_Id (id.GetAddressOf()); hr = device_info->get_Id (id.GetAddressOf ());
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
continue; continue;
if (!id.IsValid()) { if (!id.IsValid ()) {
GST_WARNING_OBJECT (self, "Device index %d has invalid id", i); GST_WARNING_OBJECT (self, "Device index %d has invalid id", i);
continue; continue;
} }
hr = device_info->get_Name (name.GetAddressOf()); hr = device_info->get_Name (name.GetAddressOf ());
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
continue; continue;
@ -740,7 +754,7 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
} }
GST_DEBUG_OBJECT (self, "device [%d] id: %s, name: %s", GST_DEBUG_OBJECT (self, "device [%d] id: %s, name: %s",
device_index, cur_device_id.c_str(), cur_device_name.c_str()); device_index, cur_device_id.c_str (), cur_device_name.c_str ());
if (self->device_id && if (self->device_id &&
g_ascii_strcasecmp (self->device_id, cur_device_id.c_str ()) == 0) { g_ascii_strcasecmp (self->device_id, cur_device_id.c_str ()) == 0) {
@ -774,7 +788,7 @@ gst_wasapi2_client_activate_async (GstWasapi2Client * self,
activate: activate:
/* fill device id and name */ /* fill device id and name */
g_free (self->device_id); g_free (self->device_id);
self->device_id = g_strdup (target_device_id.c_str()); self->device_id = g_strdup (target_device_id.c_str ());
g_free (self->device_name); g_free (self->device_name);
self->device_name = g_strdup (target_device_name.c_str ()); self->device_name = g_strdup (target_device_name.c_str ());
@ -825,10 +839,13 @@ gst_wasapi2_client_thread_func (GstWasapi2Client * self)
RoInitializeWrapper initialize (RO_INIT_MULTITHREADED); RoInitializeWrapper initialize (RO_INIT_MULTITHREADED);
GSource *source; GSource *source;
HRESULT hr; HRESULT hr;
/* *INDENT-OFF* */
ComPtr<GstWasapiDeviceActivator> activator; ComPtr<GstWasapiDeviceActivator> activator;
hr = MakeAndInitialize<GstWasapiDeviceActivator> (&activator, hr = MakeAndInitialize<GstWasapiDeviceActivator> (&activator,
self, self->dispatcher); self, self->dispatcher);
/* *INDENT-ON* */
if (!gst_wasapi2_result (hr)) { if (!gst_wasapi2_result (hr)) {
GST_ERROR_OBJECT (self, "Could not create activator object"); GST_ERROR_OBJECT (self, "Could not create activator object");
self->activate_state = GST_WASAPI2_CLIENT_ACTIVATE_FAILED; self->activate_state = GST_WASAPI2_CLIENT_ACTIVATE_FAILED;
@ -867,7 +884,7 @@ run_loop:
* Explicitly disable mute for later use of this audio device * Explicitly disable mute for later use of this audio device
* by other application. Otherwise users would blame GStreamer * by other application. Otherwise users would blame GStreamer
* if we close audio device with muted state */ * if we close audio device with muted state */
self->audio_volume->SetMute(FALSE, nullptr); self->audio_volume->SetMute (FALSE, nullptr);
self->audio_volume->Release (); self->audio_volume->Release ();
self->audio_volume = NULL; self->audio_volume = NULL;
} }
@ -914,8 +931,7 @@ gst_waveformatex_to_audio_format (WAVEFORMATEXTENSIBLE * format)
if (IsEqualGUID (format->SubFormat, KSDATAFORMAT_SUBTYPE_PCM)) { if (IsEqualGUID (format->SubFormat, KSDATAFORMAT_SUBTYPE_PCM)) {
fmt = gst_audio_format_build_integer (TRUE, G_LITTLE_ENDIAN, fmt = gst_audio_format_build_integer (TRUE, G_LITTLE_ENDIAN,
format->Format.wBitsPerSample, format->Samples.wValidBitsPerSample); format->Format.wBitsPerSample, format->Samples.wValidBitsPerSample);
} else if (IsEqualGUID (format->SubFormat, } else if (IsEqualGUID (format->SubFormat, KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) {
KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) {
if (format->Format.wBitsPerSample == 32 if (format->Format.wBitsPerSample == 32
&& format->Samples.wValidBitsPerSample == 32) && format->Samples.wValidBitsPerSample == 32)
fmt = GST_AUDIO_FORMAT_F32LE; fmt = GST_AUDIO_FORMAT_F32LE;
@ -1222,8 +1238,7 @@ gst_wasapi2_client_initialize_audio_client (GstWasapi2Client * self,
hr = audio_client->Initialize (AUDCLNT_SHAREMODE_SHARED, stream_flags, hr = audio_client->Initialize (AUDCLNT_SHAREMODE_SHARED, stream_flags,
device_buffer_duration, device_buffer_duration,
/* This must always be 0 in shared mode */ /* This must always be 0 in shared mode */
0, 0, self->mix_format, nullptr);
self->mix_format, nullptr);
if (!gst_wasapi2_result (hr)) { if (!gst_wasapi2_result (hr)) {
GST_WARNING_OBJECT (self, "Couldn't initialize audioclient"); GST_WARNING_OBJECT (self, "Couldn't initialize audioclient");
return FALSE; return FALSE;
@ -1237,14 +1252,16 @@ gst_wasapi2_client_initialize_audio_client (GstWasapi2Client * self,
} }
gboolean gboolean
gst_wasapi2_client_open (GstWasapi2Client * client, GstAudioRingBufferSpec * spec, gst_wasapi2_client_open (GstWasapi2Client * client,
GstAudioRingBuffer * buf) GstAudioRingBufferSpec * spec, GstAudioRingBuffer * buf)
{ {
HRESULT hr; HRESULT hr;
REFERENCE_TIME latency_rt; REFERENCE_TIME latency_rt;
guint bpf, rate; guint bpf, rate;
IAudioClient3 *audio_client; IAudioClient3 *audio_client;
/* *INDENT-OFF* */
ComPtr<ISimpleAudioVolume> audio_volume; ComPtr<ISimpleAudioVolume> audio_volume;
/* *INDENT-ON* */
gboolean initialized = FALSE; gboolean initialized = FALSE;
g_return_val_if_fail (GST_IS_WASAPI2_CLIENT (client), FALSE); g_return_val_if_fail (GST_IS_WASAPI2_CLIENT (client), FALSE);
@ -1325,7 +1342,9 @@ gst_wasapi2_client_open (GstWasapi2Client * client, GstAudioRingBufferSpec * spe
return FALSE; return FALSE;
if (client->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_RENDER) { if (client->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_RENDER) {
/* *INDENT-OFF* */
ComPtr<IAudioRenderClient> render_client; ComPtr<IAudioRenderClient> render_client;
/* *INDENT-ON* */
hr = audio_client->GetService (IID_PPV_ARGS (&render_client)); hr = audio_client->GetService (IID_PPV_ARGS (&render_client));
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
@ -1333,7 +1352,9 @@ gst_wasapi2_client_open (GstWasapi2Client * client, GstAudioRingBufferSpec * spe
client->audio_render_client = render_client.Detach (); client->audio_render_client = render_client.Detach ();
} else { } else {
/* *INDENT-OFF* */
ComPtr<IAudioCaptureClient> capture_client; ComPtr<IAudioCaptureClient> capture_client;
/* *INDENT-ON* */
hr = audio_client->GetService (IID_PPV_ARGS (&capture_client)); hr = audio_client->GetService (IID_PPV_ARGS (&capture_client));
if (!gst_wasapi2_result (hr)) if (!gst_wasapi2_result (hr))
@ -1355,7 +1376,7 @@ gst_wasapi2_client_open (GstWasapi2Client * client, GstAudioRingBufferSpec * spe
* Explicitly disable mute so that ensure we can produce or play audio * Explicitly disable mute so that ensure we can produce or play audio
* regardless of previous status * regardless of previous status
*/ */
client->audio_volume->SetMute(FALSE, nullptr); client->audio_volume->SetMute (FALSE, nullptr);
gst_audio_ring_buffer_set_channel_positions (buf, client->positions); gst_audio_ring_buffer_set_channel_positions (buf, client->positions);
@ -1654,7 +1675,7 @@ gst_wasapi2_client_write (GstWasapi2Client * client, gpointer data,
have_frames = length / (mix_format->nBlockAlign); have_frames = length / (mix_format->nBlockAlign);
/* In shared mode we can write parts of the buffer, so only wait /* In shared mode we can write parts of the buffer, so only wait
* in case we can't write anything */ * in case we can't write anything */
can_frames = gst_wasapi2_client_get_can_frames (client); can_frames = gst_wasapi2_client_get_can_frames (client);
if (can_frames < 0) { if (can_frames < 0) {
GST_ERROR_OBJECT (client, "Error getting frames to write to"); GST_ERROR_OBJECT (client, "Error getting frames to write to");
@ -1844,21 +1865,23 @@ gst_wasapi2_client_ensure_activation (GstWasapi2Client * client)
static HRESULT static HRESULT
find_dispatcher (ICoreDispatcher ** dispatcher) find_dispatcher (ICoreDispatcher ** dispatcher)
{ {
/* *INDENT-OFF* */
HStringReference hstr_core_app = HStringReference hstr_core_app =
HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication); HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication);
ComPtr<ICoreApplication> core_app;
ComPtr<ICoreApplicationView> core_app_view;
ComPtr<ICoreWindow> core_window;
/* *INDENT-ON* */
HRESULT hr; HRESULT hr;
ComPtr<ICoreApplication> core_app; hr = GetActivationFactory (hstr_core_app.Get (), &core_app);
hr = GetActivationFactory (hstr_core_app.Get(), &core_app);
if (FAILED (hr)) if (FAILED (hr))
return hr; return hr;
ComPtr<ICoreApplicationView> core_app_view;
hr = core_app->GetCurrentView (&core_app_view); hr = core_app->GetCurrentView (&core_app_view);
if (FAILED (hr)) if (FAILED (hr))
return hr; return hr;
ComPtr<ICoreWindow> core_window;
hr = core_app_view->get_CoreWindow (&core_window); hr = core_app_view->get_CoreWindow (&core_window);
if (FAILED (hr)) if (FAILED (hr))
return hr; return hr;
@ -1872,7 +1895,9 @@ gst_wasapi2_client_new (GstWasapi2ClientDeviceClass device_class,
gpointer dispatcher) gpointer dispatcher)
{ {
GstWasapi2Client *self; GstWasapi2Client *self;
/* *INDENT-OFF* */
ComPtr<ICoreDispatcher> core_dispatcher; ComPtr<ICoreDispatcher> core_dispatcher;
/* *INDENT-ON* */
/* Multiple COM init is allowed */ /* Multiple COM init is allowed */
RoInitializeWrapper init_wrapper (RO_INIT_MULTITHREADED); RoInitializeWrapper init_wrapper (RO_INIT_MULTITHREADED);