mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
treewide: add some examples for the spa_auto* macros
This commit is contained in:
parent
65d949558b
commit
fe45786a5d
16 changed files with 136 additions and 236 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
#include <libudev.h>
|
#include <libudev.h>
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
|
#include <spa/utils/cleanup.h>
|
||||||
#include <spa/utils/type.h>
|
#include <spa/utils/type.h>
|
||||||
#include <spa/utils/keys.h>
|
#include <spa/utils/keys.h>
|
||||||
#include <spa/utils/names.h>
|
#include <spa/utils/names.h>
|
||||||
|
|
@ -228,27 +229,24 @@ static void unescape(const char *src, char *dst)
|
||||||
|
|
||||||
static int check_device_pcm_class(const char *devname)
|
static int check_device_pcm_class(const char *devname)
|
||||||
{
|
{
|
||||||
FILE *f;
|
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char buf[16];
|
char buf[16];
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
/* Check device class */
|
/* Check device class */
|
||||||
spa_scnprintf(path, sizeof(path), "/sys/class/sound/%s/pcm_class",
|
spa_scnprintf(path, sizeof(path), "/sys/class/sound/%s/pcm_class", devname);
|
||||||
devname);
|
|
||||||
f = fopen(path, "re");
|
spa_autoptr(FILE) f = fopen(path, "re");
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
sz = fread(buf, 1, sizeof(buf) - 1, f);
|
sz = fread(buf, 1, sizeof(buf) - 1, f);
|
||||||
buf[sz] = '\0';
|
buf[sz] = '\0';
|
||||||
fclose(f);
|
|
||||||
return spa_strstartswith(buf, "modem") ? -ENXIO : 0;
|
return spa_strstartswith(buf, "modem") ? -ENXIO : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_num_pcm_devices(unsigned int card_id)
|
static int get_num_pcm_devices(unsigned int card_id)
|
||||||
{
|
{
|
||||||
char prefix[32];
|
char prefix[32];
|
||||||
DIR *snd = NULL;
|
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
int num_dev = 0;
|
int num_dev = 0;
|
||||||
int res;
|
int res;
|
||||||
|
|
@ -257,7 +255,8 @@ static int get_num_pcm_devices(unsigned int card_id)
|
||||||
|
|
||||||
spa_scnprintf(prefix, sizeof(prefix), "pcmC%uD", card_id);
|
spa_scnprintf(prefix, sizeof(prefix), "pcmC%uD", card_id);
|
||||||
|
|
||||||
if ((snd = opendir("/dev/snd")) == NULL)
|
spa_autoptr(DIR) snd = opendir("/dev/snd");
|
||||||
|
if (snd == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
while ((errno = 0, entry = readdir(snd)) != NULL) {
|
while ((errno = 0, entry = readdir(snd)) != NULL) {
|
||||||
|
|
@ -271,20 +270,13 @@ static int get_num_pcm_devices(unsigned int card_id)
|
||||||
++num_dev;
|
++num_dev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errno != 0)
|
|
||||||
res = -errno;
|
|
||||||
else
|
|
||||||
res = num_dev;
|
|
||||||
|
|
||||||
closedir(snd);
|
return errno != 0 ? -errno : num_dev;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_device_available(struct impl *this, struct device *device, int *num_pcm)
|
static int check_device_available(struct impl *this, struct device *device, int *num_pcm)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
DIR *card = NULL, *pcm = NULL;
|
|
||||||
FILE *f;
|
|
||||||
char buf[16];
|
char buf[16];
|
||||||
size_t sz;
|
size_t sz;
|
||||||
struct dirent *entry, *entry_pcm;
|
struct dirent *entry, *entry_pcm;
|
||||||
|
|
@ -314,7 +306,8 @@ static int check_device_available(struct impl *this, struct device *device, int
|
||||||
|
|
||||||
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u", (unsigned int)device->id);
|
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u", (unsigned int)device->id);
|
||||||
|
|
||||||
if ((card = opendir(path)) == NULL)
|
spa_autoptr(DIR) card = opendir(path);
|
||||||
|
if (card == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
while ((errno = 0, entry = readdir(card)) != NULL) {
|
while ((errno = 0, entry = readdir(card)) != NULL) {
|
||||||
|
|
@ -330,7 +323,9 @@ static int check_device_available(struct impl *this, struct device *device, int
|
||||||
/* Check busy status */
|
/* Check busy status */
|
||||||
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u/%s",
|
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u/%s",
|
||||||
(unsigned int)device->id, entry->d_name);
|
(unsigned int)device->id, entry->d_name);
|
||||||
if ((pcm = opendir(path)) == NULL)
|
|
||||||
|
spa_autoptr(DIR) pcm = opendir(path);
|
||||||
|
if (pcm == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
while ((errno = 0, entry_pcm = readdir(pcm)) != NULL) {
|
while ((errno = 0, entry_pcm = readdir(pcm)) != NULL) {
|
||||||
|
|
@ -341,12 +336,11 @@ static int check_device_available(struct impl *this, struct device *device, int
|
||||||
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u/%s/%s/status",
|
spa_scnprintf(path, sizeof(path), "/proc/asound/card%u/%s/%s/status",
|
||||||
(unsigned int)device->id, entry->d_name, entry_pcm->d_name);
|
(unsigned int)device->id, entry->d_name, entry_pcm->d_name);
|
||||||
|
|
||||||
f = fopen(path, "re");
|
spa_autoptr(FILE) f = fopen(path, "re");
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
sz = fread(buf, 1, 6, f);
|
sz = fread(buf, 1, 6, f);
|
||||||
buf[sz] = '\0';
|
buf[sz] = '\0';
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
if (!spa_strstartswith(buf, "closed")) {
|
if (!spa_strstartswith(buf, "closed")) {
|
||||||
spa_log_debug(this->log, "card %u pcm device %s busy",
|
spa_log_debug(this->log, "card %u pcm device %s busy",
|
||||||
|
|
@ -359,9 +353,6 @@ static int check_device_available(struct impl *this, struct device *device, int
|
||||||
}
|
}
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
closedir(pcm);
|
|
||||||
pcm = NULL;
|
|
||||||
}
|
}
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -371,10 +362,7 @@ done:
|
||||||
spa_log_info(this->log, "card %u: failed to find busy status (%s)",
|
spa_log_info(this->log, "card %u: failed to find busy status (%s)",
|
||||||
(unsigned int)device->id, spa_strerror(-errno));
|
(unsigned int)device->id, spa_strerror(-errno));
|
||||||
}
|
}
|
||||||
if (card)
|
|
||||||
closedir(card);
|
|
||||||
if (pcm)
|
|
||||||
closedir(pcm);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -519,7 +507,7 @@ static int emit_object_info(struct impl *this, struct device *device)
|
||||||
static bool check_access(struct impl *this, struct device *device)
|
static bool check_access(struct impl *this, struct device *device)
|
||||||
{
|
{
|
||||||
char path[128], prefix[32];
|
char path[128], prefix[32];
|
||||||
DIR *snd = NULL;
|
spa_autoptr(DIR) snd = NULL;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
bool accessible = false;
|
bool accessible = false;
|
||||||
|
|
||||||
|
|
@ -544,7 +532,6 @@ static bool check_access(struct impl *this, struct device *device)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(snd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessible != device->accessible)
|
if (accessible != device->accessible)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <spa/utils/cleanup.h>
|
||||||
#include <spa/utils/result.h>
|
#include <spa/utils/result.h>
|
||||||
#include <pipewire/log.h>
|
#include <pipewire/log.h>
|
||||||
|
|
||||||
|
|
@ -62,8 +63,8 @@ static int pw_check_flatpak(pid_t pid, char **app_id, char **devices)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
char root_path[2048];
|
char root_path[2048];
|
||||||
int root_fd, info_fd, res;
|
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
|
int res;
|
||||||
|
|
||||||
if (app_id)
|
if (app_id)
|
||||||
*app_id = NULL;
|
*app_id = NULL;
|
||||||
|
|
@ -71,8 +72,9 @@ static int pw_check_flatpak(pid_t pid, char **app_id, char **devices)
|
||||||
*devices = NULL;
|
*devices = NULL;
|
||||||
|
|
||||||
snprintf(root_path, sizeof(root_path), "/proc/%d/root", (int)pid);
|
snprintf(root_path, sizeof(root_path), "/proc/%d/root", (int)pid);
|
||||||
root_fd = openat (AT_FDCWD, root_path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY);
|
|
||||||
if (root_fd == -1) {
|
spa_autoclose int root_fd = openat(AT_FDCWD, root_path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY);
|
||||||
|
if (root_fd < 0) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
if (res == -EACCES) {
|
if (res == -EACCES) {
|
||||||
struct statfs buf;
|
struct statfs buf;
|
||||||
|
|
@ -90,9 +92,9 @@ static int pw_check_flatpak(pid_t pid, char **app_id, char **devices)
|
||||||
pw_log_info("failed to open \"%s\": %s", root_path, spa_strerror(res));
|
pw_log_info("failed to open \"%s\": %s", root_path, spa_strerror(res));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
info_fd = openat (root_fd, ".flatpak-info", O_RDONLY | O_CLOEXEC | O_NOCTTY);
|
|
||||||
close (root_fd);
|
spa_autoclose int info_fd = openat(root_fd, ".flatpak-info", O_RDONLY | O_CLOEXEC | O_NOCTTY);
|
||||||
if (info_fd == -1) {
|
if (info_fd < 0) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
pw_log_debug("no .flatpak-info, client on the host");
|
pw_log_debug("no .flatpak-info, client on the host");
|
||||||
/* No file => on the host */
|
/* No file => on the host */
|
||||||
|
|
@ -128,7 +130,7 @@ static int pw_check_flatpak(pid_t pid, char **app_id, char **devices)
|
||||||
pw_log_error("PID %d .flatpak-info parsing failed: %s",
|
pw_log_error("PID %d .flatpak-info parsing failed: %s",
|
||||||
(int)pid, spa_strerror(res));
|
(int)pid, spa_strerror(res));
|
||||||
}
|
}
|
||||||
close(info_fd);
|
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/utils.h>
|
#include <pipewire/utils.h>
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
@ -68,15 +69,14 @@ static int parse_cmd(void *user_data, const char *location,
|
||||||
{
|
{
|
||||||
struct impl *impl = user_data;
|
struct impl *impl = user_data;
|
||||||
struct spa_json it[3];
|
struct spa_json it[3];
|
||||||
char key[512], *s;
|
char key[512];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
s = strndup(str, len);
|
spa_autofree char *s = strndup(str, len);
|
||||||
spa_json_init(&it[0], s, len);
|
spa_json_init(&it[0], s, len);
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||||
pw_log_error("config file error: pulse.cmd is not an array");
|
pw_log_error("config file error: pulse.cmd is not an array");
|
||||||
res = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||||
|
|
@ -107,8 +107,7 @@ static int parse_cmd(void *user_data, const char *location,
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
exit:
|
|
||||||
free(s);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <spa/utils/list.h>
|
#include <spa/utils/list.h>
|
||||||
#include <spa/utils/hook.h>
|
#include <spa/utils/hook.h>
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/log.h>
|
#include <pipewire/log.h>
|
||||||
#include <pipewire/map.h>
|
#include <pipewire/map.h>
|
||||||
#include <pipewire/properties.h>
|
#include <pipewire/properties.h>
|
||||||
|
|
@ -117,7 +118,8 @@ int module_unload(struct module *module)
|
||||||
/** utils */
|
/** utils */
|
||||||
void module_args_add_props(struct pw_properties *props, const char *str)
|
void module_args_add_props(struct pw_properties *props, const char *str)
|
||||||
{
|
{
|
||||||
char *s = strdup(str), *p = s, *e, f;
|
spa_autofree char *s = strdup(str);
|
||||||
|
char *p = s, *e, f;
|
||||||
const char *k, *v;
|
const char *k, *v;
|
||||||
const struct str_map *map;
|
const struct str_map *map;
|
||||||
|
|
||||||
|
|
@ -160,7 +162,6 @@ void module_args_add_props(struct pw_properties *props, const char *str)
|
||||||
}
|
}
|
||||||
pw_properties_set(props, k, v);
|
pw_properties_set(props, k, v);
|
||||||
}
|
}
|
||||||
free(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int module_args_to_audioinfo_keys(struct impl *impl, struct pw_properties *props,
|
int module_args_to_audioinfo_keys(struct impl *impl, struct pw_properties *props,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <spa/utils/ringbuffer.h>
|
#include <spa/utils/ringbuffer.h>
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
#include <pipewire/extensions/metadata.h>
|
#include <pipewire/extensions/metadata.h>
|
||||||
|
|
||||||
|
|
@ -2516,12 +2517,12 @@ static int do_play_sample(struct client *client, uint32_t command, uint32_t tag,
|
||||||
uint32_t sink_index, volume;
|
uint32_t sink_index, volume;
|
||||||
struct sample *sample;
|
struct sample *sample;
|
||||||
const char *sink_name, *name;
|
const char *sink_name, *name;
|
||||||
struct pw_properties *props = NULL;
|
spa_autoptr(pw_properties) props = NULL;
|
||||||
struct pw_manager_object *o;
|
struct pw_manager_object *o;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if ((props = pw_properties_new(NULL, NULL)) == NULL)
|
if ((props = pw_properties_new(NULL, NULL)) == NULL)
|
||||||
goto error_errno;
|
return -errno;
|
||||||
|
|
||||||
if ((res = message_get(m,
|
if ((res = message_get(m,
|
||||||
TAG_U32, &sink_index,
|
TAG_U32, &sink_index,
|
||||||
|
|
@ -2529,13 +2530,13 @@ static int do_play_sample(struct client *client, uint32_t command, uint32_t tag,
|
||||||
TAG_U32, &volume,
|
TAG_U32, &volume,
|
||||||
TAG_STRING, &name,
|
TAG_STRING, &name,
|
||||||
TAG_INVALID)) < 0)
|
TAG_INVALID)) < 0)
|
||||||
goto error_proto;
|
return -EPROTO;
|
||||||
|
|
||||||
if (client->version >= 13) {
|
if (client->version >= 13) {
|
||||||
if ((res = message_get(m,
|
if ((res = message_get(m,
|
||||||
TAG_PROPLIST, props,
|
TAG_PROPLIST, props,
|
||||||
TAG_INVALID)) < 0)
|
TAG_INVALID)) < 0)
|
||||||
goto error_proto;
|
return -EPROTO;
|
||||||
|
|
||||||
}
|
}
|
||||||
pw_log_info("[%s] %s tag:%u sink_index:%u sink_name:%s name:%s",
|
pw_log_info("[%s] %s tag:%u sink_index:%u sink_name:%s name:%s",
|
||||||
|
|
@ -2545,35 +2546,19 @@ static int do_play_sample(struct client *client, uint32_t command, uint32_t tag,
|
||||||
pw_properties_update(props, &client->props->dict);
|
pw_properties_update(props, &client->props->dict);
|
||||||
|
|
||||||
if (sink_index != SPA_ID_INVALID && sink_name != NULL)
|
if (sink_index != SPA_ID_INVALID && sink_name != NULL)
|
||||||
goto error_inval;
|
return -EINVAL;
|
||||||
|
|
||||||
o = find_device(client, sink_index, sink_name, PW_DIRECTION_OUTPUT, NULL);
|
o = find_device(client, sink_index, sink_name, PW_DIRECTION_OUTPUT, NULL);
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
goto error_noent;
|
return -ENOENT;
|
||||||
|
|
||||||
sample = find_sample(impl, SPA_ID_INVALID, name);
|
sample = find_sample(impl, SPA_ID_INVALID, name);
|
||||||
if (sample == NULL)
|
if (sample == NULL)
|
||||||
goto error_noent;
|
return -ENOENT;
|
||||||
|
|
||||||
pw_properties_setf(props, PW_KEY_TARGET_OBJECT, "%"PRIu64, o->serial);
|
pw_properties_setf(props, PW_KEY_TARGET_OBJECT, "%"PRIu64, o->serial);
|
||||||
|
|
||||||
return pending_sample_new(client, sample, props, tag);
|
return pending_sample_new(client, sample, spa_steal_ptr(props), tag);
|
||||||
|
|
||||||
error_errno:
|
|
||||||
res = -errno;
|
|
||||||
goto error;
|
|
||||||
error_proto:
|
|
||||||
res = -EPROTO;
|
|
||||||
goto error;
|
|
||||||
error_inval:
|
|
||||||
res = -EINVAL;
|
|
||||||
goto error;
|
|
||||||
error_noent:
|
|
||||||
res = -ENOENT;
|
|
||||||
goto error;
|
|
||||||
error:
|
|
||||||
pw_properties_free(props);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_remove_sample(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_remove_sample(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
|
|
@ -3184,11 +3169,8 @@ static int do_set_stream_name(struct client *client, uint32_t command, uint32_t
|
||||||
static int do_update_proplist(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_update_proplist(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
{
|
{
|
||||||
uint32_t channel, mode;
|
uint32_t channel, mode;
|
||||||
struct stream *stream;
|
|
||||||
struct pw_properties *props;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
props = pw_properties_new(NULL, NULL);
|
spa_autoptr(pw_properties) props = pw_properties_new(NULL, NULL);
|
||||||
if (props == NULL)
|
if (props == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
|
@ -3196,7 +3178,7 @@ static int do_update_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
if (message_get(m,
|
if (message_get(m,
|
||||||
TAG_U32, &channel,
|
TAG_U32, &channel,
|
||||||
TAG_INVALID) < 0)
|
TAG_INVALID) < 0)
|
||||||
goto error_protocol;
|
return -EPROTO;
|
||||||
} else {
|
} else {
|
||||||
channel = SPA_ID_INVALID;
|
channel = SPA_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
@ -3208,12 +3190,12 @@ static int do_update_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
TAG_U32, &mode,
|
TAG_U32, &mode,
|
||||||
TAG_PROPLIST, props,
|
TAG_PROPLIST, props,
|
||||||
TAG_INVALID) < 0)
|
TAG_INVALID) < 0)
|
||||||
goto error_protocol;
|
return -EPROTO;
|
||||||
|
|
||||||
if (command != COMMAND_UPDATE_CLIENT_PROPLIST) {
|
if (command != COMMAND_UPDATE_CLIENT_PROPLIST) {
|
||||||
stream = pw_map_lookup(&client->streams, channel);
|
struct stream *stream = pw_map_lookup(&client->streams, channel);
|
||||||
if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD)
|
if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD)
|
||||||
goto error_noentity;
|
return -ENOENT;
|
||||||
|
|
||||||
pw_stream_update_properties(stream->stream, &props->dict);
|
pw_stream_update_properties(stream->stream, &props->dict);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3223,29 +3205,17 @@ static int do_update_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
pw_core_update_properties(client->core, &client->props->dict);
|
pw_core_update_properties(client->core, &client->props->dict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = reply_simple_ack(client, tag);
|
|
||||||
exit:
|
|
||||||
pw_properties_free(props);
|
|
||||||
return res;
|
|
||||||
|
|
||||||
error_protocol:
|
return reply_simple_ack(client, tag);
|
||||||
res = -EPROTO;
|
|
||||||
goto exit;
|
|
||||||
error_noentity:
|
|
||||||
res = -ENOENT;
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_remove_proplist(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_remove_proplist(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
{
|
{
|
||||||
uint32_t i, channel;
|
uint32_t i, channel;
|
||||||
struct stream *stream;
|
|
||||||
struct pw_properties *props;
|
|
||||||
struct spa_dict dict;
|
struct spa_dict dict;
|
||||||
struct spa_dict_item *items;
|
struct spa_dict_item *items;
|
||||||
int res;
|
|
||||||
|
|
||||||
props = pw_properties_new(NULL, NULL);
|
spa_autoptr(pw_properties) props = pw_properties_new(NULL, NULL);
|
||||||
if (props == NULL)
|
if (props == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
|
@ -3253,7 +3223,7 @@ static int do_remove_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
if (message_get(m,
|
if (message_get(m,
|
||||||
TAG_U32, &channel,
|
TAG_U32, &channel,
|
||||||
TAG_INVALID) < 0)
|
TAG_INVALID) < 0)
|
||||||
goto error_protocol;
|
return -EPROTO;
|
||||||
} else {
|
} else {
|
||||||
channel = SPA_ID_INVALID;
|
channel = SPA_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
@ -3267,7 +3237,7 @@ static int do_remove_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
if (message_get(m,
|
if (message_get(m,
|
||||||
TAG_STRING, &key,
|
TAG_STRING, &key,
|
||||||
TAG_INVALID) < 0)
|
TAG_INVALID) < 0)
|
||||||
goto error_protocol;
|
return -EPROTO;
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
break;
|
break;
|
||||||
pw_properties_set(props, key, key);
|
pw_properties_set(props, key, key);
|
||||||
|
|
@ -3281,25 +3251,16 @@ static int do_remove_proplist(struct client *client, uint32_t command, uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command != COMMAND_UPDATE_CLIENT_PROPLIST) {
|
if (command != COMMAND_UPDATE_CLIENT_PROPLIST) {
|
||||||
stream = pw_map_lookup(&client->streams, channel);
|
struct stream *stream = pw_map_lookup(&client->streams, channel);
|
||||||
if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD)
|
if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD)
|
||||||
goto error_noentity;
|
return -ENOENT;
|
||||||
|
|
||||||
pw_stream_update_properties(stream->stream, &dict);
|
pw_stream_update_properties(stream->stream, &dict);
|
||||||
} else {
|
} else {
|
||||||
pw_core_update_properties(client->core, &dict);
|
pw_core_update_properties(client->core, &dict);
|
||||||
}
|
}
|
||||||
res = reply_simple_ack(client, tag);
|
|
||||||
exit:
|
|
||||||
pw_properties_free(props);
|
|
||||||
return res;
|
|
||||||
|
|
||||||
error_protocol:
|
return reply_simple_ack(client, tag);
|
||||||
res = -EPROTO;
|
|
||||||
goto exit;
|
|
||||||
error_noentity:
|
|
||||||
res = -ENOENT;
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -3672,7 +3633,7 @@ static int fill_sink_info_proplist(struct message *m, const struct spa_dict *sin
|
||||||
const struct pw_manager_object *card)
|
const struct pw_manager_object *card)
|
||||||
{
|
{
|
||||||
struct pw_device_info *card_info = card ? card->info : NULL;
|
struct pw_device_info *card_info = card ? card->info : NULL;
|
||||||
struct pw_properties *props = NULL;
|
spa_autoptr(pw_properties) props = NULL;
|
||||||
|
|
||||||
if (card_info && card_info->props) {
|
if (card_info && card_info->props) {
|
||||||
props = pw_properties_new_dict(sink_props);
|
props = pw_properties_new_dict(sink_props);
|
||||||
|
|
@ -3682,9 +3643,8 @@ static int fill_sink_info_proplist(struct message *m, const struct spa_dict *sin
|
||||||
pw_properties_add(props, card_info->props);
|
pw_properties_add(props, card_info->props);
|
||||||
sink_props = &props->dict;
|
sink_props = &props->dict;
|
||||||
}
|
}
|
||||||
message_put(m, TAG_PROPLIST, sink_props, TAG_INVALID);
|
|
||||||
|
|
||||||
pw_properties_free(props);
|
message_put(m, TAG_PROPLIST, sink_props, TAG_INVALID);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -3882,7 +3842,7 @@ static int fill_source_info_proplist(struct message *m, const struct spa_dict *s
|
||||||
const struct pw_manager_object *card, const bool is_monitor)
|
const struct pw_manager_object *card, const bool is_monitor)
|
||||||
{
|
{
|
||||||
struct pw_device_info *card_info = card ? card->info : NULL;
|
struct pw_device_info *card_info = card ? card->info : NULL;
|
||||||
struct pw_properties *props = NULL;
|
spa_autoptr(pw_properties) props = NULL;
|
||||||
|
|
||||||
if ((card_info && card_info->props) || is_monitor) {
|
if ((card_info && card_info->props) || is_monitor) {
|
||||||
props = pw_properties_new_dict(source_props);
|
props = pw_properties_new_dict(source_props);
|
||||||
|
|
@ -3897,9 +3857,8 @@ static int fill_source_info_proplist(struct message *m, const struct spa_dict *s
|
||||||
|
|
||||||
source_props = &props->dict;
|
source_props = &props->dict;
|
||||||
}
|
}
|
||||||
message_put(m, TAG_PROPLIST, source_props, TAG_INVALID);
|
|
||||||
|
|
||||||
pw_properties_free(props);
|
message_put(m, TAG_PROPLIST, source_props, TAG_INVALID);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -5140,12 +5099,9 @@ static int do_send_object_message(struct client *client, uint32_t command, uint3
|
||||||
const char *object_path = NULL;
|
const char *object_path = NULL;
|
||||||
const char *message = NULL;
|
const char *message = NULL;
|
||||||
const char *params = NULL;
|
const char *params = NULL;
|
||||||
char *response = NULL;
|
|
||||||
char *path = NULL;
|
|
||||||
struct message *reply;
|
struct message *reply;
|
||||||
struct pw_manager_object *o;
|
struct pw_manager_object *o;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int res;
|
|
||||||
|
|
||||||
if (message_get(m,
|
if (message_get(m,
|
||||||
TAG_STRING, &object_path,
|
TAG_STRING, &object_path,
|
||||||
|
|
@ -5164,11 +5120,13 @@ static int do_send_object_message(struct client *client, uint32_t command, uint3
|
||||||
len = strlen(object_path);
|
len = strlen(object_path);
|
||||||
if (len > 0 && object_path[len - 1] == '/')
|
if (len > 0 && object_path[len - 1] == '/')
|
||||||
--len;
|
--len;
|
||||||
path = strndup(object_path, len);
|
|
||||||
|
spa_autofree char *path = strndup(object_path, len);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
res = -ENOENT;
|
spa_autofree char *response = NULL;
|
||||||
|
int res = -ENOENT;
|
||||||
|
|
||||||
spa_list_for_each(o, &manager->object_list, link) {
|
spa_list_for_each(o, &manager->object_list, link) {
|
||||||
if (o->message_object_path && spa_streq(o->message_object_path, path)) {
|
if (o->message_object_path && spa_streq(o->message_object_path, path)) {
|
||||||
|
|
@ -5180,7 +5138,6 @@ static int do_send_object_message(struct client *client, uint32_t command, uint3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(path);
|
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
|
@ -5188,7 +5145,7 @@ static int do_send_object_message(struct client *client, uint32_t command, uint3
|
||||||
|
|
||||||
reply = reply_new(client, tag);
|
reply = reply_new(client, tag);
|
||||||
message_put(reply, TAG_STRING, response, TAG_INVALID);
|
message_put(reply, TAG_STRING, response, TAG_INVALID);
|
||||||
free(response);
|
|
||||||
return client_queue_message(client, reply);
|
return client_queue_message(client, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <spa/utils/defs.h>
|
#include <spa/utils/defs.h>
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
#include <spa/utils/result.h>
|
#include <spa/utils/result.h>
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
@ -404,7 +405,7 @@ on_connect(void *data, int fd, uint32_t mask)
|
||||||
client_access = server->client_access;
|
client_access = server->client_access;
|
||||||
|
|
||||||
if (server->addr.ss_family == AF_UNIX) {
|
if (server->addr.ss_family == AF_UNIX) {
|
||||||
char *app_id = NULL, *devices = NULL;
|
spa_autofree char *app_id = NULL, *devices = NULL;
|
||||||
|
|
||||||
#ifdef SO_PRIORITY
|
#ifdef SO_PRIORITY
|
||||||
val = 6;
|
val = 6;
|
||||||
|
|
@ -443,8 +444,6 @@ on_connect(void *data, int fd, uint32_t mask)
|
||||||
else
|
else
|
||||||
pw_properties_set(client->props, PW_KEY_MEDIA_CATEGORY, NULL);
|
pw_properties_set(client->props, PW_KEY_MEDIA_CATEGORY, NULL);
|
||||||
}
|
}
|
||||||
free(devices);
|
|
||||||
free(app_id);
|
|
||||||
}
|
}
|
||||||
else if (server->addr.ss_family == AF_INET || server->addr.ss_family == AF_INET6) {
|
else if (server->addr.ss_family == AF_INET || server->addr.ss_family == AF_INET6) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
#include <spa/param/audio/raw.h>
|
#include <spa/param/audio/raw.h>
|
||||||
#include <spa/param/latency-utils.h>
|
#include <spa/param/latency-utils.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/impl.h>
|
#include <pipewire/impl.h>
|
||||||
#include <pipewire/i18n.h>
|
#include <pipewire/i18n.h>
|
||||||
|
|
||||||
|
|
@ -1211,7 +1212,7 @@ static int rtsp_do_announce(struct impl *impl)
|
||||||
char key[512*2];
|
char key[512*2];
|
||||||
char iv[16*2];
|
char iv[16*2];
|
||||||
int res, frames, rsa_len, ip_version;
|
int res, frames, rsa_len, ip_version;
|
||||||
char *sdp;
|
spa_autofree char *sdp = NULL;
|
||||||
char local_ip[256];
|
char local_ip[256];
|
||||||
host = pw_properties_get(impl->props, "raop.ip");
|
host = pw_properties_get(impl->props, "raop.ip");
|
||||||
|
|
||||||
|
|
@ -1289,10 +1290,8 @@ static int rtsp_do_announce(struct impl *impl)
|
||||||
default:
|
default:
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
res = rtsp_send(impl, "ANNOUNCE", "application/sdp", sdp, rtsp_announce_reply);
|
|
||||||
free(sdp);
|
|
||||||
|
|
||||||
return res;
|
return rtsp_send(impl, "ANNOUNCE", "application/sdp", sdp, rtsp_announce_reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtsp_auth_setup_reply(void *data, int status, const struct spa_dict *headers)
|
static int rtsp_auth_setup_reply(void *data, int status, const struct spa_dict *headers)
|
||||||
|
|
@ -1355,7 +1354,6 @@ static const char *find_attr(char **tokens, const char *key)
|
||||||
static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers)
|
static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers)
|
||||||
{
|
{
|
||||||
const char *str, *realm, *nonce;
|
const char *str, *realm, *nonce;
|
||||||
char **tokens;
|
|
||||||
int n_tokens;
|
int n_tokens;
|
||||||
|
|
||||||
if ((str = spa_dict_lookup(headers, "WWW-Authenticate")) == NULL)
|
if ((str = spa_dict_lookup(headers, "WWW-Authenticate")) == NULL)
|
||||||
|
|
@ -1368,9 +1366,9 @@ static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers)
|
||||||
|
|
||||||
pw_log_info("Auth: %s", str);
|
pw_log_info("Auth: %s", str);
|
||||||
|
|
||||||
tokens = pw_split_strv(str, " ", INT_MAX, &n_tokens);
|
spa_auto(pw_strv) tokens = pw_split_strv(str, " ", INT_MAX, &n_tokens);
|
||||||
if (tokens == NULL || tokens[0] == NULL)
|
if (tokens == NULL || tokens[0] == NULL)
|
||||||
goto error;
|
return -EINVAL;
|
||||||
|
|
||||||
impl->auth_method = strdup(tokens[0]);
|
impl->auth_method = strdup(tokens[0]);
|
||||||
|
|
||||||
|
|
@ -1378,20 +1376,13 @@ static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers)
|
||||||
realm = find_attr(tokens, "realm");
|
realm = find_attr(tokens, "realm");
|
||||||
nonce = find_attr(tokens, "nonce");
|
nonce = find_attr(tokens, "nonce");
|
||||||
if (realm == NULL || nonce == NULL)
|
if (realm == NULL || nonce == NULL)
|
||||||
goto error;
|
return -EINVAL;
|
||||||
|
|
||||||
impl->realm = strdup(realm);
|
impl->realm = strdup(realm);
|
||||||
impl->nonce = strdup(nonce);
|
impl->nonce = strdup(nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_free_strv(tokens);
|
return rtsp_send(impl, "OPTIONS", NULL, NULL, rtsp_auth_reply);
|
||||||
|
|
||||||
rtsp_send(impl, "OPTIONS", NULL, NULL, rtsp_auth_reply);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
pw_free_strv(tokens);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtsp_options_reply(void *data, int status, const struct spa_dict *headers)
|
static int rtsp_options_reply(void *data, int status, const struct spa_dict *headers)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/impl.h>
|
#include <pipewire/impl.h>
|
||||||
|
|
||||||
#include "spa-device.h"
|
#include "spa-device.h"
|
||||||
|
|
@ -51,12 +52,11 @@ SPA_EXPORT
|
||||||
int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
{
|
{
|
||||||
struct pw_properties *props = NULL;
|
struct pw_properties *props = NULL;
|
||||||
char **argv = NULL;
|
spa_auto(pw_strv) argv = NULL;
|
||||||
int n_tokens;
|
int n_tokens;
|
||||||
struct pw_context *context = pw_impl_module_get_context(module);
|
struct pw_context *context = pw_impl_module_get_context(module);
|
||||||
struct pw_impl_device *device;
|
struct pw_impl_device *device;
|
||||||
struct device_data *data;
|
struct device_data *data;
|
||||||
int res;
|
|
||||||
|
|
||||||
PW_LOG_TOPIC_INIT(mod_topic);
|
PW_LOG_TOPIC_INIT(mod_topic);
|
||||||
|
|
||||||
|
|
@ -69,10 +69,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
|
|
||||||
if (n_tokens == 2) {
|
if (n_tokens == 2) {
|
||||||
props = pw_properties_new_string(argv[1]);
|
props = pw_properties_new_string(argv[1]);
|
||||||
if (props == NULL) {
|
if (props == NULL)
|
||||||
res = -errno;
|
return -errno;
|
||||||
goto error_exit_cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
device = pw_spa_device_load(context,
|
device = pw_spa_device_load(context,
|
||||||
|
|
@ -80,12 +78,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
0,
|
0,
|
||||||
props,
|
props,
|
||||||
sizeof(struct device_data));
|
sizeof(struct device_data));
|
||||||
if (device == NULL) {
|
if (device == NULL)
|
||||||
res = -errno;
|
return -errno;
|
||||||
goto error_exit_cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
pw_free_strv(argv);
|
|
||||||
|
|
||||||
data = pw_spa_device_get_user_data(device);
|
data = pw_spa_device_get_user_data(device);
|
||||||
data->this = device;
|
data->this = device;
|
||||||
|
|
@ -99,10 +93,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_arguments:
|
error_arguments:
|
||||||
res = -EINVAL;
|
|
||||||
pw_log_error("usage: module-spa-device " MODULE_USAGE);
|
pw_log_error("usage: module-spa-device " MODULE_USAGE);
|
||||||
goto error_exit_cleanup;
|
return -EINVAL;
|
||||||
error_exit_cleanup:
|
|
||||||
pw_free_strv(argv);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/impl.h>
|
#include <pipewire/impl.h>
|
||||||
|
|
||||||
#include "spa-node.h"
|
#include "spa-node.h"
|
||||||
|
|
@ -52,8 +53,8 @@ SPA_EXPORT
|
||||||
int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
{
|
{
|
||||||
struct pw_properties *props = NULL;
|
struct pw_properties *props = NULL;
|
||||||
char **argv = NULL;
|
spa_auto(pw_strv) argv = NULL;
|
||||||
int n_tokens, res;
|
int n_tokens;
|
||||||
struct pw_context *context = pw_impl_module_get_context(module);
|
struct pw_context *context = pw_impl_module_get_context(module);
|
||||||
struct pw_impl_node *node;
|
struct pw_impl_node *node;
|
||||||
struct node_data *data;
|
struct node_data *data;
|
||||||
|
|
@ -69,10 +70,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
|
|
||||||
if (n_tokens == 2) {
|
if (n_tokens == 2) {
|
||||||
props = pw_properties_new_string(argv[1]);
|
props = pw_properties_new_string(argv[1]);
|
||||||
if (props == NULL) {
|
if (props == NULL)
|
||||||
res = -errno;
|
return -errno;
|
||||||
goto error_exit_cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node = pw_spa_node_load(context,
|
node = pw_spa_node_load(context,
|
||||||
|
|
@ -81,12 +80,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
props,
|
props,
|
||||||
sizeof(struct node_data));
|
sizeof(struct node_data));
|
||||||
|
|
||||||
if (node == NULL) {
|
if (node == NULL)
|
||||||
res = -errno;
|
return -errno;
|
||||||
goto error_exit_cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
pw_free_strv(argv);
|
|
||||||
|
|
||||||
data = pw_spa_node_get_user_data(node);
|
data = pw_spa_node_get_user_data(node);
|
||||||
data->this = node;
|
data->this = node;
|
||||||
|
|
@ -101,10 +96,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_arguments:
|
error_arguments:
|
||||||
res = -EINVAL;
|
|
||||||
pw_log_error("usage: module-spa-node " MODULE_USAGE);
|
pw_log_error("usage: module-spa-node " MODULE_USAGE);
|
||||||
goto error_exit_cleanup;
|
return -EINVAL;
|
||||||
error_exit_cleanup:
|
|
||||||
pw_free_strv(argv);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/impl.h>
|
#include <pipewire/impl.h>
|
||||||
#include <pipewire/private.h>
|
#include <pipewire/private.h>
|
||||||
|
|
||||||
|
|
@ -345,7 +346,8 @@ int pw_conf_save_state(const char *prefix, const char *name, const struct pw_pro
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char *tmp_name;
|
char *tmp_name;
|
||||||
int res, sfd, fd, count = 0;
|
spa_autoclose int sfd = -1;
|
||||||
|
int res, fd, count = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((sfd = open_write_dir(path, sizeof(path), prefix)) < 0)
|
if ((sfd = open_write_dir(path, sizeof(path), prefix)) < 0)
|
||||||
|
|
@ -354,9 +356,9 @@ int pw_conf_save_state(const char *prefix, const char *name, const struct pw_pro
|
||||||
tmp_name = alloca(strlen(name)+5);
|
tmp_name = alloca(strlen(name)+5);
|
||||||
sprintf(tmp_name, "%s.tmp", name);
|
sprintf(tmp_name, "%s.tmp", name);
|
||||||
if ((fd = openat(sfd, tmp_name, O_CLOEXEC | O_CREAT | O_WRONLY | O_TRUNC, 0600)) < 0) {
|
if ((fd = openat(sfd, tmp_name, O_CLOEXEC | O_CREAT | O_WRONLY | O_TRUNC, 0600)) < 0) {
|
||||||
pw_log_error("can't open file '%s': %m", tmp_name);
|
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto error;
|
pw_log_error("can't open file '%s': %m", tmp_name);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fdopen(fd, "w");
|
f = fdopen(fd, "w");
|
||||||
|
|
@ -366,46 +368,43 @@ int pw_conf_save_state(const char *prefix, const char *name, const struct pw_pro
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (renameat(sfd, tmp_name, sfd, name) < 0) {
|
if (renameat(sfd, tmp_name, sfd, name) < 0) {
|
||||||
pw_log_error("can't rename temp file '%s': %m", tmp_name);
|
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto error;
|
pw_log_error("can't rename temp file '%s': %m", tmp_name);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
res = 0;
|
|
||||||
pw_log_info("%p: saved state '%s%s'", conf, path, name);
|
pw_log_info("%p: saved state '%s%s'", conf, path, name);
|
||||||
error:
|
|
||||||
close(sfd);
|
return 0;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conf_load(const char *path, struct pw_properties *conf)
|
static int conf_load(const char *path, struct pw_properties *conf)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
int fd, count;
|
int count;
|
||||||
|
|
||||||
if ((fd = open(path, O_CLOEXEC | O_RDONLY)) < 0)
|
spa_autoclose int fd = open(path, O_CLOEXEC | O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (fstat(fd, &sbuf) < 0)
|
if (fstat(fd, &sbuf) < 0)
|
||||||
goto error_close;
|
goto error;
|
||||||
|
|
||||||
if (sbuf.st_size > 0) {
|
if (sbuf.st_size > 0) {
|
||||||
if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
||||||
goto error_close;
|
goto error;
|
||||||
|
|
||||||
count = pw_properties_update_string(conf, data, sbuf.st_size);
|
count = pw_properties_update_string(conf, data, sbuf.st_size);
|
||||||
munmap(data, sbuf.st_size);
|
munmap(data, sbuf.st_size);
|
||||||
} else {
|
} else {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
|
|
||||||
pw_log_info("%p: loaded config '%s' with %d items", conf, path, count);
|
pw_log_info("%p: loaded config '%s' with %d items", conf, path, count);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_close:
|
|
||||||
close(fd);
|
|
||||||
error:
|
error:
|
||||||
pw_log_warn("%p: error loading config '%s': %m", conf, path);
|
pw_log_warn("%p: error loading config '%s': %m", conf, path);
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
@ -455,7 +454,7 @@ int pw_conf_load_conf(const char *prefix, const char *name, struct pw_properties
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char fname[PATH_MAX + 256];
|
char fname[PATH_MAX + 256];
|
||||||
int i, res, level = 0;
|
int i, res, level = 0;
|
||||||
struct pw_properties *override = NULL;
|
spa_autoptr(pw_properties) override = NULL;
|
||||||
const char *dname;
|
const char *dname;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
|
|
@ -510,7 +509,7 @@ int pw_conf_load_conf(const char *prefix, const char *name, struct pw_properties
|
||||||
}
|
}
|
||||||
free(entries);
|
free(entries);
|
||||||
}
|
}
|
||||||
pw_properties_free(override);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -660,15 +659,14 @@ static int parse_modules(void *user_data, const char *location,
|
||||||
struct data *d = user_data;
|
struct data *d = user_data;
|
||||||
struct pw_context *context = d->context;
|
struct pw_context *context = d->context;
|
||||||
struct spa_json it[4];
|
struct spa_json it[4];
|
||||||
char key[512], *s;
|
char key[512];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
s = strndup(str, len);
|
spa_autofree char *s = strndup(str, len);
|
||||||
spa_json_init(&it[0], s, len);
|
spa_json_init(&it[0], s, len);
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||||
pw_log_error("config file error: context.modules is not an array");
|
pw_log_error("config file error: context.modules is not an array");
|
||||||
res = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||||
|
|
@ -714,8 +712,7 @@ static int parse_modules(void *user_data, const char *location,
|
||||||
|
|
||||||
d->count++;
|
d->count++;
|
||||||
}
|
}
|
||||||
exit:
|
|
||||||
free(s);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -761,15 +758,14 @@ static int parse_objects(void *user_data, const char *location,
|
||||||
struct data *d = user_data;
|
struct data *d = user_data;
|
||||||
struct pw_context *context = d->context;
|
struct pw_context *context = d->context;
|
||||||
struct spa_json it[4];
|
struct spa_json it[4];
|
||||||
char key[512], *s;
|
char key[512];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
s = strndup(str, len);
|
spa_autofree char *s = strndup(str, len);
|
||||||
spa_json_init(&it[0], s, len);
|
spa_json_init(&it[0], s, len);
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||||
pw_log_error("config file error: context.objects is not an array");
|
pw_log_error("config file error: context.objects is not an array");
|
||||||
res = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||||
|
|
@ -815,8 +811,7 @@ static int parse_objects(void *user_data, const char *location,
|
||||||
break;
|
break;
|
||||||
d->count++;
|
d->count++;
|
||||||
}
|
}
|
||||||
exit:
|
|
||||||
free(s);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -880,15 +875,14 @@ static int parse_exec(void *user_data, const char *location,
|
||||||
struct data *d = user_data;
|
struct data *d = user_data;
|
||||||
struct pw_context *context = d->context;
|
struct pw_context *context = d->context;
|
||||||
struct spa_json it[4];
|
struct spa_json it[4];
|
||||||
char key[512], *s;
|
char key[512];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
s = strndup(str, len);
|
spa_autofree char *s = strndup(str, len);
|
||||||
spa_json_init(&it[0], s, len);
|
spa_json_init(&it[0], s, len);
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||||
pw_log_error("config file error: context.exec is not an array");
|
pw_log_error("config file error: context.exec is not an array");
|
||||||
res = -EINVAL;
|
return -EINVAL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||||
|
|
@ -926,8 +920,7 @@ static int parse_exec(void *user_data, const char *location,
|
||||||
|
|
||||||
d->count++;
|
d->count++;
|
||||||
}
|
}
|
||||||
exit:
|
|
||||||
free(s);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include <spa/pod/dynamic.h>
|
#include <spa/pod/dynamic.h>
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include "pipewire/pipewire.h"
|
#include "pipewire/pipewire.h"
|
||||||
#include "pipewire/filter.h"
|
#include "pipewire/filter.h"
|
||||||
#include "pipewire/private.h"
|
#include "pipewire/private.h"
|
||||||
|
|
@ -1898,8 +1899,8 @@ int pw_filter_set_error(struct pw_filter *filter,
|
||||||
ensure_loop(impl->main_loop, return -EIO);
|
ensure_loop(impl->main_loop, return -EIO);
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
spa_autofree char *value = NULL;
|
||||||
va_list args;
|
va_list args;
|
||||||
char *value;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
va_start(args, error);
|
va_start(args, error);
|
||||||
|
|
@ -1911,8 +1912,6 @@ int pw_filter_set_error(struct pw_filter *filter,
|
||||||
if (filter->proxy)
|
if (filter->proxy)
|
||||||
pw_proxy_error(filter->proxy, res, value);
|
pw_proxy_error(filter->proxy, res, value);
|
||||||
filter_set_state(filter, PW_FILTER_STATE_ERROR, res, value);
|
filter_set_state(filter, PW_FILTER_STATE_ERROR, res, value);
|
||||||
|
|
||||||
free(value);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include "pipewire/impl.h"
|
#include "pipewire/impl.h"
|
||||||
#include "pipewire/private.h"
|
#include "pipewire/private.h"
|
||||||
|
|
||||||
|
|
@ -576,8 +577,8 @@ int pw_impl_metadata_set_propertyf(struct pw_impl_metadata *metadata,
|
||||||
uint32_t subject, const char *key, const char *type,
|
uint32_t subject, const char *key, const char *type,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
spa_autofree char *value = NULL;
|
||||||
va_list args;
|
va_list args;
|
||||||
char *value;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
@ -586,8 +587,5 @@ int pw_impl_metadata_set_propertyf(struct pw_impl_metadata *metadata,
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
res = pw_impl_metadata_set_property(metadata, subject, key, type, value);
|
return pw_impl_metadata_set_property(metadata, subject, key, type, value);
|
||||||
free(value);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include "pipewire/impl.h"
|
#include "pipewire/impl.h"
|
||||||
#include "pipewire/private.h"
|
#include "pipewire/private.h"
|
||||||
|
|
||||||
|
|
@ -38,7 +39,6 @@ static char *find_module(const char *path, const char *name, int level)
|
||||||
char *filename;
|
char *filename;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
DIR *dir;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
filename = spa_aprintf("%s/%s.so", path, name);
|
filename = spa_aprintf("%s/%s.so", path, name);
|
||||||
|
|
@ -57,7 +57,7 @@ static char *find_module(const char *path, const char *name, int level)
|
||||||
if (level <= 0)
|
if (level <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dir = opendir(path);
|
spa_autoptr(DIR) dir = opendir(path);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
pw_log_warn("could not open %s: %m", path);
|
pw_log_warn("could not open %s: %m", path);
|
||||||
|
|
@ -66,28 +66,22 @@ static char *find_module(const char *path, const char *name, int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((entry = readdir(dir))) {
|
while ((entry = readdir(dir))) {
|
||||||
char *newpath;
|
|
||||||
|
|
||||||
if (spa_streq(entry->d_name, ".") || spa_streq(entry->d_name, ".."))
|
if (spa_streq(entry->d_name, ".") || spa_streq(entry->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
newpath = spa_aprintf("%s/%s", path, entry->d_name);
|
spa_autofree char *newpath = spa_aprintf("%s/%s", path, entry->d_name);
|
||||||
if (newpath == NULL)
|
if (newpath == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (entry->d_type == DT_DIR ||
|
if (entry->d_type == DT_DIR ||
|
||||||
(entry->d_type == DT_UNKNOWN && stat(newpath, &s) == 0 && S_ISDIR(s.st_mode)))
|
(entry->d_type == DT_UNKNOWN && stat(newpath, &s) == 0 && S_ISDIR(s.st_mode))) {
|
||||||
filename = find_module(newpath, name, level - 1);
|
filename = find_module(newpath, name, level - 1);
|
||||||
|
if (filename)
|
||||||
free(newpath);
|
return filename;
|
||||||
|
}
|
||||||
if (filename != NULL)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
return NULL;
|
||||||
|
|
||||||
return filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include <spa/support/cpu.h>
|
#include <spa/support/cpu.h>
|
||||||
#include <spa/support/i18n.h>
|
#include <spa/support/i18n.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include "pipewire.h"
|
#include "pipewire.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
@ -498,7 +499,6 @@ static char *
|
||||||
parse_pw_debug_env(void)
|
parse_pw_debug_env(void)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
char **tokens;
|
|
||||||
int n_tokens;
|
int n_tokens;
|
||||||
char json[1024] = {0};
|
char json[1024] = {0};
|
||||||
char *pos = json;
|
char *pos = json;
|
||||||
|
|
@ -516,7 +516,7 @@ parse_pw_debug_env(void)
|
||||||
*/
|
*/
|
||||||
pos += spa_scnprintf(pos, end - pos, "[ { conn.* = %d },", SPA_LOG_LEVEL_NONE);
|
pos += spa_scnprintf(pos, end - pos, "[ { conn.* = %d },", SPA_LOG_LEVEL_NONE);
|
||||||
|
|
||||||
tokens = pw_split_strv(str, ",", INT_MAX, &n_tokens);
|
spa_auto(pw_strv) tokens = pw_split_strv(str, ",", INT_MAX, &n_tokens);
|
||||||
if (n_tokens > 0) {
|
if (n_tokens > 0) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < n_tokens; i++) {
|
for (i = 0; i < n_tokens; i++) {
|
||||||
|
|
@ -536,7 +536,7 @@ parse_pw_debug_env(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pw_free_strv(tokens);
|
|
||||||
pos += spa_scnprintf(pos, end - pos, "]");
|
pos += spa_scnprintf(pos, end - pos, "]");
|
||||||
return strdup(json);
|
return strdup(json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#define PW_ENABLE_DEPRECATED
|
#define PW_ENABLE_DEPRECATED
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include "pipewire/pipewire.h"
|
#include "pipewire/pipewire.h"
|
||||||
#include "pipewire/stream.h"
|
#include "pipewire/stream.h"
|
||||||
#include "pipewire/private.h"
|
#include "pipewire/private.h"
|
||||||
|
|
@ -2165,8 +2166,8 @@ int pw_stream_set_error(struct pw_stream *stream,
|
||||||
ensure_loop(impl->main_loop, return -EIO);
|
ensure_loop(impl->main_loop, return -EIO);
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
spa_autofree char *value = NULL;
|
||||||
va_list args;
|
va_list args;
|
||||||
char *value;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
va_start(args, error);
|
va_start(args, error);
|
||||||
|
|
@ -2178,8 +2179,6 @@ int pw_stream_set_error(struct pw_stream *stream,
|
||||||
if (stream->proxy)
|
if (stream->proxy)
|
||||||
pw_proxy_error(stream->proxy, res, value);
|
pw_proxy_error(stream->proxy, res, value);
|
||||||
stream_set_state(stream, PW_STREAM_STATE_ERROR, res, value);
|
stream_set_state(stream, PW_STREAM_STATE_ERROR, res, value);
|
||||||
|
|
||||||
free(value);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
|
|
||||||
|
#include <pipewire/cleanup.h>
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
#include <pipewire/i18n.h>
|
#include <pipewire/i18n.h>
|
||||||
#include <pipewire/extensions/metadata.h>
|
#include <pipewire/extensions/metadata.h>
|
||||||
|
|
@ -603,7 +604,6 @@ static unsigned int find_channel(const char *name)
|
||||||
static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
||||||
{
|
{
|
||||||
int i, nch;
|
int i, nch;
|
||||||
char **ch;
|
|
||||||
|
|
||||||
SPA_FOR_EACH_ELEMENT_VAR(maps, m) {
|
SPA_FOR_EACH_ELEMENT_VAR(maps, m) {
|
||||||
if (spa_streq(m->name, channel_map)) {
|
if (spa_streq(m->name, channel_map)) {
|
||||||
|
|
@ -614,7 +614,7 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ch = pw_split_strv(channel_map, ",", SPA_AUDIO_MAX_CHANNELS, &nch);
|
spa_auto(pw_strv) ch = pw_split_strv(channel_map, ",", SPA_AUDIO_MAX_CHANNELS, &nch);
|
||||||
if (ch == NULL)
|
if (ch == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
@ -623,7 +623,7 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
||||||
int c = find_channel(ch[i]);
|
int c = find_channel(ch[i]);
|
||||||
map->channels[i] = c;
|
map->channels[i] = c;
|
||||||
}
|
}
|
||||||
pw_free_strv(ch);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue