2018-10-10 18:50:11 +02:00
|
|
|
/* PipeWire
|
|
|
|
|
*
|
2020-02-07 15:43:13 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2018-10-10 18:50:11 +02:00
|
|
|
*
|
2020-02-07 15:43:13 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2018-10-10 18:50:11 +02:00
|
|
|
*
|
2020-02-07 15:43:13 +01:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2018-10-10 18:50:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
|
|
#include <jack/metadata.h>
|
2019-08-21 18:37:02 +02:00
|
|
|
#include <jack/uuid.h>
|
2018-10-10 18:50:11 +02:00
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
2019-11-05 10:01:43 +01:00
|
|
|
#include <extensions/metadata.h>
|
2019-08-21 18:37:02 +02:00
|
|
|
|
|
|
|
|
static struct pw_properties * get_properties(void)
|
|
|
|
|
{
|
2019-11-05 10:01:43 +01:00
|
|
|
if (globals.properties == NULL) {
|
|
|
|
|
globals.properties = pw_properties_new(NULL, NULL);
|
2019-08-21 18:37:02 +02:00
|
|
|
}
|
2019-11-05 10:01:43 +01:00
|
|
|
return globals.properties;
|
2019-08-21 18:37:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void make_key(char *dst, jack_uuid_t subject, const char *key, int keylen)
|
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
jack_uuid_unparse (subject, dst);
|
|
|
|
|
len = strlen(dst);
|
|
|
|
|
dst[len] = '@';
|
|
|
|
|
memcpy(&dst[len+1], key, keylen+1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
|
|
|
|
int jack_set_property(jack_client_t*client,
|
|
|
|
|
jack_uuid_t subject,
|
|
|
|
|
const char* key,
|
|
|
|
|
const char* value,
|
|
|
|
|
const char* type)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
2019-11-05 10:01:43 +01:00
|
|
|
struct client *c = (struct client *) client;
|
|
|
|
|
uint32_t id;
|
2019-08-21 18:37:02 +02:00
|
|
|
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_val_if_fail(c != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(key != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(value != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(type != NULL, -EINVAL);
|
|
|
|
|
|
2019-11-05 10:01:43 +01:00
|
|
|
id = jack_uuid_to_index(subject);
|
2019-08-21 18:37:02 +02:00
|
|
|
|
2019-11-05 10:01:43 +01:00
|
|
|
pw_log_debug("set id:%u (%lu) '%s' to '%s@%s'", id, subject, key, value, type);
|
|
|
|
|
pw_metadata_set_property(c->metadata->proxy,
|
|
|
|
|
id, key, type, value);
|
2019-08-21 18:37:02 +02:00
|
|
|
return 0;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
|
|
|
|
int jack_get_property(jack_uuid_t subject,
|
|
|
|
|
const char* key,
|
|
|
|
|
char** value,
|
|
|
|
|
char** type)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
int keylen;
|
|
|
|
|
char *dst;
|
2019-08-21 18:37:02 +02:00
|
|
|
struct pw_properties * props = get_properties();
|
|
|
|
|
const char *str, *at;
|
|
|
|
|
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_val_if_fail(key != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(value != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(type != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
keylen = strlen(key);
|
|
|
|
|
dst = alloca(JACK_UUID_STRING_SIZE + keylen);
|
2019-08-21 18:37:02 +02:00
|
|
|
make_key(dst, subject, key, keylen);
|
|
|
|
|
|
|
|
|
|
if ((str = pw_properties_get(props, dst)) == NULL) {
|
|
|
|
|
pw_log_warn("no property '%s'", dst);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
at = strrchr(str, '@');
|
|
|
|
|
if (at == NULL) {
|
|
|
|
|
pw_log_warn("property '%s' invalid value '%s'", dst, str);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*value = strndup(str, at - str);
|
|
|
|
|
*type = strdup(at + 1);
|
|
|
|
|
|
|
|
|
|
pw_log_debug("got '%s' with value:'%s' type:'%s'", dst, *value, *type);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
|
|
|
|
void jack_free_description (jack_description_t* desc, int free_description_itself)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
|
|
|
|
int jack_get_properties (jack_uuid_t subject,
|
|
|
|
|
jack_description_t* desc)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
|
|
|
|
int jack_get_all_properties (jack_description_t** descs)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
int jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key)
|
|
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
int keylen;
|
|
|
|
|
char *dst;
|
2019-08-21 18:37:02 +02:00
|
|
|
struct pw_properties * props = get_properties();
|
|
|
|
|
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_val_if_fail(client != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(key != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
keylen = strlen(key);
|
|
|
|
|
dst = alloca(JACK_UUID_STRING_SIZE + keylen);
|
2019-08-21 18:37:02 +02:00
|
|
|
make_key(dst, subject, key, keylen);
|
|
|
|
|
|
|
|
|
|
pw_properties_set(props, dst, NULL);
|
|
|
|
|
pw_log_debug("removed %s", dst);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
int jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
|
|
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
int jack_remove_all_properties (jack_client_t* client)
|
|
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
int jack_set_property_change_callback (jack_client_t* client,
|
|
|
|
|
JackPropertyChangeCallback callback,
|
|
|
|
|
void* arg)
|
|
|
|
|
{
|
|
|
|
|
pw_log_warn("not implemented");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_PRETTY_NAME = "http://jackaudio.org/metadata/pretty-name";
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_HARDWARE = "http://jackaudio.org/metadata/hardware";
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_CONNECTED = "http://jackaudio.org/metadata/connected";
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_PORT_GROUP = "http://jackaudio.org/metadata/port-group";
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_ICON_SMALL = "http://jackaudio.org/metadata/icon-small";
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
const char* JACK_METADATA_ICON_LARGE = "http://jackaudio.org/metadata/icon-large";
|