Merge branch '0.4' into next

This commit is contained in:
George Kiagiadakis 2023-06-21 20:59:04 +03:00
commit a0497b4256
11 changed files with 166 additions and 52 deletions

View file

@ -626,6 +626,8 @@ wp_node_send_command (WpNode * self, const gchar * command)
g_return_if_fail (WP_IS_NODE (self));
g_return_if_fail (command_value != NULL);
g_return_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
WP_PROXY_FEATURE_BOUND);
struct spa_command cmd =
SPA_NODE_COMMAND_INIT(wp_spa_id_value_number (command_value));

View file

@ -127,6 +127,18 @@ wp_spa_json_builder_new (const gchar *data, size_t size)
return self;
}
static WpSpaJsonBuilder *
wp_spa_json_builder_new_empty (size_t size)
{
WpSpaJsonBuilder *self = g_rc_box_new0 (WpSpaJsonBuilder);
self->add_separator = FALSE;
self->data = g_new0 (gchar, size + 1);
self->max_size = size;
self->data[0] = '\0';
self->size = 0;
return self;
}
static WpSpaJsonBuilder *
wp_spa_json_builder_new_formatted (const gchar *fmt, ...)
{
@ -380,6 +392,17 @@ wp_spa_json_new_float (float value)
wp_spa_json_builder_new_formatted ("%.6f", value));
}
static void
ensure_allocated_max_size (WpSpaJsonBuilder *self, size_t size)
{
size_t new_size = self->size + size + 1; /* '\0' because of vsnprintf */
if (new_size > self->max_size) {
size_t next_size = new_size * 2;
self->data = g_realloc (self->data, next_size);
self->max_size = next_size;
}
}
/*!
* \brief Creates a spa json of type string
*
@ -390,10 +413,17 @@ wp_spa_json_new_float (float value)
WpSpaJson *
wp_spa_json_new_string (const gchar *value)
{
size_t size = (strlen (value) * 4) + 2;
gchar dst[size];
gint enc_size = spa_json_encode_string (dst, sizeof(dst), value);
return wp_spa_json_new_from_builder (wp_spa_json_builder_new (dst, enc_size));
WpSpaJsonBuilder *b = wp_spa_json_builder_new_empty (strlen (value));
size_t enc_size = spa_json_encode_string (b->data + b->size,
b->max_size - b->size, value);
if (enc_size + 1 > b->max_size - b->size) {
ensure_allocated_max_size (b, enc_size);
enc_size = spa_json_encode_string (b->data + b->size,
b->max_size - b->size, value);
g_assert (enc_size < b->max_size - b->size);
}
b->size += enc_size;
return wp_spa_json_new_from_builder (b);
}
/* Args is not a pointer in some architectures, so this needs to be a macro to
@ -944,17 +974,6 @@ wp_spa_json_builder_new_object (void)
return self;
}
static void
ensure_allocated_max_size (WpSpaJsonBuilder *self, size_t size)
{
size_t new_size = self->size + size + 1; /* '\0' because of vsnprintf */
if (new_size > self->max_size) {
size_t next_size = new_size * 2;
self->data = g_realloc (self->data, next_size);
self->max_size = next_size;
}
}
static void
ensure_separator (WpSpaJsonBuilder *self, gboolean for_property)
{
@ -1001,14 +1020,18 @@ builder_add (WpSpaJsonBuilder *self, const gchar *data, size_t size)
void
wp_spa_json_builder_add_property (WpSpaJsonBuilder *self, const gchar *key)
{
size_t size = (strlen (key) * 4) + 3;
gchar dst[size];
gint enc_size;
size_t enc_size;
ensure_separator (self, TRUE);
ensure_allocated_max_size (self, size);
enc_size = spa_json_encode_string (dst, sizeof(dst), key);
builder_add (self, dst, enc_size);
builder_add (self, ":", 1);
enc_size = spa_json_encode_string (self->data + self->size,
self->max_size - self->size, key);
if (enc_size + 2 > self->max_size - self->size) {
ensure_allocated_max_size (self, enc_size + 1);
enc_size = spa_json_encode_string (self->data + self->size,
self->max_size - self->size, key);
g_assert (enc_size + 1 < self->max_size - self->size);
}
self->data[self->size + enc_size] = ':';
self->size += enc_size + 1;
}
/*!
@ -1080,13 +1103,17 @@ wp_spa_json_builder_add_float (WpSpaJsonBuilder *self, float value)
void
wp_spa_json_builder_add_string (WpSpaJsonBuilder *self, const gchar *value)
{
size_t size = (strlen (value) * 4) + 2;
gchar dst[size];
gint enc_size;
size_t enc_size;
ensure_separator (self, FALSE);
ensure_allocated_max_size (self, size);
enc_size = spa_json_encode_string (dst, sizeof(dst), value);
builder_add (self, dst, enc_size);
enc_size = spa_json_encode_string (self->data + self->size,
self->max_size - self->size, value);
if (enc_size + 1 > self->max_size - self->size) {
ensure_allocated_max_size (self, enc_size);
enc_size = spa_json_encode_string (self->data + self->size,
self->max_size - self->size, value);
g_assert (enc_size < self->max_size - self->size);
}
self->size += enc_size;
}
/*!

View file

@ -31,10 +31,6 @@ nodes_om = ObjectManager {
}
}
function applyDefaultDeviceProperties (properties)
properties["bluez5.auto-connect"] = "[ hfp_hf hsp_hs a2dp_sink ]"
end
function setOffloadActive(device, value)
local pod = Pod.Object {
"Spa:Pod:Object:Param:Props", "Props", bluetoothOffloadActive = value
@ -343,11 +339,7 @@ function createDevice(parent, id, type, factory, properties)
properties["api.bluez5.id"] = id
-- apply properties from bluetooth.conf
local applied = cutils.evaluateRulesApplyProperties (properties,
"monitor.bluetooth.rules")
if not applied then
applyDefaultDeviceProperties (properties)
end
cutils.evaluateRulesApplyProperties (properties, "monitor.bluetooth.rules")
-- create the device
device = SpaDevice(factory, properties)

View file

@ -47,8 +47,11 @@ SimpleEventHook {
-- add idle timeout; multiply by 1000, timeout_add() expects ms
sources[id] = Core.timeout_add(timeout * 1000, function()
-- Suspend the node
log:info(node, "was idle for a while; suspending ...")
node:send_command("Suspend")
-- but check first if the node still exists
if (node:get_active_features() & Feature.Proxy.BOUND) ~= 0 then
log:info(node, "was idle for a while; suspending ...")
node:send_command("Suspend")
end
-- Unref the source
sources[id] = nil

View file

@ -8,7 +8,6 @@ Conflicts=pipewire-media-session.service
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictNamespaces=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
Type=simple

View file

@ -13,7 +13,6 @@ Conflicts=pipewire-media-session.service
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictNamespaces=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
Type=simple

View file

@ -8,7 +8,6 @@ Conflicts=pipewire-media-session.service
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictNamespaces=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
Type=simple

View file

@ -13,7 +13,6 @@ Conflicts=pipewire-media-session.service
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictNamespaces=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
Type=simple

View file

@ -34,6 +34,10 @@ struct _WpCtl
static struct {
union {
struct {
gboolean display_nicknames;
gboolean display_names;
} status;
struct {
guint64 id;
gboolean show_referenced;
@ -233,10 +237,16 @@ print_device (const GValue *item, gpointer data)
WpPipewireObject *obj = g_value_get_object (item);
guint32 id = wp_proxy_get_bound_id (WP_PROXY (obj));
const gchar *api = wp_pipewire_object_get_property (obj, PW_KEY_DEVICE_API);
const gchar *name = wp_pipewire_object_get_property (obj, PW_KEY_DEVICE_DESCRIPTION);
if (!name)
const gchar *name = NULL;
if (cmdline.status.display_nicknames)
name = wp_pipewire_object_get_property (obj, PW_KEY_DEVICE_NICK);
else if (cmdline.status.display_names)
name = wp_pipewire_object_get_property (obj, PW_KEY_DEVICE_NAME);
if (!name)
name = wp_pipewire_object_get_property (obj, PW_KEY_DEVICE_DESCRIPTION);
printf (TREE_INDENT_LINE " %4u. %-35s [%s]\n", id, name, api);
}
@ -247,13 +257,16 @@ print_dev_node (const GValue *item, gpointer data)
struct print_context *context = data;
guint32 id = wp_proxy_get_bound_id (WP_PROXY (obj));
gboolean is_default = (context->default_node == id);
const gchar *name =
wp_pipewire_object_get_property (obj, PW_KEY_NODE_DESCRIPTION);
if (!name)
name = wp_pipewire_object_get_property (obj, PW_KEY_APP_NAME);
if (!name)
const gchar *name = NULL;
if (cmdline.status.display_nicknames)
name = wp_pipewire_object_get_property (obj, PW_KEY_NODE_NICK);
else if (cmdline.status.display_names)
name = wp_pipewire_object_get_property (obj, PW_KEY_NODE_NAME);
if (!name)
name = wp_pipewire_object_get_property (obj, PW_KEY_NODE_DESCRIPTION);
printf (TREE_INDENT_LINE "%c %4u. %-35s", is_default ? '*' : ' ', id, name);
print_controls (id, context);
}
@ -1202,7 +1215,15 @@ static const struct subcommand {
.positional_args = "",
.summary = "Displays the current state of objects in PipeWire",
.description = NULL,
.entries = { { NULL } },
.entries = {
{ "nick", 'k', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&cmdline.status.display_nicknames,
"Display device and node nicknames instead of descriptions", NULL },
{ "name", 'n', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&cmdline.status.display_names,
"Display device and node names instead of descriptions", NULL },
{ NULL }
},
.parse_positional = NULL,
.prepare = status_prepare,
.run = status_run,

View file

@ -73,7 +73,7 @@ wp_base_test_fixture_setup (WpBaseTestFixture * self, WpBaseTestFlags flags)
g_main_context_push_thread_default (self->context);
/* watchdog */
self->timeout_source = g_timeout_source_new_seconds (3);
self->timeout_source = g_timeout_source_new_seconds (8);
g_source_set_callback (self->timeout_source, (GSourceFunc) timeout_callback,
self, NULL);
g_source_attach (self->timeout_source, self->context);

View file

@ -78,6 +78,13 @@ test_spa_json_basic (void)
g_assert_nonnull (v3);
g_assert_cmpstr (v3, ==,
"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong");
g_autoptr (WpSpaJson) jsons = wp_spa_json_new_string ("\v\v\v\v");
g_assert_nonnull (jsons);
g_assert_true (wp_spa_json_is_string (jsons));
g_autofree gchar *v4 = wp_spa_json_parse_string (jsons);
g_assert_nonnull (v4);
g_assert_cmpstr (v4, ==, "\v\v\v\v");
}
/* Array */
@ -280,6 +287,10 @@ test_spa_json_object_builder_parser_iterator (void)
wp_spa_json_builder_add_float (b, 0.12f);
wp_spa_json_builder_add_property (b, "key-string");
wp_spa_json_builder_add_string (b, "str");
wp_spa_json_builder_add_property (b, "key-empty-string");
wp_spa_json_builder_add_string (b, "");
wp_spa_json_builder_add_property (b, "key-special-char-string");
wp_spa_json_builder_add_string (b, "\v\v\v\v");
json = wp_spa_json_builder_end (b);
}
@ -322,6 +333,20 @@ test_spa_json_object_builder_parser_iterator (void)
g_assert_nonnull (v_string);
g_assert_cmpstr (v_string, ==, "str");
g_autofree gchar *key_empty_string = wp_spa_json_parser_get_string (p);
g_assert_nonnull (key_empty_string);
g_assert_cmpstr (key_empty_string, ==, "key-empty-string");
g_autofree gchar *v_empty_string = wp_spa_json_parser_get_string (p);
g_assert_nonnull (v_empty_string);
g_assert_cmpstr (v_empty_string, ==, "");
g_autofree gchar *key_special_char_string = wp_spa_json_parser_get_string (p);
g_assert_nonnull (key_special_char_string);
g_assert_cmpstr (key_special_char_string, ==, "key-special-char-string");
g_autofree gchar *v_special_char_string = wp_spa_json_parser_get_string (p);
g_assert_nonnull (v_special_char_string);
g_assert_cmpstr (v_special_char_string, ==, "\v\v\v\v");
wp_spa_json_parser_end (p);
g_assert_false (wp_spa_json_parser_get_null (p));
}
@ -446,6 +471,54 @@ test_spa_json_object_builder_parser_iterator (void)
g_value_unset (&next);
}
{
GValue next = G_VALUE_INIT;
g_assert_true (wp_iterator_next (it, &next));
WpSpaJson *j = g_value_get_boxed (&next);
g_assert_nonnull (j);
g_assert_true (wp_spa_json_is_string (j));
g_autofree gchar *v = wp_spa_json_parse_string (j);
g_assert_nonnull (v);
g_assert_cmpstr (v, ==, "key-empty-string");
g_value_unset (&next);
}
{
GValue next = G_VALUE_INIT;
g_assert_true (wp_iterator_next (it, &next));
WpSpaJson *j = g_value_get_boxed (&next);
g_assert_nonnull (j);
g_assert_true (wp_spa_json_is_string (j));
g_autofree gchar *v = wp_spa_json_parse_string (j);
g_assert_nonnull (v);
g_assert_cmpstr (v, ==, "");
g_value_unset (&next);
}
{
GValue next = G_VALUE_INIT;
g_assert_true (wp_iterator_next (it, &next));
WpSpaJson *j = g_value_get_boxed (&next);
g_assert_nonnull (j);
g_assert_true (wp_spa_json_is_string (j));
g_autofree gchar *v = wp_spa_json_parse_string (j);
g_assert_nonnull (v);
g_assert_cmpstr (v, ==, "key-special-char-string");
g_value_unset (&next);
}
{
GValue next = G_VALUE_INIT;
g_assert_true (wp_iterator_next (it, &next));
WpSpaJson *j = g_value_get_boxed (&next);
g_assert_nonnull (j);
g_assert_true (wp_spa_json_is_string (j));
g_autofree gchar *v = wp_spa_json_parse_string (j);
g_assert_nonnull (v);
g_assert_cmpstr (v, ==, "\v\v\v\v");
g_value_unset (&next);
}
g_assert_false (wp_iterator_next (it, NULL));
wp_iterator_reset (it);