2018-08-02 11:25:27 +02:00
|
|
|
/* PipeWire
|
|
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2018-08-02 11:25:27 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +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-08-02 11:25:27 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +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-08-02 11:25:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <spa/node/node.h>
|
|
|
|
|
#include <spa/utils/hook.h>
|
|
|
|
|
#include <spa/param/audio/format-utils.h>
|
2018-10-18 15:16:59 +02:00
|
|
|
#include <spa/param/props.h>
|
2018-11-16 16:41:13 +01:00
|
|
|
#include <spa/debug/pod.h>
|
2019-09-30 21:23:29 +02:00
|
|
|
#include <spa/support/dbus.h>
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#include "pipewire/pipewire.h"
|
2018-08-02 11:25:27 +02:00
|
|
|
#include "pipewire/private.h"
|
2019-11-04 17:27:41 +01:00
|
|
|
#include "extensions/session-manager.h"
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-09-30 21:23:29 +02:00
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
#define NAME "media-session"
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
#define DEFAULT_CHANNELS 2
|
2018-09-11 10:26:19 +02:00
|
|
|
#define DEFAULT_SAMPLERATE 48000
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-21 16:43:11 +02:00
|
|
|
#define DEFAULT_IDLE_SECONDS 3
|
|
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
struct impl;
|
|
|
|
|
|
|
|
|
|
struct monitor {
|
|
|
|
|
struct impl *impl;
|
|
|
|
|
|
|
|
|
|
struct spa_handle *handle;
|
2019-09-20 13:04:14 +02:00
|
|
|
|
|
|
|
|
struct spa_device *monitor;
|
|
|
|
|
struct spa_hook listener;
|
2019-07-10 20:24:11 +02:00
|
|
|
|
|
|
|
|
struct spa_list object_list;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
struct impl {
|
|
|
|
|
struct timespec now;
|
|
|
|
|
|
|
|
|
|
struct pw_main_loop *loop;
|
|
|
|
|
struct pw_core *core;
|
|
|
|
|
struct pw_remote *remote;
|
|
|
|
|
struct spa_hook remote_listener;
|
|
|
|
|
|
|
|
|
|
struct pw_core_proxy *core_proxy;
|
|
|
|
|
struct spa_hook core_listener;
|
|
|
|
|
|
|
|
|
|
struct pw_registry_proxy *registry_proxy;
|
|
|
|
|
struct spa_hook registry_listener;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct pw_map globals;
|
|
|
|
|
|
2018-10-27 17:33:21 +01:00
|
|
|
struct spa_list client_list;
|
2018-09-11 15:25:35 +02:00
|
|
|
struct spa_list node_list;
|
2018-08-02 11:25:27 +02:00
|
|
|
struct spa_list session_list;
|
2019-02-25 16:25:27 +01:00
|
|
|
int seq;
|
2019-07-10 20:24:11 +02:00
|
|
|
|
|
|
|
|
struct monitor bluez5_monitor;
|
|
|
|
|
struct monitor alsa_monitor;
|
|
|
|
|
struct monitor v4l2_monitor;
|
2019-09-30 21:23:29 +02:00
|
|
|
|
2019-11-03 10:31:14 +01:00
|
|
|
struct sm_metadata *metadata;
|
|
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
struct pw_client_session_proxy *client_session;
|
|
|
|
|
struct spa_hook client_session_listener;
|
|
|
|
|
struct pw_session_info client_session_info;
|
|
|
|
|
|
2019-09-30 21:23:29 +02:00
|
|
|
struct spa_dbus *dbus;
|
|
|
|
|
struct spa_dbus_connection *dbus_connection;
|
|
|
|
|
DBusConnection *conn;
|
2019-10-02 21:12:42 +02:00
|
|
|
|
|
|
|
|
struct pw_proxy *midi_bridge;
|
2019-10-21 16:39:08 +02:00
|
|
|
|
|
|
|
|
struct spa_source *jack_timeout;
|
|
|
|
|
struct pw_proxy *jack_device;
|
2018-08-02 11:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct object {
|
2018-08-02 11:25:27 +02:00
|
|
|
struct impl *impl;
|
2018-09-11 10:26:19 +02:00
|
|
|
uint32_t id;
|
|
|
|
|
uint32_t type;
|
2018-09-11 15:25:35 +02:00
|
|
|
struct pw_proxy *proxy;
|
|
|
|
|
struct spa_hook listener;
|
2018-09-11 10:26:19 +02:00
|
|
|
};
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-10-27 17:33:21 +01:00
|
|
|
struct client {
|
|
|
|
|
struct object obj;
|
|
|
|
|
|
|
|
|
|
struct spa_list l;
|
|
|
|
|
|
|
|
|
|
struct spa_hook listener;
|
|
|
|
|
struct pw_client_info *info;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct node {
|
|
|
|
|
struct object obj;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
struct spa_list l;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct spa_hook listener;
|
2018-08-02 11:25:27 +02:00
|
|
|
struct pw_node_info *info;
|
|
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
uint32_t client_id;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
struct spa_list session_link;
|
|
|
|
|
struct session *session;
|
|
|
|
|
|
2019-08-06 12:19:24 +02:00
|
|
|
struct node *peer;
|
|
|
|
|
|
2018-09-21 16:43:11 +02:00
|
|
|
struct session *manager;
|
2018-09-11 10:26:19 +02:00
|
|
|
struct spa_list port_list;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
|
|
|
|
enum pw_direction direction;
|
|
|
|
|
#define NODE_TYPE_UNKNOWN 0
|
|
|
|
|
#define NODE_TYPE_STREAM 1
|
2019-07-16 11:15:30 +02:00
|
|
|
#define NODE_TYPE_DEVICE 2
|
2018-09-11 15:25:35 +02:00
|
|
|
uint32_t type;
|
2018-10-18 12:53:30 +02:00
|
|
|
char *media;
|
2018-09-11 18:09:45 +02:00
|
|
|
|
2018-11-21 12:19:47 +01:00
|
|
|
uint32_t media_type;
|
|
|
|
|
uint32_t media_subtype;
|
2018-09-11 18:09:45 +02:00
|
|
|
struct spa_audio_info_raw format;
|
2018-09-11 10:26:19 +02:00
|
|
|
};
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct port {
|
|
|
|
|
struct object obj;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
struct spa_list l;
|
|
|
|
|
enum pw_direction direction;
|
2018-09-11 18:09:45 +02:00
|
|
|
struct pw_port_info *info;
|
2018-09-11 15:25:35 +02:00
|
|
|
struct node *node;
|
2018-12-11 16:32:19 +01:00
|
|
|
#define PORT_FLAG_NONE 0
|
|
|
|
|
#define PORT_FLAG_DSP (1<<0)
|
|
|
|
|
#define PORT_FLAG_SKIP (1<<1)
|
|
|
|
|
uint32_t flags;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct spa_hook listener;
|
|
|
|
|
};
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct link {
|
|
|
|
|
struct object obj;
|
2018-09-11 15:25:35 +02:00
|
|
|
struct port *out;
|
|
|
|
|
struct port *in;
|
2018-08-02 11:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct session {
|
2018-08-02 11:25:27 +02:00
|
|
|
struct spa_list l;
|
|
|
|
|
|
|
|
|
|
uint32_t id;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
struct impl *impl;
|
2018-08-02 11:25:27 +02:00
|
|
|
enum pw_direction direction;
|
2019-10-17 12:43:23 +02:00
|
|
|
int priority;
|
2018-09-11 10:26:19 +02:00
|
|
|
uint64_t plugged;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct node *node;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
struct spa_list node_list;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
struct spa_hook listener;
|
|
|
|
|
|
2018-09-18 09:28:52 +02:00
|
|
|
struct spa_source *idle_timeout;
|
|
|
|
|
|
2018-09-14 15:23:12 +02:00
|
|
|
bool starting;
|
2018-09-11 10:26:19 +02:00
|
|
|
bool enabled;
|
|
|
|
|
bool busy;
|
|
|
|
|
bool exclusive;
|
|
|
|
|
bool need_dsp;
|
2018-08-02 11:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
struct alsa_object;
|
|
|
|
|
|
|
|
|
|
static int setup_alsa_endpoint(struct alsa_object *obj);
|
|
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
#include "alsa-monitor.c"
|
2019-11-04 17:27:41 +01:00
|
|
|
#include "alsa-endpoint.c"
|
2019-07-10 20:24:11 +02:00
|
|
|
#include "v4l2-monitor.c"
|
|
|
|
|
#include "bluez-monitor.c"
|
2019-11-03 10:31:14 +01:00
|
|
|
#include "metadata.c"
|
2019-07-10 20:24:11 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
static void add_object(struct impl *impl, struct object *obj)
|
2018-08-02 11:25:27 +02:00
|
|
|
{
|
2018-09-11 10:26:19 +02:00
|
|
|
size_t size = pw_map_get_size(&impl->globals);
|
|
|
|
|
while (obj->id > size)
|
|
|
|
|
pw_map_insert_at(&impl->globals, size++, NULL);
|
|
|
|
|
pw_map_insert_at(&impl->globals, obj->id, obj);
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
static void remove_object(struct impl *impl, struct object *obj)
|
|
|
|
|
{
|
|
|
|
|
pw_map_insert_at(&impl->globals, obj->id, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
static void *find_object(struct impl *impl, uint32_t id)
|
2018-08-02 11:25:27 +02:00
|
|
|
{
|
2018-09-11 10:26:19 +02:00
|
|
|
void *obj;
|
|
|
|
|
if ((obj = pw_map_lookup(&impl->globals, id)) != NULL)
|
|
|
|
|
return obj;
|
|
|
|
|
return NULL;
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
static void schedule_rescan(struct impl *impl)
|
|
|
|
|
{
|
2018-09-26 13:22:21 +02:00
|
|
|
if (impl->core_proxy)
|
2019-02-25 12:29:57 +01:00
|
|
|
impl->seq = pw_core_proxy_sync(impl->core_proxy, 0, impl->seq);
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-09-18 09:28:52 +02:00
|
|
|
static void remove_idle_timeout(struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = sess->impl;
|
2018-09-21 16:43:11 +02:00
|
|
|
struct pw_loop *main_loop = pw_core_get_main_loop(impl->core);
|
2018-09-18 09:28:52 +02:00
|
|
|
|
|
|
|
|
if (sess->idle_timeout) {
|
2018-09-21 16:43:11 +02:00
|
|
|
pw_loop_destroy_source(main_loop, sess->idle_timeout);
|
2018-09-18 09:28:52 +02:00
|
|
|
sess->idle_timeout = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-21 16:43:11 +02:00
|
|
|
static void idle_timeout(void *data, uint64_t expirations)
|
|
|
|
|
{
|
|
|
|
|
struct session *sess = data;
|
|
|
|
|
struct impl *impl = sess->impl;
|
|
|
|
|
struct spa_command *cmd = &SPA_NODE_COMMAND_INIT(SPA_NODE_COMMAND_Suspend);
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: session %d idle timeout", impl, sess->id);
|
|
|
|
|
|
|
|
|
|
remove_idle_timeout(sess);
|
|
|
|
|
|
|
|
|
|
pw_node_proxy_send_command((struct pw_node_proxy*)sess->node->obj.proxy, cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_idle_timeout(struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct timespec value;
|
|
|
|
|
struct impl *impl = sess->impl;
|
|
|
|
|
struct pw_loop *main_loop = pw_core_get_main_loop(impl->core);
|
|
|
|
|
|
|
|
|
|
if (sess->idle_timeout == NULL)
|
|
|
|
|
sess->idle_timeout = pw_loop_add_timer(main_loop, idle_timeout, sess);
|
|
|
|
|
|
|
|
|
|
value.tv_sec = DEFAULT_IDLE_SECONDS;
|
|
|
|
|
value.tv_nsec = 0;
|
|
|
|
|
pw_loop_update_timer(main_loop, sess->idle_timeout, &value, NULL, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int on_node_idle(struct impl *impl, struct node *node)
|
|
|
|
|
{
|
|
|
|
|
struct session *sess = node->manager;
|
|
|
|
|
|
|
|
|
|
if (sess == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_TYPE_DEVICE:
|
|
|
|
|
pw_log_debug(NAME" %p: device idle for session %d", impl, sess->id);
|
|
|
|
|
sess->busy = false;
|
|
|
|
|
sess->exclusive = false;
|
|
|
|
|
add_idle_timeout(sess);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int on_node_running(struct impl *impl, struct node *node)
|
|
|
|
|
{
|
|
|
|
|
struct session *sess = node->manager;
|
|
|
|
|
|
|
|
|
|
if (sess == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_TYPE_DEVICE:
|
|
|
|
|
pw_log_debug(NAME" %p: device running or session %d", impl, sess->id);
|
|
|
|
|
remove_idle_timeout(sess);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void node_event_info(void *object, const struct pw_node_info *info)
|
2018-08-02 11:25:27 +02:00
|
|
|
{
|
2018-09-11 10:26:19 +02:00
|
|
|
struct node *n = object;
|
2018-09-21 16:43:11 +02:00
|
|
|
struct impl *impl = n->obj.impl;
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME" %p: info for node %d type %d", impl, n->obj.id, n->type);
|
2018-09-11 10:26:19 +02:00
|
|
|
n->info = pw_node_info_update(n->info, info);
|
2018-09-21 16:43:11 +02:00
|
|
|
|
2019-10-18 21:52:24 +02:00
|
|
|
if (info->change_mask & PW_NODE_CHANGE_MASK_STATE) {
|
|
|
|
|
switch (info->state) {
|
|
|
|
|
case PW_NODE_STATE_IDLE:
|
|
|
|
|
on_node_idle(impl, n);
|
|
|
|
|
break;
|
|
|
|
|
case PW_NODE_STATE_RUNNING:
|
|
|
|
|
on_node_running(impl, n);
|
|
|
|
|
break;
|
|
|
|
|
case PW_NODE_STATE_SUSPENDED:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-21 16:43:11 +02:00
|
|
|
}
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void node_event_param(void *object, int seq,
|
2018-10-04 16:41:00 +02:00
|
|
|
uint32_t id, uint32_t index, uint32_t next,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct node *n = object;
|
|
|
|
|
struct impl *impl = n->obj.impl;
|
2018-10-18 12:53:30 +02:00
|
|
|
struct spa_audio_info_raw info = { 0, };
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2018-11-28 17:32:35 +01:00
|
|
|
pw_log_debug(NAME" %p: param for node %d, %d", impl, n->obj.id, id);
|
2018-10-04 16:41:00 +02:00
|
|
|
|
|
|
|
|
if (id != SPA_PARAM_EnumFormat)
|
2018-11-28 17:32:35 +01:00
|
|
|
goto error;
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2018-11-21 12:19:47 +01:00
|
|
|
if (spa_format_parse(param, &n->media_type, &n->media_subtype) < 0)
|
2018-11-28 17:32:35 +01:00
|
|
|
goto error;
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2018-11-21 12:19:47 +01:00
|
|
|
if (n->media_type != SPA_MEDIA_TYPE_audio ||
|
|
|
|
|
n->media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2019-01-17 17:23:47 +01:00
|
|
|
spa_pod_object_fixate((struct spa_pod_object*)param);
|
2019-10-22 13:06:20 +02:00
|
|
|
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
|
|
|
|
|
spa_debug_pod(2, NULL, param);
|
2018-10-04 16:41:00 +02:00
|
|
|
|
|
|
|
|
if (spa_format_audio_raw_parse(param, &info) < 0)
|
2018-11-28 17:32:35 +01:00
|
|
|
goto error;
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2019-08-06 12:35:42 +02:00
|
|
|
if (n->format.channels < info.channels)
|
|
|
|
|
n->format = info;
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-11-28 17:32:35 +01:00
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
pw_log_warn("unhandled param:");
|
2019-10-22 13:06:20 +02:00
|
|
|
if (pw_log_level_enabled(SPA_LOG_LEVEL_WARN))
|
|
|
|
|
spa_debug_pod(2, NULL, param);
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-10-04 16:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
static const struct pw_node_proxy_events node_events = {
|
2018-08-02 11:25:27 +02:00
|
|
|
PW_VERSION_NODE_PROXY_EVENTS,
|
2018-09-11 10:26:19 +02:00
|
|
|
.info = node_event_info,
|
2018-10-04 16:41:00 +02:00
|
|
|
.param = node_event_param,
|
2018-08-02 11:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-26 13:22:21 +02:00
|
|
|
static void remove_session(struct impl *impl, struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct node *n, *t;
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: remove session '%d'", impl, sess->id);
|
|
|
|
|
remove_idle_timeout(sess);
|
|
|
|
|
|
|
|
|
|
spa_list_for_each_safe(n, t, &sess->node_list, session_link) {
|
|
|
|
|
n->session = NULL;
|
|
|
|
|
spa_list_remove(&n->session_link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spa_list_remove(&sess->l);
|
|
|
|
|
free(sess);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
static void node_proxy_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct node *n = data;
|
2018-09-26 13:22:21 +02:00
|
|
|
struct impl *impl = n->obj.impl;
|
2018-10-11 15:56:49 +02:00
|
|
|
struct port *p, *t;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2018-09-26 13:22:21 +02:00
|
|
|
pw_log_debug(NAME " %p: proxy destroy node %d", impl, n->obj.id);
|
2018-09-11 15:25:35 +02:00
|
|
|
|
|
|
|
|
spa_list_remove(&n->l);
|
2018-10-11 15:56:49 +02:00
|
|
|
|
|
|
|
|
spa_list_for_each_safe(p, t, &n->port_list, l) {
|
|
|
|
|
spa_list_remove(&p->l);
|
|
|
|
|
p->node = NULL;
|
|
|
|
|
}
|
2018-09-11 15:25:35 +02:00
|
|
|
if (n->info)
|
|
|
|
|
pw_node_info_free(n->info);
|
2018-12-19 17:47:25 +01:00
|
|
|
free(n->media);
|
2018-09-11 15:25:35 +02:00
|
|
|
if (n->session) {
|
|
|
|
|
spa_list_remove(&n->session_link);
|
2018-09-13 17:03:56 +02:00
|
|
|
n->session = NULL;
|
2018-09-11 15:25:35 +02:00
|
|
|
}
|
2018-09-26 13:22:21 +02:00
|
|
|
if (n->manager) {
|
|
|
|
|
switch (n->type) {
|
|
|
|
|
case NODE_TYPE_DEVICE:
|
|
|
|
|
remove_session(impl, n->manager);
|
2018-10-02 05:45:50 +02:00
|
|
|
n->manager = NULL;
|
2018-09-26 13:22:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-11 15:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_proxy_events node_proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
|
|
|
|
.destroy = node_proxy_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
static int
|
2019-08-16 22:11:42 +02:00
|
|
|
handle_node(struct impl *impl, uint32_t id,
|
2018-08-02 11:25:27 +02:00
|
|
|
uint32_t type, const struct spa_dict *props)
|
|
|
|
|
{
|
2018-10-05 10:28:20 +02:00
|
|
|
const char *str, *media_class;
|
2018-08-02 11:25:27 +02:00
|
|
|
bool need_dsp = false;
|
|
|
|
|
enum pw_direction direction;
|
|
|
|
|
struct pw_proxy *p;
|
2018-09-11 10:26:19 +02:00
|
|
|
struct node *node;
|
2019-08-16 22:11:42 +02:00
|
|
|
uint32_t client_id = SPA_ID_INVALID;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
if (props && (str = spa_dict_lookup(props, PW_KEY_CLIENT_ID)) != NULL)
|
|
|
|
|
client_id = atoi(str);
|
2018-10-05 10:28:20 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
p = pw_registry_proxy_bind(impl->registry_proxy,
|
2019-05-20 16:11:23 +02:00
|
|
|
id, type, PW_VERSION_NODE_PROXY,
|
2018-09-11 10:26:19 +02:00
|
|
|
sizeof(struct node));
|
|
|
|
|
|
|
|
|
|
node = pw_proxy_get_user_data(p);
|
|
|
|
|
node->obj.impl = impl;
|
|
|
|
|
node->obj.id = id;
|
|
|
|
|
node->obj.type = type;
|
2018-09-11 15:25:35 +02:00
|
|
|
node->obj.proxy = p;
|
2019-08-16 22:11:42 +02:00
|
|
|
node->client_id = client_id;
|
2018-09-11 10:26:19 +02:00
|
|
|
spa_list_init(&node->port_list);
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_proxy_add_listener(p, &node->obj.listener, &node_proxy_events, node);
|
2019-05-29 10:39:24 +02:00
|
|
|
pw_proxy_add_object_listener(p, &node->listener, &node_events, node);
|
2018-09-11 10:26:19 +02:00
|
|
|
add_object(impl, &node->obj);
|
2018-09-11 15:25:35 +02:00
|
|
|
spa_list_append(&impl->node_list, &node->l);
|
|
|
|
|
node->type = NODE_TYPE_UNKNOWN;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
media_class = props ? spa_dict_lookup(props, PW_KEY_MEDIA_CLASS) : NULL;
|
|
|
|
|
|
2019-05-24 16:14:19 +02:00
|
|
|
pw_log_debug(NAME" %p: node "PW_KEY_MEDIA_CLASS" %s", impl, media_class);
|
2018-11-16 16:41:13 +01:00
|
|
|
|
2018-10-05 10:28:20 +02:00
|
|
|
if (media_class == NULL)
|
2018-08-02 11:25:27 +02:00
|
|
|
return 0;
|
|
|
|
|
|
2018-10-05 10:28:20 +02:00
|
|
|
if (strstr(media_class, "Stream/") == media_class) {
|
|
|
|
|
media_class += strlen("Stream/");
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2018-10-18 12:53:30 +02:00
|
|
|
if (strstr(media_class, "Output/") == media_class) {
|
2018-08-02 11:25:27 +02:00
|
|
|
direction = PW_DIRECTION_OUTPUT;
|
2018-10-18 12:53:30 +02:00
|
|
|
media_class += strlen("Output/");
|
|
|
|
|
}
|
|
|
|
|
else if (strstr(media_class, "Input/") == media_class) {
|
2018-08-02 11:25:27 +02:00
|
|
|
direction = PW_DIRECTION_INPUT;
|
2018-10-18 12:53:30 +02:00
|
|
|
media_class += strlen("Input/");
|
|
|
|
|
}
|
2018-08-02 11:25:27 +02:00
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
node->direction = direction;
|
|
|
|
|
node->type = NODE_TYPE_STREAM;
|
2018-10-18 12:53:30 +02:00
|
|
|
node->media = strdup(media_class);
|
2018-11-28 17:32:35 +01:00
|
|
|
pw_log_debug(NAME "%p: node %d is stream %s", impl, id, node->media);
|
2018-10-04 16:41:00 +02:00
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
struct session *sess;
|
|
|
|
|
|
2018-10-05 10:28:20 +02:00
|
|
|
if (strstr(media_class, "Audio/") == media_class) {
|
2018-08-02 11:25:27 +02:00
|
|
|
need_dsp = true;
|
2018-10-05 10:28:20 +02:00
|
|
|
media_class += strlen("Audio/");
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
2018-10-05 10:28:20 +02:00
|
|
|
else if (strstr(media_class, "Video/") == media_class) {
|
|
|
|
|
media_class += strlen("Video/");
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
|
2018-10-05 10:28:20 +02:00
|
|
|
if (strcmp(media_class, "Sink") == 0)
|
2018-08-02 11:25:27 +02:00
|
|
|
direction = PW_DIRECTION_OUTPUT;
|
2018-10-05 10:28:20 +02:00
|
|
|
else if (strcmp(media_class, "Source") == 0)
|
2018-08-02 11:25:27 +02:00
|
|
|
direction = PW_DIRECTION_INPUT;
|
2019-07-16 11:15:30 +02:00
|
|
|
else
|
2018-08-02 11:25:27 +02:00
|
|
|
return 0;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
sess = calloc(1, sizeof(struct session));
|
2018-08-02 11:25:27 +02:00
|
|
|
sess->impl = impl;
|
|
|
|
|
sess->direction = direction;
|
|
|
|
|
sess->id = id;
|
|
|
|
|
sess->need_dsp = need_dsp;
|
2018-10-15 12:46:50 +02:00
|
|
|
sess->enabled = false;
|
2019-07-10 20:24:11 +02:00
|
|
|
sess->starting = need_dsp;
|
2018-09-11 10:26:19 +02:00
|
|
|
sess->node = node;
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((str = spa_dict_lookup(props, PW_KEY_NODE_PLUGGED)) != NULL)
|
2018-09-13 17:03:56 +02:00
|
|
|
sess->plugged = pw_properties_parse_uint64(str);
|
|
|
|
|
else
|
2018-11-07 09:56:24 +01:00
|
|
|
sess->plugged = SPA_TIMESPEC_TO_NSEC(&impl->now);
|
2018-09-13 17:03:56 +02:00
|
|
|
|
2019-10-22 12:25:25 +02:00
|
|
|
if ((str = spa_dict_lookup(props, PW_KEY_PRIORITY_SESSION)) != NULL)
|
2019-10-17 12:43:23 +02:00
|
|
|
sess->priority = pw_properties_parse_int(str);
|
|
|
|
|
else
|
|
|
|
|
sess->priority = 0;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
spa_list_init(&sess->node_list);
|
2018-08-02 11:25:27 +02:00
|
|
|
spa_list_append(&impl->session_list, &sess->l);
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
node->direction = direction;
|
|
|
|
|
node->type = NODE_TYPE_DEVICE;
|
2018-09-21 16:43:11 +02:00
|
|
|
node->manager = sess;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
pw_log_debug(NAME" %p: new session for device node %d %d prio:%d", impl, id,
|
|
|
|
|
need_dsp, sess->priority);
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
2019-07-10 20:24:11 +02:00
|
|
|
pw_node_proxy_enum_params((struct pw_node_proxy*)p,
|
|
|
|
|
0, SPA_PARAM_EnumFormat,
|
|
|
|
|
0, -1, NULL);
|
2018-08-02 11:25:27 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void port_event_info(void *object, const struct pw_port_info *info)
|
2018-09-11 18:09:45 +02:00
|
|
|
{
|
|
|
|
|
struct port *p = object;
|
|
|
|
|
pw_log_debug(NAME" %p: info for port %d", p->obj.impl, p->obj.id);
|
|
|
|
|
p->info = pw_port_info_update(p->info, info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void port_event_param(void *object, int seq,
|
2018-09-11 18:09:45 +02:00
|
|
|
uint32_t id, uint32_t index, uint32_t next,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct port *p = object;
|
|
|
|
|
struct node *node = p->node;
|
2018-10-18 12:53:30 +02:00
|
|
|
struct spa_audio_info_raw info = { 0, };
|
2018-09-11 18:09:45 +02:00
|
|
|
|
|
|
|
|
pw_log_debug(NAME" %p: param for port %d", p->obj.impl, p->obj.id);
|
|
|
|
|
|
2018-10-11 15:56:49 +02:00
|
|
|
if (node == NULL)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-10-11 15:56:49 +02:00
|
|
|
|
2018-09-11 18:09:45 +02:00
|
|
|
if (id != SPA_PARAM_EnumFormat)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-09-11 18:09:45 +02:00
|
|
|
|
2018-10-15 17:51:47 +02:00
|
|
|
if (node->manager)
|
|
|
|
|
node->manager->enabled = true;
|
|
|
|
|
|
2018-11-21 12:19:47 +01:00
|
|
|
if (spa_format_parse(param, &node->media_type, &node->media_subtype) < 0)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-09-11 18:09:45 +02:00
|
|
|
|
2018-11-21 12:19:47 +01:00
|
|
|
if (node->media_type != SPA_MEDIA_TYPE_audio ||
|
|
|
|
|
node->media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-09-11 18:09:45 +02:00
|
|
|
|
|
|
|
|
spa_pod_fixate((struct spa_pod*)param);
|
|
|
|
|
|
|
|
|
|
if (spa_format_audio_raw_parse(param, &info) < 0)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-09-11 18:09:45 +02:00
|
|
|
|
2018-10-15 17:51:47 +02:00
|
|
|
if (info.channels > node->format.channels)
|
2018-09-11 18:09:45 +02:00
|
|
|
node->format = info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_port_proxy_events port_events = {
|
|
|
|
|
PW_VERSION_PORT_PROXY_EVENTS,
|
|
|
|
|
.info = port_event_info,
|
|
|
|
|
.param = port_event_param,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void port_proxy_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct port *p = data;
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: proxy destroy port %d", p->obj.impl, p->obj.id);
|
|
|
|
|
|
2018-10-11 15:56:49 +02:00
|
|
|
if (p->node) {
|
|
|
|
|
spa_list_remove(&p->l);
|
|
|
|
|
p->node = NULL;
|
|
|
|
|
}
|
2018-09-11 18:09:45 +02:00
|
|
|
if (p->info)
|
|
|
|
|
pw_port_info_free(p->info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_proxy_events port_proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
|
|
|
|
.destroy = port_proxy_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
static int
|
2019-08-16 22:11:42 +02:00
|
|
|
handle_port(struct impl *impl, uint32_t id, uint32_t type,
|
2018-08-02 11:25:27 +02:00
|
|
|
const struct spa_dict *props)
|
|
|
|
|
{
|
|
|
|
|
struct port *port;
|
|
|
|
|
struct pw_proxy *p;
|
2018-09-11 10:26:19 +02:00
|
|
|
struct node *node;
|
|
|
|
|
const char *str;
|
2019-08-16 22:11:42 +02:00
|
|
|
uint32_t node_id;
|
|
|
|
|
|
|
|
|
|
if (props == NULL || (str = spa_dict_lookup(props, PW_KEY_NODE_ID)) == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
node_id = atoi(str);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
if ((node = find_object(impl, node_id)) == NULL)
|
2018-09-11 10:26:19 +02:00
|
|
|
return -ESRCH;
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if (props == NULL || (str = spa_dict_lookup(props, PW_KEY_PORT_DIRECTION)) == NULL)
|
2018-09-11 10:26:19 +02:00
|
|
|
return -EINVAL;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
p = pw_registry_proxy_bind(impl->registry_proxy,
|
2019-05-20 16:11:23 +02:00
|
|
|
id, type, PW_VERSION_PORT_PROXY,
|
2018-08-02 11:25:27 +02:00
|
|
|
sizeof(struct port));
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
port = pw_proxy_get_user_data(p);
|
2018-09-11 10:26:19 +02:00
|
|
|
port->obj.impl = impl;
|
|
|
|
|
port->obj.id = id;
|
|
|
|
|
port->obj.type = type;
|
2018-09-11 15:25:35 +02:00
|
|
|
port->obj.proxy = p;
|
2018-09-11 10:26:19 +02:00
|
|
|
port->node = node;
|
|
|
|
|
port->direction = strcmp(str, "out") ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT;
|
2018-12-11 16:32:19 +01:00
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if (props != NULL && (str = spa_dict_lookup(props, PW_KEY_FORMAT_DSP)) != NULL)
|
2018-12-11 16:32:19 +01:00
|
|
|
port->flags |= PORT_FLAG_DSP;
|
|
|
|
|
|
2018-09-11 18:09:45 +02:00
|
|
|
pw_proxy_add_listener(p, &port->obj.listener, &port_proxy_events, port);
|
2019-05-29 10:39:24 +02:00
|
|
|
pw_proxy_add_object_listener(p, &port->listener, &port_events, port);
|
2018-09-11 10:26:19 +02:00
|
|
|
add_object(impl, &port->obj);
|
|
|
|
|
|
|
|
|
|
spa_list_append(&node->port_list, &port->l);
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
pw_log_debug(NAME" %p: new port %d for node %d type %d %08x", impl, id, node_id,
|
2019-02-20 17:51:05 +01:00
|
|
|
node->type, port->flags);
|
|
|
|
|
|
2018-09-11 18:09:45 +02:00
|
|
|
if (node->type == NODE_TYPE_DEVICE) {
|
|
|
|
|
pw_port_proxy_enum_params((struct pw_port_proxy*)p,
|
2019-02-25 16:25:27 +01:00
|
|
|
0, SPA_PARAM_EnumFormat,
|
2018-09-11 18:09:45 +02:00
|
|
|
0, -1, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void client_event_info(void *object, const struct pw_client_info *info)
|
2018-10-27 17:33:21 +01:00
|
|
|
{
|
|
|
|
|
struct client *c = object;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t i;
|
2018-10-27 17:33:21 +01:00
|
|
|
|
|
|
|
|
pw_log_debug(NAME" %p: info for client %d", c->obj.impl, c->obj.id);
|
|
|
|
|
c->info = pw_client_info_update(c->info, info);
|
|
|
|
|
for (i = 0; i < info->props->n_items; i++)
|
|
|
|
|
pw_log_debug(NAME" %p: %s = %s", c,
|
|
|
|
|
info->props->items[i].key,
|
|
|
|
|
info->props->items[i].value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_client_proxy_events client_events = {
|
|
|
|
|
PW_VERSION_CLIENT_PROXY_EVENTS,
|
|
|
|
|
.info = client_event_info,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void client_proxy_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct client *c = data;
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: proxy destroy client %d", c->obj.impl, c->obj.id);
|
|
|
|
|
|
|
|
|
|
spa_list_remove(&c->l);
|
|
|
|
|
if (c->info)
|
|
|
|
|
pw_client_info_free(c->info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_proxy_events client_proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
|
|
|
|
.destroy = client_proxy_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2019-08-16 22:11:42 +02:00
|
|
|
handle_client(struct impl *impl, uint32_t id,
|
2018-10-27 17:33:21 +01:00
|
|
|
uint32_t type, const struct spa_dict *props)
|
|
|
|
|
{
|
|
|
|
|
struct pw_proxy *p;
|
|
|
|
|
struct client *client;
|
2018-11-05 15:02:08 +01:00
|
|
|
struct pw_permission perms[2];
|
2018-10-29 08:47:45 +00:00
|
|
|
const char *str;
|
2018-10-27 17:33:21 +01:00
|
|
|
|
|
|
|
|
p = pw_registry_proxy_bind(impl->registry_proxy,
|
2019-05-20 16:11:23 +02:00
|
|
|
id, type, PW_VERSION_CLIENT_PROXY,
|
2018-10-27 17:33:21 +01:00
|
|
|
sizeof(struct client));
|
|
|
|
|
|
|
|
|
|
client = pw_proxy_get_user_data(p);
|
|
|
|
|
client->obj.impl = impl;
|
|
|
|
|
client->obj.id = id;
|
|
|
|
|
client->obj.type = type;
|
|
|
|
|
client->obj.proxy = p;
|
|
|
|
|
|
|
|
|
|
pw_proxy_add_listener(p, &client->obj.listener, &client_proxy_events, client);
|
2019-05-29 10:39:24 +02:00
|
|
|
pw_proxy_add_object_listener(p, &client->listener, &client_events, client);
|
2018-10-27 17:33:21 +01:00
|
|
|
add_object(impl, &client->obj);
|
|
|
|
|
spa_list_append(&impl->client_list, &client->l);
|
|
|
|
|
|
2018-10-29 08:47:45 +00:00
|
|
|
if (props == NULL)
|
|
|
|
|
return 0;
|
2018-10-27 17:33:21 +01:00
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
str = spa_dict_lookup(props, PW_KEY_ACCESS);
|
2018-10-29 08:47:45 +00:00
|
|
|
if (str == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (strcmp(str, "restricted") == 0) {
|
2018-11-05 15:02:08 +01:00
|
|
|
perms[0] = PW_PERMISSION_INIT(-1, PW_PERM_RWX);
|
2018-10-29 08:47:45 +00:00
|
|
|
pw_client_proxy_update_permissions((struct pw_client_proxy*)p,
|
2018-11-05 15:02:08 +01:00
|
|
|
1, perms);
|
2018-10-29 08:47:45 +00:00
|
|
|
}
|
2018-10-27 17:33:21 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void
|
2019-08-16 22:11:42 +02:00
|
|
|
registry_global(void *data,uint32_t id,
|
2018-08-02 11:25:27 +02:00
|
|
|
uint32_t permissions, uint32_t type, uint32_t version,
|
|
|
|
|
const struct spa_dict *props)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2019-01-30 10:36:00 +01:00
|
|
|
int res;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-01-30 10:36:00 +01:00
|
|
|
pw_log_debug(NAME " %p: new global '%d' %d", impl, id, type);
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
switch (type) {
|
2018-10-27 17:33:21 +01:00
|
|
|
case PW_TYPE_INTERFACE_Client:
|
2019-08-16 22:11:42 +02:00
|
|
|
res = handle_client(impl, id, type, props);
|
2018-10-27 17:33:21 +01:00
|
|
|
break;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
case PW_TYPE_INTERFACE_Node:
|
2019-08-16 22:11:42 +02:00
|
|
|
res = handle_node(impl, id, type, props);
|
2018-09-11 10:26:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PW_TYPE_INTERFACE_Port:
|
2019-08-16 22:11:42 +02:00
|
|
|
res = handle_port(impl, id, type, props);
|
2018-09-11 10:26:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2019-01-30 10:36:00 +01:00
|
|
|
res = 0;
|
2018-09-11 10:26:19 +02:00
|
|
|
break;
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
2019-01-30 10:36:00 +01:00
|
|
|
if (res < 0) {
|
|
|
|
|
pw_log_warn(NAME" %p: can't handle global %d", impl, id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
schedule_rescan(impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void
|
2018-09-11 15:25:35 +02:00
|
|
|
registry_global_remove(void *data, uint32_t id)
|
2018-08-02 11:25:27 +02:00
|
|
|
{
|
2018-09-11 15:25:35 +02:00
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: remove global '%d'", impl, id);
|
|
|
|
|
|
|
|
|
|
if ((obj = find_object(impl, id)) == NULL)
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2018-09-21 16:43:11 +02:00
|
|
|
switch (obj->type) {
|
|
|
|
|
case PW_TYPE_INTERFACE_Node:
|
|
|
|
|
{
|
2019-08-06 12:19:24 +02:00
|
|
|
struct node *node = (struct node*) obj, *n;
|
2018-09-21 16:43:11 +02:00
|
|
|
if (node->manager)
|
|
|
|
|
remove_session(impl, node->manager);
|
2018-10-02 05:45:50 +02:00
|
|
|
node->manager = NULL;
|
2019-08-06 12:19:24 +02:00
|
|
|
|
|
|
|
|
spa_list_for_each(n, &impl->node_list, l) {
|
|
|
|
|
if (n->peer == node)
|
|
|
|
|
n->peer = NULL;
|
|
|
|
|
}
|
2018-09-21 16:43:11 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2018-09-17 17:17:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-09-11 15:25:35 +02:00
|
|
|
remove_object(impl, obj);
|
|
|
|
|
schedule_rescan(impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_registry_proxy_events registry_events = {
|
|
|
|
|
PW_VERSION_REGISTRY_PROXY_EVENTS,
|
|
|
|
|
.global = registry_global,
|
|
|
|
|
.global_remove = registry_global_remove,
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
struct find_data {
|
|
|
|
|
struct impl *impl;
|
|
|
|
|
uint32_t path_id;
|
|
|
|
|
const char *media_class;
|
|
|
|
|
struct session *sess;
|
|
|
|
|
bool exclusive;
|
2019-10-17 12:43:23 +02:00
|
|
|
int priority;
|
2018-09-11 10:26:19 +02:00
|
|
|
uint64_t plugged;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int find_session(void *data, struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct find_data *find = data;
|
|
|
|
|
struct impl *impl = find->impl;
|
|
|
|
|
const struct spa_dict *props;
|
|
|
|
|
const char *str;
|
2019-10-17 12:43:23 +02:00
|
|
|
int priority = 0;
|
2018-09-11 10:26:19 +02:00
|
|
|
uint64_t plugged = 0;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME " %p: looking at session '%d' enabled:%d busy:%d exclusive:%d",
|
2018-09-11 10:26:19 +02:00
|
|
|
impl, sess->id, sess->enabled, sess->busy, sess->exclusive);
|
|
|
|
|
|
|
|
|
|
if (!sess->enabled)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (find->path_id != SPA_ID_INVALID && sess->id != find->path_id)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (find->path_id == SPA_ID_INVALID) {
|
|
|
|
|
if ((props = sess->node->info->props) == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((str = spa_dict_lookup(props, PW_KEY_MEDIA_CLASS)) == NULL)
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (strcmp(str, find->media_class) != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
plugged = sess->plugged;
|
2019-10-17 12:43:23 +02:00
|
|
|
priority = sess->priority;
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((find->exclusive && sess->busy) || sess->exclusive) {
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME " %p: session '%d' in use", impl, sess->id);
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
pw_log_debug(NAME " %p: found session '%d' %"PRIu64" prio:%d", impl,
|
|
|
|
|
sess->id, plugged, priority);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-10-17 12:43:23 +02:00
|
|
|
if (find->sess == NULL ||
|
|
|
|
|
priority > find->priority ||
|
|
|
|
|
(priority == find->priority && plugged > find->plugged)) {
|
|
|
|
|
pw_log_debug(NAME " %p: new best %d %" PRIu64, impl, priority, plugged);
|
2018-09-11 10:26:19 +02:00
|
|
|
find->sess = sess;
|
2019-10-17 12:43:23 +02:00
|
|
|
find->priority = priority;
|
2018-09-11 10:26:19 +02:00
|
|
|
find->plugged = plugged;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 11:45:52 +02:00
|
|
|
static int link_nodes(struct node *peer, enum pw_direction direction, struct node *node, int max)
|
2018-09-11 10:26:19 +02:00
|
|
|
{
|
2018-09-11 15:25:35 +02:00
|
|
|
struct impl *impl = peer->obj.impl;
|
2018-09-11 10:26:19 +02:00
|
|
|
struct port *p;
|
|
|
|
|
|
2018-12-13 17:18:37 +01:00
|
|
|
pw_log_debug(NAME " %p: link nodes %d %d %d", impl, max, node->obj.id, peer->obj.id);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
spa_list_for_each(p, &peer->port_list, l) {
|
2018-10-05 10:28:20 +02:00
|
|
|
struct pw_properties *props;
|
|
|
|
|
|
2018-12-13 17:18:37 +01:00
|
|
|
pw_log_debug(NAME " %p: port %p: %d %d", impl, p, p->direction, p->flags);
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
if (p->direction == direction)
|
|
|
|
|
continue;
|
2018-12-11 16:32:19 +01:00
|
|
|
if (p->flags & PORT_FLAG_SKIP)
|
|
|
|
|
continue;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2018-10-08 11:45:52 +02:00
|
|
|
if (max-- == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
props = pw_properties_new(NULL, NULL);
|
2018-09-11 12:02:35 +02:00
|
|
|
if (p->direction == PW_DIRECTION_OUTPUT) {
|
2019-05-24 15:47:48 +02:00
|
|
|
pw_properties_setf(props, PW_KEY_LINK_OUTPUT_NODE, "%d", node->obj.id);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_OUTPUT_PORT, "%d", -1);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_INPUT_NODE, "%d", peer->obj.id);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_INPUT_PORT, "%d", p->obj.id);
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME " %p: node %d -> port %d:%d", impl,
|
|
|
|
|
node->obj.id, peer->obj.id, p->obj.id);
|
|
|
|
|
|
2018-09-11 12:02:35 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-24 15:47:48 +02:00
|
|
|
pw_properties_setf(props, PW_KEY_LINK_OUTPUT_NODE, "%d", peer->obj.id);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_OUTPUT_PORT, "%d", p->obj.id);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_INPUT_NODE, "%d", node->obj.id);
|
|
|
|
|
pw_properties_setf(props, PW_KEY_LINK_INPUT_PORT, "%d", -1);
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME " %p: port %d:%d -> node %d", impl,
|
|
|
|
|
peer->obj.id, p->obj.id, node->obj.id);
|
2018-09-11 12:02:35 +02:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
pw_core_proxy_create_object(impl->core_proxy,
|
|
|
|
|
"link-factory",
|
|
|
|
|
PW_TYPE_INTERFACE_Link,
|
2019-05-20 16:11:23 +02:00
|
|
|
PW_VERSION_LINK_PROXY,
|
2018-09-11 10:26:19 +02:00
|
|
|
&props->dict,
|
|
|
|
|
0);
|
2018-10-05 10:28:20 +02:00
|
|
|
|
|
|
|
|
pw_properties_free(props);
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
2019-08-06 12:19:24 +02:00
|
|
|
node->peer = peer;
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 15:16:59 +02:00
|
|
|
static void stream_set_volume(struct impl *impl, struct node *node, float volume, bool mute)
|
|
|
|
|
{
|
|
|
|
|
char buf[1024];
|
|
|
|
|
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
|
|
|
|
|
|
|
|
|
|
pw_log_debug(NAME " %p: node %d set volume:%f mute:%d", impl, node->obj.id, volume, mute);
|
|
|
|
|
|
|
|
|
|
pw_node_proxy_set_param((struct pw_node_proxy*)node->obj.proxy,
|
|
|
|
|
SPA_PARAM_Props, 0,
|
2019-01-16 11:05:12 +01:00
|
|
|
spa_pod_builder_add_object(&b,
|
2018-10-18 15:16:59 +02:00
|
|
|
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PROP_volume, SPA_POD_Float(volume),
|
|
|
|
|
SPA_PROP_mute, SPA_POD_Bool(mute)));
|
2018-10-18 15:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
static int rescan_node(struct impl *impl, struct node *node)
|
2018-09-11 10:26:19 +02:00
|
|
|
{
|
|
|
|
|
struct spa_dict *props;
|
|
|
|
|
const char *str, *media, *category, *role;
|
|
|
|
|
bool exclusive;
|
|
|
|
|
struct find_data find;
|
|
|
|
|
struct session *session;
|
|
|
|
|
struct pw_node_info *info;
|
|
|
|
|
struct node *peer;
|
|
|
|
|
enum pw_direction direction;
|
2018-10-08 11:45:52 +02:00
|
|
|
struct spa_pod_builder b = { 0, };
|
2018-10-18 12:53:30 +02:00
|
|
|
struct spa_audio_info_raw audio_info = { 0, };
|
2018-10-08 11:45:52 +02:00
|
|
|
struct spa_pod *param;
|
|
|
|
|
char buf[1024];
|
2018-10-30 16:30:16 +00:00
|
|
|
int n_links = 0;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-07-16 11:15:30 +02:00
|
|
|
if (node->type == NODE_TYPE_DEVICE)
|
2018-09-11 15:25:35 +02:00
|
|
|
return 0;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-08-06 12:19:24 +02:00
|
|
|
if (node->session != NULL || node->peer != NULL)
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
if (node->info == NULL || node->info->props == NULL) {
|
|
|
|
|
pw_log_debug(NAME " %p: node %d has no properties", impl, node->obj.id);
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
info = node->info;
|
2018-09-11 10:26:19 +02:00
|
|
|
props = info->props;
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
str = spa_dict_lookup(props, PW_KEY_NODE_AUTOCONNECT);
|
2018-09-11 10:26:19 +02:00
|
|
|
if (str == NULL || !pw_properties_parse_bool(str)) {
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME" %p: node %d does not need autoconnect", impl, node->obj.id);
|
2018-09-11 10:26:19 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((media = spa_dict_lookup(props, PW_KEY_MEDIA_TYPE)) == NULL)
|
2018-10-18 12:53:30 +02:00
|
|
|
media = node->media;
|
2019-01-29 16:51:55 +01:00
|
|
|
if (media == NULL) {
|
|
|
|
|
pw_log_debug(NAME" %p: node %d has unknown media", impl, node->obj.id);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-10-17 12:43:23 +02:00
|
|
|
spa_zero(find);
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((category = spa_dict_lookup(props, PW_KEY_MEDIA_CATEGORY)) == NULL) {
|
2018-11-28 17:32:35 +01:00
|
|
|
pw_log_debug(NAME" %p: node %d find category from ports: %d %d",
|
|
|
|
|
impl, node->obj.id, info->n_input_ports, info->n_output_ports);
|
|
|
|
|
if (node->direction == PW_DIRECTION_INPUT ||
|
|
|
|
|
(info->n_input_ports > 0 && info->n_output_ports == 0))
|
2018-09-11 10:26:19 +02:00
|
|
|
category = "Capture";
|
2018-11-28 17:32:35 +01:00
|
|
|
else if (node->direction == PW_DIRECTION_OUTPUT ||
|
|
|
|
|
(info->n_output_ports > 0 && info->n_input_ports == 0))
|
2018-09-11 10:26:19 +02:00
|
|
|
category = "Playback";
|
2018-10-18 12:53:30 +02:00
|
|
|
else if (info->n_output_ports > 0 && info->n_input_ports > 0)
|
|
|
|
|
category = "Duplex";
|
2018-11-28 17:32:35 +01:00
|
|
|
else {
|
|
|
|
|
pw_log_warn(NAME" %p: node %d can't determine category",
|
|
|
|
|
impl, node->obj.id);
|
2018-09-11 10:26:19 +02:00
|
|
|
return -EINVAL;
|
2018-11-28 17:32:35 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((role = spa_dict_lookup(props, PW_KEY_MEDIA_ROLE)) == NULL) {
|
2018-10-18 12:53:30 +02:00
|
|
|
if (strcmp(media, "Audio") == 0) {
|
|
|
|
|
if (strcmp(category, "Duplex") == 0)
|
|
|
|
|
role = "Communication";
|
|
|
|
|
else if (strcmp(category, "Capture") == 0)
|
|
|
|
|
role = "Production";
|
|
|
|
|
else
|
|
|
|
|
role = "Music";
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(media, "Video") == 0) {
|
|
|
|
|
if (strcmp(category, "Duplex") == 0)
|
|
|
|
|
role = "Communication";
|
|
|
|
|
else if (strcmp(category, "Capture") == 0)
|
|
|
|
|
role = "Camera";
|
|
|
|
|
else
|
|
|
|
|
role = "Video";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((str = spa_dict_lookup(props, PW_KEY_NODE_EXCLUSIVE)) != NULL)
|
2018-09-11 10:26:19 +02:00
|
|
|
exclusive = pw_properties_parse_bool(str);
|
|
|
|
|
else
|
|
|
|
|
exclusive = false;
|
|
|
|
|
|
|
|
|
|
if (strcmp(media, "Audio") == 0) {
|
|
|
|
|
if (strcmp(category, "Playback") == 0)
|
|
|
|
|
find.media_class = "Audio/Sink";
|
|
|
|
|
else if (strcmp(category, "Capture") == 0)
|
|
|
|
|
find.media_class = "Audio/Source";
|
2018-11-28 17:32:35 +01:00
|
|
|
else {
|
|
|
|
|
pw_log_debug(NAME" %p: node %d unhandled category %s",
|
|
|
|
|
impl, node->obj.id, category);
|
2018-09-11 10:26:19 +02:00
|
|
|
return -EINVAL;
|
2018-11-28 17:32:35 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
else if (strcmp(media, "Video") == 0) {
|
|
|
|
|
if (strcmp(category, "Capture") == 0)
|
|
|
|
|
find.media_class = "Video/Source";
|
2018-11-28 17:32:35 +01:00
|
|
|
else {
|
|
|
|
|
pw_log_debug(NAME" %p: node %d unhandled category %s",
|
|
|
|
|
impl, node->obj.id, category);
|
2018-09-11 10:26:19 +02:00
|
|
|
return -EINVAL;
|
2018-11-28 17:32:35 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
2018-11-28 17:32:35 +01:00
|
|
|
else {
|
|
|
|
|
pw_log_debug(NAME" %p: node %d unhandled media %s",
|
|
|
|
|
impl, node->obj.id, media);
|
2018-09-11 10:26:19 +02:00
|
|
|
return -EINVAL;
|
2018-11-28 17:32:35 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2018-10-30 16:30:16 +00:00
|
|
|
if (strcmp(category, "Capture") == 0)
|
|
|
|
|
direction = PW_DIRECTION_OUTPUT;
|
|
|
|
|
else if (strcmp(category, "Playback") == 0)
|
|
|
|
|
direction = PW_DIRECTION_INPUT;
|
2018-11-28 17:32:35 +01:00
|
|
|
else {
|
|
|
|
|
pw_log_debug(NAME" %p: node %d unhandled category %s",
|
|
|
|
|
impl, node->obj.id, category);
|
2018-10-30 16:30:16 +00:00
|
|
|
return -EINVAL;
|
2018-11-28 17:32:35 +01:00
|
|
|
}
|
2018-10-30 16:30:16 +00:00
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
str = spa_dict_lookup(props, PW_KEY_NODE_TARGET);
|
2018-09-11 10:26:19 +02:00
|
|
|
if (str != NULL)
|
|
|
|
|
find.path_id = atoi(str);
|
|
|
|
|
else
|
|
|
|
|
find.path_id = SPA_ID_INVALID;
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_info(NAME " %p: '%s' '%s' '%s' exclusive:%d target %d", impl,
|
2018-09-11 10:26:19 +02:00
|
|
|
media, category, role, exclusive, find.path_id);
|
|
|
|
|
|
|
|
|
|
find.impl = impl;
|
|
|
|
|
find.exclusive = exclusive;
|
2019-10-17 12:43:23 +02:00
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
spa_list_for_each(session, &impl->session_list, l)
|
|
|
|
|
find_session(&find, session);
|
2018-10-27 17:33:21 +01:00
|
|
|
|
2018-10-30 16:30:16 +00:00
|
|
|
if (find.sess == NULL && find.path_id != SPA_ID_INVALID) {
|
|
|
|
|
pw_log_debug(NAME " %p: no session found for %d, try node", impl, node->obj.id);
|
|
|
|
|
|
|
|
|
|
n_links = 1;
|
2018-12-14 16:35:57 +01:00
|
|
|
if ((peer = find_object(impl, find.path_id)) != NULL) {
|
|
|
|
|
if (peer->obj.type == PW_TYPE_INTERFACE_Node) {
|
|
|
|
|
if (peer->media_type == SPA_MEDIA_TYPE_audio)
|
|
|
|
|
goto do_link_profile;
|
|
|
|
|
else
|
|
|
|
|
goto do_link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-05-24 15:47:48 +02:00
|
|
|
str = spa_dict_lookup(props, PW_KEY_NODE_DONT_RECONNECT);
|
2018-12-14 16:35:57 +01:00
|
|
|
if (str != NULL && pw_properties_parse_bool(str)) {
|
|
|
|
|
pw_registry_proxy_destroy(impl->registry_proxy, node->obj.id);
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
}
|
2018-12-13 17:18:37 +01:00
|
|
|
}
|
2018-10-30 16:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-27 17:33:21 +01:00
|
|
|
if (find.sess == NULL) {
|
|
|
|
|
struct client *client;
|
|
|
|
|
|
|
|
|
|
pw_log_warn(NAME " %p: no session found for %d", impl, node->obj.id);
|
|
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
client = find_object(impl, node->client_id);
|
2018-10-27 17:33:21 +01:00
|
|
|
if (client && client->obj.type == PW_TYPE_INTERFACE_Client) {
|
|
|
|
|
pw_client_proxy_error((struct pw_client_proxy*)client->obj.proxy,
|
2018-12-14 16:35:57 +01:00
|
|
|
node->obj.id, -ENOENT, "no session available");
|
2018-10-27 17:33:21 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
return -ENOENT;
|
2018-10-27 17:33:21 +01:00
|
|
|
}
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
session = find.sess;
|
|
|
|
|
|
2018-09-14 15:23:12 +02:00
|
|
|
if (session->starting) {
|
|
|
|
|
pw_log_info(NAME " %p: session %d is starting", impl, session->id);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
if (exclusive && session->busy) {
|
|
|
|
|
pw_log_warn(NAME" %p: session %d busy, can't get exclusive access", impl, session->id);
|
|
|
|
|
return -EBUSY;
|
2018-09-11 10:26:19 +02:00
|
|
|
}
|
2019-07-10 20:24:11 +02:00
|
|
|
peer = session->node;
|
|
|
|
|
session->exclusive = exclusive;
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_debug(NAME" %p: linking to session '%d'", impl, session->id);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
session->busy = true;
|
2018-09-11 15:25:35 +02:00
|
|
|
node->session = session;
|
|
|
|
|
spa_list_append(&session->node_list, &node->session_link);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
2019-07-29 16:52:24 +02:00
|
|
|
if (!exclusive && peer->media_type == SPA_MEDIA_TYPE_audio) {
|
2018-12-13 17:18:37 +01:00
|
|
|
do_link_profile:
|
2019-07-16 11:15:30 +02:00
|
|
|
audio_info = peer->format;
|
2019-02-25 12:29:57 +01:00
|
|
|
|
2018-12-05 15:59:45 +01:00
|
|
|
if (direction == PW_DIRECTION_INPUT)
|
2019-07-16 11:15:30 +02:00
|
|
|
audio_info.channels = SPA_MIN(audio_info.channels, node->format.channels);
|
2018-12-05 15:59:45 +01:00
|
|
|
else
|
2019-07-16 11:15:30 +02:00
|
|
|
audio_info.channels = SPA_MAX(audio_info.channels, node->format.channels);
|
2018-12-05 15:59:45 +01:00
|
|
|
|
2019-07-16 11:15:30 +02:00
|
|
|
pw_log_debug(NAME" %p: channels: %d -> %d", impl,
|
|
|
|
|
node->format.channels, audio_info.channels);
|
2019-02-25 12:29:57 +01:00
|
|
|
|
2019-07-09 16:56:05 +02:00
|
|
|
audio_info.rate = DEFAULT_SAMPLERATE;
|
2018-10-08 11:45:52 +02:00
|
|
|
|
|
|
|
|
spa_pod_builder_init(&b, buf, sizeof(buf));
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_format_audio_raw_build(&b, SPA_PARAM_Format, &audio_info);
|
|
|
|
|
param = spa_pod_builder_add_object(&b,
|
2019-08-06 12:45:20 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamPortConfig, SPA_PARAM_PortConfig,
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_direction, SPA_POD_Id(pw_direction_reverse(direction)),
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_mode, SPA_POD_Id(SPA_PARAM_PORT_CONFIG_MODE_dsp),
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_format, SPA_POD_Pod(param));
|
2018-11-16 16:41:13 +01:00
|
|
|
|
|
|
|
|
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
|
|
|
|
|
spa_debug_pod(2, NULL, param);
|
|
|
|
|
|
2018-10-08 11:45:52 +02:00
|
|
|
pw_node_proxy_set_param((struct pw_node_proxy*)node->obj.proxy,
|
2019-08-06 12:45:20 +02:00
|
|
|
SPA_PARAM_PortConfig, 0, param);
|
2018-10-18 15:16:59 +02:00
|
|
|
|
|
|
|
|
stream_set_volume(impl, node, 1.0, false);
|
2018-10-30 16:30:16 +00:00
|
|
|
n_links = audio_info.channels;
|
2018-10-08 11:45:52 +02:00
|
|
|
} else {
|
2018-10-30 16:30:16 +00:00
|
|
|
n_links = audio_info.channels = 1;
|
2018-10-08 11:45:52 +02:00
|
|
|
}
|
2018-12-13 17:18:37 +01:00
|
|
|
do_link:
|
2018-10-30 16:30:16 +00:00
|
|
|
link_nodes(peer, direction, node, n_links);
|
2018-09-11 10:26:19 +02:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
static void rescan_session(struct impl *impl, struct session *sess)
|
2018-08-02 11:25:27 +02:00
|
|
|
{
|
2019-07-10 20:24:11 +02:00
|
|
|
struct node *node = sess->node;
|
|
|
|
|
struct spa_audio_info_raw info = { 0, };
|
|
|
|
|
uint8_t buf[1024];
|
|
|
|
|
struct spa_pod_builder b = { 0, };
|
|
|
|
|
struct spa_pod *param;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
if (!sess->starting)
|
|
|
|
|
return;
|
2018-11-21 12:19:47 +01:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
if (node->info->props == NULL) {
|
|
|
|
|
pw_log_debug(NAME " %p: node %p has no properties", impl, node);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-14 15:23:12 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
if (node->media_type != SPA_MEDIA_TYPE_audio ||
|
|
|
|
|
node->media_subtype != SPA_MEDIA_SUBTYPE_raw) {
|
|
|
|
|
pw_log_debug(NAME " %p: node %p has no media type", impl, node);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
info = node->format;
|
|
|
|
|
info.rate = DEFAULT_SAMPLERATE;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2019-08-06 12:45:20 +02:00
|
|
|
pw_log_debug(NAME" %p: setting profile for session %d %d", impl, sess->id, sess->direction);
|
2018-10-05 10:28:20 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
spa_pod_builder_init(&b, buf, sizeof(buf));
|
|
|
|
|
param = spa_format_audio_raw_build(&b, SPA_PARAM_Format, &info);
|
|
|
|
|
param = spa_pod_builder_add_object(&b,
|
2019-08-06 12:45:20 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamPortConfig, SPA_PARAM_PortConfig,
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_direction, SPA_POD_Id(pw_direction_reverse(sess->direction)),
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_mode, SPA_POD_Id(SPA_PARAM_PORT_CONFIG_MODE_dsp),
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_monitor, SPA_POD_Bool(true),
|
|
|
|
|
SPA_PARAM_PORT_CONFIG_format, SPA_POD_Pod(param));
|
2018-10-08 11:45:52 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
pw_node_proxy_set_param((struct pw_node_proxy*)sess->node->obj.proxy,
|
2019-08-06 12:45:20 +02:00
|
|
|
SPA_PARAM_PortConfig, 0, param);
|
2019-07-10 20:24:11 +02:00
|
|
|
schedule_rescan(impl);
|
2018-10-08 11:45:52 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
sess->starting = false;
|
2018-09-11 15:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_rescan(struct impl *impl)
|
|
|
|
|
{
|
|
|
|
|
struct session *sess;
|
|
|
|
|
struct node *node;
|
|
|
|
|
|
2018-09-13 17:03:56 +02:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &impl->now);
|
2019-02-20 17:51:05 +01:00
|
|
|
pw_log_debug("media-session %p: do rescan", impl);
|
2018-09-13 17:03:56 +02:00
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
spa_list_for_each(sess, &impl->session_list, l)
|
|
|
|
|
rescan_session(impl, sess);
|
|
|
|
|
spa_list_for_each(node, &impl->node_list, l)
|
|
|
|
|
rescan_node(impl, node);
|
2018-08-02 11:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void core_done(void *data, uint32_t id, int seq)
|
2019-01-10 10:08:14 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2019-05-20 16:11:23 +02:00
|
|
|
pw_log_debug("media-session %p: sync %u %d/%d", impl, id, seq, impl->seq);
|
2019-01-10 10:08:14 +01:00
|
|
|
if (impl->seq == seq)
|
|
|
|
|
do_rescan(impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_core_proxy_events core_events = {
|
|
|
|
|
PW_VERSION_CORE_EVENTS,
|
|
|
|
|
.done = core_done
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
static int client_session_set_id(void *object, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = object;
|
|
|
|
|
|
|
|
|
|
pw_log_debug("got sesssion id:%d", id);
|
|
|
|
|
impl->client_session_info.id = id;
|
|
|
|
|
|
|
|
|
|
pw_client_session_proxy_update(impl->client_session,
|
|
|
|
|
PW_CLIENT_SESSION_UPDATE_INFO,
|
|
|
|
|
0, NULL,
|
|
|
|
|
&impl->client_session_info);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int client_session_set_param(void *object, uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = object;
|
|
|
|
|
pw_proxy_error((struct pw_proxy*)impl->client_session,
|
|
|
|
|
-ENOTSUP, "Session:SetParam not supported");
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int client_session_link_set_param(void *object, uint32_t link_id, uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = object;
|
|
|
|
|
pw_proxy_error((struct pw_proxy*)impl->client_session,
|
|
|
|
|
-ENOTSUP, "Session:LinkSetParam not supported");
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int client_session_create_link(void *object, const struct spa_dict *props)
|
|
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int client_session_destroy_link(void *object, uint32_t link_id)
|
|
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int client_session_link_request_state(void *object, uint32_t link_id, uint32_t state)
|
|
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct pw_client_session_proxy_events client_session_events = {
|
|
|
|
|
PW_VERSION_CLIENT_SESSION_PROXY_METHODS,
|
|
|
|
|
.set_id = client_session_set_id,
|
|
|
|
|
.set_param = client_session_set_param,
|
|
|
|
|
.link_set_param = client_session_link_set_param,
|
|
|
|
|
.create_link = client_session_create_link,
|
|
|
|
|
.destroy_link = client_session_destroy_link,
|
|
|
|
|
.link_request_state = client_session_link_request_state,
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-30 21:23:29 +02:00
|
|
|
static void start_services(struct impl *impl)
|
|
|
|
|
{
|
|
|
|
|
const struct spa_support *support;
|
|
|
|
|
uint32_t n_support;
|
|
|
|
|
|
|
|
|
|
support = pw_core_get_support(impl->core, &n_support);
|
|
|
|
|
|
|
|
|
|
impl->dbus = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DBus);
|
|
|
|
|
if (impl->dbus)
|
|
|
|
|
impl->dbus_connection = spa_dbus_get_connection(impl->dbus, DBUS_BUS_SESSION);
|
|
|
|
|
if (impl->dbus_connection)
|
|
|
|
|
impl->conn = spa_dbus_connection_get(impl->dbus_connection);
|
|
|
|
|
if (impl->conn == NULL)
|
|
|
|
|
pw_log_warn("no dbus connection, device reservation disabled");
|
|
|
|
|
else
|
|
|
|
|
pw_log_debug("got dbus connection %p", impl->conn);
|
|
|
|
|
|
2019-11-03 10:31:14 +01:00
|
|
|
pw_remote_export(impl->remote,
|
|
|
|
|
PW_TYPE_INTERFACE_Metadata,
|
|
|
|
|
NULL,
|
|
|
|
|
impl->metadata,
|
|
|
|
|
0);
|
|
|
|
|
|
2019-11-04 17:27:41 +01:00
|
|
|
impl->client_session = pw_core_proxy_create_object(impl->core_proxy,
|
|
|
|
|
"client-session",
|
|
|
|
|
PW_TYPE_INTERFACE_ClientSession,
|
|
|
|
|
PW_VERSION_CLIENT_SESSION_PROXY,
|
|
|
|
|
NULL, 0);
|
|
|
|
|
impl->client_session_info.version = PW_VERSION_SESSION_INFO;
|
|
|
|
|
|
|
|
|
|
pw_client_session_proxy_add_listener(impl->client_session,
|
|
|
|
|
&impl->client_session_listener,
|
|
|
|
|
&client_session_events,
|
|
|
|
|
impl);
|
|
|
|
|
|
2019-09-30 21:23:29 +02:00
|
|
|
bluez5_start_monitor(impl, &impl->bluez5_monitor);
|
|
|
|
|
alsa_start_monitor(impl, &impl->alsa_monitor);
|
2019-10-02 21:12:42 +02:00
|
|
|
alsa_start_midi_bridge(impl);
|
2019-10-21 16:39:08 +02:00
|
|
|
alsa_start_jack_device(impl);
|
2019-09-30 21:23:29 +02:00
|
|
|
v4l2_start_monitor(impl, &impl->v4l2_monitor);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = _data;
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case PW_REMOTE_STATE_ERROR:
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_error(NAME" %p: remote error: %s", impl, error);
|
2018-08-02 11:25:27 +02:00
|
|
|
pw_main_loop_quit(impl->loop);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PW_REMOTE_STATE_CONNECTED:
|
2018-09-26 13:22:21 +02:00
|
|
|
pw_log_info(NAME" %p: connected", impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
impl->core_proxy = pw_remote_get_core_proxy(impl->remote);
|
2019-01-10 10:08:14 +01:00
|
|
|
pw_core_proxy_add_listener(impl->core_proxy,
|
|
|
|
|
&impl->core_listener,
|
|
|
|
|
&core_events, impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
impl->registry_proxy = pw_core_proxy_get_registry(impl->core_proxy,
|
2019-05-20 16:11:23 +02:00
|
|
|
PW_VERSION_REGISTRY_PROXY, 0);
|
2018-08-02 11:25:27 +02:00
|
|
|
pw_registry_proxy_add_listener(impl->registry_proxy,
|
|
|
|
|
&impl->registry_listener,
|
|
|
|
|
®istry_events, impl);
|
2019-09-30 21:23:29 +02:00
|
|
|
start_services(impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
schedule_rescan(impl);
|
|
|
|
|
break;
|
2018-09-26 13:22:21 +02:00
|
|
|
|
|
|
|
|
case PW_REMOTE_STATE_UNCONNECTED:
|
|
|
|
|
pw_log_info(NAME" %p: disconnected", impl);
|
|
|
|
|
impl->core_proxy = NULL;
|
|
|
|
|
impl->registry_proxy = NULL;
|
|
|
|
|
pw_main_loop_quit(impl->loop);
|
|
|
|
|
break;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_remote_events remote_events = {
|
|
|
|
|
PW_VERSION_REMOTE_EVENTS,
|
|
|
|
|
.state_changed = on_state_changed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct impl impl = { 0, };
|
|
|
|
|
|
|
|
|
|
pw_init(&argc, &argv);
|
|
|
|
|
|
|
|
|
|
impl.loop = pw_main_loop_new(NULL);
|
2019-01-08 17:30:12 +01:00
|
|
|
impl.core = pw_core_new(pw_main_loop_get_loop(impl.loop), NULL, 0);
|
2018-08-02 11:25:27 +02:00
|
|
|
impl.remote = pw_remote_new(impl.core, NULL, 0);
|
|
|
|
|
|
2018-09-11 10:26:19 +02:00
|
|
|
pw_map_init(&impl.globals, 64, 64);
|
|
|
|
|
|
2018-10-27 17:33:21 +01:00
|
|
|
spa_list_init(&impl.client_list);
|
2018-09-11 15:25:35 +02:00
|
|
|
spa_list_init(&impl.node_list);
|
2018-10-27 17:33:21 +01:00
|
|
|
spa_list_init(&impl.session_list);
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
pw_core_add_spa_lib(impl.core, "api.bluez5.*", "bluez5/libspa-bluez5");
|
|
|
|
|
pw_core_add_spa_lib(impl.core, "api.alsa.*", "alsa/libspa-alsa");
|
|
|
|
|
pw_core_add_spa_lib(impl.core, "api.v4l2.*", "v4l2/libspa-v4l2");
|
|
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-client-device", NULL, NULL);
|
|
|
|
|
pw_module_load(impl.core, "libpipewire-module-adapter", NULL, NULL);
|
2019-11-03 10:31:14 +01:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-metadata", NULL, NULL);
|
2019-11-04 17:27:41 +01:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-session-manager", NULL, NULL);
|
2019-07-10 20:24:11 +02:00
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &impl.now);
|
|
|
|
|
|
|
|
|
|
pw_remote_add_listener(impl.remote, &impl.remote_listener, &remote_events, &impl);
|
|
|
|
|
|
2019-01-10 10:08:14 +01:00
|
|
|
if (pw_remote_connect(impl.remote) < 0)
|
|
|
|
|
return -1;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-11-03 10:31:14 +01:00
|
|
|
impl.metadata = sm_metadata_new(NULL);
|
|
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
pw_main_loop_run(impl.loop);
|
|
|
|
|
|
|
|
|
|
pw_core_destroy(impl.core);
|
|
|
|
|
pw_main_loop_destroy(impl.loop);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|