mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
media-session: switch to new property helpers
This commit is contained in:
parent
fb884b9441
commit
12c5a9b7ea
5 changed files with 42 additions and 56 deletions
|
|
@ -1029,7 +1029,7 @@ static struct device *alsa_create_device(struct impl *impl, uint32_t id,
|
|||
{
|
||||
struct device *device;
|
||||
int res;
|
||||
const char *str, *card, *rules;
|
||||
const char *card, *rules;
|
||||
|
||||
pw_log_debug("new device %u", id);
|
||||
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
|
||||
|
|
@ -1059,8 +1059,7 @@ static struct device *alsa_create_device(struct impl *impl, uint32_t id,
|
|||
if ((rules = pw_properties_get(impl->conf, "rules")) != NULL)
|
||||
sm_media_session_match_rules(rules, strlen(rules), device->props);
|
||||
|
||||
str = pw_properties_get(device->props, "api.alsa.use-acp");
|
||||
device->use_acp = str ? pw_properties_parse_bool(str) : true;
|
||||
device->use_acp = pw_properties_get_bool(device->props, "api.alsa.use-acp", true);
|
||||
if (device->use_acp)
|
||||
device->factory_name = strdup(SPA_NAME_API_ALSA_ACP_DEVICE);
|
||||
else
|
||||
|
|
@ -1203,9 +1202,7 @@ int sm_alsa_monitor_start(struct sm_media_session *session)
|
|||
if ((str = pw_properties_get(impl->conf, "properties")) != NULL)
|
||||
pw_properties_update_string(impl->props, str, strlen(str));
|
||||
|
||||
if ((str = pw_properties_get(impl->props, "alsa.reserve")) == NULL ||
|
||||
pw_properties_parse_bool(str))
|
||||
impl->reserve = true;
|
||||
impl->reserve = pw_properties_get_bool(impl->props, "alsa.reserve", true);
|
||||
|
||||
impl->handle = pw_context_load_spa_handle(context, SPA_NAME_API_ALSA_ENUM_UDEV, NULL);
|
||||
if (impl->handle == NULL) {
|
||||
|
|
@ -1222,8 +1219,7 @@ int sm_alsa_monitor_start(struct sm_media_session *session)
|
|||
spa_list_init(&impl->device_list);
|
||||
spa_device_add_listener(impl->monitor, &impl->listener, &alsa_udev_events, impl);
|
||||
|
||||
if ((str = pw_properties_get(impl->props, "alsa.jack-device")) != NULL &&
|
||||
pw_properties_parse_bool(str)) {
|
||||
if (pw_properties_get_bool(impl->props, "alsa.jack-device", true)) {
|
||||
if ((res = alsa_start_jack_device(impl)) < 0)
|
||||
goto out_free;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,18 +134,16 @@ static struct sm_object *find_by_id(struct impl *impl, const char *type, uint32_
|
|||
static struct sm_device *find_default_output_device(struct impl *impl)
|
||||
{
|
||||
struct sm_object *obj;
|
||||
const char *str;
|
||||
uint32_t device_id;
|
||||
|
||||
if ((obj = find_by_name(impl, PW_TYPE_INTERFACE_Node, impl->default_sink)) == NULL ||
|
||||
!obj->props)
|
||||
return NULL;
|
||||
|
||||
if ((str = pw_properties_get(obj->props, PW_KEY_DEVICE_ID)) == NULL)
|
||||
if (pw_properties_fetch_uint32(obj->props, PW_KEY_DEVICE_ID, &device_id) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!spa_atou32(str, &device_id, 10) ||
|
||||
(obj = find_by_id(impl, PW_TYPE_INTERFACE_Device, device_id)) == NULL)
|
||||
if ((obj = find_by_id(impl, PW_TYPE_INTERFACE_Device, device_id)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!spa_streq(obj->type, PW_TYPE_INTERFACE_Device) || !obj->props)
|
||||
|
|
@ -231,7 +229,7 @@ bool get_pending_save(struct impl *impl, const char *dev_name)
|
|||
{
|
||||
char saved_profile_key[512];
|
||||
spa_scnprintf(saved_profile_key, sizeof(saved_profile_key), "%s:pending-save", dev_name);
|
||||
return spa_atob(pw_properties_get(impl->properties, saved_profile_key));
|
||||
return pw_properties_get_bool(impl->properties, saved_profile_key, false);
|
||||
}
|
||||
|
||||
void set_pending_save(struct impl *impl, const char *dev_name, bool pending)
|
||||
|
|
|
|||
|
|
@ -667,16 +667,17 @@ static int node_init(void *object)
|
|||
struct sm_node *node = object;
|
||||
struct impl *impl = SPA_CONTAINER_OF(node->obj.session, struct impl, this);
|
||||
struct pw_properties *props = node->obj.props;
|
||||
const char *str;
|
||||
|
||||
spa_list_init(&node->port_list);
|
||||
spa_list_init(&node->param_list);
|
||||
|
||||
if (props) {
|
||||
if ((str = pw_properties_get(props, PW_KEY_DEVICE_ID)) != NULL)
|
||||
node->device = find_object(impl, atoi(str), NULL);
|
||||
pw_log_debug("%p: node %d parent device %s (%p)", impl,
|
||||
node->obj.id, str, node->device);
|
||||
uint32_t id = SPA_ID_INVALID;
|
||||
|
||||
if (pw_properties_fetch_uint32(props, PW_KEY_DEVICE_ID, &id) == 0)
|
||||
node->device = find_object(impl, id, NULL);
|
||||
pw_log_debug("%p: node %d parent device %d (%p)", impl,
|
||||
node->obj.id, id, node->device);
|
||||
if (node->device) {
|
||||
spa_list_append(&node->device->node_list, &node->link);
|
||||
node->device->obj.avail |= SM_DEVICE_CHANGE_MASK_NODES;
|
||||
|
|
@ -758,6 +759,8 @@ static int port_init(void *object)
|
|||
const char *str;
|
||||
|
||||
if (props) {
|
||||
uint32_t id = SPA_ID_INVALID;
|
||||
|
||||
if ((str = pw_properties_get(props, PW_KEY_PORT_DIRECTION)) != NULL)
|
||||
port->direction = spa_streq(str, "out") ?
|
||||
PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT;
|
||||
|
|
@ -769,8 +772,8 @@ static int port_init(void *object)
|
|||
}
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_CHANNEL)) != NULL)
|
||||
port->channel = find_channel(str);
|
||||
if ((str = pw_properties_get(props, PW_KEY_NODE_ID)) != NULL)
|
||||
port->node = find_object(impl, atoi(str), PW_TYPE_INTERFACE_Node);
|
||||
if (pw_properties_fetch_uint32(props, PW_KEY_NODE_ID, &id) == 0)
|
||||
port->node = find_object(impl, id, PW_TYPE_INTERFACE_Node);
|
||||
|
||||
pw_log_debug("%p: port %d parent node %s (%p) direction:%d type:%d", impl,
|
||||
port->obj.id, str, port->node, port->direction, port->type);
|
||||
|
|
@ -921,13 +924,14 @@ static int endpoint_init(void *object)
|
|||
struct sm_endpoint *endpoint = object;
|
||||
struct impl *impl = SPA_CONTAINER_OF(endpoint->obj.session, struct impl, this);
|
||||
struct pw_properties *props = endpoint->obj.props;
|
||||
const char *str;
|
||||
|
||||
if (props) {
|
||||
if ((str = pw_properties_get(props, PW_KEY_SESSION_ID)) != NULL)
|
||||
endpoint->session = find_object(impl, atoi(str), PW_TYPE_INTERFACE_Session);
|
||||
pw_log_debug("%p: endpoint %d parent session %s", impl,
|
||||
endpoint->obj.id, str);
|
||||
uint32_t id = SPA_ID_INVALID;
|
||||
|
||||
if (pw_properties_fetch_uint32(props, PW_KEY_SESSION_ID, &id) == 0)
|
||||
endpoint->session = find_object(impl, id, PW_TYPE_INTERFACE_Session);
|
||||
pw_log_debug("%p: endpoint %d parent session %d", impl,
|
||||
endpoint->obj.id, id);
|
||||
if (endpoint->session) {
|
||||
spa_list_append(&endpoint->session->endpoint_list, &endpoint->link);
|
||||
endpoint->session->obj.avail |= SM_SESSION_CHANGE_MASK_ENDPOINTS;
|
||||
|
|
@ -1006,13 +1010,14 @@ static int endpoint_stream_init(void *object)
|
|||
struct sm_endpoint_stream *stream = object;
|
||||
struct impl *impl = SPA_CONTAINER_OF(stream->obj.session, struct impl, this);
|
||||
struct pw_properties *props = stream->obj.props;
|
||||
const char *str;
|
||||
|
||||
if (props) {
|
||||
if ((str = pw_properties_get(props, PW_KEY_ENDPOINT_ID)) != NULL)
|
||||
stream->endpoint = find_object(impl, atoi(str), PW_TYPE_INTERFACE_Endpoint);
|
||||
pw_log_debug("%p: stream %d parent endpoint %s", impl,
|
||||
stream->obj.id, str);
|
||||
uint32_t id = SPA_ID_INVALID;
|
||||
|
||||
if (pw_properties_fetch_uint32(props, PW_KEY_ENDPOINT_ID, &id) == 0)
|
||||
stream->endpoint = find_object(impl, id, PW_TYPE_INTERFACE_Endpoint);
|
||||
pw_log_debug("%p: stream %d parent endpoint %d", impl,
|
||||
stream->obj.id, id);
|
||||
if (stream->endpoint) {
|
||||
spa_list_append(&stream->endpoint->stream_list, &stream->link);
|
||||
stream->endpoint->obj.avail |= SM_ENDPOINT_CHANGE_MASK_STREAMS;
|
||||
|
|
@ -2430,8 +2435,7 @@ static const struct {
|
|||
|
||||
static bool is_module_enabled(struct impl *impl, const char *val)
|
||||
{
|
||||
const char *str = pw_properties_get(impl->modules, val);
|
||||
return str ? pw_properties_parse_bool(str) : false;
|
||||
return pw_properties_get_bool(impl->modules, val, false);
|
||||
}
|
||||
|
||||
static void show_help(const char *name, struct impl *impl, const char *config_name)
|
||||
|
|
|
|||
|
|
@ -110,14 +110,13 @@ struct stream {
|
|||
static int
|
||||
handle_endpoint(struct impl *impl, struct sm_object *object)
|
||||
{
|
||||
const char *str, *media_class;
|
||||
const char *media_class;
|
||||
enum pw_direction direction;
|
||||
struct endpoint *ep;
|
||||
uint32_t client_id = SPA_ID_INVALID;
|
||||
|
||||
if (object->props) {
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_CLIENT_ID)) != NULL)
|
||||
client_id = atoi(str);
|
||||
pw_properties_fetch_uint32(object->props, PW_KEY_CLIENT_ID, &client_id);
|
||||
}
|
||||
|
||||
media_class = object->props ? pw_properties_get(object->props, PW_KEY_MEDIA_CLASS) : NULL;
|
||||
|
|
|
|||
|
|
@ -407,14 +407,13 @@ static const struct sm_object_events object_events = {
|
|||
static int
|
||||
handle_node(struct impl *impl, struct sm_object *object)
|
||||
{
|
||||
const char *str, *media_class = NULL, *role;
|
||||
const char *media_class = NULL, *role;
|
||||
enum pw_direction direction;
|
||||
struct node *node;
|
||||
uint32_t client_id = SPA_ID_INVALID;
|
||||
|
||||
if (object->props) {
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_CLIENT_ID)) != NULL)
|
||||
client_id = atoi(str);
|
||||
pw_properties_fetch_uint32(object->props, PW_KEY_CLIENT_ID, &client_id);
|
||||
|
||||
media_class = pw_properties_get(object->props, PW_KEY_MEDIA_CLASS);
|
||||
role = pw_properties_get(object->props, PW_KEY_MEDIA_ROLE);
|
||||
|
|
@ -453,10 +452,8 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
|
||||
if (spa_strstartswith(media_class, "Video")) {
|
||||
if (direction == PW_DIRECTION_OUTPUT) {
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL)
|
||||
node->plugged = pw_properties_parse_uint64(str);
|
||||
else
|
||||
node->plugged = SPA_TIMESPEC_TO_NSEC(&impl->now);
|
||||
node->plugged = pw_properties_get_uint64(object->props, PW_KEY_NODE_PLUGGED,
|
||||
SPA_TIMESPEC_TO_NSEC(&impl->now));
|
||||
}
|
||||
node->active = node->configured = true;
|
||||
}
|
||||
|
|
@ -496,15 +493,9 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
} else
|
||||
return 0;
|
||||
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL)
|
||||
node->plugged = pw_properties_parse_uint64(str);
|
||||
else
|
||||
node->plugged = SPA_TIMESPEC_TO_NSEC(&impl->now);
|
||||
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_PRIORITY_SESSION)) != NULL)
|
||||
node->priority = pw_properties_parse_int(str);
|
||||
else
|
||||
node->priority = 0;
|
||||
node->plugged = pw_properties_get_uint64(object->props, PW_KEY_NODE_PLUGGED,
|
||||
SPA_TIMESPEC_TO_NSEC(&impl->now));
|
||||
node->priority = pw_properties_get_uint32(object->props, PW_KEY_PRIORITY_SESSION, 0);
|
||||
|
||||
node->direction = direction;
|
||||
node->virtual = virtual;
|
||||
|
|
@ -1410,7 +1401,6 @@ static const struct pw_metadata_events metadata_events = {
|
|||
int sm_policy_node_start(struct sm_media_session *session)
|
||||
{
|
||||
struct impl *impl;
|
||||
const char *flag;
|
||||
|
||||
PW_LOG_TOPIC_INIT(mod_topic);
|
||||
|
||||
|
|
@ -1434,10 +1424,9 @@ int sm_policy_node_start(struct sm_media_session *session)
|
|||
};
|
||||
impl->defaults[3] = (struct default_node){ NULL, NULL, NULL, NULL };
|
||||
|
||||
flag = pw_properties_get(session->props, NAME ".streams-follow-default");
|
||||
impl->streams_follow_default = (flag != NULL && pw_properties_parse_bool(flag));
|
||||
flag = pw_properties_get(session->props, NAME ".alsa-no-dsp");
|
||||
impl->alsa_no_dsp = (flag != NULL && pw_properties_parse_bool(flag));
|
||||
|
||||
impl->streams_follow_default = pw_properties_get_bool(session->props, NAME ".streams-follow-default", false);
|
||||
impl->alsa_no_dsp = pw_properties_get_bool(session->props, NAME ".alsa-no-dsp", false);
|
||||
|
||||
spa_list_init(&impl->node_list);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue