mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-22 17:51:16 +00:00
wasapi2: Use C++ atomic instead of GLib
Release-Acquire ordering could be faster than MemoryBarrier() Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5176>
This commit is contained in:
parent
c992dd2184
commit
ae04702d23
2 changed files with 24 additions and 10 deletions
|
@ -40,6 +40,7 @@
|
|||
#include <string>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <atomic>
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
using namespace ABI::Windows::ApplicationModel::Core;
|
||||
|
@ -315,7 +316,7 @@ public:
|
|||
{
|
||||
GstWasapi2Client *client = (GstWasapi2Client *) g_weak_ref_get (&client_);
|
||||
if (client) {
|
||||
gst_wasapi2_client_set_endpoint_muted (client, !!notify->bMuted);
|
||||
gst_wasapi2_client_set_endpoint_muted (client, notify->bMuted);
|
||||
gst_object_unref (client);
|
||||
}
|
||||
return S_OK;
|
||||
|
@ -349,10 +350,17 @@ enum
|
|||
#define DEFAULT_DEVICE_INDEX -1
|
||||
#define DEFAULT_DEVICE_CLASS GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE
|
||||
|
||||
struct GstWasapi2ClientPrivate
|
||||
{
|
||||
std::atomic < bool >is_endpoint_muted;
|
||||
};
|
||||
|
||||
struct _GstWasapi2Client
|
||||
{
|
||||
GstObject parent;
|
||||
|
||||
GstWasapi2ClientPrivate *priv;
|
||||
|
||||
GstWasapi2ClientDeviceClass device_class;
|
||||
gchar *device_id;
|
||||
gchar *device_name;
|
||||
|
@ -366,7 +374,6 @@ struct _GstWasapi2Client
|
|||
GMutex endpoint_volume_lock;
|
||||
IAudioEndpointVolume *audio_endpoint_volume;
|
||||
GstWasapiEndpointVolumeCallback *endpoint_volume_callback;
|
||||
gint is_endpoint_muted;
|
||||
|
||||
GstCaps *supported_caps;
|
||||
|
||||
|
@ -481,6 +488,9 @@ gst_wasapi2_client_init (GstWasapi2Client * self)
|
|||
|
||||
self->context = g_main_context_new ();
|
||||
self->loop = g_main_loop_new (self->context, FALSE);
|
||||
|
||||
self->priv = new GstWasapi2ClientPrivate ();
|
||||
self->priv->is_endpoint_muted.store (false, std::memory_order_release);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -531,6 +541,8 @@ gst_wasapi2_client_finalize (GObject * object)
|
|||
|
||||
g_mutex_clear (&self->endpoint_volume_lock);
|
||||
|
||||
delete self->priv;
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -664,7 +676,7 @@ gst_wasapi2_client_on_endpoint_volume_activated (GstWasapi2Client * self,
|
|||
|
||||
hr = audio_endpoint_volume->GetMute (&initially_muted);
|
||||
if (gst_wasapi2_result (hr)) {
|
||||
gst_wasapi2_client_set_endpoint_muted (self, !!initially_muted);
|
||||
gst_wasapi2_client_set_endpoint_muted (self, initially_muted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -679,7 +691,7 @@ gst_wasapi2_client_set_endpoint_muted (GstWasapi2Client * self, gboolean muted)
|
|||
{
|
||||
GST_DEBUG_OBJECT (self, "Audio Endpoint Volume: muted=%d", muted);
|
||||
|
||||
g_atomic_int_set (&self->is_endpoint_muted, muted);
|
||||
self->priv->is_endpoint_muted.store (muted, std::memory_order_release);
|
||||
}
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
@ -1287,5 +1299,5 @@ gst_wasapi2_client_is_endpoint_muted (GstWasapi2Client * client)
|
|||
{
|
||||
g_return_val_if_fail (GST_IS_WASAPI2_CLIENT (client), FALSE);
|
||||
|
||||
return g_atomic_int_get (&client->is_endpoint_muted);
|
||||
return client->priv->is_endpoint_muted.load (std::memory_order_acquire);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <mfapi.h>
|
||||
#include <wrl.h>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_wasapi2_ring_buffer_debug);
|
||||
#define GST_CAT_DEFAULT gst_wasapi2_ring_buffer_debug
|
||||
|
@ -141,6 +142,7 @@ private:
|
|||
struct GstWasapi2RingBufferPrivate
|
||||
{
|
||||
std::shared_ptr<GstWasapi2RingBufferPtr> obj_ptr;
|
||||
std::atomic<bool> monitor_device_mute;
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
@ -186,8 +188,6 @@ struct _GstWasapi2RingBuffer
|
|||
gboolean mute_changed;
|
||||
gboolean volume_changed;
|
||||
|
||||
gboolean monitor_device_mute;
|
||||
|
||||
GstCaps *supported_caps;
|
||||
|
||||
GstWasapi2RingBufferPrivate *priv;
|
||||
|
@ -254,6 +254,7 @@ gst_wasapi2_ring_buffer_init (GstWasapi2RingBuffer * self)
|
|||
|
||||
self->priv = new GstWasapi2RingBufferPrivate ();
|
||||
self->priv->obj_ptr = std::make_shared < GstWasapi2RingBufferPtr > (self);
|
||||
self->priv->monitor_device_mute.store (false, std::memory_order_release);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -484,7 +485,7 @@ gst_wasapi2_ring_buffer_read (GstWasapi2RingBuffer * self)
|
|||
gint segment;
|
||||
guint8 *readptr;
|
||||
gint len;
|
||||
gboolean is_device_muted;
|
||||
bool is_device_muted;
|
||||
|
||||
if (!capture_client) {
|
||||
GST_ERROR_OBJECT (self, "IAudioCaptureClient is not available");
|
||||
|
@ -498,7 +499,8 @@ gst_wasapi2_ring_buffer_read (GstWasapi2RingBuffer * self)
|
|||
goto out;
|
||||
}
|
||||
|
||||
is_device_muted = g_atomic_int_get (&self->monitor_device_mute) &&
|
||||
is_device_muted =
|
||||
self->priv->monitor_device_mute.load (std::memory_order_acquire) &&
|
||||
gst_wasapi2_client_is_endpoint_muted (self->client);
|
||||
|
||||
to_read_bytes = to_read * GST_AUDIO_INFO_BPF (info);
|
||||
|
@ -1517,5 +1519,5 @@ gst_wasapi2_ring_buffer_set_device_mute_monitoring (GstWasapi2RingBuffer * buf,
|
|||
{
|
||||
g_return_if_fail (GST_IS_WASAPI2_RING_BUFFER (buf));
|
||||
|
||||
g_atomic_int_set (&buf->monitor_device_mute, value);
|
||||
buf->priv->monitor_device_mute.store (value, std::memory_order_release);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue