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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
|
|
#include <jack/uuid.h>
|
|
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2018-10-10 18:50:11 +02:00
|
|
|
jack_uuid_t jack_client_uuid_generate ()
|
|
|
|
|
{
|
2019-08-21 18:37:02 +02:00
|
|
|
static uint32_t uuid_cnt = 0;
|
|
|
|
|
jack_uuid_t uuid = 0x2; /* JackUUIDClient */;
|
|
|
|
|
uuid = (uuid << 32) | ++uuid_cnt;
|
2019-08-21 20:36:29 +02:00
|
|
|
pw_log_debug("uuid %"PRIu64, uuid);
|
2019-08-21 18:37:02 +02:00
|
|
|
return uuid;
|
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
|
|
|
jack_uuid_t jack_port_uuid_generate (uint32_t port_id)
|
|
|
|
|
{
|
2019-08-21 18:37:02 +02:00
|
|
|
jack_uuid_t uuid = 0x1; /* JackUUIDPort */
|
|
|
|
|
uuid = (uuid << 32) | (port_id + 1);
|
2019-08-21 20:36:29 +02:00
|
|
|
pw_log_debug("uuid %d -> %"PRIu64, port_id, uuid);
|
2019-08-21 18:37:02 +02:00
|
|
|
return uuid;
|
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
|
|
|
uint32_t jack_uuid_to_index (jack_uuid_t id)
|
|
|
|
|
{
|
2021-12-24 11:30:56 +01:00
|
|
|
return (id & 0xffffff) - 1;
|
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_uuid_compare (jack_uuid_t id1, jack_uuid_t id2)
|
|
|
|
|
{
|
2019-08-21 18:37:02 +02:00
|
|
|
if (id1 == id2)
|
|
|
|
|
return 0;
|
|
|
|
|
if (id1 < id2)
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
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
|
|
|
void jack_uuid_copy (jack_uuid_t* dst, jack_uuid_t src)
|
|
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_if_fail(dst != NULL);
|
2019-08-21 18:37:02 +02:00
|
|
|
*dst = src;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2019-08-21 18:37:02 +02:00
|
|
|
void jack_uuid_clear (jack_uuid_t *id)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_if_fail(id != NULL);
|
2019-08-21 18:37:02 +02:00
|
|
|
*id = 0;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-11 16:36:52 +02:00
|
|
|
SPA_EXPORT
|
2019-08-21 18:37:02 +02:00
|
|
|
int jack_uuid_parse (const char *buf, jack_uuid_t *id)
|
2018-10-10 18:50:11 +02:00
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_val_if_fail(buf != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(id != NULL, -EINVAL);
|
|
|
|
|
|
2019-08-21 18:37:02 +02:00
|
|
|
if (sscanf (buf, "%" PRIu64, id) == 1) {
|
|
|
|
|
if (*id < (0x1LL << 32)) {
|
|
|
|
|
/* has not type bits set - not legal */
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
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
|
|
|
void jack_uuid_unparse (jack_uuid_t id, char buf[JACK_UUID_STRING_SIZE])
|
|
|
|
|
{
|
2020-02-24 11:25:31 +01:00
|
|
|
spa_return_if_fail(buf != NULL);
|
2019-08-21 18:37:02 +02:00
|
|
|
snprintf (buf, JACK_UUID_STRING_SIZE, "%" PRIu64, id);
|
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_uuid_empty (jack_uuid_t id)
|
|
|
|
|
{
|
2019-08-21 18:37:02 +02:00
|
|
|
return id == 0;
|
2018-10-10 18:50:11 +02:00
|
|
|
}
|