diff --git a/.gitignore b/.gitignore index a64c06153..0c2f76c23 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,4 @@ ABOUT-NLS *.tar.xz *.o config.h.meson -pkgconfig/libpinos-*.pc diff --git a/LICENSE b/LICENSE index 113c2c1f9..9a8f9e494 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,3 @@ -All Pinos source files are licensed under the GNU Lesser General Public +All PipeWire source files are licensed under the GNU Lesser General Public License. (see file LGPL for details) diff --git a/Makefile b/Makefile index c27999982..546ab8deb 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,6 @@ clean: ninja-build -C build clean run: - PINOS_MODULE_DIR=build \ - PINOS_CONFIG_FILE=build/pinos/daemon/pinos.conf \ - build/pinos/daemon/pinos + PIPEWIRE_MODULE_DIR=build \ + PIPEWIRE_CONFIG_FILE=build/pipewire/daemon/pipewire.conf \ + build/pipewire/daemon/pipewire diff --git a/NEWS b/NEWS index c965a018a..a25453dd8 100644 --- a/NEWS +++ b/NEWS @@ -1 +1 @@ -Pinos 0.1 +PipeWire 0.1 diff --git a/README b/README index 6dcbbb52f..d133ce93e 100644 --- a/README +++ b/README @@ -1,12 +1,15 @@ -Pinos ------ +PipeWire +-------- -Pinos is a user space API to deal with video. This includes: +PipeWire is a server and user space API to deal with multimedia +pipelines. This includes: - Make availabe sources of video (such as from a capture devices or - application provided streams) + application provided streams) and multiplexing this with + clients. - Accessing sources of video for consumption. + - Generating graphs for audio and video processing -Video providers and consumers are implemented as separate processes -communicating with DBUS and exchanging video frames using fd passing. - +Nodes in the graph can be implemented as separate processes, +communicating with sockets and exchanging multimedia content using fd +passing. diff --git a/autogen.sh b/autogen.sh index 607ef9f55..5becaea53 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,19 +1,19 @@ #!/bin/sh -# This file is part of Pinos +# This file is part of PipeWire # -# Pinos is free software; you can redistribute it and/or modify it +# PipeWire is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -# Pinos is distributed in the hope that it will be useful, but +# PipeWire is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with Pinos; if not, see . +# along with PipeWire; if not, see . # Only there to make jhbuild happy diff --git a/config.h.meson b/config.h.meson index b455cebf6..08b7d55a3 100644 --- a/config.h.meson +++ b/config.h.meson @@ -364,7 +364,7 @@ #mesondefine MODULEDIR /* directory where config files are located */ -#mesondefine PINOS_CONFIG_DIR +#mesondefine PIPEWIRE_CONFIG_DIR /* Define to necessary symbol if this constant uses a non-standard name on your system. */ diff --git a/doc/.gitignore b/doc/.gitignore index 2fcf77a7d..e69de29bb 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1 +0,0 @@ -org-pinos-*.xml diff --git a/doc/design.txt b/doc/design.txt index 5bf477146..6d581069e 100644 --- a/doc/design.txt +++ b/doc/design.txt @@ -1,5 +1,5 @@ -Pinos ------ +PipeWire +-------- The idea is to make a server where you can provide and consume media to/from. diff --git a/man/.gitignore b/man/.gitignore index 8e63953b9..0b321c8ef 100644 --- a/man/.gitignore +++ b/man/.gitignore @@ -1,4 +1,4 @@ -pinos-monitor.1 -pinos-monitor.1.xml -pinos.1 -pinos.1.xml +pipewire-monitor.1 +pipewire-monitor.1.xml +pipewire.1 +pipewire.1.xml diff --git a/man/pinos-monitor.1.xml.in b/man/pipewire-monitor.1.xml.in similarity index 63% rename from man/pinos-monitor.1.xml.in rename to man/pipewire-monitor.1.xml.in index 43e29a4e9..650c8e7a8 100644 --- a/man/pinos-monitor.1.xml.in +++ b/man/pipewire-monitor.1.xml.in @@ -3,30 +3,30 @@ - + - pinos + pipewire -

Monitor objects on the Pinos service.

+

Monitor objects on the PipeWire service.

@@ -46,12 +46,12 @@ License along with Pinos; if not, see .
-

The Pinos Developers <@PACKAGE_BUGREPORT@>; Pinos is available from

+

The PipeWire Developers <@PACKAGE_BUGREPORT@>; PipeWire is available from

- , + ,

diff --git a/man/pinos.1.xml.in b/man/pipewire.1.xml.in similarity index 64% rename from man/pinos.1.xml.in rename to man/pipewire.1.xml.in index 837a8e82d..735e696d8 100644 --- a/man/pinos.1.xml.in +++ b/man/pipewire.1.xml.in @@ -3,30 +3,30 @@ - + - pinos + pipewire -

Pinos is a DBus service that allows access to multimedia devices +

PipeWire is a service that allows access to multimedia devices and allows media sharing between applications.

@@ -47,12 +47,12 @@ License along with Pinos; if not, see .
-

The Pinos Developers <@PACKAGE_BUGREPORT@>; Pinos is available from

+

The PipeWire Developers <@PACKAGE_BUGREPORT@>; PipeWire is available from

- , + ,

diff --git a/man/xmltoman.css b/man/xmltoman.css index a90c08990..aac91028d 100644 --- a/man/xmltoman.css +++ b/man/xmltoman.css @@ -1,18 +1,18 @@ /*** - This file is part of Pinos. + This file is part of PipeWire. - Pinos is free software; you can redistribute it and/or modify it under + PipeWire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - Pinos is distributed in the hope that it will be useful, but WITHOUT + PipeWire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with Pinos; if not, see . + along with PipeWire; if not, see . ***/ body { color: black; background-color: white; } diff --git a/man/xmltoman.dtd b/man/xmltoman.dtd index a8f91e601..ed9784456 100644 --- a/man/xmltoman.dtd +++ b/man/xmltoman.dtd @@ -1,18 +1,18 @@ diff --git a/man/xmltoman.xsl b/man/xmltoman.xsl index 8e49a1441..86ce073b5 100644 --- a/man/xmltoman.xsl +++ b/man/xmltoman.xsl @@ -2,20 +2,20 @@ diff --git a/meson.build b/meson.build index a2e986cd0..8af401740 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('pinos', 'c', +project('pipewire', 'c', version : '0.0.1.1', meson_version : '>= 0.36.0', default_options : [ 'warning_level=1', @@ -6,24 +6,24 @@ project('pinos', 'c', 'buildtype=debugoptimized' ]) -pinos_version = meson.project_version() -version_arr = pinos_version.split('.') -pinos_version_major = version_arr[0] -pinos_version_minor = version_arr[1] -pinos_version_micro = version_arr[2] +pipewire_version = meson.project_version() +version_arr = pipewire_version.split('.') +pipewire_version_major = version_arr[0] +pipewire_version_minor = version_arr[1] +pipewire_version_micro = version_arr[2] if version_arr.length() == 4 - pinos_version_nano = version_arr[3] + pipewire_version_nano = version_arr[3] else - pinos_version_nano = 0 + pipewire_version_nano = 0 endif apiversion = '0.1' soversion = 0 -libversion = '@0@.@1@.0'.format(soversion, pinos_version_minor.to_int() * 100 + pinos_version_micro.to_int()) +libversion = '@0@.@1@.0'.format(soversion, pipewire_version_minor.to_int() * 100 + pipewire_version_micro.to_int()) prefix = get_option('prefix') -modules_install_dir = '@0@/pinos-@1@'.format(get_option('libdir'), apiversion) +modules_install_dir = '@0@/pipewire-@1@'.format(get_option('libdir'), apiversion) gnome = import('gnome') @@ -31,27 +31,27 @@ cc = meson.get_compiler('c') cdata = configuration_data() -cdata.set('PINOS_VERSION_MAJOR', pinos_version_major) -cdata.set('PINOS_VERSION_MINOR', pinos_version_minor) -cdata.set('PINOS_VERSION_MICRO', pinos_version_micro) -cdata.set('PINOS_VERSION_NANO', pinos_version_nano) -cdata.set('PINOS_API_VERSION', '"@0@"'.format(apiversion)) -cdata.set('PINOS_DATADIR', '"@0@/@1@"'.format(prefix, get_option('datadir'))) +cdata.set('PIPEWIRE_VERSION_MAJOR', pipewire_version_major) +cdata.set('PIPEWIRE_VERSION_MINOR', pipewire_version_minor) +cdata.set('PIPEWIRE_VERSION_MICRO', pipewire_version_micro) +cdata.set('PIPEWIRE_VERSION_NANO', pipewire_version_nano) +cdata.set('PIPEWIRE_API_VERSION', '"@0@"'.format(apiversion)) +cdata.set('PIPEWIRE_DATADIR', '"@0@/@1@"'.format(prefix, get_option('datadir'))) cdata.set('LOCALEDIR', '"@0@/@1@"'.format(prefix, get_option('localedir'))) cdata.set('LIBDIR', '"@0@/@1@"'.format(prefix, get_option('libdir'))) -cdata.set('GETTEXT_PACKAGE', '"pinos"') -cdata.set('PINOS_LICENSE', '"LGPL"') -cdata.set('PINOS_PACKAGE_ORIGIN', '"Unknown package origin"') -cdata.set('PINOS_PACKAGE_NAME', '"Pinos source release"') -cdata.set('PACKAGE', '"pinos"') -cdata.set('PACKAGE_NAME', '"Pinos"') -cdata.set('PACKAGE_STRING', '"Pinos @0@"'.format(pinos_version)) -cdata.set('PACKAGE_TARNAME', '"pinos"') +cdata.set('GETTEXT_PACKAGE', '"pipewire"') +cdata.set('PIPEWIRE_LICENSE', '"LGPL"') +cdata.set('PIPEWIRE_PACKAGE_ORIGIN', '"Unknown package origin"') +cdata.set('PIPEWIRE_PACKAGE_NAME', '"PipeWire source release"') +cdata.set('PACKAGE', '"pipewire"') +cdata.set('PACKAGE_NAME', '"PipeWire"') +cdata.set('PACKAGE_STRING', '"PipeWire @0@"'.format(pipewire_version)) +cdata.set('PACKAGE_TARNAME', '"pipewire"') cdata.set('PACKAGE_URL', '""') -cdata.set('PACKAGE_VERSION', '"@0@"'.format(pinos_version)) -cdata.set('MODULEDIR', '"@0@/@1@/pinos-@2@"'.format(get_option('prefix'),get_option('libdir'),apiversion)) -cdata.set('PINOS_CONFIG_DIR', '"@0@/pinos"'.format(join_paths(get_option('prefix'), get_option('sysconfdir')))) -cdata.set('VERSION', '"@0@"'.format(pinos_version)) +cdata.set('PACKAGE_VERSION', '"@0@"'.format(pipewire_version)) +cdata.set('MODULEDIR', '"@0@/@1@/pipewire-@2@"'.format(get_option('prefix'),get_option('libdir'),apiversion)) +cdata.set('PIPEWIRE_CONFIG_DIR', '"@0@/pipewire"'.format(join_paths(get_option('prefix'), get_option('sysconfdir')))) +cdata.set('VERSION', '"@0@"'.format(pipewire_version)) # FIXME: --with-memory-alignment],[8,N,malloc,pagesize (default is 32)]) option cdata.set('MEMORY_ALIGNMENT_MALLOC', 1) @@ -134,7 +134,7 @@ gst_dep = [dependency('gstreamer-1.0'), dependency('gstreamer-allocators-1.0'),] subdir('spa') -subdir('pinos') +subdir('pipewire') subdir('pkgconfig') #gtkdoc = find_program('gtkdoc-scan', required : false) diff --git a/pinos/.gitignore b/pinos/.gitignore deleted file mode 100644 index 5ff803879..000000000 --- a/pinos/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -pinos -test-client -pinos-monitor diff --git a/pinos/client/connection.h b/pinos/client/connection.h deleted file mode 100644 index 316093e51..000000000 --- a/pinos/client/connection.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_CONNECTION_H__ -#define __PINOS_CONNECTION_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct _PinosConnection PinosConnection; - -struct _PinosConnection { - int fd; - - PINOS_SIGNAL (need_flush, (PinosListener *listener, - PinosConnection *conn)); - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosConnection *conn)); -}; - -PinosConnection * pinos_connection_new (int fd); -void pinos_connection_destroy (PinosConnection *conn); - -uint32_t pinos_connection_add_fd (PinosConnection *conn, - int fd); -int pinos_connection_get_fd (PinosConnection *conn, - uint32_t index); - -bool pinos_connection_get_next (PinosConnection *conn, - uint8_t *opcode, - uint32_t *dest_id, - void **data, - uint32_t *size); - -void * pinos_connection_begin_write (PinosConnection *conn, - uint32_t size); -void pinos_connection_end_write (PinosConnection *conn, - uint32_t dest_id, - uint8_t opcode, - uint32_t size); - -bool pinos_connection_flush (PinosConnection *conn); -bool pinos_connection_clear (PinosConnection *conn); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __PINOS_CONNECTION_H__ */ diff --git a/pinos/client/context.c b/pinos/client/context.c deleted file mode 100644 index da8251a23..000000000 --- a/pinos/client/context.c +++ /dev/null @@ -1,877 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include - -#include "pinos/client/pinos.h" - -#include "pinos/client/context.h" -#include "pinos/client/protocol-native.h" -#include "pinos/client/connection.h" -#include "pinos/client/subscribe.h" - -typedef struct { - PinosContext this; - - bool no_proxy; - - int fd; - PinosConnection *connection; - SpaSource *source; - - bool disconnecting; - PinosListener need_flush; - SpaSource *flush_event; -} PinosContextImpl; - -/** - * pinos_context_state_as_string: - * @state: a #PinosContextState - * - * Return the string representation of @state. - * - * Returns: the string representation of @state. - */ -const char * -pinos_context_state_as_string (PinosContextState state) -{ - switch (state) { - case PINOS_CONTEXT_STATE_ERROR: - return "error"; - case PINOS_CONTEXT_STATE_UNCONNECTED: - return "unconnected"; - case PINOS_CONTEXT_STATE_CONNECTING: - return "connecting"; - case PINOS_CONTEXT_STATE_CONNECTED: - return "connected"; - } - return "invalid-state"; -} - -static void -context_set_state (PinosContext *context, - PinosContextState state, - const char *fmt, - ...) -{ - if (context->state != state) { - - if (context->error) - free (context->error); - - if (fmt) { - va_list varargs; - - va_start (varargs, fmt); - vasprintf (&context->error, fmt, varargs); - va_end (varargs); - } else { - context->error = NULL; - } - pinos_log_debug ("context %p: update state from %s -> %s (%s)", context, - pinos_context_state_as_string (context->state), - pinos_context_state_as_string (state), - context->error); - - context->state = state; - pinos_signal_emit (&context->state_changed, context); - } -} - -static void -core_event_info (void *object, - PinosCoreInfo *info) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - PinosSubscriptionEvent event; - - pinos_log_debug ("got core info"); - - if (proxy->user_data == NULL) - event = PINOS_SUBSCRIPTION_EVENT_NEW; - else - event = PINOS_SUBSCRIPTION_EVENT_CHANGE; - - proxy->user_data = pinos_core_info_update (proxy->user_data, info); - - pinos_signal_emit (&this->subscription, - this, - event, - proxy->type, - proxy->id); -} - -static void -core_event_done (void *object, - uint32_t seq) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - - if (seq == 0) { - pinos_core_do_sync (this->core_proxy, 1); - } else if (seq == 1) { - context_set_state (this, PINOS_CONTEXT_STATE_CONNECTED, NULL); - } -} - -static void -core_event_error (void *object, - uint32_t id, - SpaResult res, - const char *error, ...) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - context_set_state (this, PINOS_CONTEXT_STATE_ERROR, error); -} - -static void -core_event_remove_id (void *object, - uint32_t id) -{ - PinosProxy *core_proxy = object; - PinosContext *this = core_proxy->context; - PinosProxy *proxy; - - proxy = pinos_map_lookup (&this->objects, id); - if (proxy) { - pinos_log_debug ("context %p: object remove %u", this, id); - pinos_proxy_destroy (proxy); - } -} - -static void -core_event_update_types (void *object, - uint32_t first_id, - uint32_t n_types, - const char **types) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - int i; - - for (i = 0; i < n_types; i++, first_id++) { - SpaType this_id = spa_type_map_get_id (this->type.map, types[i]); - if (!pinos_map_insert_at (&this->types, first_id, PINOS_MAP_ID_TO_PTR (this_id))) - pinos_log_error ("can't add type for client"); - } -} - -static const PinosCoreEvents core_events = { - &core_event_info, - &core_event_done, - &core_event_error, - &core_event_remove_id, - &core_event_update_types -}; - -static void -module_event_info (void *object, - PinosModuleInfo *info) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - PinosSubscriptionEvent event; - - pinos_log_debug ("got module info"); - - if (proxy->user_data == NULL) - event = PINOS_SUBSCRIPTION_EVENT_NEW; - else - event = PINOS_SUBSCRIPTION_EVENT_CHANGE; - - proxy->user_data = pinos_module_info_update (proxy->user_data, info); - - pinos_signal_emit (&this->subscription, - this, - event, - proxy->type, - proxy->id); -} - -static const PinosModuleEvents module_events = { - &module_event_info, -}; - -static void -node_event_info (void *object, - PinosNodeInfo *info) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - PinosSubscriptionEvent event; - - pinos_log_debug ("got node info"); - - if (proxy->user_data == NULL) - event = PINOS_SUBSCRIPTION_EVENT_NEW; - else - event = PINOS_SUBSCRIPTION_EVENT_CHANGE; - - proxy->user_data = pinos_node_info_update (proxy->user_data, info); - - pinos_signal_emit (&this->subscription, - this, - event, - proxy->type, - proxy->id); -} - -static const PinosNodeEvents node_events = { - &node_event_info -}; - -static void -client_event_info (void *object, - PinosClientInfo *info) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - PinosSubscriptionEvent event; - - pinos_log_debug ("got client info"); - - if (proxy->user_data == NULL) - event = PINOS_SUBSCRIPTION_EVENT_NEW; - else - event = PINOS_SUBSCRIPTION_EVENT_CHANGE; - - proxy->user_data = pinos_client_info_update (proxy->user_data, info); - - pinos_signal_emit (&this->subscription, - this, - event, - proxy->type, - proxy->id); -} - -static const PinosClientEvents client_events = { - &client_event_info -}; - -static void -link_event_info (void *object, - PinosLinkInfo *info) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - PinosSubscriptionEvent event; - - pinos_log_debug ("got link info"); - - if (proxy->user_data == NULL) - event = PINOS_SUBSCRIPTION_EVENT_NEW; - else - event = PINOS_SUBSCRIPTION_EVENT_CHANGE; - - proxy->user_data = pinos_link_info_update (proxy->user_data, info); - - pinos_signal_emit (&this->subscription, - this, - event, - proxy->type, - proxy->id); -} - -static const PinosLinkEvents link_events = { - &link_event_info -}; - -static void -registry_event_global (void *object, - uint32_t id, - const char *type) -{ - PinosProxy *registry_proxy = object; - PinosContext *this = registry_proxy->context; - PinosContextImpl *impl = SPA_CONTAINER_OF (this, PinosContextImpl, this); - PinosProxy *proxy = NULL; - - if (impl->no_proxy) - return; - - pinos_log_debug ("got global %u %s", id, type); - - if (!strcmp (type, PINOS_TYPE__Node)) { - proxy = pinos_proxy_new (this, - SPA_ID_INVALID, - this->type.node); - if (proxy == NULL) - goto no_mem; - - proxy->implementation = &node_events; - } else if (!strcmp (type, PINOS_TYPE__Module)) { - proxy = pinos_proxy_new (this, - SPA_ID_INVALID, - this->type.module); - if (proxy == NULL) - goto no_mem; - - proxy->implementation = &module_events; - } else if (!strcmp (type, PINOS_TYPE__Client)) { - proxy = pinos_proxy_new (this, - SPA_ID_INVALID, - this->type.client); - if (proxy == NULL) - goto no_mem; - - proxy->implementation = &client_events; - } else if (!strcmp (type, PINOS_TYPE__Link)) { - proxy = pinos_proxy_new (this, - SPA_ID_INVALID, - this->type.link); - if (proxy == NULL) - goto no_mem; - - proxy->implementation = &link_events; - } - if (proxy) { - pinos_registry_do_bind (registry_proxy, id, proxy->id); - } - - return; - -no_mem: - pinos_log_error ("context %p: failed to create proxy", this); - return; -} - -static void -registry_event_global_remove (void *object, - uint32_t id) -{ - PinosProxy *proxy = object; - PinosContext *this = proxy->context; - - pinos_log_debug ("got global remove %u", id); - - pinos_signal_emit (&this->subscription, - this, - PINOS_SUBSCRIPTION_EVENT_REMOVE, - SPA_ID_INVALID, - id); -} - -static const PinosRegistryEvents registry_events = { - ®istry_event_global, - ®istry_event_global_remove -}; - -typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size); - -static void -do_flush_event (SpaLoopUtils *utils, - SpaSource *source, - void *data) -{ - PinosContextImpl *impl = data; - if (impl->connection) - if (!pinos_connection_flush (impl->connection)) - pinos_context_disconnect (&impl->this); -} - -static void -on_need_flush (PinosListener *listener, - PinosConnection *connection) -{ - PinosContextImpl *impl = SPA_CONTAINER_OF (listener, PinosContextImpl, need_flush); - PinosContext *this = &impl->this; - pinos_loop_signal_event (this->loop, impl->flush_event); -} - -static void -on_context_data (SpaLoopUtils *utils, - SpaSource *source, - int fd, - SpaIO mask, - void *data) -{ - PinosContextImpl *impl = data; - PinosContext *this = &impl->this; - PinosConnection *conn = impl->connection; - - if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { - context_set_state (this, - PINOS_CONTEXT_STATE_ERROR, - "connection closed"); - return; - } - - if (mask & SPA_IO_IN) { - uint8_t opcode; - uint32_t id; - uint32_t size; - void *message; - - while (!impl->disconnecting - && pinos_connection_get_next (conn, &opcode, &id, &message, &size)) { - PinosProxy *proxy; - const PinosDemarshalFunc *demarshal; - - pinos_log_trace ("context %p: got message %d from %u", this, opcode, id); - - proxy = pinos_map_lookup (&this->objects, id); - if (proxy == NULL) { - pinos_log_error ("context %p: could not find proxy %u", this, id); - continue; - } - if (opcode >= proxy->iface->n_events) { - pinos_log_error ("context %p: invalid method %u for %u", this, opcode, id); - continue; - } - - demarshal = proxy->iface->events; - if (demarshal[opcode]) { - if (!demarshal[opcode] (proxy, message, size)) - pinos_log_error ("context %p: invalid message received %u for %u", this, opcode, id); - } else - pinos_log_error ("context %p: function %d not implemented on %u", this, opcode, id); - - } - } -} - -/** - * pinos_context_new: - * @context: a #GMainContext to run in - * @name: an application name - * @properties: (transfer full): optional properties - * - * Make a new unconnected #PinosContext - * - * Returns: a new unconnected #PinosContext - */ -PinosContext * -pinos_context_new (PinosLoop *loop, - const char *name, - PinosProperties *properties) -{ - PinosContextImpl *impl; - PinosContext *this; - - impl = calloc (1, sizeof (PinosContextImpl)); - if (impl == NULL) - return NULL; - - impl->fd = -1; - - this = &impl->this; - pinos_log_debug ("context %p: new", impl); - - this->name = strdup (name); - - if (properties == NULL) - properties = pinos_properties_new ("application.name", name, NULL); - if (properties == NULL) - goto no_mem; - - pinos_fill_context_properties (properties); - this->properties = properties; - - pinos_type_init (&this->type); - - this->loop = loop; - - impl->flush_event = pinos_loop_add_event (loop, do_flush_event, impl); - - this->state = PINOS_CONTEXT_STATE_UNCONNECTED; - - pinos_map_init (&this->objects, 64, 32); - pinos_map_init (&this->types, 64, 32); - - spa_list_init (&this->stream_list); - spa_list_init (&this->global_list); - spa_list_init (&this->proxy_list); - - pinos_signal_init (&this->state_changed); - pinos_signal_init (&this->subscription); - pinos_signal_init (&this->destroy_signal); - - return this; - -no_mem: - free (this->name); - free (impl); - return NULL; -} - -void -pinos_context_destroy (PinosContext *context) -{ - PinosContextImpl *impl = SPA_CONTAINER_OF (context, PinosContextImpl, this); - PinosStream *stream, *t1; - PinosProxy *proxy, *t2; - - pinos_log_debug ("context %p: destroy", context); - pinos_signal_emit (&context->destroy_signal, context); - - pinos_loop_destroy_source (impl->this.loop, impl->flush_event); - - if (context->state != PINOS_CONTEXT_STATE_UNCONNECTED) - pinos_context_disconnect (context); - - spa_list_for_each_safe (stream, t1, &context->stream_list, link) - pinos_stream_destroy (stream); - spa_list_for_each_safe (proxy, t2, &context->proxy_list, link) - pinos_proxy_destroy (proxy); - - pinos_map_clear (&context->objects); - - free (context->name); - if (context->properties) - pinos_properties_free (context->properties); - free (context->error); - free (impl); -} - -/** - * pinos_context_connect: - * @context: a #PinosContext - * - * Connect to the daemon - * - * Returns: %TRUE on success. - */ -bool -pinos_context_connect (PinosContext *context, - PinosContextFlags flags) -{ - struct sockaddr_un addr; - socklen_t size; - const char *runtime_dir, *name = NULL; - int name_size, fd; - - if ((runtime_dir = getenv ("XDG_RUNTIME_DIR")) == NULL) { - context_set_state (context, - PINOS_CONTEXT_STATE_ERROR, - "connect failed: XDG_RUNTIME_DIR not set in the environment"); - return false; - } - - if (name == NULL) - name = getenv("PINOS_CORE"); - if (name == NULL) - name = "pinos-0"; - - if ((fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) - return false; - - memset (&addr, 0, sizeof (addr)); - addr.sun_family = AF_LOCAL; - name_size = snprintf (addr.sun_path, sizeof (addr.sun_path), - "%s/%s", runtime_dir, name) + 1; - - if (name_size > (int)sizeof addr.sun_path) { - pinos_log_error ("socket path \"%s/%s\" plus null terminator exceeds 108 bytes", - runtime_dir, name); - goto error_close; - }; - - size = offsetof (struct sockaddr_un, sun_path) + name_size; - - if (connect (fd, (struct sockaddr *) &addr, size) < 0) { - context_set_state (context, - PINOS_CONTEXT_STATE_ERROR, - "connect failed: %s", strerror (errno)); - goto error_close; - } - - return pinos_context_connect_fd (context, flags, fd); - -error_close: - close (fd); - return false; -} - -/** - * pinos_context_connect_fd: - * @context: a #PinosContext - * @fd: FD of a connected Pinos socket - * - * Connect to a daemon. @fd should already be connected to a Pinos socket. - * - * Returns: %TRUE on success. - */ -bool -pinos_context_connect_fd (PinosContext *context, - PinosContextFlags flags, - int fd) -{ - PinosContextImpl *impl = SPA_CONTAINER_OF (context, PinosContextImpl, this); - - context_set_state (context, PINOS_CONTEXT_STATE_CONNECTING, NULL); - - impl->connection = pinos_connection_new (fd); - if (impl->connection == NULL) - goto error_close; - - context->protocol_private = impl->connection; - - pinos_signal_add (&impl->connection->need_flush, - &impl->need_flush, - on_need_flush); - - impl->fd = fd; - - impl->source = pinos_loop_add_io (context->loop, - fd, - SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR, - false, - on_context_data, - impl); - - context->core_proxy = pinos_proxy_new (context, - 0, - context->type.core); - if (context->core_proxy == NULL) - goto no_proxy; - - context->core_proxy->implementation = &core_events; - - pinos_core_do_client_update (context->core_proxy, - &context->properties->dict); - - if (!(flags & PINOS_CONTEXT_FLAG_NO_REGISTRY)) { - context->registry_proxy = pinos_proxy_new (context, - SPA_ID_INVALID, - context->type.registry); - if (context->registry_proxy == NULL) - goto no_registry; - - context->registry_proxy->implementation = ®istry_events; - - pinos_core_do_get_registry (context->core_proxy, - context->registry_proxy->id); - - } - impl->no_proxy = !!(flags & PINOS_CONTEXT_FLAG_NO_PROXY); - - pinos_core_do_sync (context->core_proxy, 0); - - return true; - -no_registry: - pinos_proxy_destroy (context->core_proxy); -no_proxy: - pinos_loop_destroy_source (context->loop, impl->source); - pinos_connection_destroy (impl->connection); -error_close: - close (fd); - return false; -} - -/** - * pinos_context_disconnect: - * @context: a #PinosContext - * - * Disonnect from the daemon. - * - * Returns: %TRUE on success. - */ -bool -pinos_context_disconnect (PinosContext *context) -{ - PinosContextImpl *impl = SPA_CONTAINER_OF (context, PinosContextImpl, this); - - impl->disconnecting = true; - - if (impl->source) - pinos_loop_destroy_source (context->loop, impl->source); - impl->source = NULL; - - if (context->registry_proxy) - pinos_proxy_destroy (context->registry_proxy); - context->registry_proxy = NULL; - - if (context->core_proxy) - pinos_proxy_destroy (context->core_proxy); - context->core_proxy = NULL; - - if (impl->connection) - pinos_connection_destroy (impl->connection); - impl->connection = NULL; - context->protocol_private = NULL; - - if (impl->fd != -1) - close (impl->fd); - impl->fd = -1; - - context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED, NULL); - - return true; -} - -void -pinos_context_get_core_info (PinosContext *context, - PinosCoreInfoCallback cb, - void *user_data) -{ - PinosProxy *proxy; - - proxy = pinos_map_lookup (&context->objects, 0); - if (proxy == NULL) { - cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); - } else if (proxy->type == context->type.core && proxy->user_data) { - PinosCoreInfo *info = proxy->user_data; - cb (context, SPA_RESULT_OK, info, user_data); - info->change_mask = 0; - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} - -typedef void (*ListFunc) (PinosContext *, SpaResult, void *, void *); - -static void -do_list (PinosContext *context, - uint32_t type, - ListFunc cb, - void *user_data) -{ - PinosMapItem *item; - - pinos_array_for_each (item, &context->objects.items) { - PinosProxy *proxy; - - if (pinos_map_item_is_free (item)) - continue; - - proxy = item->data; - if (proxy->type != type) - continue; - - if (proxy->user_data) - cb (context, SPA_RESULT_OK, proxy->user_data, user_data); - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} - - -void -pinos_context_list_module_info (PinosContext *context, - PinosModuleInfoCallback cb, - void *user_data) -{ - do_list (context, context->type.module, (ListFunc) cb, user_data); -} - -void -pinos_context_get_module_info_by_id (PinosContext *context, - uint32_t id, - PinosModuleInfoCallback cb, - void *user_data) -{ - PinosProxy *proxy; - - proxy = pinos_map_lookup (&context->objects, id); - if (proxy == NULL) { - cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); - } else if (proxy->type == context->type.module && proxy->user_data) { - PinosModuleInfo *info = proxy->user_data; - cb (context, SPA_RESULT_OK, info, user_data); - info->change_mask = 0; - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} - -void -pinos_context_list_client_info (PinosContext *context, - PinosClientInfoCallback cb, - void *user_data) -{ - do_list (context, context->type.client, (ListFunc) cb, user_data); -} - -void -pinos_context_get_client_info_by_id (PinosContext *context, - uint32_t id, - PinosClientInfoCallback cb, - void *user_data) -{ - PinosProxy *proxy; - - proxy = pinos_map_lookup (&context->objects, id); - if (proxy == NULL) { - cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); - } else if (proxy->type == context->type.client && proxy->user_data) { - PinosClientInfo *info = proxy->user_data; - cb (context, SPA_RESULT_OK, info, user_data); - info->change_mask = 0; - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} - -void -pinos_context_list_node_info (PinosContext *context, - PinosNodeInfoCallback cb, - void *user_data) -{ - do_list (context, context->type.node, (ListFunc) cb, user_data); -} - -void -pinos_context_get_node_info_by_id (PinosContext *context, - uint32_t id, - PinosNodeInfoCallback cb, - void *user_data) -{ - PinosProxy *proxy; - - proxy = pinos_map_lookup (&context->objects, id); - if (proxy == NULL) { - cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); - } else if (proxy->type == context->type.node && proxy->user_data) { - PinosNodeInfo *info = proxy->user_data; - cb (context, SPA_RESULT_OK, info, user_data); - info->change_mask = 0; - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} - -void -pinos_context_list_link_info (PinosContext *context, - PinosLinkInfoCallback cb, - void *user_data) -{ - do_list (context, context->type.link, (ListFunc) cb, user_data); -} - -void -pinos_context_get_link_info_by_id (PinosContext *context, - uint32_t id, - PinosLinkInfoCallback cb, - void *user_data) -{ - PinosProxy *proxy; - - proxy = pinos_map_lookup (&context->objects, id); - if (proxy == NULL) { - cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); - } else if (proxy->type == context->type.link && proxy->user_data) { - PinosLinkInfo *info = proxy->user_data; - cb (context, SPA_RESULT_OK, info, user_data); - info->change_mask = 0; - } - cb (context, SPA_RESULT_ENUM_END, NULL, user_data); -} diff --git a/pinos/client/context.h b/pinos/client/context.h deleted file mode 100644 index 1b370fc97..000000000 --- a/pinos/client/context.h +++ /dev/null @@ -1,117 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_CONTEXT_H__ -#define __PINOS_CONTEXT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosContext PinosContext; - -#include -#include -#include -#include -#include -#include - -/** - * PinosContextState: - * @PINOS_CONTEXT_STATE_ERROR: context is in error - * @PINOS_CONTEXT_STATE_UNCONNECTED: not connected - * @PINOS_CONTEXT_STATE_CONNECTING: connecting to daemon - * @PINOS_CONTEXT_STATE_CONNECTED: context is connected and ready - * - * The state of a #PinosContext - */ -typedef enum { - PINOS_CONTEXT_STATE_ERROR = -1, - PINOS_CONTEXT_STATE_UNCONNECTED = 0, - PINOS_CONTEXT_STATE_CONNECTING = 1, - PINOS_CONTEXT_STATE_CONNECTED = 2, -} PinosContextState; - -typedef enum { - PINOS_CONTEXT_FLAG_NONE = 0, - PINOS_CONTEXT_FLAG_NO_REGISTRY = (1 << 0), - PINOS_CONTEXT_FLAG_NO_PROXY = (1 << 1), -} PinosContextFlags; - -const char * pinos_context_state_as_string (PinosContextState state); - -/** - * PinosContext: - * - * Pinos context object class. - */ -struct _PinosContext { - char *name; - PinosProperties *properties; - - PinosType type; - - PinosLoop *loop; - - PinosProxy *core_proxy; - PinosProxy *registry_proxy; - - PinosMap objects; - uint32_t n_types; - PinosMap types; - - SpaList global_list; - SpaList stream_list; - SpaList proxy_list; - - void *protocol_private; - - PinosContextState state; - char *error; - PINOS_SIGNAL (state_changed, (PinosListener *listener, - PinosContext *context)); - - PINOS_SIGNAL (subscription, (PinosListener *listener, - PinosContext *context, - PinosSubscriptionEvent event, - uint32_t type, - uint32_t id)); - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosContext *context)); -}; - -PinosContext * pinos_context_new (PinosLoop *loop, - const char *name, - PinosProperties *properties); -void pinos_context_destroy (PinosContext *context); - -bool pinos_context_connect (PinosContext *context, - PinosContextFlags flags); -bool pinos_context_connect_fd (PinosContext *context, - PinosContextFlags flags, - int fd); -bool pinos_context_disconnect (PinosContext *context); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_CONTEXT_H__ */ diff --git a/pinos/client/introspect.h b/pinos/client/introspect.h deleted file mode 100644 index 8bb88a012..000000000 --- a/pinos/client/introspect.h +++ /dev/null @@ -1,348 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_INTROSPECT_H__ -#define __PINOS_INTROSPECT_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum _PinosNodeState PinosNodeState; -typedef enum _PinosDirection PinosDirection; -typedef enum _PinosLinkState PinosLinkState; - -typedef struct _PinosCoreInfo PinosCoreInfo; -typedef struct _PinosModuleInfo PinosModuleInfo; -typedef struct _PinosClientInfo PinosClientInfo; -typedef struct _PinosNodeInfo PinosNodeInfo; -typedef struct _PinosLinkInfo PinosLinkInfo; - -#include -#include - -/** - * PinosNodeState: - * @PINOS_NODE_STATE_ERROR: the node is in error - * @PINOS_NODE_STATE_CREATING: the node is being created - * @PINOS_NODE_STATE_SUSPENDED: the node is suspended, the device might - * be closed - * @PINOS_NODE_STATE_IDLE: the node is running but there is no active - * port - * @PINOS_NODE_STATE_RUNNING: the node is running - * - * The different node states - */ -enum _PinosNodeState { - PINOS_NODE_STATE_ERROR = -1, - PINOS_NODE_STATE_CREATING = 0, - PINOS_NODE_STATE_SUSPENDED = 1, - PINOS_NODE_STATE_IDLE = 2, - PINOS_NODE_STATE_RUNNING = 3, -}; - -const char * pinos_node_state_as_string (PinosNodeState state); - -/** - * PinosDirection: - * @PINOS_DIRECTION_INVALID: invalid direction - * @PINOS_DIRECTION_INPUT: an input port - * @PINOS_DIRECTION_OUTPUT: an output port - * - * The direction of a port - */ -enum _PinosDirection { - PINOS_DIRECTION_INPUT = SPA_DIRECTION_INPUT, - PINOS_DIRECTION_OUTPUT = SPA_DIRECTION_OUTPUT -}; - -const char * pinos_direction_as_string (PinosDirection direction); - -/** - * PinosLinkState: - * @PINOS_LINK_STATE_ERROR: the link is in error - * @PINOS_LINK_STATE_UNLINKED: the link is unlinked - * @PINOS_LINK_STATE_INIT: the link is initialized - * @PINOS_LINK_STATE_NEGOTIATING: the link is negotiating formats - * @PINOS_LINK_STATE_ALLOCATING: the link is allocating buffers - * @PINOS_LINK_STATE_PAUSED: the link is paused - * @PINOS_LINK_STATE_RUNNING: the link is running - * - * The different link states - */ -enum _PinosLinkState { - PINOS_LINK_STATE_ERROR = -2, - PINOS_LINK_STATE_UNLINKED = -1, - PINOS_LINK_STATE_INIT = 0, - PINOS_LINK_STATE_NEGOTIATING = 1, - PINOS_LINK_STATE_ALLOCATING = 2, - PINOS_LINK_STATE_PAUSED = 3, - PINOS_LINK_STATE_RUNNING = 4, -}; - -const char * pinos_link_state_as_string (PinosLinkState state); - -/** - * PinosCoreInfo: - * @id: generic id of the core - * @change_mask: bitfield of changed fields since last call - * @user_name: name of the user that started the core - * @host_name: name of the machine the core is running on - * @version: version of the core - * @name: name of the core - * @cookie: a random cookie for identifying this instance of Pinos - * @props: extra properties - * - * The core information. Extra information can be added in later - * versions. - */ -struct _PinosCoreInfo { - uint32_t id; - uint64_t change_mask; -#define PINOS_CORE_CHANGE_MASK_USER_NAME (1 << 0) -#define PINOS_CORE_CHANGE_MASK_HOST_NAME (1 << 1) -#define PINOS_CORE_CHANGE_MASK_VERSION (1 << 2) -#define PINOS_CORE_CHANGE_MASK_NAME (1 << 3) -#define PINOS_CORE_CHANGE_MASK_COOKIE (1 << 4) -#define PINOS_CORE_CHANGE_MASK_PROPS (1 << 5) -#define PINOS_CORE_CHANGE_MASK_ALL (~0) - const char *user_name; - const char *host_name; - const char *version; - const char *name; - uint32_t cookie; - SpaDict *props; -}; - -PinosCoreInfo * pinos_core_info_update (PinosCoreInfo *info, - const PinosCoreInfo *update); -void pinos_core_info_free (PinosCoreInfo *info); - -/** - * PinosCoreInfoCallback: - * @c: a #PinosContext - * @info: a #PinosCoreInfo - * @user_data: user data - * - * Callback with information about the Pinos core in @info. - */ -typedef void (*PinosCoreInfoCallback) (PinosContext *c, - SpaResult res, - const PinosCoreInfo *info, - void *user_data); - -void pinos_context_get_core_info (PinosContext *context, - PinosCoreInfoCallback cb, - void *user_data); - -/** - * PinosModuleInfo: - * @id: generic id of the module - * @change_mask: bitfield of changed fields since last call - * @props: extra properties - * - * The module information. Extra information can be added in later - * versions. - */ -struct _PinosModuleInfo { - uint32_t id; - uint64_t change_mask; - const char *name; - const char *filename; - const char *args; - SpaDict *props; -}; - -PinosModuleInfo * pinos_module_info_update (PinosModuleInfo *info, - const PinosModuleInfo *update); -void pinos_module_info_free (PinosModuleInfo *info); - - -/** - * PinosModuleInfoCallback: - * @c: a #PinosContext - * @info: a #PinosModuleInfo - * @user_data: user data - * - * Callback with information about the Pinos module in @info. - */ -typedef void (*PinosModuleInfoCallback) (PinosContext *c, - SpaResult res, - const PinosModuleInfo *info, - void *user_data); - -void pinos_context_list_module_info (PinosContext *context, - PinosModuleInfoCallback cb, - void *user_data); -void pinos_context_get_module_info_by_id (PinosContext *context, - uint32_t id, - PinosModuleInfoCallback cb, - void *user_data); - -/** - * PinosClientInfo: - * @id: generic id of the client - * @change_mask: bitfield of changed fields since last call - * @props: extra properties - * - * The client information. Extra information can be added in later - * versions. - */ -struct _PinosClientInfo { - uint32_t id; - uint64_t change_mask; - SpaDict *props; -}; - -PinosClientInfo * pinos_client_info_update (PinosClientInfo *info, - const PinosClientInfo *update); -void pinos_client_info_free (PinosClientInfo *info); - - -/** - * PinosClientInfoCallback: - * @c: a #PinosContext - * @info: a #PinosClientInfo - * @user_data: user data - * - * Callback with information about the Pinos client in @info. - */ -typedef void (*PinosClientInfoCallback) (PinosContext *c, - SpaResult res, - const PinosClientInfo *info, - void *user_data); - -void pinos_context_list_client_info (PinosContext *context, - PinosClientInfoCallback cb, - void *user_data); -void pinos_context_get_client_info_by_id (PinosContext *context, - uint32_t id, - PinosClientInfoCallback cb, - void *user_data); - -/** - * PinosNodeInfo: - * @id: generic id of the node - * @change_mask: bitfield of changed fields since last call - * @name: name the node, suitable for display - * @state: the current state of the node - * @error: an error reason if @state is error - * @props: the properties of the node - * - * The node information. Extra information can be added in later - * versions. - */ -struct _PinosNodeInfo { - uint32_t id; - uint64_t change_mask; - const char *name; - uint32_t max_inputs; - uint32_t n_inputs; - uint32_t n_input_formats; - SpaFormat **input_formats; - uint32_t max_outputs; - uint32_t n_outputs; - uint32_t n_output_formats; - SpaFormat **output_formats; - PinosNodeState state; - const char *error; - SpaDict *props; -}; - -PinosNodeInfo * pinos_node_info_update (PinosNodeInfo *info, - const PinosNodeInfo *update); -void pinos_node_info_free (PinosNodeInfo *info); - -/** - * PinosNodeInfoCallback: - * @c: a #PinosContext - * @info: a #PinosNodeInfo - * @user_data: user data - * - * Callback with information about the Pinos node in @info. - */ -typedef void (*PinosNodeInfoCallback) (PinosContext *c, - SpaResult res, - const PinosNodeInfo *info, - void *user_data); - -void pinos_context_list_node_info (PinosContext *context, - PinosNodeInfoCallback cb, - void *user_data); -void pinos_context_get_node_info_by_id (PinosContext *context, - uint32_t id, - PinosNodeInfoCallback cb, - void *user_data); - - -/** - * PinosLinkInfo: - * @id: generic id of the link - * @change_mask: bitfield of changed fields since last call - * @output_node_path: the output node - * @output_port: the output port - * @input_node_path: the input node - * @input_port: the input port - * - * The link information. Extra information can be added in later - * versions. - */ -struct _PinosLinkInfo { - uint32_t id; - uint64_t change_mask; - uint32_t output_node_id; - uint32_t output_port_id; - uint32_t input_node_id; - uint32_t input_port_id; -}; - -PinosLinkInfo * pinos_link_info_update (PinosLinkInfo *info, - const PinosLinkInfo *update); -void pinos_link_info_free (PinosLinkInfo *info); - - -/** - * PinosLinkInfoCallback: - * @c: a #PinosContext - * @info: a #PinosLinkInfo - * @user_data: user data - * - * Callback with information about the Pinos link in @info. - */ -typedef void (*PinosLinkInfoCallback) (PinosContext *c, - SpaResult res, - const PinosLinkInfo *info, - void *user_data); - -void pinos_context_list_link_info (PinosContext *context, - PinosLinkInfoCallback cb, - void *user_data); -void pinos_context_get_link_info_by_id (PinosContext *context, - uint32_t id, - PinosLinkInfoCallback cb, - void *user_data); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_INTROSPECT_H__ */ diff --git a/pinos/client/log.h b/pinos/client/log.h deleted file mode 100644 index bea851d9b..000000000 --- a/pinos/client/log.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_LOG_H__ -#define __PINOS_LOG_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern SpaLogLevel pinos_log_level; - -SpaLog * pinos_log_get (void); - -void pinos_log_set_level (SpaLogLevel level); -void pinos_log_set_trace_event (SpaSource *source); - - -void pinos_log_log (SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, ...) SPA_PRINTF_FUNC(5, 6); -void pinos_log_logv (SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, - va_list args) SPA_PRINTF_FUNC(5, 0); - -#define pinos_log_level_enabled(lev) (pinos_log_level >= (lev)) - -#if __STDC_VERSION__ >= 199901L - -#define pinos_log_logc(lev,...) \ - if (SPA_UNLIKELY (pinos_log_level_enabled (lev))) \ - pinos_log_log(lev,__VA_ARGS__) - -#define pinos_log_error(...) pinos_log_logc(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__) -#define pinos_log_warn(...) pinos_log_logc(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__) -#define pinos_log_info(...) pinos_log_logc(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__) -#define pinos_log_debug(...) pinos_log_logc(SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__) -#define pinos_log_trace(...) pinos_log_logc(SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__) - -#else - -#include - -#define PINOS_LOG_FUNC(name,lev) \ -static inline void pinos_log_##name (const char *format, ...) \ -{ \ - if (SPA_UNLIKELY (pinos_log_level_enabled (lev))) { \ - va_list varargs; \ - va_start (varargs, format); \ - pinos_log_logv (lev,__FILE__,__LINE__,__func__,format,varargs); \ - va_end (varargs); \ - } \ -} -PINOS_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR) -PINOS_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN) -PINOS_LOG_FUNC(info, SPA_LOG_LEVEL_INFO) -PINOS_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG) -PINOS_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE) - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_LOG_H__ */ diff --git a/pinos/client/loop.h b/pinos/client/loop.h deleted file mode 100644 index 21428f162..000000000 --- a/pinos/client/loop.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_LOOP_H__ -#define __PINOS_LOOP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -typedef struct _PinosLoop PinosLoop; - -/** - * PinosLoop: - * - * Pinos loop interface. - */ -struct _PinosLoop { - SpaLoop *loop; - SpaLoopControl *control; - SpaLoopUtils *utils; - - PINOS_SIGNAL (before_iterate, (PinosListener *listener, - PinosLoop *loop)); - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosLoop *loop)); -}; - -PinosLoop * pinos_loop_new (void); -void pinos_loop_destroy (PinosLoop *loop); - -#define pinos_loop_add_source(l,...) spa_loop_add_source((l)->loop,__VA_ARGS__) -#define pinos_loop_update_source(l,...) spa_loop_update_source(__VA_ARGS__) -#define pinos_loop_remove_source(l,...) spa_loop_remove_source(__VA_ARGS__) -#define pinos_loop_invoke(l,...) spa_loop_invoke((l)->loop,__VA_ARGS__) - -#define pinos_loop_get_fd(l) spa_loop_control_get_fd((l)->control) -#define pinos_loop_set_hooks(l,...) spa_loop_control_set_hooks((l)->control,__VA_ARGS__) -#define pinos_loop_enter(l) spa_loop_control_enter((l)->control) -#define pinos_loop_iterate(l,...) spa_loop_control_iterate((l)->control,__VA_ARGS__) -#define pinos_loop_leave(l) spa_loop_control_leave((l)->control) - -#define pinos_loop_add_io(l,...) spa_loop_utils_add_io((l)->utils,__VA_ARGS__) -#define pinos_loop_update_io(l,...) spa_loop_utils_update_io((l)->utils,__VA_ARGS__) -#define pinos_loop_add_idle(l,...) spa_loop_utils_add_idle((l)->utils,__VA_ARGS__) -#define pinos_loop_enable_idle(l,...) spa_loop_utils_enable_idle((l)->utils,__VA_ARGS__) -#define pinos_loop_add_event(l,...) spa_loop_utils_add_event((l)->utils,__VA_ARGS__) -#define pinos_loop_signal_event(l,...) spa_loop_utils_signal_event((l)->utils,__VA_ARGS__) -#define pinos_loop_add_timer(l,...) spa_loop_utils_add_timer((l)->utils,__VA_ARGS__) -#define pinos_loop_update_timer(l,...) spa_loop_utils_update_timer((l)->utils,__VA_ARGS__) -#define pinos_loop_add_signal(l,...) spa_loop_utils_add_signal((l)->utils,__VA_ARGS__) -#define pinos_loop_destroy_source(l,...) spa_loop_utils_destroy_source((l)->utils,__VA_ARGS__) - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_LOOP_H__ */ diff --git a/pinos/client/map.h b/pinos/client/map.h deleted file mode 100644 index 6533ba785..000000000 --- a/pinos/client/map.h +++ /dev/null @@ -1,153 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_MAP_H__ -#define __PINOS_MAP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosMap PinosMap; - -#include -#include - -#include -#include -#include - -typedef union { - uint32_t next; - void *data; -} PinosMapItem; - -struct _PinosMap { - PinosArray items; - uint32_t free_list; -}; - -#define PINOS_MAP_INIT(extend) { PINOS_ARRAY_INIT(extend), 0 } - -#define pinos_map_get_size(m) pinos_array_get_len (&(m)->items, PinosMapItem) -#define pinos_map_get_item(m,id) pinos_array_get_unchecked(&(m)->items,id,PinosMapItem) -#define pinos_map_item_is_free(item) ((item)->next & 0x1) -#define pinos_map_id_is_free(m,id) (pinos_map_item_is_free (pinos_map_get_item(m,id))) -#define pinos_map_check_id(m,id) ((id) < pinos_map_get_size (m)) -#define pinos_map_has_item(m,id) (pinos_map_check_id(m,id) && !pinos_map_id_is_free(m, id)) -#define pinos_map_lookup_unchecked(m,id) pinos_map_get_item(m,id)->data - -#define PINOS_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1)) -#define PINOS_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1) - -static inline void -pinos_map_init (PinosMap *map, - size_t size, - size_t extend) -{ - pinos_array_init (&map->items, extend); - pinos_array_ensure_size (&map->items, size * sizeof (PinosMapItem)); - map->free_list = 0; -} - -static inline void -pinos_map_clear (PinosMap *map) -{ - pinos_array_clear (&map->items); -} - -static inline uint32_t -pinos_map_insert_new (PinosMap *map, - void *data) -{ - PinosMapItem *start, *item; - uint32_t id; - - if (map->free_list) { - start = map->items.data; - item = &start[map->free_list >> 1]; - map->free_list = item->next; - } else { - item = pinos_array_add (&map->items, sizeof (PinosMapItem)); - if (!item) - return SPA_ID_INVALID; - start = map->items.data; - } - item->data = data; - id = (item - start); - return id; -} - -static inline bool -pinos_map_insert_at (PinosMap *map, - uint32_t id, - void *data) -{ - size_t size = pinos_map_get_size (map); - PinosMapItem *item; - - if (id > size) - return false; - else if (id == size) - item = pinos_array_add (&map->items, sizeof (PinosMapItem)); - else - item = pinos_map_get_item (map, id); - - item->data = data; - return true; -} - -static inline void -pinos_map_remove (PinosMap *map, - uint32_t id) -{ - pinos_map_get_item (map, id)->next = map->free_list; - map->free_list = (id << 1) | 1; -} - -static inline void * -pinos_map_lookup (PinosMap *map, - uint32_t id) -{ - if (SPA_LIKELY (pinos_map_check_id (map, id))) { - PinosMapItem *item = pinos_map_get_item (map, id); - if (!pinos_map_item_is_free (item)) - return item->data; - } - return NULL; -} - -static inline void -pinos_map_for_each (PinosMap *map, - void (*func) (void *, void *), - void *data) -{ - PinosMapItem *item; - - pinos_array_for_each (item, &map->items) { - if (item->data && !pinos_map_item_is_free (item)) - func (item->data, data); - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __PINOS_MAP_H__ */ diff --git a/pinos/client/pinos.c b/pinos/client/pinos.c deleted file mode 100644 index 76f7a0482..000000000 --- a/pinos/client/pinos.c +++ /dev/null @@ -1,157 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include "pinos/client/pinos.h" - -/** - * pinos_init: - * @argc: pointer to argc - * @argv: pointer to argv - * - * initialize the pinos system, parse and modify any parameters given - * by @argc and @argv. - */ -void -pinos_init (int *argc, char **argv[]) -{ - const char *str; - - if ((str = getenv ("PINOS_DEBUG"))) - pinos_log_set_level (atoi (str)); -} - -const char * -pinos_get_application_name (void) -{ - return NULL; -} - -const char * -pinos_get_prgname (void) -{ - static char tcomm[16+1]; - spa_zero(tcomm); - - if (prctl (PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0) - return tcomm; - - return NULL; -} - -const char * -pinos_get_user_name (void) -{ - struct passwd *pw; - - if ((pw = getpwuid (getuid ()))) - return pw->pw_name; - - return NULL; -} - -const char * -pinos_get_host_name (void) -{ - static char hname[256]; - - if (gethostname (hname, 256) < 0) - return NULL; - - hname[255] = 0; - return hname; -} - -/** - * pinos_client_name: - * - * Make a new pinos client name that can be used to construct a context. - */ -char * -pinos_client_name (void) -{ - char *c; - const char *cc; - - if ((cc = pinos_get_application_name ())) - return strdup (cc); - else if ((cc = pinos_get_prgname ())) - return strdup (cc); - else { - asprintf (&c, "pinos-pid-%zd", (size_t) getpid ()); - return c; - } -} - -/** - * pinos_fill_context_properties: - * @properties: a #PinosProperties - * - * Fill @properties with a set of default context properties. - */ -void -pinos_fill_context_properties (PinosProperties *properties) -{ - if (!pinos_properties_get (properties, "application.name")) - pinos_properties_set (properties, "application.name", pinos_get_application_name ()); - - if (!pinos_properties_get (properties, "application.prgname")) - pinos_properties_set (properties, "application.prgname", pinos_get_prgname ()); - - if (!pinos_properties_get (properties, "application.language")) { - pinos_properties_set (properties, "application.language", getenv ("LANG")); - } - if (!pinos_properties_get (properties, "application.process.id")) { - pinos_properties_setf (properties, "application.process.id", "%zd", (size_t) getpid ()); - } - if (!pinos_properties_get (properties, "application.process.user")) - pinos_properties_set (properties, "application.process.user", pinos_get_user_name ()); - - if (!pinos_properties_get (properties, "application.process.host")) - pinos_properties_set (properties, "application.process.host", pinos_get_host_name ()); - - if (!pinos_properties_get (properties, "application.process.session_id")) { - pinos_properties_set (properties, "application.process.session_id", getenv ("XDG_SESSION_ID")); - } -} - -/** - * pinos_fill_stream_properties - * @properties: a #PinosProperties - * - * Fill @properties with a set of default stream properties. - */ -void -pinos_fill_stream_properties (PinosProperties *properties) -{ -} - -PinosDirection -pinos_direction_reverse (PinosDirection direction) -{ - if (direction == PINOS_DIRECTION_INPUT) - return PINOS_DIRECTION_OUTPUT; - else if (direction == PINOS_DIRECTION_OUTPUT) - return PINOS_DIRECTION_INPUT; - return direction; -} diff --git a/pinos/client/pinos.h b/pinos/client/pinos.h deleted file mode 100644 index 3714d8e2c..000000000 --- a/pinos/client/pinos.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_H__ -#define __PINOS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -void pinos_init (int *argc, char **argv[]); - -const char * pinos_get_application_name (void); -const char * pinos_get_prgname (void); -const char * pinos_get_user_name (void); -const char * pinos_get_host_name (void); - -char * pinos_client_name (void); - -void pinos_fill_context_properties (PinosProperties *properties); -void pinos_fill_stream_properties (PinosProperties *properties); - -PinosDirection pinos_direction_reverse (PinosDirection direction); - -SpaTypeMap * pinos_type_map_get_default (void); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_H__ */ diff --git a/pinos/client/properties.h b/pinos/client/properties.h deleted file mode 100644 index 248c9524a..000000000 --- a/pinos/client/properties.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_PROPERTIES_H__ -#define __PINOS_PROPERTIES_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosProperties PinosProperties; - -#include - -struct _PinosProperties { - SpaDict dict; -}; - -PinosProperties * pinos_properties_new (const char *key, ...); -PinosProperties * pinos_properties_new_dict (const SpaDict *dict); -PinosProperties * pinos_properties_copy (PinosProperties *properties); -PinosProperties * pinos_properties_merge (PinosProperties *oldprops, - PinosProperties *newprops); -void pinos_properties_free (PinosProperties *properties); - -void pinos_properties_set (PinosProperties *properties, - const char *key, - const char *value); -void pinos_properties_setf (PinosProperties *properties, - const char *key, - const char *format, - ...) SPA_PRINTF_FUNC (3, 4); -const char * pinos_properties_get (PinosProperties *properties, - const char *key); - -const char * pinos_properties_iterate (PinosProperties *properties, - void **state); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_PROPERTIES_H__ */ diff --git a/pinos/client/stream.h b/pinos/client/stream.h deleted file mode 100644 index 258723f4a..000000000 --- a/pinos/client/stream.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_STREAM_H__ -#define __PINOS_STREAM_H__ - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosStream PinosStream; - -typedef enum { - PINOS_STREAM_STATE_ERROR = -1, - PINOS_STREAM_STATE_UNCONNECTED = 0, - PINOS_STREAM_STATE_CONNECTING = 1, - PINOS_STREAM_STATE_CONFIGURE = 2, - PINOS_STREAM_STATE_READY = 3, - PINOS_STREAM_STATE_PAUSED = 4, - PINOS_STREAM_STATE_STREAMING = 5 -} PinosStreamState; - -const char * pinos_stream_state_as_string (PinosStreamState state); - -typedef enum { - PINOS_STREAM_FLAG_NONE = 0, - PINOS_STREAM_FLAG_AUTOCONNECT = (1 << 0), - PINOS_STREAM_FLAG_CLOCK_UPDATE = (1 << 1), -} PinosStreamFlags; - -typedef enum { - PINOS_STREAM_MODE_BUFFER = 0, - PINOS_STREAM_MODE_RINGBUFFER = 1, -} PinosStreamMode; - -typedef struct { - int64_t now; - int64_t ticks; - int32_t rate; -} PinosTime; - -/** - * PinosStream: - * - * Pinos stream object class. - */ -struct _PinosStream { - PinosContext *context; - SpaList link; - - char *name; - PinosProperties *properties; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosStream *stream)); - - PinosStreamState state; - char *error; - PINOS_SIGNAL (state_changed, (PinosListener *listener, - PinosStream *stream)); - - PINOS_SIGNAL (format_changed, (PinosListener *listener, - PinosStream *stream, - SpaFormat *format)); - - PINOS_SIGNAL (add_buffer, (PinosListener *listener, - PinosStream *stream, - uint32_t id)); - PINOS_SIGNAL (remove_buffer, (PinosListener *listener, - PinosStream *stream, - uint32_t id)); - PINOS_SIGNAL (new_buffer, (PinosListener *listener, - PinosStream *stream, - uint32_t id)); - PINOS_SIGNAL (need_buffer, (PinosListener *listener, - PinosStream *stream)); -}; - -PinosStream * pinos_stream_new (PinosContext *context, - const char *name, - PinosProperties *props); -void pinos_stream_destroy (PinosStream *stream); - -bool pinos_stream_connect (PinosStream *stream, - PinosDirection direction, - PinosStreamMode mode, - const char *port_path, - PinosStreamFlags flags, - uint32_t n_possible_formats, - SpaFormat **possible_formats); -bool pinos_stream_disconnect (PinosStream *stream); - -bool pinos_stream_finish_format (PinosStream *stream, - SpaResult res, - SpaParam **params, - uint32_t n_params); - -bool pinos_stream_get_time (PinosStream *stream, - PinosTime *time); - -uint32_t pinos_stream_get_empty_buffer (PinosStream *stream); -bool pinos_stream_recycle_buffer (PinosStream *stream, - uint32_t id); -SpaBuffer * pinos_stream_peek_buffer (PinosStream *stream, - uint32_t id); -bool pinos_stream_send_buffer (PinosStream *stream, - uint32_t id); -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_STREAM_H__ */ diff --git a/pinos/client/subscribe.h b/pinos/client/subscribe.h deleted file mode 100644 index 748d7af20..000000000 --- a/pinos/client/subscribe.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_SUBSCRIBE_H__ -#define __PINOS_SUBSCRIBE_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PINOS_TYPE__Core "Pinos:Object:Core" -#define PINOS_TYPE_CORE_BASE PINOS_TYPE__Core ":" - -#define PINOS_TYPE__Registry "Pinos:Object:Registry" -#define PINOS_TYPE_REGISYRY_BASE PINOS_TYPE__Registry ":" - -#define PINOS_TYPE__Node "Pinos:Object:Node" -#define PINOS_TYPE_NODE_BASE PINOS_TYPE__Node ":" - -#define PINOS_TYPE__Client "Pinos:Object:Client" -#define PINOS_TYPE_CLIENT_BASE PINOS_TYPE__Client ":" - -#define PINOS_TYPE__Link "Pinos:Object:Link" -#define PINOS_TYPE_LINK_BASE PINOS_TYPE__Link ":" - -#define PINOS_TYPE__Module "Pinos:Object:Module" -#define PINOS_TYPE_MODULE_BASE PINOS_TYPE__Module ":" - -typedef enum { - PINOS_SUBSCRIPTION_EVENT_NEW = 0, - PINOS_SUBSCRIPTION_EVENT_CHANGE = 1, - PINOS_SUBSCRIPTION_EVENT_REMOVE = 2, -} PinosSubscriptionEvent; - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_SUBSCRIBE_H__ */ diff --git a/pinos/client/thread-mainloop.h b/pinos/client/thread-mainloop.h deleted file mode 100644 index db2195c29..000000000 --- a/pinos/client/thread-mainloop.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_THREAD_MAIN_LOOP_H__ -#define __PINOS_THREAD_MAIN_LOOP_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosThreadMainLoop PinosThreadMainLoop; - -/** - * PinosThreadMainLoop: - * - * Pinos main loop object class. - */ -struct _PinosThreadMainLoop { - PinosLoop *loop; - char *name; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosThreadMainLoop *loop)); -}; - -PinosThreadMainLoop * pinos_thread_main_loop_new (PinosLoop *loop, - const char *name); -void pinos_thread_main_loop_destroy (PinosThreadMainLoop *loop); - -SpaResult pinos_thread_main_loop_start (PinosThreadMainLoop *loop); -void pinos_thread_main_loop_stop (PinosThreadMainLoop *loop); - -void pinos_thread_main_loop_lock (PinosThreadMainLoop *loop); -void pinos_thread_main_loop_unlock (PinosThreadMainLoop *loop); - -void pinos_thread_main_loop_wait (PinosThreadMainLoop *loop); -void pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, - bool wait_for_accept); -void pinos_thread_main_loop_accept (PinosThreadMainLoop *loop); - -bool pinos_thread_main_loop_in_thread (PinosThreadMainLoop *loop); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_THREAD_MAIN_LOOP_H__ */ diff --git a/pinos/client/transport.h b/pinos/client/transport.h deleted file mode 100644 index 5c0d94060..000000000 --- a/pinos/client/transport.h +++ /dev/null @@ -1,131 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_TRANSPORT_H__ -#define __PINOS_TRANSPORT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosTransport PinosTransport; -typedef struct _PinosTransportArea PinosTransportArea; - -#include - -#include -#include - -#include -#include - -typedef struct { - int memfd; - uint32_t offset; - uint32_t size; -} PinosTransportInfo; - -/** - * PinosTransportArea: - * - * Shared structure between client and server - */ -struct _PinosTransportArea { - uint32_t max_inputs; - uint32_t n_inputs; - uint32_t max_outputs; - uint32_t n_outputs; -}; - -struct _PinosTransport { - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosTransport *trans)); - - PinosTransportArea *area; - SpaPortIO *inputs; - SpaPortIO *outputs; - void *input_data; - SpaRingbuffer *input_buffer; - void *output_data; - SpaRingbuffer *output_buffer; -}; - -PinosTransport * pinos_transport_new (uint32_t max_inputs, - uint32_t max_outputs); -PinosTransport * pinos_transport_new_from_info (PinosTransportInfo *info); - -void pinos_transport_destroy (PinosTransport *trans); - -SpaResult pinos_transport_get_info (PinosTransport *trans, - PinosTransportInfo *info); - -SpaResult pinos_transport_add_event (PinosTransport *trans, - SpaEvent *event); - -SpaResult pinos_transport_next_event (PinosTransport *trans, - SpaEvent *event); -SpaResult pinos_transport_parse_event (PinosTransport *trans, - void *event); - -#define PINOS_TYPE_EVENT__Transport SPA_TYPE_EVENT_BASE "Transport" -#define PINOS_TYPE_EVENT_TRANSPORT_BASE PINOS_TYPE_EVENT__Transport ":" - -#define PINOS_TYPE_EVENT_TRANSPORT__HaveOutput PINOS_TYPE_EVENT_TRANSPORT_BASE "HaveOutput" -#define PINOS_TYPE_EVENT_TRANSPORT__NeedInput PINOS_TYPE_EVENT_TRANSPORT_BASE "NeedInput" -#define PINOS_TYPE_EVENT_TRANSPORT__ReuseBuffer PINOS_TYPE_EVENT_TRANSPORT_BASE "ReuseBuffer" - -typedef struct { - uint32_t HaveOutput; - uint32_t NeedInput; - uint32_t ReuseBuffer; -} PinosTypeEventTransport; - -static inline void -pinos_type_event_transport_map (SpaTypeMap *map, PinosTypeEventTransport *type) -{ - if (type->HaveOutput == 0) { - type->HaveOutput = spa_type_map_get_id (map, PINOS_TYPE_EVENT_TRANSPORT__HaveOutput); - type->NeedInput = spa_type_map_get_id (map, PINOS_TYPE_EVENT_TRANSPORT__NeedInput); - type->ReuseBuffer = spa_type_map_get_id (map, PINOS_TYPE_EVENT_TRANSPORT__ReuseBuffer); - } -} - -typedef struct { - SpaPODObjectBody body; - SpaPODInt port_id; - SpaPODInt buffer_id; -} PinosEventTransportReuseBufferBody; - -typedef struct { - SpaPOD pod; - PinosEventTransportReuseBufferBody body; -} PinosEventTransportReuseBuffer; - -#define PINOS_EVENT_TRANSPORT_REUSE_BUFFER_INIT(type,port_id,buffer_id) \ - SPA_EVENT_INIT_COMPLEX (PinosEventTransportReuseBuffer, \ - sizeof (PinosEventTransportReuseBufferBody), type, \ - SPA_POD_INT_INIT (port_id), \ - SPA_POD_INT_INIT (buffer_id)) - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __PINOS_TRANSPORT_H__ */ diff --git a/pinos/daemon/.gitignore b/pinos/daemon/.gitignore deleted file mode 100644 index 1417b050a..000000000 --- a/pinos/daemon/.gitignore +++ /dev/null @@ -1 +0,0 @@ -pinos.desktop diff --git a/pinos/daemon/daemon-config.h b/pinos/daemon/daemon-config.h deleted file mode 100644 index 78ccd6b15..000000000 --- a/pinos/daemon/daemon-config.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Axis Communications - * @author Linus Svensson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_DAEMON_CONFIG_H__ -#define __PINOS_DAEMON_CONFIG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct _PinosDaemonConfig PinosDaemonConfig; - -struct _PinosDaemonConfig { - SpaList commands; -}; - -PinosDaemonConfig * pinos_daemon_config_new (void); -void pinos_daemon_config_free (PinosDaemonConfig *config); -bool pinos_daemon_config_load_file (PinosDaemonConfig *config, - const char *filename, - char **err); -bool pinos_daemon_config_load (PinosDaemonConfig *config, - char **err); -bool pinos_daemon_config_run_commands (PinosDaemonConfig *config, - PinosCore *core); -#ifdef __cplusplus -} -#endif - - -#endif /* __PINOS_DAEMON_CONFIG_H__ */ diff --git a/pinos/daemon/meson.build b/pinos/daemon/meson.build deleted file mode 100644 index f1cbc1f05..000000000 --- a/pinos/daemon/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -pinos_sources = [ - 'main.c', - 'daemon-config.c', -] - -pinos_headers = [ - 'daemon-config.h', -] - -pinos_c_args = [ - '-DHAVE_CONFIG_H', - '-D_GNU_SOURCE', - '-DG_LOG_DOMAIN=g_log_domain_pinos', -] - -conf_config = configuration_data() -conf_install_dir = '@0@/pinos'.format(get_option('sysconfdir')) - -configure_file(input : 'pinos.conf.in', - output : 'pinos.conf', - configuration : conf_config, - install_dir : conf_install_dir) - -executable('pinos', - pinos_sources, - install: true, - c_args : pinos_c_args, - include_directories : [configinc, spa_inc], - dependencies : [pinos_dep, pinoscore_dep], -) diff --git a/pinos/daemon/pinos.conf.in b/pinos/daemon/pinos.conf.in deleted file mode 100644 index 41d796927..000000000 --- a/pinos/daemon/pinos.conf.in +++ /dev/null @@ -1,7 +0,0 @@ -#load-module libpinos-module-protocol-dbus -load-module libpinos-module-protocol-native -load-module libpinos-module-suspend-on-idle -load-module libpinos-module-spa --pattern snow -load-module libpinos-module-autolink -#load-module libpinos-module-mixer -load-module libpinos-module-flatpak diff --git a/pinos/dbus/.gitignore b/pinos/dbus/.gitignore deleted file mode 100644 index 5c8219669..000000000 --- a/pinos/dbus/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -org-pinos.c -org-pinos.h diff --git a/pinos/dbus/meson.build b/pinos/dbus/meson.build deleted file mode 100644 index 0ebd03a2d..000000000 --- a/pinos/dbus/meson.build +++ /dev/null @@ -1,15 +0,0 @@ - -gdbus_codegen = find_program('gdbus-codegen') - -org_pinos_files = ['org-pinos.c', 'org-pinos.h'] - -gdbus_target = custom_target('org-pinos', -output : org_pinos_files, -input : 'org.pinos.xml', -command : [gdbus_codegen, - '--interface-prefix', 'org.pinos.', - '--generate-c-code', 'pinos/dbus/org-pinos', - '--c-namespace', 'Pinos', - '--c-generate-object-manager', - '@INPUT@'], -) diff --git a/pinos/dbus/org.pinos.xml b/pinos/dbus/org.pinos.xml deleted file mode 100644 index b24e0a395..000000000 --- a/pinos/dbus/org.pinos.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pinos/gst/gstpinosclock.h b/pinos/gst/gstpinosclock.h deleted file mode 100644 index 33c68fb77..000000000 --- a/pinos/gst/gstpinosclock.h +++ /dev/null @@ -1,62 +0,0 @@ -/* GStreamer - * Copyright (C) <2016> Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __GST_PINOS_CLOCK_H__ -#define __GST_PINOS_CLOCK_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PINOS_CLOCK \ - (gst_pinos_clock_get_type()) -#define GST_PINOS_CLOCK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_CLOCK,GstPinosClock)) -#define GST_PINOS_CLOCK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_CLOCK,GstPinosClockClass)) -#define GST_IS_PINOS_CLOCK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_CLOCK)) -#define GST_IS_PINOS_CLOCK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_CLOCK)) -#define GST_PINOS_CLOCK_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_PINOS_CLOCK, GstPinosClockClass)) - -typedef struct _GstPinosClock GstPinosClock; -typedef struct _GstPinosClockClass GstPinosClockClass; - -struct _GstPinosClock { - GstSystemClock parent; - - PinosStream *stream; -}; - -struct _GstPinosClockClass { - GstSystemClockClass parent_class; -}; - -GType gst_pinos_clock_get_type (void); - -GstClock * gst_pinos_clock_new (PinosStream *stream); - - -G_END_DECLS - -#endif /* __GST_PINOS_CLOCK_H__ */ diff --git a/pinos/gst/gstpinosdeviceprovider.h b/pinos/gst/gstpinosdeviceprovider.h deleted file mode 100644 index 3fbeed2e4..000000000 --- a/pinos/gst/gstpinosdeviceprovider.h +++ /dev/null @@ -1,100 +0,0 @@ -/* GStreamer - * Copyright (C) 2012 Olivier Crete - * (C) 2015 Wim Taymans - * - * pinosdeviceprovider.h: Device probing and monitoring - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __GST_PINOS_DEVICE_PROVIDER_H__ -#define __GST_PINOS_DEVICE_PROVIDER_H__ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include - -G_BEGIN_DECLS - -typedef struct _GstPinosDevice GstPinosDevice; -typedef struct _GstPinosDeviceClass GstPinosDeviceClass; - -#define GST_TYPE_PINOS_DEVICE (gst_pinos_device_get_type()) -#define GST_IS_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE)) -#define GST_IS_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE)) -#define GST_PINOS_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDeviceClass)) -#define GST_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDevice)) -#define GST_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstPinosDeviceClass)) -#define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj)) - -typedef enum { - GST_PINOS_DEVICE_TYPE_UNKNOWN, - GST_PINOS_DEVICE_TYPE_SOURCE, - GST_PINOS_DEVICE_TYPE_SINK, -} GstPinosDeviceType; - -struct _GstPinosDevice { - GstDevice parent; - - GstPinosDeviceType type; - uint32_t id; - const gchar *element; -}; - -struct _GstPinosDeviceClass { - GstDeviceClass parent_class; -}; - -GType gst_pinos_device_get_type (void); - -typedef struct _GstPinosDeviceProvider GstPinosDeviceProvider; -typedef struct _GstPinosDeviceProviderClass GstPinosDeviceProviderClass; - -#define GST_TYPE_PINOS_DEVICE_PROVIDER (gst_pinos_device_provider_get_type()) -#define GST_IS_PINOS_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER)) -#define GST_IS_PINOS_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE_PROVIDER)) -#define GST_PINOS_DEVICE_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER, GstPinosDeviceProviderClass)) -#define GST_PINOS_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER, GstPinosDeviceProvider)) -#define GST_PINOS_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE_PROVIDER, GstPinosDeviceProviderClass)) -#define GST_PINOS_DEVICE_PROVIDER_CAST(obj) ((GstPinosDeviceProvider *)(obj)) - -struct _GstPinosDeviceProvider { - GstDeviceProvider parent; - - gchar *client_name; - - PinosLoop *loop; - PinosThreadMainLoop *main_loop; - - PinosContext *context; - PinosListener ctx_state_changed; - PinosListener ctx_subscription; -}; - -struct _GstPinosDeviceProviderClass { - GstDeviceProviderClass parent_class; -}; - -GType gst_pinos_device_provider_get_type (void); - -G_END_DECLS - -#endif /* __GST_PINOS_DEVICE_PROVIDER_H__ */ diff --git a/pinos/gst/gstpinospool.h b/pinos/gst/gstpinospool.h deleted file mode 100644 index 7f654a072..000000000 --- a/pinos/gst/gstpinospool.h +++ /dev/null @@ -1,66 +0,0 @@ -/* GStreamer - * Copyright (C) <2016> Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __GST_PINOS_POOL_H__ -#define __GST_PINOS_POOL_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PINOS_POOL \ - (gst_pinos_pool_get_type()) -#define GST_PINOS_POOL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_POOL,GstPinosPool)) -#define GST_PINOS_POOL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_POOL,GstPinosPoolClass)) -#define GST_IS_PINOS_POOL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_POOL)) -#define GST_IS_PINOS_POOL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_POOL)) -#define GST_PINOS_POOL_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_PINOS_POOL, GstPinosPoolClass)) - -typedef struct _GstPinosPool GstPinosPool; -typedef struct _GstPinosPoolClass GstPinosPoolClass; - -struct _GstPinosPool { - GstBufferPool parent; - - PinosStream *stream; - GQueue available; - GCond cond; -}; - -struct _GstPinosPoolClass { - GstBufferPoolClass parent_class; -}; - -GType gst_pinos_pool_get_type (void); - -GstPinosPool * gst_pinos_pool_new (void); - -gboolean gst_pinos_pool_add_buffer (GstPinosPool *pool, GstBuffer *buffer); -gboolean gst_pinos_pool_remove_buffer (GstPinosPool *pool, GstBuffer *buffer); - -G_END_DECLS - -#endif /* __GST_PINOS_POOL_H__ */ diff --git a/pinos/gst/gstpinossink.h b/pinos/gst/gstpinossink.h deleted file mode 100644 index abb442ffa..000000000 --- a/pinos/gst/gstpinossink.h +++ /dev/null @@ -1,113 +0,0 @@ -/* GStreamer - * Copyright (C) <2015> Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __GST_PINOS_SINK_H__ -#define __GST_PINOS_SINK_H__ - -#include -#include - -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PINOS_SINK \ - (gst_pinos_sink_get_type()) -#define GST_PINOS_SINK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_SINK,GstPinosSink)) -#define GST_PINOS_SINK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_SINK,GstPinosSinkClass)) -#define GST_IS_PINOS_SINK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_SINK)) -#define GST_IS_PINOS_SINK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_SINK)) -#define GST_PINOS_SINK_CAST(obj) \ - ((GstPinosSink *) (obj)) - -typedef struct _GstPinosSink GstPinosSink; -typedef struct _GstPinosSinkClass GstPinosSinkClass; - - -/** - * GstPinosSinkMode: - * @GST_PINOS_SINK_MODE_DEFAULT: the default mode as configured in the server - * @GST_PINOS_SINK_MODE_RENDER: try to render the media - * @GST_PINOS_SINK_MODE_PROVIDE: provide the media - * - * Different modes of operation. - */ -typedef enum -{ - GST_PINOS_SINK_MODE_DEFAULT, - GST_PINOS_SINK_MODE_RENDER, - GST_PINOS_SINK_MODE_PROVIDE, -} GstPinosSinkMode; - -#define GST_TYPE_PINOS_SINK_MODE (gst_pinos_sink_mode_get_type ()) - -/** - * GstPinosSink: - * - * Opaque data structure. - */ -struct _GstPinosSink { - GstBaseSink element; - - /*< private >*/ - gchar *path; - gchar *client_name; - - /* video state */ - gboolean negotiated; - - PinosLoop *loop; - PinosThreadMainLoop *main_loop; - - PinosContext *ctx; - PinosListener ctx_state_changed; - - PinosStream *stream; - PinosListener stream_state_changed; - PinosListener stream_format_changed; - PinosListener stream_add_buffer; - PinosListener stream_remove_buffer; - PinosListener stream_new_buffer; - PinosListener stream_need_buffer; - - GstAllocator *allocator; - GstStructure *properties; - GstPinosSinkMode mode; - - GstPinosPool *pool; - GHashTable *buf_ids; - GQueue queue; - guint need_ready; -}; - -struct _GstPinosSinkClass { - GstBaseSinkClass parent_class; -}; - -GType gst_pinos_sink_get_type (void); -GType gst_pinos_sink_mode_get_type (void); - -G_END_DECLS - -#endif /* __GST_PINOS_SINK_H__ */ diff --git a/pinos/gst/meson.build b/pinos/gst/meson.build deleted file mode 100644 index 22c5b22f0..000000000 --- a/pinos/gst/meson.build +++ /dev/null @@ -1,31 +0,0 @@ -pinos_gst_sources = [ - 'gstpinos.c', - 'gstpinosclock.c', - 'gstpinosdeviceprovider.c', - 'gstpinosformat.c', - 'gstpinospool.c', - 'gstpinossink.c', - 'gstpinossrc.c', -] - -pinos_gst_headers = [ - 'gstpinosclock.h', - 'gstpinosdeviceprovider.h', - 'gstpinosformat.h', - 'gstpinospool.h', - 'gstpinossink.h', - 'gstpinossrc.h', -] - -pinos_gst_c_args = [ - '-DHAVE_CONFIG_H', -] - -pinos_gst = shared_library('gstpinos', - pinos_gst_sources, - c_args : pinos_gst_c_args, - include_directories : [configinc, spa_inc], - dependencies : [gobject_dep, glib_dep, gio_dep, gst_dep, pinos_dep, pinoscore_dep], - install : true, - install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')), -) diff --git a/pinos/modules/gst/gst-manager.c b/pinos/modules/gst/gst-manager.c deleted file mode 100644 index 6de81e6f4..000000000 --- a/pinos/modules/gst/gst-manager.c +++ /dev/null @@ -1,334 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "gst-manager.h" -#include "gst-source.h" -#include "gst-sink.h" - -#define PINOS_GST_MANAGER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_GST_MANAGER, PinosGstManagerPrivate)) - -struct _PinosGstManagerPrivate -{ - PinosDaemon *daemon; - - GstDeviceMonitor *monitor; -}; - -enum -{ - PROP_0, - PROP_DAEMON -}; - -G_DEFINE_TYPE (PinosGstManager, pinos_gst_manager, G_TYPE_OBJECT); - -static gboolean -copy_properties (GQuark field_id, - const GValue *value, - gpointer user_data) -{ - PinosProperties *properties = user_data; - - if (G_VALUE_HOLDS_STRING (value)) - pinos_properties_set (properties, - g_quark_to_string (field_id), - g_value_get_string (value)); - - return TRUE; -} - -static void -device_added (PinosGstManager *manager, - GstDevice *device) -{ - PinosGstManagerPrivate *priv = manager->priv; - gchar *name, *klass; - GstElement *element; - PinosNode *node = NULL; - GstStructure *p; - PinosProperties *properties; - GstCaps *caps; - - name = gst_device_get_display_name (device); - if (g_strcmp0 (name, "gst") == 0) { - g_free (name); - return; - } - - caps = gst_device_get_caps (device); - - g_print("Device added: %s\n", name); - - properties = pinos_properties_new (NULL, NULL); - if ((p = gst_device_get_properties (device))) { - gst_structure_foreach (p, copy_properties, properties); - gst_structure_free (p); - } - - klass = gst_device_get_device_class (device); - pinos_properties_set (properties, - "gstreamer.device.class", - klass); - - - element = gst_device_create_element (device, NULL); - - if (strstr (klass, "Source")) { - node = pinos_gst_source_new (priv->daemon, - name, - properties, - element, - caps, - NULL, - NULL); - } else if (strstr (klass, "Sink")) { - node = pinos_gst_sink_new (priv->daemon, - name, - properties, - element, - caps, - NULL, - NULL); - } - if (node) - g_object_set_data (G_OBJECT (device), "PinosNode", node); - - pinos_properties_free (properties); - gst_caps_unref (caps); - g_free (name); - g_free (klass); -} - -static void -device_removed (PinosGstManager *manager, - GstDevice *device) -{ - gchar *name; - PinosNode *node; - - name = gst_device_get_display_name (device); - if (strcmp (name, "gst") == 0) - return; - - g_print("Device removed: %s\n", name); - - node = g_object_steal_data (G_OBJECT (device), "PinosNode"); - g_object_unref (node); - g_free (name); -} - -static gboolean -bus_handler (GstBus *bus, - GstMessage *message, - gpointer user_data) -{ - PinosGstManager *manager = user_data; - GstDevice *device; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_DEVICE_ADDED: - gst_message_parse_device_added (message, &device); - device_added (manager, device); - break; - case GST_MESSAGE_DEVICE_REMOVED: - gst_message_parse_device_removed (message, &device); - device_removed (manager, device); - break; - default: - break; - } - return TRUE; -} - -static void -disable_pinos_provider (PinosGstManager *manager) -{ - GList *factories = NULL; - - factories = gst_device_provider_factory_list_get_device_providers (1); - - while (factories) { - GstDeviceProviderFactory *factory = factories->data; - - if (strcmp (GST_OBJECT_NAME (factory), "pinosdeviceprovider") == 0) { - gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), 0); - } - factories = g_list_remove (factories, factory); - gst_object_unref (factory); - } - -} - -static void -start_monitor (PinosGstManager *manager) -{ - PinosGstManagerPrivate *priv = manager->priv; - GstBus *bus; - GList *devices; - gchar **providers; - PinosProperties *props; - - disable_pinos_provider (manager); - - priv->monitor = gst_device_monitor_new (); - - bus = gst_device_monitor_get_bus (priv->monitor); - gst_bus_add_watch (bus, bus_handler, manager); - gst_object_unref (bus); - - gst_device_monitor_add_filter (priv->monitor, "Video/Source", NULL); - gst_device_monitor_add_filter (priv->monitor, "Audio/Source", NULL); - gst_device_monitor_add_filter (priv->monitor, "Audio/Sink", NULL); - gst_device_monitor_start (priv->monitor); - - providers = gst_device_monitor_get_providers (priv->monitor); - if (providers != NULL) { - gchar *provided; - - provided = g_strjoinv (",", providers); - g_strfreev (providers); - - g_object_get (priv->daemon, "properties", &props, NULL); - pinos_properties_set (props, "gstreamer.deviceproviders", provided); - g_object_set (priv->daemon, "properties", props, NULL); - pinos_properties_free (props); - g_free (provided); - } - - devices = gst_device_monitor_get_devices (priv->monitor); - while (devices != NULL) { - GstDevice *device = devices->data; - - device_added (manager, device); - gst_object_unref (device); - devices = g_list_delete_link (devices, devices); - } -} - -static void -stop_monitor (PinosGstManager *manager) -{ - PinosGstManagerPrivate *priv = manager->priv; - - if (priv->monitor) { - gst_device_monitor_stop (priv->monitor); - g_object_unref (priv->monitor); - priv->monitor = NULL; - } -} - -static void -pinos_gst_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PinosGstManager *manager = PINOS_GST_MANAGER (object); - PinosGstManagerPrivate *priv = manager->priv; - - switch (prop_id) { - case PROP_DAEMON: - g_value_set_object (value, priv->daemon); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -pinos_gst_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - PinosGstManager *manager = PINOS_GST_MANAGER (object); - PinosGstManagerPrivate *priv = manager->priv; - - switch (prop_id) { - case PROP_DAEMON: - priv->daemon = g_value_dup_object (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_manager_constructed (GObject * object) -{ - PinosGstManager *manager = PINOS_GST_MANAGER (object); - - start_monitor (manager); - - G_OBJECT_CLASS (pinos_gst_manager_parent_class)->constructed (object); -} - -static void -gst_manager_finalize (GObject * object) -{ - PinosGstManager *manager = PINOS_GST_MANAGER (object); - - stop_monitor (manager); - - G_OBJECT_CLASS (pinos_gst_manager_parent_class)->finalize (object); -} - -static void -pinos_gst_manager_class_init (PinosGstManagerClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (PinosGstManagerPrivate)); - - gobject_class->constructed = gst_manager_constructed; - gobject_class->finalize = gst_manager_finalize; - gobject_class->set_property = pinos_gst_manager_set_property; - gobject_class->get_property = pinos_gst_manager_get_property; - - g_object_class_install_property (gobject_class, - PROP_DAEMON, - g_param_spec_object ("daemon", - "Daemon", - "The daemon", - PINOS_TYPE_DAEMON, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); -} - -static void -pinos_gst_manager_init (PinosGstManager * manager) -{ - manager->priv = PINOS_GST_MANAGER_GET_PRIVATE (manager); -} - -PinosGstManager * -pinos_gst_manager_new (PinosDaemon *daemon) -{ - return g_object_new (PINOS_TYPE_GST_MANAGER, "daemon", daemon, NULL); -} diff --git a/pinos/modules/gst/gst-manager.h b/pinos/modules/gst/gst-manager.h deleted file mode 100644 index f2172a066..000000000 --- a/pinos/modules/gst/gst-manager.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_GST_MANAGER_H__ -#define __PINOS_GST_MANAGER_H__ - -#include - -#include -#include - -G_BEGIN_DECLS - -#define PINOS_TYPE_GST_MANAGER (pinos_gst_manager_get_type ()) -#define PINOS_IS_GST_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_GST_MANAGER)) -#define PINOS_IS_GST_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_GST_MANAGER)) -#define PINOS_GST_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_GST_MANAGER, PinosGstManagerClass)) -#define PINOS_GST_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_GST_MANAGER, PinosGstManager)) -#define PINOS_GST_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_GST_MANAGER, PinosGstManagerClass)) -#define PINOS_GST_MANAGER_CAST(obj) ((PinosGstManager*)(obj)) -#define PINOS_GST_MANAGER_CLASS_CAST(klass) ((PinosGstManagerClass*)(klass)) - -typedef struct _PinosGstManager PinosGstManager; -typedef struct _PinosGstManagerClass PinosGstManagerClass; -typedef struct _PinosGstManagerPrivate PinosGstManagerPrivate; - -struct _PinosGstManager { - GObject object; - - PinosGstManagerPrivate *priv; -}; - -struct _PinosGstManagerClass { - GObjectClass parent_class; -}; - -GType pinos_gst_manager_get_type (void); - -PinosGstManager * pinos_gst_manager_new (PinosDaemon *daemon); - -G_END_DECLS - -#endif /* __PINOS_GST_MANAGER_H__ */ diff --git a/pinos/modules/gst/gst-node-factory.c b/pinos/modules/gst/gst-node-factory.c deleted file mode 100644 index 7a3e559a0..000000000 --- a/pinos/modules/gst/gst-node-factory.c +++ /dev/null @@ -1,71 +0,0 @@ -#/* Pinos - * Copyright (C) 2016 Axis Communications AB - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "gst-node-factory.h" -#include "gst-source.h" - -G_DEFINE_TYPE (PinosGstNodeFactory, pinos_gst_node_factory, PINOS_TYPE_NODE_FACTORY); - -static PinosNode * -factory_create_node (PinosNodeFactory * factory, - PinosDaemon * daemon, - const gchar * sender, - const gchar * name, - PinosProperties * properties) -{ - PinosNode *node; - - node = g_object_new (PINOS_TYPE_GST_SOURCE, - "daemon", daemon, - "sender", sender, - "name", name, - "properties", properties, - NULL); - return node; -} - -static void -pinos_gst_node_factory_class_init (PinosGstNodeFactoryClass * klass) -{ - PinosNodeFactoryClass *factory_class = PINOS_NODE_FACTORY_CLASS (klass); - - factory_class->create_node = factory_create_node; -} - -static void -pinos_gst_node_factory_init (PinosGstNodeFactory * factory) -{ -} - -PinosNodeFactory * -pinos_gst_node_factory_new (const gchar * name) -{ - PinosNodeFactory *factory; - - factory = g_object_new (PINOS_TYPE_GST_NODE_FACTORY, - "name", name, - NULL); - return factory; -} diff --git a/pinos/modules/gst/gst-node-factory.h b/pinos/modules/gst/gst-node-factory.h deleted file mode 100644 index 21174d8d9..000000000 --- a/pinos/modules/gst/gst-node-factory.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Axis Communications AB - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_GST_NODE_FACTORY_H__ -#define __PINOS_GST_NODE_FACTORY_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define PINOS_TYPE_GST_NODE_FACTORY (pinos_gst_node_factory_get_type ()) -#define PINOS_IS_GST_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_GST_NODE_FACTORY)) -#define PINOS_IS_GST_NODE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_GST_NODE_FACTORY)) -#define PINOS_GST_NODE_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_GST_NODE_FACTORY, PinosGstNodeFactoryClass)) -#define PINOS_GST_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_GST_NODE_FACTORY, PinosGstNodeFactory)) -#define PINOS_GST_NODE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_GST_NODE_FACTORY, PinosGstNodeFactoryClass)) -#define PINOS_GST_NODE_FACTORY_CAST(obj) ((PinosGstNodeFactory*)(obj)) -#define PINOS_GST_NODE_FACTORY_CLASS_CAST(klass) ((PinosGstNodeFactoryClass*)(klass)) - -typedef struct _PinosGstNodeFactory PinosGstNodeFactory; -typedef struct _PinosGstNodeFactoryClass PinosGstNodeFactoryClass; - -struct _PinosGstNodeFactory { - PinosNodeFactory object; -}; - -struct _PinosGstNodeFactoryClass { - PinosNodeFactoryClass parent_class; -}; - -GType pinos_gst_node_factory_get_type (void); - -PinosNodeFactory * pinos_gst_node_factory_new (const gchar * name); - -G_END_DECLS - -#endif /* __PINOS_GST_NODE_FACTORY_H__ */ diff --git a/pinos/modules/gst/gst-sink.c b/pinos/modules/gst/gst-sink.c deleted file mode 100644 index da00af5d4..000000000 --- a/pinos/modules/gst/gst-sink.c +++ /dev/null @@ -1,545 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include - -#include "gst-sink.h" - -#define PINOS_GST_SINK_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_GST_SINK, PinosGstSinkPrivate)) - -typedef struct { - PinosGstSink *sink; - - PinosPort *port; - - GstElement *src; - GstElement *convert; - - GstPad *srcpad; - GstPad *peerpad; -} SinkPortData; - -struct _PinosGstSinkPrivate -{ - gchar *convert_name; - - GstElement *pipeline; - GstElement *mixer; - GstElement *element; - - GList *ports; - GstCaps *possible_formats; - - GstNetTimeProvider *provider; -}; - -enum { - PROP_0, - PROP_ELEMENT, - PROP_POSSIBLE_FORMATS, - PROP_MIXER, - PROP_CONVERT_NAME -}; - -G_DEFINE_TYPE (PinosGstSink, pinos_gst_sink, PINOS_TYPE_NODE); - -static gboolean -bus_handler (GstBus *bus, - GstMessage *message, - gpointer user_data) -{ - PinosNode *node = user_data; - PinosGstSinkPrivate *priv = PINOS_GST_SINK (node)->priv; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - { - GError *error; - gchar *debug; - - gst_message_parse_error (message, &error, &debug); - g_warning ("got error %s (%s)\n", error->message, debug); - g_free (debug); - - pinos_node_report_error (node, error); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - break; - } - case GST_MESSAGE_NEW_CLOCK: - { - GstClock *clock; - PinosProperties *props; - - gst_message_parse_new_clock (message, &clock); - GST_INFO ("got new clock %s", GST_OBJECT_NAME (clock)); - - g_object_get (node, "properties", &props, NULL); - pinos_properties_set (props, "gst.pipeline.clock", GST_OBJECT_NAME (clock)); - g_object_set (node, "properties", props, NULL); - pinos_properties_free (props); - break; - } - case GST_MESSAGE_CLOCK_LOST: - { - GstClock *clock; - PinosProperties *props; - - gst_message_parse_new_clock (message, &clock); - GST_INFO ("clock lost %s", GST_OBJECT_NAME (clock)); - - g_object_get (node, "properties", &props, NULL); - pinos_properties_set (props, "gst.pipeline.clock", NULL); - g_object_set (node, "properties", props, NULL); - pinos_properties_free (props); - - gst_element_set_state (priv->pipeline, GST_STATE_PAUSED); - gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); - break; - } - default: - break; - } - return TRUE; -} - -static gboolean -setup_pipeline (PinosGstSink *sink, GError **error) -{ - PinosGstSinkPrivate *priv = sink->priv; - GstBus *bus; - - g_debug ("gst-sink %p: setup pipeline", sink); - priv->pipeline = gst_pipeline_new (NULL); - - g_object_set (priv->element, "sync", FALSE, NULL); - gst_bin_add (GST_BIN (priv->pipeline), priv->element); - - if (priv->mixer) { - gst_bin_add (GST_BIN (priv->pipeline), priv->mixer); - gst_element_link (priv->mixer, priv->element); - } - - bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline)); - gst_bus_add_watch (bus, bus_handler, sink); - gst_object_unref (bus); - - return TRUE; -} - -#if 0 -static gboolean -start_pipeline (PinosGstSink *sink, GError **error) -{ - PinosGstSinkPrivate *priv = sink->priv; -#if 0 - GstCaps *caps; - GstQuery *query; - gchar *str; -#endif - GstStateChangeReturn ret; - - g_debug ("gst-sink %p: starting pipeline", sink); - - ret = gst_element_set_state (priv->pipeline, GST_STATE_READY); - if (ret == GST_STATE_CHANGE_FAILURE) - goto ready_failed; - -#if 0 - query = gst_query_new_caps (NULL); - if (gst_element_query (priv->element, query)) { - gst_query_parse_caps_result (query, &caps); - gst_caps_replace (&priv->possible_formats, caps); - str = gst_caps_to_string (caps); - g_debug ("gst-sink %p: updated possible formats %s", sink, str); - g_free (str); - } - gst_query_unref (query); -#endif - - return TRUE; - - /* ERRORS */ -ready_failed: - { - GST_ERROR_OBJECT (sink, "failed state change to READY"); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - if (error) - *error = g_error_new (G_IO_ERROR, - G_IO_ERROR_FAILED, - "Failed to start pipeline"); - return FALSE; - } -} -#endif - -static void -stop_pipeline (PinosGstSink *sink) -{ - PinosGstSinkPrivate *priv = sink->priv; - - g_debug ("gst-sink %p: stopping pipeline", sink); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - g_clear_object (&priv->provider); -} - -static void -destroy_pipeline (PinosGstSink *sink) -{ - PinosGstSinkPrivate *priv = sink->priv; - - g_debug ("gst-sink %p: destroy pipeline", sink); - stop_pipeline (sink); - g_clear_object (&priv->pipeline); -} - - -static gboolean -set_state (PinosNode *node, - PinosNodeState state) -{ - PinosGstSinkPrivate *priv = PINOS_GST_SINK (node)->priv; - - g_debug ("gst-sink %p: set state %s", node, pinos_node_state_as_string (state)); - - switch (state) { - case PINOS_NODE_STATE_SUSPENDED: - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - break; - - case PINOS_NODE_STATE_INITIALIZING: - gst_element_set_state (priv->pipeline, GST_STATE_READY); - break; - - case PINOS_NODE_STATE_IDLE: - gst_element_set_state (priv->pipeline, GST_STATE_PAUSED); - break; - - case PINOS_NODE_STATE_RUNNING: - gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); - break; - - case PINOS_NODE_STATE_ERROR: - break; - } - pinos_node_update_state (node, state); - return TRUE; -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PinosGstSink *sink = PINOS_GST_SINK (object); - PinosGstSinkPrivate *priv = sink->priv; - - switch (prop_id) { - case PROP_ELEMENT: - g_value_set_object (value, priv->element); - break; - - case PROP_POSSIBLE_FORMATS: - g_value_set_boxed (value, priv->possible_formats); - break; - - case PROP_MIXER: - g_value_set_object (value, priv->mixer); - break; - - case PROP_CONVERT_NAME: - g_value_set_string (value, priv->convert_name); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - PinosGstSink *sink = PINOS_GST_SINK (object); - PinosGstSinkPrivate *priv = sink->priv; - - switch (prop_id) { - case PROP_ELEMENT: - priv->element = g_value_dup_object (value); - break; - - case PROP_POSSIBLE_FORMATS: - priv->possible_formats = g_value_dup_boxed (value); - break; - - case PROP_MIXER: - priv->mixer = g_value_dup_object (value); - break; - - case PROP_CONVERT_NAME: - priv->convert_name = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -on_activate (PinosPort *port, gpointer user_data) -{ - SinkPortData *data = user_data; - PinosGstSink *sink = data->sink; - PinosGstSinkPrivate *priv = sink->priv; - - g_debug ("port %p: activate", port); - - if (priv->mixer) { - data->peerpad = gst_element_get_request_pad (priv->mixer, "sink_%u"); - } else { - data->peerpad = gst_element_get_static_pad (priv->element, "sink"); - } - if (gst_pad_link (data->srcpad, data->peerpad) != GST_PAD_LINK_OK) { - g_clear_object (&data->peerpad); - return; - } - - pinos_node_report_busy (PINOS_NODE (sink)); - - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_PLAYING); - } - gst_element_set_state (data->src, GST_STATE_PLAYING); - - return; -} - -static void -on_deactivate (PinosPort *port, gpointer user_data) -{ - SinkPortData *data = user_data; - PinosGstSink *sink = data->sink; - PinosGstSinkPrivate *priv = sink->priv; - - g_debug ("port %p: deactivate", port); - - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_NULL); - } - gst_element_set_state (data->src, GST_STATE_NULL); - - gst_pad_unlink (data->srcpad, data->peerpad); - if (priv->mixer) - gst_element_release_request_pad (priv->mixer, data->peerpad); - g_clear_object (&data->peerpad); -} - -static void -free_sink_port_data (SinkPortData *data) -{ - PinosGstSink *sink = data->sink; - PinosGstSinkPrivate *priv = sink->priv; - - gst_element_set_state (data->src, GST_STATE_NULL); - gst_bin_remove (GST_BIN (priv->pipeline), data->src); - - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_NULL); - gst_bin_remove (GST_BIN (priv->pipeline), data->convert); - } - if (data->peerpad) - gst_element_release_request_pad (priv->mixer, data->peerpad); - - g_clear_object (&data->srcpad); - g_clear_object (&data->peerpad); - - g_slice_free (SinkPortData, data); -} - -static PinosPort * -add_port (PinosNode *node, - guint id, - GError **error) -{ - PinosGstSink *sink = PINOS_GST_SINK (node); - PinosGstSinkPrivate *priv = sink->priv; - SinkPortData *data; - - data = g_slice_new0 (SinkPortData); - data->sink = sink; - data->port = PINOS_NODE_CLASS (pinos_gst_sink_parent_class) - ->add_port (node, id, error); - - g_debug ("connecting signals"); - g_signal_connect (data->port, "activate", (GCallback) on_activate, data); - g_signal_connect (data->port, "deactivate", (GCallback) on_deactivate, data); - - data->src = gst_element_factory_make ("pinosportsrc", NULL); - g_object_set (data->src, "port", data->port, NULL); - gst_bin_add (GST_BIN (priv->pipeline), data->src); - - if (priv->convert_name) { - data->convert = gst_element_factory_make (priv->convert_name, NULL); - gst_bin_add (GST_BIN (priv->pipeline), data->convert); - gst_element_link (data->src, data->convert); - data->srcpad = gst_element_get_static_pad (data->convert, "src"); - } else { - data->srcpad = gst_element_get_static_pad (data->src, "src"); - } - - priv->ports = g_list_append (priv->ports, data); - - return data->port; -} - -static gboolean -remove_port (PinosNode *node, - PinosPort *port) -{ - PinosGstSink *sink = PINOS_GST_SINK (node); - PinosGstSinkPrivate *priv = sink->priv; - GList *walk; - - for (walk = priv->ports; walk; walk = g_list_next (walk)) { - SinkPortData *data = walk->data; - - if (data->port == port) { - free_sink_port_data (data); - priv->ports = g_list_delete_link (priv->ports, walk); - break; - } - } - if (priv->ports == NULL) - pinos_node_report_idle (node); - - return TRUE; -} - -static void -sink_constructed (GObject * object) -{ - PinosGstSink *sink = PINOS_GST_SINK (object); - - G_OBJECT_CLASS (pinos_gst_sink_parent_class)->constructed (object); - - setup_pipeline (sink, NULL); -} - -static void -sink_finalize (GObject * object) -{ - PinosGstSink *sink = PINOS_GST_SINK (object); - PinosGstSinkPrivate *priv = sink->priv; - - destroy_pipeline (sink); - g_clear_pointer (&priv->possible_formats, gst_caps_unref); - - G_OBJECT_CLASS (pinos_gst_sink_parent_class)->finalize (object); -} - -static void -pinos_gst_sink_class_init (PinosGstSinkClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - PinosNodeClass *node_class = PINOS_NODE_CLASS (klass); - - g_type_class_add_private (klass, sizeof (PinosGstSinkPrivate)); - - gobject_class->constructed = sink_constructed; - gobject_class->finalize = sink_finalize; - gobject_class->get_property = get_property; - gobject_class->set_property = set_property; - - g_object_class_install_property (gobject_class, - PROP_ELEMENT, - g_param_spec_object ("element", - "Element", - "The element", - GST_TYPE_ELEMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, - PROP_POSSIBLE_FORMATS, - g_param_spec_boxed ("possible-formats", - "Possible Formats", - "The possible formats", - GST_TYPE_CAPS, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, - PROP_MIXER, - g_param_spec_object ("mixer", - "Mixer", - "The mixer element", - GST_TYPE_ELEMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, - PROP_CONVERT_NAME, - g_param_spec_string ("convert-name", - "Convert name", - "The converter element name", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - node_class->set_state = set_state; -} - -static void -pinos_gst_sink_init (PinosGstSink * sink) -{ - sink->priv = PINOS_GST_SINK_GET_PRIVATE (sink); -} - -PinosNode * -pinos_gst_sink_new (PinosDaemon *daemon, - const gchar *name, - PinosProperties *properties, - GstElement *element, - GstCaps *caps, - GstElement *mixer, - const gchar *convert_name) -{ - PinosNode *node; - - node = g_object_new (PINOS_TYPE_GST_SINK, - "daemon", daemon, - "name", name, - "properties", properties, - "element", element, - "possible-formats", caps, - "mixer", mixer, - "convert-name", convert_name, - NULL); - - return node; -} diff --git a/pinos/modules/gst/gst-sink.h b/pinos/modules/gst/gst-sink.h deleted file mode 100644 index cfe8fdbd2..000000000 --- a/pinos/modules/gst/gst-sink.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_GST_SINK_H__ -#define __PINOS_GST_SINK_H__ - -#include - -#include -#include - -G_BEGIN_DECLS - -#define PINOS_TYPE_GST_SINK (pinos_gst_sink_get_type ()) -#define PINOS_IS_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_GST_SINK)) -#define PINOS_IS_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_GST_SINK)) -#define PINOS_GST_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_GST_SINK, PinosGstSinkClass)) -#define PINOS_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_GST_SINK, PinosGstSink)) -#define PINOS_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_GST_SINK, PinosGstSinkClass)) -#define PINOS_GST_SINK_CAST(obj) ((PinosGstSink*)(obj)) -#define PINOS_GST_SINK_CLASS_CAST(klass) ((PinosGstSinkClass*)(klass)) - -typedef struct _PinosGstSink PinosGstSink; -typedef struct _PinosGstSinkClass PinosGstSinkClass; -typedef struct _PinosGstSinkPrivate PinosGstSinkPrivate; - -struct _PinosGstSink { - PinosNode object; - - PinosGstSinkPrivate *priv; -}; - -struct _PinosGstSinkClass { - PinosNodeClass parent_class; -}; - -GType pinos_gst_sink_get_type (void); - -PinosNode * pinos_gst_sink_new (PinosDaemon *daemon, - const gchar *name, - PinosProperties *properties, - GstElement *element, - GstCaps *caps, - GstElement *mixer, - const gchar *convert_name); - -G_END_DECLS - -#endif /* __PINOS_GST_SINK_H__ */ diff --git a/pinos/modules/gst/gst-source.c b/pinos/modules/gst/gst-source.c deleted file mode 100644 index 50a00c264..000000000 --- a/pinos/modules/gst/gst-source.c +++ /dev/null @@ -1,691 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include - -#include "gst-source.h" - -#define PINOS_GST_SOURCE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_GST_SOURCE, PinosGstSourcePrivate)) - -typedef struct { - PinosGstSource *source; - - guint id; - PinosPort *port; - - GstElement *convert; - GstElement *sink; - - GstPad *peerpad; - GstPad *sinkpad; -} SourcePortData; - -struct _PinosGstSourcePrivate -{ - gchar *convert_name; - - GstElement *pipeline; - GstElement *element; - GstElement *splitter; - - GList *ports; - GstCaps *possible_formats; - - GstNetTimeProvider *provider; -}; - -enum { - PROP_0, - PROP_ELEMENT, - PROP_POSSIBLE_FORMATS, - PROP_SPLITTER, - PROP_CONVERT_NAME -}; - -G_DEFINE_TYPE (PinosGstSource, pinos_gst_source, PINOS_TYPE_NODE); - -static gboolean -bus_handler (GstBus *bus, - GstMessage *message, - gpointer user_data) -{ - PinosNode *node = user_data; - PinosGstSourcePrivate *priv = PINOS_GST_SOURCE (node)->priv; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - { - GError *error; - gchar *debug; - - gst_message_parse_error (message, &error, &debug); - g_warning ("got error %s (%s)\n", error->message, debug); - g_free (debug); - - pinos_node_report_error (node, error); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - break; - } - case GST_MESSAGE_NEW_CLOCK: - { - GstClock *clock; - PinosProperties *props; - - gst_message_parse_new_clock (message, &clock); - GST_INFO ("got new clock %s", GST_OBJECT_NAME (clock)); - - g_object_get (node, "properties", &props, NULL); - pinos_properties_set (props, "gst.pipeline.clock", GST_OBJECT_NAME (clock)); - g_object_set (node, "properties", props, NULL); - pinos_properties_free (props); - break; - } - case GST_MESSAGE_CLOCK_LOST: - { - GstClock *clock; - PinosProperties *props; - - gst_message_parse_new_clock (message, &clock); - GST_INFO ("clock lost %s", GST_OBJECT_NAME (clock)); - - g_object_get (node, "properties", &props, NULL); - pinos_properties_set (props, "gst.pipeline.clock", NULL); - g_object_set (node, "properties", props, NULL); - pinos_properties_free (props); - - gst_element_set_state (priv->pipeline, GST_STATE_PAUSED); - gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); - break; - } - default: - break; - } - return TRUE; -} - -static gboolean -setup_pipeline (PinosGstSource *source, GError **error) -{ - PinosGstSourcePrivate *priv = source->priv; - GstBus *bus; - - g_debug ("gst-source %p: setup pipeline", source); - priv->pipeline = gst_pipeline_new (NULL); - gst_pipeline_set_latency (GST_PIPELINE_CAST (priv->pipeline), 0); - - gst_bin_add (GST_BIN (priv->pipeline), priv->element); - - if (priv->splitter) { - gst_bin_add (GST_BIN (priv->pipeline), priv->splitter); - gst_element_link (priv->element, priv->splitter); - } - - bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline)); - gst_bus_add_watch (bus, bus_handler, source); - gst_object_unref (bus); - - return TRUE; -} - -#if 0 -static gboolean -start_pipeline (PinosGstSource *source, GError **error) -{ - PinosGstSourcePrivate *priv = source->priv; - GstCaps *caps; - GstQuery *query; - GstStateChangeReturn ret; - gchar *str; - - g_debug ("gst-source %p: starting pipeline", source); - - ret = gst_element_set_state (priv->pipeline, GST_STATE_READY); - if (ret == GST_STATE_CHANGE_FAILURE) - goto ready_failed; - - query = gst_query_new_caps (NULL); - if (gst_element_query (priv->element, query)) { - gst_query_parse_caps_result (query, &caps); - gst_caps_replace (&priv->possible_formats, caps); - str = gst_caps_to_string (caps); - g_debug ("gst-source %p: updated possible formats %s", source, str); - g_free (str); - } - gst_query_unref (query); - - return TRUE; - - /* ERRORS */ -ready_failed: - { - GST_ERROR_OBJECT (source, "failed state change to READY"); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - if (error) - *error = g_error_new (G_IO_ERROR, - G_IO_ERROR_FAILED, - "Failed to start pipeline"); - return FALSE; - } -} -#endif - -static void -stop_pipeline (PinosGstSource *source) -{ - PinosGstSourcePrivate *priv = source->priv; - - g_debug ("gst-source %p: stopping pipeline", source); - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - g_clear_object (&priv->provider); -} - -static void -destroy_pipeline (PinosGstSource *source) -{ - PinosGstSourcePrivate *priv = source->priv; - - g_debug ("gst-source %p: destroy pipeline", source); - stop_pipeline (source); - g_clear_object (&priv->pipeline); -} - - -static gboolean -set_state (PinosNode *node, - PinosNodeState state) -{ - PinosGstSourcePrivate *priv = PINOS_GST_SOURCE (node)->priv; - - g_debug ("gst-source %p: set state %s", node, pinos_node_state_as_string (state)); - - switch (state) { - case PINOS_NODE_STATE_SUSPENDED: - gst_element_set_state (priv->pipeline, GST_STATE_NULL); - break; - - case PINOS_NODE_STATE_INITIALIZING: - gst_element_set_state (priv->pipeline, GST_STATE_READY); - break; - - case PINOS_NODE_STATE_IDLE: - gst_element_set_state (priv->pipeline, GST_STATE_PAUSED); - break; - - case PINOS_NODE_STATE_RUNNING: - { - GstQuery *query; - GstClock *clock; - gchar *address; - gint port; - PinosProperties *props; - GstClockTime base_time; - gboolean live; - GstClockTime min_latency, max_latency; - - gst_element_set_state (priv->pipeline, GST_STATE_PAUSED); - gst_element_get_state (priv->pipeline, NULL, NULL, -1); - gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); - gst_element_get_state (priv->pipeline, NULL, NULL, -1); - - clock = gst_pipeline_get_clock (GST_PIPELINE (priv->pipeline)); - base_time = gst_clock_get_time (clock); - - if (priv->provider) - g_object_unref (priv->provider); - priv->provider = gst_net_time_provider_new (clock, NULL, 0); - - g_object_get (priv->provider, "address", &address, "port", &port, NULL); - - g_object_get (node, "properties", &props, NULL); - - pinos_properties_set (props, "pinos.clock.type", "gst.net.time.provider"); - pinos_properties_set (props, "pinos.clock.source", GST_OBJECT_NAME (clock)); - pinos_properties_set (props, "pinos.clock.address", address); - pinos_properties_setf (props, "pinos.clock.port", "%d", port); - pinos_properties_setf (props, "pinos.clock.base-time", "%"G_GUINT64_FORMAT, base_time); - - g_free (address); - gst_object_unref (clock); - - query = gst_query_new_latency (); - if (gst_element_query (GST_ELEMENT_CAST (priv->pipeline), query)) { - gst_query_parse_latency (query, &live, &min_latency, &max_latency); - } else { - live = FALSE; - min_latency = 0; - max_latency = -1; - } - gst_query_unref (query); - - GST_DEBUG_OBJECT (priv->pipeline, - "got min latency %" GST_TIME_FORMAT ", max latency %" - GST_TIME_FORMAT ", live %d", GST_TIME_ARGS (min_latency), - GST_TIME_ARGS (max_latency), live); - - pinos_properties_setf (props, "pinos.latency.is-live", "%d", live); - pinos_properties_setf (props, "pinos.latency.min", "%"G_GUINT64_FORMAT, min_latency); - pinos_properties_setf (props, "pinos.latency.max", "%"G_GUINT64_FORMAT, max_latency); - - g_object_set (node, "properties", props, NULL); - pinos_properties_free (props); - break; - } - case PINOS_NODE_STATE_ERROR: - break; - } - pinos_node_update_state (node, state); - return TRUE; -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PinosGstSource *source = PINOS_GST_SOURCE (object); - PinosGstSourcePrivate *priv = source->priv; - - switch (prop_id) { - case PROP_ELEMENT: - g_value_set_object (value, priv->element); - break; - - case PROP_POSSIBLE_FORMATS: - g_value_set_boxed (value, priv->possible_formats); - break; - - case PROP_SPLITTER: - g_value_set_object (value, priv->splitter); - break; - - case PROP_CONVERT_NAME: - g_value_set_string (value, priv->convert_name); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - PinosGstSource *source = PINOS_GST_SOURCE (object); - PinosGstSourcePrivate *priv = source->priv; - - switch (prop_id) { - case PROP_ELEMENT: - priv->element = g_value_dup_object (value); - break; - - case PROP_POSSIBLE_FORMATS: - priv->possible_formats = g_value_dup_boxed (value); - break; - - case PROP_SPLITTER: - priv->splitter = g_value_dup_object (value); - break; - - case PROP_CONVERT_NAME: - priv->convert_name = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static gboolean -on_activate (PinosPort *port, gpointer user_data) -{ - SourcePortData *data = user_data; - PinosGstSource *source = data->source; - PinosGstSourcePrivate *priv = source->priv; - - if (priv->splitter) { - data->peerpad = gst_element_get_request_pad (priv->splitter, "src_%u"); - } else { - data->peerpad = gst_element_get_static_pad (priv->element, "src"); - } - if (gst_pad_link (data->peerpad, data->sinkpad) != GST_PAD_LINK_OK) { - g_clear_object (&data->peerpad); - return FALSE; - } - - pinos_node_report_busy (PINOS_NODE (source)); - - gst_element_set_state (data->sink, GST_STATE_PLAYING); - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_PLAYING); - } - - return TRUE; -} - -static void -on_deactivate (PinosPort *port, gpointer user_data) -{ - SourcePortData *data = user_data; - PinosGstSource *source = data->source; - PinosGstSourcePrivate *priv = source->priv; - - gst_pad_unlink (data->peerpad, data->sinkpad); - if (priv->splitter) - gst_element_release_request_pad (priv->splitter, data->peerpad); - - gst_element_set_state (data->sink, GST_STATE_NULL); - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_NULL); - } - g_clear_object (&data->peerpad); - - pinos_node_report_idle (PINOS_NODE (source)); -} - -static void -free_source_port_data (SourcePortData *data) -{ - PinosGstSource *source = data->source; - PinosGstSourcePrivate *priv = source->priv; - - gst_element_set_state (data->sink, GST_STATE_NULL); - gst_bin_remove (GST_BIN (priv->pipeline), data->sink); - - if (data->convert) { - gst_element_set_state (data->convert, GST_STATE_NULL); - gst_bin_remove (GST_BIN (priv->pipeline), data->convert); - } - if (data->peerpad) - gst_element_release_request_pad (priv->splitter, data->peerpad); - - g_clear_object (&data->peerpad); - g_clear_object (&data->sinkpad); - - g_slice_free (SourcePortData, data); -} - -static gboolean -remove_port (PinosNode *node, - PinosPort *port) -{ - PinosGstSource *source = PINOS_GST_SOURCE (node); - PinosGstSourcePrivate *priv = source->priv; - GList *walk; - - for (walk = priv->ports; walk; walk = g_list_next (walk)) { - SourcePortData *data = walk->data; - - if (data->port == port) { - free_source_port_data (data); - priv->ports = g_list_delete_link (priv->ports, walk); - break; - } - } - if (priv->ports == NULL) - pinos_node_report_idle (node); - - return TRUE; -} - -static void -source_constructed (GObject * object) -{ - PinosGstSource *source = PINOS_GST_SOURCE (object); - PinosGstSourcePrivate *priv = source->priv; - - G_OBJECT_CLASS (pinos_gst_source_parent_class)->constructed (object); - - if (priv->element) - setup_pipeline (source, NULL); -} - -static void -source_finalize (GObject * object) -{ - PinosGstSource *source = PINOS_GST_SOURCE (object); - PinosGstSourcePrivate *priv = source->priv; - - g_debug ("gst-source %p: dispose", source); - destroy_pipeline (source); - g_clear_pointer (&priv->possible_formats, gst_caps_unref); - - G_OBJECT_CLASS (pinos_gst_source_parent_class)->finalize (object); -} - -static gboolean -factory_filter (GstPluginFeature * feature, gpointer data) -{ - guint rank; - const gchar *klass; - - if (!GST_IS_ELEMENT_FACTORY (feature)) - return FALSE; - - rank = gst_plugin_feature_get_rank (feature); - if (rank < 1) - return FALSE; - - klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature), - GST_ELEMENT_METADATA_KLASS); - if (g_strcmp0 (klass, "Source/Video") && g_strcmp0 (klass, "Source/Audio")) - return FALSE; - - return TRUE; -} - -static GstElement * -create_best_element (GstCaps *caps) -{ - GstElement *element = NULL; - GList *list, *item; - - /* get factories from registry */ - list = gst_registry_feature_filter (gst_registry_get (), - (GstPluginFeatureFilter) factory_filter, - FALSE, NULL); - list = g_list_sort (list, - (GCompareFunc) gst_plugin_feature_rank_compare_func); - - /* loop through list and try to find factory that best matches caps, - * following the pattern from GstAutoDetect */ - for (item = list; item != NULL; item = item->next) { - GstElementFactory *f = GST_ELEMENT_FACTORY (item->data); - GstElement *el; - GstPad *el_pad; - GstCaps *el_caps = NULL; - gboolean match = FALSE; - GstStateChangeReturn ret; - - if ((el = gst_element_factory_create (f, NULL))) { - el_pad = gst_element_get_static_pad (el, "src"); - el_caps = gst_pad_query_caps (el_pad, NULL); - gst_object_unref (el_pad); - match = gst_caps_can_intersect (caps, el_caps); - gst_caps_unref (el_caps); - - if (!match) { - gst_object_unref (el); - continue; - } - } - - ret = gst_element_set_state (el, GST_STATE_READY); - if (ret == GST_STATE_CHANGE_SUCCESS) { - element = el; - g_debug ("element %p selected", element); - break; - } - - gst_element_set_state (el, GST_STATE_NULL); - gst_object_unref (el); - } - - return element; -} - -static PinosPort * -add_port (PinosNode *node, - guint id, - GError **error) -{ - PinosGstSource *source = PINOS_GST_SOURCE (node); - PinosGstSourcePrivate *priv = source->priv; - SourcePortData *data; - PinosProperties *props = NULL; - - if (priv->element == NULL) { - GstCaps *caps; - - caps = NULL; - priv->element = create_best_element (caps); - gst_caps_unref (caps); - - if (priv->element) { - props = pinos_properties_new (NULL, NULL); - pinos_properties_set (props, "autoconnect", "0"); - setup_pipeline (source, NULL); - } - } - - data = g_slice_new0 (SourcePortData); - data->source = source; - data->port = PINOS_NODE_CLASS (pinos_gst_source_parent_class) - ->add_port (node, id, error); - - g_debug ("connecting signals"); - g_signal_connect (data->port, "activate", (GCallback) on_activate, data); - g_signal_connect (data->port, "deactivate", (GCallback) on_deactivate, data); - - data->sink = gst_element_factory_make ("pinosportsink", NULL); - g_object_set (data->sink, "sync", TRUE, - "enable-last-sample", FALSE, - "qos", FALSE, - "port", data->port, - NULL); - gst_bin_add (GST_BIN (priv->pipeline), data->sink); - - if (priv->convert_name) { - data->convert = gst_element_factory_make (priv->convert_name, NULL); - gst_bin_add (GST_BIN (priv->pipeline), data->convert); - gst_element_link (data->convert, data->sink); - data->sinkpad = gst_element_get_static_pad (data->convert, "sink"); - } else { - data->sinkpad = gst_element_get_static_pad (data->sink, "sink"); - } - - priv->ports = g_list_append (priv->ports, data); - - return data->port; -} - -static void -pinos_gst_source_class_init (PinosGstSourceClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - PinosNodeClass *node_class = PINOS_NODE_CLASS (klass); - - g_type_class_add_private (klass, sizeof (PinosGstSourcePrivate)); - - gobject_class->constructed = source_constructed; - gobject_class->finalize = source_finalize; - gobject_class->get_property = get_property; - gobject_class->set_property = set_property; - - g_object_class_install_property (gobject_class, - PROP_ELEMENT, - g_param_spec_object ("element", - "Element", - "The element", - GST_TYPE_ELEMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, - PROP_POSSIBLE_FORMATS, - g_param_spec_boxed ("possible-formats", - "Possible Formats", - "The possible formats", - GST_TYPE_CAPS, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (gobject_class, - PROP_SPLITTER, - g_param_spec_object ("splitter", - "Splitter", - "The splitter element", - GST_TYPE_ELEMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, - PROP_CONVERT_NAME, - g_param_spec_string ("convert-name", - "Convert name", - "The converter element name", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - node_class->set_state = set_state; - node_class->add_port = add_port; - node_class->remove_port = remove_port; -} - -static void -pinos_gst_source_init (PinosGstSource * source) -{ - source->priv = PINOS_GST_SOURCE_GET_PRIVATE (source); -} - -PinosNode * -pinos_gst_source_new (PinosDaemon *daemon, - const gchar *name, - PinosProperties *properties, - GstElement *element, - GstCaps *caps, - GstElement *splitter, - const gchar *convert_name) -{ - PinosNode *node; - - node = g_object_new (PINOS_TYPE_GST_SOURCE, - "daemon", daemon, - "name", name, - "properties", properties, - "element", element, - "possible-formats", caps, - "splitter", splitter, - "convert-name", convert_name, - NULL); - - return node; -} diff --git a/pinos/modules/gst/gst-source.h b/pinos/modules/gst/gst-source.h deleted file mode 100644 index 2ce4f3060..000000000 --- a/pinos/modules/gst/gst-source.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_GST_SOURCE_H__ -#define __PINOS_GST_SOURCE_H__ - -#include - -#include -#include - -G_BEGIN_DECLS - -#define PINOS_TYPE_GST_SOURCE (pinos_gst_source_get_type ()) -#define PINOS_IS_GST_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_GST_SOURCE)) -#define PINOS_IS_GST_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_GST_SOURCE)) -#define PINOS_GST_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_GST_SOURCE, PinosGstSourceClass)) -#define PINOS_GST_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_GST_SOURCE, PinosGstSource)) -#define PINOS_GST_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_GST_SOURCE, PinosGstSourceClass)) -#define PINOS_GST_SOURCE_CAST(obj) ((PinosGstSource*)(obj)) -#define PINOS_GST_SOURCE_CLASS_CAST(klass) ((PinosGstSourceClass*)(klass)) - -typedef struct _PinosGstSource PinosGstSource; -typedef struct _PinosGstSourceClass PinosGstSourceClass; -typedef struct _PinosGstSourcePrivate PinosGstSourcePrivate; - -struct _PinosGstSource { - PinosNode object; - - PinosGstSourcePrivate *priv; -}; - -struct _PinosGstSourceClass { - PinosNodeClass parent_class; -}; - -GType pinos_gst_source_get_type (void); - -PinosNode * pinos_gst_source_new (PinosDaemon *daemon, - const gchar *name, - PinosProperties *properties, - GstElement *element, - GstCaps *caps, - GstElement *mixer, - const gchar *converter); - -G_END_DECLS - -#endif /* __PINOS_GST_SOURCE_H__ */ diff --git a/pinos/modules/gst/meson.build b/pinos/modules/gst/meson.build deleted file mode 100644 index d3f75e221..000000000 --- a/pinos/modules/gst/meson.build +++ /dev/null @@ -1,27 +0,0 @@ -pinos_module_spa_headers = [ - 'spa-alsa-monitor.h', - 'spa-audiotestsrc.h', - 'spa-v4l2-monitor.h', - 'spa-videotestsrc.h', -] - -pinos_module_spa_sources = [ - 'module.c', - 'spa-alsa-monitor.c', - 'spa-audiotestsrc.c', - 'spa-v4l2-monitor.c', - 'spa-videotestsrc.c', -] - -pinos_module_spa_c_args = [ - '-DHAVE_CONFIG_H', - '-D_GNU_SOURCE', -] - - -pinos_module_spa = shared_library('pinos-module-spa', pinos_module_spa_sources, - c_args : pinos_module_spa_c_args, - include_directories : [configinc, pinosinc, spa_inc], - link_with : spalib, - dependencies : [gobject_dep, gmodule_dep, glib_dep, gio_dep, mathlib, dl_lib, pinos_dep, pinoscore_dep], -) diff --git a/pinos/modules/gst/module.c b/pinos/modules/gst/module.c deleted file mode 100644 index 440e79e46..000000000 --- a/pinos/modules/gst/module.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Axis Communications - * @author Linus Svensson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include "gst-manager.h" -#include "gst-node-factory.h" - -gboolean pinos__module_init (PinosModule *module, const gchar * args); - -G_MODULE_EXPORT gboolean -pinos__module_init (PinosModule * module, G_GNUC_UNUSED const gchar * args) -{ - PinosNodeFactory *factory; - - pinos_gst_manager_new (module->daemon); - - factory = pinos_gst_node_factory_new ("gst-node-factory"); - pinos_daemon_add_node_factory (module->daemon, factory); - - g_object_unref (factory); - - return TRUE; -} diff --git a/pinos/modules/meson.build b/pinos/modules/meson.build deleted file mode 100644 index e9524e5c6..000000000 --- a/pinos/modules/meson.build +++ /dev/null @@ -1,61 +0,0 @@ -#subdir('gst') -subdir('spa') - -pinos_module_c_args = [ - '-DHAVE_CONFIG_H', - '-D_GNU_SOURCE', -] - -pinos_module_flatpak = shared_library('pinos-module-flatpak', [ 'module-flatpak.c' ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [dbus_dep, mathlib, dl_lib, pinos_dep, pinoscore_dep], -) - -pinos_module_autolink = shared_library('pinos-module-autolink', [ 'module-autolink.c' ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep], -) - -pinos_module_mixer = shared_library('pinos-module-mixer', [ 'module-mixer.c' ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep], -) - -pinos_module_protocol_dbus = shared_library('pinos-module-protocol-dbus', [ 'module-protocol-dbus.c', gdbus_target ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [glib_dep, gio_dep, mathlib, dl_lib, pinos_dep, pinoscore_dep], -) - -pinos_module_protocol_native = shared_library('pinos-module-protocol-native', [ 'module-protocol-native.c' ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep], -) - -pinos_module_suspend_on_idle = shared_library('pinos-module-suspend-on-idle', [ 'module-suspend-on-idle.c' ], - c_args : pinos_module_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : modules_install_dir, - dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep], -) diff --git a/pinos/modules/module-autolink.c b/pinos/modules/module-autolink.c deleted file mode 100644 index 12b528381..000000000 --- a/pinos/modules/module-autolink.c +++ /dev/null @@ -1,442 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "config.h" - -#include "pinos/client/interfaces.h" -#include "pinos/server/core.h" -#include "pinos/server/module.h" -#include "pinos/server/client-node.h" - -typedef struct { - PinosCore *core; - PinosProperties *properties; - - PinosListener global_added; - PinosListener global_removed; - - SpaList client_list; -} ModuleImpl; - -typedef struct { - ModuleImpl *impl; - PinosClient *client; - SpaList link; - PinosListener resource_added; - PinosListener resource_removed; - SpaList node_list; -} ClientInfo; - -typedef struct { - ModuleImpl *impl; - ClientInfo *info; - PinosNode *node; - PinosResource *resource; - SpaList link; - PinosListener state_changed; - PinosListener port_added; - PinosListener port_removed; - PinosListener port_unlinked; - PinosListener link_state_changed; -} NodeInfo; - -static NodeInfo * -find_node_info (ClientInfo *cinfo, PinosNode *node) -{ - NodeInfo *info; - - spa_list_for_each (info, &cinfo->node_list, link) { - if (info->node == node) - return info; - } - return NULL; -} - -static ClientInfo * -find_client_info (ModuleImpl *impl, PinosClient *client) -{ - ClientInfo *info; - - spa_list_for_each (info, &impl->client_list, link) { - if (info->client == client) - return info; - } - return NULL; -} - -static void -node_info_free (NodeInfo *info) -{ - spa_list_remove (&info->link); - pinos_signal_remove (&info->state_changed); - pinos_signal_remove (&info->port_added); - pinos_signal_remove (&info->port_removed); - pinos_signal_remove (&info->port_unlinked); - pinos_signal_remove (&info->link_state_changed); - free (info); -} - -static void -client_info_free (ClientInfo *cinfo) -{ - NodeInfo *info, *tmp; - - spa_list_remove (&cinfo->link); - pinos_signal_remove (&cinfo->resource_added); - pinos_signal_remove (&cinfo->resource_removed); - - spa_list_for_each_safe (info, tmp, &cinfo->node_list, link) - node_info_free (info); - - free (cinfo); -} - -static void try_link_port (PinosNode *node, PinosPort *port, NodeInfo *info); - -static void -on_link_port_unlinked (PinosListener *listener, - PinosLink *link, - PinosPort *port) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, port_unlinked); - ModuleImpl *impl = info->impl; - - pinos_log_debug ("module %p: link %p: port %p unlinked", impl, link, port); - if (port->direction == PINOS_DIRECTION_OUTPUT && link->input) - try_link_port (link->input->node, link->input, info); -} - -static void -on_link_state_changed (PinosListener *listener, - PinosLink *link, - PinosLinkState old, - PinosLinkState state) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, link_state_changed); - ModuleImpl *impl = info->impl; - - switch (state) { - case PINOS_LINK_STATE_ERROR: - { - PinosResource *resource; - - pinos_log_debug ("module %p: link %p: state error: %s", impl, link, link->error); - - spa_list_for_each (resource, &link->resource_list, link) { - pinos_core_notify_error (resource->client->core_resource, - resource->id, - SPA_RESULT_ERROR, - link->error); - } - if (info->info->client) { - pinos_core_notify_error (info->info->client->core_resource, - info->resource->id, - SPA_RESULT_ERROR, - link->error); - } - break; - } - - case PINOS_LINK_STATE_UNLINKED: - pinos_log_debug ("module %p: link %p: unlinked", impl, link); - break; - - case PINOS_LINK_STATE_INIT: - case PINOS_LINK_STATE_NEGOTIATING: - case PINOS_LINK_STATE_ALLOCATING: - case PINOS_LINK_STATE_PAUSED: - case PINOS_LINK_STATE_RUNNING: - break; - } -} - -static void -try_link_port (PinosNode *node, - PinosPort *port, - NodeInfo *info) -{ - ModuleImpl *impl = info->impl; - PinosProperties *props; - const char *str; - uint32_t path_id; - char *error = NULL; - PinosLink *link; - PinosPort *target; - - props = node->properties; - if (props == NULL) { - pinos_log_debug ("module %p: node has no properties", impl); - return; - } - - str = pinos_properties_get (props, "pinos.target.node"); - if (str != NULL) - path_id = atoi (str); - else { - str = pinos_properties_get (props, "pinos.autoconnect"); - if (str == NULL || atoi (str) == 0) { - pinos_log_debug ("module %p: node does not need autoconnect", impl); - return; - } - path_id = SPA_ID_INVALID; - } - - pinos_log_debug ("module %p: try to find and link to node '%d'", impl, path_id); - - target = pinos_core_find_port (impl->core, - port, - path_id, - NULL, - 0, - NULL, - &error); - if (target == NULL) - goto error; - - if (port->direction == PINOS_DIRECTION_OUTPUT) - link = pinos_port_link (port, target, NULL, NULL, &error); - else - link = pinos_port_link (target, port, NULL, NULL, &error); - - if (link == NULL) - goto error; - - pinos_signal_add (&link->port_unlinked, &info->port_unlinked, on_link_port_unlinked); - pinos_signal_add (&link->state_changed, &info->link_state_changed, on_link_state_changed); - - pinos_link_activate (link); - - return; - -error: - { - pinos_log_error ("module %p: can't link node '%s'", impl, error); - if (info->info->client && info->info->client->core_resource) { - pinos_core_notify_error (info->info->client->core_resource, - info->resource->id, - SPA_RESULT_ERROR, - error); - } - free (error); - return; - } -} - -static void -on_port_added (PinosListener *listener, - PinosNode *node, - PinosPort *port) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, port_added); - - try_link_port (node, port, info); -} - -static void -on_port_removed (PinosListener *listener, - PinosNode *node, - PinosPort *port) -{ -} - -static void -on_node_created (PinosNode *node, - NodeInfo *info) -{ - PinosPort *port; - - spa_list_for_each (port, &node->input_ports, link) - on_port_added (&info->port_added, node, port); - - spa_list_for_each (port, &node->output_ports, link) - on_port_added (&info->port_added, node, port); -} - -static void -on_state_changed (PinosListener *listener, - PinosNode *node, - PinosNodeState old, - PinosNodeState state) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, state_changed); - - if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED) - on_node_created (node, info); -} - -static void -on_node_added (ModuleImpl *impl, - PinosNode *node, - PinosResource *resource, - ClientInfo *cinfo) -{ - NodeInfo *info; - - info = calloc (1, sizeof (NodeInfo)); - info->impl = impl; - info->node = node; - info->resource = resource; - info->info = cinfo; - spa_list_insert (cinfo->node_list.prev, &info->link); - - spa_list_init (&info->port_unlinked.link); - spa_list_init (&info->link_state_changed.link); - pinos_signal_add (&node->port_added, &info->port_added, on_port_added); - pinos_signal_add (&node->port_removed, &info->port_removed, on_port_removed); - pinos_signal_add (&node->state_changed, &info->state_changed, on_state_changed); - - pinos_log_debug ("module %p: node %p added", impl, node); - - if (node->state > PINOS_NODE_STATE_CREATING) - on_node_created (node, info); -} - -static void -on_resource_added (PinosListener *listener, - PinosClient *client, - PinosResource *resource) -{ - ClientInfo *cinfo = SPA_CONTAINER_OF (listener, ClientInfo, resource_added); - ModuleImpl *impl = cinfo->impl; - - if (resource->type == impl->core->type.client_node) { - PinosClientNode *cnode = resource->object; - on_node_added (impl, cnode->node, resource, cinfo); - } -} - -static void -on_resource_removed (PinosListener *listener, - PinosClient *client, - PinosResource *resource) -{ - ClientInfo *cinfo = SPA_CONTAINER_OF (listener, ClientInfo, resource_removed); - ModuleImpl *impl = cinfo->impl; - - if (resource->type == impl->core->type.client_node) { - PinosClientNode *cnode = resource->object; - NodeInfo *ninfo; - - if ((ninfo = find_node_info (cinfo, cnode->node))) - node_info_free (ninfo); - - pinos_log_debug ("module %p: node %p removed", impl, cnode->node); - } -} - -static void -on_global_added (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) -{ - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_added); - - if (global->type == impl->core->type.client) { - PinosClient *client = global->object; - ClientInfo *cinfo; - - cinfo = calloc (1, sizeof (ClientInfo)); - cinfo->impl = impl; - cinfo->client = global->object; - spa_list_init (&cinfo->node_list); - - spa_list_insert (impl->client_list.prev, &cinfo->link); - - pinos_signal_add (&client->resource_added, &cinfo->resource_added, on_resource_added); - pinos_signal_add (&client->resource_removed, &cinfo->resource_removed, on_resource_removed); - - pinos_log_debug ("module %p: client %p added", impl, cinfo->client); - } -} - -static void -on_global_removed (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) -{ - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_removed); - - if (global->type == impl->core->type.client) { - PinosClient *client = global->object; - ClientInfo *cinfo; - - if ((cinfo = find_client_info (impl, client))) - client_info_free (cinfo); - - pinos_log_debug ("module %p: client %p removed", impl, client); - } -} - -/** - * module_new: - * @core: #PinosCore - * @properties: #PinosProperties - * - * Make a new #ModuleImpl object with given @properties - * - * Returns: a new #ModuleImpl - */ -static ModuleImpl * -module_new (PinosCore *core, - PinosProperties *properties) -{ - ModuleImpl *impl; - - impl = calloc (1, sizeof (ModuleImpl)); - pinos_log_debug ("module %p: new", impl); - - impl->core = core; - impl->properties = properties; - - spa_list_init (&impl->client_list); - - pinos_signal_add (&core->global_added, &impl->global_added, on_global_added); - pinos_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); - - return impl; -} - -#if 0 -static void -module_destroy (ModuleImpl *impl) -{ - pinos_log_debug ("module %p: destroy", impl); - - pinos_global_destroy (impl->global); - - pinos_signal_remove (&impl->global_added); - pinos_signal_remove (&impl->global_removed); - pinos_signal_remove (&impl->port_added); - pinos_signal_remove (&impl->port_removed); - pinos_signal_remove (&impl->port_unlinked); - pinos_signal_remove (&impl->link_state_changed); - free (impl); -} -#endif - -bool -pinos__module_init (PinosModule * module, const char * args) -{ - module->user_data = module_new (module->core, NULL); - return true; -} diff --git a/pinos/modules/module-suspend-on-idle.c b/pinos/modules/module-suspend-on-idle.c deleted file mode 100644 index 4d4bbef5b..000000000 --- a/pinos/modules/module-suspend-on-idle.c +++ /dev/null @@ -1,215 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "config.h" - -#include "pinos/server/core.h" -#include "pinos/server/module.h" - -typedef struct { - PinosCore *core; - PinosProperties *properties; - - PinosListener global_added; - PinosListener global_removed; - - SpaList node_list; -} ModuleImpl; - -typedef struct { - ModuleImpl *impl; - PinosNode *node; - SpaList link; - PinosListener node_state_request; - PinosListener node_state_changed; - SpaSource *idle_timeout; -} NodeInfo; - -static NodeInfo * -find_node_info (ModuleImpl *impl, PinosNode *node) -{ - NodeInfo *info; - - spa_list_for_each (info, &impl->node_list, link) { - if (info->node == node) - return info; - } - return NULL; -} - -static void -remove_idle_timeout (NodeInfo *info) -{ - if (info->idle_timeout) { - pinos_loop_destroy_source (info->impl->core->main_loop->loop, info->idle_timeout); - info->idle_timeout = NULL; - } -} - -static void -node_info_free (NodeInfo *info) -{ - spa_list_remove (&info->link); - remove_idle_timeout (info); - pinos_signal_remove (&info->node_state_request); - pinos_signal_remove (&info->node_state_changed); - free (info); -} - -static void -idle_timeout (SpaLoopUtils *utils, - SpaSource *source, - void *data) -{ - NodeInfo *info = data; - - pinos_log_debug ("module %p: node %p idle timeout", info->impl, info->node); - remove_idle_timeout (info); - pinos_node_set_state (info->node, PINOS_NODE_STATE_SUSPENDED); -} - -static void -on_node_state_request (PinosListener *listener, - PinosNode *node, - PinosNodeState state) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, node_state_request); - remove_idle_timeout (info); -} - -static void -on_node_state_changed (PinosListener *listener, - PinosNode *node, - PinosNodeState old, - PinosNodeState state) -{ - NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, node_state_changed); - ModuleImpl *impl = info->impl; - - if (state != PINOS_NODE_STATE_IDLE) { - remove_idle_timeout (info); - } else { - struct timespec value; - - pinos_log_debug ("module %p: node %p became idle", impl, node); - info->idle_timeout = pinos_loop_add_timer (impl->core->main_loop->loop, - idle_timeout, - info); - value.tv_sec = 3; - value.tv_nsec = 0; - pinos_loop_update_timer (impl->core->main_loop->loop, - info->idle_timeout, - &value, - NULL, - false); - } -} - -static void -on_global_added (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) -{ - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_added); - - if (global->type == impl->core->type.node) { - PinosNode *node = global->object; - NodeInfo *info; - - info = calloc (1, sizeof (NodeInfo)); - info->impl = impl; - info->node = node; - spa_list_insert (impl->node_list.prev, &info->link); - pinos_signal_add (&node->state_request, &info->node_state_request, on_node_state_request); - pinos_signal_add (&node->state_changed, &info->node_state_changed, on_node_state_changed); - - pinos_log_debug ("module %p: node %p added", impl, node); - } -} - -static void -on_global_removed (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) -{ - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_removed); - - if (global->type == impl->core->type.node) { - PinosNode *node = global->object; - NodeInfo *info; - - if ((info = find_node_info (impl, node))) - node_info_free (info); - - pinos_log_debug ("module %p: node %p removed", impl, node); - } -} - - -/** - * module_new: - * @core: #PinosCore - * @properties: #PinosProperties - * - * Make a new #ModuleImpl object with given @properties - * - * Returns: a new #ModuleImpl - */ -static ModuleImpl * -module_new (PinosCore *core, - PinosProperties *properties) -{ - ModuleImpl *impl; - - impl = calloc (1, sizeof (ModuleImpl)); - pinos_log_debug ("module %p: new", impl); - - impl->core = core; - impl->properties = properties; - - spa_list_init (&impl->node_list); - - pinos_signal_add (&core->global_added, &impl->global_added, on_global_added); - pinos_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); - - return impl; -} - -#if 0 -static void -module_destroy (ModuleImpl *impl) -{ - pinos_log_debug ("module %p: destroy", impl); - - pinos_global_destroy (impl->global); - - free (impl); -} -#endif - -bool -pinos__module_init (PinosModule * module, const char * args) -{ - module_new (module->core, NULL); - return true; -} diff --git a/pinos/modules/spa/meson.build b/pinos/modules/spa/meson.build deleted file mode 100644 index e79e5ff63..000000000 --- a/pinos/modules/spa/meson.build +++ /dev/null @@ -1,24 +0,0 @@ -pinos_module_spa_headers = [ - 'spa-node.h', - 'spa-monitor.h', -] - -pinos_module_spa_sources = [ - 'module.c', - 'spa-node.c', - 'spa-monitor.c', -] - -pinos_module_spa_c_args = [ - '-DHAVE_CONFIG_H', - '-D_GNU_SOURCE', -] - -pinos_module_spa = shared_library('pinos-module-spa', pinos_module_spa_sources, - c_args : pinos_module_spa_c_args, - include_directories : [configinc, spa_inc], - link_with : spalib, - install : true, - install_dir : '@0@/pinos-0.1'.format(get_option('libdir')), - dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep], -) diff --git a/pinos/modules/spa/spa-node.h b/pinos/modules/spa/spa-node.h deleted file mode 100644 index 0498feeb7..000000000 --- a/pinos/modules/spa/spa-node.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_SPA_NODE_H__ -#define __PINOS_SPA_NODE_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosSpaNode PinosSpaNode; - -struct _PinosSpaNode { - PinosNode *node; - - char *lib; - char *factory_name; - SpaHandle *handle; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosSpaNode *node)); -}; - -typedef SpaResult (*SetupNode) (PinosCore *core, - SpaNode *spa_node, - PinosProperties *pinos_props); - -PinosSpaNode * pinos_spa_node_load (PinosCore *core, - const char *lib, - const char *factory_name, - const char *name, - PinosProperties *properties, - SetupNode setup_func); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_SPA_NODE_H__ */ diff --git a/pinos/server/access.h b/pinos/server/access.h deleted file mode 100644 index d9586ee01..000000000 --- a/pinos/server/access.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_ACCESS_H__ -#define __PINOS_ACCESS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define PINOS_TYPE__Access "Pinos:Object:Access" -#define PINOS_TYPE_ACCESS_BASE PINOS_TYPE__Access ":" - -#include - -typedef struct _PinosAccess PinosAccess; -typedef struct _PinosAccessData PinosAccessData; - -#include -#include - -struct _PinosAccessData { - SpaResult res; - PinosResource *resource; - void * (*async_copy) (PinosAccessData *data, size_t size); - void (*complete_cb) (PinosAccessData *data); - void (*free_cb) (PinosAccessData *data); - void * user_data; -}; - - -/** - * PinosAccess: - * - * Pinos Access support struct. - */ -struct _PinosAccess { - SpaResult (*view_global) (PinosAccess *access, - PinosClient *client, - PinosGlobal *global); - SpaResult (*create_node) (PinosAccess *access, - PinosAccessData *data, - const char *factory_name, - const char *name, - PinosProperties *properties); - SpaResult (*create_client_node) (PinosAccess *access, - PinosAccessData *data, - const char *name, - PinosProperties *properties); -}; - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_ACCESS_H__ */ diff --git a/pinos/server/client-node.h b/pinos/server/client-node.h deleted file mode 100644 index 9402c021b..000000000 --- a/pinos/server/client-node.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_CLIENT_NODE_H__ -#define __PINOS_CLIENT_NODE_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PINOS_TYPE__ClientNode "Pinos:Object:ClientNode" -#define PINOS_TYPE_CLIENT_NODE_BASE PINOS_TYPE__ClientNode ":" - -typedef struct _PinosClientNode PinosClientNode; - -/** - * PinosClientNode: - * - * Pinos client node interface - */ -struct _PinosClientNode { - PinosNode *node; - - PinosClient *client; - PinosResource *resource; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosClientNode *node)); -}; - -PinosClientNode * pinos_client_node_new (PinosClient *client, - uint32_t id, - const char *name, - PinosProperties *properties); -void pinos_client_node_destroy (PinosClientNode *node); - -SpaResult pinos_client_node_get_fds (PinosClientNode *node, - int *readfd, - int *writefd); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_CLIENT_NODE_H__ */ diff --git a/pinos/server/client.h b/pinos/server/client.h deleted file mode 100644 index e8eea176e..000000000 --- a/pinos/server/client.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_CLIENT_H__ -#define __PINOS_CLIENT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosClient PinosClient; - -#include - -#include -#include -#include - -#include -#include - -/** - * PinosClient: - * - * Pinos client object class. - */ -struct _PinosClient { - PinosCore *core; - SpaList link; - PinosGlobal *global; - - PinosProperties *properties; - PINOS_SIGNAL (properties_changed, (PinosListener *listener, - PinosClient *client)); - - PinosClientInfo info; - bool ucred_valid; - struct ucred ucred; - - void *protocol_private; - - PinosResource *core_resource; - - PinosMap objects; - uint32_t n_types; - PinosMap types; - - SpaList resource_list; - PINOS_SIGNAL (resource_added, (PinosListener *listener, - PinosClient *client, - PinosResource *resource)); - PINOS_SIGNAL (resource_removed, (PinosListener *listener, - PinosClient *client, - PinosResource *resource)); - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosClient *client)); -}; - -PinosClient * pinos_client_new (PinosCore *core, - struct ucred *ucred, - PinosProperties *properties); -void pinos_client_destroy (PinosClient *client); - -void pinos_client_update_properties (PinosClient *client, - const SpaDict *dict); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_CLIENT_H__ */ diff --git a/pinos/server/core.h b/pinos/server/core.h deleted file mode 100644 index 000a9d9d6..000000000 --- a/pinos/server/core.h +++ /dev/null @@ -1,145 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_CORE_H__ -#define __PINOS_CORE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosCore PinosCore; -typedef struct _PinosGlobal PinosGlobal; - -#include - -#include - -#include -#include -#include -#include -#include -#include - -typedef SpaResult (*PinosBindFunc) (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id); - -struct _PinosGlobal { - PinosCore *core; - PinosClient *owner; - SpaList link; - uint32_t id; - uint32_t type; - uint32_t version; - void *object; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosGlobal *global)); -}; - -/** - * PinosCore: - * - * Pinos core object class. - */ -struct _PinosCore { - PinosGlobal *global; - - PinosCoreInfo info; - - PinosProperties *properties; - - PinosType type; - PinosAccess *access; - - PinosMap objects; - - SpaList resource_list; - SpaList registry_resource_list; - SpaList global_list; - SpaList client_list; - SpaList node_list; - SpaList node_factory_list; - SpaList link_list; - - PinosMainLoop *main_loop; - PinosDataLoop *data_loop; - - SpaSupport *support; - uint32_t n_support; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosCore *core)); - - PINOS_SIGNAL (global_added, (PinosListener *listener, - PinosCore *core, - PinosGlobal *global)); - PINOS_SIGNAL (global_removed, (PinosListener *listener, - PinosCore *core, - PinosGlobal *global)); -}; - -PinosCore * pinos_core_new (PinosMainLoop *main_loop, - PinosProperties *props); -void pinos_core_destroy (PinosCore *core); - -void pinos_core_update_properties (PinosCore *core, - const SpaDict *dict); - -bool pinos_core_add_global (PinosCore *core, - PinosClient *owner, - uint32_t type, - uint32_t version, - void *object, - PinosBindFunc bind, - PinosGlobal **global); - -SpaResult pinos_global_bind (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id); -void pinos_global_destroy (PinosGlobal *global); - -SpaFormat * pinos_core_find_format (PinosCore *core, - PinosPort *output, - PinosPort *input, - PinosProperties *props, - uint32_t n_format_filters, - SpaFormat **format_filters, - char **error); - -PinosPort * pinos_core_find_port (PinosCore *core, - PinosPort *other_port, - uint32_t id, - PinosProperties *props, - uint32_t n_format_filters, - SpaFormat **format_filters, - char **error); - -PinosNodeFactory * pinos_core_find_node_factory (PinosCore *core, - const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_CORE_H__ */ diff --git a/pinos/server/link.h b/pinos/server/link.h deleted file mode 100644 index ad40062c7..000000000 --- a/pinos/server/link.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_LINK_H__ -#define __PINOS_LINK_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _PinosLink PinosLink; - -#include - -#include - -#include -#include -#include - -/** - * PinosLink: - * - * Pinos link interface. - */ -struct _PinosLink { - PinosCore *core; - SpaList link; - PinosGlobal *global; - - PinosProperties *properties; - - PinosLinkState state; - char *error; - PINOS_SIGNAL (state_changed, (PinosListener *listener, - PinosLink *link, - PinosLinkState old, - PinosLinkState state)); - - PINOS_SIGNAL (destroy_signal, (PinosListener *, - PinosLink *)); - PINOS_SIGNAL (free_signal, (PinosListener *, - PinosLink *)); - - SpaList resource_list; - - PinosPort *output; - SpaList output_link; - PinosPort *input; - SpaList input_link; - PINOS_SIGNAL (port_unlinked, (PinosListener *listener, - PinosLink *link, - PinosPort *port)); - - struct { - uint32_t in_ready; - PinosPort *input; - PinosPort *output; - SpaList input_link; - SpaList output_link; - } rt; -}; - - -PinosLink * pinos_link_new (PinosCore *core, - PinosPort *output, - PinosPort *input, - SpaFormat **format_filter, - PinosProperties *properties); -void pinos_link_destroy (PinosLink *link); - -bool pinos_link_activate (PinosLink *link); -bool pinos_link_deactivate (PinosLink *link); - -#ifdef __cplusplus -} -#endif - - -#endif /* __PINOS_LINK_H__ */ diff --git a/pinos/server/main-loop.c b/pinos/server/main-loop.c deleted file mode 100644 index f36154065..000000000 --- a/pinos/server/main-loop.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Pinos - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include "spa/list.h" -#include "spa/ringbuffer.h" -#include "pinos/client/log.h" -#include "pinos/server/main-loop.h" - -typedef struct -{ - PinosMainLoop this; - - bool running; -} PinosMainLoopImpl; - -/** - * pinos_main_loop_new: - * - * Create a new #PinosMainLoop. - * - * Returns: a new #PinosMainLoop - */ -PinosMainLoop * -pinos_main_loop_new (void) -{ - PinosMainLoopImpl *impl; - PinosMainLoop *this; - - impl = calloc (1, sizeof (PinosMainLoopImpl)); - if (impl == NULL) - return NULL; - - pinos_log_debug ("main-loop %p: new", impl); - this = &impl->this; - - this->loop = pinos_loop_new (); - if (this->loop == NULL) - goto no_loop; - - pinos_signal_init (&this->destroy_signal); - - return this; - -no_loop: - free (impl); - return NULL; -} - -void -pinos_main_loop_destroy (PinosMainLoop *loop) -{ - PinosMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosMainLoopImpl, this); - - pinos_log_debug ("main-loop %p: destroy", impl); - pinos_signal_emit (&loop->destroy_signal, loop); - - pinos_loop_destroy (loop->loop); - - free (impl); -} - -/** - * pinos_main_loop_quit: - * @loop: a #PinosMainLoop - * - * Stop the running @loop. - */ -void -pinos_main_loop_quit (PinosMainLoop *loop) -{ - PinosMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosMainLoopImpl, this); - pinos_log_debug ("main-loop %p: quit", impl); - impl->running = false; -} - -/** - * pinos_main_loop_run: - * @loop: a #PinosMainLoop - * - * Start running @loop. This function blocks until pinos_main_loop_quit() - * has been called. - */ -void -pinos_main_loop_run (PinosMainLoop *loop) -{ - PinosMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosMainLoopImpl, this); - - pinos_log_debug ("main-loop %p: run", impl); - - impl->running = true; - pinos_loop_enter (loop->loop); - while (impl->running) { - pinos_loop_iterate (loop->loop, -1); - } - pinos_loop_leave (loop->loop); -} diff --git a/pinos/server/node.h b/pinos/server/node.h deleted file mode 100644 index 7cba7c171..000000000 --- a/pinos/server/node.h +++ /dev/null @@ -1,139 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_NODE_H__ -#define __PINOS_NODE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define PINOS_TYPE__Node "Pinos:Object:Node" -#define PINOS_TYPE_NODE_BASE PINOS_TYPE__Node ":" - -typedef struct _PinosNode PinosNode; - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -/** - * PinosNode: - * - * Pinos node class. - */ -struct _PinosNode { - PinosCore *core; - SpaList link; - PinosGlobal *global; - - PinosClient *owner; - char *name; - PinosProperties *properties; - PinosNodeState state; - char *error; - PINOS_SIGNAL (state_request, (PinosListener *listener, - PinosNode *object, - PinosNodeState state)); - PINOS_SIGNAL (state_changed, (PinosListener *listener, - PinosNode *object, - PinosNodeState old, - PinosNodeState state)); - - SpaHandle *handle; - SpaNode *node; - bool live; - SpaClock *clock; - - SpaList resource_list; - - PINOS_SIGNAL (initialized, (PinosListener *listener, - PinosNode *object)); - - uint32_t max_input_ports; - uint32_t n_input_ports; - SpaList input_ports; - PinosPort **input_port_map; - uint32_t n_used_input_links; - - uint32_t max_output_ports; - uint32_t n_output_ports; - SpaList output_ports; - PinosPort **output_port_map; - uint32_t n_used_output_links; - - PINOS_SIGNAL (port_added, (PinosListener *listener, - PinosNode *node, - PinosPort *port)); - PINOS_SIGNAL (port_removed, (PinosListener *listener, - PinosNode *node, - PinosPort *port)); - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosNode *object)); - PINOS_SIGNAL (free_signal, (PinosListener *listener, - PinosNode *object)); - - PINOS_SIGNAL (async_complete, (PinosListener *listener, - PinosNode *node, - uint32_t seq, - SpaResult res)); - - PinosDataLoop *data_loop; - PINOS_SIGNAL (loop_changed, (PinosListener *listener, - PinosNode *object)); - -}; - -PinosNode * pinos_node_new (PinosCore *core, - PinosClient *owner, - const char *name, - bool async, - SpaNode *node, - SpaClock *clock, - PinosProperties *properties); -void pinos_node_destroy (PinosNode *node); - - -void pinos_node_set_data_loop (PinosNode *node, - PinosDataLoop *loop); - -PinosPort * pinos_node_get_free_port (PinosNode *node, - PinosDirection direction); - -SpaResult pinos_node_set_state (PinosNode *node, - PinosNodeState state); -void pinos_node_update_state (PinosNode *node, - PinosNodeState state, - char *error); - -#ifdef __cplusplus -} -#endif - - -#endif /* __PINOS_NODE_H__ */ diff --git a/pinos/server/port.h b/pinos/server/port.h deleted file mode 100644 index 1df0f6bbb..000000000 --- a/pinos/server/port.h +++ /dev/null @@ -1,94 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __PINOS_PORT_H__ -#define __PINOS_PORT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define PINOS_TYPE__Port "Pinos:Object:Port" -#define PINOS_TYPE_PORT_BASE PINOS_TYPE__Port ":" - -typedef struct _PinosPort PinosPort; - -#include - -#include -#include - -#include -#include - -typedef enum { - PINOS_PORT_STATE_ERROR = -1, - PINOS_PORT_STATE_INIT = 0, - PINOS_PORT_STATE_CONFIGURE = 1, - PINOS_PORT_STATE_READY = 2, - PINOS_PORT_STATE_PAUSED = 3, - PINOS_PORT_STATE_STREAMING = 4, -} PinosPortState; - -struct _PinosPort { - SpaList link; - - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, PinosPort *)); - - PinosNode *node; - PinosDirection direction; - uint32_t port_id; - PinosPortState state; - SpaPortIO io; - - bool allocated; - PinosMemblock buffer_mem; - SpaBuffer **buffers; - uint32_t n_buffers; - - SpaList links; - - struct { - SpaList links; - } rt; -}; - -PinosPort * pinos_port_new (PinosNode *node, - PinosDirection direction, - uint32_t port_id); -void pinos_port_destroy (PinosPort *port); - - -PinosLink * pinos_port_link (PinosPort *output_port, - PinosPort *input_port, - SpaFormat **format_filter, - PinosProperties *properties, - char **error); -SpaResult pinos_port_unlink (PinosPort *port, - PinosLink *link); - -SpaResult pinos_port_pause_rt (PinosPort *port); -SpaResult pinos_port_clear_buffers (PinosPort *port); - - -#ifdef __cplusplus -} -#endif - -#endif /* __PINOS_PORT_H__ */ diff --git a/pinos/server/resource.c b/pinos/server/resource.c deleted file mode 100644 index 718dc64b9..000000000 --- a/pinos/server/resource.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include - -#include "pinos/client/interfaces.h" -#include "pinos/server/resource.h" - -typedef struct { - PinosResource this; -} PinosResourceImpl; - -PinosResource * -pinos_resource_new (PinosClient *client, - uint32_t id, - uint32_t type, - void *object, - PinosDestroy destroy) -{ - PinosResourceImpl *impl; - PinosResource *this; - - impl = calloc (1, sizeof (PinosResourceImpl)); - if (impl == NULL) - return NULL; - - this = &impl->this; - this->core = client->core; - this->client = client; - this->type = type; - this->object = object; - this->destroy = destroy; - - pinos_signal_init (&this->destroy_signal); - - if (id == SPA_ID_INVALID) { - this->id = pinos_map_insert_new (&client->objects, this); - } else if (!pinos_map_insert_at (&client->objects, id, this)) - goto in_use; - - this->id = id; - - pinos_log_debug ("resource %p: new for client %p id %u", this, client, this->id); - pinos_signal_emit (&client->resource_added, client, this); - - return this; - -in_use: - pinos_log_debug ("resource %p: id %u in use for client %p", this, id, client); - free (impl); - return NULL; -} - -void -pinos_resource_destroy (PinosResource *resource) -{ - PinosClient *client = resource->client; - - pinos_log_trace ("resource %p: destroy %u", resource, resource->id); - pinos_signal_emit (&resource->destroy_signal, resource); - - pinos_map_insert_at (&client->objects, resource->id, NULL); - pinos_signal_emit (&client->resource_removed, client, resource); - - if (resource->destroy) - resource->destroy (resource); - - if (client->core_resource) - pinos_core_notify_remove_id (client->core_resource, resource->id); - - free (resource); -} diff --git a/pinos/tests/test-client.c b/pinos/tests/test-client.c deleted file mode 100644 index 6a9116337..000000000 --- a/pinos/tests/test-client.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Pinos - * Copyright (C) 2015 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include - -#define ANY_CAPS "ANY" - -static GMainLoop *loop; - -static void -on_stream_notify (GObject *gobject, - GParamSpec *pspec, - gpointer user_data) -{ - PinosStreamState state; - PinosStream *s = user_data; - - g_object_get (gobject, "state", &state, NULL); - g_print ("got stream state %d\n", state); - - switch (state) { - case PINOS_STREAM_STATE_ERROR: - g_main_loop_quit (loop); - break; - - case PINOS_STREAM_STATE_READY: - pinos_stream_start (s); - break; - - case PINOS_STREAM_STATE_STREAMING: - break; - - default: - break; - } -} - -static void -on_state_notify (GObject *gobject, - GParamSpec *pspec, - gpointer user_data) -{ - PinosContextState state; - PinosContext *c = user_data; - - g_object_get (gobject, "state", &state, NULL); - g_print ("got context state %d\n", state); - - switch (state) { - case PINOS_CONTEXT_STATE_ERROR: - g_main_loop_quit (loop); - break; - case PINOS_CONTEXT_STATE_CONNECTED: - { - PinosStream *stream; - GPtrArray *possible; - - stream = pinos_stream_new (c, "test", NULL); - g_signal_connect (stream, "notify::state", (GCallback) on_stream_notify, stream); - - possible = NULL; - pinos_stream_connect (stream, - PINOS_DIRECTION_OUTPUT, - PINOS_STREAM_MODE_BUFFER, - NULL, - 0, - possible); - break; - } - default: - break; - } -} - -gint -main (gint argc, gchar *argv[]) -{ - PinosContext *c; - - pinos_init (&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - - c = pinos_context_new (NULL, "test-client", NULL); - g_signal_connect (c, "notify::state", (GCallback) on_state_notify, c); - pinos_context_connect(c, PINOS_CONTEXT_FLAGS_NONE); - - g_main_loop_run (loop); - - g_object_unref (c); - - return 0; -} diff --git a/pinos/tools/meson.build b/pinos/tools/meson.build deleted file mode 100644 index 2588207ec..000000000 --- a/pinos/tools/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -executable('pinos-monitor', - 'pinos-monitor.c', - install: true, - dependencies : [pinos_dep], -) diff --git a/pinos.spec b/pipewire.spec similarity index 67% rename from pinos.spec rename to pipewire.spec index ae7c07d2a..d4acf3460 100644 --- a/pinos.spec +++ b/pipewire.spec @@ -11,18 +11,18 @@ # where/how to apply multilib hacks %global multilib_archs x86_64 %{ix86} ppc64 ppc s390x s390 sparc64 sparcv9 ppc64le -Name: pinos +Name: pipewire Summary: Media Sharing Server Version: 0.1 Release: 2%{?snap:.%{snap}git%{shortcommit}}%{?dist} License: LGPLv2+ -URL: http://www.freedesktop.org/wiki/Software/Pinos +URL: http://www.freedesktop.org/wiki/Software/PipeWire %if 0%{?gitrel} -# git clone git://anongit.freedesktop.org/gstreamer/pinos -# cd pinos; git reset --hard %{gitcommit}; ./autogen.sh; make; make distcheck -Source0: pinos-%{version}-%{gitrel}-g%{shortcommit}.tar.xz +# git clone git://anongit.freedesktop.org/gstreamer/pipewire +# cd pipewire; git reset --hard %{gitcommit}; ./autogen.sh; make; make distcheck +Source0: pipewire-%{version}-%{gitrel}-g%{shortcommit}.tar.xz %else -Source0: http://freedesktop.org/software/pinos/releases/pinos-%{version}.tar.xz +Source0: http://freedesktop.org/software/pipewire/releases/pipewire-%{version}.tar.xz %endif ## upstream patches @@ -51,32 +51,32 @@ Requires: systemd >= 184 Requires: rtkit %description -Pinos is a multimedia server for Linux and other Unix like operating +PipeWire is a multimedia server for Linux and other Unix like operating systems. %package libs -Summary: Libraries for Pinos clients +Summary: Libraries for PipeWire clients License: LGPLv2+ %description libs This package contains the runtime libraries for any application that wishes -to interface with a Pinos media server. +to interface with a PipeWire media server. %package libs-devel -Summary: Headers and libraries for Pinos client development +Summary: Headers and libraries for PipeWire client development License: LGPLv2+ Requires: %{name}-libs%{?_isa} = %{version}-%{release} %description libs-devel Headers and libraries for developing applications that can communicate with -a Pinos media server. +a PipeWire media server. %package utils -Summary: Pinos media server utilities +Summary: PipeWire media server utilities License: LGPLv2+ Requires: %{name}-libs%{?_isa} = %{version}-%{release} %description utils -This package contains command line utilities for the Pinos media server. +This package contains command line utilities for the PipeWire media server. %prep %setup -q -T -b0 -n %{name}-%{version}%{?gitrel:-%{gitrel}-g%{shortcommit}} @@ -97,9 +97,9 @@ sed -i -e 's|"/lib /usr/lib|"/%{_lib} %{_libdir}|' configure --disable-silent-rules \ --disable-static \ --disable-rpath \ - --with-system-user=pinos \ - --with-system-group=pinos \ - --with-access-group=pinos-access \ + --with-system-user=pipewire \ + --with-system-group=pipewire \ + --with-access-group=pipewire-access \ --disable-systemd-daemon \ --enable-tests @@ -123,9 +123,9 @@ make check \ %pre -getent group pinos >/dev/null || groupadd -r pinos -getent passwd pinos >/dev/null || \ - useradd -r -g pinos -d /var/run/pinos -s /sbin/nologin -c "Pinos System Daemon" pinos +getent group pipewire >/dev/null || groupadd -r pipewire +getent passwd pipewire >/dev/null || \ + useradd -r -g pipewire -d /var/run/pipewire -s /sbin/nologin -c "PipeWire System Daemon" pipewire exit 0 %post -p /sbin/ldconfig @@ -134,29 +134,29 @@ exit 0 %files %license LICENSE GPL LGPL %doc README -%{_sysconfdir}/xdg/autostart/pinos.desktop +%{_sysconfdir}/xdg/autostart/pipewire.desktop ## already owned by -libs, see also https://bugzilla.redhat.com/show_bug.cgi?id=909690 -#dir %{_sysconfdir}/pinos/ -%{_sysconfdir}/dbus-1/system.d/pinos-system.conf -%{_bindir}/pinos -%{_libdir}/libpinos-%{majorminor}.so -%{_libdir}/libpinoscore-%{majorminor}.so -%{_libdir}/gstreamer-1.0/libgstpinos.* -%{_mandir}/man1/pinos.1* +#dir %{_sysconfdir}/pipewire/ +%{_sysconfdir}/dbus-1/system.d/pipewire-system.conf +%{_bindir}/pipewire +%{_libdir}/libpipewire-%{majorminor}.so +%{_libdir}/libpipewirecore-%{majorminor}.so +%{_libdir}/gstreamer-1.0/libgstpipewire.* +%{_mandir}/man1/pipewire.1* -%files libs +%files libs %license LICENSE GPL LGPL %doc README -#%dir %{_sysconfdir}/pinos/ -#%dir %{_libdir}/pinos/ +#%dir %{_sysconfdir}/pipewire/ +#%dir %{_libdir}/pipewire/ %files libs-devel -%{_includedir}/pinos/ -%{_libdir}/pkgconfig/libpinos*.pc +%{_includedir}/pipewire/ +%{_libdir}/pkgconfig/libpipewire*.pc %files utils -%{_bindir}/pinos-monitor -%{_mandir}/man1/pinos-monitor.1* +%{_bindir}/pipewire-monitor +%{_mandir}/man1/pipewire-monitor.1* %changelog * Wed Sep 9 2015 Wim Taymans - 0.1.0-2 diff --git a/pipewire/.gitignore b/pipewire/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/pinos/client/.gitignore b/pipewire/client/.gitignore similarity index 100% rename from pinos/client/.gitignore rename to pipewire/client/.gitignore diff --git a/pinos/client/array.h b/pipewire/client/array.h similarity index 61% rename from pinos/client/array.h rename to pipewire/client/array.h index 35672f59e..5adf5000c 100644 --- a/pinos/client/array.h +++ b/pipewire/client/array.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,41 +17,39 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_ARRAY_H__ -#define __PINOS_ARRAY_H__ +#ifndef __PIPEWIRE_ARRAY_H__ +#define __PIPEWIRE_ARRAY_H__ #ifdef __cplusplus extern "C" { #endif -typedef struct _PinosArray PinosArray; - #include -struct _PinosArray { +struct pw_array { void *data; size_t size; size_t alloc; size_t extend; }; -#define PINOS_ARRAY_INIT(extend) { NULL, 0, 0, extend } +#define PW_ARRAY_INIT(extend) { NULL, 0, 0, extend } -#define pinos_array_get_len_s(a,s) ((a)->size / (s)) -#define pinos_array_get_unchecked_s(a,idx,s,t) SPA_MEMBER ((a)->data,(idx)*(s),t) -#define pinos_array_check_index_s(a,idx,s) ((idx) < pinos_array_get_len(a,s)) +#define pw_array_get_len_s(a,s) ((a)->size / (s)) +#define pw_array_get_unchecked_s(a,idx,s,t) SPA_MEMBER ((a)->data,(idx)*(s),t) +#define pw_array_check_index_s(a,idx,s) ((idx) < pw_array_get_len(a,s)) -#define pinos_array_get_len(a,t) pinos_array_get_len_s(a,sizeof(t)) -#define pinos_array_get_unchecked(a,idx,t) pinos_array_get_unchecked_s(a,idx,sizeof(t),t) -#define pinos_array_check_index(a,idx,t) pinos_array_check_index_s(a,idx,sizeof(t)) +#define pw_array_get_len(a,t) pw_array_get_len_s(a,sizeof(t)) +#define pw_array_get_unchecked(a,idx,t) pw_array_get_unchecked_s(a,idx,sizeof(t),t) +#define pw_array_check_index(a,idx,t) pw_array_check_index_s(a,idx,sizeof(t)) -#define pinos_array_for_each(pos, array) \ +#define pw_array_for_each(pos, array) \ for (pos = (array)->data; \ (const uint8_t *) pos < ((const uint8_t *) (array)->data + (array)->size); \ (pos)++) static inline void -pinos_array_init (PinosArray *arr, size_t extend) +pw_array_init (struct pw_array *arr, size_t extend) { arr->data = NULL; arr->size = arr->alloc = 0; @@ -59,14 +57,14 @@ pinos_array_init (PinosArray *arr, size_t extend) } static inline void -pinos_array_clear (PinosArray *arr) +pw_array_clear (struct pw_array *arr) { free (arr->data); } static inline bool -pinos_array_ensure_size (PinosArray *arr, - size_t size) +pw_array_ensure_size (struct pw_array *arr, + size_t size) { size_t alloc, need; @@ -87,12 +85,12 @@ pinos_array_ensure_size (PinosArray *arr, } static inline void * -pinos_array_add (PinosArray *arr, - size_t size) +pw_array_add (struct pw_array *arr, + size_t size) { void *p; - if (!pinos_array_ensure_size (arr, size)) + if (!pw_array_ensure_size (arr, size)) return NULL; p = arr->data + arr->size; @@ -102,8 +100,8 @@ pinos_array_add (PinosArray *arr, } static inline void * -pinos_array_add_fixed (PinosArray *arr, - size_t size) +pw_array_add_fixed (struct pw_array *arr, + size_t size) { void *p; @@ -116,11 +114,11 @@ pinos_array_add_fixed (PinosArray *arr, return p; } -#define pinos_array_add_ptr(a,p) \ - *((void**) pinos_array_add (a, sizeof (void*))) = (p) +#define pw_array_add_ptr(a,p) \ + *((void**) pw_array_add (a, sizeof (void*))) = (p) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __PINOS_ARRAY_H__ */ +#endif /* __PIPEWIRE_ARRAY_H__ */ diff --git a/pinos/client/connection.c b/pipewire/client/connection.c similarity index 72% rename from pinos/client/connection.c rename to pipewire/client/connection.c index efc540ed6..d69e8ae37 100644 --- a/pinos/client/connection.c +++ b/pipewire/client/connection.c @@ -1,4 +1,4 @@ -/* Simple Plugin API +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -31,7 +31,7 @@ #define MAX_BUFFER_SIZE 4096 #define MAX_FDS 28 -typedef struct { +struct buffer { uint8_t *buffer_data; size_t buffer_size; size_t buffer_maxsize; @@ -43,19 +43,19 @@ typedef struct { size_t size; bool update; -} ConnectionBuffer; +}; -typedef struct { - PinosConnection this; +struct pw_connection_impl { + struct pw_connection this; - ConnectionBuffer in, out; -} PinosConnectionImpl; + struct buffer in, out; +}; int -pinos_connection_get_fd (PinosConnection *conn, - uint32_t index) +pw_connection_get_fd (struct pw_connection *conn, + uint32_t index) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); if (index < 0 || index >= impl->in.n_fds) return -1; @@ -64,10 +64,10 @@ pinos_connection_get_fd (PinosConnection *conn, } uint32_t -pinos_connection_add_fd (PinosConnection *conn, - int fd) +pw_connection_add_fd (struct pw_connection *conn, + int fd) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); uint32_t index, i; for (i = 0; i < impl->out.n_fds; i++) { @@ -77,7 +77,7 @@ pinos_connection_add_fd (PinosConnection *conn, index = impl->out.n_fds; if (index >= MAX_FDS) { - pinos_log_error ("connection %p: too many fds", conn); + pw_log_error ("connection %p: too many fds", conn); return -1; } @@ -88,18 +88,20 @@ pinos_connection_add_fd (PinosConnection *conn, } static void * -connection_ensure_size (PinosConnection *conn, ConnectionBuffer *buf, size_t size) +connection_ensure_size (struct pw_connection *conn, struct buffer *buf, size_t size) { if (buf->buffer_size + size > buf->buffer_maxsize) { buf->buffer_maxsize = SPA_ROUND_UP_N (buf->buffer_size + size, MAX_BUFFER_SIZE); - pinos_log_warn ("connection %p: resize buffer to %zd %zd %zd", conn, buf->buffer_size, size, buf->buffer_maxsize); buf->buffer_data = realloc (buf->buffer_data, buf->buffer_maxsize); + + pw_log_warn ("connection %p: resize buffer to %zd %zd %zd", + conn, buf->buffer_size, size, buf->buffer_maxsize); } return (uint8_t *) buf->buffer_data + buf->buffer_size; } static bool -refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) +refill_buffer (struct pw_connection *conn, struct buffer *buf) { ssize_t len; struct cmsghdr *cmsg; @@ -136,20 +138,20 @@ refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) buf->n_fds = (cmsg->cmsg_len - ((char *)CMSG_DATA (cmsg) - (char *)cmsg)) / sizeof (int); memcpy (buf->fds, CMSG_DATA (cmsg), buf->n_fds * sizeof (int)); } - pinos_log_trace ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds); + pw_log_trace ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds); return true; /* ERRORS */ recv_error: { - pinos_log_error ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno)); + pw_log_error ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno)); return false; } } static void -clear_buffer (ConnectionBuffer *buf) +clear_buffer (struct buffer *buf) { buf->n_fds = 0; buf->offset = 0; @@ -157,23 +159,23 @@ clear_buffer (ConnectionBuffer *buf) buf->buffer_size = 0; } -PinosConnection * -pinos_connection_new (int fd) +struct pw_connection * +pw_connection_new (int fd) { - PinosConnectionImpl *impl; - PinosConnection *this; + struct pw_connection_impl *impl; + struct pw_connection *this; - impl = calloc (1, sizeof (PinosConnectionImpl)); + impl = calloc (1, sizeof (struct pw_connection_impl)); if (impl == NULL) return NULL; this = &impl->this; - pinos_log_debug ("connection %p: new", this); + pw_log_debug ("connection %p: new", this); this->fd = fd; - pinos_signal_init (&this->need_flush); - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->need_flush); + pw_signal_init (&this->destroy_signal); impl->out.buffer_data = malloc (MAX_BUFFER_SIZE); impl->out.buffer_maxsize = MAX_BUFFER_SIZE; @@ -194,13 +196,13 @@ no_mem: } void -pinos_connection_destroy (PinosConnection *conn) +pw_connection_destroy (struct pw_connection *conn) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); - pinos_log_debug ("connection %p: destroy", conn); + pw_log_debug ("connection %p: destroy", conn); - pinos_signal_emit (&conn->destroy_signal, conn); + pw_signal_emit (&conn->destroy_signal, conn); free (impl->out.buffer_data); free (impl->in.buffer_data); @@ -208,24 +210,24 @@ pinos_connection_destroy (PinosConnection *conn) } /** - * pinos_connection_has_next: - * @iter: a #PinosConnection + * pw_connection_has_next: + * @iter: a connection * * Move to the next packet in @conn. * * Returns: %true if more packets are available. */ bool -pinos_connection_get_next (PinosConnection *conn, +pw_connection_get_next (struct pw_connection *conn, uint8_t *opcode, uint32_t *dest_id, void **dt, uint32_t *sz) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); size_t len, size; uint8_t *data; - ConnectionBuffer *buf; + struct buffer *buf; uint32_t *p; buf = &impl->in; @@ -284,26 +286,26 @@ again: } void * -pinos_connection_begin_write (PinosConnection *conn, +pw_connection_begin_write (struct pw_connection *conn, uint32_t size) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); uint32_t *p; - ConnectionBuffer *buf = &impl->out; + struct buffer *buf = &impl->out; /* 4 for dest_id, 1 for opcode, 3 for size and size for payload */ p = connection_ensure_size (conn, buf, 8 + size); return p + 2; } void -pinos_connection_end_write (PinosConnection *conn, +pw_connection_end_write (struct pw_connection *conn, uint32_t dest_id, uint8_t opcode, uint32_t size) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); uint32_t *p; - ConnectionBuffer *buf = &impl->out; + struct buffer *buf = &impl->out; p = connection_ensure_size (conn, buf, 8 + size); *p++ = dest_id; @@ -313,20 +315,20 @@ pinos_connection_end_write (PinosConnection *conn, // spa_debug_pod (p); - pinos_signal_emit (&conn->need_flush, conn); + pw_signal_emit (&conn->need_flush, conn); } bool -pinos_connection_flush (PinosConnection *conn) +pw_connection_flush (struct pw_connection *conn) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); ssize_t len; struct msghdr msg = {0}; struct iovec iov[1]; struct cmsghdr *cmsg; char cmsgbuf[CMSG_SPACE (MAX_FDS * sizeof (int))]; int *cm, i, fds_len; - ConnectionBuffer *buf; + struct buffer *buf; buf = &impl->out; @@ -366,7 +368,7 @@ pinos_connection_flush (PinosConnection *conn) } break; } - pinos_log_trace ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds); + pw_log_trace ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds); buf->buffer_size -= len; buf->n_fds = 0; @@ -376,15 +378,15 @@ pinos_connection_flush (PinosConnection *conn) /* ERRORS */ send_error: { - pinos_log_error ("could not sendmsg: %s", strerror (errno)); + pw_log_error ("could not sendmsg: %s", strerror (errno)); return false; } } bool -pinos_connection_clear (PinosConnection *conn) +pw_connection_clear (struct pw_connection *conn) { - PinosConnectionImpl *impl = SPA_CONTAINER_OF (conn, PinosConnectionImpl, this); + struct pw_connection_impl *impl = SPA_CONTAINER_OF (conn, struct pw_connection_impl, this); clear_buffer (&impl->out); clear_buffer (&impl->in); diff --git a/pipewire/client/connection.h b/pipewire/client/connection.h new file mode 100644 index 000000000..e2b713786 --- /dev/null +++ b/pipewire/client/connection.h @@ -0,0 +1,67 @@ +/* PipeWire + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_CONNECTION_H__ +#define __PIPEWIRE_CONNECTION_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +struct pw_connection { + int fd; + + PW_SIGNAL (need_flush, (struct pw_listener *listener, + struct pw_connection *conn)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_connection *conn)); +}; + +struct pw_connection * pw_connection_new (int fd); +void pw_connection_destroy (struct pw_connection *conn); + +uint32_t pw_connection_add_fd (struct pw_connection *conn, + int fd); +int pw_connection_get_fd (struct pw_connection *conn, + uint32_t index); + +bool pw_connection_get_next (struct pw_connection *conn, + uint8_t *opcode, + uint32_t *dest_id, + void **data, + uint32_t *size); + +void * pw_connection_begin_write (struct pw_connection *conn, + uint32_t size); +void pw_connection_end_write (struct pw_connection *conn, + uint32_t dest_id, + uint8_t opcode, + uint32_t size); + +bool pw_connection_flush (struct pw_connection *conn); +bool pw_connection_clear (struct pw_connection *conn); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PIPEWIRE_CONNECTION_H__ */ diff --git a/pipewire/client/context.c b/pipewire/client/context.c new file mode 100644 index 000000000..7486a2978 --- /dev/null +++ b/pipewire/client/context.c @@ -0,0 +1,878 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include "pipewire/client/pipewire.h" + +#include "pipewire/client/context.h" +#include "pipewire/client/introspect.h" +#include "pipewire/client/protocol-native.h" +#include "pipewire/client/connection.h" +#include "pipewire/client/subscribe.h" + +struct context { + struct pw_context this; + + bool no_proxy; + + int fd; + struct pw_connection *connection; + SpaSource *source; + + bool disconnecting; + struct pw_listener need_flush; + SpaSource *flush_event; +}; + +/** + * pw_context_state_as_string: + * @state: a #enum pw_context_state + * + * Return the string representation of @state. + * + * Returns: the string representation of @state. + */ +const char * +pw_context_state_as_string (enum pw_context_state state) +{ + switch (state) { + case PW_CONTEXT_STATE_ERROR: + return "error"; + case PW_CONTEXT_STATE_UNCONNECTED: + return "unconnected"; + case PW_CONTEXT_STATE_CONNECTING: + return "connecting"; + case PW_CONTEXT_STATE_CONNECTED: + return "connected"; + } + return "invalid-state"; +} + +static void +context_set_state (struct pw_context *context, + enum pw_context_state state, + const char *fmt, + ...) +{ + if (context->state != state) { + + if (context->error) + free (context->error); + + if (fmt) { + va_list varargs; + + va_start (varargs, fmt); + vasprintf (&context->error, fmt, varargs); + va_end (varargs); + } else { + context->error = NULL; + } + pw_log_debug ("context %p: update state from %s -> %s (%s)", context, + pw_context_state_as_string (context->state), + pw_context_state_as_string (state), + context->error); + + context->state = state; + pw_signal_emit (&context->state_changed, context); + } +} + +static void +core_event_info (void *object, + struct pw_core_info *info) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + enum pw_subscription_event event; + + pw_log_debug ("got core info"); + + if (proxy->user_data == NULL) + event = PW_SUBSCRIPTION_EVENT_NEW; + else + event = PW_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pw_core_info_update (proxy->user_data, info); + + pw_signal_emit (&this->subscription, + this, + event, + proxy->type, + proxy->id); +} + +static void +core_event_done (void *object, + uint32_t seq) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + + if (seq == 0) { + pw_core_do_sync (this->core_proxy, 1); + } else if (seq == 1) { + context_set_state (this, PW_CONTEXT_STATE_CONNECTED, NULL); + } +} + +static void +core_event_error (void *object, + uint32_t id, + SpaResult res, + const char *error, ...) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + context_set_state (this, PW_CONTEXT_STATE_ERROR, error); +} + +static void +core_event_remove_id (void *object, + uint32_t id) +{ + struct pw_proxy *core_proxy = object; + struct pw_context *this = core_proxy->context; + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&this->objects, id); + if (proxy) { + pw_log_debug ("context %p: object remove %u", this, id); + pw_proxy_destroy (proxy); + } +} + +static void +core_event_update_types (void *object, + uint32_t first_id, + uint32_t n_types, + const char **types) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + int i; + + for (i = 0; i < n_types; i++, first_id++) { + SpaType this_id = spa_type_map_get_id (this->type.map, types[i]); + if (!pw_map_insert_at (&this->types, first_id, PW_MAP_ID_TO_PTR (this_id))) + pw_log_error ("can't add type for client"); + } +} + +static const struct pw_core_events core_events = { + &core_event_info, + &core_event_done, + &core_event_error, + &core_event_remove_id, + &core_event_update_types +}; + +static void +module_event_info (void *object, + struct pw_module_info *info) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + enum pw_subscription_event event; + + pw_log_debug ("got module info"); + + if (proxy->user_data == NULL) + event = PW_SUBSCRIPTION_EVENT_NEW; + else + event = PW_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pw_module_info_update (proxy->user_data, info); + + pw_signal_emit (&this->subscription, + this, + event, + proxy->type, + proxy->id); +} + +static const struct pw_module_events module_events = { + &module_event_info, +}; + +static void +node_event_info (void *object, + struct pw_node_info *info) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + enum pw_subscription_event event; + + pw_log_debug ("got node info"); + + if (proxy->user_data == NULL) + event = PW_SUBSCRIPTION_EVENT_NEW; + else + event = PW_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pw_node_info_update (proxy->user_data, info); + + pw_signal_emit (&this->subscription, + this, + event, + proxy->type, + proxy->id); +} + +static const struct pw_node_events node_events = { + &node_event_info +}; + +static void +client_event_info (void *object, + struct pw_client_info *info) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + enum pw_subscription_event event; + + pw_log_debug ("got client info"); + + if (proxy->user_data == NULL) + event = PW_SUBSCRIPTION_EVENT_NEW; + else + event = PW_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pw_client_info_update (proxy->user_data, info); + + pw_signal_emit (&this->subscription, + this, + event, + proxy->type, + proxy->id); +} + +static const struct pw_client_events client_events = { + &client_event_info +}; + +static void +link_event_info (void *object, + struct pw_link_info *info) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + enum pw_subscription_event event; + + pw_log_debug ("got link info"); + + if (proxy->user_data == NULL) + event = PW_SUBSCRIPTION_EVENT_NEW; + else + event = PW_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pw_link_info_update (proxy->user_data, info); + + pw_signal_emit (&this->subscription, + this, + event, + proxy->type, + proxy->id); +} + +static const struct pw_link_events link_events = { + &link_event_info +}; + +static void +registry_event_global (void *object, + uint32_t id, + const char *type) +{ + struct pw_proxy *registry_proxy = object; + struct pw_context *this = registry_proxy->context; + struct context *impl = SPA_CONTAINER_OF (this, struct context, this); + struct pw_proxy *proxy = NULL; + + if (impl->no_proxy) + return; + + pw_log_debug ("got global %u %s", id, type); + + if (!strcmp (type, PIPEWIRE_TYPE__Node)) { + proxy = pw_proxy_new (this, + SPA_ID_INVALID, + this->type.node); + if (proxy == NULL) + goto no_mem; + + proxy->implementation = &node_events; + } else if (!strcmp (type, PIPEWIRE_TYPE__Module)) { + proxy = pw_proxy_new (this, + SPA_ID_INVALID, + this->type.module); + if (proxy == NULL) + goto no_mem; + + proxy->implementation = &module_events; + } else if (!strcmp (type, PIPEWIRE_TYPE__Client)) { + proxy = pw_proxy_new (this, + SPA_ID_INVALID, + this->type.client); + if (proxy == NULL) + goto no_mem; + + proxy->implementation = &client_events; + } else if (!strcmp (type, PIPEWIRE_TYPE__Link)) { + proxy = pw_proxy_new (this, + SPA_ID_INVALID, + this->type.link); + if (proxy == NULL) + goto no_mem; + + proxy->implementation = &link_events; + } + if (proxy) { + pw_registry_do_bind (registry_proxy, id, proxy->id); + } + + return; + +no_mem: + pw_log_error ("context %p: failed to create proxy", this); + return; +} + +static void +registry_event_global_remove (void *object, + uint32_t id) +{ + struct pw_proxy *proxy = object; + struct pw_context *this = proxy->context; + + pw_log_debug ("got global remove %u", id); + + pw_signal_emit (&this->subscription, + this, + PW_SUBSCRIPTION_EVENT_REMOVE, + SPA_ID_INVALID, + id); +} + +static const struct pw_registry_events registry_events = { + ®istry_event_global, + ®istry_event_global_remove +}; + +typedef bool (*demarshal_func_t) (void *object, void *data, size_t size); + +static void +do_flush_event (SpaLoopUtils *utils, + SpaSource *source, + void *data) +{ + struct context *impl = data; + if (impl->connection) + if (!pw_connection_flush (impl->connection)) + pw_context_disconnect (&impl->this); +} + +static void +on_need_flush (struct pw_listener *listener, + struct pw_connection *connection) +{ + struct context *impl = SPA_CONTAINER_OF (listener, struct context, need_flush); + struct pw_context *this = &impl->this; + pw_loop_signal_event (this->loop, impl->flush_event); +} + +static void +on_context_data (SpaLoopUtils *utils, + SpaSource *source, + int fd, + SpaIO mask, + void *data) +{ + struct context *impl = data; + struct pw_context *this = &impl->this; + struct pw_connection *conn = impl->connection; + + if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { + context_set_state (this, + PW_CONTEXT_STATE_ERROR, + "connection closed"); + return; + } + + if (mask & SPA_IO_IN) { + uint8_t opcode; + uint32_t id; + uint32_t size; + void *message; + + while (!impl->disconnecting + && pw_connection_get_next (conn, &opcode, &id, &message, &size)) { + struct pw_proxy *proxy; + const demarshal_func_t *demarshal; + + pw_log_trace ("context %p: got message %d from %u", this, opcode, id); + + proxy = pw_map_lookup (&this->objects, id); + if (proxy == NULL) { + pw_log_error ("context %p: could not find proxy %u", this, id); + continue; + } + if (opcode >= proxy->iface->n_events) { + pw_log_error ("context %p: invalid method %u for %u", this, opcode, id); + continue; + } + + demarshal = proxy->iface->events; + if (demarshal[opcode]) { + if (!demarshal[opcode] (proxy, message, size)) + pw_log_error ("context %p: invalid message received %u for %u", this, opcode, id); + } else + pw_log_error ("context %p: function %d not implemented on %u", this, opcode, id); + + } + } +} + +/** + * pw_context_new: + * @context: a #GMainContext to run in + * @name: an application name + * @properties: (transfer full): optional properties + * + * Make a new unconnected #struct pw_context + * + * Returns: a new unconnected #struct pw_context + */ +struct pw_context * +pw_context_new (struct pw_loop *loop, + const char *name, + struct pw_properties *properties) +{ + struct context *impl; + struct pw_context *this; + + impl = calloc (1, sizeof (struct context)); + if (impl == NULL) + return NULL; + + impl->fd = -1; + + this = &impl->this; + pw_log_debug ("context %p: new", impl); + + this->name = strdup (name); + + if (properties == NULL) + properties = pw_properties_new ("application.name", name, NULL); + if (properties == NULL) + goto no_mem; + + pw_fill_context_properties (properties); + this->properties = properties; + + pw_type_init (&this->type); + + this->loop = loop; + + impl->flush_event = pw_loop_add_event (loop, do_flush_event, impl); + + this->state = PW_CONTEXT_STATE_UNCONNECTED; + + pw_map_init (&this->objects, 64, 32); + pw_map_init (&this->types, 64, 32); + + spa_list_init (&this->stream_list); + spa_list_init (&this->global_list); + spa_list_init (&this->proxy_list); + + pw_signal_init (&this->state_changed); + pw_signal_init (&this->subscription); + pw_signal_init (&this->destroy_signal); + + return this; + +no_mem: + free (this->name); + free (impl); + return NULL; +} + +void +pw_context_destroy (struct pw_context *context) +{ + struct context *impl = SPA_CONTAINER_OF (context, struct context, this); + struct pw_stream *stream, *t1; + struct pw_proxy *proxy, *t2; + + pw_log_debug ("context %p: destroy", context); + pw_signal_emit (&context->destroy_signal, context); + + pw_loop_destroy_source (impl->this.loop, impl->flush_event); + + if (context->state != PW_CONTEXT_STATE_UNCONNECTED) + pw_context_disconnect (context); + + spa_list_for_each_safe (stream, t1, &context->stream_list, link) + pw_stream_destroy (stream); + spa_list_for_each_safe (proxy, t2, &context->proxy_list, link) + pw_proxy_destroy (proxy); + + pw_map_clear (&context->objects); + + free (context->name); + if (context->properties) + pw_properties_free (context->properties); + free (context->error); + free (impl); +} + +/** + * pw_context_connect: + * @context: a #struct pw_context + * + * Connect to the daemon + * + * Returns: %TRUE on success. + */ +bool +pw_context_connect (struct pw_context *context, + enum pw_context_flags flags) +{ + struct sockaddr_un addr; + socklen_t size; + const char *runtime_dir, *name = NULL; + int name_size, fd; + + if ((runtime_dir = getenv ("XDG_RUNTIME_DIR")) == NULL) { + context_set_state (context, + PW_CONTEXT_STATE_ERROR, + "connect failed: XDG_RUNTIME_DIR not set in the environment"); + return false; + } + + if (name == NULL) + name = getenv("PIPEWIRE_CORE"); + if (name == NULL) + name = "pipewire-0"; + + if ((fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) + return false; + + memset (&addr, 0, sizeof (addr)); + addr.sun_family = AF_LOCAL; + name_size = snprintf (addr.sun_path, sizeof (addr.sun_path), + "%s/%s", runtime_dir, name) + 1; + + if (name_size > (int)sizeof addr.sun_path) { + pw_log_error ("socket path \"%s/%s\" plus null terminator exceeds 108 bytes", + runtime_dir, name); + goto error_close; + }; + + size = offsetof (struct sockaddr_un, sun_path) + name_size; + + if (connect (fd, (struct sockaddr *) &addr, size) < 0) { + context_set_state (context, + PW_CONTEXT_STATE_ERROR, + "connect failed: %s", strerror (errno)); + goto error_close; + } + + return pw_context_connect_fd (context, flags, fd); + +error_close: + close (fd); + return false; +} + +/** + * pw_context_connect_fd: + * @context: a #struct pw_context + * @fd: FD of a connected PipeWire socket + * + * Connect to a daemon. @fd should already be connected to a PipeWire socket. + * + * Returns: %TRUE on success. + */ +bool +pw_context_connect_fd (struct pw_context *context, + enum pw_context_flags flags, + int fd) +{ + struct context *impl = SPA_CONTAINER_OF (context, struct context, this); + + context_set_state (context, PW_CONTEXT_STATE_CONNECTING, NULL); + + impl->connection = pw_connection_new (fd); + if (impl->connection == NULL) + goto error_close; + + context->protocol_private = impl->connection; + + pw_signal_add (&impl->connection->need_flush, + &impl->need_flush, + on_need_flush); + + impl->fd = fd; + + impl->source = pw_loop_add_io (context->loop, + fd, + SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR, + false, + on_context_data, + impl); + + context->core_proxy = pw_proxy_new (context, + 0, + context->type.core); + if (context->core_proxy == NULL) + goto no_proxy; + + context->core_proxy->implementation = &core_events; + + pw_core_do_client_update (context->core_proxy, + &context->properties->dict); + + if (!(flags & PW_CONTEXT_FLAG_NO_REGISTRY)) { + context->registry_proxy = pw_proxy_new (context, + SPA_ID_INVALID, + context->type.registry); + if (context->registry_proxy == NULL) + goto no_registry; + + context->registry_proxy->implementation = ®istry_events; + + pw_core_do_get_registry (context->core_proxy, + context->registry_proxy->id); + + } + impl->no_proxy = !!(flags & PW_CONTEXT_FLAG_NO_PROXY); + + pw_core_do_sync (context->core_proxy, 0); + + return true; + +no_registry: + pw_proxy_destroy (context->core_proxy); +no_proxy: + pw_loop_destroy_source (context->loop, impl->source); + pw_connection_destroy (impl->connection); +error_close: + close (fd); + return false; +} + +/** + * pw_context_disconnect: + * @context: a #struct pw_context + * + * Disonnect from the daemon. + * + * Returns: %TRUE on success. + */ +bool +pw_context_disconnect (struct pw_context *context) +{ + struct context *impl = SPA_CONTAINER_OF (context, struct context, this); + + impl->disconnecting = true; + + if (impl->source) + pw_loop_destroy_source (context->loop, impl->source); + impl->source = NULL; + + if (context->registry_proxy) + pw_proxy_destroy (context->registry_proxy); + context->registry_proxy = NULL; + + if (context->core_proxy) + pw_proxy_destroy (context->core_proxy); + context->core_proxy = NULL; + + if (impl->connection) + pw_connection_destroy (impl->connection); + impl->connection = NULL; + context->protocol_private = NULL; + + if (impl->fd != -1) + close (impl->fd); + impl->fd = -1; + + context_set_state (context, PW_CONTEXT_STATE_UNCONNECTED, NULL); + + return true; +} + +void +pw_context_get_core_info (struct pw_context *context, + pw_core_info_cb_t cb, + void *user_data) +{ + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&context->objects, 0); + if (proxy == NULL) { + cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); + } else if (proxy->type == context->type.core && proxy->user_data) { + struct pw_core_info *info = proxy->user_data; + cb (context, SPA_RESULT_OK, info, user_data); + info->change_mask = 0; + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} + +typedef void (*list_func_t) (struct pw_context *, SpaResult, void *, void *); + +static void +do_list (struct pw_context *context, + uint32_t type, + list_func_t cb, + void *user_data) +{ + union pw_map_item *item; + + pw_array_for_each (item, &context->objects.items) { + struct pw_proxy *proxy; + + if (pw_map_item_is_free (item)) + continue; + + proxy = item->data; + if (proxy->type != type) + continue; + + if (proxy->user_data) + cb (context, SPA_RESULT_OK, proxy->user_data, user_data); + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} + + +void +pw_context_list_module_info (struct pw_context *context, + pw_module_info_cb_t cb, + void *user_data) +{ + do_list (context, context->type.module, (list_func_t) cb, user_data); +} + +void +pw_context_get_module_info_by_id (struct pw_context *context, + uint32_t id, + pw_module_info_cb_t cb, + void *user_data) +{ + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&context->objects, id); + if (proxy == NULL) { + cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); + } else if (proxy->type == context->type.module && proxy->user_data) { + struct pw_module_info *info = proxy->user_data; + cb (context, SPA_RESULT_OK, info, user_data); + info->change_mask = 0; + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} + +void +pw_context_list_client_info (struct pw_context *context, + pw_client_info_cb_t cb, + void *user_data) +{ + do_list (context, context->type.client, (list_func_t) cb, user_data); +} + +void +pw_context_get_client_info_by_id (struct pw_context *context, + uint32_t id, + pw_client_info_cb_t cb, + void *user_data) +{ + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&context->objects, id); + if (proxy == NULL) { + cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); + } else if (proxy->type == context->type.client && proxy->user_data) { + struct pw_client_info *info = proxy->user_data; + cb (context, SPA_RESULT_OK, info, user_data); + info->change_mask = 0; + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} + +void +pw_context_list_node_info (struct pw_context *context, + pw_node_info_cb_t cb, + void *user_data) +{ + do_list (context, context->type.node, (list_func_t) cb, user_data); +} + +void +pw_context_get_node_info_by_id (struct pw_context *context, + uint32_t id, + pw_node_info_cb_t cb, + void *user_data) +{ + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&context->objects, id); + if (proxy == NULL) { + cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); + } else if (proxy->type == context->type.node && proxy->user_data) { + struct pw_node_info *info = proxy->user_data; + cb (context, SPA_RESULT_OK, info, user_data); + info->change_mask = 0; + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} + +void +pw_context_list_link_info (struct pw_context *context, + pw_link_info_cb_t cb, + void *user_data) +{ + do_list (context, context->type.link, (list_func_t) cb, user_data); +} + +void +pw_context_get_link_info_by_id (struct pw_context *context, + uint32_t id, + pw_link_info_cb_t cb, + void *user_data) +{ + struct pw_proxy *proxy; + + proxy = pw_map_lookup (&context->objects, id); + if (proxy == NULL) { + cb (context, SPA_RESULT_INVALID_OBJECT_ID, NULL, user_data); + } else if (proxy->type == context->type.link && proxy->user_data) { + struct pw_link_info *info = proxy->user_data; + cb (context, SPA_RESULT_OK, info, user_data); + info->change_mask = 0; + } + cb (context, SPA_RESULT_ENUM_END, NULL, user_data); +} diff --git a/pipewire/client/context.h b/pipewire/client/context.h new file mode 100644 index 000000000..b345afd32 --- /dev/null +++ b/pipewire/client/context.h @@ -0,0 +1,115 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_CONTEXT_H__ +#define __PIPEWIRE_CONTEXT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include + +/** + * pw_context_state: + * @PW_CONTEXT_STATE_ERROR: context is in error + * @PW_CONTEXT_STATE_UNCONNECTED: not connected + * @PW_CONTEXT_STATE_CONNECTING: connecting to daemon + * @PW_CONTEXT_STATE_CONNECTED: context is connected and ready + * + * The state of a pw_context + */ +enum pw_context_state { + PW_CONTEXT_STATE_ERROR = -1, + PW_CONTEXT_STATE_UNCONNECTED = 0, + PW_CONTEXT_STATE_CONNECTING = 1, + PW_CONTEXT_STATE_CONNECTED = 2, +}; + +const char * pw_context_state_as_string (enum pw_context_state state); + +enum pw_context_flags { + PW_CONTEXT_FLAG_NONE = 0, + PW_CONTEXT_FLAG_NO_REGISTRY = (1 << 0), + PW_CONTEXT_FLAG_NO_PROXY = (1 << 1), +}; + +/** + * pw_context: + * + * PipeWire context object class. + */ +struct pw_context { + char *name; + struct pw_properties *properties; + + struct pw_type type; + + struct pw_loop *loop; + + struct pw_proxy *core_proxy; + struct pw_proxy *registry_proxy; + + struct pw_map objects; + uint32_t n_types; + struct pw_map types; + + SpaList global_list; + SpaList stream_list; + SpaList proxy_list; + + void *protocol_private; + + enum pw_context_state state; + char *error; + PW_SIGNAL (state_changed, (struct pw_listener *listener, + struct pw_context *context)); + + PW_SIGNAL (subscription, (struct pw_listener *listener, + struct pw_context *context, + enum pw_subscription_event event, + uint32_t type, + uint32_t id)); + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_context *context)); +}; + +struct pw_context * pw_context_new (struct pw_loop *loop, + const char *name, + struct pw_properties *properties); +void pw_context_destroy (struct pw_context *context); + +bool pw_context_connect (struct pw_context *context, + enum pw_context_flags flags); +bool pw_context_connect_fd (struct pw_context *context, + enum pw_context_flags flags, + int fd); +bool pw_context_disconnect (struct pw_context *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_CONTEXT_H__ */ diff --git a/pinos/client/interfaces.h b/pipewire/client/interfaces.h similarity index 51% rename from pinos/client/interfaces.h rename to pipewire/client/interfaces.h index ce3980f0f..75b9c0b37 100644 --- a/pinos/client/interfaces.h +++ b/pipewire/client/interfaces.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_INTERFACES_H__ -#define __PINOS_INTERFACES_H__ +#ifndef __PIPEWIRE_INTERFACES_H__ +#define __PIPEWIRE_INTERFACES_H__ #ifdef __cplusplus extern "C" { @@ -30,27 +30,17 @@ extern "C" { #include #include -typedef struct _PinosClientNodeBuffer PinosClientNodeBuffer; -typedef struct _PinosInterface PinosInterface; +#include -#include +#define PW_CORE_METHOD_CLIENT_UPDATE 0 +#define PW_CORE_METHOD_SYNC 1 +#define PW_CORE_METHOD_GET_REGISTRY 2 +#define PW_CORE_METHOD_CREATE_NODE 3 +#define PW_CORE_METHOD_CREATE_CLIENT_NODE 4 +#define PW_CORE_METHOD_UPDATE_TYPES 5 +#define PW_CORE_METHOD_NUM 6 -struct _PinosInterface { - uint32_t n_methods; - const void *methods; - uint32_t n_events; - const void *events; -}; - -#define PINOS_CORE_METHOD_CLIENT_UPDATE 0 -#define PINOS_CORE_METHOD_SYNC 1 -#define PINOS_CORE_METHOD_GET_REGISTRY 2 -#define PINOS_CORE_METHOD_CREATE_NODE 3 -#define PINOS_CORE_METHOD_CREATE_CLIENT_NODE 4 -#define PINOS_CORE_METHOD_UPDATE_TYPES 5 -#define PINOS_CORE_METHOD_NUM 6 - -typedef struct { +struct pw_core_methods { void (*client_update) (void *object, const SpaDict *props); void (*sync) (void *object, @@ -70,25 +60,25 @@ typedef struct { uint32_t first_id, uint32_t n_types, const char **types); -} PinosCoreMethods; +}; -#define pinos_core_do_client_update(r,...) ((PinosCoreMethods*)r->iface->methods)->client_update(r,__VA_ARGS__) -#define pinos_core_do_sync(r,...) ((PinosCoreMethods*)r->iface->methods)->sync(r,__VA_ARGS__) -#define pinos_core_do_get_registry(r,...) ((PinosCoreMethods*)r->iface->methods)->get_registry(r,__VA_ARGS__) -#define pinos_core_do_create_node(r,...) ((PinosCoreMethods*)r->iface->methods)->create_node(r,__VA_ARGS__) -#define pinos_core_do_create_client_node(r,...) ((PinosCoreMethods*)r->iface->methods)->create_client_node(r,__VA_ARGS__) -#define pinos_core_do_update_types(r,...) ((PinosCoreMethods*)r->iface->methods)->update_types(r,__VA_ARGS__) +#define pw_core_do_client_update(r,...) ((struct pw_core_methods*)r->iface->methods)->client_update(r,__VA_ARGS__) +#define pw_core_do_sync(r,...) ((struct pw_core_methods*)r->iface->methods)->sync(r,__VA_ARGS__) +#define pw_core_do_get_registry(r,...) ((struct pw_core_methods*)r->iface->methods)->get_registry(r,__VA_ARGS__) +#define pw_core_do_create_node(r,...) ((struct pw_core_methods*)r->iface->methods)->create_node(r,__VA_ARGS__) +#define pw_core_do_create_client_node(r,...) ((struct pw_core_methods*)r->iface->methods)->create_client_node(r,__VA_ARGS__) +#define pw_core_do_update_types(r,...) ((struct pw_core_methods*)r->iface->methods)->update_types(r,__VA_ARGS__) -#define PINOS_CORE_EVENT_INFO 0 -#define PINOS_CORE_EVENT_DONE 1 -#define PINOS_CORE_EVENT_ERROR 2 -#define PINOS_CORE_EVENT_REMOVE_ID 3 -#define PINOS_CORE_EVENT_UPDATE_TYPES 4 -#define PINOS_CORE_EVENT_NUM 5 +#define PW_CORE_EVENT_INFO 0 +#define PW_CORE_EVENT_DONE 1 +#define PW_CORE_EVENT_ERROR 2 +#define PW_CORE_EVENT_REMOVE_ID 3 +#define PW_CORE_EVENT_UPDATE_TYPES 4 +#define PW_CORE_EVENT_NUM 5 -typedef struct { +struct pw_core_events { void (*info) (void *object, - PinosCoreInfo *info); + struct pw_core_info *info); void (*done) (void *object, uint32_t seq); void (*error) (void *object, @@ -101,79 +91,79 @@ typedef struct { uint32_t first_id, uint32_t n_types, const char **types); -} PinosCoreEvents; +}; -#define pinos_core_notify_info(r,...) ((PinosCoreEvents*)r->iface->events)->info(r,__VA_ARGS__) -#define pinos_core_notify_done(r,...) ((PinosCoreEvents*)r->iface->events)->done(r,__VA_ARGS__) -#define pinos_core_notify_error(r,...) ((PinosCoreEvents*)r->iface->events)->error(r,__VA_ARGS__) -#define pinos_core_notify_remove_id(r,...) ((PinosCoreEvents*)r->iface->events)->remove_id(r,__VA_ARGS__) -#define pinos_core_notify_update_types(r,...) ((PinosCoreEvents*)r->iface->events)->update_types(r,__VA_ARGS__) +#define pw_core_notify_info(r,...) ((struct pw_core_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_core_notify_done(r,...) ((struct pw_core_events*)r->iface->events)->done(r,__VA_ARGS__) +#define pw_core_notify_error(r,...) ((struct pw_core_events*)r->iface->events)->error(r,__VA_ARGS__) +#define pw_core_notify_remove_id(r,...) ((struct pw_core_events*)r->iface->events)->remove_id(r,__VA_ARGS__) +#define pw_core_notify_update_types(r,...) ((struct pw_core_events*)r->iface->events)->update_types(r,__VA_ARGS__) -#define PINOS_REGISTRY_METHOD_BIND 0 -#define PINOS_REGISTRY_METHOD_NUM 1 +#define PW_REGISTRY_METHOD_BIND 0 +#define PW_REGISTRY_METHOD_NUM 1 -typedef struct { +struct pw_registry_methods { void (*bind) (void *object, uint32_t id, uint32_t new_id); -} PinosRegistryMethods; +}; -#define pinos_registry_do_bind(r,...) ((PinosRegistryMethods*)r->iface->methods)->bind(r,__VA_ARGS__) +#define pw_registry_do_bind(r,...) ((struct pw_registry_methods*)r->iface->methods)->bind(r,__VA_ARGS__) -#define PINOS_REGISTRY_EVENT_GLOBAL 0 -#define PINOS_REGISTRY_EVENT_GLOBAL_REMOVE 1 -#define PINOS_REGISTRY_EVENT_NUM 2 +#define PW_REGISTRY_EVENT_GLOBAL 0 +#define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1 +#define PW_REGISTRY_EVENT_NUM 2 -typedef struct { +struct pw_registry_events { void (*global) (void *object, uint32_t id, const char *type); void (*global_remove) (void *object, uint32_t id); -} PinosRegistryEvents; +}; -#define pinos_registry_notify_global(r,...) ((PinosRegistryEvents*)r->iface->events)->global(r,__VA_ARGS__) -#define pinos_registry_notify_global_remove(r,...) ((PinosRegistryEvents*)r->iface->events)->global_remove(r,__VA_ARGS__) +#define pw_registry_notify_global(r,...) ((struct pw_registry_events*)r->iface->events)->global(r,__VA_ARGS__) +#define pw_registry_notify_global_remove(r,...) ((struct pw_registry_events*)r->iface->events)->global_remove(r,__VA_ARGS__) -#define PINOS_MODULE_EVENT_INFO 0 -#define PINOS_MODULE_EVENT_NUM 1 +#define PW_MODULE_EVENT_INFO 0 +#define PW_MODULE_EVENT_NUM 1 -typedef struct { +struct pw_module_events { void (*info) (void *object, - PinosModuleInfo *info); -} PinosModuleEvents; + struct pw_module_info *info); +}; -#define pinos_module_notify_info(r,...) ((PinosModuleEvents*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_module_notify_info(r,...) ((struct pw_module_events*)r->iface->events)->info(r,__VA_ARGS__) -#define PINOS_NODE_EVENT_INFO 0 -#define PINOS_NODE_EVENT_NUM 1 +#define PW_NODE_EVENT_INFO 0 +#define PW_NODE_EVENT_NUM 1 -typedef struct { +struct pw_node_events { void (*info) (void *object, - PinosNodeInfo *info); -} PinosNodeEvents; + struct pw_node_info *info); +}; -#define pinos_node_notify_info(r,...) ((PinosNodeEvents*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_node_notify_info(r,...) ((struct pw_node_events*)r->iface->events)->info(r,__VA_ARGS__) -struct _PinosClientNodeBuffer { +struct pw_client_node_buffer { uint32_t mem_id; uint32_t offset; uint32_t size; SpaBuffer *buffer; }; -#define PINOS_CLIENT_NODE_METHOD_UPDATE 0 -#define PINOS_CLIENT_NODE_METHOD_PORT_UPDATE 1 -#define PINOS_CLIENT_NODE_METHOD_EVENT 2 -#define PINOS_CLIENT_NODE_METHOD_DESTROY 3 -#define PINOS_CLIENT_NODE_METHOD_NUM 4 +#define PW_CLIENT_NODE_METHOD_UPDATE 0 +#define PW_CLIENT_NODE_METHOD_PORT_UPDATE 1 +#define PW_CLIENT_NODE_METHOD_EVENT 2 +#define PW_CLIENT_NODE_METHOD_DESTROY 3 +#define PW_CLIENT_NODE_METHOD_NUM 4 -typedef struct { +struct pw_client_node_methods { void (*update) (void *object, -#define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0) -#define PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS (1 << 1) -#define PINOS_MESSAGE_NODE_UPDATE_PROPS (1 << 2) +#define PW_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0) +#define PW_MESSAGE_NODE_UPDATE_MAX_OUTPUTS (1 << 1) +#define PW_MESSAGE_NODE_UPDATE_PROPS (1 << 2) uint32_t change_mask, uint32_t max_input_ports, uint32_t max_output_ports, @@ -182,10 +172,10 @@ typedef struct { void (*port_update) (void *object, SpaDirection direction, uint32_t port_id, -#define PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0) -#define PINOS_MESSAGE_PORT_UPDATE_FORMAT (1 << 1) -#define PINOS_MESSAGE_PORT_UPDATE_PARAMS (1 << 2) -#define PINOS_MESSAGE_PORT_UPDATE_INFO (1 << 3) +#define PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0) +#define PW_MESSAGE_PORT_UPDATE_FORMAT (1 << 1) +#define PW_MESSAGE_PORT_UPDATE_PARAMS (1 << 2) +#define PW_MESSAGE_PORT_UPDATE_INFO (1 << 3) uint32_t change_mask, uint32_t n_possible_formats, const SpaFormat **possible_formats, @@ -196,27 +186,27 @@ typedef struct { void (*event) (void *object, SpaEvent *event); void (*destroy) (void *object); -} PinosClientNodeMethods; +}; -#define pinos_client_node_do_update(r,...) ((PinosClientNodeMethods*)r->iface->methods)->update(r,__VA_ARGS__) -#define pinos_client_node_do_port_update(r,...) ((PinosClientNodeMethods*)r->iface->methods)->port_update(r,__VA_ARGS__) -#define pinos_client_node_do_event(r,...) ((PinosClientNodeMethods*)r->iface->methods)->event(r,__VA_ARGS__) -#define pinos_client_node_do_destroy(r) ((PinosClientNodeMethods*)r->iface->methods)->destroy(r) +#define pw_client_node_do_update(r,...) ((struct pw_client_node_methods*)r->iface->methods)->update(r,__VA_ARGS__) +#define pw_client_node_do_port_update(r,...) ((struct pw_client_node_methods*)r->iface->methods)->port_update(r,__VA_ARGS__) +#define pw_client_node_do_event(r,...) ((struct pw_client_node_methods*)r->iface->methods)->event(r,__VA_ARGS__) +#define pw_client_node_do_destroy(r) ((struct pw_client_node_methods*)r->iface->methods)->destroy(r) -#define PINOS_CLIENT_NODE_EVENT_DONE 0 -#define PINOS_CLIENT_NODE_EVENT_EVENT 1 -#define PINOS_CLIENT_NODE_EVENT_ADD_PORT 2 -#define PINOS_CLIENT_NODE_EVENT_REMOVE_PORT 3 -#define PINOS_CLIENT_NODE_EVENT_SET_FORMAT 4 -#define PINOS_CLIENT_NODE_EVENT_SET_PROPERTY 5 -#define PINOS_CLIENT_NODE_EVENT_ADD_MEM 6 -#define PINOS_CLIENT_NODE_EVENT_USE_BUFFERS 7 -#define PINOS_CLIENT_NODE_EVENT_NODE_COMMAND 8 -#define PINOS_CLIENT_NODE_EVENT_PORT_COMMAND 9 -#define PINOS_CLIENT_NODE_EVENT_TRANSPORT 10 -#define PINOS_CLIENT_NODE_EVENT_NUM 11 +#define PW_CLIENT_NODE_EVENT_DONE 0 +#define PW_CLIENT_NODE_EVENT_EVENT 1 +#define PW_CLIENT_NODE_EVENT_ADD_PORT 2 +#define PW_CLIENT_NODE_EVENT_REMOVE_PORT 3 +#define PW_CLIENT_NODE_EVENT_SET_FORMAT 4 +#define PW_CLIENT_NODE_EVENT_SET_PROPERTY 5 +#define PW_CLIENT_NODE_EVENT_ADD_MEM 6 +#define PW_CLIENT_NODE_EVENT_USE_BUFFERS 7 +#define PW_CLIENT_NODE_EVENT_NODE_COMMAND 8 +#define PW_CLIENT_NODE_EVENT_PORT_COMMAND 9 +#define PW_CLIENT_NODE_EVENT_TRANSPORT 10 +#define PW_CLIENT_NODE_EVENT_NUM 11 -typedef struct { +struct pw_client_node_events { void (*done) (void *object, int readfd, int writefd); @@ -255,7 +245,7 @@ typedef struct { SpaDirection direction, uint32_t port_id, uint32_t n_buffers, - PinosClientNodeBuffer *buffers); + struct pw_client_node_buffer *buffers); void (*node_command) (void *object, uint32_t seq, const SpaCommand *command); @@ -266,42 +256,42 @@ typedef struct { int memfd, uint32_t offset, uint32_t size); -} PinosClientNodeEvents; +}; -#define pinos_client_node_notify_done(r,...) ((PinosClientNodeEvents*)r->iface->events)->done(r,__VA_ARGS__) -#define pinos_client_node_notify_event(r,...) ((PinosClientNodeEvents*)r->iface->events)->event(r,__VA_ARGS__) -#define pinos_client_node_notify_add_port(r,...) ((PinosClientNodeEvents*)r->iface->events)->add_port(r,__VA_ARGS__) -#define pinos_client_node_notify_remove_port(r,...) ((PinosClientNodeEvents*)r->iface->events)->remove_port(r,__VA_ARGS__) -#define pinos_client_node_notify_set_format(r,...) ((PinosClientNodeEvents*)r->iface->events)->set_format(r,__VA_ARGS__) -#define pinos_client_node_notify_set_property(r,...) ((PinosClientNodeEvents*)r->iface->events)->set_property(r,__VA_ARGS__) -#define pinos_client_node_notify_add_mem(r,...) ((PinosClientNodeEvents*)r->iface->events)->add_mem(r,__VA_ARGS__) -#define pinos_client_node_notify_use_buffers(r,...) ((PinosClientNodeEvents*)r->iface->events)->use_buffers(r,__VA_ARGS__) -#define pinos_client_node_notify_node_command(r,...) ((PinosClientNodeEvents*)r->iface->events)->node_command(r,__VA_ARGS__) -#define pinos_client_node_notify_port_command(r,...) ((PinosClientNodeEvents*)r->iface->events)->port_command(r,__VA_ARGS__) -#define pinos_client_node_notify_transport(r,...) ((PinosClientNodeEvents*)r->iface->events)->transport(r,__VA_ARGS__) +#define pw_client_node_notify_done(r,...) ((struct pw_client_node_events*)r->iface->events)->done(r,__VA_ARGS__) +#define pw_client_node_notify_event(r,...) ((struct pw_client_node_events*)r->iface->events)->event(r,__VA_ARGS__) +#define pw_client_node_notify_add_port(r,...) ((struct pw_client_node_events*)r->iface->events)->add_port(r,__VA_ARGS__) +#define pw_client_node_notify_remove_port(r,...) ((struct pw_client_node_events*)r->iface->events)->remove_port(r,__VA_ARGS__) +#define pw_client_node_notify_set_format(r,...) ((struct pw_client_node_events*)r->iface->events)->set_format(r,__VA_ARGS__) +#define pw_client_node_notify_set_property(r,...) ((struct pw_client_node_events*)r->iface->events)->set_property(r,__VA_ARGS__) +#define pw_client_node_notify_add_mem(r,...) ((struct pw_client_node_events*)r->iface->events)->add_mem(r,__VA_ARGS__) +#define pw_client_node_notify_use_buffers(r,...) ((struct pw_client_node_events*)r->iface->events)->use_buffers(r,__VA_ARGS__) +#define pw_client_node_notify_node_command(r,...) ((struct pw_client_node_events*)r->iface->events)->node_command(r,__VA_ARGS__) +#define pw_client_node_notify_port_command(r,...) ((struct pw_client_node_events*)r->iface->events)->port_command(r,__VA_ARGS__) +#define pw_client_node_notify_transport(r,...) ((struct pw_client_node_events*)r->iface->events)->transport(r,__VA_ARGS__) -#define PINOS_CLIENT_EVENT_INFO 0 -#define PINOS_CLIENT_EVENT_NUM 1 +#define PW_CLIENT_EVENT_INFO 0 +#define PW_CLIENT_EVENT_NUM 1 -typedef struct { +struct pw_client_events { void (*info) (void *object, - PinosClientInfo *info); -} PinosClientEvents; + struct pw_client_info *info); +}; -#define pinos_client_notify_info(r,...) ((PinosClientEvents*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_client_notify_info(r,...) ((struct pw_client_events*)r->iface->events)->info(r,__VA_ARGS__) -#define PINOS_LINK_EVENT_INFO 0 -#define PINOS_LINK_EVENT_NUM 1 +#define PW_LINK_EVENT_INFO 0 +#define PW_LINK_EVENT_NUM 1 -typedef struct { +struct pw_link_events { void (*info) (void *object, - PinosLinkInfo *info); -} PinosLinkEvents; + struct pw_link_info *info); +}; -#define pinos_link_notify_info(r,...) ((PinosLinkEvents*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_link_notify_info(r,...) ((struct pw_link_events*)r->iface->events)->info(r,__VA_ARGS__) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __PINOS_INTERFACES_H__ */ +#endif /* __PIPEWIRE_INTERFACES_H__ */ diff --git a/pinos/client/introspect.c b/pipewire/client/introspect.c similarity index 76% rename from pinos/client/introspect.c rename to pipewire/client/introspect.c index 018f8d7d8..7ff267449 100644 --- a/pinos/client/introspect.c +++ b/pipewire/client/introspect.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,52 +19,52 @@ #include -#include "pinos/client/pinos.h" +#include "pipewire/client/pipewire.h" -#include "pinos/client/context.h" -#include "pinos/client/subscribe.h" +#include "pipewire/client/context.h" +#include "pipewire/client/subscribe.h" /** - * pinos_node_state_as_string: - * @state: a #PinosNodeeState + * pw_node_state_as_string: + * @state: a #enum pw_node_state * * Return the string representation of @state. * * Returns: the string representation of @state. */ const char * -pinos_node_state_as_string (PinosNodeState state) +pw_node_state_as_string (enum pw_node_state state) { switch (state) { - case PINOS_NODE_STATE_ERROR: + case PW_NODE_STATE_ERROR: return "error"; - case PINOS_NODE_STATE_CREATING: + case PW_NODE_STATE_CREATING: return "creating"; - case PINOS_NODE_STATE_SUSPENDED: + case PW_NODE_STATE_SUSPENDED: return "suspended"; - case PINOS_NODE_STATE_IDLE: + case PW_NODE_STATE_IDLE: return "idle"; - case PINOS_NODE_STATE_RUNNING: + case PW_NODE_STATE_RUNNING: return "running"; } return "invalid-state"; } /** - * pinos_direction_as_string: - * @direction: a #PinosDirection + * pw_direction_as_string: + * @direction: a #enum pw_direction * * Return the string representation of @direction. * * Returns: the string representation of @direction. */ const char * -pinos_direction_as_string (PinosDirection direction) +pw_direction_as_string (enum pw_direction direction) { switch (direction) { - case PINOS_DIRECTION_INPUT: + case PW_DIRECTION_INPUT: return "input"; - case PINOS_DIRECTION_OUTPUT: + case PW_DIRECTION_OUTPUT: return "output"; default: return "invalid"; @@ -73,37 +73,37 @@ pinos_direction_as_string (PinosDirection direction) } /** - * pinos_link_state_as_string: - * @state: a #PinosLinkeState + * pw_link_state_as_string: + * @state: a #enum pw_link_state * * Return the string representation of @state. * * Returns: the string representation of @state. */ const char * -pinos_link_state_as_string (PinosLinkState state) +pw_link_state_as_string (enum pw_link_state state) { switch (state) { - case PINOS_LINK_STATE_ERROR: + case PW_LINK_STATE_ERROR: return "error"; - case PINOS_LINK_STATE_UNLINKED: + case PW_LINK_STATE_UNLINKED: return "unlinked"; - case PINOS_LINK_STATE_INIT: + case PW_LINK_STATE_INIT: return "init"; - case PINOS_LINK_STATE_NEGOTIATING: + case PW_LINK_STATE_NEGOTIATING: return "negotiating"; - case PINOS_LINK_STATE_ALLOCATING: + case PW_LINK_STATE_ALLOCATING: return "allocating"; - case PINOS_LINK_STATE_PAUSED: + case PW_LINK_STATE_PAUSED: return "paused"; - case PINOS_LINK_STATE_RUNNING: + case PW_LINK_STATE_RUNNING: return "running"; } return "invalid-state"; } static void -pinos_spa_dict_destroy (SpaDict *dict) +pw_spa_dict_destroy (SpaDict *dict) { SpaDictItem *item; @@ -116,7 +116,7 @@ pinos_spa_dict_destroy (SpaDict *dict) } static SpaDict * -pinos_spa_dict_copy (SpaDict *dict) +pw_spa_dict_copy (SpaDict *dict) { SpaDict *copy; uint32_t i; @@ -144,9 +144,9 @@ no_mem: return NULL; } -PinosCoreInfo * -pinos_core_info_update (PinosCoreInfo *info, - const PinosCoreInfo *update) +struct pw_core_info * +pw_core_info_update (struct pw_core_info *info, + const struct pw_core_info *update) { uint64_t change_mask; @@ -154,7 +154,7 @@ pinos_core_info_update (PinosCoreInfo *info, return info; if (info == NULL) { - info = calloc (1, sizeof (PinosCoreInfo)); + info = calloc (1, sizeof (struct pw_core_info)); if (info == NULL) return NULL; change_mask = ~0; @@ -188,14 +188,14 @@ pinos_core_info_update (PinosCoreInfo *info, info->cookie = update->cookie; if (update->change_mask & (1 << 5)) { if (info->props) - pinos_spa_dict_destroy (info->props); - info->props = pinos_spa_dict_copy (update->props); + pw_spa_dict_destroy (info->props); + info->props = pw_spa_dict_copy (update->props); } return info; } void -pinos_core_info_free (PinosCoreInfo *info) +pw_core_info_free (struct pw_core_info *info) { if (info == NULL) return; @@ -209,13 +209,13 @@ pinos_core_info_free (PinosCoreInfo *info) if (info->name) free ((void*)info->name); if (info->props) - pinos_spa_dict_destroy (info->props); + pw_spa_dict_destroy (info->props); free (info); } -PinosNodeInfo * -pinos_node_info_update (PinosNodeInfo *info, - const PinosNodeInfo *update) +struct pw_node_info * +pw_node_info_update (struct pw_node_info *info, + const struct pw_node_info *update) { uint64_t change_mask; int i; @@ -224,7 +224,7 @@ pinos_node_info_update (PinosNodeInfo *info, return info; if (info == NULL) { - info = calloc (1, sizeof (PinosNodeInfo)); + info = calloc (1, sizeof (struct pw_node_info)); if (info == NULL) return NULL; change_mask = ~0; @@ -280,14 +280,14 @@ pinos_node_info_update (PinosNodeInfo *info, } if (update->change_mask & (1 << 6)) { if (info->props) - pinos_spa_dict_destroy (info->props); - info->props = pinos_spa_dict_copy (update->props); + pw_spa_dict_destroy (info->props); + info->props = pw_spa_dict_copy (update->props); } return info; } void -pinos_node_info_free (PinosNodeInfo *info) +pw_node_info_free (struct pw_node_info *info) { int i; @@ -308,13 +308,13 @@ pinos_node_info_free (PinosNodeInfo *info) if (info->error) free ((void*)info->error); if (info->props) - pinos_spa_dict_destroy (info->props); + pw_spa_dict_destroy (info->props); free (info); } -PinosModuleInfo * -pinos_module_info_update (PinosModuleInfo *info, - const PinosModuleInfo *update) +struct pw_module_info * +pw_module_info_update (struct pw_module_info *info, + const struct pw_module_info *update) { uint64_t change_mask; @@ -322,7 +322,7 @@ pinos_module_info_update (PinosModuleInfo *info, return info; if (info == NULL) { - info = calloc (1, sizeof (PinosModuleInfo)); + info = calloc (1, sizeof (struct pw_module_info)); if (info == NULL) return NULL; change_mask = ~0; @@ -349,14 +349,14 @@ pinos_module_info_update (PinosModuleInfo *info, } if (update->change_mask & (1 << 3)) { if (info->props) - pinos_spa_dict_destroy (info->props); - info->props = pinos_spa_dict_copy (update->props); + pw_spa_dict_destroy (info->props); + info->props = pw_spa_dict_copy (update->props); } return info; } void -pinos_module_info_free (PinosModuleInfo *info) +pw_module_info_free (struct pw_module_info *info) { if (info == NULL) return; @@ -368,14 +368,14 @@ pinos_module_info_free (PinosModuleInfo *info) if (info->args) free ((void*)info->args); if (info->props) - pinos_spa_dict_destroy (info->props); + pw_spa_dict_destroy (info->props); free (info); } -PinosClientInfo * -pinos_client_info_update (PinosClientInfo *info, - const PinosClientInfo *update) +struct pw_client_info * +pw_client_info_update (struct pw_client_info *info, + const struct pw_client_info *update) { uint64_t change_mask; @@ -383,7 +383,7 @@ pinos_client_info_update (PinosClientInfo *info, return info; if (info == NULL) { - info = calloc (1, sizeof (PinosClientInfo)); + info = calloc (1, sizeof (struct pw_client_info)); if (info == NULL) return NULL; change_mask = ~0; @@ -395,25 +395,25 @@ pinos_client_info_update (PinosClientInfo *info, if (update->change_mask & (1 << 0)) { if (info->props) - pinos_spa_dict_destroy (info->props); - info->props = pinos_spa_dict_copy (update->props); + pw_spa_dict_destroy (info->props); + info->props = pw_spa_dict_copy (update->props); } return info; } void -pinos_client_info_free (PinosClientInfo *info) +pw_client_info_free (struct pw_client_info *info) { if (info == NULL) return; if (info->props) - pinos_spa_dict_destroy (info->props); + pw_spa_dict_destroy (info->props); free (info); } -PinosLinkInfo * -pinos_link_info_update (PinosLinkInfo *info, - const PinosLinkInfo *update) +struct pw_link_info * +pw_link_info_update (struct pw_link_info *info, + const struct pw_link_info *update) { uint64_t change_mask; @@ -421,7 +421,7 @@ pinos_link_info_update (PinosLinkInfo *info, return info; if (info == NULL) { - info = calloc (1, sizeof (PinosLinkInfo)); + info = calloc (1, sizeof (struct pw_link_info)); if (info == NULL) return NULL; change_mask = ~0; @@ -444,7 +444,7 @@ pinos_link_info_update (PinosLinkInfo *info, } void -pinos_link_info_free (PinosLinkInfo *info) +pw_link_info_free (struct pw_link_info *info) { free (info); } diff --git a/pipewire/client/introspect.h b/pipewire/client/introspect.h new file mode 100644 index 000000000..5e7fd796f --- /dev/null +++ b/pipewire/client/introspect.h @@ -0,0 +1,340 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_INTROSPECT_H__ +#define __PIPEWIRE_INTROSPECT_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct pw_context; + +#include +#include + +/** + * pw_node_state: + * @PW_NODE_STATE_ERROR: the node is in error + * @PW_NODE_STATE_CREATING: the node is being created + * @PW_NODE_STATE_SUSPENDED: the node is suspended, the device might + * be closed + * @PW_NODE_STATE_IDLE: the node is running but there is no active + * port + * @PW_NODE_STATE_RUNNING: the node is running + * + * The different node states + */ +enum pw_node_state { + PW_NODE_STATE_ERROR = -1, + PW_NODE_STATE_CREATING = 0, + PW_NODE_STATE_SUSPENDED = 1, + PW_NODE_STATE_IDLE = 2, + PW_NODE_STATE_RUNNING = 3, +}; + +const char * pw_node_state_as_string (enum pw_node_state state); + +/** + * pw_direction: + * @PW_DIRECTION_INVALID: invalid direction + * @PW_DIRECTION_INPUT: an input port + * @PW_DIRECTION_OUTPUT: an output port + * + * The direction of a port + */ +enum pw_direction { + PW_DIRECTION_INPUT = SPA_DIRECTION_INPUT, + PW_DIRECTION_OUTPUT = SPA_DIRECTION_OUTPUT +}; + +const char * pw_direction_as_string (enum pw_direction direction); + +/** + * pw_link_state: + * @PW_LINK_STATE_ERROR: the link is in error + * @PW_LINK_STATE_UNLINKED: the link is unlinked + * @PW_LINK_STATE_INIT: the link is initialized + * @PW_LINK_STATE_NEGOTIATING: the link is negotiating formats + * @PW_LINK_STATE_ALLOCATING: the link is allocating buffers + * @PW_LINK_STATE_PAUSED: the link is paused + * @PW_LINK_STATE_RUNNING: the link is running + * + * The different link states + */ +enum pw_link_state { + PW_LINK_STATE_ERROR = -2, + PW_LINK_STATE_UNLINKED = -1, + PW_LINK_STATE_INIT = 0, + PW_LINK_STATE_NEGOTIATING = 1, + PW_LINK_STATE_ALLOCATING = 2, + PW_LINK_STATE_PAUSED = 3, + PW_LINK_STATE_RUNNING = 4, +}; + +const char * pw_link_state_as_string (enum pw_link_state state); + +/** + * pw_core_info: + * @id: generic id of the core + * @change_mask: bitfield of changed fields since last call + * @user_name: name of the user that started the core + * @host_name: name of the machine the core is running on + * @version: version of the core + * @name: name of the core + * @cookie: a random cookie for identifying this instance of PipeWire + * @props: extra properties + * + * The core information. Extra information can be added in later + * versions. + */ +struct pw_core_info { + uint32_t id; + uint64_t change_mask; +#define PW_CORE_CHANGE_MASK_USER_NAME (1 << 0) +#define PW_CORE_CHANGE_MASK_HOST_NAME (1 << 1) +#define PW_CORE_CHANGE_MASK_VERSION (1 << 2) +#define PW_CORE_CHANGE_MASK_NAME (1 << 3) +#define PW_CORE_CHANGE_MASK_COOKIE (1 << 4) +#define PW_CORE_CHANGE_MASK_PROPS (1 << 5) +#define PW_CORE_CHANGE_MASK_ALL (~0) + const char *user_name; + const char *host_name; + const char *version; + const char *name; + uint32_t cookie; + SpaDict *props; +}; + +struct pw_core_info * pw_core_info_update (struct pw_core_info *info, + const struct pw_core_info *update); +void pw_core_info_free (struct pw_core_info *info); + +/** + * pw_core_info_cb_t: + * @c: a #struct pw_context + * @info: a #struct pw_core_info + * @user_data: user data + * + * Callback with information about the PipeWire core in @info. + */ +typedef void (*pw_core_info_cb_t) (struct pw_context *c, + SpaResult res, + const struct pw_core_info *info, + void *user_data); + +void pw_context_get_core_info (struct pw_context *context, + pw_core_info_cb_t cb, + void *user_data); + +/** + * pw_module_info: + * @id: generic id of the module + * @change_mask: bitfield of changed fields since last call + * @props: extra properties + * + * The module information. Extra information can be added in later + * versions. + */ +struct pw_module_info { + uint32_t id; + uint64_t change_mask; + const char *name; + const char *filename; + const char *args; + SpaDict *props; +}; + +struct pw_module_info * pw_module_info_update (struct pw_module_info *info, + const struct pw_module_info *update); +void pw_module_info_free (struct pw_module_info *info); + + +/** + * pw_module_info_cb_t: + * @c: a #struct pw_context + * @info: a #struct pw_module_info + * @user_data: user data + * + * Callback with information about the PipeWire module in @info. + */ +typedef void (*pw_module_info_cb_t) (struct pw_context *c, + SpaResult res, + const struct pw_module_info *info, + void *user_data); + +void pw_context_list_module_info (struct pw_context *context, + pw_module_info_cb_t cb, + void *user_data); +void pw_context_get_module_info_by_id (struct pw_context *context, + uint32_t id, + pw_module_info_cb_t cb, + void *user_data); + +/** + * pw_client_info: + * @id: generic id of the client + * @change_mask: bitfield of changed fields since last call + * @props: extra properties + * + * The client information. Extra information can be added in later + * versions. + */ +struct pw_client_info { + uint32_t id; + uint64_t change_mask; + SpaDict *props; +}; + +struct pw_client_info * pw_client_info_update (struct pw_client_info *info, + const struct pw_client_info *update); +void pw_client_info_free (struct pw_client_info *info); + + +/** + * pw_client_info_cb_t: + * @c: a #struct pw_context + * @info: a #struct pw_client_info + * @user_data: user data + * + * Callback with information about the PipeWire client in @info. + */ +typedef void (*pw_client_info_cb_t) (struct pw_context *c, + SpaResult res, + const struct pw_client_info *info, + void *user_data); + +void pw_context_list_client_info (struct pw_context *context, + pw_client_info_cb_t cb, + void *user_data); +void pw_context_get_client_info_by_id (struct pw_context *context, + uint32_t id, + pw_client_info_cb_t cb, + void *user_data); + +/** + * pw_node_info: + * @id: generic id of the node + * @change_mask: bitfield of changed fields since last call + * @name: name the node, suitable for display + * @state: the current state of the node + * @error: an error reason if @state is error + * @props: the properties of the node + * + * The node information. Extra information can be added in later + * versions. + */ +struct pw_node_info { + uint32_t id; + uint64_t change_mask; + const char *name; + uint32_t max_inputs; + uint32_t n_inputs; + uint32_t n_input_formats; + SpaFormat **input_formats; + uint32_t max_outputs; + uint32_t n_outputs; + uint32_t n_output_formats; + SpaFormat **output_formats; + enum pw_node_state state; + const char *error; + SpaDict *props; +}; + +struct pw_node_info * pw_node_info_update (struct pw_node_info *info, + const struct pw_node_info *update); +void pw_node_info_free (struct pw_node_info *info); + +/** + * pw_node_info_cb_t: + * @c: a #struct pw_context + * @info: a #struct pw_node_info + * @user_data: user data + * + * Callback with information about the PipeWire node in @info. + */ +typedef void (*pw_node_info_cb_t) (struct pw_context *c, + SpaResult res, + const struct pw_node_info *info, + void *user_data); + +void pw_context_list_node_info (struct pw_context *context, + pw_node_info_cb_t cb, + void *user_data); +void pw_context_get_node_info_by_id (struct pw_context *context, + uint32_t id, + pw_node_info_cb_t cb, + void *user_data); + + +/** + * pw_link_info: + * @id: generic id of the link + * @change_mask: bitfield of changed fields since last call + * @output_node_path: the output node + * @output_port: the output port + * @input_node_path: the input node + * @input_port: the input port + * + * The link information. Extra information can be added in later + * versions. + */ +struct pw_link_info { + uint32_t id; + uint64_t change_mask; + uint32_t output_node_id; + uint32_t output_port_id; + uint32_t input_node_id; + uint32_t input_port_id; +}; + +struct pw_link_info * pw_link_info_update (struct pw_link_info *info, + const struct pw_link_info *update); +void pw_link_info_free (struct pw_link_info *info); + + +/** + * pw_link_info_cb_t: + * @c: a #struct pw_context + * @info: a #struct pw_link_info + * @user_data: user data + * + * Callback with information about the PipeWire link in @info. + */ +typedef void (*pw_link_info_cb_t) (struct pw_context *c, + SpaResult res, + const struct pw_link_info *info, + void *user_data); + +void pw_context_list_link_info (struct pw_context *context, + pw_link_info_cb_t cb, + void *user_data); +void pw_context_get_link_info_by_id (struct pw_context *context, + uint32_t id, + pw_link_info_cb_t cb, + void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_INTROSPECT_H__ */ diff --git a/pinos/client/log.c b/pipewire/client/log.c similarity index 84% rename from pinos/client/log.c rename to pipewire/client/log.c index ebd111668..91980a076 100644 --- a/pinos/client/log.c +++ b/pipewire/client/log.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -23,11 +23,11 @@ #include -#include +#include #define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_ERROR -SpaLogLevel pinos_log_level = DEFAULT_LOG_LEVEL; +SpaLogLevel pw_log_level = DEFAULT_LOG_LEVEL; #define TRACE_BUFFER (16*1024) @@ -101,15 +101,15 @@ static DebugLog log = { }; SpaLog * -pinos_log_get (void) +pw_log_get (void) { return &log.log; } void -pinos_log_set_level (SpaLogLevel level) +pw_log_set_level (SpaLogLevel level) { - pinos_log_level = level; + pw_log_level = level; log.log.level = level; } @@ -143,7 +143,7 @@ on_trace_event (SpaSource *source) } void -pinos_log_set_trace_event (SpaSource *source) +pw_log_set_trace_event (SpaSource *source) { log.source = source; log.source->func = on_trace_event; @@ -151,13 +151,13 @@ pinos_log_set_trace_event (SpaSource *source) } void -pinos_log_log (SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, ...) +pw_log_log (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, ...) { - if (SPA_UNLIKELY (pinos_log_level_enabled (level))) { + if (SPA_UNLIKELY (pw_log_level_enabled (level))) { va_list args; va_start (args, fmt); do_logv (&log.log, level, file, line, func, fmt, args); @@ -166,14 +166,14 @@ pinos_log_log (SpaLogLevel level, } void -pinos_log_logv (SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, - va_list args) +pw_log_logv (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, + va_list args) { - if (SPA_UNLIKELY (pinos_log_level_enabled (level))) { + if (SPA_UNLIKELY (pw_log_level_enabled (level))) { do_logv (&log.log, level, file, line, func, fmt, args); } } diff --git a/pipewire/client/log.h b/pipewire/client/log.h new file mode 100644 index 000000000..686e16283 --- /dev/null +++ b/pipewire/client/log.h @@ -0,0 +1,90 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_LOG_H__ +#define __PIPEWIRE_LOG_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern SpaLogLevel pw_log_level; + +SpaLog * pw_log_get (void); + +void pw_log_set_level (SpaLogLevel level); +void pw_log_set_trace_event (SpaSource *source); + + +void pw_log_log (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, ...) SPA_PRINTF_FUNC(5, 6); +void pw_log_logv (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, + va_list args) SPA_PRINTF_FUNC(5, 0); + +#define pw_log_level_enabled(lev) (pw_log_level >= (lev)) + +#if __STDC_VERSION__ >= 199901L + +#define pw_log_logc(lev,...) \ + if (SPA_UNLIKELY (pw_log_level_enabled (lev))) \ + pw_log_log(lev,__VA_ARGS__) + +#define pw_log_error(...) pw_log_logc(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pw_log_warn(...) pw_log_logc(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pw_log_info(...) pw_log_logc(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pw_log_debug(...) pw_log_logc(SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pw_log_trace(...) pw_log_logc(SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__) + +#else + +#include + +#define PW_LOG_FUNC(name,lev) \ +static inline void pw_log_##name (const char *format, ...) \ +{ \ + if (SPA_UNLIKELY (pw_log_level_enabled (lev))) { \ + va_list varargs; \ + va_start (varargs, format); \ + pw_log_logv (lev,__FILE__,__LINE__,__func__,format,varargs); \ + va_end (varargs); \ + } \ +} +PW_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR) +PW_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN) +PW_LOG_FUNC(info, SPA_LOG_LEVEL_INFO) +PW_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG) +PW_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE) + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_LOG_H__ */ diff --git a/pinos/client/loop.c b/pipewire/client/loop.c similarity index 84% rename from pinos/client/loop.c rename to pipewire/client/loop.c index bf3130b9f..fc26cb154 100644 --- a/pinos/client/loop.c +++ b/pipewire/client/loop.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -32,22 +32,22 @@ #include #include -#include -#include +#include +#include #define DATAS_SIZE (4096 * 8) -typedef struct { +struct invoke_item { size_t item_size; SpaInvokeFunc func; uint32_t seq; size_t size; void *data; void *user_data; -} InvokeItem; +}; -typedef struct { - PinosLoop this; +struct loop { + struct pw_loop this; SpaList source_list; @@ -66,12 +66,12 @@ typedef struct { SpaRingbuffer buffer; uint8_t buffer_data[DATAS_SIZE]; -} PinosLoopImpl; +}; typedef struct { SpaSource source; - PinosLoopImpl *impl; + struct loop *impl; SpaList link; bool close; @@ -124,7 +124,7 @@ static SpaResult loop_add_source (SpaLoop *loop, SpaSource *source) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosLoopImpl, loop); + struct loop *impl = SPA_CONTAINER_OF (loop, struct loop, loop); source->loop = loop; @@ -145,7 +145,7 @@ static SpaResult loop_update_source (SpaSource *source) { SpaLoop *loop = source->loop; - PinosLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosLoopImpl, loop); + struct loop *impl = SPA_CONTAINER_OF (loop, struct loop, loop); if (source->fd != -1) { struct epoll_event ep; @@ -164,7 +164,7 @@ static void loop_remove_source (SpaSource *source) { SpaLoop *loop = source->loop; - PinosLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosLoopImpl, loop); + struct loop *impl = SPA_CONTAINER_OF (loop, struct loop, loop); if (source->fd != -1) epoll_ctl (impl->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL); @@ -180,9 +180,9 @@ loop_invoke (SpaLoop *loop, void *data, void *user_data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosLoopImpl, loop); + struct loop *impl = SPA_CONTAINER_OF (loop, struct loop, loop); bool in_thread = pthread_equal (impl->thread, pthread_self()); - InvokeItem *item; + struct invoke_item *item; SpaResult res; if (in_thread) { @@ -193,12 +193,12 @@ loop_invoke (SpaLoop *loop, filled = spa_ringbuffer_get_write_index (&impl->buffer, &idx); if (filled < 0 || filled > impl->buffer.size) { - pinos_log_warn ("data-loop %p: queue xrun %d", impl, filled); + pw_log_warn ("data-loop %p: queue xrun %d", impl, filled); return SPA_RESULT_ERROR; } avail = impl->buffer.size - filled; - if (avail < sizeof (InvokeItem)) { - pinos_log_warn ("data-loop %p: queue full %d", impl, avail); + if (avail < sizeof (struct invoke_item)) { + pw_log_warn ("data-loop %p: queue full %d", impl, avail); return SPA_RESULT_ERROR; } offset = idx & impl->buffer.mask; @@ -207,16 +207,16 @@ loop_invoke (SpaLoop *loop, if (l0 > impl->buffer.size) l0 = impl->buffer.size - l0; - item = SPA_MEMBER (impl->buffer_data, offset, InvokeItem); + item = SPA_MEMBER (impl->buffer_data, offset, struct invoke_item); item->func = func; item->seq = seq; item->size = size; item->user_data = user_data; - if (l0 > sizeof (InvokeItem) + size) { - item->data = SPA_MEMBER (item, sizeof (InvokeItem), void); - item->item_size = sizeof (InvokeItem) + size; - if (l0 < sizeof (InvokeItem) + item->item_size) + if (l0 > sizeof (struct invoke_item) + size) { + item->data = SPA_MEMBER (item, sizeof (struct invoke_item), void); + item->item_size = sizeof (struct invoke_item) + size; + if (l0 < sizeof (struct invoke_item) + item->item_size) item->item_size = l0; } else { item->data = impl->buffer_data; @@ -226,7 +226,7 @@ loop_invoke (SpaLoop *loop, spa_ringbuffer_write_update (&impl->buffer, idx + item->item_size); - pinos_loop_signal_event (&impl->this, impl->event); + pw_loop_signal_event (&impl->this, impl->event); if (seq != SPA_ID_INVALID) res = SPA_RESULT_RETURN_ASYNC (seq); @@ -241,11 +241,11 @@ event_func (SpaLoopUtils *utils, SpaSource *source, void *data) { - PinosLoopImpl *impl = data; + struct loop *impl = data; uint32_t index; while (spa_ringbuffer_get_read_index (&impl->buffer, &index) > 0) { - InvokeItem *item = SPA_MEMBER (impl->buffer_data, index & impl->buffer.mask, InvokeItem); + struct invoke_item *item = SPA_MEMBER (impl->buffer_data, index & impl->buffer.mask, struct invoke_item); item->func (impl->this.loop, true, item->seq, item->size, item->data, item->user_data); spa_ringbuffer_read_update (&impl->buffer, index + item->item_size); } @@ -254,7 +254,7 @@ event_func (SpaLoopUtils *utils, static int loop_get_fd (SpaLoopControl *ctrl) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control); + struct loop *impl = SPA_CONTAINER_OF (ctrl, struct loop, control); return impl->epoll_fd; } @@ -265,7 +265,7 @@ loop_set_hooks (SpaLoopControl *ctrl, SpaLoopHook post_func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control); + struct loop *impl = SPA_CONTAINER_OF (ctrl, struct loop, control); impl->pre_func = pre_func; impl->post_func = post_func; @@ -275,14 +275,14 @@ loop_set_hooks (SpaLoopControl *ctrl, static void loop_enter (SpaLoopControl *ctrl) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control); + struct loop *impl = SPA_CONTAINER_OF (ctrl, struct loop, control); impl->thread = pthread_self(); } static void loop_leave (SpaLoopControl *ctrl) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control); + struct loop *impl = SPA_CONTAINER_OF (ctrl, struct loop, control); impl->thread = 0; } @@ -290,12 +290,12 @@ static SpaResult loop_iterate (SpaLoopControl *ctrl, int timeout) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control); - PinosLoop *loop = &impl->this; + struct loop *impl = SPA_CONTAINER_OF (ctrl, struct loop, control); + struct pw_loop *loop = &impl->this; struct epoll_event ep[32]; int i, nfds, save_errno; - pinos_signal_emit (&loop->before_iterate, loop); + pw_signal_emit (&loop->before_iterate, loop); if (SPA_UNLIKELY (impl->pre_func)) impl->pre_func (ctrl, impl->hook_data); @@ -342,7 +342,7 @@ loop_add_io (SpaLoopUtils *utils, SpaSourceIOFunc func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (utils, PinosLoopImpl, utils); + struct loop *impl = SPA_CONTAINER_OF (utils, struct loop, utils); SpaSourceImpl *source; source = calloc (1, sizeof (SpaSourceImpl)); @@ -387,7 +387,7 @@ loop_add_idle (SpaLoopUtils *utils, SpaSourceIdleFunc func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (utils, PinosLoopImpl, utils); + struct loop *impl = SPA_CONTAINER_OF (utils, struct loop, utils); SpaSourceImpl *source; source = calloc (1, sizeof (SpaSourceImpl)); @@ -423,10 +423,10 @@ loop_enable_idle (SpaSource *source, if (enabled && !impl->enabled) { count = 1; if (write (source->fd, &count, sizeof (uint64_t)) != sizeof (uint64_t)) - pinos_log_warn ("loop %p: failed to write idle fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to write idle fd: %s", source, strerror (errno)); } else if (!enabled && impl->enabled) { if (read (source->fd, &count, sizeof (uint64_t)) != sizeof (uint64_t)) - pinos_log_warn ("loop %p: failed to read idle fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to read idle fd: %s", source, strerror (errno)); } impl->enabled = enabled; } @@ -438,7 +438,7 @@ source_event_func (SpaSource *source) uint64_t count; if (read (source->fd, &count, sizeof (uint64_t)) != sizeof (uint64_t)) - pinos_log_warn ("loop %p: failed to read event fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to read event fd: %s", source, strerror (errno)); impl->func.event (&impl->impl->utils, source, source->data); } @@ -448,7 +448,7 @@ loop_add_event (SpaLoopUtils *utils, SpaSourceEventFunc func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (utils, PinosLoopImpl, utils); + struct loop *impl = SPA_CONTAINER_OF (utils, struct loop, utils); SpaSourceImpl *source; source = calloc (1, sizeof (SpaSourceImpl)); @@ -477,7 +477,7 @@ loop_signal_event (SpaSource *source) uint64_t count = 1; if (write (source->fd, &count, sizeof(uint64_t)) != sizeof(uint64_t)) - pinos_log_warn ("loop %p: failed to write event fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to write event fd: %s", source, strerror (errno)); } static void @@ -487,7 +487,7 @@ source_timer_func (SpaSource *source) uint64_t expires; if (read (source->fd, &expires, sizeof (uint64_t)) != sizeof (uint64_t)) - pinos_log_warn ("loop %p: failed to read timer fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to read timer fd: %s", source, strerror (errno)); impl->func.timer (&impl->impl->utils, source, source->data); } @@ -497,7 +497,7 @@ loop_add_timer (SpaLoopUtils *utils, SpaSourceTimerFunc func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (utils, PinosLoopImpl, utils); + struct loop *impl = SPA_CONTAINER_OF (utils, struct loop, utils); SpaSourceImpl *source; source = calloc (1, sizeof (SpaSourceImpl)); @@ -555,7 +555,7 @@ source_signal_func (SpaSource *source) struct signalfd_siginfo signal_info; if (read (source->fd, &signal_info, sizeof (signal_info)) != sizeof (signal_info)) - pinos_log_warn ("loop %p: failed to read signal fd: %s", source, strerror (errno)); + pw_log_warn ("loop %p: failed to read signal fd: %s", source, strerror (errno)); impl->func.signal (&impl->impl->utils, source, impl->signal_number, source->data); } @@ -566,7 +566,7 @@ loop_add_signal (SpaLoopUtils *utils, SpaSourceSignalFunc func, void *data) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (utils, PinosLoopImpl, utils); + struct loop *impl = SPA_CONTAINER_OF (utils, struct loop, utils); SpaSourceImpl *source; sigset_t mask; @@ -608,13 +608,13 @@ loop_destroy_source (SpaSource *source) free (impl); } -PinosLoop * -pinos_loop_new (void) +struct pw_loop * +pw_loop_new (void) { - PinosLoopImpl *impl; - PinosLoop *this; + struct loop *impl; + struct pw_loop *this; - impl = calloc (1, sizeof (PinosLoopImpl)); + impl = calloc (1, sizeof (struct loop)); if (impl == NULL) return NULL; @@ -626,8 +626,8 @@ pinos_loop_new (void) spa_list_init (&impl->source_list); - pinos_signal_init (&this->before_iterate); - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->before_iterate); + pw_signal_init (&this->destroy_signal); impl->loop.size = sizeof (SpaLoop); impl->loop.add_source = loop_add_source; @@ -671,12 +671,12 @@ no_epoll: } void -pinos_loop_destroy (PinosLoop *loop) +pw_loop_destroy (struct pw_loop *loop) { - PinosLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosLoopImpl, this); + struct loop *impl = SPA_CONTAINER_OF (loop, struct loop, this); SpaSourceImpl *source, *tmp; - pinos_signal_emit (&loop->destroy_signal, loop); + pw_signal_emit (&loop->destroy_signal, loop); spa_list_for_each_safe (source, tmp, &impl->source_list, link) loop_destroy_source (&source->source); diff --git a/pipewire/client/loop.h b/pipewire/client/loop.h new file mode 100644 index 000000000..95af48bb5 --- /dev/null +++ b/pipewire/client/loop.h @@ -0,0 +1,76 @@ +/* PipeWire + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_LOOP_H__ +#define __PIPEWIRE_LOOP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** + * pw_loop: + * + * PipeWire loop interface. + */ +struct pw_loop { + SpaLoop *loop; + SpaLoopControl *control; + SpaLoopUtils *utils; + + PW_SIGNAL (before_iterate, (struct pw_listener *listener, + struct pw_loop *loop)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_loop *loop)); +}; + +struct pw_loop * pw_loop_new (void); +void pw_loop_destroy (struct pw_loop *loop); + +#define pw_loop_add_source(l,...) spa_loop_add_source((l)->loop,__VA_ARGS__) +#define pw_loop_update_source(l,...) spa_loop_update_source(__VA_ARGS__) +#define pw_loop_remove_source(l,...) spa_loop_remove_source(__VA_ARGS__) +#define pw_loop_invoke(l,...) spa_loop_invoke((l)->loop,__VA_ARGS__) + +#define pw_loop_get_fd(l) spa_loop_control_get_fd((l)->control) +#define pw_loop_set_hooks(l,...) spa_loop_control_set_hooks((l)->control,__VA_ARGS__) +#define pw_loop_enter(l) spa_loop_control_enter((l)->control) +#define pw_loop_iterate(l,...) spa_loop_control_iterate((l)->control,__VA_ARGS__) +#define pw_loop_leave(l) spa_loop_control_leave((l)->control) + +#define pw_loop_add_io(l,...) spa_loop_utils_add_io((l)->utils,__VA_ARGS__) +#define pw_loop_update_io(l,...) spa_loop_utils_update_io((l)->utils,__VA_ARGS__) +#define pw_loop_add_idle(l,...) spa_loop_utils_add_idle((l)->utils,__VA_ARGS__) +#define pw_loop_enable_idle(l,...) spa_loop_utils_enable_idle((l)->utils,__VA_ARGS__) +#define pw_loop_add_event(l,...) spa_loop_utils_add_event((l)->utils,__VA_ARGS__) +#define pw_loop_signal_event(l,...) spa_loop_utils_signal_event((l)->utils,__VA_ARGS__) +#define pw_loop_add_timer(l,...) spa_loop_utils_add_timer((l)->utils,__VA_ARGS__) +#define pw_loop_update_timer(l,...) spa_loop_utils_update_timer((l)->utils,__VA_ARGS__) +#define pw_loop_add_signal(l,...) spa_loop_utils_add_signal((l)->utils,__VA_ARGS__) +#define pw_loop_destroy_source(l,...) spa_loop_utils_destroy_source((l)->utils,__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_LOOP_H__ */ diff --git a/pipewire/client/map.h b/pipewire/client/map.h new file mode 100644 index 000000000..46a2a3a30 --- /dev/null +++ b/pipewire/client/map.h @@ -0,0 +1,151 @@ +/* PipeWire + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_MAP_H__ +#define __PIPEWIRE_MAP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include +#include + +union pw_map_item{ + uint32_t next; + void *data; +}; + +struct pw_map { + struct pw_array items; + uint32_t free_list; +}; + +#define PW_MAP_INIT(extend) { PW_ARRAY_INIT(extend), 0 } + +#define pw_map_get_size(m) pw_array_get_len (&(m)->items, union pw_map_item) +#define pw_map_get_item(m,id) pw_array_get_unchecked(&(m)->items,id,union pw_map_item) +#define pw_map_item_is_free(item) ((item)->next & 0x1) +#define pw_map_id_is_free(m,id) (pw_map_item_is_free (pw_map_get_item(m,id))) +#define pw_map_check_id(m,id) ((id) < pw_map_get_size (m)) +#define pw_map_has_item(m,id) (pw_map_check_id(m,id) && !pw_map_id_is_free(m, id)) +#define pw_map_lookup_unchecked(m,id) pw_map_get_item(m,id)->data + +#define PW_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1)) +#define PW_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1) + +static inline void +pw_map_init (struct pw_map *map, + size_t size, + size_t extend) +{ + pw_array_init (&map->items, extend); + pw_array_ensure_size (&map->items, size * sizeof (union pw_map_item)); + map->free_list = 0; +} + +static inline void +pw_map_clear (struct pw_map *map) +{ + pw_array_clear (&map->items); +} + +static inline uint32_t +pw_map_insert_new (struct pw_map *map, + void *data) +{ + union pw_map_item *start, *item; + uint32_t id; + + if (map->free_list) { + start = map->items.data; + item = &start[map->free_list >> 1]; + map->free_list = item->next; + } else { + item = pw_array_add (&map->items, sizeof (union pw_map_item)); + if (!item) + return SPA_ID_INVALID; + start = map->items.data; + } + item->data = data; + id = (item - start); + return id; +} + +static inline bool +pw_map_insert_at (struct pw_map *map, + uint32_t id, + void *data) +{ + size_t size = pw_map_get_size (map); + union pw_map_item *item; + + if (id > size) + return false; + else if (id == size) + item = pw_array_add (&map->items, sizeof (union pw_map_item)); + else + item = pw_map_get_item (map, id); + + item->data = data; + return true; +} + +static inline void +pw_map_remove (struct pw_map *map, + uint32_t id) +{ + pw_map_get_item (map, id)->next = map->free_list; + map->free_list = (id << 1) | 1; +} + +static inline void * +pw_map_lookup (struct pw_map *map, + uint32_t id) +{ + if (SPA_LIKELY (pw_map_check_id (map, id))) { + union pw_map_item *item = pw_map_get_item (map, id); + if (!pw_map_item_is_free (item)) + return item->data; + } + return NULL; +} + +static inline void +pw_map_for_each (struct pw_map *map, + void (*func) (void *, void *), + void *data) +{ + union pw_map_item *item; + + pw_array_for_each (item, &map->items) { + if (item->data && !pw_map_item_is_free (item)) + func (item->data, data); + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PIPEWIRE_MAP_H__ */ diff --git a/pinos/client/mapper.c b/pipewire/client/mapper.c similarity index 76% rename from pinos/client/mapper.c rename to pipewire/client/mapper.c index 2ae959a3b..87aaa83e9 100644 --- a/pinos/client/mapper.c +++ b/pipewire/client/mapper.c @@ -1,4 +1,4 @@ -/* Simple Plugin API +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -25,12 +25,12 @@ #include #include -#include +#include typedef struct { - SpaTypeMap map; - PinosMap types; - PinosArray strings; + SpaTypeMap map; + struct pw_map types; + struct pw_array strings; } TypeMap; static uint32_t @@ -42,16 +42,16 @@ type_map_get_id (SpaTypeMap *map, const char *type) off_t o; if (type != NULL) { - for (i = 0; i < pinos_map_get_size (&this->types); i++) { - o = (off_t) pinos_map_lookup_unchecked (&this->types, i); + for (i = 0; i < pw_map_get_size (&this->types); i++) { + o = (off_t) pw_map_lookup_unchecked (&this->types, i); if (strcmp (SPA_MEMBER (this->strings.data, o, char), type) == 0) return i; } len = strlen (type); - p = pinos_array_add (&this->strings, SPA_ROUND_UP_N (len+1, 2)); + p = pw_array_add (&this->strings, SPA_ROUND_UP_N (len+1, 2)); memcpy (p, type, len+1); o = (p - this->strings.data); - i = pinos_map_insert_new (&this->types, (void *)o); + i = pw_map_insert_new (&this->types, (void *)o); } return i; } @@ -64,8 +64,8 @@ type_map_get_type (const SpaTypeMap *map, uint32_t id) if (id == SPA_ID_INVALID) return NULL; - if (SPA_LIKELY (pinos_map_check_id (&this->types, id))) { - off_t o = (off_t) pinos_map_lookup_unchecked (&this->types, id); + if (SPA_LIKELY (pw_map_check_id (&this->types, id))) { + off_t o = (off_t) pw_map_lookup_unchecked (&this->types, id); return SPA_MEMBER (this->strings.data, o, char); } return NULL; @@ -75,7 +75,7 @@ static size_t type_map_get_size (const SpaTypeMap *map) { TypeMap *this = SPA_CONTAINER_OF (map, TypeMap, map); - return pinos_map_get_size (&this->types); + return pw_map_get_size (&this->types); } static TypeMap default_type_map = { @@ -85,12 +85,12 @@ static TypeMap default_type_map = { type_map_get_type, type_map_get_size, }, - PINOS_MAP_INIT(128), - PINOS_ARRAY_INIT (4096) + PW_MAP_INIT(128), + PW_ARRAY_INIT (4096) }; SpaTypeMap * -pinos_type_map_get_default (void) +pw_type_map_get_default (void) { spa_type_map_set_default (&default_type_map.map); return &default_type_map.map; diff --git a/pinos/client/mem.c b/pipewire/client/mem.c similarity index 78% rename from pinos/client/mem.c rename to pipewire/client/mem.c index b84edf728..c96df8d99 100644 --- a/pinos/client/mem.c +++ b/pipewire/client/mem.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -31,8 +31,8 @@ #include #include -#include -#include +#include +#include /* * No glibc wrappers exist for memfd_create(2), so provide our own. @@ -76,20 +76,20 @@ static inline int memfd_create(const char *name, unsigned int flags) { #undef USE_MEMFD SpaResult -pinos_memblock_map (PinosMemblock *mem) +pw_memblock_map (struct pw_memblock *mem) { if (mem->ptr != NULL) return SPA_RESULT_OK; - if (mem->flags & PINOS_MEMBLOCK_FLAG_MAP_READWRITE) { + if (mem->flags & PW_MEMBLOCK_FLAG_MAP_READWRITE) { int prot = 0; - if (mem->flags & PINOS_MEMBLOCK_FLAG_MAP_READ) + if (mem->flags & PW_MEMBLOCK_FLAG_MAP_READ) prot |= PROT_READ; - if (mem->flags & PINOS_MEMBLOCK_FLAG_MAP_WRITE) + if (mem->flags & PW_MEMBLOCK_FLAG_MAP_WRITE) prot |= PROT_WRITE; - if (mem->flags & PINOS_MEMBLOCK_FLAG_MAP_TWICE) { + if (mem->flags & PW_MEMBLOCK_FLAG_MAP_TWICE) { void *ptr; mem->ptr = mmap (NULL, mem->size << 1, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); @@ -119,9 +119,9 @@ pinos_memblock_map (PinosMemblock *mem) } SpaResult -pinos_memblock_alloc (PinosMemblockFlags flags, - size_t size, - PinosMemblock *mem) +pw_memblock_alloc (enum pw_memblock_flags flags, + size_t size, + struct pw_memblock *mem) { bool use_fd; @@ -132,39 +132,39 @@ pinos_memblock_alloc (PinosMemblockFlags flags, mem->flags = flags; mem->size = size; - use_fd = !!(flags & (PINOS_MEMBLOCK_FLAG_MAP_TWICE | PINOS_MEMBLOCK_FLAG_WITH_FD)); + use_fd = !!(flags & (PW_MEMBLOCK_FLAG_MAP_TWICE | PW_MEMBLOCK_FLAG_WITH_FD)); if (use_fd) { #ifdef USE_MEMFD - mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); + mem->fd = memfd_create ("pipewire-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (mem->fd == -1) { - pinos_log_error ("Failed to create memfd: %s\n", strerror (errno)); + pw_log_error ("Failed to create memfd: %s\n", strerror (errno)); return SPA_RESULT_ERRNO; } #else char filename[] = "/dev/shm/spa-tmpfile.XXXXXX"; mem->fd = mkostemp (filename, O_CLOEXEC); if (mem->fd == -1) { - pinos_log_error ("Failed to create temporary file: %s\n", strerror (errno)); + pw_log_error ("Failed to create temporary file: %s\n", strerror (errno)); return SPA_RESULT_ERRNO; } unlink (filename); #endif if (ftruncate (mem->fd, size) < 0) { - pinos_log_warn ("Failed to truncate temporary file: %s", strerror (errno)); + pw_log_warn ("Failed to truncate temporary file: %s", strerror (errno)); close (mem->fd); return SPA_RESULT_ERRNO; } #ifdef USE_MEMFD - if (flags & PINOS_MEMBLOCK_FLAG_SEAL) { + if (flags & PW_MEMBLOCK_FLAG_SEAL) { unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) { - pinos_log_warn ("Failed to add seals: %s", strerror (errno)); + pw_log_warn ("Failed to add seals: %s", strerror (errno)); } } #endif - if (pinos_memblock_map (mem) != SPA_RESULT_OK) + if (pw_memblock_map (mem) != SPA_RESULT_OK) goto mmap_failed; } else { mem->ptr = malloc (size); @@ -172,7 +172,7 @@ pinos_memblock_alloc (PinosMemblockFlags flags, return SPA_RESULT_NO_MEMORY; mem->fd = -1; } - if (!(flags & PINOS_MEMBLOCK_FLAG_WITH_FD) && mem->fd != -1) { + if (!(flags & PW_MEMBLOCK_FLAG_WITH_FD) && mem->fd != -1) { close (mem->fd); mem->fd = -1; } @@ -184,12 +184,12 @@ mmap_failed: } void -pinos_memblock_free (PinosMemblock *mem) +pw_memblock_free (struct pw_memblock *mem) { if (mem == NULL) return; - if (mem->flags & PINOS_MEMBLOCK_FLAG_WITH_FD) { + if (mem->flags & PW_MEMBLOCK_FLAG_WITH_FD) { if (mem->ptr) munmap (mem->ptr, mem->size); if (mem->fd != -1) diff --git a/pinos/client/mem.h b/pipewire/client/mem.h similarity index 51% rename from pinos/client/mem.h rename to pipewire/client/mem.h index 88032dc13..28174f043 100644 --- a/pinos/client/mem.h +++ b/pipewire/client/mem.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_MEM_H__ -#define __PINOS_MEM_H__ +#ifndef __PIPEWIRE_MEM_H__ +#define __PIPEWIRE_MEM_H__ #include @@ -26,35 +26,33 @@ extern "C" { #endif -typedef struct _PinosMemblock PinosMemblock; +enum pw_memblock_flags { + PW_MEMBLOCK_FLAG_NONE = 0, + PW_MEMBLOCK_FLAG_WITH_FD = (1 << 0), + PW_MEMBLOCK_FLAG_SEAL = (1 << 1), + PW_MEMBLOCK_FLAG_MAP_READ = (1 << 2), + PW_MEMBLOCK_FLAG_MAP_WRITE = (1 << 3), + PW_MEMBLOCK_FLAG_MAP_TWICE = (1 << 4), +}; -typedef enum { - PINOS_MEMBLOCK_FLAG_NONE = 0, - PINOS_MEMBLOCK_FLAG_WITH_FD = (1 << 0), - PINOS_MEMBLOCK_FLAG_SEAL = (1 << 1), - PINOS_MEMBLOCK_FLAG_MAP_READ = (1 << 2), - PINOS_MEMBLOCK_FLAG_MAP_WRITE = (1 << 3), - PINOS_MEMBLOCK_FLAG_MAP_TWICE = (1 << 4), -} PinosMemblockFlags; +#define PW_MEMBLOCK_FLAG_MAP_READWRITE (PW_MEMBLOCK_FLAG_MAP_READ | PW_MEMBLOCK_FLAG_MAP_WRITE) -#define PINOS_MEMBLOCK_FLAG_MAP_READWRITE (PINOS_MEMBLOCK_FLAG_MAP_READ | PINOS_MEMBLOCK_FLAG_MAP_WRITE) - -struct _PinosMemblock { - PinosMemblockFlags flags; +struct pw_memblock { + enum pw_memblock_flags flags; int fd; off_t offset; void *ptr; size_t size; }; -SpaResult pinos_memblock_alloc (PinosMemblockFlags flags, - size_t size, - PinosMemblock *mem); -SpaResult pinos_memblock_map (PinosMemblock *mem); -void pinos_memblock_free (PinosMemblock *mem); +SpaResult pw_memblock_alloc (enum pw_memblock_flags flags, + size_t size, + struct pw_memblock *mem); +SpaResult pw_memblock_map (struct pw_memblock *mem); +void pw_memblock_free (struct pw_memblock *mem); #ifdef __cplusplus } #endif -#endif /* __PINOS_MEM_H__ */ +#endif /* __PIPEWIRE_MEM_H__ */ diff --git a/pinos/client/memfd-wrappers.h b/pipewire/client/memfd-wrappers.h similarity index 99% rename from pinos/client/memfd-wrappers.h rename to pipewire/client/memfd-wrappers.h index 7470f5638..f6f7d14ba 100644 --- a/pinos/client/memfd-wrappers.h +++ b/pipewire/client/memfd-wrappers.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or diff --git a/pinos/client/meson.build b/pipewire/client/meson.build similarity index 74% rename from pinos/client/meson.build rename to pipewire/client/meson.build index 9c0dcf05a..9cda8f8ae 100644 --- a/pinos/client/meson.build +++ b/pipewire/client/meson.build @@ -1,4 +1,4 @@ -pinos_headers = [ +pipewire_headers = [ 'array.h', 'connection.h', 'context.h', @@ -8,7 +8,7 @@ pinos_headers = [ 'loop.h', 'map.h', 'mem.h', - 'pinos.h', + 'pipewire.h', 'properties.h', 'protocol-native.h', 'proxy.h', @@ -22,7 +22,7 @@ pinos_headers = [ 'utils.h', ] -pinos_sources = [ +pipewire_sources = [ 'connection.c', 'context.c', 'introspect.c', @@ -34,7 +34,7 @@ pinos_sources = [ 'protocol-native.c', 'proxy.c', 'stream.c', - 'pinos.c', + 'pipewire.c', 'rtkit.c', 'thread-mainloop.c', 'transport.c', @@ -42,26 +42,26 @@ pinos_sources = [ 'utils.c', ] -install_headers(pinos_headers, subdir : 'pinos/client') +install_headers(pipewire_headers, subdir : 'pipewire/client') -libpinos_c_args = [ +libpipewire_c_args = [ '-DHAVE_CONFIG_H', '-D_GNU_SOURCE', '-D_POSIX_C_SOURCE', ] -libpinos = shared_library('pinos', pinos_sources, +libpipewire = shared_library('pipewire', pipewire_sources, version : libversion, soversion : soversion, - c_args : libpinos_c_args, + c_args : libpipewire_c_args, include_directories : [configinc, spa_inc], link_with : spalib, install : true, dependencies : [dbus_dep, mathlib, pthread_lib], ) -pinos_dep = declare_dependency(link_with : libpinos, +pipewire_dep = declare_dependency(link_with : libpipewire, include_directories : [configinc, spa_inc], dependencies : [pthread_lib], ) diff --git a/pipewire/client/pipewire.c b/pipewire/client/pipewire.c new file mode 100644 index 000000000..34f9b8c21 --- /dev/null +++ b/pipewire/client/pipewire.c @@ -0,0 +1,157 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include "pipewire/client/pipewire.h" + +/** + * pw_init: + * @argc: pointer to argc + * @argv: pointer to argv + * + * initialize the PipeWire system, parse and modify any parameters given + * by @argc and @argv. + */ +void +pw_init (int *argc, char **argv[]) +{ + const char *str; + + if ((str = getenv ("PIPEWIRE_DEBUG"))) + pw_log_set_level (atoi (str)); +} + +const char * +pw_get_application_name (void) +{ + return NULL; +} + +const char * +pw_get_prgname (void) +{ + static char tcomm[16+1]; + spa_zero(tcomm); + + if (prctl (PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0) + return tcomm; + + return NULL; +} + +const char * +pw_get_user_name (void) +{ + struct passwd *pw; + + if ((pw = getpwuid (getuid ()))) + return pw->pw_name; + + return NULL; +} + +const char * +pw_get_host_name (void) +{ + static char hname[256]; + + if (gethostname (hname, 256) < 0) + return NULL; + + hname[255] = 0; + return hname; +} + +/** + * pw_client_name: + * + * Make a new PipeWire client name that can be used to construct a context. + */ +char * +pw_client_name (void) +{ + char *c; + const char *cc; + + if ((cc = pw_get_application_name ())) + return strdup (cc); + else if ((cc = pw_get_prgname ())) + return strdup (cc); + else { + asprintf (&c, "pipewire-pid-%zd", (size_t) getpid ()); + return c; + } +} + +/** + * pw_fill_context_properties: + * @properties: a #struct pw_properties + * + * Fill @properties with a set of default context properties. + */ +void +pw_fill_context_properties (struct pw_properties *properties) +{ + if (!pw_properties_get (properties, "application.name")) + pw_properties_set (properties, "application.name", pw_get_application_name ()); + + if (!pw_properties_get (properties, "application.prgname")) + pw_properties_set (properties, "application.prgname", pw_get_prgname ()); + + if (!pw_properties_get (properties, "application.language")) { + pw_properties_set (properties, "application.language", getenv ("LANG")); + } + if (!pw_properties_get (properties, "application.process.id")) { + pw_properties_setf (properties, "application.process.id", "%zd", (size_t) getpid ()); + } + if (!pw_properties_get (properties, "application.process.user")) + pw_properties_set (properties, "application.process.user", pw_get_user_name ()); + + if (!pw_properties_get (properties, "application.process.host")) + pw_properties_set (properties, "application.process.host", pw_get_host_name ()); + + if (!pw_properties_get (properties, "application.process.session_id")) { + pw_properties_set (properties, "application.process.session_id", getenv ("XDG_SESSION_ID")); + } +} + +/** + * pw_fill_stream_properties + * @properties: a #struct pw_properties + * + * Fill @properties with a set of default stream properties. + */ +void +pw_fill_stream_properties (struct pw_properties *properties) +{ +} + +enum pw_direction +pw_direction_reverse (enum pw_direction direction) +{ + if (direction == PW_DIRECTION_INPUT) + return PW_DIRECTION_OUTPUT; + else if (direction == PW_DIRECTION_OUTPUT) + return PW_DIRECTION_INPUT; + return direction; +} diff --git a/pipewire/client/pipewire.h b/pipewire/client/pipewire.h new file mode 100644 index 000000000..89b695a21 --- /dev/null +++ b/pipewire/client/pipewire.h @@ -0,0 +1,60 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_H__ +#define __PIPEWIRE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +void pw_init (int *argc, char **argv[]); + +const char * pw_get_application_name (void); +const char * pw_get_prgname (void); +const char * pw_get_user_name (void); +const char * pw_get_host_name (void); + +char * pw_client_name (void); + +void pw_fill_context_properties (struct pw_properties *properties); +void pw_fill_stream_properties (struct pw_properties *properties); + +enum pw_direction pw_direction_reverse (enum pw_direction direction); + +SpaTypeMap * pw_type_map_get_default (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_H__ */ diff --git a/pinos/client/properties.c b/pipewire/client/properties.c similarity index 51% rename from pinos/client/properties.c rename to pipewire/client/properties.c index e33e04a6d..f2cdef45a 100644 --- a/pinos/client/properties.c +++ b/pipewire/client/properties.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,27 +17,27 @@ * Boston, MA 02110-1301, USA. */ -#include "pinos/client/pinos.h" -#include "pinos/client/properties.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/properties.h" -typedef struct { - PinosProperties this; +struct properties { + struct pw_properties this; - PinosArray items; -} PinosPropertiesImpl; + struct pw_array items; +}; static void -add_func (PinosProperties *this, char *key, char *value) +add_func (struct pw_properties *this, char *key, char *value) { SpaDictItem *item; - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (this, PinosPropertiesImpl, this); + struct properties *impl = SPA_CONTAINER_OF (this, struct properties, this); - item = pinos_array_add (&impl->items, sizeof (SpaDictItem)); + item = pw_array_add (&impl->items, sizeof (SpaDictItem)); item->key = key; item->value = value; this->dict.items = impl->items.data; - this->dict.n_items = pinos_array_get_len (&impl->items, SpaDictItem); + this->dict.n_items = pw_array_get_len (&impl->items, SpaDictItem); } static void @@ -48,13 +48,13 @@ clear_item (SpaDictItem *item) } static int -find_index (PinosProperties *this, const char *key) +find_index (struct pw_properties *this, const char *key) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (this, PinosPropertiesImpl, this); - int i, len = pinos_array_get_len (&impl->items, SpaDictItem); + struct properties *impl = SPA_CONTAINER_OF (this, struct properties, this); + int i, len = pw_array_get_len (&impl->items, SpaDictItem); for (i = 0; i < len; i++) { - SpaDictItem *item = pinos_array_get_unchecked (&impl->items, i, SpaDictItem); + SpaDictItem *item = pw_array_get_unchecked (&impl->items, i, SpaDictItem); if (strcmp (item->key, key) == 0) return i; } @@ -62,26 +62,26 @@ find_index (PinosProperties *this, const char *key) } /** - * pinos_properties_new: + * pw_properties_new: * @key: first key * @...: value * - * Make a new #PinosProperties with given, NULL-terminated key/value pairs. + * Make a new #struct pw_properties with given, NULL-terminated key/value pairs. * - * Returns: a new #PinosProperties + * Returns: a new #struct pw_properties */ -PinosProperties * -pinos_properties_new (const char *key, ...) +struct pw_properties * +pw_properties_new (const char *key, ...) { - PinosPropertiesImpl *impl; + struct properties *impl; va_list varargs; const char *value; - impl = calloc (1, sizeof (PinosPropertiesImpl)); + impl = calloc (1, sizeof (struct properties)); if (impl == NULL) return NULL; - pinos_array_init (&impl->items, 16); + pw_array_init (&impl->items, 16); va_start (varargs, key); while (key != NULL) { @@ -95,24 +95,24 @@ pinos_properties_new (const char *key, ...) } /** - * pinos_properties_new_dict: + * pw_properties_new_dict: * @dict: a dict * - * Make a new #PinosProperties with given @dict. + * Make a new #struct pw_properties with given @dict. * - * Returns: a new #PinosProperties + * Returns: a new #struct pw_properties */ -PinosProperties * -pinos_properties_new_dict (const SpaDict *dict) +struct pw_properties * +pw_properties_new_dict (const SpaDict *dict) { uint32_t i; - PinosPropertiesImpl *impl; + struct properties *impl; - impl = calloc (1, sizeof (PinosPropertiesImpl)); + impl = calloc (1, sizeof (struct properties)); if (impl == NULL) return NULL; - pinos_array_init (&impl->items, 16); + pw_array_init (&impl->items, 16); for (i = 0; i < dict->n_items; i++) add_func (&impl->this, strdup (dict->items[i].key), strdup (dict->items[i].value)); @@ -121,96 +121,96 @@ pinos_properties_new_dict (const SpaDict *dict) } /** - * pinos_properties_copy: - * @properties: a #PinosProperties + * pw_properties_copy: + * @properties: a #struct pw_properties * * Make a copy of @properties. * * Returns: a copy of @properties */ -PinosProperties * -pinos_properties_copy (PinosProperties *properties) +struct pw_properties * +pw_properties_copy (struct pw_properties *properties) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (properties, PinosPropertiesImpl, this); - PinosProperties *copy; + struct properties *impl = SPA_CONTAINER_OF (properties, struct properties, this); + struct pw_properties *copy; SpaDictItem *item; - copy = pinos_properties_new (NULL, NULL); + copy = pw_properties_new (NULL, NULL); if (copy == NULL) return NULL; - pinos_array_for_each (item, &impl->items) + pw_array_for_each (item, &impl->items) add_func (copy, strdup (item->key), strdup (item->value)); return copy; } -PinosProperties * -pinos_properties_merge (PinosProperties *oldprops, - PinosProperties *newprops) +struct pw_properties * +pw_properties_merge (struct pw_properties *oldprops, + struct pw_properties *newprops) { - PinosProperties *res = NULL; + struct pw_properties *res = NULL; if (oldprops == NULL) { if (newprops == NULL) res = NULL; else - res = pinos_properties_copy (newprops); + res = pw_properties_copy (newprops); } else if (newprops == NULL) { - res = pinos_properties_copy (oldprops); + res = pw_properties_copy (oldprops); } else { const char *key; void * state = NULL; - res = pinos_properties_copy (oldprops); + res = pw_properties_copy (oldprops); if (res == NULL) return NULL; - while ((key = pinos_properties_iterate (newprops, &state))) { - pinos_properties_set (res, + while ((key = pw_properties_iterate (newprops, &state))) { + pw_properties_set (res, key, - pinos_properties_get (newprops, key)); + pw_properties_get (newprops, key)); } } return res; } /** - * pinos_properties_free: - * @properties: a #PinosProperties + * pw_properties_free: + * @properties: a #struct pw_properties * * Free @properties */ void -pinos_properties_free (PinosProperties *properties) +pw_properties_free (struct pw_properties *properties) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (properties, PinosPropertiesImpl, this); + struct properties *impl = SPA_CONTAINER_OF (properties, struct properties, this); SpaDictItem *item; - pinos_array_for_each (item, &impl->items) + pw_array_for_each (item, &impl->items) clear_item (item); - pinos_array_clear (&impl->items); + pw_array_clear (&impl->items); free (impl); } static void -do_replace (PinosProperties *properties, - char *key, - char *value) +do_replace (struct pw_properties *properties, + char *key, + char *value) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (properties, PinosPropertiesImpl, this); + struct properties *impl = SPA_CONTAINER_OF (properties, struct properties, this); int index = find_index (properties, key); if (index == -1) { add_func (properties, key, value); } else { - SpaDictItem *item = pinos_array_get_unchecked (&impl->items, index, SpaDictItem); + SpaDictItem *item = pw_array_get_unchecked (&impl->items, index, SpaDictItem); clear_item (item); if (value == NULL) { - SpaDictItem *other = pinos_array_get_unchecked (&impl->items, - pinos_array_get_len (&impl->items, SpaDictItem) - 1, + SpaDictItem *other = pw_array_get_unchecked (&impl->items, + pw_array_get_len (&impl->items, SpaDictItem) - 1, SpaDictItem); item->key = other->key; item->value = other->value; @@ -223,8 +223,8 @@ do_replace (PinosProperties *properties, } /** - * pinos_properties_set: - * @properties: a #PinosProperties + * pw_properties_set: + * @properties: a #struct pw_properties * @key: a key * @value: a value * @@ -233,16 +233,16 @@ do_replace (PinosProperties *properties, * removed. */ void -pinos_properties_set (PinosProperties *properties, - const char *key, - const char *value) +pw_properties_set (struct pw_properties *properties, + const char *key, + const char *value) { do_replace (properties, strdup (key), value ? strdup (value) : NULL); } /** - * pinos_properties_setf: - * @properties: a #PinosProperties + * pw_properties_setf: + * @properties: a #struct pw_properties * @key: a key * @format: a value * @...: extra arguments @@ -251,10 +251,10 @@ pinos_properties_set (PinosProperties *properties, * Any previous value of @key will be overwritten. */ void -pinos_properties_setf (PinosProperties *properties, - const char *key, - const char *format, - ...) +pw_properties_setf (struct pw_properties *properties, + const char *key, + const char *format, + ...) { va_list varargs; char *value; @@ -267,8 +267,8 @@ pinos_properties_setf (PinosProperties *properties, } /** - * pinos_properties_get: - * @properties: a #PinosProperties + * pw_properties_get: + * @properties: a #struct pw_properties * @key: a key * * Get the property in @properties with @key. @@ -276,21 +276,21 @@ pinos_properties_setf (PinosProperties *properties, * Returns: the property for @key or %NULL when the key was not found */ const char * -pinos_properties_get (PinosProperties *properties, - const char *key) +pw_properties_get (struct pw_properties *properties, + const char *key) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (properties, PinosPropertiesImpl, this); + struct properties *impl = SPA_CONTAINER_OF (properties, struct properties, this); int index = find_index (properties, key); if (index == -1) return NULL; - return pinos_array_get_unchecked (&impl->items, index, SpaDictItem)->value; + return pw_array_get_unchecked (&impl->items, index, SpaDictItem)->value; } /** - * pinos_properties_iterate: - * @properties: a #PinosProperties + * pw_properties_iterate: + * @properties: a #struct pw_properties * @state: state * * Iterate over @properties, returning each key in turn. @state should point @@ -303,10 +303,10 @@ pinos_properties_get (PinosProperties *properties, * Returns: The next key or %NULL when there are no more keys to iterate. */ const char * -pinos_properties_iterate (PinosProperties *properties, - void **state) +pw_properties_iterate (struct pw_properties *properties, + void **state) { - PinosPropertiesImpl *impl = SPA_CONTAINER_OF (properties, PinosPropertiesImpl, this); + struct properties *impl = SPA_CONTAINER_OF (properties, struct properties, this); uint32_t index; if (*state == NULL) @@ -314,10 +314,10 @@ pinos_properties_iterate (PinosProperties *properties, else index = SPA_PTR_TO_INT (*state); - if (!pinos_array_check_index (&impl->items, index, SpaDictItem)) + if (!pw_array_check_index (&impl->items, index, SpaDictItem)) return NULL; *state = SPA_INT_TO_PTR (index + 1); - return pinos_array_get_unchecked (&impl->items, index, SpaDictItem)->key; + return pw_array_get_unchecked (&impl->items, index, SpaDictItem)->key; } diff --git a/pipewire/client/properties.h b/pipewire/client/properties.h new file mode 100644 index 000000000..4f58acadc --- /dev/null +++ b/pipewire/client/properties.h @@ -0,0 +1,57 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_PROPERTIES_H__ +#define __PIPEWIRE_PROPERTIES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct pw_properties { + SpaDict dict; +}; + +struct pw_properties * pw_properties_new (const char *key, ...); +struct pw_properties * pw_properties_new_dict (const SpaDict *dict); +struct pw_properties * pw_properties_copy (struct pw_properties *properties); +struct pw_properties * pw_properties_merge (struct pw_properties *oldprops, + struct pw_properties *newprops); +void pw_properties_free (struct pw_properties *properties); + +void pw_properties_set (struct pw_properties *properties, + const char *key, + const char *value); +void pw_properties_setf (struct pw_properties *properties, + const char *key, + const char *format, + ...) SPA_PRINTF_FUNC (3, 4); +const char * pw_properties_get (struct pw_properties *properties, + const char *key); + +const char * pw_properties_iterate (struct pw_properties *properties, + void **state); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_PROPERTIES_H__ */ diff --git a/pinos/client/protocol-native.c b/pipewire/client/protocol-native.c similarity index 71% rename from pinos/client/protocol-native.c rename to pipewire/client/protocol-native.c index 62d4612dd..cb05ca62c 100644 --- a/pinos/client/protocol-native.c +++ b/pipewire/client/protocol-native.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -20,18 +20,18 @@ #include #include "spa/pod-iter.h" -#include "pinos/client/pinos.h" +#include "pipewire/client/pipewire.h" -#include "pinos/client/protocol-native.h" -#include "pinos/client/interfaces.h" -#include "pinos/client/connection.h" +#include "pipewire/client/protocol-native.h" +#include "pipewire/client/interfaces.h" +#include "pipewire/client/connection.h" -typedef struct { +struct builder { SpaPODBuilder b; - PinosConnection *connection; -} Builder; + struct pw_connection *connection; +}; -typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size); +typedef bool (*demarshal_func_t) (void *object, void *data, size_t size); static uint32_t write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size) @@ -41,14 +41,14 @@ write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size) if (b->size <= b->offset) { b->size = SPA_ROUND_UP_N (b->offset + size, 4096); - b->data = pinos_connection_begin_write (((Builder*)b)->connection, b->size); + b->data = pw_connection_begin_write (((struct builder*)b)->connection, b->size); } memcpy (b->data + ref, data, size); return ref; } static void -core_update_map (PinosContext *context) +core_update_map (struct pw_context *context) { uint32_t diff, base, i; const char **types; @@ -62,7 +62,7 @@ core_update_map (PinosContext *context) for (i = 0; i < diff; i++, base++) types[i] = spa_type_map_get_type (context->type.map, base); - pinos_core_do_update_types (context->core_proxy, + pw_core_do_update_types (context->core_proxy, context->n_types, diff, types); @@ -73,9 +73,9 @@ static void core_marshal_client_update (void *object, const SpaDict *props) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; int i, n_items; @@ -98,16 +98,16 @@ core_marshal_client_update (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CLIENT_UPDATE, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_CLIENT_UPDATE, b.b.offset); } static void core_marshal_sync (void *object, uint32_t seq) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -118,16 +118,16 @@ core_marshal_sync (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_INT, seq); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_SYNC, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_SYNC, b.b.offset); } static void core_marshal_get_registry (void *object, uint32_t new_id) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -138,7 +138,7 @@ core_marshal_get_registry (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_INT, new_id); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_GET_REGISTRY, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_GET_REGISTRY, b.b.offset); } static void @@ -148,9 +148,9 @@ core_marshal_create_node (void *object, const SpaDict *props, uint32_t new_id) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -177,7 +177,7 @@ core_marshal_create_node (void *object, SPA_POD_TYPE_INT, new_id, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CREATE_NODE, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_CREATE_NODE, b.b.offset); } static void @@ -186,9 +186,9 @@ core_marshal_create_client_node (void *object, const SpaDict *props, uint32_t new_id) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -214,7 +214,7 @@ core_marshal_create_client_node (void *object, SPA_POD_TYPE_INT, new_id, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CREATE_CLIENT_NODE, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_CREATE_CLIENT_NODE, b.b.offset); } static void @@ -223,9 +223,9 @@ core_marshal_update_types (void *object, uint32_t n_types, const char **types) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i; @@ -244,7 +244,7 @@ core_marshal_update_types (void *object, spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_UPDATE_TYPES, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CORE_METHOD_UPDATE_TYPES, b.b.offset); } static bool @@ -252,9 +252,9 @@ core_demarshal_info (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaDict props; - PinosCoreInfo info; + struct pw_core_info info; SpaPODIter it; int i; @@ -280,7 +280,7 @@ core_demarshal_info (void *object, 0)) return false; } - ((PinosCoreEvents*)proxy->implementation)->info (proxy, &info); + ((struct pw_core_events*)proxy->implementation)->info (proxy, &info); return true; } @@ -289,7 +289,7 @@ core_demarshal_done (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t seq; @@ -299,7 +299,7 @@ core_demarshal_done (void *object, 0)) return false; - ((PinosCoreEvents*)proxy->implementation)->done (proxy, seq); + ((struct pw_core_events*)proxy->implementation)->done (proxy, seq); return true; } @@ -308,7 +308,7 @@ core_demarshal_error (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t id, res; const char *error; @@ -321,7 +321,7 @@ core_demarshal_error (void *object, 0)) return false; - ((PinosCoreEvents*)proxy->implementation)->error (proxy, id, res, error); + ((struct pw_core_events*)proxy->implementation)->error (proxy, id, res, error); return true; } @@ -330,7 +330,7 @@ core_demarshal_remove_id (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t id; @@ -340,7 +340,7 @@ core_demarshal_remove_id (void *object, 0)) return false; - ((PinosCoreEvents*)proxy->implementation)->remove_id (proxy, id); + ((struct pw_core_events*)proxy->implementation)->remove_id (proxy, id); return true; } @@ -349,7 +349,7 @@ core_demarshal_update_types (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t first_id, n_types; const char **types; @@ -367,7 +367,7 @@ core_demarshal_update_types (void *object, if (!spa_pod_iter_get (&it, SPA_POD_TYPE_STRING, &types[i], 0)) return false; } - ((PinosCoreEvents*)proxy->implementation)->update_types (proxy, first_id, n_types, types); + ((struct pw_core_events*)proxy->implementation)->update_types (proxy, first_id, n_types, types); return true; } @@ -376,10 +376,10 @@ module_demarshal_info (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; SpaDict props; - PinosModuleInfo info; + struct pw_module_info info; int i; if (!spa_pod_iter_struct (&it, data, size) || @@ -402,7 +402,7 @@ module_demarshal_info (void *object, 0)) return false; } - ((PinosModuleEvents*)proxy->implementation)->info (proxy, &info); + ((struct pw_module_events*)proxy->implementation)->info (proxy, &info); return true; } @@ -411,14 +411,14 @@ node_demarshal_info (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; SpaDict props; - PinosNodeInfo info; + struct pw_node_info info; int i; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &info.id, SPA_POD_TYPE_LONG, &info.change_mask, @@ -462,7 +462,7 @@ node_demarshal_info (void *object, 0)) return false; } - ((PinosNodeEvents*)proxy->implementation)->info (proxy, &info); + ((struct pw_node_events*)proxy->implementation)->info (proxy, &info); return true; } @@ -473,9 +473,9 @@ client_node_marshal_update (void *object, uint32_t max_output_ports, const SpaProps *props) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -489,7 +489,7 @@ client_node_marshal_update (void *object, SPA_POD_TYPE_INT, max_output_ports, SPA_POD_TYPE_POD, props); - pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_UPDATE, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CLIENT_NODE_METHOD_UPDATE, b.b.offset); } static void @@ -504,9 +504,9 @@ client_node_marshal_port_update (void *object, const SpaParam **params, const SpaPortInfo *info) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f[2]; int i; @@ -548,16 +548,16 @@ client_node_marshal_port_update (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f[0], 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_PORT_UPDATE, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CLIENT_NODE_METHOD_PORT_UPDATE, b.b.offset); } static void client_node_marshal_event (void *object, SpaEvent *event) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -568,15 +568,15 @@ client_node_marshal_event (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_POD, event); - pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_EVENT, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CLIENT_NODE_METHOD_EVENT, b.b.offset); } static void client_node_marshal_destroy (void *object) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -586,7 +586,7 @@ client_node_marshal_destroy (void *object) spa_pod_builder_struct (&b.b, &f, 0); - pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_DESTROY, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_CLIENT_NODE_METHOD_DESTROY, b.b.offset); } static bool @@ -594,9 +594,9 @@ client_node_demarshal_done (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; - PinosConnection *connection = proxy->context->protocol_private; + struct pw_connection *connection = proxy->context->protocol_private; int32_t ridx, widx; int readfd, writefd; @@ -607,12 +607,12 @@ client_node_demarshal_done (void *object, 0)) return false; - readfd = pinos_connection_get_fd (connection, ridx); - writefd = pinos_connection_get_fd (connection, widx); + readfd = pw_connection_get_fd (connection, ridx); + writefd = pw_connection_get_fd (connection, widx); if (readfd == -1 || writefd == -1) return false; - ((PinosClientNodeEvents*)proxy->implementation)->done (proxy, readfd, writefd); + ((struct pw_client_node_events*)proxy->implementation)->done (proxy, readfd, writefd); return true; } @@ -621,18 +621,18 @@ client_node_demarshal_event (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; const SpaEvent *event; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &event, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->event (proxy, event); + ((struct pw_client_node_events*)proxy->implementation)->event (proxy, event); return true; } @@ -641,7 +641,7 @@ client_node_demarshal_add_port (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; int32_t seq, direction, port_id; @@ -653,7 +653,7 @@ client_node_demarshal_add_port (void *object, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->add_port (proxy, seq, direction, port_id); + ((struct pw_client_node_events*)proxy->implementation)->add_port (proxy, seq, direction, port_id); return true; } @@ -662,7 +662,7 @@ client_node_demarshal_remove_port (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; int32_t seq, direction, port_id; @@ -674,7 +674,7 @@ client_node_demarshal_remove_port (void *object, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->remove_port (proxy, seq, direction, port_id); + ((struct pw_client_node_events*)proxy->implementation)->remove_port (proxy, seq, direction, port_id); return true; } @@ -683,13 +683,13 @@ client_node_demarshal_set_format (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t seq, direction, port_id, flags; const SpaFormat *format = NULL; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &seq, SPA_POD_TYPE_INT, &direction, @@ -699,7 +699,7 @@ client_node_demarshal_set_format (void *object, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->set_format (proxy, seq, direction, port_id, + ((struct pw_client_node_events*)proxy->implementation)->set_format (proxy, seq, direction, port_id, flags, format); return true; } @@ -709,7 +709,7 @@ client_node_demarshal_set_property (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t seq, id; const void *value; @@ -723,7 +723,7 @@ client_node_demarshal_set_property (void *object, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->set_property (proxy, seq, id, s, value); + ((struct pw_client_node_events*)proxy->implementation)->set_property (proxy, seq, id, s, value); return true; } @@ -732,14 +732,14 @@ client_node_demarshal_add_mem (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; - PinosConnection *connection = proxy->context->protocol_private; + struct pw_connection *connection = proxy->context->protocol_private; uint32_t direction, port_id, mem_id, type, memfd_idx, flags, offset, sz; int memfd; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &direction, SPA_POD_TYPE_INT, &port_id, @@ -752,9 +752,9 @@ client_node_demarshal_add_mem (void *object, 0)) return false; - memfd = pinos_connection_get_fd (connection, memfd_idx); + memfd = pw_connection_get_fd (connection, memfd_idx); - ((PinosClientNodeEvents*)proxy->implementation)->add_mem (proxy, + ((struct pw_client_node_events*)proxy->implementation)->add_mem (proxy, direction, port_id, mem_id, @@ -771,14 +771,14 @@ client_node_demarshal_use_buffers (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t seq, direction, port_id, n_buffers, data_id; - PinosClientNodeBuffer *buffers; + struct pw_client_node_buffer *buffers; int i, j; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &seq, SPA_POD_TYPE_INT, &direction, @@ -787,7 +787,7 @@ client_node_demarshal_use_buffers (void *object, 0)) return false; - buffers = alloca (sizeof (PinosClientNodeBuffer) * n_buffers); + buffers = alloca (sizeof (struct pw_client_node_buffer) * n_buffers); for (i = 0; i < n_buffers; i++) { SpaBuffer *buf = buffers[i].buffer = alloca (sizeof (SpaBuffer)); @@ -827,7 +827,7 @@ client_node_demarshal_use_buffers (void *object, d->data = SPA_UINT32_TO_PTR (data_id); } } - ((PinosClientNodeEvents*)proxy->implementation)->use_buffers (proxy, + ((struct pw_client_node_events*)proxy->implementation)->use_buffers (proxy, seq, direction, port_id, @@ -841,20 +841,20 @@ client_node_demarshal_node_command (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; const SpaCommand *command; uint32_t seq; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &seq, SPA_POD_TYPE_OBJECT, &command, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->node_command (proxy, seq, command); + ((struct pw_client_node_events*)proxy->implementation)->node_command (proxy, seq, command); return true; } @@ -863,20 +863,20 @@ client_node_demarshal_port_command (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; const SpaCommand *command; uint32_t port_id; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &port_id, SPA_POD_TYPE_OBJECT, &command, 0)) return false; - ((PinosClientNodeEvents*)proxy->implementation)->port_command (proxy, port_id, command); + ((struct pw_client_node_events*)proxy->implementation)->port_command (proxy, port_id, command); return true; } @@ -885,9 +885,9 @@ client_node_demarshal_transport (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; - PinosConnection *connection = proxy->context->protocol_private; + struct pw_connection *connection = proxy->context->protocol_private; uint32_t memfd_idx, offset, sz; int memfd; @@ -899,8 +899,8 @@ client_node_demarshal_transport (void *object, 0)) return false; - memfd = pinos_connection_get_fd (connection, memfd_idx); - ((PinosClientNodeEvents*)proxy->implementation)->transport (proxy, memfd, offset, sz); + memfd = pw_connection_get_fd (connection, memfd_idx); + ((struct pw_client_node_events*)proxy->implementation)->transport (proxy, memfd, offset, sz); return true; } @@ -909,10 +909,10 @@ client_demarshal_info (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; SpaDict props; - PinosClientInfo info; + struct pw_client_info info; uint32_t i; if (!spa_pod_iter_struct (&it, data, size) || @@ -932,7 +932,7 @@ client_demarshal_info (void *object, 0)) return false; } - ((PinosClientEvents*)proxy->implementation)->info (proxy, &info); + ((struct pw_client_events*)proxy->implementation)->info (proxy, &info); return true; } @@ -941,9 +941,9 @@ link_demarshal_info (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; - PinosLinkInfo info; + struct pw_link_info info; if (!spa_pod_iter_struct (&it, data, size) || !spa_pod_iter_get (&it, @@ -956,7 +956,7 @@ link_demarshal_info (void *object, 0)) return false; - ((PinosLinkEvents*)proxy->implementation)->info (proxy, &info); + ((struct pw_link_events*)proxy->implementation)->info (proxy, &info); return true; } @@ -965,7 +965,7 @@ registry_demarshal_global (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t id; const char *type; @@ -977,7 +977,7 @@ registry_demarshal_global (void *object, 0)) return false; - ((PinosRegistryEvents*)proxy->implementation)->global (proxy, id, type); + ((struct pw_registry_events*)proxy->implementation)->global (proxy, id, type); return true; } @@ -986,7 +986,7 @@ registry_demarshal_global_remove (void *object, void *data, size_t size) { - PinosProxy *proxy = object; + struct pw_proxy *proxy = object; SpaPODIter it; uint32_t id; @@ -996,7 +996,7 @@ registry_demarshal_global_remove (void *object, 0)) return false; - ((PinosRegistryEvents*)proxy->implementation)->global_remove (proxy, id); + ((struct pw_registry_events*)proxy->implementation)->global_remove (proxy, id); return true; } @@ -1005,9 +1005,9 @@ registry_marshal_bind (void *object, uint32_t id, uint32_t new_id) { - PinosProxy *proxy = object; - PinosConnection *connection = proxy->context->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_proxy *proxy = object; + struct pw_connection *connection = proxy->context->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; if (connection == NULL) @@ -1019,10 +1019,10 @@ registry_marshal_bind (void *object, SPA_POD_TYPE_INT, id, SPA_POD_TYPE_INT, new_id); - pinos_connection_end_write (connection, proxy->id, PINOS_REGISTRY_METHOD_BIND, b.b.offset); + pw_connection_end_write (connection, proxy->id, PW_REGISTRY_METHOD_BIND, b.b.offset); } -static const PinosCoreMethods pinos_protocol_native_client_core_methods = { +static const struct pw_core_methods pw_protocol_native_client_core_methods = { &core_marshal_client_update, &core_marshal_sync, &core_marshal_get_registry, @@ -1031,7 +1031,7 @@ static const PinosCoreMethods pinos_protocol_native_client_core_methods = { &core_marshal_update_types, }; -static const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_core_demarshal[] = { &core_demarshal_info, &core_demarshal_done, &core_demarshal_error, @@ -1039,33 +1039,33 @@ static const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[] = &core_demarshal_update_types, }; -static const PinosInterface pinos_protocol_native_client_core_interface = { - PINOS_CORE_METHOD_NUM, &pinos_protocol_native_client_core_methods, - PINOS_CORE_EVENT_NUM, pinos_protocol_native_client_core_demarshal +static const struct pw_interface pw_protocol_native_client_core_interface = { + PW_CORE_METHOD_NUM, &pw_protocol_native_client_core_methods, + PW_CORE_EVENT_NUM, pw_protocol_native_client_core_demarshal }; -static const PinosRegistryMethods pinos_protocol_native_client_registry_methods = { +static const struct pw_registry_methods pw_protocol_native_client_registry_methods = { ®istry_marshal_bind }; -static const PinosDemarshalFunc pinos_protocol_native_client_registry_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_registry_demarshal[] = { ®istry_demarshal_global, ®istry_demarshal_global_remove, }; -static const PinosInterface pinos_protocol_native_client_registry_interface = { - PINOS_REGISTRY_METHOD_NUM, &pinos_protocol_native_client_registry_methods, - PINOS_REGISTRY_EVENT_NUM, pinos_protocol_native_client_registry_demarshal, +static const struct pw_interface pw_protocol_native_client_registry_interface = { + PW_REGISTRY_METHOD_NUM, &pw_protocol_native_client_registry_methods, + PW_REGISTRY_EVENT_NUM, pw_protocol_native_client_registry_demarshal, }; -static const PinosClientNodeMethods pinos_protocol_native_client_client_node_methods = { +static const struct pw_client_node_methods pw_protocol_native_client_client_node_methods = { &client_node_marshal_update, &client_node_marshal_port_update, &client_node_marshal_event, &client_node_marshal_destroy }; -static const PinosDemarshalFunc pinos_protocol_native_client_client_node_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_client_node_demarshal[] = { &client_node_demarshal_done, &client_node_demarshal_event, &client_node_demarshal_add_port, @@ -1079,72 +1079,72 @@ static const PinosDemarshalFunc pinos_protocol_native_client_client_node_demarsh &client_node_demarshal_transport }; -static const PinosInterface pinos_protocol_native_client_client_node_interface = { - PINOS_CLIENT_NODE_METHOD_NUM, &pinos_protocol_native_client_client_node_methods, - PINOS_CLIENT_NODE_EVENT_NUM, pinos_protocol_native_client_client_node_demarshal, +static const struct pw_interface pw_protocol_native_client_client_node_interface = { + PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_client_client_node_methods, + PW_CLIENT_NODE_EVENT_NUM, pw_protocol_native_client_client_node_demarshal, }; -static const PinosDemarshalFunc pinos_protocol_native_client_module_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_module_demarshal[] = { &module_demarshal_info, }; -static const PinosInterface pinos_protocol_native_client_module_interface = { +static const struct pw_interface pw_protocol_native_client_module_interface = { 0, NULL, - PINOS_MODULE_EVENT_NUM, pinos_protocol_native_client_module_demarshal, + PW_MODULE_EVENT_NUM, pw_protocol_native_client_module_demarshal, }; -static const PinosDemarshalFunc pinos_protocol_native_client_node_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_node_demarshal[] = { &node_demarshal_info, }; -static const PinosInterface pinos_protocol_native_client_node_interface = { +static const struct pw_interface pw_protocol_native_client_node_interface = { 0, NULL, - PINOS_NODE_EVENT_NUM, pinos_protocol_native_client_node_demarshal, + PW_NODE_EVENT_NUM, pw_protocol_native_client_node_demarshal, }; -static const PinosDemarshalFunc pinos_protocol_native_client_client_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_client_demarshal[] = { &client_demarshal_info, }; -static const PinosInterface pinos_protocol_native_client_client_interface = { +static const struct pw_interface pw_protocol_native_client_client_interface = { 0, NULL, - PINOS_CLIENT_EVENT_NUM, pinos_protocol_native_client_client_demarshal, + PW_CLIENT_EVENT_NUM, pw_protocol_native_client_client_demarshal, }; -static const PinosDemarshalFunc pinos_protocol_native_client_link_demarshal[] = { +static const demarshal_func_t pw_protocol_native_client_link_demarshal[] = { &link_demarshal_info, }; -static const PinosInterface pinos_protocol_native_client_link_interface = { +static const struct pw_interface pw_protocol_native_client_link_interface = { 0, NULL, - PINOS_LINK_EVENT_NUM, pinos_protocol_native_client_link_demarshal, + PW_LINK_EVENT_NUM, pw_protocol_native_client_link_demarshal, }; bool -pinos_protocol_native_client_setup (PinosProxy *proxy) +pw_protocol_native_client_setup (struct pw_proxy *proxy) { - const PinosInterface *iface; + const struct pw_interface *iface; if (proxy->type == proxy->context->type.core) { - iface = &pinos_protocol_native_client_core_interface; + iface = &pw_protocol_native_client_core_interface; } else if (proxy->type == proxy->context->type.registry) { - iface = &pinos_protocol_native_client_registry_interface; + iface = &pw_protocol_native_client_registry_interface; } else if (proxy->type == proxy->context->type.module) { - iface = &pinos_protocol_native_client_module_interface; + iface = &pw_protocol_native_client_module_interface; } else if (proxy->type == proxy->context->type.node) { - iface = &pinos_protocol_native_client_node_interface; + iface = &pw_protocol_native_client_node_interface; } else if (proxy->type == proxy->context->type.client_node) { - iface = &pinos_protocol_native_client_client_node_interface; + iface = &pw_protocol_native_client_client_node_interface; } else if (proxy->type == proxy->context->type.client) { - iface = &pinos_protocol_native_client_client_interface; + iface = &pw_protocol_native_client_client_interface; } else if (proxy->type == proxy->context->type.link) { - iface = &pinos_protocol_native_client_link_interface; + iface = &pw_protocol_native_client_link_interface; } else return false; proxy->iface = iface; diff --git a/pinos/client/protocol-native.h b/pipewire/client/protocol-native.h similarity index 84% rename from pinos/client/protocol-native.h rename to pipewire/client/protocol-native.h index 6d9f5f4d7..aef4915f4 100644 --- a/pinos/client/protocol-native.h +++ b/pipewire/client/protocol-native.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" -bool pinos_protocol_native_client_setup (PinosProxy *proxy); +bool pw_protocol_native_client_setup (struct pw_proxy *proxy); diff --git a/pinos/client/proxy.c b/pipewire/client/proxy.c similarity index 53% rename from pinos/client/proxy.c rename to pipewire/client/proxy.c index 98f7a35b7..cb511b250 100644 --- a/pinos/client/proxy.c +++ b/pipewire/client/proxy.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,23 +17,23 @@ * Boston, MA 02110-1301, USA. */ -#include -#include -#include +#include +#include +#include -typedef struct { - PinosProxy this; -} PinosProxyImpl; +struct proxy { + struct pw_proxy this; +}; -PinosProxy * -pinos_proxy_new (PinosContext *context, - uint32_t id, - uint32_t type) +struct pw_proxy * +pw_proxy_new (struct pw_context *context, + uint32_t id, + uint32_t type) { - PinosProxyImpl *impl; - PinosProxy *this; + struct proxy *impl; + struct pw_proxy *this; - impl = calloc (1, sizeof (PinosProxyImpl)); + impl = calloc (1, sizeof (struct proxy)); if (impl == NULL) return NULL; @@ -41,38 +41,38 @@ pinos_proxy_new (PinosContext *context, this->context = context; this->type = type; - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); if (id == SPA_ID_INVALID) { - id = pinos_map_insert_new (&context->objects, this); - } else if (!pinos_map_insert_at (&context->objects, id, this)) + id = pw_map_insert_new (&context->objects, this); + } else if (!pw_map_insert_at (&context->objects, id, this)) goto in_use; this->id = id; - pinos_protocol_native_client_setup (this); + pw_protocol_native_client_setup (this); spa_list_insert (&this->context->proxy_list, &this->link); - pinos_log_trace ("proxy %p: new %u", this, this->id); + pw_log_trace ("proxy %p: new %u", this, this->id); return this; in_use: - pinos_log_error ("proxy %p: id %u in use for context %p", this, id, context); + pw_log_error ("proxy %p: id %u in use for context %p", this, id, context); free (impl); return NULL; } void -pinos_proxy_destroy (PinosProxy *proxy) +pw_proxy_destroy (struct pw_proxy *proxy) { - PinosProxyImpl *impl = SPA_CONTAINER_OF (proxy, PinosProxyImpl, this); + struct proxy *impl = SPA_CONTAINER_OF (proxy, struct proxy, this); - pinos_log_trace ("proxy %p: destroy %u", proxy, proxy->id); - pinos_signal_emit (&proxy->destroy_signal, proxy); + pw_log_trace ("proxy %p: destroy %u", proxy, proxy->id); + pw_signal_emit (&proxy->destroy_signal, proxy); - pinos_map_remove (&proxy->context->objects, proxy->id); + pw_map_remove (&proxy->context->objects, proxy->id); spa_list_remove (&proxy->link); free (impl); diff --git a/pinos/client/proxy.h b/pipewire/client/proxy.h similarity index 54% rename from pinos/client/proxy.h rename to pipewire/client/proxy.h index 8dc06a255..f89f5f56e 100644 --- a/pinos/client/proxy.h +++ b/pipewire/client/proxy.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,42 +17,40 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_PROXY_H__ -#define __PINOS_PROXY_H__ +#ifndef __PIPEWIRE_PROXY_H__ +#define __PIPEWIRE_PROXY_H__ #ifdef __cplusplus extern "C" { #endif -typedef struct _PinosProxy PinosProxy; +#include +#include +#include -#include -#include -#include - -struct _PinosProxy { - PinosContext *context; - SpaList link; +struct pw_proxy { + struct pw_context *context; + SpaList link; uint32_t id; uint32_t type; - const PinosInterface *iface; - const void *implementation; + const struct pw_interface *iface; + const void *implementation; void *user_data; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosProxy *proxy)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_proxy *proxy)); }; -PinosProxy * pinos_proxy_new (PinosContext *context, - uint32_t id, - uint32_t type); -void pinos_proxy_destroy (PinosProxy *proxy); +struct pw_proxy * pw_proxy_new (struct pw_context *context, + uint32_t id, + uint32_t type); +void pw_proxy_destroy (struct pw_proxy *proxy); #ifdef __cplusplus } #endif -#endif /* __PINOS_PROXY_H__ */ +#endif /* __PIPEWIRE_PROXY_H__ */ diff --git a/pinos/client/rtkit.c b/pipewire/client/rtkit.c similarity index 88% rename from pinos/client/rtkit.c rename to pipewire/client/rtkit.c index 1468d6aba..2b1e82113 100644 --- a/pinos/client/rtkit.c +++ b/pipewire/client/rtkit.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -47,23 +47,23 @@ #include -#include +#include #include "rtkit.h" -struct _PinosRTKitBus { +struct pw_rtkit_bus { DBusConnection *bus; }; -PinosRTKitBus * -pinos_rtkit_bus_get_system (void) +struct pw_rtkit_bus * +pw_rtkit_bus_get_system (void) { - PinosRTKitBus *bus; + struct pw_rtkit_bus *bus; DBusError error; dbus_error_init(&error); - bus = calloc (1, sizeof (PinosRTKitBus)); + bus = calloc (1, sizeof (struct pw_rtkit_bus)); if (bus == NULL) return NULL; @@ -76,13 +76,13 @@ pinos_rtkit_bus_get_system (void) return bus; error: - pinos_log_error ("Failed to connect to system bus: %s", error.message); + pw_log_error ("Failed to connect to system bus: %s", error.message); dbus_error_free (&error); return NULL; } void -pinos_rtkit_bus_free (PinosRTKitBus *system_bus) +pw_rtkit_bus_free (struct pw_rtkit_bus *system_bus) { dbus_connection_close (system_bus->bus); dbus_connection_unref (system_bus->bus); @@ -122,7 +122,7 @@ static int translate_error(const char *name) { return -EIO; } -static long long rtkit_get_int_property(PinosRTKitBus *connection, const char* propname, long long* propval) { +static long long rtkit_get_int_property(struct pw_rtkit_bus *connection, const char* propname, long long* propval) { DBusMessage *m = NULL, *r = NULL; DBusMessageIter iter, subiter; dbus_int64_t i64; @@ -202,7 +202,7 @@ finish: return ret; } -int pinos_rtkit_get_max_realtime_priority(PinosRTKitBus *connection) { +int pw_rtkit_get_max_realtime_priority(struct pw_rtkit_bus *connection) { long long retval; int err; @@ -210,7 +210,7 @@ int pinos_rtkit_get_max_realtime_priority(PinosRTKitBus *connection) { return err < 0 ? err : retval; } -int pinos_rtkit_get_min_nice_level(PinosRTKitBus *connection, int* min_nice_level) { +int pw_rtkit_get_min_nice_level(struct pw_rtkit_bus *connection, int* min_nice_level) { long long retval; int err; @@ -220,7 +220,7 @@ int pinos_rtkit_get_min_nice_level(PinosRTKitBus *connection, int* min_nice_leve return err; } -long long pinos_rtkit_get_rttime_usec_max(PinosRTKitBus *connection) { +long long pw_rtkit_get_rttime_usec_max(struct pw_rtkit_bus *connection) { long long retval; int err; @@ -229,7 +229,7 @@ long long pinos_rtkit_get_rttime_usec_max(PinosRTKitBus *connection) { } int -pinos_rtkit_make_realtime (PinosRTKitBus *connection, +pw_rtkit_make_realtime (struct pw_rtkit_bus *connection, pid_t thread, int priority) { @@ -292,7 +292,7 @@ finish: } int -pinos_rtkit_make_high_priority (PinosRTKitBus *connection, +pw_rtkit_make_high_priority (struct pw_rtkit_bus *connection, pid_t thread, int nice_level) { @@ -358,23 +358,23 @@ finish: #else -int pinos_rtkit_make_realtime(PinosRTKitBus *connection, pid_t thread, int priority) { +int pw_rtkit_make_realtime(struct pw_rtkit_bus *connection, pid_t thread, int priority) { return -ENOTSUP; } -int pinos_rtkit_make_high_priority(PinosRTKitBus *connection, pid_t thread, int nice_level) { +int pw_rtkit_make_high_priority(struct pw_rtkit_bus *connection, pid_t thread, int nice_level) { return -ENOTSUP; } -int pinos_rtkit_get_max_realtime_priority(PinosRTKitBus *connection) { +int pw_rtkit_get_max_realtime_priority(struct pw_rtkit_bus *connection) { return -ENOTSUP; } -int pinos_rtkit_get_min_nice_level(PinosRTKitBus *connection, int* min_nice_level) { +int pw_rtkit_get_min_nice_level(struct pw_rtkit_bus *connection, int* min_nice_level) { return -ENOTSUP; } -long long pinos_rtkit_get_rttime_usec_max(PinosRTKitBus *connection) { +long long pw_rtkit_get_rttime_usec_max(struct pw_rtkit_bus *connection) { return -ENOTSUP; } diff --git a/pinos/client/rtkit.h b/pipewire/client/rtkit.h similarity index 68% rename from pinos/client/rtkit.h rename to pipewire/client/rtkit.h index 9de91d11c..f4810096e 100644 --- a/pinos/client/rtkit.h +++ b/pipewire/client/rtkit.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_RTKIT_H__ -#define __PINOS_RTKIT_H__ +#ifndef __PIPEWIRE_RTKIT_H__ +#define __PIPEWIRE_RTKIT_H__ #include #include @@ -30,10 +30,8 @@ extern "C" { #define RTKIT_SERVICE_NAME "org.freedesktop.RealtimeKit1" #define RTKIT_OBJECT_PATH "/org/freedesktop/RealtimeKit1" -typedef struct _PinosRTKitBus PinosRTKitBus; - -PinosRTKitBus * pinos_rtkit_bus_get_system (void); -void pinos_rtkit_bus_free (PinosRTKitBus *system_bus); +struct pw_rtkit_bus * pw_rtkit_bus_get_system (void); +void pw_rtkit_bus_free (struct pw_rtkit_bus *system_bus); /* This is mostly equivalent to sched_setparam(thread, SCHED_RR, { @@ -41,9 +39,9 @@ void pinos_rtkit_bus_free (PinosRTKitBus *system_bus); * id as returned by gettid(), not a pthread_t! If 'thread' is 0 the * current thread is used. The returned value is a negative errno * style error code, or 0 on success. */ -int pinos_rtkit_make_realtime (PinosRTKitBus *system_bus, - pid_t thread, - int priority); +int pw_rtkit_make_realtime (struct pw_rtkit_bus *system_bus, + pid_t thread, + int priority); /* This is mostly equivalent to setpriority(PRIO_PROCESS, thread, @@ -51,28 +49,28 @@ int pinos_rtkit_make_realtime (PinosRTKitBus *system * gettid(), not a pthread_t! If 'thread' is 0 the current thread is * used. The returned value is a negative errno style error code, or * 0 on success. */ -int pinos_rtkit_make_high_priority (PinosRTKitBus *system_bus, - pid_t thread, - int nice_level); +int pw_rtkit_make_high_priority (struct pw_rtkit_bus *system_bus, + pid_t thread, + int nice_level); /* Return the maximum value of realtime priority available. Realtime requests * above this value will fail. A negative value is an errno style error code. */ -int pinos_rtkit_get_max_realtime_priority (PinosRTKitBus *system_bus); +int pw_rtkit_get_max_realtime_priority (struct pw_rtkit_bus *system_bus); /* Retreive the minimum value of nice level available. High prio requests * below this value will fail. The returned value is a negative errno * style error code, or 0 on success.*/ -int pinos_rtkit_get_min_nice_level (PinosRTKitBus *system_bus, - int *min_nice_level); +int pw_rtkit_get_min_nice_level (struct pw_rtkit_bus *system_bus, + int *min_nice_level); /* Return the maximum value of RLIMIT_RTTIME to set before attempting a * realtime request. A negative value is an errno style error code. */ -long long pinos_rtkit_get_rttime_usec_max (PinosRTKitBus *system_bus); +long long pw_rtkit_get_rttime_usec_max (struct pw_rtkit_bus *system_bus); #ifdef __cplusplus } #endif -#endif /* __PINOS_RTKIT_H__ */ +#endif /* __PIPEWIRE_RTKIT_H__ */ diff --git a/pinos/client/sig.h b/pipewire/client/sig.h similarity index 76% rename from pinos/client/sig.h rename to pipewire/client/sig.h index 290748af5..7f08a0544 100644 --- a/pinos/client/sig.h +++ b/pipewire/client/sig.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_SIGNAL_H__ -#define __PINOS_SIGNAL_H__ +#ifndef __PIPEWIRE_SIGNAL_H__ +#define __PIPEWIRE_SIGNAL_H__ #include @@ -26,24 +26,21 @@ extern "C" { #endif -typedef struct _PinosSignal PinosSignal; -typedef struct _PinosListener PinosListener; - -struct _PinosListener { +struct pw_listener { SpaList link; void (*notify) (void *); }; -#define PINOS_SIGNAL(name,func) \ +#define PW_SIGNAL(name,func) \ union { \ SpaList listeners; \ void (*notify) func; \ } name; -#define pinos_signal_init(signal) \ +#define pw_signal_init(signal) \ spa_list_init (&(signal)->listeners); -#define pinos_signal_add(signal,listener,func) \ +#define pw_signal_add(signal,listener,func) \ do { \ __typeof__((signal)->notify) n = (func); \ (listener)->notify = (void (*) (void *)) n; \ @@ -51,14 +48,14 @@ struct _PinosListener { } while (false); static inline void -pinos_signal_remove (PinosListener *listener) +pw_signal_remove (struct pw_listener *listener) { spa_list_remove (&listener->link); } -#define pinos_signal_emit(signal,...) \ +#define pw_signal_emit(signal,...) \ do { \ - PinosListener *l, *next; \ + struct pw_listener *l, *next; \ spa_list_for_each_safe (l, next, &(signal)->listeners, link) \ ((__typeof__((signal)->notify))l->notify) (l,__VA_ARGS__); \ } while (false); @@ -67,4 +64,4 @@ pinos_signal_remove (PinosListener *listener) } #endif -#endif /* __PINOS_SIGNAL_H__ */ +#endif /* __PIPEWIRE_SIGNAL_H__ */ diff --git a/pinos/client/stream.c b/pipewire/client/stream.c similarity index 57% rename from pinos/client/stream.c rename to pipewire/client/stream.c index b80485ff6..64106e1e5 100644 --- a/pinos/client/stream.c +++ b/pipewire/client/stream.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -26,41 +26,40 @@ #include "spa/lib/debug.h" -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" -#include "pinos/client/protocol-native.h" -#include "pinos/client/array.h" -#include "pinos/client/connection.h" -#include "pinos/client/context.h" -#include "pinos/client/stream.h" -#include "pinos/client/transport.h" -#include "pinos/client/utils.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" +#include "pipewire/client/protocol-native.h" +#include "pipewire/client/array.h" +#include "pipewire/client/connection.h" +#include "pipewire/client/context.h" +#include "pipewire/client/stream.h" +#include "pipewire/client/transport.h" +#include "pipewire/client/utils.h" #define MAX_BUFFER_SIZE 4096 #define MAX_FDS 32 #define MAX_INPUTS 64 #define MAX_OUTPUTS 64 -typedef struct { +struct mem_id { uint32_t id; int fd; uint32_t flags; void *ptr; uint32_t offset; uint32_t size; -} MemId; +}; -typedef struct { +struct buffer_id { SpaList link; uint32_t id; bool used; void *buf_ptr; SpaBuffer *buf; -} BufferId; +}; -typedef struct -{ - PinosStream this; +struct stream { + struct pw_stream this; uint32_t n_possible_formats; SpaFormat **possible_formats; @@ -74,22 +73,22 @@ typedef struct uint32_t port_id; uint32_t pending_seq; - PinosStreamMode mode; + enum pw_stream_mode mode; int rtreadfd; int rtwritefd; SpaSource *rtsocket_source; - PinosProxy *node_proxy; + struct pw_proxy *node_proxy; bool disconnecting; - PinosListener node_proxy_destroy; + struct pw_listener node_proxy_destroy; - PinosTransport *trans; + struct pw_transport *trans; SpaSource *timeout_source; - PinosArray mem_ids; - PinosArray buffer_ids; + struct pw_array mem_ids; + struct pw_array buffer_ids; bool in_order; SpaList free; @@ -98,10 +97,10 @@ typedef struct int64_t last_ticks; int32_t last_rate; int64_t last_monotonic; -} PinosStreamImpl; +}; static void -clear_memid (MemId *mid) +clear_memid (struct mem_id *mid) { if (mid->ptr != NULL) munmap (mid->ptr, mid->size + mid->offset); @@ -110,26 +109,26 @@ clear_memid (MemId *mid) } static void -clear_mems (PinosStream *stream) +clear_mems (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - MemId *mid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct mem_id *mid; - pinos_array_for_each (mid, &impl->mem_ids) + pw_array_for_each (mid, &impl->mem_ids) clear_memid (mid); impl->mem_ids.size = 0; } static void -clear_buffers (PinosStream *stream) +clear_buffers (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - BufferId *bid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct buffer_id *bid; - pinos_log_debug ("stream %p: clear buffers", stream); + pw_log_debug ("stream %p: clear buffers", stream); - pinos_array_for_each (bid, &impl->buffer_ids) { - pinos_signal_emit (&stream->remove_buffer, stream, bid->id); + pw_array_for_each (bid, &impl->buffer_ids) { + pw_signal_emit (&stream->remove_buffer, stream, bid->id); free (bid->buf); bid->buf = NULL; bid->used = false; @@ -140,8 +139,8 @@ clear_buffers (PinosStream *stream) } static bool -stream_set_state (PinosStream *stream, - PinosStreamState state, +stream_set_state (struct pw_stream *stream, + enum pw_stream_state state, char *error) { bool res = stream->state != state; @@ -150,76 +149,76 @@ stream_set_state (PinosStream *stream, free (stream->error); stream->error = error; - pinos_log_debug ("stream %p: update state from %s -> %s (%s)", stream, - pinos_stream_state_as_string (stream->state), - pinos_stream_state_as_string (state), + pw_log_debug ("stream %p: update state from %s -> %s (%s)", stream, + pw_stream_state_as_string (stream->state), + pw_stream_state_as_string (state), stream->error); stream->state = state; - pinos_signal_emit (&stream->state_changed, stream); + pw_signal_emit (&stream->state_changed, stream); } return res; } /** - * pinos_stream_state_as_string: - * @state: a #PinosStreamState + * pw_stream_state_as_string: + * @state: a #enum pw_stream_state * * Return the string representation of @state. * * Returns: the string representation of @state. */ const char * -pinos_stream_state_as_string (PinosStreamState state) +pw_stream_state_as_string (enum pw_stream_state state) { switch (state) { - case PINOS_STREAM_STATE_ERROR: + case PW_STREAM_STATE_ERROR: return "error"; - case PINOS_STREAM_STATE_UNCONNECTED: + case PW_STREAM_STATE_UNCONNECTED: return "unconnected"; - case PINOS_STREAM_STATE_CONNECTING: + case PW_STREAM_STATE_CONNECTING: return "connecting"; - case PINOS_STREAM_STATE_CONFIGURE: + case PW_STREAM_STATE_CONFIGURE: return "configure"; - case PINOS_STREAM_STATE_READY: + case PW_STREAM_STATE_READY: return "ready"; - case PINOS_STREAM_STATE_PAUSED: + case PW_STREAM_STATE_PAUSED: return "paused"; - case PINOS_STREAM_STATE_STREAMING: + case PW_STREAM_STATE_STREAMING: return "streaming"; } return "invalid-state"; } /** - * pinos_stream_new: - * @context: a #PinosContext + * pw_stream_new: + * @context: a #struct pw_context * @name: a stream name * @properties: (transfer full): stream properties * - * Make a new unconnected #PinosStream + * Make a new unconnected #struct pw_stream * - * Returns: a new unconnected #PinosStream + * Returns: a new unconnected #struct pw_stream */ -PinosStream * -pinos_stream_new (PinosContext *context, +struct pw_stream * +pw_stream_new (struct pw_context *context, const char *name, - PinosProperties *props) + struct pw_properties *props) { - PinosStreamImpl *impl; - PinosStream *this; + struct stream *impl; + struct pw_stream *this; - impl = calloc (1, sizeof (PinosStreamImpl)); + impl = calloc (1, sizeof (struct stream)); if (impl == NULL) return NULL; this = &impl->this; - pinos_log_debug ("stream %p: new", impl); + pw_log_debug ("stream %p: new", impl); if (props == NULL) { - props = pinos_properties_new ("media.name", name, NULL); - } else if (!pinos_properties_get (props, "media.name")) { - pinos_properties_set (props, "media.name", name); + props = pw_properties_new ("media.name", name, NULL); + } else if (!pw_properties_get (props, "media.name")) { + pw_properties_set (props, "media.name", name); } if (props == NULL) goto no_mem; @@ -229,20 +228,20 @@ pinos_stream_new (PinosContext *context, this->context = context; this->name = strdup (name); - pinos_signal_init (&this->destroy_signal); - pinos_signal_init (&this->state_changed); - pinos_signal_init (&this->format_changed); - pinos_signal_init (&this->add_buffer); - pinos_signal_init (&this->remove_buffer); - pinos_signal_init (&this->new_buffer); - pinos_signal_init (&this->need_buffer); + pw_signal_init (&this->destroy_signal); + pw_signal_init (&this->state_changed); + pw_signal_init (&this->format_changed); + pw_signal_init (&this->add_buffer); + pw_signal_init (&this->remove_buffer); + pw_signal_init (&this->new_buffer); + pw_signal_init (&this->need_buffer); - this->state = PINOS_STREAM_STATE_UNCONNECTED; + this->state = PW_STREAM_STATE_UNCONNECTED; - pinos_array_init (&impl->mem_ids, 64); - pinos_array_ensure_size (&impl->mem_ids, sizeof (MemId) * 64); - pinos_array_init (&impl->buffer_ids, 32); - pinos_array_ensure_size (&impl->buffer_ids, sizeof (BufferId) * 64); + pw_array_init (&impl->mem_ids, 64); + pw_array_ensure_size (&impl->mem_ids, sizeof (struct mem_id) * 64); + pw_array_init (&impl->buffer_ids, 32); + pw_array_ensure_size (&impl->buffer_ids, sizeof (struct buffer_id) * 64); impl->pending_seq = SPA_ID_INVALID; spa_list_init (&impl->free); @@ -256,26 +255,26 @@ no_mem: } static void -unhandle_socket (PinosStream *stream) +unhandle_socket (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); if (impl->rtsocket_source) { - pinos_loop_destroy_source (stream->context->loop, impl->rtsocket_source); + pw_loop_destroy_source (stream->context->loop, impl->rtsocket_source); impl->rtsocket_source = NULL; } if (impl->timeout_source) { - pinos_loop_destroy_source (stream->context->loop, impl->timeout_source); + pw_loop_destroy_source (stream->context->loop, impl->timeout_source); impl->timeout_source = NULL; } } static void -set_possible_formats (PinosStream *stream, +set_possible_formats (struct pw_stream *stream, int n_possible_formats, SpaFormat **possible_formats) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); int i; if (impl->possible_formats) { @@ -293,11 +292,11 @@ set_possible_formats (PinosStream *stream, } static void -set_params (PinosStream *stream, +set_params (struct pw_stream *stream, int n_params, SpaParam **params) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); int i; if (impl->params) { @@ -315,20 +314,20 @@ set_params (PinosStream *stream, } void -pinos_stream_destroy (PinosStream *stream) +pw_stream_destroy (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - pinos_log_debug ("stream %p: destroy", stream); + pw_log_debug ("stream %p: destroy", stream); - pinos_signal_emit (&stream->destroy_signal, stream); + pw_signal_emit (&stream->destroy_signal, stream); unhandle_socket (stream); spa_list_remove (&stream->link); if (impl->node_proxy) - pinos_signal_remove (&impl->node_proxy_destroy); + pw_signal_remove (&impl->node_proxy_destroy); set_possible_formats (stream, 0, NULL); set_params (stream, 0, NULL); @@ -340,16 +339,16 @@ pinos_stream_destroy (PinosStream *stream) free (stream->error); clear_buffers (stream); - pinos_array_clear (&impl->buffer_ids); + pw_array_clear (&impl->buffer_ids); clear_mems (stream); - pinos_array_clear (&impl->mem_ids); + pw_array_clear (&impl->mem_ids); if (stream->properties) - pinos_properties_free (stream->properties); + pw_properties_free (stream->properties); if (impl->trans) - pinos_transport_destroy (impl->trans); + pw_transport_destroy (impl->trans); if (stream->name) free (stream->name); @@ -358,17 +357,17 @@ pinos_stream_destroy (PinosStream *stream) } static void -add_node_update (PinosStream *stream, uint32_t change_mask) +add_node_update (struct pw_stream *stream, uint32_t change_mask) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); uint32_t max_input_ports = 0, max_output_ports = 0; - if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS) + if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_INPUTS) max_input_ports = impl->direction == SPA_DIRECTION_INPUT ? 1 : 0; - if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) + if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) max_output_ports = impl->direction == SPA_DIRECTION_OUTPUT ? 1 : 0; - pinos_client_node_do_update (impl->node_proxy, + pw_client_node_do_update (impl->node_proxy, change_mask, max_input_ports, max_output_ports, @@ -376,11 +375,11 @@ add_node_update (PinosStream *stream, uint32_t change_mask) } static void -add_port_update (PinosStream *stream, uint32_t change_mask) +add_port_update (struct pw_stream *stream, uint32_t change_mask) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - pinos_client_node_do_port_update (impl->node_proxy, + pw_client_node_do_port_update (impl->node_proxy, impl->direction, impl->port_id, change_mask, @@ -393,67 +392,67 @@ add_port_update (PinosStream *stream, uint32_t change_mask) } static inline void -send_need_input (PinosStream *stream) +send_need_input (struct pw_stream *stream) { #if 0 - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); SpaEventNodeNeedInput ni; uint64_t cmd = 1; - pinos_log_debug ("stream %p: need input", stream); + pw_log_debug ("stream %p: need input", stream); ni.event.type = SPA_EVENT_NODE_NEED_INPUT; ni.event.size = sizeof (ni); - pinos_transport_add_event (impl->trans, &ni.event); + pw_transport_add_event (impl->trans, &ni.event); write (impl->rtwritefd, &cmd, 8); #endif } static inline void -send_have_output (PinosStream *stream) +send_have_output (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); uint64_t cmd = 1; - pinos_transport_add_event (impl->trans, + pw_transport_add_event (impl->trans, &SPA_EVENT_INIT (stream->context->type.event_transport.HaveOutput)); write (impl->rtwritefd, &cmd, 8); } static void -add_request_clock_update (PinosStream *stream) +add_request_clock_update (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - pinos_client_node_do_event (impl->node_proxy, (SpaEvent*) + pw_client_node_do_event (impl->node_proxy, (SpaEvent*) &SPA_EVENT_NODE_REQUEST_CLOCK_UPDATE_INIT (stream->context->type.event_node.RequestClockUpdate, SPA_EVENT_NODE_REQUEST_CLOCK_UPDATE_TIME, 0, 0)); } static void -add_async_complete (PinosStream *stream, +add_async_complete (struct pw_stream *stream, uint32_t seq, SpaResult res) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - pinos_client_node_do_event (impl->node_proxy, (SpaEvent*) + pw_client_node_do_event (impl->node_proxy, (SpaEvent*) &SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (stream->context->type.event_node.AsyncComplete, seq, res)); } static void -do_node_init (PinosStream *stream) +do_node_init (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - add_node_update (stream, PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS | - PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS); + add_node_update (stream, PW_MESSAGE_NODE_UPDATE_MAX_INPUTS | + PW_MESSAGE_NODE_UPDATE_MAX_OUTPUTS); impl->port_info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; - add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | - PINOS_MESSAGE_PORT_UPDATE_INFO); + add_port_update (stream, PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | + PW_MESSAGE_PORT_UPDATE_INFO); add_async_complete (stream, 0, SPA_RESULT_OK); } @@ -462,34 +461,34 @@ on_timeout (SpaLoopUtils *utils, SpaSource *source, void *data) { - PinosStream *stream = data; + struct pw_stream *stream = data; add_request_clock_update (stream); } -static MemId * -find_mem (PinosStream *stream, uint32_t id) +static struct mem_id * +find_mem (struct pw_stream *stream, uint32_t id) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - MemId *mid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct mem_id *mid; - pinos_array_for_each (mid, &impl->mem_ids) { + pw_array_for_each (mid, &impl->mem_ids) { if (mid->id == id) return mid; } return NULL; } -static BufferId * -find_buffer (PinosStream *stream, uint32_t id) +static struct buffer_id * +find_buffer (struct pw_stream *stream, uint32_t id) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - if (impl->in_order && pinos_array_check_index (&impl->buffer_ids, id, BufferId)) { - return pinos_array_get_unchecked (&impl->buffer_ids, id, BufferId); + if (impl->in_order && pw_array_check_index (&impl->buffer_ids, id, struct buffer_id)) { + return pw_array_get_unchecked (&impl->buffer_ids, id, struct buffer_id); } else { - BufferId *bid; + struct buffer_id *bid; - pinos_array_for_each (bid, &impl->buffer_ids) { + pw_array_for_each (bid, &impl->buffer_ids) { if (bid->id == id) return bid; } @@ -498,25 +497,25 @@ find_buffer (PinosStream *stream, uint32_t id) } static inline void -reuse_buffer (PinosStream *stream, uint32_t id) +reuse_buffer (struct pw_stream *stream, uint32_t id) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - BufferId *bid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct buffer_id *bid; if ((bid = find_buffer (stream, id)) && bid->used) { - pinos_log_trace ("stream %p: reuse buffer %u", stream, id); + pw_log_trace ("stream %p: reuse buffer %u", stream, id); bid->used = false; spa_list_insert (impl->free.prev, &bid->link); - pinos_signal_emit (&stream->new_buffer, stream, id); + pw_signal_emit (&stream->new_buffer, stream, id); } } static void -handle_rtnode_event (PinosStream *stream, +handle_rtnode_event (struct pw_stream *stream, SpaEvent *event) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - PinosContext *context = impl->this.context; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct pw_context *context = impl->this.context; if (SPA_EVENT_TYPE (event) == context->type.event_transport.HaveOutput) { int i; @@ -524,11 +523,11 @@ handle_rtnode_event (PinosStream *stream, for (i = 0; i < impl->trans->area->n_inputs; i++) { SpaPortIO *input = &impl->trans->inputs[i]; - pinos_log_trace ("stream %p: have output %d %d", stream, input->status, input->buffer_id); + pw_log_trace ("stream %p: have output %d %d", stream, input->status, input->buffer_id); if (input->buffer_id == SPA_ID_INVALID) continue; - pinos_signal_emit (&stream->new_buffer, stream, input->buffer_id); + pw_signal_emit (&stream->new_buffer, stream, input->buffer_id); input->buffer_id = SPA_ID_INVALID; } send_need_input (stream); @@ -545,13 +544,13 @@ handle_rtnode_event (PinosStream *stream, reuse_buffer (stream, output->buffer_id); output->buffer_id = SPA_ID_INVALID; } - pinos_log_trace ("stream %p: need input", stream); + pw_log_trace ("stream %p: need input", stream); impl->in_need_buffer = true; - pinos_signal_emit (&stream->need_buffer, stream); + pw_signal_emit (&stream->need_buffer, stream); impl->in_need_buffer = false; } else if (SPA_EVENT_TYPE (event) == context->type.event_transport.ReuseBuffer) { - PinosEventTransportReuseBuffer *p = (PinosEventTransportReuseBuffer *) event; + struct pw_event_transport_reuse_buffer *p = (struct pw_event_transport_reuse_buffer *) event; if (p->body.port_id.value != impl->port_id) return; @@ -561,7 +560,7 @@ handle_rtnode_event (PinosStream *stream, reuse_buffer (stream, p->body.buffer_id.value); } else { - pinos_log_warn ("unexpected node event %d", SPA_EVENT_TYPE (event)); + pw_log_warn ("unexpected node event %d", SPA_EVENT_TYPE (event)); } } @@ -572,11 +571,11 @@ on_rtsocket_condition (SpaLoopUtils *utils, SpaIO mask, void *data) { - PinosStream *stream = data; - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct pw_stream *stream = data; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { - pinos_log_warn ("got error"); + pw_log_warn ("got error"); unhandle_socket (stream); return; } @@ -587,35 +586,35 @@ on_rtsocket_condition (SpaLoopUtils *utils, read (impl->rtreadfd, &cmd, 8); - while (pinos_transport_next_event (impl->trans, &event) == SPA_RESULT_OK) { + while (pw_transport_next_event (impl->trans, &event) == SPA_RESULT_OK) { SpaEvent *ev = alloca (SPA_POD_SIZE (&event)); - pinos_transport_parse_event (impl->trans, ev); + pw_transport_parse_event (impl->trans, ev); handle_rtnode_event (stream, ev); } } } static void -handle_socket (PinosStream *stream, int rtreadfd, int rtwritefd) +handle_socket (struct pw_stream *stream, int rtreadfd, int rtwritefd) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); struct timespec interval; impl->rtreadfd = rtreadfd; impl->rtwritefd = rtwritefd; - impl->rtsocket_source = pinos_loop_add_io (stream->context->loop, + impl->rtsocket_source = pw_loop_add_io (stream->context->loop, impl->rtreadfd, SPA_IO_ERR | SPA_IO_HUP, true, on_rtsocket_condition, stream); - impl->timeout_source = pinos_loop_add_timer (stream->context->loop, + impl->timeout_source = pw_loop_add_timer (stream->context->loop, on_timeout, stream); interval.tv_sec = 0; interval.tv_nsec = 100000000; - pinos_loop_update_timer (stream->context->loop, + pw_loop_update_timer (stream->context->loop, impl->timeout_source, NULL, &interval, @@ -624,40 +623,40 @@ handle_socket (PinosStream *stream, int rtreadfd, int rtwritefd) } static void -handle_node_event (PinosStream *stream, +handle_node_event (struct pw_stream *stream, const SpaEvent *event) { - pinos_log_warn ("unhandled node event %d", SPA_EVENT_TYPE (event)); + pw_log_warn ("unhandled node event %d", SPA_EVENT_TYPE (event)); } static bool -handle_node_command (PinosStream *stream, +handle_node_command (struct pw_stream *stream, uint32_t seq, const SpaCommand *command) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - PinosContext *context = stream->context; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct pw_context *context = stream->context; if (SPA_COMMAND_TYPE (command) == context->type.command_node.Pause) { add_async_complete (stream, seq, SPA_RESULT_OK); - if (stream->state == PINOS_STREAM_STATE_STREAMING) { - pinos_log_debug ("stream %p: pause %d", stream, seq); + if (stream->state == PW_STREAM_STATE_STREAMING) { + pw_log_debug ("stream %p: pause %d", stream, seq); - pinos_loop_update_io (stream->context->loop, + pw_loop_update_io (stream->context->loop, impl->rtsocket_source, SPA_IO_ERR | SPA_IO_HUP); - stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL); + stream_set_state (stream, PW_STREAM_STATE_PAUSED, NULL); } } else if (SPA_COMMAND_TYPE (command) == context->type.command_node.Start) { add_async_complete (stream, seq, SPA_RESULT_OK); - if (stream->state == PINOS_STREAM_STATE_PAUSED) { - pinos_log_debug ("stream %p: start %d %d", stream, seq, impl->direction); + if (stream->state == PW_STREAM_STATE_PAUSED) { + pw_log_debug ("stream %p: start %d %d", stream, seq, impl->direction); - pinos_loop_update_io (stream->context->loop, + pw_loop_update_io (stream->context->loop, impl->rtsocket_source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP); @@ -665,26 +664,26 @@ handle_node_command (PinosStream *stream, send_need_input (stream); else { impl->in_need_buffer = true; - pinos_signal_emit (&stream->need_buffer, stream); + pw_signal_emit (&stream->need_buffer, stream); impl->in_need_buffer = false; } - stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL); + stream_set_state (stream, PW_STREAM_STATE_STREAMING, NULL); } } else if (SPA_COMMAND_TYPE (command) == context->type.command_node.ClockUpdate) { SpaCommandNodeClockUpdate *cu = (SpaCommandNodeClockUpdate *) command; if (cu->body.flags.value & SPA_COMMAND_NODE_CLOCK_UPDATE_FLAG_LIVE) { - pinos_properties_set (stream->properties, - "pinos.latency.is-live", "1"); - pinos_properties_setf (stream->properties, - "pinos.latency.min", "%"PRId64, cu->body.latency.value); + pw_properties_set (stream->properties, + "pipewire.latency.is-live", "1"); + pw_properties_setf (stream->properties, + "pipewire.latency.min", "%"PRId64, cu->body.latency.value); } impl->last_ticks = cu->body.ticks.value; impl->last_rate = cu->body.rate.value; impl->last_monotonic = cu->body.monotonic_time.value; } else { - pinos_log_warn ("unhandled node command %d", SPA_COMMAND_TYPE (command)); + pw_log_warn ("unhandled node command %d", SPA_COMMAND_TYPE (command)); add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED); } return true; @@ -695,22 +694,22 @@ client_node_done (void *object, int readfd, int writefd) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; - pinos_log_info ("stream %p: create client node done with fds %d %d", stream, readfd, writefd); + pw_log_info ("stream %p: create client node done with fds %d %d", stream, readfd, writefd); handle_socket (stream, readfd, writefd); do_node_init (stream); - stream_set_state (stream, PINOS_STREAM_STATE_CONFIGURE, NULL); + stream_set_state (stream, PW_STREAM_STATE_CONFIGURE, NULL); } static void client_node_event (void *object, const SpaEvent *event) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; handle_node_event (stream, event); } @@ -720,7 +719,7 @@ client_node_add_port (void *object, SpaDirection direction, uint32_t port_id) { - pinos_log_warn ("add port not supported"); + pw_log_warn ("add port not supported"); } static void @@ -729,7 +728,7 @@ client_node_remove_port (void *object, SpaDirection direction, uint32_t port_id) { - pinos_log_warn ("remove port not supported"); + pw_log_warn ("remove port not supported"); } static void @@ -740,21 +739,21 @@ client_node_set_format (void *object, uint32_t flags, const SpaFormat *format) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); if (impl->format) free (impl->format); impl->format = format ? spa_format_copy (format) : NULL; impl->pending_seq = seq; - pinos_signal_emit (&stream->format_changed, stream, impl->format); + pw_signal_emit (&stream->format_changed, stream, impl->format); if (format) - stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL); + stream_set_state (stream, PW_STREAM_STATE_READY, NULL); else - stream_set_state (stream, PINOS_STREAM_STATE_CONFIGURE, NULL); + stream_set_state (stream, PW_STREAM_STATE_CONFIGURE, NULL); } static void @@ -764,7 +763,7 @@ client_node_set_property (void *object, uint32_t size, const void *value) { - pinos_log_warn ("set property not implemented"); + pw_log_warn ("set property not implemented"); } static void @@ -778,19 +777,19 @@ client_node_add_mem (void *object, uint32_t offset, uint32_t size) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - MemId *m; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct mem_id *m; m = find_mem (stream, mem_id); if (m) { - pinos_log_debug ("update mem %u, fd %d, flags %d, off %d, size %d", + pw_log_debug ("update mem %u, fd %d, flags %d, off %d, size %d", mem_id, memfd, flags, offset, size); clear_memid (m); } else { - m = pinos_array_add (&impl->mem_ids, sizeof (MemId)); - pinos_log_debug ("add mem %u, fd %d, flags %d, off %d, size %d", + m = pw_array_add (&impl->mem_ids, sizeof (struct mem_id)); + pw_log_debug ("add mem %u, fd %d, flags %d, off %d, size %d", mem_id, memfd, flags, offset, size); } m->id = mem_id; @@ -807,12 +806,12 @@ client_node_use_buffers (void *object, SpaDirection direction, uint32_t port_id, uint32_t n_buffers, - PinosClientNodeBuffer *buffers) + struct pw_client_node_buffer *buffers) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - BufferId *bid; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct buffer_id *bid; uint32_t i, j, len; SpaBuffer *b; @@ -822,9 +821,9 @@ client_node_use_buffers (void *object, for (i = 0; i < n_buffers; i++) { off_t offset; - MemId *mid = find_mem (stream, buffers[i].mem_id); + struct mem_id *mid = find_mem (stream, buffers[i].mem_id); if (mid == NULL) { - pinos_log_warn ("unknown memory id %u", buffers[i].mem_id); + pw_log_warn ("unknown memory id %u", buffers[i].mem_id); continue; } @@ -832,13 +831,13 @@ client_node_use_buffers (void *object, mid->ptr = mmap (NULL, mid->size + mid->offset, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0); if (mid->ptr == MAP_FAILED) { mid->ptr = NULL; - pinos_log_warn ("Failed to mmap memory %d %p: %s", mid->size, mid, strerror (errno)); + pw_log_warn ("Failed to mmap memory %d %p: %s", mid->size, mid, strerror (errno)); continue; } mid->ptr = SPA_MEMBER (mid->ptr, mid->offset, void); } - len = pinos_array_get_len (&impl->buffer_ids, BufferId); - bid = pinos_array_add (&impl->buffer_ids, sizeof (BufferId)); + len = pw_array_get_len (&impl->buffer_ids, struct buffer_id); + bid = pw_array_add (&impl->buffer_ids, sizeof (struct buffer_id)); if (impl->direction == SPA_DIRECTION_OUTPUT) { bid->used = false; spa_list_insert (impl->free.prev, &bid->link); @@ -868,10 +867,10 @@ client_node_use_buffers (void *object, bid->id = b->id; if (bid->id != len) { - pinos_log_warn ("unexpected id %u found, expected %u", bid->id, len); + pw_log_warn ("unexpected id %u found, expected %u", bid->id, len); impl->in_order = false; } - pinos_log_debug ("add buffer %d %d %u", mid->id, bid->id, buffers[i].offset); + pw_log_debug ("add buffer %d %d %u", mid->id, bid->id, buffers[i].offset); offset = 0; for (j = 0; j < b->n_metas; j++) { @@ -888,31 +887,31 @@ client_node_use_buffers (void *object, d->chunk = SPA_MEMBER (bid->buf_ptr, offset + sizeof (SpaChunk) * j, SpaChunk); if (d->type == stream->context->type.data.Id) { - MemId *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->data)); + struct mem_id *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->data)); d->type = stream->context->type.data.MemFd; d->data = NULL; d->fd = bmid->fd; - pinos_log_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd); + pw_log_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd); } else if (d->type == stream->context->type.data.MemPtr) { d->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (d->data), void); d->fd = -1; - pinos_log_debug (" data %d %u -> mem %p", j, bid->id, d->data); + pw_log_debug (" data %d %u -> mem %p", j, bid->id, d->data); } else { - pinos_log_warn ("unknown buffer data type %d", d->type); + pw_log_warn ("unknown buffer data type %d", d->type); } } - pinos_signal_emit (&stream->add_buffer, stream, bid->id); + pw_signal_emit (&stream->add_buffer, stream, bid->id); } add_async_complete (stream, seq, SPA_RESULT_OK); if (n_buffers) - stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL); + stream_set_state (stream, PW_STREAM_STATE_PAUSED, NULL); else { clear_mems (stream); - stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL); + stream_set_state (stream, PW_STREAM_STATE_READY, NULL); } } @@ -921,8 +920,8 @@ client_node_node_command (void *object, uint32_t seq, const SpaCommand *command) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; handle_node_command (stream, seq, command); } @@ -931,7 +930,7 @@ client_node_port_command (void *object, uint32_t port_id, const SpaCommand *command) { - pinos_log_warn ("port command not supported"); + pw_log_warn ("port command not supported"); } static void @@ -940,10 +939,10 @@ client_node_transport (void *object, uint32_t offset, uint32_t size) { - PinosProxy *proxy = object; - PinosStream *stream = proxy->user_data; - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - PinosTransportInfo info; + struct pw_proxy *proxy = object; + struct pw_stream *stream = proxy->user_data; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct pw_transport_info info; info.memfd = memfd; if (info.memfd == -1) @@ -952,13 +951,13 @@ client_node_transport (void *object, info.size = size; if (impl->trans) - pinos_transport_destroy (impl->trans); - impl->trans = pinos_transport_new_from_info (&info); + pw_transport_destroy (impl->trans); + impl->trans = pw_transport_new_from_info (&info); - pinos_log_debug ("transport update %p", impl->trans); + pw_log_debug ("transport update %p", impl->trans); } -static const PinosClientNodeEvents client_node_events = { +static const struct pw_client_node_events client_node_events = { &client_node_done, &client_node_event, &client_node_add_port, @@ -973,78 +972,78 @@ static const PinosClientNodeEvents client_node_events = { }; static void -on_node_proxy_destroy (PinosListener *listener, - PinosProxy *proxy) +on_node_proxy_destroy (struct pw_listener *listener, + struct pw_proxy *proxy) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (listener, PinosStreamImpl, node_proxy_destroy); - PinosStream *this = &impl->this; + struct stream *impl = SPA_CONTAINER_OF (listener, struct stream, node_proxy_destroy); + struct pw_stream *this = &impl->this; impl->disconnecting = false; impl->node_proxy = NULL; - pinos_signal_remove (&impl->node_proxy_destroy); - stream_set_state (this, PINOS_STREAM_STATE_UNCONNECTED, NULL); + pw_signal_remove (&impl->node_proxy_destroy); + stream_set_state (this, PW_STREAM_STATE_UNCONNECTED, NULL); } /** - * pinos_stream_connect: - * @stream: a #PinosStream + * pw_stream_connect: + * @stream: a #struct pw_stream * @direction: the stream direction - * @mode: a #PinosStreamMode + * @mode: a #enum pw_stream_mode * @port_path: the port path to connect to or %NULL to get the default port - * @flags: a #PinosStreamFlags + * @flags: a #struct pw_stream * @n_possible_formats: number of items in @possible_formats * @possible_formats: an array with possible accepted formats * * Connect @stream for input or output on @port_path. * - * When @mode is #PINOS_STREAM_MODE_BUFFER, you should connect to the new-buffer - * signal and use pinos_stream_capture_buffer() to get the latest metadata and + * When @mode is #PW_STREAM_MODE_BUFFER, you should connect to the new-buffer + * signal and use pw_stream_capture_buffer() to get the latest metadata and * data. * * Returns: %true on success. */ bool -pinos_stream_connect (PinosStream *stream, - PinosDirection direction, - PinosStreamMode mode, - const char *port_path, - PinosStreamFlags flags, - uint32_t n_possible_formats, - SpaFormat **possible_formats) +pw_stream_connect (struct pw_stream *stream, + enum pw_direction direction, + enum pw_stream_mode mode, + const char *port_path, + enum pw_stream_flags flags, + uint32_t n_possible_formats, + SpaFormat **possible_formats) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); - impl->direction = direction == PINOS_DIRECTION_INPUT ? SPA_DIRECTION_INPUT : SPA_DIRECTION_OUTPUT; + impl->direction = direction == PW_DIRECTION_INPUT ? SPA_DIRECTION_INPUT : SPA_DIRECTION_OUTPUT; impl->port_id = 0; impl->mode = mode; set_possible_formats (stream, n_possible_formats, possible_formats); - stream_set_state (stream, PINOS_STREAM_STATE_CONNECTING, NULL); + stream_set_state (stream, PW_STREAM_STATE_CONNECTING, NULL); if (stream->properties == NULL) - stream->properties = pinos_properties_new (NULL, NULL); + stream->properties = pw_properties_new (NULL, NULL); if (port_path) - pinos_properties_set (stream->properties, - "pinos.target.node", port_path); - if (flags & PINOS_STREAM_FLAG_AUTOCONNECT) - pinos_properties_set (stream->properties, - "pinos.autoconnect", "1"); + pw_properties_set (stream->properties, + "pipewire.target.node", port_path); + if (flags & PW_STREAM_FLAG_AUTOCONNECT) + pw_properties_set (stream->properties, + "pipewire.autoconnect", "1"); - impl->node_proxy = pinos_proxy_new (stream->context, + impl->node_proxy = pw_proxy_new (stream->context, SPA_ID_INVALID, stream->context->type.client_node); if (impl->node_proxy == NULL) return false; - pinos_signal_add (&impl->node_proxy->destroy_signal, + pw_signal_add (&impl->node_proxy->destroy_signal, &impl->node_proxy_destroy, on_node_proxy_destroy); impl->node_proxy->user_data = stream; impl->node_proxy->implementation = &client_node_events; - pinos_core_do_create_client_node (stream->context->core_proxy, + pw_core_do_create_client_node (stream->context->core_proxy, "client-node", &stream->properties->dict, impl->node_proxy->id); @@ -1052,8 +1051,8 @@ pinos_stream_connect (PinosStream *stream, } /** - * pinos_stream_finish_format: - * @stream: a #PinosStream + * pw_stream_finish_format: + * @stream: a #struct pw_stream * @res: a #SpaResult * @params: an array of pointers to #SpaParam * @n_params: number of elements in @params @@ -1068,18 +1067,18 @@ pinos_stream_connect (PinosStream *stream, * Returns: %true on success */ bool -pinos_stream_finish_format (PinosStream *stream, +pw_stream_finish_format (struct pw_stream *stream, SpaResult res, SpaParam **params, uint32_t n_params) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); set_params (stream, n_params, params); if (SPA_RESULT_IS_OK (res)) { - add_port_update (stream, (n_params ? PINOS_MESSAGE_PORT_UPDATE_PARAMS : 0) | - PINOS_MESSAGE_PORT_UPDATE_FORMAT); + add_port_update (stream, (n_params ? PW_MESSAGE_PORT_UPDATE_PARAMS : 0) | + PW_MESSAGE_PORT_UPDATE_FORMAT); if (!impl->format) { clear_buffers (stream); @@ -1094,32 +1093,32 @@ pinos_stream_finish_format (PinosStream *stream, } /** - * pinos_stream_disconnect: - * @stream: a #PinosStream + * pw_stream_disconnect: + * @stream: a #struct pw_stream * * Disconnect @stream. * * Returns: %true on success */ bool -pinos_stream_disconnect (PinosStream *stream) +pw_stream_disconnect (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); impl->disconnecting = true; unhandle_socket (stream); - pinos_client_node_do_destroy (impl->node_proxy); + pw_client_node_do_destroy (impl->node_proxy); return true; } bool -pinos_stream_get_time (PinosStream *stream, - PinosTime *time) +pw_stream_get_time (struct pw_stream *stream, + struct pw_time *time) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); int64_t elapsed; struct timespec ts; @@ -1134,8 +1133,8 @@ pinos_stream_get_time (PinosStream *stream, } /** - * pinos_stream_get_empty_buffer: - * @stream: a #PinosStream + * pw_stream_get_empty_buffer: + * @stream: a #struct pw_stream * * Get the id of an empty buffer that can be filled * @@ -1143,22 +1142,22 @@ pinos_stream_get_time (PinosStream *stream, * available. */ uint32_t -pinos_stream_get_empty_buffer (PinosStream *stream) +pw_stream_get_empty_buffer (struct pw_stream *stream) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - BufferId *bid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct buffer_id *bid; if (spa_list_is_empty (&impl->free)) return SPA_ID_INVALID; - bid = spa_list_first (&impl->free, BufferId, link); + bid = spa_list_first (&impl->free, struct buffer_id, link); return bid->id; } /** - * pinos_stream_recycle_buffer: - * @stream: a #PinosStream + * pw_stream_recycle_buffer: + * @stream: a #struct pw_stream * @id: a buffer id * * Recycle the buffer with @id. @@ -1166,13 +1165,13 @@ pinos_stream_get_empty_buffer (PinosStream *stream) * Returns: %true on success. */ bool -pinos_stream_recycle_buffer (PinosStream *stream, - uint32_t id) +pw_stream_recycle_buffer (struct pw_stream *stream, + uint32_t id) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - PinosEventTransportReuseBuffer rb = PINOS_EVENT_TRANSPORT_REUSE_BUFFER_INIT + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct pw_event_transport_reuse_buffer rb = PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT (stream->context->type.event_transport.ReuseBuffer, impl->port_id, id); - BufferId *bid; + struct buffer_id *bid; uint64_t cmd = 1; if ((bid = find_buffer (stream, id)) == NULL || !bid->used) @@ -1181,15 +1180,15 @@ pinos_stream_recycle_buffer (PinosStream *stream, bid->used = false; spa_list_insert (impl->free.prev, &bid->link); - pinos_transport_add_event (impl->trans, (SpaEvent *)&rb); + pw_transport_add_event (impl->trans, (SpaEvent *)&rb); write (impl->rtwritefd, &cmd, 8); return true; } /** - * pinos_stream_peek_buffer: - * @stream: a #PinosStream + * pw_stream_peek_buffer: + * @stream: a #struct pw_stream * @id: the buffer id * * Get the buffer with @id from @stream. This function should be called from @@ -1198,10 +1197,10 @@ pinos_stream_recycle_buffer (PinosStream *stream, * Returns: a #SpaBuffer or %NULL when there is no buffer. */ SpaBuffer * -pinos_stream_peek_buffer (PinosStream *stream, - uint32_t id) +pw_stream_peek_buffer (struct pw_stream *stream, + uint32_t id) { - BufferId *bid; + struct buffer_id *bid; if ((bid = find_buffer (stream, id))) return bid->buf; @@ -1210,8 +1209,8 @@ pinos_stream_peek_buffer (PinosStream *stream, } /** - * pinos_stream_send_buffer: - * @stream: a #PinosStream + * pw_stream_send_buffer: + * @stream: a #struct pw_stream * @id: a buffer id * @offset: the offset in the buffer * @size: the size in the buffer @@ -1224,14 +1223,14 @@ pinos_stream_peek_buffer (PinosStream *stream, * Returns: %true when @id was handled */ bool -pinos_stream_send_buffer (PinosStream *stream, - uint32_t id) +pw_stream_send_buffer (struct pw_stream *stream, + uint32_t id) { - PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); - BufferId *bid; + struct stream *impl = SPA_CONTAINER_OF (stream, struct stream, this); + struct buffer_id *bid; if (impl->trans->outputs[0].buffer_id != SPA_ID_INVALID) { - pinos_log_debug ("can't send %u, pending buffer %u", id, impl->trans->outputs[0].buffer_id); + pw_log_debug ("can't send %u, pending buffer %u", id, impl->trans->outputs[0].buffer_id); return false; } @@ -1240,11 +1239,11 @@ pinos_stream_send_buffer (PinosStream *stream, spa_list_remove (&bid->link); impl->trans->outputs[0].buffer_id = id; impl->trans->outputs[0].status = SPA_RESULT_HAVE_BUFFER; - pinos_log_trace ("stream %p: send buffer %d", stream, id); + pw_log_trace ("stream %p: send buffer %d", stream, id); if (!impl->in_need_buffer) send_have_output (stream); } else { - pinos_log_debug ("stream %p: output %u was used", stream, id); + pw_log_debug ("stream %p: output %u was used", stream, id); } return true; diff --git a/pipewire/client/stream.h b/pipewire/client/stream.h new file mode 100644 index 000000000..fbbd2920c --- /dev/null +++ b/pipewire/client/stream.h @@ -0,0 +1,131 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_STREAM_H__ +#define __PIPEWIRE_STREAM_H__ + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum pw_stream_state { + PW_STREAM_STATE_ERROR = -1, + PW_STREAM_STATE_UNCONNECTED = 0, + PW_STREAM_STATE_CONNECTING = 1, + PW_STREAM_STATE_CONFIGURE = 2, + PW_STREAM_STATE_READY = 3, + PW_STREAM_STATE_PAUSED = 4, + PW_STREAM_STATE_STREAMING = 5 +}; + +const char * pw_stream_state_as_string (enum pw_stream_state state); + +enum pw_stream_flags { + PW_STREAM_FLAG_NONE = 0, + PW_STREAM_FLAG_AUTOCONNECT = (1 << 0), + PW_STREAM_FLAG_CLOCK_UPDATE = (1 << 1), +}; + +enum pw_stream_mode { + PW_STREAM_MODE_BUFFER = 0, + PW_STREAM_MODE_RINGBUFFER = 1, +}; + +struct pw_time{ + int64_t now; + int64_t ticks; + int32_t rate; +}; + +/** + * pw_stream: + * + * PipeWire stream object class. + */ +struct pw_stream { + struct pw_context *context; + SpaList link; + + char *name; + struct pw_properties *properties; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_stream *stream)); + + enum pw_stream_state state; + char *error; + PW_SIGNAL (state_changed, (struct pw_listener *listener, + struct pw_stream *stream)); + + PW_SIGNAL (format_changed, (struct pw_listener *listener, + struct pw_stream *stream, + SpaFormat *format)); + + PW_SIGNAL (add_buffer, (struct pw_listener *listener, + struct pw_stream *stream, + uint32_t id)); + PW_SIGNAL (remove_buffer, (struct pw_listener *listener, + struct pw_stream *stream, + uint32_t id)); + PW_SIGNAL (new_buffer, (struct pw_listener *listener, + struct pw_stream *stream, + uint32_t id)); + PW_SIGNAL (need_buffer, (struct pw_listener *listener, + struct pw_stream *stream)); +}; + +struct pw_stream * pw_stream_new (struct pw_context *context, + const char *name, + struct pw_properties *props); +void pw_stream_destroy (struct pw_stream *stream); + +bool pw_stream_connect (struct pw_stream *stream, + enum pw_direction direction, + enum pw_stream_mode mode, + const char *port_path, + enum pw_stream_flags flags, + uint32_t n_possible_formats, + SpaFormat **possible_formats); +bool pw_stream_disconnect (struct pw_stream *stream); + +bool pw_stream_finish_format (struct pw_stream *stream, + SpaResult res, + SpaParam **params, + uint32_t n_params); + +bool pw_stream_get_time (struct pw_stream *stream, + struct pw_time *time); + +uint32_t pw_stream_get_empty_buffer (struct pw_stream *stream); +bool pw_stream_recycle_buffer (struct pw_stream *stream, + uint32_t id); +SpaBuffer * pw_stream_peek_buffer (struct pw_stream *stream, + uint32_t id); +bool pw_stream_send_buffer (struct pw_stream *stream, + uint32_t id); +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_STREAM_H__ */ diff --git a/pipewire/client/subscribe.h b/pipewire/client/subscribe.h new file mode 100644 index 000000000..1af60e8bb --- /dev/null +++ b/pipewire/client/subscribe.h @@ -0,0 +1,57 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_SUBSCRIBE_H__ +#define __PIPEWIRE_SUBSCRIBE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPEWIRE_TYPE__Core "PipeWire:Object:Core" +#define PIPEWIRE_TYPE_CORE_BASE PIPEWIRE_TYPE__Core ":" + +#define PIPEWIRE_TYPE__Registry "PipeWire:Object:Registry" +#define PIPEWIRE_TYPE_REGISYRY_BASE PIPEWIRE_TYPE__Registry ":" + +#define PIPEWIRE_TYPE__Node "PipeWire:Object:Node" +#define PIPEWIRE_TYPE_NODE_BASE PIPEWIRE_TYPE__Node ":" + +#define PIPEWIRE_TYPE__Client "PipeWire:Object:Client" +#define PIPEWIRE_TYPE_CLIENT_BASE PIPEWIRE_TYPE__Client ":" + +#define PIPEWIRE_TYPE__Link "PipeWire:Object:Link" +#define PIPEWIRE_TYPE_LINK_BASE PIPEWIRE_TYPE__Link ":" + +#define PIPEWIRE_TYPE__Module "PipeWire:Object:Module" +#define PIPEWIRE_TYPE_MODULE_BASE PIPEWIRE_TYPE__Module ":" + +enum pw_subscription_event { + PW_SUBSCRIPTION_EVENT_NEW = 0, + PW_SUBSCRIPTION_EVENT_CHANGE = 1, + PW_SUBSCRIPTION_EVENT_REMOVE = 2, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_SUBSCRIBE_H__ */ diff --git a/pinos/client/thread-mainloop.c b/pipewire/client/thread-mainloop.c similarity index 50% rename from pinos/client/thread-mainloop.c rename to pipewire/client/thread-mainloop.c index 653a0f5b8..9de3f766f 100644 --- a/pinos/client/thread-mainloop.c +++ b/pipewire/client/thread-mainloop.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,11 +19,11 @@ #include -#include "pinos.h" +#include "pipewire.h" #include "thread-mainloop.h" -typedef struct { - PinosThreadMainLoop this; +struct thread_main_loop { + struct pw_thread_main_loop this; char *name; @@ -38,13 +38,13 @@ typedef struct { int n_waiting; int n_waiting_for_accept; -} PinosThreadMainLoopImpl; +}; static void pre_hook (SpaLoopControl *ctrl, void *data) { - PinosThreadMainLoopImpl *impl = data; + struct thread_main_loop *impl = data; pthread_mutex_unlock (&impl->lock); } @@ -52,7 +52,7 @@ static void post_hook (SpaLoopControl *ctrl, void *data) { - PinosThreadMainLoopImpl *impl = data; + struct thread_main_loop *impl = data; pthread_mutex_lock (&impl->lock); } @@ -61,44 +61,44 @@ do_stop (SpaLoopUtils *utils, SpaSource *source, void *data) { - PinosThreadMainLoopImpl *impl = data; + struct thread_main_loop *impl = data; impl->running = false; } /** - * pinos_thread_main_loop_new: + * pw_thread_main_loop_new: * @context: a #GMainContext * @name: a thread name * - * Make a new #PinosThreadMainLoop that will run a mainloop on @context in + * Make a new #struct pw_thread_main_loop that will run a mainloop on @context in * a thread with @name. * - * Returns: a #PinosThreadMainLoop + * Returns: a #struct pw_thread_main_loop */ -PinosThreadMainLoop * -pinos_thread_main_loop_new (PinosLoop *loop, - const char *name) +struct pw_thread_main_loop * +pw_thread_main_loop_new (struct pw_loop *loop, + const char *name) { - PinosThreadMainLoopImpl *impl; - PinosThreadMainLoop *this; + struct thread_main_loop *impl; + struct pw_thread_main_loop *this; pthread_mutexattr_t attr; - impl = calloc (1, sizeof (PinosThreadMainLoopImpl)); + impl = calloc (1, sizeof (struct thread_main_loop)); if (impl == NULL) return NULL; this = &impl->this; - pinos_log_debug ("thread-mainloop %p: new", impl); + pw_log_debug ("thread-mainloop %p: new", impl); this->loop = loop; this->name = name ? strdup (name) : NULL; - pinos_loop_set_hooks (loop, + pw_loop_set_hooks (loop, pre_hook, post_hook, impl); - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); pthread_mutexattr_init (&attr); pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); @@ -106,7 +106,7 @@ pinos_thread_main_loop_new (PinosLoop *loop, pthread_cond_init (&impl->cond, NULL); pthread_cond_init (&impl->accept_cond, NULL); - impl->event = pinos_loop_add_event (this->loop, + impl->event = pw_loop_add_event (this->loop, do_stop, impl); @@ -114,13 +114,13 @@ pinos_thread_main_loop_new (PinosLoop *loop, } void -pinos_thread_main_loop_destroy (PinosThreadMainLoop *loop) +pw_thread_main_loop_destroy (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); - pinos_signal_emit (&loop->destroy_signal, loop); + pw_signal_emit (&loop->destroy_signal, loop); - pinos_thread_main_loop_stop (loop); + pw_thread_main_loop_stop (loop); if (loop->name) free (loop->name); @@ -134,44 +134,44 @@ pinos_thread_main_loop_destroy (PinosThreadMainLoop *loop) static void * do_loop (void *user_data) { - PinosThreadMainLoopImpl *impl = user_data; - PinosThreadMainLoop *this = &impl->this; + struct thread_main_loop *impl = user_data; + struct pw_thread_main_loop *this = &impl->this; SpaResult res; pthread_mutex_lock (&impl->lock); - pinos_log_debug ("thread-mainloop %p: enter thread", this); - pinos_loop_enter (this->loop); + pw_log_debug ("thread-mainloop %p: enter thread", this); + pw_loop_enter (this->loop); while (impl->running) { - if ((res = pinos_loop_iterate (this->loop, -1)) < 0) - pinos_log_warn ("thread-mainloop %p: iterate error %d", this, res); + if ((res = pw_loop_iterate (this->loop, -1)) < 0) + pw_log_warn ("thread-mainloop %p: iterate error %d", this, res); } - pinos_log_debug ("thread-mainloop %p: leave thread", this); - pinos_loop_leave (this->loop); + pw_log_debug ("thread-mainloop %p: leave thread", this); + pw_loop_leave (this->loop); pthread_mutex_unlock (&impl->lock); return NULL; } /** - * pinos_thread_main_loop_start: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_start: + * @loop: a #struct pw_thread_main_loop * * Start the thread to handle @loop. * * Returns: %SPA_RESULT_OK on success. */ SpaResult -pinos_thread_main_loop_start (PinosThreadMainLoop *loop) +pw_thread_main_loop_start (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); if (!impl->running) { int err; impl->running = true; if ((err = pthread_create (&impl->thread, NULL, do_loop, impl)) != 0) { - pinos_log_warn ("thread-mainloop %p: can't create thread: %s", impl, strerror (err)); + pw_log_warn ("thread-mainloop %p: can't create thread: %s", impl, strerror (err)); impl->running = false; return SPA_RESULT_ERROR; } @@ -180,66 +180,66 @@ pinos_thread_main_loop_start (PinosThreadMainLoop *loop) } /** - * pinos_thread_main_loop_stop: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_stop: + * @loop: a #struct pw_thread_main_loop * * Quit the main loop and stop its thread. */ void -pinos_thread_main_loop_stop (PinosThreadMainLoop *loop) +pw_thread_main_loop_stop (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); - pinos_log_debug ("thread-mainloop: %p stopping", impl); + pw_log_debug ("thread-mainloop: %p stopping", impl); if (impl->running) { - pinos_log_debug ("thread-mainloop: %p signal", impl); - pinos_loop_signal_event (loop->loop, impl->event); - pinos_log_debug ("thread-mainloop: %p join", impl); + pw_log_debug ("thread-mainloop: %p signal", impl); + pw_loop_signal_event (loop->loop, impl->event); + pw_log_debug ("thread-mainloop: %p join", impl); pthread_join (impl->thread, NULL); - pinos_log_debug ("thread-mainloop: %p joined", impl); + pw_log_debug ("thread-mainloop: %p joined", impl); impl->running = false; } - pinos_log_debug ("thread-mainloop: %p stopped", impl); + pw_log_debug ("thread-mainloop: %p stopped", impl); } /** - * pinos_thread_main_loop_lock: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_lock: + * @loop: a #struct pw_thread_main_loop * * Lock the mutex associated with @loop. */ void -pinos_thread_main_loop_lock (PinosThreadMainLoop *loop) +pw_thread_main_loop_lock (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); pthread_mutex_lock (&impl->lock); } /** - * pinos_thread_main_loop_unlock: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_unlock: + * @loop: a #struct pw_thread_main_loop * * Unlock the mutex associated with @loop. */ void -pinos_thread_main_loop_unlock (PinosThreadMainLoop *loop) +pw_thread_main_loop_unlock (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); pthread_mutex_unlock (&impl->lock); } /** - * pinos_thread_main_loop_signal: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_signal: + * @loop: a #struct pw_thread_main_loop * * Signal the main thread of @loop. If @wait_for_accept is %TRUE, - * this function waits until pinos_thread_main_loop_accept() is called. + * this function waits until pw_thread_main_loop_accept() is called. */ void -pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, - bool wait_for_accept) +pw_thread_main_loop_signal (struct pw_thread_main_loop *loop, + bool wait_for_accept) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); if (impl->n_waiting > 0) pthread_cond_broadcast (&impl->cond); @@ -253,15 +253,15 @@ pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, } /** - * pinos_thread_main_loop_wait: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_wait: + * @loop: a #struct pw_thread_main_loop * - * Wait for the loop thread to call pinos_thread_main_loop_signal(). + * Wait for the loop thread to call pw_thread_main_loop_signal(). */ void -pinos_thread_main_loop_wait (PinosThreadMainLoop *loop) +pw_thread_main_loop_wait (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); impl->n_waiting++; @@ -270,31 +270,31 @@ pinos_thread_main_loop_wait (PinosThreadMainLoop *loop) } /** - * pinos_thread_main_loop_accept: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_accept: + * @loop: a #struct pw_thread_main_loop * - * Signal the loop thread waiting for accept with pinos_thread_main_loop_signal(). + * Signal the loop thread waiting for accept with pw_thread_main_loop_signal(). */ void -pinos_thread_main_loop_accept (PinosThreadMainLoop *loop) +pw_thread_main_loop_accept (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); impl->n_waiting_for_accept--; pthread_cond_signal (&impl->accept_cond); } /** - * pinos_thread_main_loop_in_thread: - * @loop: a #PinosThreadMainLoop + * pw_thread_main_loop_in_thread: + * @loop: a #struct pw_thread_main_loop * * Check if we are inside the thread of @loop. * * Returns: %TRUE when called inside the thread of @loop. */ bool -pinos_thread_main_loop_in_thread (PinosThreadMainLoop *loop) +pw_thread_main_loop_in_thread (struct pw_thread_main_loop *loop) { - PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); + struct thread_main_loop *impl = SPA_CONTAINER_OF (loop, struct thread_main_loop, this); return pthread_self() == impl->thread; } diff --git a/pipewire/client/thread-mainloop.h b/pipewire/client/thread-mainloop.h new file mode 100644 index 000000000..ccdd5df32 --- /dev/null +++ b/pipewire/client/thread-mainloop.h @@ -0,0 +1,63 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_THREAD_MAIN_LOOP_H__ +#define __PIPEWIRE_THREAD_MAIN_LOOP_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * pw_thread_main_loop: + * + * PipeWire main loop object class. + */ +struct pw_thread_main_loop { + struct pw_loop *loop; + char *name; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_thread_main_loop *loop)); +}; + +struct pw_thread_main_loop * pw_thread_main_loop_new (struct pw_loop *loop, + const char *name); +void pw_thread_main_loop_destroy (struct pw_thread_main_loop *loop); + +SpaResult pw_thread_main_loop_start (struct pw_thread_main_loop *loop); +void pw_thread_main_loop_stop (struct pw_thread_main_loop *loop); + +void pw_thread_main_loop_lock (struct pw_thread_main_loop *loop); +void pw_thread_main_loop_unlock (struct pw_thread_main_loop *loop); + +void pw_thread_main_loop_wait (struct pw_thread_main_loop *loop); +void pw_thread_main_loop_signal (struct pw_thread_main_loop *loop, + bool wait_for_accept); +void pw_thread_main_loop_accept (struct pw_thread_main_loop *loop); + +bool pw_thread_main_loop_in_thread (struct pw_thread_main_loop *loop); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_THREAD_MAIN_LOOP_H__ */ diff --git a/pinos/client/transport.c b/pipewire/client/transport.c similarity index 67% rename from pinos/client/transport.c rename to pipewire/client/transport.c index e143e0db9..0287b7829 100644 --- a/pinos/client/transport.c +++ b/pipewire/client/transport.c @@ -1,4 +1,4 @@ -/* Simple Plugin API +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #define INPUT_BUFFER_SIZE (1<<12) #define OUTPUT_BUFFER_SIZE (1<<12) @@ -32,21 +32,21 @@ #define CMD_PROCESS_EVENTS (1<<1) #define CMD_PROCESS_SYNC (1<<2) -typedef struct { - PinosTransport trans; +struct transport { + struct pw_transport trans; - PinosMemblock mem; - size_t offset; + struct pw_memblock mem; + size_t offset; - SpaEvent current; - uint32_t current_index; -} PinosTransportImpl; + SpaEvent current; + uint32_t current_index; +}; static size_t -transport_area_get_size (PinosTransportArea *area) +transport_area_get_size (struct pw_transport_area *area) { size_t size; - size = sizeof (PinosTransportArea); + size = sizeof (struct pw_transport_area); size += area->max_inputs * sizeof (SpaPortIO); size += area->max_outputs * sizeof (SpaPortIO); size += sizeof (SpaRingbuffer); @@ -57,12 +57,12 @@ transport_area_get_size (PinosTransportArea *area) } static void -transport_setup_area (void *p, PinosTransport *trans) +transport_setup_area (void *p, struct pw_transport *trans) { - PinosTransportArea *a; + struct pw_transport_area *a; trans->area = a = p; - p = SPA_MEMBER (p, sizeof (PinosTransportArea), SpaPortIO); + p = SPA_MEMBER (p, sizeof (struct pw_transport_area), SpaPortIO); trans->inputs = p; p = SPA_MEMBER (p, a->max_inputs * sizeof (SpaPortIO), void); @@ -84,10 +84,10 @@ transport_setup_area (void *p, PinosTransport *trans) } static void -transport_reset_area (PinosTransport *trans) +transport_reset_area (struct pw_transport *trans) { int i; - PinosTransportArea *a = trans->area; + struct pw_transport_area *a = trans->area; for (i = 0; i < a->max_inputs; i++) { trans->inputs[i].status = SPA_RESULT_OK; @@ -101,62 +101,62 @@ transport_reset_area (PinosTransport *trans) spa_ringbuffer_init (trans->output_buffer, OUTPUT_BUFFER_SIZE); } -PinosTransport * -pinos_transport_new (uint32_t max_inputs, - uint32_t max_outputs) +struct pw_transport * +pw_transport_new (uint32_t max_inputs, + uint32_t max_outputs) { - PinosTransportImpl *impl; - PinosTransport *trans; - PinosTransportArea area; + struct transport *impl; + struct pw_transport *trans; + struct pw_transport_area area; area.max_inputs = max_inputs; area.n_inputs = 0; area.max_outputs = max_outputs; area.n_outputs = 0; - impl = calloc (1, sizeof (PinosTransportImpl)); + impl = calloc (1, sizeof (struct transport)); if (impl == NULL) return NULL; impl->offset = 0; trans = &impl->trans; - pinos_signal_init (&trans->destroy_signal); + pw_signal_init (&trans->destroy_signal); - pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD | - PINOS_MEMBLOCK_FLAG_MAP_READWRITE | - PINOS_MEMBLOCK_FLAG_SEAL, + pw_memblock_alloc (PW_MEMBLOCK_FLAG_WITH_FD | + PW_MEMBLOCK_FLAG_MAP_READWRITE | + PW_MEMBLOCK_FLAG_SEAL, transport_area_get_size (&area), &impl->mem); - memcpy (impl->mem.ptr, &area, sizeof (PinosTransportArea)); + memcpy (impl->mem.ptr, &area, sizeof (struct pw_transport_area)); transport_setup_area (impl->mem.ptr, trans); transport_reset_area (trans); return trans; } -PinosTransport * -pinos_transport_new_from_info (PinosTransportInfo *info) +struct pw_transport * +pw_transport_new_from_info (struct pw_transport_info *info) { - PinosTransportImpl *impl; - PinosTransport *trans; + struct transport *impl; + struct pw_transport *trans; void *tmp; - impl = calloc (1, sizeof (PinosTransportImpl)); + impl = calloc (1, sizeof (struct transport)); if (impl == NULL) return NULL; trans = &impl->trans; - pinos_signal_init (&trans->destroy_signal); + pw_signal_init (&trans->destroy_signal); - impl->mem.flags = PINOS_MEMBLOCK_FLAG_MAP_READWRITE | - PINOS_MEMBLOCK_FLAG_WITH_FD; + impl->mem.flags = PW_MEMBLOCK_FLAG_MAP_READWRITE | + PW_MEMBLOCK_FLAG_WITH_FD; impl->mem.fd = info->memfd; impl->mem.offset = info->offset; impl->mem.size = info->size; - if (pinos_memblock_map (&impl->mem) != SPA_RESULT_OK) { - pinos_log_warn ("transport %p: failed to map fd %d: %s", impl, info->memfd, strerror (errno)); + if (pw_memblock_map (&impl->mem) != SPA_RESULT_OK) { + pw_log_warn ("transport %p: failed to map fd %d: %s", impl, info->memfd, strerror (errno)); goto mmap_failed; } @@ -181,23 +181,23 @@ mmap_failed: void -pinos_transport_destroy (PinosTransport *trans) +pw_transport_destroy (struct pw_transport *trans) { - PinosTransportImpl *impl = (PinosTransportImpl *) trans; + struct transport *impl = (struct transport *) trans; - pinos_log_debug ("transport %p: destroy", trans); + pw_log_debug ("transport %p: destroy", trans); - pinos_signal_emit (&trans->destroy_signal, trans); + pw_signal_emit (&trans->destroy_signal, trans); - pinos_memblock_free (&impl->mem); + pw_memblock_free (&impl->mem); free (impl); } SpaResult -pinos_transport_get_info (PinosTransport *trans, - PinosTransportInfo *info) +pw_transport_get_info (struct pw_transport *trans, + struct pw_transport_info *info) { - PinosTransportImpl *impl = (PinosTransportImpl *) trans; + struct transport *impl = (struct transport *) trans; info->memfd = impl->mem.fd; info->offset = impl->offset; @@ -207,10 +207,10 @@ pinos_transport_get_info (PinosTransport *trans, } SpaResult -pinos_transport_add_event (PinosTransport *trans, - SpaEvent *event) +pw_transport_add_event (struct pw_transport *trans, + SpaEvent *event) { - PinosTransportImpl *impl = (PinosTransportImpl *) trans; + struct transport *impl = (struct transport *) trans; int32_t filled, avail; uint32_t size, index; @@ -234,10 +234,10 @@ pinos_transport_add_event (PinosTransport *trans, } SpaResult -pinos_transport_next_event (PinosTransport *trans, - SpaEvent *event) +pw_transport_next_event (struct pw_transport *trans, + SpaEvent *event) { - PinosTransportImpl *impl = (PinosTransportImpl *) trans; + struct transport *impl = (struct transport *) trans; int32_t avail; if (impl == NULL || event == NULL) @@ -259,10 +259,10 @@ pinos_transport_next_event (PinosTransport *trans, } SpaResult -pinos_transport_parse_event (PinosTransport *trans, - void *event) +pw_transport_parse_event (struct pw_transport *trans, + void *event) { - PinosTransportImpl *impl = (PinosTransportImpl *) trans; + struct transport *impl = (struct transport *) trans; uint32_t size; if (impl == NULL || event == NULL) diff --git a/pipewire/client/transport.h b/pipewire/client/transport.h new file mode 100644 index 000000000..ef1d966c1 --- /dev/null +++ b/pipewire/client/transport.h @@ -0,0 +1,128 @@ +/* PipeWire + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_TRANSPORT_H__ +#define __PIPEWIRE_TRANSPORT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +#include +#include + +struct pw_transport_info { + int memfd; + uint32_t offset; + uint32_t size; +}; + +/** + * struct pw_transport_area: + * + * Shared structure between client and server + */ +struct pw_transport_area { + uint32_t max_inputs; + uint32_t n_inputs; + uint32_t max_outputs; + uint32_t n_outputs; +}; + +struct pw_transport { + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_transport *trans)); + + struct pw_transport_area *area; + SpaPortIO *inputs; + SpaPortIO *outputs; + void *input_data; + SpaRingbuffer *input_buffer; + void *output_data; + SpaRingbuffer *output_buffer; +}; + +struct pw_transport * pw_transport_new (uint32_t max_inputs, + uint32_t max_outputs); +struct pw_transport * pw_transport_new_from_info (struct pw_transport_info *info); + +void pw_transport_destroy (struct pw_transport *trans); + +SpaResult pw_transport_get_info (struct pw_transport *trans, + struct pw_transport_info *info); + +SpaResult pw_transport_add_event (struct pw_transport *trans, + SpaEvent *event); + +SpaResult pw_transport_next_event (struct pw_transport *trans, + SpaEvent *event); +SpaResult pw_transport_parse_event (struct pw_transport *trans, + void *event); + +#define PIPEWIRE_TYPE_EVENT__Transport SPA_TYPE_EVENT_BASE "Transport" +#define PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE PIPEWIRE_TYPE_EVENT__Transport ":" + +#define PIPEWIRE_TYPE_EVENT_TRANSPORT__HaveOutput PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "HaveOutput" +#define PIPEWIRE_TYPE_EVENT_TRANSPORT__NeedInput PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "NeedInput" +#define PIPEWIRE_TYPE_EVENT_TRANSPORT__ReuseBuffer PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "ReuseBuffer" + +struct pw_type_event_transport { + uint32_t HaveOutput; + uint32_t NeedInput; + uint32_t ReuseBuffer; +}; + +static inline void +pw_type_event_transport_map (SpaTypeMap *map, struct pw_type_event_transport *type) +{ + if (type->HaveOutput == 0) { + type->HaveOutput = spa_type_map_get_id (map, PIPEWIRE_TYPE_EVENT_TRANSPORT__HaveOutput); + type->NeedInput = spa_type_map_get_id (map, PIPEWIRE_TYPE_EVENT_TRANSPORT__NeedInput); + type->ReuseBuffer = spa_type_map_get_id (map, PIPEWIRE_TYPE_EVENT_TRANSPORT__ReuseBuffer); + } +} + +struct pw_event_transport_reuse_buffer_body { + SpaPODObjectBody body; + SpaPODInt port_id; + SpaPODInt buffer_id; +}; + +struct pw_event_transport_reuse_buffer { + SpaPOD pod; + struct pw_event_transport_reuse_buffer_body body; +}; + +#define PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT(type,port_id,buffer_id) \ + SPA_EVENT_INIT_COMPLEX (struct pw_event_transport_reuse_buffer, \ + sizeof (struct pw_event_transport_reuse_buffer_body), type, \ + SPA_POD_INT_INIT (port_id), \ + SPA_POD_INT_INIT (buffer_id)) + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PIPEWIRE_TRANSPORT_H__ */ diff --git a/pinos/client/type.c b/pipewire/client/type.c similarity index 58% rename from pinos/client/type.c rename to pipewire/client/type.c index da0dcf544..1845f7412 100644 --- a/pinos/client/type.c +++ b/pipewire/client/type.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,31 +19,31 @@ #include -#include "pinos/client/pinos.h" -#include "pinos/client/type.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/type.h" -#include "pinos/server/core.h" -#include "pinos/server/node.h" -#include "pinos/server/node-factory.h" -#include "pinos/server/client.h" -#include "pinos/server/client-node.h" -#include "pinos/server/module.h" +#include "pipewire/server/core.h" +#include "pipewire/server/node.h" +#include "pipewire/server/node-factory.h" +#include "pipewire/server/client.h" +#include "pipewire/server/client-node.h" +#include "pipewire/server/module.h" #include "spa/monitor.h" void -pinos_type_init (PinosType *type) +pw_type_init (struct pw_type *type) { - type->map = pinos_type_map_get_default(); + type->map = pw_type_map_get_default(); - type->core = spa_type_map_get_id (type->map, PINOS_TYPE__Core); - type->registry = spa_type_map_get_id (type->map, PINOS_TYPE__Registry); - type->node = spa_type_map_get_id (type->map, PINOS_TYPE__Node); - type->node_factory = spa_type_map_get_id (type->map, PINOS_TYPE__NodeFactory); - type->link = spa_type_map_get_id (type->map, PINOS_TYPE__Link); - type->client = spa_type_map_get_id (type->map, PINOS_TYPE__Client); - type->client_node = spa_type_map_get_id (type->map, PINOS_TYPE__ClientNode); - type->module = spa_type_map_get_id (type->map, PINOS_TYPE__Module); + type->core = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Core); + type->registry = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Registry); + type->node = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Node); + type->node_factory = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__NodeFactory); + type->link = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Link); + type->client = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Client); + type->client_node = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__ClientNode); + type->module = spa_type_map_get_id (type->map, PIPEWIRE_TYPE__Module); type->spa_node = spa_type_map_get_id (type->map, SPA_TYPE__Node); type->spa_clock = spa_type_map_get_id (type->map, SPA_TYPE__Clock); @@ -60,35 +60,35 @@ pinos_type_init (PinosType *type) spa_type_param_alloc_meta_enable_map (type->map, &type->param_alloc_meta_enable); spa_type_param_alloc_video_padding_map (type->map, &type->param_alloc_video_padding); - pinos_type_event_transport_map (type->map, &type->event_transport); + pw_type_event_transport_map (type->map, &type->event_transport); } bool -pinos_pod_remap_data (uint32_t type, void * body, uint32_t size, PinosMap *types) +pw_pod_remap_data (uint32_t type, void * body, uint32_t size, struct pw_map *types) { void *t; switch (type) { case SPA_POD_TYPE_ID: - if ((t = pinos_map_lookup (types, *(int32_t*)body)) == NULL) + if ((t = pw_map_lookup (types, *(int32_t*)body)) == NULL) return false; - *(int32_t*)body = PINOS_MAP_PTR_TO_ID (t); + *(int32_t*)body = PW_MAP_PTR_TO_ID (t); break; case SPA_POD_TYPE_PROP: { SpaPODPropBody *b = body; - if ((t = pinos_map_lookup (types, b->key)) == NULL) + if ((t = pw_map_lookup (types, b->key)) == NULL) return false; - b->key = PINOS_MAP_PTR_TO_ID (t); + b->key = PW_MAP_PTR_TO_ID (t); if (b->value.type == SPA_POD_TYPE_ID) { void *alt; - if (!pinos_pod_remap_data (b->value.type, SPA_POD_BODY (&b->value), b->value.size, types)) + if (!pw_pod_remap_data (b->value.type, SPA_POD_BODY (&b->value), b->value.size, types)) return false; SPA_POD_PROP_ALTERNATIVE_FOREACH (b, size, alt) - if (!pinos_pod_remap_data (b->value.type, alt, b->value.size, types)) + if (!pw_pod_remap_data (b->value.type, alt, b->value.size, types)) return false; } break; @@ -98,12 +98,12 @@ pinos_pod_remap_data (uint32_t type, void * body, uint32_t size, PinosMap *types SpaPODObjectBody *b = body; SpaPOD *p; - if ((t = pinos_map_lookup (types, b->type)) == NULL) + if ((t = pw_map_lookup (types, b->type)) == NULL) return false; - b->type = PINOS_MAP_PTR_TO_ID (t); + b->type = PW_MAP_PTR_TO_ID (t); SPA_POD_OBJECT_BODY_FOREACH (b, size, p) - if (!pinos_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types)) + if (!pw_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types)) return false; break; } @@ -112,7 +112,7 @@ pinos_pod_remap_data (uint32_t type, void * body, uint32_t size, PinosMap *types SpaPOD *b = body, *p; SPA_POD_FOREACH (b, size, p) - if (!pinos_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types)) + if (!pw_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types)) return false; break; } diff --git a/pinos/client/type.h b/pipewire/client/type.h similarity index 71% rename from pinos/client/type.h rename to pipewire/client/type.h index 76991f96f..b0c3805a6 100644 --- a/pinos/client/type.h +++ b/pipewire/client/type.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_TYPE_H__ -#define __PINOS_TYPE_H__ +#ifndef __PIPEWIRE_TYPE_H__ +#define __PIPEWIRE_TYPE_H__ #ifdef __cplusplus extern "C" { @@ -30,17 +30,22 @@ extern "C" { #include #include -#include -#include +#include +#include -typedef struct _PinosType PinosType; +struct pw_interface { + uint32_t n_methods; + const void *methods; + uint32_t n_events; + const void *events; +}; /** - * PinosType: + * pw_type: * - * Pinos Type support struct. + * PipeWire Type support struct. */ -struct _PinosType { +struct pw_type { SpaTypeMap *map; SpaType core; @@ -66,21 +71,21 @@ struct _PinosType { SpaTypeParamAllocBuffers param_alloc_buffers; SpaTypeParamAllocMetaEnable param_alloc_meta_enable; SpaTypeParamAllocVideoPadding param_alloc_video_padding; - PinosTypeEventTransport event_transport; + struct pw_type_event_transport event_transport; }; -void pinos_type_init (PinosType *type); +void pw_type_init (struct pw_type *type); -bool pinos_pod_remap_data (uint32_t type, void *body, uint32_t size, PinosMap *types); +bool pw_pod_remap_data (uint32_t type, void *body, uint32_t size, struct pw_map *types); static inline bool -pinos_pod_remap (SpaPOD *pod, PinosMap *types) +pw_pod_remap (SpaPOD *pod, struct pw_map *types) { - return pinos_pod_remap_data (pod->type, SPA_POD_BODY (pod), pod->size, types); + return pw_pod_remap_data (pod->type, SPA_POD_BODY (pod), pod->size, types); } #ifdef __cplusplus } #endif -#endif /* __PINOS_TYPE_H__ */ +#endif /* __PIPEWIRE_TYPE_H__ */ diff --git a/pinos/client/utils.c b/pipewire/client/utils.c similarity index 66% rename from pinos/client/utils.c rename to pipewire/client/utils.c index ec2e38720..0e9888912 100644 --- a/pinos/client/utils.c +++ b/pipewire/client/utils.c @@ -1,4 +1,4 @@ -/* Simple Plugin API +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,15 +19,15 @@ #include -#include -#include -#include +#include +#include +#include const char * -pinos_split_walk (const char *str, - const char *delimiter, - size_t *len, - const char **state) +pw_split_walk (const char *str, + const char *delimiter, + size_t *len, + const char **state) { const char *s = *state ? *state : str; @@ -43,29 +43,29 @@ pinos_split_walk (const char *str, } char ** -pinos_split_strv (const char *str, - const char *delimiter, - int max_tokens, - int *n_tokens) +pw_split_strv (const char *str, + const char *delimiter, + int max_tokens, + int *n_tokens) { const char *state = NULL, *s = NULL; - PinosArray arr; + struct pw_array arr; size_t len; int n = 0; - pinos_array_init (&arr, 16); + pw_array_init (&arr, 16); - s = pinos_split_walk (str, delimiter, &len, &state); + s = pw_split_walk (str, delimiter, &len, &state); while (s && n + 1 < max_tokens) { - pinos_array_add_ptr (&arr, strndup (s, len)); - s = pinos_split_walk (str, delimiter, &len, &state); + pw_array_add_ptr (&arr, strndup (s, len)); + s = pw_split_walk (str, delimiter, &len, &state); n++; } if (s) { - pinos_array_add_ptr (&arr, strdup (s)); + pw_array_add_ptr (&arr, strdup (s)); n++; } - pinos_array_add_ptr (&arr, NULL); + pw_array_add_ptr (&arr, NULL); *n_tokens = n; @@ -74,7 +74,7 @@ pinos_split_strv (const char *str, void -pinos_free_strv (char **str) +pw_free_strv (char **str) { int i; for (i = 0; str[i]; i++) @@ -83,8 +83,8 @@ pinos_free_strv (char **str) } char * -pinos_strip (char *str, - const char *whitespace) +pw_strip (char *str, + const char *whitespace) { char *e, *l = NULL; diff --git a/pinos/client/utils.h b/pipewire/client/utils.h similarity index 52% rename from pinos/client/utils.h rename to pipewire/client/utils.h index b8da5407b..cf6138f50 100644 --- a/pinos/client/utils.h +++ b/pipewire/client/utils.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_UTILS_H__ -#define __PINOS_UTILS_H__ +#ifndef __PIPEWIRE_UTILS_H__ +#define __PIPEWIRE_UTILS_H__ #ifdef __cplusplus extern "C" { @@ -27,31 +27,31 @@ extern "C" { #include #include -const char * pinos_split_walk (const char *str, - const char *delimiter, - size_t *len, - const char **state); -char ** pinos_split_strv (const char *str, - const char *delimiter, - int max_tokens, - int *n_tokens); -void pinos_free_strv (char **str); +const char * pw_split_walk (const char *str, + const char *delimiter, + size_t *len, + const char **state); +char ** pw_split_strv (const char *str, + const char *delimiter, + int max_tokens, + int *n_tokens); +void pw_free_strv (char **str); -char * pinos_strip (char *str, - const char *whitespace); +char * pw_strip (char *str, + const char *whitespace); static inline SpaPOD * -pinos_spa_pod_copy (const SpaPOD *pod) +pw_spa_pod_copy (const SpaPOD *pod) { return pod ? memcpy (malloc (SPA_POD_SIZE (pod)), pod, SPA_POD_SIZE (pod)) : NULL; } -#define spa_format_copy(f) ((SpaFormat*)pinos_spa_pod_copy(&(f)->pod)) -#define spa_props_copy(p) ((SpaProps*)pinos_spa_pod_copy(&(p)->pod)) -#define spa_param_copy(p) ((SpaParam*)pinos_spa_pod_copy(&(p)->pod)) +#define spa_format_copy(f) ((SpaFormat*)pw_spa_pod_copy(&(f)->pod)) +#define spa_props_copy(p) ((SpaProps*)pw_spa_pod_copy(&(p)->pod)) +#define spa_param_copy(p) ((SpaParam*)pw_spa_pod_copy(&(p)->pod)) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __PINOS_UTILS_H__ */ +#endif /* __PIPEWIRE_UTILS_H__ */ diff --git a/pipewire/daemon/.gitignore b/pipewire/daemon/.gitignore new file mode 100644 index 000000000..5347568e4 --- /dev/null +++ b/pipewire/daemon/.gitignore @@ -0,0 +1 @@ +pipewire.desktop diff --git a/pinos/daemon/daemon-config.c b/pipewire/daemon/daemon-config.c similarity index 58% rename from pinos/daemon/daemon-config.c rename to pipewire/daemon/daemon-config.c index a67cdb3f9..7a9da9278 100644 --- a/pinos/daemon/daemon-config.c +++ b/pipewire/daemon/daemon-config.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -25,21 +25,21 @@ #include #include -#include -#include +#include +#include -#include "pinos/daemon/daemon-config.h" +#include "pipewire/daemon/daemon-config.h" -#define DEFAULT_CONFIG_FILE PINOS_CONFIG_DIR "/pinos.conf" +#define DEFAULT_CONFIG_FILE PIPEWIRE_CONFIG_DIR "/pipewire.conf" static bool -parse_line (PinosDaemonConfig *config, - const char *filename, - char *line, - unsigned int lineno, - char **err) +parse_line (struct pw_daemon_config *config, + const char *filename, + char *line, + unsigned int lineno, + char **err) { - PinosCommand *command = NULL; + struct pw_command *command = NULL; char *p; bool ret = true; char *local_err = NULL; @@ -49,12 +49,12 @@ parse_line (PinosDaemonConfig *config, *p = '\0'; /* remove whitespaces */ - pinos_strip (line, "\n\r \t"); + pw_strip (line, "\n\r \t"); if (*line == '\0') /* empty line */ return true; - if ((command = pinos_command_parse (line, &local_err)) == NULL) { + if ((command = pw_command_parse (line, &local_err)) == NULL) { asprintf (err, "%s:%u: %s", filename, lineno, local_err); free (local_err); ret = false; @@ -66,58 +66,58 @@ parse_line (PinosDaemonConfig *config, } /** - * pinos_daemon_config_new: + * pw_daemon_config_new: * - * Returns a new empty #PinosDaemonConfig. + * Returns a new empty #struct pw_daemon_config. */ -PinosDaemonConfig * -pinos_daemon_config_new (void) +struct pw_daemon_config * +pw_daemon_config_new (void) { - PinosDaemonConfig *config; + struct pw_daemon_config *config; - config = calloc (1, sizeof (PinosDaemonConfig)); + config = calloc (1, sizeof (struct pw_daemon_config)); spa_list_init (&config->commands); return config; } /** - * pinos_daemon_config_free: - * @config: A #PinosDaemonConfig + * pw_daemon_config_free: + * @config: A #struct pw_daemon_config * * Free all resources associated to @config. */ void -pinos_daemon_config_free (PinosDaemonConfig * config) +pw_daemon_config_free (struct pw_daemon_config * config) { - PinosCommand *cmd, *tmp; + struct pw_command *cmd, *tmp; spa_list_for_each_safe (cmd, tmp, &config->commands, link) - pinos_command_free (cmd); + pw_command_free (cmd); free (config); } /** - * pinos_daemon_config_load_file: - * @config: A #PinosDaemonConfig + * pw_daemon_config_load_file: + * @config: A #struct pw_daemon_config * @filename: A filename * @err: Return location for an error string * - * Loads pinos config from @filename. + * Loads PipeWire config from @filename. * * Returns: %true on success, otherwise %false and @err is set. */ bool -pinos_daemon_config_load_file (PinosDaemonConfig *config, - const char *filename, - char **err) +pw_daemon_config_load_file (struct pw_daemon_config *config, + const char *filename, + char **err) { unsigned int line; FILE *f; char buf[4096]; - pinos_log_debug ("deamon-config %p: loading configuration file '%s'", config, filename); + pw_log_debug ("deamon-config %p: loading configuration file '%s'", config, filename); if ((f = fopen (filename, "r")) == NULL) { asprintf (err, "failed to open configuration file '%s': %s", filename, strerror (errno)); @@ -152,34 +152,34 @@ open_error: } /** - * pinos_daemon_config_load: - * @config: A #PinosDaemonConfig + * pw_daemon_config_load: + * @config: A #struct pw_daemon_config * @err: Return location for a #GError, or %NULL * - * Loads the default config file for pinos. The filename can be overridden with - * an evironment variable PINOS_CONFIG_FILE. + * Loads the default config file for PipeWire. The filename can be overridden with + * an evironment variable PIPEWIRE_CONFIG_FILE. * * Return: %true on success, otherwise %false and @err is set. */ bool -pinos_daemon_config_load (PinosDaemonConfig *config, - char **err) +pw_daemon_config_load (struct pw_daemon_config *config, + char **err) { const char *filename; - filename = getenv ("PINOS_CONFIG_FILE"); + filename = getenv ("PIPEWIRE_CONFIG_FILE"); if (filename != NULL && *filename != '\0') { - pinos_log_debug ("PINOS_CONFIG_FILE set to: %s", filename); + pw_log_debug ("PIPEWIRE_CONFIG_FILE set to: %s", filename); } else { filename = DEFAULT_CONFIG_FILE; } - return pinos_daemon_config_load_file (config, filename, err); + return pw_daemon_config_load_file (config, filename, err); } /** - * pinos_daemon_config_run_commands: - * @config: A #PinosDaemonConfig - * @core: A #PinosCore + * pw_daemon_config_run_commands: + * @config: A #struct pw_daemon_config + * @core: A #struct pw_core * * Run all commands that have been parsed. The list of commands will be cleared * when this function has been called. @@ -187,23 +187,23 @@ pinos_daemon_config_load (PinosDaemonConfig *config, * Returns: %true if all commands where executed with success, otherwise %false. */ bool -pinos_daemon_config_run_commands (PinosDaemonConfig *config, - PinosCore *core) +pw_daemon_config_run_commands (struct pw_daemon_config *config, + struct pw_core *core) { char *err = NULL; bool ret = true; - PinosCommand *command, *tmp; + struct pw_command *command, *tmp; spa_list_for_each (command, &config->commands, link) { - if (!pinos_command_run (command, core, &err)) { - pinos_log_warn ("could not run command %s: %s", command->name, err); + if (!pw_command_run (command, core, &err)) { + pw_log_warn ("could not run command %s: %s", command->name, err); free (err); ret = false; } } spa_list_for_each_safe (command, tmp, &config->commands, link) { - pinos_command_free (command); + pw_command_free (command); } return ret; diff --git a/pipewire/daemon/daemon-config.h b/pipewire/daemon/daemon-config.h new file mode 100644 index 000000000..23921605a --- /dev/null +++ b/pipewire/daemon/daemon-config.h @@ -0,0 +1,48 @@ +/* PipeWire + * Copyright (C) 2016 Axis Communications + * @author Linus Svensson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_DAEMON_CONFIG_H__ +#define __PIPEWIRE_DAEMON_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct pw_daemon_config { + SpaList commands; +}; + +struct pw_daemon_config * pw_daemon_config_new (void); +void pw_daemon_config_free (struct pw_daemon_config *config); +bool pw_daemon_config_load_file (struct pw_daemon_config *config, + const char *filename, + char **err); +bool pw_daemon_config_load (struct pw_daemon_config *config, + char **err); +bool pw_daemon_config_run_commands (struct pw_daemon_config *config, + struct pw_core *core); +#ifdef __cplusplus +} +#endif + + +#endif /* __PIPEWIRE_DAEMON_CONFIG_H__ */ diff --git a/pinos/daemon/main.c b/pipewire/daemon/main.c similarity index 60% rename from pinos/daemon/main.c rename to pipewire/daemon/main.c index 6b4b1ba26..fc4234ca3 100644 --- a/pinos/daemon/main.c +++ b/pipewire/daemon/main.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,48 +17,48 @@ * Boston, MA 02110-1301, USA. */ -#include -#include -#include +#include +#include +#include #include "daemon-config.h" int main (int argc, char *argv[]) { - PinosCore *core; - PinosMainLoop *loop; - PinosDaemonConfig *config; + struct pw_core *core; + struct pw_main_loop *loop; + struct pw_daemon_config *config; char *err = NULL; - pinos_init (&argc, &argv); + pw_init (&argc, &argv); /* parse configuration */ - config = pinos_daemon_config_new (); - if (!pinos_daemon_config_load (config, &err)) { - pinos_log_error ("failed to parse config: %s", err); + config = pw_daemon_config_new (); + if (!pw_daemon_config_load (config, &err)) { + pw_log_error ("failed to parse config: %s", err); free (err); return -1; } - loop = pinos_main_loop_new (); + loop = pw_main_loop_new (); #if 1 { SpaSource *source; - source = pinos_loop_add_event (loop->loop, NULL, NULL); - pinos_log_set_trace_event (source); + source = pw_loop_add_event (loop->loop, NULL, NULL); + pw_log_set_trace_event (source); } #endif - core = pinos_core_new (loop, NULL); + core = pw_core_new (loop, NULL); - pinos_daemon_config_run_commands (config, core); + pw_daemon_config_run_commands (config, core); - pinos_main_loop_run (loop); + pw_main_loop_run (loop); - pinos_main_loop_destroy (loop); + pw_main_loop_destroy (loop); - pinos_core_destroy (core); + pw_core_destroy (core); return 0; } diff --git a/pipewire/daemon/meson.build b/pipewire/daemon/meson.build new file mode 100644 index 000000000..72c616c96 --- /dev/null +++ b/pipewire/daemon/meson.build @@ -0,0 +1,30 @@ +pipewire_sources = [ + 'main.c', + 'daemon-config.c', +] + +pipewire_headers = [ + 'daemon-config.h', +] + +pipewire_c_args = [ + '-DHAVE_CONFIG_H', + '-D_GNU_SOURCE', + '-DG_LOG_DOMAIN=g_log_domain_pipewire', +] + +conf_config = configuration_data() +conf_install_dir = '@0@/pipewire'.format(get_option('sysconfdir')) + +configure_file(input : 'pipewire.conf.in', + output : 'pipewire.conf', + configuration : conf_config, + install_dir : conf_install_dir) + +executable('pipewire', + pipewire_sources, + install: true, + c_args : pipewire_c_args, + include_directories : [configinc, spa_inc], + dependencies : [pipewire_dep, pipewirecore_dep], +) diff --git a/pinos/daemon/pinos-system.conf b/pipewire/daemon/pipewire-system.conf similarity index 60% rename from pinos/daemon/pinos-system.conf rename to pipewire/daemon/pipewire-system.conf index 19206c999..9ea2adec7 100644 --- a/pinos/daemon/pinos-system.conf +++ b/pipewire/daemon/pipewire-system.conf @@ -3,29 +3,29 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + - - + + diff --git a/pipewire/daemon/pipewire.conf.in b/pipewire/daemon/pipewire.conf.in new file mode 100644 index 000000000..79949cb9d --- /dev/null +++ b/pipewire/daemon/pipewire.conf.in @@ -0,0 +1,7 @@ +#load-module libpipewire-module-protocol-dbus +load-module libpipewire-module-protocol-native +load-module libpipewire-module-suspend-on-idle +load-module libpipewire-module-spa --pattern snow +load-module libpipewire-module-autolink +#load-module libpipewire-module-mixer +load-module libpipewire-module-flatpak diff --git a/pinos/daemon/pinos.desktop.in b/pipewire/daemon/pipewire.desktop.in similarity index 64% rename from pinos/daemon/pinos.desktop.in rename to pipewire/daemon/pipewire.desktop.in index ac5c31718..7ff72c557 100644 --- a/pinos/daemon/pinos.desktop.in +++ b/pipewire/daemon/pipewire.desktop.in @@ -1,8 +1,8 @@ [Desktop Entry] Version=1.0 -_Name=Pinos Media System -_Comment=Start the Pinos Media System -Exec=pinos +_Name=PipeWire Media System +_Comment=Start the PipeWire Media System +Exec=pipewire Terminal=false Type=Application Categories= diff --git a/pinos/examples/meson.build b/pipewire/examples/meson.build similarity index 62% rename from pinos/examples/meson.build rename to pipewire/examples/meson.build index 9d0142463..3276cecf9 100644 --- a/pinos/examples/meson.build +++ b/pipewire/examples/meson.build @@ -1,11 +1,11 @@ executable('video-src', 'video-src.c', install: false, - dependencies : [pinos_dep], + dependencies : [pipewire_dep], ) executable('video-play', 'video-play.c', install: false, - dependencies : [pinos_dep,sdl_dep], + dependencies : [pipewire_dep,sdl_dep], ) diff --git a/pinos/examples/video-play.c b/pipewire/examples/video-play.c similarity index 79% rename from pinos/examples/video-play.c rename to pipewire/examples/video-play.c index 372e0c9e9..abb4e2d49 100644 --- a/pinos/examples/video-play.c +++ b/pipewire/examples/video-play.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include typedef struct { @@ -60,7 +60,7 @@ init_type (Type *type, SpaTypeMap *map) #define HEIGHT 480 #define BPP 3 -typedef struct { +struct data { Type type; const char *path; @@ -70,26 +70,26 @@ typedef struct { SDL_Texture *texture; bool running; - PinosLoop *loop; + struct pw_loop *loop; SpaSource *timer; - PinosContext *context; - PinosListener on_state_changed; + struct pw_context *context; + struct pw_listener on_state_changed; - PinosStream *stream; - PinosListener on_stream_state_changed; - PinosListener on_stream_format_changed; - PinosListener on_stream_new_buffer; + struct pw_stream *stream; + struct pw_listener on_stream_state_changed; + struct pw_listener on_stream_format_changed; + struct pw_listener on_stream_new_buffer; SpaVideoInfoRaw format; int32_t stride; uint8_t params_buffer[1024]; int counter; -} Data; +}; static void -handle_events (Data *data) +handle_events (struct data *data) { SDL_Event event; while (SDL_PollEvent (&event)) { @@ -102,11 +102,11 @@ handle_events (Data *data) } static void -on_stream_new_buffer (PinosListener *listener, - PinosStream *stream, - uint32_t id) +on_stream_new_buffer (struct pw_listener *listener, + struct pw_stream *stream, + uint32_t id) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_stream_new_buffer); + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_stream_new_buffer); SpaBuffer *buf; uint8_t *map; void *sdata, *ddata; @@ -114,7 +114,7 @@ on_stream_new_buffer (PinosListener *listener, int i; uint8_t *src, *dst; - buf = pinos_stream_peek_buffer (data->stream, id); + buf = pw_stream_peek_buffer (data->stream, id); if (buf->datas[0].type == data->type.data.MemFd) { map = mmap (NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset, PROT_READ, @@ -150,16 +150,16 @@ on_stream_new_buffer (PinosListener *listener, if (map) munmap (map, buf->datas[0].maxsize); - pinos_stream_recycle_buffer (data->stream, id); + pw_stream_recycle_buffer (data->stream, id); handle_events (data); } static void -on_stream_state_changed (PinosListener *listener, - PinosStream *stream) +on_stream_state_changed (struct pw_listener *listener, + struct pw_stream *stream) { - printf ("stream state: \"%s\"\n", pinos_stream_state_as_string (stream->state)); + printf ("stream state: \"%s\"\n", pw_stream_state_as_string (stream->state)); } static struct { @@ -209,7 +209,7 @@ static struct { }; static uint32_t -sdl_format_to_id (Data *data, Uint32 format) +sdl_format_to_id (struct data *data, Uint32 format) { int i; @@ -221,7 +221,7 @@ sdl_format_to_id (Data *data, Uint32 format) } static Uint32 -id_to_sdl_format (Data *data, uint32_t id) +id_to_sdl_format (struct data *data, uint32_t id) { int i; @@ -239,12 +239,12 @@ id_to_sdl_format (Data *data, uint32_t id) SPA_POD_PROP_RANGE_MIN_MAX,type,3,__VA_ARGS__) static void -on_stream_format_changed (PinosListener *listener, - PinosStream *stream, - SpaFormat *format) +on_stream_format_changed (struct pw_listener *listener, + struct pw_stream *stream, + SpaFormat *format) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_stream_format_changed); - PinosContext *ctx = stream->context; + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_stream_format_changed); + struct pw_context *ctx = stream->context; SpaPODBuilder b = { NULL }; SpaPODFrame f[2]; SpaParam *params[2]; @@ -259,7 +259,7 @@ on_stream_format_changed (PinosListener *listener, sdl_format = id_to_sdl_format (data, data->format.format); if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) { - pinos_stream_finish_format (stream, SPA_RESULT_ERROR, NULL, 0); + pw_stream_finish_format (stream, SPA_RESULT_ERROR, NULL, 0); return; } @@ -285,25 +285,25 @@ on_stream_format_changed (PinosListener *listener, PROP (&f[1], ctx->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader))); params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam); - pinos_stream_finish_format (stream, SPA_RESULT_OK, params, 2); + pw_stream_finish_format (stream, SPA_RESULT_OK, params, 2); } else { - pinos_stream_finish_format (stream, SPA_RESULT_OK, NULL, 0); + pw_stream_finish_format (stream, SPA_RESULT_OK, NULL, 0); } } static void -on_state_changed (PinosListener *listener, - PinosContext *context) +on_state_changed (struct pw_listener *listener, + struct pw_context *context) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_state_changed); + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_state_changed); switch (context->state) { - case PINOS_CONTEXT_STATE_ERROR: + case PW_CONTEXT_STATE_ERROR: printf ("context error: %s\n", context->error); data->running = false; break; - case PINOS_CONTEXT_STATE_CONNECTED: + case PW_CONTEXT_STATE_CONNECTED: { SpaFormat *formats[1]; uint8_t buffer[1024]; @@ -312,9 +312,9 @@ on_state_changed (PinosListener *listener, SDL_RendererInfo info; int i, c; - printf ("context state: \"%s\"\n", pinos_context_state_as_string (context->state)); + printf ("context state: \"%s\"\n", pw_context_state_as_string (context->state)); - data->stream = pinos_stream_new (context, "video-play", NULL); + data->stream = pw_stream_new (context, "video-play", NULL); SDL_GetRendererInfo(data->renderer, &info); @@ -355,27 +355,27 @@ on_state_changed (PinosListener *listener, printf ("supported formats:\n"); spa_debug_format (formats[0], data->context->type.map); - pinos_signal_add (&data->stream->state_changed, - &data->on_stream_state_changed, - on_stream_state_changed); - pinos_signal_add (&data->stream->format_changed, - &data->on_stream_format_changed, - on_stream_format_changed); - pinos_signal_add (&data->stream->new_buffer, - &data->on_stream_new_buffer, - on_stream_new_buffer); + pw_signal_add (&data->stream->state_changed, + &data->on_stream_state_changed, + on_stream_state_changed); + pw_signal_add (&data->stream->format_changed, + &data->on_stream_format_changed, + on_stream_format_changed); + pw_signal_add (&data->stream->new_buffer, + &data->on_stream_new_buffer, + on_stream_new_buffer); - pinos_stream_connect (data->stream, - PINOS_DIRECTION_INPUT, - PINOS_STREAM_MODE_BUFFER, - data->path, - PINOS_STREAM_FLAG_AUTOCONNECT, - 1, - formats); + pw_stream_connect (data->stream, + PW_DIRECTION_INPUT, + PW_STREAM_MODE_BUFFER, + data->path, + PW_STREAM_FLAG_AUTOCONNECT, + 1, + formats); break; } default: - printf ("context state: \"%s\"\n", pinos_context_state_as_string (context->state)); + printf ("context state: \"%s\"\n", pw_context_state_as_string (context->state)); break; } } @@ -383,13 +383,13 @@ on_state_changed (PinosListener *listener, int main (int argc, char *argv[]) { - Data data = { 0, }; + struct data data = { 0, }; - pinos_init (&argc, &argv); + pw_init (&argc, &argv); - data.loop = pinos_loop_new (); + data.loop = pw_loop_new (); data.running = true; - data.context = pinos_context_new (data.loop, "video-play", NULL); + data.context = pw_context_new (data.loop, "video-play", NULL); data.path = argc > 1 ? argv[1] : NULL; init_type (&data.type, data.context->type.map); @@ -404,20 +404,20 @@ main (int argc, char *argv[]) return -1; } - pinos_signal_add (&data.context->state_changed, + pw_signal_add (&data.context->state_changed, &data.on_state_changed, on_state_changed); - pinos_context_connect (data.context, PINOS_CONTEXT_FLAG_NO_REGISTRY); + pw_context_connect (data.context, PW_CONTEXT_FLAG_NO_REGISTRY); - pinos_loop_enter (data.loop); + pw_loop_enter (data.loop); while (data.running) { - pinos_loop_iterate (data.loop, -1); + pw_loop_iterate (data.loop, -1); } - pinos_loop_leave (data.loop); + pw_loop_leave (data.loop); - pinos_context_destroy (data.context); - pinos_loop_destroy (data.loop); + pw_context_destroy (data.context); + pw_loop_destroy (data.loop); return 0; } diff --git a/pinos/examples/video-src.c b/pipewire/examples/video-src.c similarity index 69% rename from pinos/examples/video-src.c rename to pipewire/examples/video-src.c index 6ac9abbe9..fee60eb09 100644 --- a/pinos/examples/video-src.c +++ b/pipewire/examples/video-src.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -28,11 +28,11 @@ #include #include -#include -#include +#include +#include #include -typedef struct { +struct type { uint32_t format; uint32_t props; SpaTypeMeta meta; @@ -41,10 +41,10 @@ typedef struct { SpaTypeMediaSubtype media_subtype; SpaTypeFormatVideo format_video; SpaTypeVideoFormat video_format; -} Type; +}; static inline void -init_type (Type *type, SpaTypeMap *map) +init_type (struct type *type, SpaTypeMap *map) { type->format = spa_type_map_get_id (map, SPA_TYPE__Format); type->props = spa_type_map_get_id (map, SPA_TYPE__Props); @@ -58,19 +58,19 @@ init_type (Type *type, SpaTypeMap *map) #define BPP 3 -typedef struct { - Type type; +struct data { + struct type type; bool running; - PinosLoop *loop; + struct pw_loop *loop; SpaSource *timer; - PinosContext *context; - PinosListener on_state_changed; + struct pw_context *context; + struct pw_listener on_state_changed; - PinosStream *stream; - PinosListener on_stream_state_changed; - PinosListener on_stream_format_changed; + struct pw_stream *stream; + struct pw_listener on_stream_state_changed; + struct pw_listener on_stream_format_changed; SpaVideoInfoRaw format; int32_t stride; @@ -78,25 +78,25 @@ typedef struct { uint8_t params_buffer[1024]; int counter; uint32_t seq; -} Data; +}; static void on_timeout (SpaLoopUtils *utils, SpaSource *source, void *userdata) { - Data *data = userdata; + struct data *data = userdata; uint32_t id; SpaBuffer *buf; int i, j; uint8_t *p, *map; SpaMetaHeader *h; - id = pinos_stream_get_empty_buffer (data->stream); + id = pw_stream_get_empty_buffer (data->stream); if (id == SPA_ID_INVALID) return; - buf = pinos_stream_peek_buffer (data->stream, id); + buf = pw_stream_peek_buffer (data->stream, id); if (buf->datas[0].type == data->type.data.MemFd) { map = mmap (NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset, PROT_READ | PROT_WRITE, @@ -133,27 +133,27 @@ on_timeout (SpaLoopUtils *utils, if (map) munmap (map, buf->datas[0].maxsize + buf->datas[0].mapoffset); - pinos_stream_send_buffer (data->stream, id); + pw_stream_send_buffer (data->stream, id); } static void -on_stream_state_changed (PinosListener *listener, - PinosStream *stream) +on_stream_state_changed (struct pw_listener *listener, + struct pw_stream *stream) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_stream_state_changed); + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_stream_state_changed); - printf ("stream state: \"%s\"\n", pinos_stream_state_as_string (stream->state)); + printf ("stream state: \"%s\"\n", pw_stream_state_as_string (stream->state)); switch (stream->state) { - case PINOS_STREAM_STATE_PAUSED: - pinos_loop_update_timer (data->loop, + case PW_STREAM_STATE_PAUSED: + pw_loop_update_timer (data->loop, data->timer, NULL, NULL, false); break; - case PINOS_STREAM_STATE_STREAMING: + case PW_STREAM_STATE_STREAMING: { struct timespec timeout, interval; @@ -162,7 +162,7 @@ on_stream_state_changed (PinosListener *listener, interval.tv_sec = 0; interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC; - pinos_loop_update_timer (data->loop, + pw_loop_update_timer (data->loop, data->timer, &timeout, &interval, @@ -181,12 +181,12 @@ on_stream_state_changed (PinosListener *listener, SPA_POD_PROP_RANGE_MIN_MAX,type,3,__VA_ARGS__) static void -on_stream_format_changed (PinosListener *listener, - PinosStream *stream, +on_stream_format_changed (struct pw_listener *listener, + struct pw_stream *stream, SpaFormat *format) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_stream_format_changed); - PinosContext *ctx = stream->context; + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_stream_format_changed); + struct pw_context *ctx = stream->context; SpaPODBuilder b = { NULL }; SpaPODFrame f[2]; SpaParam *params[2]; @@ -210,35 +210,35 @@ on_stream_format_changed (PinosListener *listener, PROP (&f[1], ctx->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader))); params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam); - pinos_stream_finish_format (stream, SPA_RESULT_OK, params, 2); + pw_stream_finish_format (stream, SPA_RESULT_OK, params, 2); } else { - pinos_stream_finish_format (stream, SPA_RESULT_OK, NULL, 0); + pw_stream_finish_format (stream, SPA_RESULT_OK, NULL, 0); } } static void -on_state_changed (PinosListener *listener, - PinosContext *context) +on_state_changed (struct pw_listener *listener, + struct pw_context *context) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_state_changed); + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_state_changed); switch (context->state) { - case PINOS_CONTEXT_STATE_ERROR: + case PW_CONTEXT_STATE_ERROR: printf ("context error: %s\n", context->error); data->running = false; break; - case PINOS_CONTEXT_STATE_CONNECTED: + case PW_CONTEXT_STATE_CONNECTED: { SpaFormat *formats[1]; uint8_t buffer[1024]; SpaPODBuilder b = SPA_POD_BUILDER_INIT (buffer, sizeof (buffer)); SpaPODFrame f[2]; - printf ("context state: \"%s\"\n", pinos_context_state_as_string (context->state)); + printf ("context state: \"%s\"\n", pw_context_state_as_string (context->state)); - data->stream = pinos_stream_new (context, "video-src", NULL); + data->stream = pw_stream_new (context, "video-src", NULL); spa_pod_builder_format (&b, &f[0], data->type.format, data->type.media_type.video, data->type.media_subtype.raw, @@ -249,24 +249,24 @@ on_state_changed (PinosListener *listener, PROP (&f[1], data->type.format_video.framerate, SPA_POD_TYPE_FRACTION, 25, 1)); formats[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat); - pinos_signal_add (&data->stream->state_changed, - &data->on_stream_state_changed, - on_stream_state_changed); - pinos_signal_add (&data->stream->format_changed, - &data->on_stream_format_changed, - on_stream_format_changed); + pw_signal_add (&data->stream->state_changed, + &data->on_stream_state_changed, + on_stream_state_changed); + pw_signal_add (&data->stream->format_changed, + &data->on_stream_format_changed, + on_stream_format_changed); - pinos_stream_connect (data->stream, - PINOS_DIRECTION_OUTPUT, - PINOS_STREAM_MODE_BUFFER, - NULL, - PINOS_STREAM_FLAG_NONE, - 1, - formats); + pw_stream_connect (data->stream, + PW_DIRECTION_OUTPUT, + PW_STREAM_MODE_BUFFER, + NULL, + PW_STREAM_FLAG_NONE, + 1, + formats); break; } default: - printf ("context state: \"%s\"\n", pinos_context_state_as_string (context->state)); + printf ("context state: \"%s\"\n", pw_context_state_as_string (context->state)); break; } } @@ -274,33 +274,33 @@ on_state_changed (PinosListener *listener, int main (int argc, char *argv[]) { - Data data = { 0, }; + struct data data = { 0, }; - pinos_init (&argc, &argv); + pw_init (&argc, &argv); - data.loop = pinos_loop_new (); + data.loop = pw_loop_new (); data.running = true; - data.context = pinos_context_new (data.loop, "video-src", NULL); + data.context = pw_context_new (data.loop, "video-src", NULL); init_type (&data.type, data.context->type.map); - data.timer = pinos_loop_add_timer (data.loop, on_timeout, &data); + data.timer = pw_loop_add_timer (data.loop, on_timeout, &data); - pinos_signal_add (&data.context->state_changed, - &data.on_state_changed, - on_state_changed); + pw_signal_add (&data.context->state_changed, + &data.on_state_changed, + on_state_changed); - pinos_context_connect (data.context, - PINOS_CONTEXT_FLAG_NO_REGISTRY); + pw_context_connect (data.context, + PW_CONTEXT_FLAG_NO_REGISTRY); - pinos_loop_enter (data.loop); + pw_loop_enter (data.loop); while (data.running) { - pinos_loop_iterate (data.loop, -1); + pw_loop_iterate (data.loop, -1); } - pinos_loop_leave (data.loop); + pw_loop_leave (data.loop); - pinos_context_destroy (data.context); - pinos_loop_destroy (data.loop); + pw_context_destroy (data.context); + pw_loop_destroy (data.loop); return 0; } diff --git a/pinos/gst/gstburstcache.c b/pipewire/gst/gstburstcache.c similarity index 100% rename from pinos/gst/gstburstcache.c rename to pipewire/gst/gstburstcache.c diff --git a/pinos/gst/gstburstcache.h b/pipewire/gst/gstburstcache.h similarity index 100% rename from pinos/gst/gstburstcache.h rename to pipewire/gst/gstburstcache.h diff --git a/pinos/gst/gstpinos.c b/pipewire/gst/gstpipewire.c similarity index 57% rename from pinos/gst/gstpinos.c rename to pipewire/gst/gstpipewire.c index 9b2750a64..b51e47199 100644 --- a/pinos/gst/gstpinos.c +++ b/pipewire/gst/gstpipewire.c @@ -18,13 +18,13 @@ */ /** - * SECTION:element-pinossrc + * SECTION:element-pipewiresrc * * * Example launch line * |[ - * gst-launch -v pinossrc ! ximagesink - * ]| Shows pinos output in an X window. + * gst-launch -v pipewiresrc ! ximagesink + * ]| Shows PipeWire output in an X window. * */ @@ -32,33 +32,33 @@ #include "config.h" #endif -#include "gstpinossrc.h" -#include "gstpinossink.h" -#include "gstpinosdeviceprovider.h" +#include "gstpipewiresrc.h" +#include "gstpipewiresink.h" +#include "gstpipewiredeviceprovider.h" -GST_DEBUG_CATEGORY (pinos_debug); +GST_DEBUG_CATEGORY (pipewire_debug); static gboolean plugin_init (GstPlugin * plugin) { - pinos_init (NULL, NULL); + pw_init (NULL, NULL); - gst_element_register (plugin, "pinossrc", GST_RANK_PRIMARY + 1, - GST_TYPE_PINOS_SRC); - gst_element_register (plugin, "pinossink", GST_RANK_NONE, - GST_TYPE_PINOS_SINK); + gst_element_register (plugin, "pipewiresrc", GST_RANK_PRIMARY + 1, + GST_TYPE_PIPEWIRE_SRC); + gst_element_register (plugin, "pipewiresink", GST_RANK_NONE, + GST_TYPE_PIPEWIRE_SINK); - if (!gst_device_provider_register (plugin, "pinosdeviceprovider", - GST_RANK_PRIMARY + 1, GST_TYPE_PINOS_DEVICE_PROVIDER)) + if (!gst_device_provider_register (plugin, "pipewiredeviceprovider", + GST_RANK_PRIMARY + 1, GST_TYPE_PIPEWIRE_DEVICE_PROVIDER)) return FALSE; - GST_DEBUG_CATEGORY_INIT (pinos_debug, "pinos", 0, "Pinos elements"); + GST_DEBUG_CATEGORY_INIT (pipewire_debug, "pipewire", 0, "PipeWirie elements"); return TRUE; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, - pinos, - "Uses pinos to handle media streams", - plugin_init, VERSION, "LGPL", "pinos", "pinos.org") + pipewire, + "Uses PipeWire to handle media streams", + plugin_init, VERSION, "LGPL", "pipewire", "pipewire.org") diff --git a/pinos/gst/gstpinosclock.c b/pipewire/gst/gstpipewireclock.c similarity index 57% rename from pinos/gst/gstpinosclock.c rename to pipewire/gst/gstpipewireclock.c index 8e8583dc1..a82631efe 100644 --- a/pinos/gst/gstpinosclock.c +++ b/pipewire/gst/gstpipewireclock.c @@ -23,32 +23,32 @@ #include -#include "gstpinosclock.h" +#include "gstpipewireclock.h" -GST_DEBUG_CATEGORY_STATIC (gst_pinos_clock_debug_category); -#define GST_CAT_DEFAULT gst_pinos_clock_debug_category +GST_DEBUG_CATEGORY_STATIC (gst_pipewire_clock_debug_category); +#define GST_CAT_DEFAULT gst_pipewire_clock_debug_category -G_DEFINE_TYPE (GstPinosClock, gst_pinos_clock, GST_TYPE_SYSTEM_CLOCK); +G_DEFINE_TYPE (GstPipeWireClock, gst_pipewire_clock, GST_TYPE_SYSTEM_CLOCK); GstClock * -gst_pinos_clock_new (PinosStream *stream) +gst_pipewire_clock_new (struct pw_stream *stream) { - GstPinosClock *clock; + GstPipeWireClock *clock; - clock = g_object_new (GST_TYPE_PINOS_CLOCK, NULL); + clock = g_object_new (GST_TYPE_PIPEWIRE_CLOCK, NULL); clock->stream = stream; return GST_CLOCK_CAST (clock); } static GstClockTime -gst_pinos_clock_get_internal_time (GstClock * clock) +gst_pipewire_clock_get_internal_time (GstClock * clock) { - GstPinosClock *pclock = (GstPinosClock *) clock; + GstPipeWireClock *pclock = (GstPipeWireClock *) clock; GstClockTime result; - PinosTime t; + struct pw_time t; - pinos_stream_get_time (pclock->stream, &t); + pw_stream_get_time (pclock->stream, &t); if (t.rate) result = gst_util_uint64_scale_int (t.ticks, GST_SECOND, t.rate); @@ -62,31 +62,31 @@ gst_pinos_clock_get_internal_time (GstClock * clock) static void -gst_pinos_clock_finalize (GObject * object) +gst_pipewire_clock_finalize (GObject * object) { - GstPinosClock *clock = GST_PINOS_CLOCK (object); + GstPipeWireClock *clock = GST_PIPEWIRE_CLOCK (object); GST_DEBUG_OBJECT (clock, "finalize"); - G_OBJECT_CLASS (gst_pinos_clock_parent_class)->finalize (object); + G_OBJECT_CLASS (gst_pipewire_clock_parent_class)->finalize (object); } static void -gst_pinos_clock_class_init (GstPinosClockClass * klass) +gst_pipewire_clock_class_init (GstPipeWireClockClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstClockClass *gstclock_class = GST_CLOCK_CLASS (klass); - gobject_class->finalize = gst_pinos_clock_finalize; + gobject_class->finalize = gst_pipewire_clock_finalize; - gstclock_class->get_internal_time = gst_pinos_clock_get_internal_time; + gstclock_class->get_internal_time = gst_pipewire_clock_get_internal_time; - GST_DEBUG_CATEGORY_INIT (gst_pinos_clock_debug_category, "pinosclock", 0, - "debug category for pinosclock object"); + GST_DEBUG_CATEGORY_INIT (gst_pipewire_clock_debug_category, "pipewireclock", 0, + "debug category for pipewireclock object"); } static void -gst_pinos_clock_init (GstPinosClock * clock) +gst_pipewire_clock_init (GstPipeWireClock * clock) { GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER); } diff --git a/pipewire/gst/gstpipewireclock.h b/pipewire/gst/gstpipewireclock.h new file mode 100644 index 000000000..4832dbeb1 --- /dev/null +++ b/pipewire/gst/gstpipewireclock.h @@ -0,0 +1,62 @@ +/* GStreamer + * Copyright (C) <2016> Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_PIPEWIRE_CLOCK_H__ +#define __GST_PIPEWIRE_CLOCK_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_PIPEWIRE_CLOCK \ + (gst_pipewire_clock_get_type()) +#define GST_PIPEWIRE_CLOCK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PIPEWIRE_CLOCK,GstPipeWireClock)) +#define GST_PIPEWIRE_CLOCK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PIPEWIRE_CLOCK,GstPipeWireClockClass)) +#define GST_IS_PIPEWIRE_CLOCK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PIPEWIRE_CLOCK)) +#define GST_IS_PIPEWIRE_CLOCK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PIPEWIRE_CLOCK)) +#define GST_PIPEWIRE_CLOCK_GET_CLASS(klass) \ + (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_PIPEWIRE_CLOCK, GstPipeWireClockClass)) + +typedef struct _GstPipeWireClock GstPipeWireClock; +typedef struct _GstPipeWireClockClass GstPipeWireClockClass; + +struct _GstPipeWireClock { + GstSystemClock parent; + + struct pw_stream *stream; +}; + +struct _GstPipeWireClockClass { + GstSystemClockClass parent_class; +}; + +GType gst_pipewire_clock_get_type (void); + +GstClock * gst_pipewire_clock_new (struct pw_stream *stream); + + +G_END_DECLS + +#endif /* __GST_PIPEWIRE_CLOCK_H__ */ diff --git a/pinos/gst/gstpinosdeviceprovider.c b/pipewire/gst/gstpipewiredeviceprovider.c similarity index 52% rename from pinos/gst/gstpinosdeviceprovider.c rename to pipewire/gst/gstpipewiredeviceprovider.c index 10d42988d..bdcdbdf83 100644 --- a/pinos/gst/gstpinosdeviceprovider.c +++ b/pipewire/gst/gstpipewiredeviceprovider.c @@ -2,7 +2,7 @@ * Copyright (C) 2012 Olivier Crete * (C) 2015 Wim Taymans * - * pinosdeviceprovider.c: pinos device probing and monitoring + * pipewiredeviceprovider.c: PipeWire device probing and monitoring * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,15 +28,15 @@ #include -#include "gstpinosformat.h" -#include "gstpinosdeviceprovider.h" -#include "gstpinossrc.h" -#include "gstpinossink.h" +#include "gstpipewireformat.h" +#include "gstpipewiredeviceprovider.h" +#include "gstpipewiresrc.h" +#include "gstpipewiresink.h" -GST_DEBUG_CATEGORY_EXTERN (pinos_debug); -#define GST_CAT_DEFAULT pinos_debug +GST_DEBUG_CATEGORY_EXTERN (pipewire_debug); +#define GST_CAT_DEFAULT pipewire_debug -G_DEFINE_TYPE (GstPinosDevice, gst_pinos_device, GST_TYPE_DEVICE); +G_DEFINE_TYPE (GstPipeWireDevice, gst_pipewire_device, GST_TYPE_DEVICE); enum { @@ -44,29 +44,29 @@ enum }; static GstDevice * -gst_pinos_device_new (uint32_t id, const gchar * device_name, +gst_pipewire_device_new (uint32_t id, const gchar * device_name, GstCaps * caps, const gchar *klass, - GstPinosDeviceType type, GstStructure *props) + GstPipeWireDeviceType type, GstStructure *props) { - GstPinosDevice *gstdev; + GstPipeWireDevice *gstdev; const gchar *element = NULL; g_return_val_if_fail (device_name, NULL); g_return_val_if_fail (caps, NULL); switch (type) { - case GST_PINOS_DEVICE_TYPE_SOURCE: - element = "pinossrc"; + case GST_PIPEWIRE_DEVICE_TYPE_SOURCE: + element = "pipewiresrc"; break; - case GST_PINOS_DEVICE_TYPE_SINK: - element = "pinossink"; + case GST_PIPEWIRE_DEVICE_TYPE_SINK: + element = "pipewiresink"; break; default: g_assert_not_reached (); break; } - gstdev = g_object_new (GST_TYPE_PINOS_DEVICE, + gstdev = g_object_new (GST_TYPE_PIPEWIRE_DEVICE, "display-name", device_name, "caps", caps, "device-class", klass, "id", id, "properties", props, NULL); @@ -78,14 +78,14 @@ gst_pinos_device_new (uint32_t id, const gchar * device_name, } static GstElement * -gst_pinos_device_create_element (GstDevice * device, const gchar * name) +gst_pipewire_device_create_element (GstDevice * device, const gchar * name) { - GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device); + GstPipeWireDevice *pipewire_dev = GST_PIPEWIRE_DEVICE (device); GstElement *elem; gchar *str; - elem = gst_element_factory_make (pinos_dev->element, name); - str = g_strdup_printf ("%u", pinos_dev->id); + elem = gst_element_factory_make (pipewire_dev->element, name); + str = g_strdup_printf ("%u", pipewire_dev->id); g_object_set (elem, "path", str, NULL); g_free (str); @@ -93,22 +93,22 @@ gst_pinos_device_create_element (GstDevice * device, const gchar * name) } static gboolean -gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element) +gst_pipewire_device_reconfigure_element (GstDevice * device, GstElement * element) { - GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device); + GstPipeWireDevice *pipewire_dev = GST_PIPEWIRE_DEVICE (device); gchar *str; - if (!strcmp (pinos_dev->element, "pinossrc")) { - if (!GST_IS_PINOS_SRC (element)) + if (!strcmp (pipewire_dev->element, "pipewiresrc")) { + if (!GST_IS_PIPEWIRE_SRC (element)) return FALSE; - } else if (!strcmp (pinos_dev->element, "pinossink")) { - if (!GST_IS_PINOS_SINK (element)) + } else if (!strcmp (pipewire_dev->element, "pipewiresink")) { + if (!GST_IS_PIPEWIRE_SINK (element)) return FALSE; } else { g_assert_not_reached (); } - str = g_strdup_printf ("%u", pinos_dev->id); + str = g_strdup_printf ("%u", pipewire_dev->id); g_object_set (element, "path", str, NULL); g_free (str); @@ -117,12 +117,12 @@ gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element) static void -gst_pinos_device_get_property (GObject * object, guint prop_id, +gst_pipewire_device_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstPinosDevice *device; + GstPipeWireDevice *device; - device = GST_PINOS_DEVICE_CAST (object); + device = GST_PIPEWIRE_DEVICE_CAST (object); switch (prop_id) { case PROP_ID: @@ -135,12 +135,12 @@ gst_pinos_device_get_property (GObject * object, guint prop_id, } static void -gst_pinos_device_set_property (GObject * object, guint prop_id, +gst_pipewire_device_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstPinosDevice *device; + GstPipeWireDevice *device; - device = GST_PINOS_DEVICE_CAST (object); + device = GST_PIPEWIRE_DEVICE_CAST (object); switch (prop_id) { case PROP_ID: @@ -153,36 +153,36 @@ gst_pinos_device_set_property (GObject * object, guint prop_id, } static void -gst_pinos_device_finalize (GObject * object) +gst_pipewire_device_finalize (GObject * object) { - G_OBJECT_CLASS (gst_pinos_device_parent_class)->finalize (object); + G_OBJECT_CLASS (gst_pipewire_device_parent_class)->finalize (object); } static void -gst_pinos_device_class_init (GstPinosDeviceClass * klass) +gst_pipewire_device_class_init (GstPipeWireDeviceClass * klass) { GstDeviceClass *dev_class = GST_DEVICE_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); - dev_class->create_element = gst_pinos_device_create_element; - dev_class->reconfigure_element = gst_pinos_device_reconfigure_element; + dev_class->create_element = gst_pipewire_device_create_element; + dev_class->reconfigure_element = gst_pipewire_device_reconfigure_element; - object_class->get_property = gst_pinos_device_get_property; - object_class->set_property = gst_pinos_device_set_property; - object_class->finalize = gst_pinos_device_finalize; + object_class->get_property = gst_pipewire_device_get_property; + object_class->set_property = gst_pipewire_device_set_property; + object_class->finalize = gst_pipewire_device_finalize; g_object_class_install_property (object_class, PROP_ID, g_param_spec_uint ("id", "Id", - "The internal id of the Pinos device", 0, G_MAXUINT32, SPA_ID_INVALID, + "The internal id of the PipeWire device", 0, G_MAXUINT32, SPA_ID_INVALID, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void -gst_pinos_device_init (GstPinosDevice * device) +gst_pipewire_device_init (GstPipeWireDevice * device) { } -G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider, +G_DEFINE_TYPE (GstPipeWireDeviceProvider, gst_pipewire_device_provider, GST_TYPE_DEVICE_PROVIDER); enum @@ -193,18 +193,18 @@ enum }; static GstDevice * -new_node (const PinosNodeInfo *info) +new_node (const struct pw_node_info *info) { GstCaps *caps = NULL; GstStructure *props; const gchar *klass = NULL; SpaDictItem *item; - GstPinosDeviceType type; + GstPipeWireDeviceType type; int i; caps = gst_caps_new_empty (); if (info->max_inputs > 0 && info->max_outputs == 0) { - type = GST_PINOS_DEVICE_TYPE_SINK; + type = GST_PIPEWIRE_DEVICE_TYPE_SINK; for (i = 0; i < info->n_input_formats; i++) { GstCaps *c1 = gst_caps_from_format (info->input_formats[i]); @@ -213,17 +213,17 @@ new_node (const PinosNodeInfo *info) } } else if (info->max_outputs > 0 && info->max_inputs == 0) { - type = GST_PINOS_DEVICE_TYPE_SOURCE; + type = GST_PIPEWIRE_DEVICE_TYPE_SOURCE; for (i = 0; i < info->n_output_formats; i++) { GstCaps *c1 = gst_caps_from_format (info->output_formats[i]); if (c1) gst_caps_append (caps, c1); } } else { - type = GST_PINOS_DEVICE_TYPE_UNKNOWN; + type = GST_PIPEWIRE_DEVICE_TYPE_UNKNOWN; } - props = gst_structure_new_empty ("pinos-proplist"); + props = gst_structure_new_empty ("pipewire-proplist"); if (info->props) { spa_dict_for_each (item, info->props) gst_structure_set (props, item->key, G_TYPE_STRING, item->value, NULL); @@ -233,7 +233,7 @@ new_node (const PinosNodeInfo *info) if (klass == NULL) klass = "unknown/unknown"; - return gst_pinos_device_new (info->id, + return gst_pipewire_device_new (info->id, info->name, caps, klass, @@ -242,12 +242,12 @@ new_node (const PinosNodeInfo *info) } static void -get_node_info_cb (PinosContext *context, +get_node_info_cb (struct pw_context *context, SpaResult res, - const PinosNodeInfo *info, + const struct pw_node_info *info, gpointer user_data) { - GstPinosDeviceProvider *self = user_data; + GstPipeWireDeviceProvider *self = user_data; if (info) { GstDevice *dev; @@ -257,11 +257,11 @@ get_node_info_cb (PinosContext *context, } } -static GstPinosDevice * +static GstPipeWireDevice * find_device (GstDeviceProvider *provider, uint32_t id) { GList *item; - GstPinosDevice *dev = NULL; + GstPipeWireDevice *dev = NULL; GST_OBJECT_LOCK (provider); for (item = provider->devices; item; item = item->next) { @@ -278,28 +278,28 @@ find_device (GstDeviceProvider *provider, uint32_t id) } static void -on_context_subscription (PinosListener *listener, - PinosContext *context, - PinosSubscriptionEvent event, - uint32_t type, - uint32_t id) +on_context_subscription (struct pw_listener *listener, + struct pw_context *context, + enum pw_subscription_event event, + uint32_t type, + uint32_t id) { - GstPinosDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPinosDeviceProvider, ctx_subscription); + GstPipeWireDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPipeWireDeviceProvider, ctx_subscription); GstDeviceProvider *provider = GST_DEVICE_PROVIDER (self); - GstPinosDevice *dev; + GstPipeWireDevice *dev; if (type != context->type.node) return; dev = find_device (provider, id); - if (event == PINOS_SUBSCRIPTION_EVENT_NEW) { + if (event == PW_SUBSCRIPTION_EVENT_NEW) { if (dev == NULL) - pinos_context_get_node_info_by_id (context, - id, - get_node_info_cb, - self); - } else if (event == PINOS_SUBSCRIPTION_EVENT_REMOVE) { + pw_context_get_node_info_by_id (context, + id, + get_node_info_cb, + self); + } else if (event == PW_SUBSCRIPTION_EVENT_REMOVE) { if (dev != NULL) { gst_device_provider_device_remove (GST_DEVICE_PROVIDER (self), GST_DEVICE (dev)); @@ -315,9 +315,9 @@ typedef struct { } InfoData; static void -list_node_info_cb (PinosContext *c, +list_node_info_cb (struct pw_context *c, SpaResult res, - const PinosNodeInfo *info, + const struct pw_node_info *info, void *user_data) { InfoData *data = user_data; @@ -329,10 +329,10 @@ list_node_info_cb (PinosContext *c, } static void -get_core_info_cb (PinosContext *c, - SpaResult res, - const PinosCoreInfo *info, - void *user_data) +get_core_info_cb (struct pw_context *c, + SpaResult res, + const struct pw_core_info *info, + void *user_data) { GstDeviceProvider *provider = user_data; const gchar *value; @@ -358,25 +358,25 @@ get_core_info_cb (PinosContext *c, } static GList * -gst_pinos_device_provider_probe (GstDeviceProvider * provider) +gst_pipewire_device_provider_probe (GstDeviceProvider * provider) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); - PinosLoop *l = NULL; - PinosContext *c = NULL; + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider); + struct pw_loop *l = NULL; + struct pw_context *c = NULL; InfoData data; GST_DEBUG_OBJECT (self, "starting probe"); - if (!(l = pinos_loop_new ())) + if (!(l = pw_loop_new ())) return NULL; - if (!(c = pinos_context_new (l, self->client_name, NULL))) + if (!(c = pw_context_new (l, self->client_name, NULL))) goto failed; - pinos_context_connect (c, 0); + pw_context_connect (c, 0); for (;;) { - PinosContextState state; + enum pw_context_state state; state = c->state; @@ -385,103 +385,103 @@ gst_pinos_device_provider_probe (GstDeviceProvider * provider) goto failed; } - if (state == PINOS_CONTEXT_STATE_CONNECTED) + if (state == PW_CONTEXT_STATE_CONNECTED) break; /* Wait until something happens */ - pinos_loop_iterate (l, -1); + pw_loop_iterate (l, -1); } GST_DEBUG_OBJECT (self, "connected"); - pinos_context_get_core_info (c, - get_core_info_cb, - self); + pw_context_get_core_info (c, + get_core_info_cb, + self); data.end = FALSE; data.devices = NULL; - pinos_context_list_node_info (c, - list_node_info_cb, - &data); + pw_context_list_node_info (c, + list_node_info_cb, + &data); for (;;) { if (c->state <= 0) break; if (data.end) break; - pinos_loop_iterate (l, -1); + pw_loop_iterate (l, -1); } - pinos_context_disconnect (c); - pinos_context_destroy (c); - pinos_loop_destroy (l); + pw_context_disconnect (c); + pw_context_destroy (c); + pw_loop_destroy (l); return *data.devices; failed: - pinos_loop_destroy (l); + pw_loop_destroy (l); return NULL; } static void -on_context_state_changed (PinosListener *listener, - PinosContext *context) +on_context_state_changed (struct pw_listener *listener, + struct pw_context *context) { - GstPinosDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPinosDeviceProvider, ctx_state_changed); - PinosContextState state; + GstPipeWireDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPipeWireDeviceProvider, ctx_state_changed); + enum pw_context_state state; state= context->state; GST_DEBUG ("got context state %d", state); switch (state) { - case PINOS_CONTEXT_STATE_CONNECTING: + case PW_CONTEXT_STATE_CONNECTING: break; - case PINOS_CONTEXT_STATE_UNCONNECTED: - case PINOS_CONTEXT_STATE_CONNECTED: + case PW_CONTEXT_STATE_UNCONNECTED: + case PW_CONTEXT_STATE_CONNECTED: break; - case PINOS_CONTEXT_STATE_ERROR: + case PW_CONTEXT_STATE_ERROR: GST_ERROR_OBJECT (self, "context error: %s", context->error); break; } - pinos_thread_main_loop_signal (self->main_loop, FALSE); + pw_thread_main_loop_signal (self->main_loop, FALSE); } static gboolean -gst_pinos_device_provider_start (GstDeviceProvider * provider) +gst_pipewire_device_provider_start (GstDeviceProvider * provider) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider); GST_DEBUG_OBJECT (self, "starting provider"); - self->loop = pinos_loop_new (); + self->loop = pw_loop_new (); - if (!(self->main_loop = pinos_thread_main_loop_new (self->loop, "pinos-device-monitor"))) { - GST_ERROR_OBJECT (self, "Could not create pinos mainloop"); + if (!(self->main_loop = pw_thread_main_loop_new (self->loop, "pipewire-device-monitor"))) { + GST_ERROR_OBJECT (self, "Could not create PipeWire mainloop"); goto failed_main_loop; } - if (pinos_thread_main_loop_start (self->main_loop) != SPA_RESULT_OK) { - GST_ERROR_OBJECT (self, "Could not start pinos mainloop"); + if (pw_thread_main_loop_start (self->main_loop) != SPA_RESULT_OK) { + GST_ERROR_OBJECT (self, "Could not start PipeWire mainloop"); goto failed_start; } - pinos_thread_main_loop_lock (self->main_loop); + pw_thread_main_loop_lock (self->main_loop); - if (!(self->context = pinos_context_new (self->loop, self->client_name, NULL))) { + if (!(self->context = pw_context_new (self->loop, self->client_name, NULL))) { GST_ERROR_OBJECT (self, "Failed to create context"); goto failed_context; } - pinos_signal_add (&self->context->state_changed, + pw_signal_add (&self->context->state_changed, &self->ctx_state_changed, on_context_state_changed); - pinos_signal_add (&self->context->subscription, + pw_signal_add (&self->context->subscription, &self->ctx_subscription, on_context_subscription); - pinos_context_connect (self->context, 0); + pw_context_connect (self->context, 0); for (;;) { - PinosContextState state; + enum pw_context_state state; state = self->context->state; @@ -490,68 +490,68 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider) goto not_running; } - if (state == PINOS_CONTEXT_STATE_CONNECTED) + if (state == PW_CONTEXT_STATE_CONNECTED) break; /* Wait until something happens */ - pinos_thread_main_loop_wait (self->main_loop); + pw_thread_main_loop_wait (self->main_loop); } GST_DEBUG_OBJECT (self, "connected"); - pinos_context_get_core_info (self->context, - get_core_info_cb, - self); - pinos_thread_main_loop_unlock (self->main_loop); + pw_context_get_core_info (self->context, + get_core_info_cb, + self); + pw_thread_main_loop_unlock (self->main_loop); return TRUE; not_running: - pinos_context_destroy (self->context); + pw_context_destroy (self->context); self->context = NULL; failed_context: - pinos_thread_main_loop_unlock (self->main_loop); + pw_thread_main_loop_unlock (self->main_loop); failed_start: - pinos_thread_main_loop_destroy (self->main_loop); + pw_thread_main_loop_destroy (self->main_loop); self->main_loop = NULL; failed_main_loop: - pinos_loop_destroy (self->loop); + pw_loop_destroy (self->loop); self->loop = NULL; return TRUE; } static void -gst_pinos_device_provider_stop (GstDeviceProvider * provider) +gst_pipewire_device_provider_stop (GstDeviceProvider * provider) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider); if (self->context) { - pinos_context_disconnect (self->context); - pinos_context_destroy (self->context); + pw_context_disconnect (self->context); + pw_context_destroy (self->context); self->context = NULL; } if (self->main_loop) { - pinos_thread_main_loop_destroy (self->main_loop); + pw_thread_main_loop_destroy (self->main_loop); self->main_loop = NULL; } if (self->loop) { - pinos_loop_destroy (self->loop); + pw_loop_destroy (self->loop); self->loop = NULL; } } static void -gst_pinos_device_provider_set_property (GObject * object, +gst_pipewire_device_provider_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object); switch (prop_id) { case PROP_CLIENT_NAME: g_free (self->client_name); if (!g_value_get_string (value)) { GST_WARNING_OBJECT (self, - "Empty Pinos client name not allowed. " + "Empty PipeWire client name not allowed. " "Resetting to default value"); - self->client_name = pinos_client_name (); + self->client_name = pw_client_name (); } else self->client_name = g_value_dup_string (value); break; @@ -562,10 +562,10 @@ gst_pinos_device_provider_set_property (GObject * object, } static void -gst_pinos_device_provider_get_property (GObject * object, +gst_pipewire_device_provider_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object); switch (prop_id) { case PROP_CLIENT_NAME: @@ -578,47 +578,47 @@ gst_pinos_device_provider_get_property (GObject * object, } static void -gst_pinos_device_provider_finalize (GObject * object) +gst_pipewire_device_provider_finalize (GObject * object) { - GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object); g_free (self->client_name); - G_OBJECT_CLASS (gst_pinos_device_provider_parent_class)->finalize (object); + G_OBJECT_CLASS (gst_pipewire_device_provider_parent_class)->finalize (object); } static void -gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass) +gst_pipewire_device_provider_class_init (GstPipeWireDeviceProviderClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass); gchar *client_name; - gobject_class->set_property = gst_pinos_device_provider_set_property; - gobject_class->get_property = gst_pinos_device_provider_get_property; - gobject_class->finalize = gst_pinos_device_provider_finalize; + gobject_class->set_property = gst_pipewire_device_provider_set_property; + gobject_class->get_property = gst_pipewire_device_provider_get_property; + gobject_class->finalize = gst_pipewire_device_provider_finalize; - dm_class->probe = gst_pinos_device_provider_probe; - dm_class->start = gst_pinos_device_provider_start; - dm_class->stop = gst_pinos_device_provider_stop; + dm_class->probe = gst_pipewire_device_provider_probe; + dm_class->start = gst_pipewire_device_provider_start; + dm_class->stop = gst_pipewire_device_provider_stop; - client_name = pinos_client_name (); + client_name = pw_client_name (); g_object_class_install_property (gobject_class, PROP_CLIENT_NAME, g_param_spec_string ("client-name", "Client Name", - "The Pinos client_name_to_use", client_name, + "The PipeWire client_name_to_use", client_name, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_MUTABLE_READY)); g_free (client_name); gst_device_provider_class_set_static_metadata (dm_class, - "Pinos Device Provider", "Sink/Source/Audio/Video", - "List and provide Pinos source and sink devices", + "PipeWire Device Provider", "Sink/Source/Audio/Video", + "List and provide PipeWire source and sink devices", "Wim Taymans "); } static void -gst_pinos_device_provider_init (GstPinosDeviceProvider * self) +gst_pipewire_device_provider_init (GstPipeWireDeviceProvider * self) { - self->client_name = pinos_client_name (); + self->client_name = pw_client_name (); } diff --git a/pipewire/gst/gstpipewiredeviceprovider.h b/pipewire/gst/gstpipewiredeviceprovider.h new file mode 100644 index 000000000..6fb54221e --- /dev/null +++ b/pipewire/gst/gstpipewiredeviceprovider.h @@ -0,0 +1,100 @@ +/* GStreamer + * Copyright (C) 2012 Olivier Crete + * (C) 2015 Wim Taymans + * + * pipewiredeviceprovider.h: Device probing and monitoring + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_PIPEWIRE_DEVICE_PROVIDER_H__ +#define __GST_PIPEWIRE_DEVICE_PROVIDER_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +G_BEGIN_DECLS + +typedef struct _GstPipeWireDevice GstPipeWireDevice; +typedef struct _GstPipeWireDeviceClass GstPipeWireDeviceClass; + +#define GST_TYPE_PIPEWIRE_DEVICE (gst_pipewire_device_get_type()) +#define GST_IS_PIPEWIRE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PIPEWIRE_DEVICE)) +#define GST_IS_PIPEWIRE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PIPEWIRE_DEVICE)) +#define GST_PIPEWIRE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PIPEWIRE_DEVICE, GstPipeWireDeviceClass)) +#define GST_PIPEWIRE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PIPEWIRE_DEVICE, GstPipeWireDevice)) +#define GST_PIPEWIRE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstPipeWireDeviceClass)) +#define GST_PIPEWIRE_DEVICE_CAST(obj) ((GstPipeWireDevice *)(obj)) + +typedef enum { + GST_PIPEWIRE_DEVICE_TYPE_UNKNOWN, + GST_PIPEWIRE_DEVICE_TYPE_SOURCE, + GST_PIPEWIRE_DEVICE_TYPE_SINK, +} GstPipeWireDeviceType; + +struct _GstPipeWireDevice { + GstDevice parent; + + GstPipeWireDeviceType type; + uint32_t id; + const gchar *element; +}; + +struct _GstPipeWireDeviceClass { + GstDeviceClass parent_class; +}; + +GType gst_pipewire_device_get_type (void); + +typedef struct _GstPipeWireDeviceProvider GstPipeWireDeviceProvider; +typedef struct _GstPipeWireDeviceProviderClass GstPipeWireDeviceProviderClass; + +#define GST_TYPE_PIPEWIRE_DEVICE_PROVIDER (gst_pipewire_device_provider_get_type()) +#define GST_IS_PIPEWIRE_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PIPEWIRE_DEVICE_PROVIDER)) +#define GST_IS_PIPEWIRE_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PIPEWIRE_DEVICE_PROVIDER)) +#define GST_PIPEWIRE_DEVICE_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PIPEWIRE_DEVICE_PROVIDER, GstPipeWireDeviceProviderClass)) +#define GST_PIPEWIRE_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PIPEWIRE_DEVICE_PROVIDER, GstPipeWireDeviceProvider)) +#define GST_PIPEWIRE_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE_PROVIDER, GstPipeWireDeviceProviderClass)) +#define GST_PIPEWIRE_DEVICE_PROVIDER_CAST(obj) ((GstPipeWireDeviceProvider *)(obj)) + +struct _GstPipeWireDeviceProvider { + GstDeviceProvider parent; + + gchar *client_name; + + struct pw_loop *loop; + struct pw_thread_main_loop *main_loop; + + struct pw_context *context; + struct pw_listener ctx_state_changed; + struct pw_listener ctx_subscription; +}; + +struct _GstPipeWireDeviceProviderClass { + GstDeviceProviderClass parent_class; +}; + +GType gst_pipewire_device_provider_get_type (void); + +G_END_DECLS + +#endif /* __GST_PIPEWIRE_DEVICE_PROVIDER_H__ */ diff --git a/pinos/gst/gstpinosformat.c b/pipewire/gst/gstpipewireformat.c similarity index 99% rename from pinos/gst/gstpinosformat.c rename to pipewire/gst/gstpipewireformat.c index c9edc7795..f553d1f51 100644 --- a/pinos/gst/gstpinosformat.c +++ b/pipewire/gst/gstpipewireformat.c @@ -29,7 +29,7 @@ #include #include -#include "gstpinosformat.h" +#include "gstpipewireformat.h" typedef struct { const char *name; diff --git a/pinos/gst/gstpinosformat.h b/pipewire/gst/gstpipewireformat.h similarity index 94% rename from pinos/gst/gstpinosformat.h rename to pipewire/gst/gstpipewireformat.h index 11219f5d9..74b4833d2 100644 --- a/pinos/gst/gstpinosformat.h +++ b/pipewire/gst/gstpipewireformat.h @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef _GST_PINOS_FORMAT_H_ -#define _GST_PINOS_FORMAT_H_ +#ifndef _GST_PIPEWIRE_FORMAT_H_ +#define _GST_PIPEWIRE_FORMAT_H_ #include diff --git a/pinos/gst/gstpinospool.c b/pipewire/gst/gstpipewirepool.c similarity index 72% rename from pinos/gst/gstpinospool.c rename to pipewire/gst/gstpipewirepool.c index 6f81d30e8..eb36f957f 100644 --- a/pinos/gst/gstpinospool.c +++ b/pipewire/gst/gstpipewirepool.c @@ -23,12 +23,12 @@ #include -#include "gstpinospool.h" +#include "gstpipewirepool.h" -GST_DEBUG_CATEGORY_STATIC (gst_pinos_pool_debug_category); -#define GST_CAT_DEFAULT gst_pinos_pool_debug_category +GST_DEBUG_CATEGORY_STATIC (gst_pipewire_pool_debug_category); +#define GST_CAT_DEFAULT gst_pipewire_pool_debug_category -G_DEFINE_TYPE (GstPinosPool, gst_pinos_pool, GST_TYPE_BUFFER_POOL); +G_DEFINE_TYPE (GstPipeWirePool, gst_pipewire_pool, GST_TYPE_BUFFER_POOL); enum { @@ -40,20 +40,20 @@ enum static guint pool_signals[LAST_SIGNAL] = { 0 }; -GstPinosPool * -gst_pinos_pool_new (void) +GstPipeWirePool * +gst_pipewire_pool_new (void) { - GstPinosPool *pool; + GstPipeWirePool *pool; - pool = g_object_new (GST_TYPE_PINOS_POOL, NULL); + pool = g_object_new (GST_TYPE_PIPEWIRE_POOL, NULL); return pool; } gboolean -gst_pinos_pool_add_buffer (GstPinosPool *pool, GstBuffer *buffer) +gst_pipewire_pool_add_buffer (GstPipeWirePool *pool, GstBuffer *buffer) { - g_return_val_if_fail (GST_IS_PINOS_POOL (pool), FALSE); + g_return_val_if_fail (GST_IS_PIPEWIRE_POOL (pool), FALSE); g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); GST_OBJECT_LOCK (pool); @@ -65,11 +65,11 @@ gst_pinos_pool_add_buffer (GstPinosPool *pool, GstBuffer *buffer) } gboolean -gst_pinos_pool_remove_buffer (GstPinosPool *pool, GstBuffer *buffer) +gst_pipewire_pool_remove_buffer (GstPipeWirePool *pool, GstBuffer *buffer) { gboolean res; - g_return_val_if_fail (GST_IS_PINOS_POOL (pool), FALSE); + g_return_val_if_fail (GST_IS_PIPEWIRE_POOL (pool), FALSE); g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); GST_OBJECT_LOCK (pool); @@ -83,7 +83,7 @@ static GstFlowReturn acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer, GstBufferPoolAcquireParams * params) { - GstPinosPool *p = GST_PINOS_POOL (pool); + GstPipeWirePool *p = GST_PIPEWIRE_POOL (pool); GST_OBJECT_LOCK (pool); while (TRUE) { @@ -112,7 +112,7 @@ flushing: static void flush_start (GstBufferPool * pool) { - GstPinosPool *p = GST_PINOS_POOL (pool); + GstPipeWirePool *p = GST_PIPEWIRE_POOL (pool); GST_DEBUG ("flush start"); GST_OBJECT_LOCK (pool); @@ -123,7 +123,7 @@ flush_start (GstBufferPool * pool) static void release_buffer (GstBufferPool * pool, GstBuffer *buffer) { - GstPinosPool *p = GST_PINOS_POOL (pool); + GstPipeWirePool *p = GST_PIPEWIRE_POOL (pool); GST_DEBUG ("release buffer %p", buffer); GST_OBJECT_LOCK (pool); @@ -140,22 +140,22 @@ do_start (GstBufferPool * pool) } static void -gst_pinos_pool_finalize (GObject * object) +gst_pipewire_pool_finalize (GObject * object) { - GstPinosPool *pool = GST_PINOS_POOL (object); + GstPipeWirePool *pool = GST_PIPEWIRE_POOL (object); GST_DEBUG_OBJECT (pool, "finalize"); - G_OBJECT_CLASS (gst_pinos_pool_parent_class)->finalize (object); + G_OBJECT_CLASS (gst_pipewire_pool_parent_class)->finalize (object); } static void -gst_pinos_pool_class_init (GstPinosPoolClass * klass) +gst_pipewire_pool_class_init (GstPipeWirePoolClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstBufferPoolClass *bufferpool_class = GST_BUFFER_POOL_CLASS (klass); - gobject_class->finalize = gst_pinos_pool_finalize; + gobject_class->finalize = gst_pipewire_pool_finalize; bufferpool_class->start = do_start; bufferpool_class->flush_start = flush_start; @@ -166,12 +166,12 @@ gst_pinos_pool_class_init (GstPinosPoolClass * klass) g_signal_new ("activated", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE); - GST_DEBUG_CATEGORY_INIT (gst_pinos_pool_debug_category, "pinospool", 0, - "debug category for pinospool object"); + GST_DEBUG_CATEGORY_INIT (gst_pipewire_pool_debug_category, "pipewirepool", 0, + "debug category for pipewirepool object"); } static void -gst_pinos_pool_init (GstPinosPool * pool) +gst_pipewire_pool_init (GstPipeWirePool * pool) { g_cond_init (&pool->cond); g_queue_init (&pool->available); diff --git a/pipewire/gst/gstpipewirepool.h b/pipewire/gst/gstpipewirepool.h new file mode 100644 index 000000000..617eb8b75 --- /dev/null +++ b/pipewire/gst/gstpipewirepool.h @@ -0,0 +1,66 @@ +/* GStreamer + * Copyright (C) <2016> Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_PIPEWIRE_POOL_H__ +#define __GST_PIPEWIRE_POOL_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_PIPEWIRE_POOL \ + (gst_pipewire_pool_get_type()) +#define GST_PIPEWIRE_POOL(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PIPEWIRE_POOL,GstPipeWirePool)) +#define GST_PIPEWIRE_POOL_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PIPEWIRE_POOL,GstPipeWirePoolClass)) +#define GST_IS_PIPEWIRE_POOL(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PIPEWIRE_POOL)) +#define GST_IS_PIPEWIRE_POOL_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PIPEWIRE_POOL)) +#define GST_PIPEWIRE_POOL_GET_CLASS(klass) \ + (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_PIPEWIRE_POOL, GstPipeWirePoolClass)) + +typedef struct _GstPipeWirePool GstPipeWirePool; +typedef struct _GstPipeWirePoolClass GstPipeWirePoolClass; + +struct _GstPipeWirePool { + GstBufferPool parent; + + struct pw_stream *stream; + GQueue available; + GCond cond; +}; + +struct _GstPipeWirePoolClass { + GstBufferPoolClass parent_class; +}; + +GType gst_pipewire_pool_get_type (void); + +GstPipeWirePool * gst_pipewire_pool_new (void); + +gboolean gst_pipewire_pool_add_buffer (GstPipeWirePool *pool, GstBuffer *buffer); +gboolean gst_pipewire_pool_remove_buffer (GstPipeWirePool *pool, GstBuffer *buffer); + +G_END_DECLS + +#endif /* __GST_PIPEWIRE_POOL_H__ */ diff --git a/pinos/gst/gstpinossink.c b/pipewire/gst/gstpipewiresink.c similarity index 56% rename from pinos/gst/gstpinossink.c rename to pipewire/gst/gstpipewiresink.c index 91edacb0a..8e68fbff8 100644 --- a/pinos/gst/gstpinossink.c +++ b/pipewire/gst/gstpipewiresink.c @@ -18,20 +18,20 @@ */ /** - * SECTION:element-pinossink + * SECTION:element-pipewiresink * * * Example launch line * |[ - * gst-launch -v videotestsrc ! pinossink - * ]| Sends a test video source to pinos + * gst-launch -v videotestsrc ! pipewiresink + * ]| Sends a test video source to PipeWire * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "gstpinossink.h" +#include "gstpipewiresink.h" #include #include @@ -45,14 +45,14 @@ #include -#include "gstpinosformat.h" +#include "gstpipewireformat.h" static GQuark process_mem_data_quark; -GST_DEBUG_CATEGORY_STATIC (pinos_sink_debug); -#define GST_CAT_DEFAULT pinos_sink_debug +GST_DEBUG_CATEGORY_STATIC (pipewire_sink_debug); +#define GST_CAT_DEFAULT pipewire_sink_debug -#define DEFAULT_PROP_MODE GST_PINOS_SINK_MODE_DEFAULT +#define DEFAULT_PROP_MODE GST_PIPEWIRE_SINK_MODE_DEFAULT enum { @@ -64,19 +64,19 @@ enum }; GType -gst_pinos_sink_mode_get_type (void) +gst_pipewire_sink_mode_get_type (void) { static volatile gsize mode_type = 0; static const GEnumValue mode[] = { - {GST_PINOS_SINK_MODE_DEFAULT, "GST_PINOS_SINK_MODE_DEFAULT", "default"}, - {GST_PINOS_SINK_MODE_RENDER, "GST_PINOS_SINK_MODE_RENDER", "render"}, - {GST_PINOS_SINK_MODE_PROVIDE, "GST_PINOS_SINK_MODE_PROVIDE", "provide"}, + {GST_PIPEWIRE_SINK_MODE_DEFAULT, "GST_PIPEWIRE_SINK_MODE_DEFAULT", "default"}, + {GST_PIPEWIRE_SINK_MODE_RENDER, "GST_PIPEWIRE_SINK_MODE_RENDER", "render"}, + {GST_PIPEWIRE_SINK_MODE_PROVIDE, "GST_PIPEWIRE_SINK_MODE_PROVIDE", "provide"}, {0, NULL, NULL}, }; if (g_once_init_enter (&mode_type)) { GType tmp = - g_enum_register_static ("GstPinosSinkMode", mode); + g_enum_register_static ("GstPipeWireSinkMode", mode); g_once_init_leave (&mode_type, tmp); } @@ -84,69 +84,67 @@ gst_pinos_sink_mode_get_type (void) } -#define PINOSS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) - -static GstStaticPadTemplate gst_pinos_sink_template = +static GstStaticPadTemplate gst_pipewire_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY ); -#define gst_pinos_sink_parent_class parent_class -G_DEFINE_TYPE (GstPinosSink, gst_pinos_sink, GST_TYPE_BASE_SINK); +#define gst_pipewire_sink_parent_class parent_class +G_DEFINE_TYPE (GstPipeWireSink, gst_pipewire_sink, GST_TYPE_BASE_SINK); -static void gst_pinos_sink_set_property (GObject * object, guint prop_id, +static void gst_pipewire_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_pinos_sink_get_property (GObject * object, guint prop_id, +static void gst_pipewire_sink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static GstStateChangeReturn -gst_pinos_sink_change_state (GstElement * element, GstStateChange transition); +gst_pipewire_sink_change_state (GstElement * element, GstStateChange transition); -static gboolean gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps); -static GstCaps *gst_pinos_sink_sink_fixate (GstBaseSink * bsink, +static gboolean gst_pipewire_sink_setcaps (GstBaseSink * bsink, GstCaps * caps); +static GstCaps *gst_pipewire_sink_sink_fixate (GstBaseSink * bsink, GstCaps * caps); -static GstFlowReturn gst_pinos_sink_render (GstBaseSink * psink, +static GstFlowReturn gst_pipewire_sink_render (GstBaseSink * psink, GstBuffer * buffer); -static gboolean gst_pinos_sink_start (GstBaseSink * basesink); -static gboolean gst_pinos_sink_stop (GstBaseSink * basesink); +static gboolean gst_pipewire_sink_start (GstBaseSink * basesink); +static gboolean gst_pipewire_sink_stop (GstBaseSink * basesink); static void -gst_pinos_sink_finalize (GObject * object) +gst_pipewire_sink_finalize (GObject * object) { - GstPinosSink *pinossink = GST_PINOS_SINK (object); + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (object); - g_object_unref (pinossink->pool); + g_object_unref (pwsink->pool); - pinos_thread_main_loop_destroy (pinossink->main_loop); - pinossink->main_loop = NULL; + pw_thread_main_loop_destroy (pwsink->main_loop); + pwsink->main_loop = NULL; - pinos_loop_destroy (pinossink->loop); - pinossink->loop = NULL; + pw_loop_destroy (pwsink->loop); + pwsink->loop = NULL; - if (pinossink->properties) - gst_structure_free (pinossink->properties); - g_object_unref (pinossink->allocator); - g_free (pinossink->path); - g_free (pinossink->client_name); - g_hash_table_unref (pinossink->buf_ids); + if (pwsink->properties) + gst_structure_free (pwsink->properties); + g_object_unref (pwsink->allocator); + g_free (pwsink->path); + g_free (pwsink->client_name); + g_hash_table_unref (pwsink->buf_ids); G_OBJECT_CLASS (parent_class)->finalize (object); } static gboolean -gst_pinos_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query) +gst_pipewire_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query) { - GstPinosSink *pinossink = GST_PINOS_SINK (bsink); + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (bsink); - gst_query_add_allocation_pool (query, GST_BUFFER_POOL_CAST (pinossink->pool), 0, 0, 0); + gst_query_add_allocation_pool (query, GST_BUFFER_POOL_CAST (pwsink->pool), 0, 0, 0); return TRUE; } static void -gst_pinos_sink_class_init (GstPinosSinkClass * klass) +gst_pipewire_sink_class_init (GstPipeWireSinkClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; @@ -156,9 +154,9 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass) gstelement_class = (GstElementClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass; - gobject_class->finalize = gst_pinos_sink_finalize; - gobject_class->set_property = gst_pinos_sink_set_property; - gobject_class->get_property = gst_pinos_sink_get_property; + gobject_class->finalize = gst_pipewire_sink_finalize; + gobject_class->set_property = gst_pipewire_sink_set_property; + gobject_class->get_property = gst_pipewire_sink_get_property; g_object_class_install_property (gobject_class, PROP_PATH, @@ -182,7 +180,7 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass) PROP_STREAM_PROPERTIES, g_param_spec_boxed ("stream-properties", "Stream properties", - "List of pinos stream properties", + "List of PipeWire stream properties", GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -192,31 +190,31 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass) g_param_spec_enum ("mode", "Mode", "The mode to operate in", - GST_TYPE_PINOS_SINK_MODE, + GST_TYPE_PIPEWIRE_SINK_MODE, DEFAULT_PROP_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - gstelement_class->change_state = gst_pinos_sink_change_state; + gstelement_class->change_state = gst_pipewire_sink_change_state; gst_element_class_set_static_metadata (gstelement_class, - "Pinos sink", "Sink/Video", - "Send video to Pinos", "Wim Taymans "); + "PipeWire sink", "Sink/Video", + "Send video to PipeWire", "Wim Taymans "); gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_pinos_sink_template)); + gst_static_pad_template_get (&gst_pipewire_sink_template)); - gstbasesink_class->set_caps = gst_pinos_sink_setcaps; - gstbasesink_class->fixate = gst_pinos_sink_sink_fixate; - gstbasesink_class->propose_allocation = gst_pinos_sink_propose_allocation; - gstbasesink_class->start = gst_pinos_sink_start; - gstbasesink_class->stop = gst_pinos_sink_stop; - gstbasesink_class->render = gst_pinos_sink_render; + gstbasesink_class->set_caps = gst_pipewire_sink_setcaps; + gstbasesink_class->fixate = gst_pipewire_sink_sink_fixate; + gstbasesink_class->propose_allocation = gst_pipewire_sink_propose_allocation; + gstbasesink_class->start = gst_pipewire_sink_start; + gstbasesink_class->stop = gst_pipewire_sink_stop; + gstbasesink_class->render = gst_pipewire_sink_render; - GST_DEBUG_CATEGORY_INIT (pinos_sink_debug, "pinossink", 0, - "Pinos Sink"); + GST_DEBUG_CATEGORY_INIT (pipewire_sink_debug, "pipewiresink", 0, + "PipeWire Sink"); - process_mem_data_quark = g_quark_from_static_string ("GstPinosSinkProcessMemQuark"); + process_mem_data_quark = g_quark_from_static_string ("GstPipeWireSinkProcessMemQuark"); } @@ -235,9 +233,9 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass) SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \ SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__) static void -pool_activated (GstPinosPool *pool, GstPinosSink *sink) +pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink) { - PinosContext *ctx = sink->stream->context; + struct pw_context *ctx = sink->stream->context; GstStructure *config; GstCaps *caps; guint size; @@ -284,15 +282,15 @@ pool_activated (GstPinosPool *pool, GstPinosSink *sink) PROP (&f[1], ctx->type.param_alloc_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16)); port_params[2] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam); - pinos_stream_finish_format (sink->stream, SPA_RESULT_OK, port_params, 2); + pw_stream_finish_format (sink->stream, SPA_RESULT_OK, port_params, 2); } static void -gst_pinos_sink_init (GstPinosSink * sink) +gst_pipewire_sink_init (GstPipeWireSink * sink) { sink->allocator = gst_fd_allocator_new (); - sink->pool = gst_pinos_pool_new (); - sink->client_name = pinos_client_name(); + sink->pool = gst_pipewire_pool_new (); + sink->client_name = pw_client_name(); sink->mode = DEFAULT_PROP_MODE; g_signal_connect (sink->pool, "activated", G_CALLBACK (pool_activated), sink); @@ -302,13 +300,13 @@ gst_pinos_sink_init (GstPinosSink * sink) g_queue_init (&sink->queue); - sink->loop = pinos_loop_new (); - sink->main_loop = pinos_thread_main_loop_new (sink->loop, "pinos-sink-loop"); + sink->loop = pw_loop_new (); + sink->main_loop = pw_thread_main_loop_new (sink->loop, "pipewire-sink-loop"); GST_DEBUG ("loop %p %p", sink->loop, sink->main_loop); } static GstCaps * -gst_pinos_sink_sink_fixate (GstBaseSink * bsink, GstCaps * caps) +gst_pipewire_sink_sink_fixate (GstBaseSink * bsink, GstCaps * caps) { GstStructure *structure; @@ -351,31 +349,31 @@ gst_pinos_sink_sink_fixate (GstBaseSink * bsink, GstCaps * caps) } static void -gst_pinos_sink_set_property (GObject * object, guint prop_id, +gst_pipewire_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstPinosSink *pinossink = GST_PINOS_SINK (object); + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (object); switch (prop_id) { case PROP_PATH: - g_free (pinossink->path); - pinossink->path = g_value_dup_string (value); + g_free (pwsink->path); + pwsink->path = g_value_dup_string (value); break; case PROP_CLIENT_NAME: - g_free (pinossink->client_name); - pinossink->client_name = g_value_dup_string (value); + g_free (pwsink->client_name); + pwsink->client_name = g_value_dup_string (value); break; case PROP_STREAM_PROPERTIES: - if (pinossink->properties) - gst_structure_free (pinossink->properties); - pinossink->properties = + if (pwsink->properties) + gst_structure_free (pwsink->properties); + pwsink->properties = gst_structure_copy (gst_value_get_structure (value)); break; case PROP_MODE: - pinossink->mode = g_value_get_enum (value); + pwsink->mode = g_value_get_enum (value); break; default: @@ -385,26 +383,26 @@ gst_pinos_sink_set_property (GObject * object, guint prop_id, } static void -gst_pinos_sink_get_property (GObject * object, guint prop_id, +gst_pipewire_sink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstPinosSink *pinossink = GST_PINOS_SINK (object); + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (object); switch (prop_id) { case PROP_PATH: - g_value_set_string (value, pinossink->path); + g_value_set_string (value, pwsink->path); break; case PROP_CLIENT_NAME: - g_value_set_string (value, pinossink->client_name); + g_value_set_string (value, pwsink->client_name); break; case PROP_STREAM_PROPERTIES: - gst_value_set_structure (value, pinossink->properties); + gst_value_set_structure (value, pwsink->properties); break; case PROP_MODE: - g_value_set_enum (value, pinossink->mode); + g_value_set_enum (value, pwsink->mode); break; default: @@ -414,7 +412,7 @@ gst_pinos_sink_get_property (GObject * object, guint prop_id, } typedef struct { - GstPinosSink *sink; + GstPipeWireSink *sink; guint id; SpaBuffer *buf; SpaMetaHeader *header; @@ -432,26 +430,26 @@ process_mem_data_destroy (gpointer user_data) } static void -on_add_buffer (PinosListener *listener, - PinosStream *stream, +on_add_buffer (struct pw_listener *listener, + struct pw_stream *stream, uint32_t id) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_add_buffer); + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_add_buffer); SpaBuffer *b; GstBuffer *buf; uint32_t i; ProcessMemData data; - GST_LOG_OBJECT (pinossink, "add buffer"); + GST_LOG_OBJECT (pwsink, "add buffer"); - if (!(b = pinos_stream_peek_buffer (pinossink->stream, id))) { + if (!(b = pw_stream_peek_buffer (pwsink->stream, id))) { g_warning ("failed to peek buffer"); return; } buf = gst_buffer_new (); - data.sink = gst_object_ref (pinossink); + data.sink = gst_object_ref (pwsink); data.id = id; data.buf = b; data.header = spa_buffer_find_meta (b, stream->context->type.meta.Header); @@ -462,7 +460,7 @@ on_add_buffer (PinosListener *listener, if (d->type == stream->context->type.data.MemFd || d->type == stream->context->type.data.DmaBuf) { - gmem = gst_fd_allocator_alloc (pinossink->allocator, dup (d->fd), + gmem = gst_fd_allocator_alloc (pwsink->allocator, dup (d->fd), d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE); gst_memory_resize (gmem, d->chunk->offset + d->mapoffset, d->chunk->size); data.offset = d->mapoffset; @@ -481,61 +479,61 @@ on_add_buffer (PinosListener *listener, g_slice_dup (ProcessMemData, &data), process_mem_data_destroy); - gst_pinos_pool_add_buffer (pinossink->pool, buf); - g_hash_table_insert (pinossink->buf_ids, GINT_TO_POINTER (id), buf); + gst_pipewire_pool_add_buffer (pwsink->pool, buf); + g_hash_table_insert (pwsink->buf_ids, GINT_TO_POINTER (id), buf); - pinos_thread_main_loop_signal (pinossink->main_loop, FALSE); + pw_thread_main_loop_signal (pwsink->main_loop, FALSE); } static void -on_remove_buffer (PinosListener *listener, - PinosStream *stream, +on_remove_buffer (struct pw_listener *listener, + struct pw_stream *stream, uint32_t id) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_remove_buffer); + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_remove_buffer); GstBuffer *buf; - GST_LOG_OBJECT (pinossink, "remove buffer"); - buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id)); + GST_LOG_OBJECT (pwsink, "remove buffer"); + buf = g_hash_table_lookup (pwsink->buf_ids, GINT_TO_POINTER (id)); if (buf) { GST_MINI_OBJECT_CAST (buf)->dispose = NULL; - if (!gst_pinos_pool_remove_buffer (pinossink->pool, buf)) + if (!gst_pipewire_pool_remove_buffer (pwsink->pool, buf)) gst_buffer_ref (buf); - if (g_queue_remove (&pinossink->queue, buf)) + if (g_queue_remove (&pwsink->queue, buf)) gst_buffer_unref (buf); - g_hash_table_remove (pinossink->buf_ids, GINT_TO_POINTER (id)); + g_hash_table_remove (pwsink->buf_ids, GINT_TO_POINTER (id)); } } static void -on_new_buffer (PinosListener *listener, - PinosStream *stream, +on_new_buffer (struct pw_listener *listener, + struct pw_stream *stream, uint32_t id) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_new_buffer); + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_new_buffer); GstBuffer *buf; - GST_LOG_OBJECT (pinossink, "got new buffer %u", id); - if (pinossink->stream == NULL) { - GST_LOG_OBJECT (pinossink, "no stream"); + GST_LOG_OBJECT (pwsink, "got new buffer %u", id); + if (pwsink->stream == NULL) { + GST_LOG_OBJECT (pwsink, "no stream"); return; } - buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id)); + buf = g_hash_table_lookup (pwsink->buf_ids, GINT_TO_POINTER (id)); if (buf) { - pinos_thread_main_loop_signal (pinossink->main_loop, FALSE); + pw_thread_main_loop_signal (pwsink->main_loop, FALSE); } } static void -do_send_buffer (GstPinosSink *pinossink) +do_send_buffer (GstPipeWireSink *pwsink) { GstBuffer *buffer; ProcessMemData *data; gboolean res; guint i; - buffer = g_queue_pop_head (&pinossink->queue); + buffer = g_queue_pop_head (&pwsink->queue); if (buffer == NULL) { GST_WARNING ("out of buffers"); return; @@ -556,148 +554,148 @@ do_send_buffer (GstPinosSink *pinossink) d->chunk->size = mem->size; } - if (!(res = pinos_stream_send_buffer (pinossink->stream, data->id))) { + if (!(res = pw_stream_send_buffer (pwsink->stream, data->id))) { g_warning ("can't send buffer"); - pinos_thread_main_loop_signal (pinossink->main_loop, FALSE); + pw_thread_main_loop_signal (pwsink->main_loop, FALSE); } else - pinossink->need_ready--; + pwsink->need_ready--; gst_buffer_unref (buffer); } static void -on_need_buffer (PinosListener *listener, - PinosStream *stream) +on_need_buffer (struct pw_listener *listener, + struct pw_stream *stream) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_need_buffer); + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_need_buffer); - pinossink->need_ready++; - GST_DEBUG ("need buffer %u", pinossink->need_ready); - do_send_buffer (pinossink); + pwsink->need_ready++; + GST_DEBUG ("need buffer %u", pwsink->need_ready); + do_send_buffer (pwsink); } static void -on_state_changed (PinosListener *listener, - PinosStream *stream) +on_state_changed (struct pw_listener *listener, + struct pw_stream *stream) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_state_changed); - PinosStreamState state; + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_state_changed); + enum pw_stream_state state; state = stream->state; GST_DEBUG ("got stream state %d", state); switch (state) { - case PINOS_STREAM_STATE_UNCONNECTED: - case PINOS_STREAM_STATE_CONNECTING: - case PINOS_STREAM_STATE_CONFIGURE: - case PINOS_STREAM_STATE_READY: - case PINOS_STREAM_STATE_PAUSED: - case PINOS_STREAM_STATE_STREAMING: + case PW_STREAM_STATE_UNCONNECTED: + case PW_STREAM_STATE_CONNECTING: + case PW_STREAM_STATE_CONFIGURE: + case PW_STREAM_STATE_READY: + case PW_STREAM_STATE_PAUSED: + case PW_STREAM_STATE_STREAMING: break; - case PINOS_STREAM_STATE_ERROR: - GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED, + case PW_STREAM_STATE_ERROR: + GST_ELEMENT_ERROR (pwsink, RESOURCE, FAILED, ("stream error: %s", stream->error), (NULL)); break; } - pinos_thread_main_loop_signal (pinossink->main_loop, FALSE); + pw_thread_main_loop_signal (pwsink->main_loop, FALSE); } static void -on_format_changed (PinosListener *listener, - PinosStream *stream, +on_format_changed (struct pw_listener *listener, + struct pw_stream *stream, SpaFormat *format) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, stream_format_changed); + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, stream_format_changed); - if (gst_buffer_pool_is_active (GST_BUFFER_POOL_CAST (pinossink->pool))) - pool_activated (pinossink->pool, pinossink); + if (gst_buffer_pool_is_active (GST_BUFFER_POOL_CAST (pwsink->pool))) + pool_activated (pwsink->pool, pwsink); } static gboolean -gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) +gst_pipewire_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) { - GstPinosSink *pinossink; + GstPipeWireSink *pwsink; GPtrArray *possible; - PinosStreamState state; + enum pw_stream_state state; gboolean res = FALSE; - pinossink = GST_PINOS_SINK (bsink); + pwsink = GST_PIPEWIRE_SINK (bsink); possible = gst_caps_to_format_all (caps); - pinos_thread_main_loop_lock (pinossink->main_loop); - state = pinossink->stream->state; + pw_thread_main_loop_lock (pwsink->main_loop); + state = pwsink->stream->state; - if (state == PINOS_STREAM_STATE_ERROR) + if (state == PW_STREAM_STATE_ERROR) goto start_error; - if (state == PINOS_STREAM_STATE_UNCONNECTED) { - PinosStreamFlags flags = 0; + if (state == PW_STREAM_STATE_UNCONNECTED) { + enum pw_stream_flags flags = 0; - if (pinossink->mode != GST_PINOS_SINK_MODE_PROVIDE) - flags |= PINOS_STREAM_FLAG_AUTOCONNECT; + if (pwsink->mode != GST_PIPEWIRE_SINK_MODE_PROVIDE) + flags |= PW_STREAM_FLAG_AUTOCONNECT; - pinos_stream_connect (pinossink->stream, - PINOS_DIRECTION_OUTPUT, - PINOS_STREAM_MODE_BUFFER, - pinossink->path, + pw_stream_connect (pwsink->stream, + PW_DIRECTION_OUTPUT, + PW_STREAM_MODE_BUFFER, + pwsink->path, flags, possible->len, (SpaFormat **) possible->pdata); while (TRUE) { - state = pinossink->stream->state; + state = pwsink->stream->state; - if (state == PINOS_STREAM_STATE_CONFIGURE) + if (state == PW_STREAM_STATE_CONFIGURE) break; - if (state == PINOS_STREAM_STATE_ERROR) + if (state == PW_STREAM_STATE_ERROR) goto start_error; - pinos_thread_main_loop_wait (pinossink->main_loop); + pw_thread_main_loop_wait (pwsink->main_loop); } } res = TRUE; - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); - pinossink->negotiated = res; + pwsink->negotiated = res; return res; start_error: { GST_ERROR ("could not start stream"); - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); g_ptr_array_unref (possible); return FALSE; } } static GstFlowReturn -gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer) +gst_pipewire_sink_render (GstBaseSink * bsink, GstBuffer * buffer) { - GstPinosSink *pinossink; + GstPipeWireSink *pwsink; GstFlowReturn res = GST_FLOW_OK; - pinossink = GST_PINOS_SINK (bsink); + pwsink = GST_PIPEWIRE_SINK (bsink); - if (!pinossink->negotiated) + if (!pwsink->negotiated) goto not_negotiated; - pinos_thread_main_loop_lock (pinossink->main_loop); - if (pinossink->stream->state != PINOS_STREAM_STATE_STREAMING) + pw_thread_main_loop_lock (pwsink->main_loop); + if (pwsink->stream->state != PW_STREAM_STATE_STREAMING) goto done; - if (buffer->pool != GST_BUFFER_POOL_CAST (pinossink->pool)) { + if (buffer->pool != GST_BUFFER_POOL_CAST (pwsink->pool)) { GstBuffer *b = NULL; GstMapInfo info = { 0, }; - if (!gst_buffer_pool_is_active (GST_BUFFER_POOL_CAST (pinossink->pool))) - gst_buffer_pool_set_active (GST_BUFFER_POOL_CAST (pinossink->pool), TRUE); + if (!gst_buffer_pool_is_active (GST_BUFFER_POOL_CAST (pwsink->pool))) + gst_buffer_pool_set_active (GST_BUFFER_POOL_CAST (pwsink->pool), TRUE); - if ((res = gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL_CAST (pinossink->pool), &b, NULL)) != GST_FLOW_OK) + if ((res = gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL_CAST (pwsink->pool), &b, NULL)) != GST_FLOW_OK) goto done; gst_buffer_map (b, &info, GST_MAP_WRITE); @@ -709,13 +707,13 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer) gst_buffer_ref (buffer); GST_DEBUG ("push buffer in queue"); - g_queue_push_tail (&pinossink->queue, buffer); + g_queue_push_tail (&pwsink->queue, buffer); - if (pinossink->need_ready && pinossink->mode == GST_PINOS_SINK_MODE_PROVIDE) - do_send_buffer (pinossink); + if (pwsink->need_ready && pwsink->mode == GST_PIPEWIRE_SINK_MODE_PROVIDE) + do_send_buffer (pwsink); done: - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); return res; @@ -730,177 +728,177 @@ copy_properties (GQuark field_id, const GValue *value, gpointer user_data) { - PinosProperties *properties = user_data; + struct pw_properties *properties = user_data; if (G_VALUE_HOLDS_STRING (value)) - pinos_properties_set (properties, - g_quark_to_string (field_id), - g_value_get_string (value)); + pw_properties_set (properties, + g_quark_to_string (field_id), + g_value_get_string (value)); return TRUE; } static gboolean -gst_pinos_sink_start (GstBaseSink * basesink) +gst_pipewire_sink_start (GstBaseSink * basesink) { - GstPinosSink *pinossink = GST_PINOS_SINK (basesink); - PinosProperties *props; + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (basesink); + struct pw_properties *props; - pinossink->negotiated = FALSE; + pwsink->negotiated = FALSE; - if (pinossink->properties) { - props = pinos_properties_new (NULL, NULL); - gst_structure_foreach (pinossink->properties, copy_properties, props); + if (pwsink->properties) { + props = pw_properties_new (NULL, NULL); + gst_structure_foreach (pwsink->properties, copy_properties, props); } else { props = NULL; } - pinos_thread_main_loop_lock (pinossink->main_loop); - pinossink->stream = pinos_stream_new (pinossink->ctx, pinossink->client_name, props); - pinossink->pool->stream = pinossink->stream; + pw_thread_main_loop_lock (pwsink->main_loop); + pwsink->stream = pw_stream_new (pwsink->ctx, pwsink->client_name, props); + pwsink->pool->stream = pwsink->stream; - pinos_signal_add (&pinossink->stream->state_changed, &pinossink->stream_state_changed, on_state_changed); - pinos_signal_add (&pinossink->stream->format_changed, &pinossink->stream_format_changed, on_format_changed); - pinos_signal_add (&pinossink->stream->add_buffer, &pinossink->stream_add_buffer, on_add_buffer); - pinos_signal_add (&pinossink->stream->remove_buffer, &pinossink->stream_remove_buffer, on_remove_buffer); - pinos_signal_add (&pinossink->stream->new_buffer, &pinossink->stream_new_buffer, on_new_buffer); - pinos_signal_add (&pinossink->stream->need_buffer, &pinossink->stream_need_buffer, on_need_buffer); - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_signal_add (&pwsink->stream->state_changed, &pwsink->stream_state_changed, on_state_changed); + pw_signal_add (&pwsink->stream->format_changed, &pwsink->stream_format_changed, on_format_changed); + pw_signal_add (&pwsink->stream->add_buffer, &pwsink->stream_add_buffer, on_add_buffer); + pw_signal_add (&pwsink->stream->remove_buffer, &pwsink->stream_remove_buffer, on_remove_buffer); + pw_signal_add (&pwsink->stream->new_buffer, &pwsink->stream_new_buffer, on_new_buffer); + pw_signal_add (&pwsink->stream->need_buffer, &pwsink->stream_need_buffer, on_need_buffer); + pw_thread_main_loop_unlock (pwsink->main_loop); return TRUE; } static gboolean -gst_pinos_sink_stop (GstBaseSink * basesink) +gst_pipewire_sink_stop (GstBaseSink * basesink) { - GstPinosSink *pinossink = GST_PINOS_SINK (basesink); + GstPipeWireSink *pwsink = GST_PIPEWIRE_SINK (basesink); - pinos_thread_main_loop_lock (pinossink->main_loop); - if (pinossink->stream) { - pinos_stream_disconnect (pinossink->stream); - pinos_stream_destroy (pinossink->stream); - pinossink->stream = NULL; - pinossink->pool->stream = NULL; + pw_thread_main_loop_lock (pwsink->main_loop); + if (pwsink->stream) { + pw_stream_disconnect (pwsink->stream); + pw_stream_destroy (pwsink->stream); + pwsink->stream = NULL; + pwsink->pool->stream = NULL; } - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); - pinossink->negotiated = FALSE; + pwsink->negotiated = FALSE; return TRUE; } static void -on_ctx_state_changed (PinosListener *listener, - PinosContext *ctx) +on_ctx_state_changed (struct pw_listener *listener, + struct pw_context *ctx) { - GstPinosSink *pinossink = SPA_CONTAINER_OF (listener, GstPinosSink, ctx_state_changed); - PinosContextState state; + GstPipeWireSink *pwsink = SPA_CONTAINER_OF (listener, GstPipeWireSink, ctx_state_changed); + enum pw_context_state state; state = ctx->state; GST_DEBUG ("got context state %d", state); switch (state) { - case PINOS_CONTEXT_STATE_UNCONNECTED: - case PINOS_CONTEXT_STATE_CONNECTING: - case PINOS_CONTEXT_STATE_CONNECTED: + case PW_CONTEXT_STATE_UNCONNECTED: + case PW_CONTEXT_STATE_CONNECTING: + case PW_CONTEXT_STATE_CONNECTED: break; - case PINOS_CONTEXT_STATE_ERROR: - GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED, + case PW_CONTEXT_STATE_ERROR: + GST_ELEMENT_ERROR (pwsink, RESOURCE, FAILED, ("context error: %s", ctx->error), (NULL)); break; } - pinos_thread_main_loop_signal (pinossink->main_loop, FALSE); + pw_thread_main_loop_signal (pwsink->main_loop, FALSE); } static gboolean -gst_pinos_sink_open (GstPinosSink * pinossink) +gst_pipewire_sink_open (GstPipeWireSink * pwsink) { - if (pinos_thread_main_loop_start (pinossink->main_loop) != SPA_RESULT_OK) + if (pw_thread_main_loop_start (pwsink->main_loop) != SPA_RESULT_OK) goto mainloop_error; - pinos_thread_main_loop_lock (pinossink->main_loop); - pinossink->ctx = pinos_context_new (pinossink->loop, g_get_application_name (), NULL); + pw_thread_main_loop_lock (pwsink->main_loop); + pwsink->ctx = pw_context_new (pwsink->loop, g_get_application_name (), NULL); - pinos_signal_add (&pinossink->ctx->state_changed, &pinossink->ctx_state_changed, on_ctx_state_changed); + pw_signal_add (&pwsink->ctx->state_changed, &pwsink->ctx_state_changed, on_ctx_state_changed); - pinos_context_connect (pinossink->ctx, PINOS_CONTEXT_FLAG_NO_REGISTRY); + pw_context_connect (pwsink->ctx, PW_CONTEXT_FLAG_NO_REGISTRY); while (TRUE) { - PinosContextState state = pinossink->ctx->state; + enum pw_context_state state = pwsink->ctx->state; - if (state == PINOS_CONTEXT_STATE_CONNECTED) + if (state == PW_CONTEXT_STATE_CONNECTED) break; - if (state == PINOS_CONTEXT_STATE_ERROR) + if (state == PW_CONTEXT_STATE_ERROR) goto connect_error; - pinos_thread_main_loop_wait (pinossink->main_loop); + pw_thread_main_loop_wait (pwsink->main_loop); } - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); return TRUE; /* ERRORS */ mainloop_error: { - GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED, + GST_ELEMENT_ERROR (pwsink, RESOURCE, FAILED, ("Failed to start mainloop"), (NULL)); return FALSE; } connect_error: { - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); return FALSE; } } static gboolean -gst_pinos_sink_close (GstPinosSink * pinossink) +gst_pipewire_sink_close (GstPipeWireSink * pwsink) { - pinos_thread_main_loop_lock (pinossink->main_loop); - if (pinossink->stream) { - pinos_stream_disconnect (pinossink->stream); + pw_thread_main_loop_lock (pwsink->main_loop); + if (pwsink->stream) { + pw_stream_disconnect (pwsink->stream); } - if (pinossink->ctx) { - pinos_context_disconnect (pinossink->ctx); + if (pwsink->ctx) { + pw_context_disconnect (pwsink->ctx); while (TRUE) { - PinosContextState state = pinossink->ctx->state; + enum pw_context_state state = pwsink->ctx->state; - if (state == PINOS_CONTEXT_STATE_UNCONNECTED) + if (state == PW_CONTEXT_STATE_UNCONNECTED) break; - if (state == PINOS_CONTEXT_STATE_ERROR) + if (state == PW_CONTEXT_STATE_ERROR) break; - pinos_thread_main_loop_wait (pinossink->main_loop); + pw_thread_main_loop_wait (pwsink->main_loop); } } - pinos_thread_main_loop_unlock (pinossink->main_loop); + pw_thread_main_loop_unlock (pwsink->main_loop); - pinos_thread_main_loop_stop (pinossink->main_loop); + pw_thread_main_loop_stop (pwsink->main_loop); - if (pinossink->stream) { - pinos_stream_destroy (pinossink->stream); - pinossink->stream = NULL; + if (pwsink->stream) { + pw_stream_destroy (pwsink->stream); + pwsink->stream = NULL; } - if (pinossink->ctx) { - pinos_context_destroy (pinossink->ctx); - pinossink->ctx = NULL; + if (pwsink->ctx) { + pw_context_destroy (pwsink->ctx); + pwsink->ctx = NULL; } return TRUE; } static GstStateChangeReturn -gst_pinos_sink_change_state (GstElement * element, GstStateChange transition) +gst_pipewire_sink_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret; - GstPinosSink *this = GST_PINOS_SINK_CAST (element); + GstPipeWireSink *this = GST_PIPEWIRE_SINK_CAST (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: - if (!gst_pinos_sink_open (this)) + if (!gst_pipewire_sink_open (this)) goto open_failed; break; case GST_STATE_CHANGE_READY_TO_PAUSED: @@ -923,7 +921,7 @@ gst_pinos_sink_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PAUSED_TO_READY: break; case GST_STATE_CHANGE_READY_TO_NULL: - gst_pinos_sink_close (this); + gst_pipewire_sink_close (this); break; default: break; diff --git a/pipewire/gst/gstpipewiresink.h b/pipewire/gst/gstpipewiresink.h new file mode 100644 index 000000000..9f11fbc5f --- /dev/null +++ b/pipewire/gst/gstpipewiresink.h @@ -0,0 +1,113 @@ +/* GStreamer + * Copyright (C) <2015> Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_PIPEWIRE_SINK_H__ +#define __GST_PIPEWIRE_SINK_H__ + +#include +#include + +#include +#include + +G_BEGIN_DECLS + +#define GST_TYPE_PIPEWIRE_SINK \ + (gst_pipewire_sink_get_type()) +#define GST_PIPEWIRE_SINK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PIPEWIRE_SINK,GstPipeWireSink)) +#define GST_PIPEWIRE_SINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PIPEWIRE_SINK,GstPipeWireSinkClass)) +#define GST_IS_PIPEWIRE_SINK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PIPEWIRE_SINK)) +#define GST_IS_PIPEWIRE_SINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PIPEWIRE_SINK)) +#define GST_PIPEWIRE_SINK_CAST(obj) \ + ((GstPipeWireSink *) (obj)) + +typedef struct _GstPipeWireSink GstPipeWireSink; +typedef struct _GstPipeWireSinkClass GstPipeWireSinkClass; + + +/** + * GstPipeWireSinkMode: + * @GST_PIPEWIRE_SINK_MODE_DEFAULT: the default mode as configured in the server + * @GST_PIPEWIRE_SINK_MODE_RENDER: try to render the media + * @GST_PIPEWIRE_SINK_MODE_PROVIDE: provide the media + * + * Different modes of operation. + */ +typedef enum +{ + GST_PIPEWIRE_SINK_MODE_DEFAULT, + GST_PIPEWIRE_SINK_MODE_RENDER, + GST_PIPEWIRE_SINK_MODE_PROVIDE, +} GstPipeWireSinkMode; + +#define GST_TYPE_PIPEWIRE_SINK_MODE (gst_pipewire_sink_mode_get_type ()) + +/** + * GstPipeWireSink: + * + * Opaque data structure. + */ +struct _GstPipeWireSink { + GstBaseSink element; + + /*< private >*/ + gchar *path; + gchar *client_name; + + /* video state */ + gboolean negotiated; + + struct pw_loop *loop; + struct pw_thread_main_loop *main_loop; + + struct pw_context *ctx; + struct pw_listener ctx_state_changed; + + struct pw_stream *stream; + struct pw_listener stream_state_changed; + struct pw_listener stream_format_changed; + struct pw_listener stream_add_buffer; + struct pw_listener stream_remove_buffer; + struct pw_listener stream_new_buffer; + struct pw_listener stream_need_buffer; + + GstAllocator *allocator; + GstStructure *properties; + GstPipeWireSinkMode mode; + + GstPipeWirePool *pool; + GHashTable *buf_ids; + GQueue queue; + guint need_ready; +}; + +struct _GstPipeWireSinkClass { + GstBaseSinkClass parent_class; +}; + +GType gst_pipewire_sink_get_type (void); +GType gst_pipewire_sink_mode_get_type (void); + +G_END_DECLS + +#endif /* __GST_PIPEWIRE_SINK_H__ */ diff --git a/pinos/gst/gstpinossrc.c b/pipewire/gst/gstpipewiresrc.c similarity index 53% rename from pinos/gst/gstpinossrc.c rename to pipewire/gst/gstpipewiresrc.c index 701b54d13..2883a4ca2 100644 --- a/pinos/gst/gstpinossrc.c +++ b/pipewire/gst/gstpipewiresrc.c @@ -18,21 +18,21 @@ */ /** - * SECTION:element-pinossrc + * SECTION:element-pipewiresrc * * * Example launch line * |[ - * gst-launch -v pinossrc ! videoconvert ! ximagesink - * ]| Shows pinos output in an X window. + * gst-launch -v pipewiresrc ! videoconvert ! ximagesink + * ]| Shows pipewire output in an X window. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "gstpinossrc.h" -#include "gstpinosformat.h" +#include "gstpipewiresrc.h" +#include "gstpipewireformat.h" #include #include @@ -47,12 +47,12 @@ #include -#include "gstpinosclock.h" +#include "gstpipewireclock.h" static GQuark process_mem_data_quark; -GST_DEBUG_CATEGORY_STATIC (pinos_src_debug); -#define GST_CAT_DEFAULT pinos_src_debug +GST_DEBUG_CATEGORY_STATIC (pipewire_src_debug); +#define GST_CAT_DEFAULT pipewire_src_debug #define DEFAULT_ALWAYS_COPY false @@ -66,60 +66,58 @@ enum }; -#define PINOSS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) - -static GstStaticPadTemplate gst_pinos_src_template = +static GstStaticPadTemplate gst_pipewire_src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY ); -#define gst_pinos_src_parent_class parent_class -G_DEFINE_TYPE (GstPinosSrc, gst_pinos_src, GST_TYPE_PUSH_SRC); +#define gst_pipewire_src_parent_class parent_class +G_DEFINE_TYPE (GstPipeWireSrc, gst_pipewire_src, GST_TYPE_PUSH_SRC); static GstStateChangeReturn -gst_pinos_src_change_state (GstElement * element, GstStateChange transition); +gst_pipewire_src_change_state (GstElement * element, GstStateChange transition); -static gboolean gst_pinos_src_negotiate (GstBaseSrc * basesrc); -static GstCaps *gst_pinos_src_src_fixate (GstBaseSrc * bsrc, +static gboolean gst_pipewire_src_negotiate (GstBaseSrc * basesrc); +static GstCaps *gst_pipewire_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps); -static GstFlowReturn gst_pinos_src_create (GstPushSrc * psrc, +static GstFlowReturn gst_pipewire_src_create (GstPushSrc * psrc, GstBuffer ** buffer); -static gboolean gst_pinos_src_unlock (GstBaseSrc * basesrc); -static gboolean gst_pinos_src_unlock_stop (GstBaseSrc * basesrc); -static gboolean gst_pinos_src_start (GstBaseSrc * basesrc); -static gboolean gst_pinos_src_stop (GstBaseSrc * basesrc); -static gboolean gst_pinos_src_event (GstBaseSrc * src, GstEvent * event); -static gboolean gst_pinos_src_query (GstBaseSrc * src, GstQuery * query); +static gboolean gst_pipewire_src_unlock (GstBaseSrc * basesrc); +static gboolean gst_pipewire_src_unlock_stop (GstBaseSrc * basesrc); +static gboolean gst_pipewire_src_start (GstBaseSrc * basesrc); +static gboolean gst_pipewire_src_stop (GstBaseSrc * basesrc); +static gboolean gst_pipewire_src_event (GstBaseSrc * src, GstEvent * event); +static gboolean gst_pipewire_src_query (GstBaseSrc * src, GstQuery * query); static void -gst_pinos_src_set_property (GObject * object, guint prop_id, +gst_pipewire_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (object); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (object); switch (prop_id) { case PROP_PATH: - g_free (pinossrc->path); - pinossrc->path = g_value_dup_string (value); + g_free (pwsrc->path); + pwsrc->path = g_value_dup_string (value); break; case PROP_CLIENT_NAME: - g_free (pinossrc->client_name); - pinossrc->client_name = g_value_dup_string (value); + g_free (pwsrc->client_name); + pwsrc->client_name = g_value_dup_string (value); break; case PROP_STREAM_PROPERTIES: - if (pinossrc->properties) - gst_structure_free (pinossrc->properties); - pinossrc->properties = + if (pwsrc->properties) + gst_structure_free (pwsrc->properties); + pwsrc->properties = gst_structure_copy (gst_value_get_structure (value)); break; case PROP_ALWAYS_COPY: - pinossrc->always_copy = g_value_get_boolean (value); + pwsrc->always_copy = g_value_get_boolean (value); break; default: @@ -129,26 +127,26 @@ gst_pinos_src_set_property (GObject * object, guint prop_id, } static void -gst_pinos_src_get_property (GObject * object, guint prop_id, +gst_pipewire_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (object); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (object); switch (prop_id) { case PROP_PATH: - g_value_set_string (value, pinossrc->path); + g_value_set_string (value, pwsrc->path); break; case PROP_CLIENT_NAME: - g_value_set_string (value, pinossrc->client_name); + g_value_set_string (value, pwsrc->client_name); break; case PROP_STREAM_PROPERTIES: - gst_value_set_structure (value, pinossrc->properties); + gst_value_set_structure (value, pwsrc->properties); break; case PROP_ALWAYS_COPY: - g_value_set_boolean (value, pinossrc->always_copy); + g_value_set_boolean (value, pwsrc->always_copy); break; default: @@ -158,65 +156,65 @@ gst_pinos_src_get_property (GObject * object, guint prop_id, } static GstClock * -gst_pinos_src_provide_clock (GstElement * elem) +gst_pipewire_src_provide_clock (GstElement * elem) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (elem); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (elem); GstClock *clock; - GST_OBJECT_LOCK (pinossrc); - if (!GST_OBJECT_FLAG_IS_SET (pinossrc, GST_ELEMENT_FLAG_PROVIDE_CLOCK)) + GST_OBJECT_LOCK (pwsrc); + if (!GST_OBJECT_FLAG_IS_SET (pwsrc, GST_ELEMENT_FLAG_PROVIDE_CLOCK)) goto clock_disabled; - if (pinossrc->clock && pinossrc->is_live) - clock = GST_CLOCK_CAST (gst_object_ref (pinossrc->clock)); + if (pwsrc->clock && pwsrc->is_live) + clock = GST_CLOCK_CAST (gst_object_ref (pwsrc->clock)); else clock = NULL; - GST_OBJECT_UNLOCK (pinossrc); + GST_OBJECT_UNLOCK (pwsrc); return clock; /* ERRORS */ clock_disabled: { - GST_DEBUG_OBJECT (pinossrc, "clock provide disabled"); - GST_OBJECT_UNLOCK (pinossrc); + GST_DEBUG_OBJECT (pwsrc, "clock provide disabled"); + GST_OBJECT_UNLOCK (pwsrc); return NULL; } } static void -clear_queue (GstPinosSrc *pinossrc) +clear_queue (GstPipeWireSrc *pwsrc) { - g_queue_foreach (&pinossrc->queue, (GFunc) gst_mini_object_unref, NULL); - g_queue_clear (&pinossrc->queue); + g_queue_foreach (&pwsrc->queue, (GFunc) gst_mini_object_unref, NULL); + g_queue_clear (&pwsrc->queue); } static void -gst_pinos_src_finalize (GObject * object) +gst_pipewire_src_finalize (GObject * object) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (object); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (object); - clear_queue (pinossrc); + clear_queue (pwsrc); - pinos_thread_main_loop_destroy (pinossrc->main_loop); - pinossrc->main_loop = NULL; - pinos_loop_destroy (pinossrc->loop); - pinossrc->loop = NULL; + pw_thread_main_loop_destroy (pwsrc->main_loop); + pwsrc->main_loop = NULL; + pw_loop_destroy (pwsrc->loop); + pwsrc->loop = NULL; - if (pinossrc->properties) - gst_structure_free (pinossrc->properties); - g_object_unref (pinossrc->fd_allocator); - if (pinossrc->clock) - gst_object_unref (pinossrc->clock); - g_free (pinossrc->path); - g_free (pinossrc->client_name); - g_hash_table_unref (pinossrc->buf_ids); + if (pwsrc->properties) + gst_structure_free (pwsrc->properties); + g_object_unref (pwsrc->fd_allocator); + if (pwsrc->clock) + gst_object_unref (pwsrc->clock); + g_free (pwsrc->path); + g_free (pwsrc->client_name); + g_hash_table_unref (pwsrc->buf_ids); G_OBJECT_CLASS (parent_class)->finalize (object); } static void -gst_pinos_src_class_init (GstPinosSrcClass * klass) +gst_pipewire_src_class_init (GstPipeWireSrcClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; @@ -228,9 +226,9 @@ gst_pinos_src_class_init (GstPinosSrcClass * klass) gstbasesrc_class = (GstBaseSrcClass *) klass; gstpushsrc_class = (GstPushSrcClass *) klass; - gobject_class->finalize = gst_pinos_src_finalize; - gobject_class->set_property = gst_pinos_src_set_property; - gobject_class->get_property = gst_pinos_src_get_property; + gobject_class->finalize = gst_pipewire_src_finalize; + gobject_class->set_property = gst_pipewire_src_set_property; + gobject_class->get_property = gst_pipewire_src_get_property; g_object_class_install_property (gobject_class, PROP_PATH, @@ -254,7 +252,7 @@ gst_pinos_src_class_init (GstPinosSrcClass * klass) PROP_STREAM_PROPERTIES, g_param_spec_boxed ("stream-properties", "stream properties", - "list of pinos stream properties", + "list of PipeWire stream properties", GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -268,34 +266,34 @@ gst_pinos_src_class_init (GstPinosSrcClass * klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - gstelement_class->provide_clock = gst_pinos_src_provide_clock; - gstelement_class->change_state = gst_pinos_src_change_state; + gstelement_class->provide_clock = gst_pipewire_src_provide_clock; + gstelement_class->change_state = gst_pipewire_src_change_state; gst_element_class_set_static_metadata (gstelement_class, - "Pinos source", "Source/Video", - "Uses pinos to create video", "Wim Taymans "); + "PipeWire source", "Source/Video", + "Uses PipeWire to create video", "Wim Taymans "); gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_pinos_src_template)); + gst_static_pad_template_get (&gst_pipewire_src_template)); - gstbasesrc_class->negotiate = gst_pinos_src_negotiate; - gstbasesrc_class->fixate = gst_pinos_src_src_fixate; - gstbasesrc_class->unlock = gst_pinos_src_unlock; - gstbasesrc_class->unlock_stop = gst_pinos_src_unlock_stop; - gstbasesrc_class->start = gst_pinos_src_start; - gstbasesrc_class->stop = gst_pinos_src_stop; - gstbasesrc_class->event = gst_pinos_src_event; - gstbasesrc_class->query = gst_pinos_src_query; - gstpushsrc_class->create = gst_pinos_src_create; + gstbasesrc_class->negotiate = gst_pipewire_src_negotiate; + gstbasesrc_class->fixate = gst_pipewire_src_src_fixate; + gstbasesrc_class->unlock = gst_pipewire_src_unlock; + gstbasesrc_class->unlock_stop = gst_pipewire_src_unlock_stop; + gstbasesrc_class->start = gst_pipewire_src_start; + gstbasesrc_class->stop = gst_pipewire_src_stop; + gstbasesrc_class->event = gst_pipewire_src_event; + gstbasesrc_class->query = gst_pipewire_src_query; + gstpushsrc_class->create = gst_pipewire_src_create; - GST_DEBUG_CATEGORY_INIT (pinos_src_debug, "pinossrc", 0, - "Pinos Source"); + GST_DEBUG_CATEGORY_INIT (pipewire_src_debug, "pipewiresrc", 0, + "PipeWire Source"); - process_mem_data_quark = g_quark_from_static_string ("GstPinosSrcProcessMemQuark"); + process_mem_data_quark = g_quark_from_static_string ("GstPipeWireSrcProcessMemQuark"); } static void -gst_pinos_src_init (GstPinosSrc * src) +gst_pipewire_src_init (GstPipeWireSrc * src) { /* we operate in time */ gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); @@ -307,17 +305,17 @@ gst_pinos_src_init (GstPinosSrc * src) g_queue_init (&src->queue); src->fd_allocator = gst_fd_allocator_new (); - src->client_name = pinos_client_name (); + src->client_name = pw_client_name (); src->buf_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gst_buffer_unref); - src->loop = pinos_loop_new (); - src->main_loop = pinos_thread_main_loop_new (src->loop, "pinos-main-loop"); + src->loop = pw_loop_new (); + src->main_loop = pw_thread_main_loop_new (src->loop, "pipewire-main-loop"); GST_DEBUG ("loop %p, mainloop %p", src->loop, src->main_loop); } static GstCaps * -gst_pinos_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps) +gst_pipewire_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps) { GstStructure *structure; const gchar *name; @@ -364,7 +362,7 @@ gst_pinos_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps) } typedef struct { - GstPinosSrc *src; + GstPipeWireSrc *src; guint id; SpaBuffer *buf; SpaMetaHeader *header; @@ -385,7 +383,7 @@ static gboolean buffer_recycle (GstMiniObject *obj) { ProcessMemData *data; - GstPinosSrc *src; + GstPipeWireSrc *src; gst_mini_object_ref (obj); data = gst_mini_object_get_qdata (obj, @@ -394,28 +392,28 @@ buffer_recycle (GstMiniObject *obj) src = data->src; GST_LOG_OBJECT (obj, "recycle buffer"); - pinos_thread_main_loop_lock (src->main_loop); - pinos_stream_recycle_buffer (src->stream, data->id); - pinos_thread_main_loop_unlock (src->main_loop); + pw_thread_main_loop_lock (src->main_loop); + pw_stream_recycle_buffer (src->stream, data->id); + pw_thread_main_loop_unlock (src->main_loop); return FALSE; } static void -on_add_buffer (PinosListener *listener, - PinosStream *stream, +on_add_buffer (struct pw_listener *listener, + struct pw_stream *stream, guint id) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_add_buffer); + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, stream_add_buffer); SpaBuffer *b; GstBuffer *buf; uint32_t i; ProcessMemData data; - PinosContext *ctx = pinossrc->stream->context; + struct pw_context *ctx = pwsrc->stream->context; - GST_LOG_OBJECT (pinossrc, "add buffer"); + GST_LOG_OBJECT (pwsrc, "add buffer"); - if (!(b = pinos_stream_peek_buffer (pinossrc->stream, id))) { + if (!(b = pw_stream_peek_buffer (pwsrc->stream, id))) { g_warning ("failed to peek buffer"); return; } @@ -423,7 +421,7 @@ on_add_buffer (PinosListener *listener, buf = gst_buffer_new (); GST_MINI_OBJECT_CAST (buf)->dispose = buffer_recycle; - data.src = gst_object_ref (pinossrc); + data.src = gst_object_ref (pwsrc); data.id = id; data.buf = b; data.header = spa_buffer_find_meta (b, ctx->type.meta.Header); @@ -433,7 +431,7 @@ on_add_buffer (PinosListener *listener, GstMemory *gmem = NULL; if (d->type == ctx->type.data.MemFd || d->type == ctx->type.data.DmaBuf) { - gmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (d->fd), + gmem = gst_fd_allocator_alloc (pwsrc->fd_allocator, dup (d->fd), d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE); gst_memory_resize (gmem, d->chunk->offset + d->mapoffset, d->chunk->size); data.offset = d->mapoffset; @@ -452,55 +450,55 @@ on_add_buffer (PinosListener *listener, g_slice_dup (ProcessMemData, &data), process_mem_data_destroy); - g_hash_table_insert (pinossrc->buf_ids, GINT_TO_POINTER (id), buf); + g_hash_table_insert (pwsrc->buf_ids, GINT_TO_POINTER (id), buf); } static void -on_remove_buffer (PinosListener *listener, - PinosStream *stream, +on_remove_buffer (struct pw_listener *listener, + struct pw_stream *stream, guint id) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_remove_buffer); + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, stream_remove_buffer); GstBuffer *buf; - GST_LOG_OBJECT (pinossrc, "remove buffer"); - buf = g_hash_table_lookup (pinossrc->buf_ids, GINT_TO_POINTER (id)); + GST_LOG_OBJECT (pwsrc, "remove buffer"); + buf = g_hash_table_lookup (pwsrc->buf_ids, GINT_TO_POINTER (id)); if (buf) { GList *walk; GST_MINI_OBJECT_CAST (buf)->dispose = NULL; - walk = pinossrc->queue.head; + walk = pwsrc->queue.head; while (walk) { GList *next = walk->next; if (walk->data == buf) { gst_buffer_unref (buf); - g_queue_delete_link (&pinossrc->queue, walk); + g_queue_delete_link (&pwsrc->queue, walk); } walk = next; } - g_hash_table_remove (pinossrc->buf_ids, GINT_TO_POINTER (id)); + g_hash_table_remove (pwsrc->buf_ids, GINT_TO_POINTER (id)); } } static void -on_new_buffer (PinosListener *listener, - PinosStream *stream, +on_new_buffer (struct pw_listener *listener, + struct pw_stream *stream, guint id) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_new_buffer); + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, stream_new_buffer); GstBuffer *buf; ProcessMemData *data; SpaMetaHeader *h; guint i; - buf = g_hash_table_lookup (pinossrc->buf_ids, GINT_TO_POINTER (id)); + buf = g_hash_table_lookup (pwsrc->buf_ids, GINT_TO_POINTER (id)); if (buf == NULL) { g_warning ("unknown buffer %d", id); return; } - GST_LOG_OBJECT (pinossrc, "got new buffer %p", buf); + GST_LOG_OBJECT (pwsrc, "got new buffer %p", buf); data = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buf), process_mem_data_quark); @@ -522,137 +520,137 @@ on_new_buffer (PinosListener *listener, mem->size = d->chunk->size; } - if (pinossrc->always_copy) + if (pwsrc->always_copy) buf = gst_buffer_copy_deep (buf); else gst_buffer_ref (buf); - g_queue_push_tail (&pinossrc->queue, buf); + g_queue_push_tail (&pwsrc->queue, buf); - pinos_thread_main_loop_signal (pinossrc->main_loop, FALSE); + pw_thread_main_loop_signal (pwsrc->main_loop, FALSE); return; } static void -on_state_changed (PinosListener *listener, - PinosStream *stream) +on_state_changed (struct pw_listener *listener, + struct pw_stream *stream) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_state_changed); - PinosStreamState state = stream->state; + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, stream_state_changed); + enum pw_stream_state state = stream->state; - GST_DEBUG ("got stream state %s", pinos_stream_state_as_string (state)); + GST_DEBUG ("got stream state %s", pw_stream_state_as_string (state)); switch (state) { - case PINOS_STREAM_STATE_UNCONNECTED: - case PINOS_STREAM_STATE_CONNECTING: - case PINOS_STREAM_STATE_CONFIGURE: - case PINOS_STREAM_STATE_READY: - case PINOS_STREAM_STATE_PAUSED: - case PINOS_STREAM_STATE_STREAMING: + case PW_STREAM_STATE_UNCONNECTED: + case PW_STREAM_STATE_CONNECTING: + case PW_STREAM_STATE_CONFIGURE: + case PW_STREAM_STATE_READY: + case PW_STREAM_STATE_PAUSED: + case PW_STREAM_STATE_STREAMING: break; - case PINOS_STREAM_STATE_ERROR: - GST_ELEMENT_ERROR (pinossrc, RESOURCE, FAILED, + case PW_STREAM_STATE_ERROR: + GST_ELEMENT_ERROR (pwsrc, RESOURCE, FAILED, ("stream error: %s", stream->error), (NULL)); break; } - pinos_thread_main_loop_signal (pinossrc->main_loop, FALSE); + pw_thread_main_loop_signal (pwsrc->main_loop, FALSE); } static void -parse_stream_properties (GstPinosSrc *pinossrc, PinosProperties *props) +parse_stream_properties (GstPipeWireSrc *pwsrc, struct pw_properties *props) { const gchar *var; gboolean is_live; - GST_OBJECT_LOCK (pinossrc); - var = pinos_properties_get (props, "pinos.latency.is-live"); - is_live = pinossrc->is_live = var ? (atoi (var) == 1) : FALSE; + GST_OBJECT_LOCK (pwsrc); + var = pw_properties_get (props, "pipewire.latency.is-live"); + is_live = pwsrc->is_live = var ? (atoi (var) == 1) : FALSE; - var = pinos_properties_get (props, "pinos.latency.min"); - pinossrc->min_latency = var ? (GstClockTime) atoi (var) : 0; + var = pw_properties_get (props, "pipewire.latency.min"); + pwsrc->min_latency = var ? (GstClockTime) atoi (var) : 0; - var = pinos_properties_get (props, "pinos.latency.max"); - pinossrc->max_latency = var ? (GstClockTime) atoi (var) : GST_CLOCK_TIME_NONE; - GST_OBJECT_UNLOCK (pinossrc); + var = pw_properties_get (props, "pipewire.latency.max"); + pwsrc->max_latency = var ? (GstClockTime) atoi (var) : GST_CLOCK_TIME_NONE; + GST_OBJECT_UNLOCK (pwsrc); - GST_DEBUG_OBJECT (pinossrc, "live %d", is_live); + GST_DEBUG_OBJECT (pwsrc, "live %d", is_live); - gst_base_src_set_live (GST_BASE_SRC (pinossrc), is_live); + gst_base_src_set_live (GST_BASE_SRC (pwsrc), is_live); } static gboolean -gst_pinos_src_stream_start (GstPinosSrc *pinossrc) +gst_pipewire_src_stream_start (GstPipeWireSrc *pwsrc) { - pinos_thread_main_loop_lock (pinossrc->main_loop); - GST_DEBUG_OBJECT (pinossrc, "doing stream start"); + pw_thread_main_loop_lock (pwsrc->main_loop); + GST_DEBUG_OBJECT (pwsrc, "doing stream start"); while (TRUE) { - PinosStreamState state = pinossrc->stream->state; + enum pw_stream_state state = pwsrc->stream->state; - GST_DEBUG_OBJECT (pinossrc, "waiting for STREAMING, now %s", pinos_stream_state_as_string (state)); - if (state == PINOS_STREAM_STATE_STREAMING) + GST_DEBUG_OBJECT (pwsrc, "waiting for STREAMING, now %s", pw_stream_state_as_string (state)); + if (state == PW_STREAM_STATE_STREAMING) break; - if (state == PINOS_STREAM_STATE_ERROR) + if (state == PW_STREAM_STATE_ERROR) goto start_error; - if (pinossrc->ctx->state == PINOS_CONTEXT_STATE_ERROR) + if (pwsrc->ctx->state == PW_CONTEXT_STATE_ERROR) goto start_error; - pinos_thread_main_loop_wait (pinossrc->main_loop); + pw_thread_main_loop_wait (pwsrc->main_loop); } - parse_stream_properties (pinossrc, pinossrc->stream->properties); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + parse_stream_properties (pwsrc, pwsrc->stream->properties); + pw_thread_main_loop_unlock (pwsrc->main_loop); - pinos_thread_main_loop_lock (pinossrc->main_loop); - GST_DEBUG_OBJECT (pinossrc, "signal started"); - pinossrc->started = TRUE; - pinos_thread_main_loop_signal (pinossrc->main_loop, FALSE); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_lock (pwsrc->main_loop); + GST_DEBUG_OBJECT (pwsrc, "signal started"); + pwsrc->started = TRUE; + pw_thread_main_loop_signal (pwsrc->main_loop, FALSE); + pw_thread_main_loop_unlock (pwsrc->main_loop); return TRUE; start_error: { - GST_DEBUG_OBJECT (pinossrc, "error starting stream"); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + GST_DEBUG_OBJECT (pwsrc, "error starting stream"); + pw_thread_main_loop_unlock (pwsrc->main_loop); return FALSE; } } -static PinosStreamState -wait_negotiated (GstPinosSrc *this) +static enum pw_stream_state +wait_negotiated (GstPipeWireSrc *this) { - PinosStreamState state; + enum pw_stream_state state; - pinos_thread_main_loop_lock (this->main_loop); + pw_thread_main_loop_lock (this->main_loop); while (TRUE) { state = this->stream->state; GST_DEBUG_OBJECT (this, "waiting for started signal, state now %s", - pinos_stream_state_as_string (state)); + pw_stream_state_as_string (state)); - if (state == PINOS_STREAM_STATE_ERROR) + if (state == PW_STREAM_STATE_ERROR) break; - if (this->ctx->state == PINOS_CONTEXT_STATE_ERROR) + if (this->ctx->state == PW_CONTEXT_STATE_ERROR) break; if (this->started) break; - pinos_thread_main_loop_wait (this->main_loop); + pw_thread_main_loop_wait (this->main_loop); } GST_DEBUG_OBJECT (this, "got started signal"); - pinos_thread_main_loop_unlock (this->main_loop); + pw_thread_main_loop_unlock (this->main_loop); return state; } static gboolean -gst_pinos_src_negotiate (GstBaseSrc * basesrc) +gst_pipewire_src_negotiate (GstBaseSrc * basesrc) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (basesrc); GstCaps *thiscaps; GstCaps *caps = NULL; GstCaps *peercaps = NULL; @@ -689,56 +687,56 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc) possible = gst_caps_to_format_all (caps); /* first disconnect */ - pinos_thread_main_loop_lock (pinossrc->main_loop); - if (pinossrc->stream->state != PINOS_STREAM_STATE_UNCONNECTED) { + pw_thread_main_loop_lock (pwsrc->main_loop); + if (pwsrc->stream->state != PW_STREAM_STATE_UNCONNECTED) { GST_DEBUG_OBJECT (basesrc, "disconnect capture"); - pinos_stream_disconnect (pinossrc->stream); + pw_stream_disconnect (pwsrc->stream); while (TRUE) { - PinosStreamState state = pinossrc->stream->state; + enum pw_stream_state state = pwsrc->stream->state; - GST_DEBUG_OBJECT (basesrc, "waiting for UNCONNECTED, now %s", pinos_stream_state_as_string (state)); - if (state == PINOS_STREAM_STATE_UNCONNECTED) + GST_DEBUG_OBJECT (basesrc, "waiting for UNCONNECTED, now %s", pw_stream_state_as_string (state)); + if (state == PW_STREAM_STATE_UNCONNECTED) break; - if (state == PINOS_STREAM_STATE_ERROR) { + if (state == PW_STREAM_STATE_ERROR) { g_ptr_array_unref (possible); goto connect_error; } - pinos_thread_main_loop_wait (pinossrc->main_loop); + pw_thread_main_loop_wait (pwsrc->main_loop); } } - GST_DEBUG_OBJECT (basesrc, "connect capture with path %s", pinossrc->path); - pinos_stream_connect (pinossrc->stream, - PINOS_DIRECTION_INPUT, - PINOS_STREAM_MODE_BUFFER, - pinossrc->path, - PINOS_STREAM_FLAG_AUTOCONNECT, - possible->len, - (SpaFormat **)possible->pdata); + GST_DEBUG_OBJECT (basesrc, "connect capture with path %s", pwsrc->path); + pw_stream_connect (pwsrc->stream, + PW_DIRECTION_INPUT, + PW_STREAM_MODE_BUFFER, + pwsrc->path, + PW_STREAM_FLAG_AUTOCONNECT, + possible->len, + (SpaFormat **)possible->pdata); while (TRUE) { - PinosStreamState state = pinossrc->stream->state; + enum pw_stream_state state = pwsrc->stream->state; - GST_DEBUG_OBJECT (basesrc, "waiting for PAUSED, now %s", pinos_stream_state_as_string (state)); - if (state == PINOS_STREAM_STATE_PAUSED || - state == PINOS_STREAM_STATE_STREAMING) + GST_DEBUG_OBJECT (basesrc, "waiting for PAUSED, now %s", pw_stream_state_as_string (state)); + if (state == PW_STREAM_STATE_PAUSED || + state == PW_STREAM_STATE_STREAMING) break; - if (state == PINOS_STREAM_STATE_ERROR) + if (state == PW_STREAM_STATE_ERROR) goto connect_error; - if (pinossrc->ctx->state == PINOS_CONTEXT_STATE_ERROR) + if (pwsrc->ctx->state == PW_CONTEXT_STATE_ERROR) goto connect_error; - pinos_thread_main_loop_wait (pinossrc->main_loop); + pw_thread_main_loop_wait (pwsrc->main_loop); } - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); - result = gst_pinos_src_stream_start (pinossrc); + result = gst_pipewire_src_stream_start (pwsrc); - pinossrc->negotiated = result; + pwsrc->negotiated = result; return result; @@ -769,7 +767,7 @@ no_common_caps: } connect_error: { - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); return FALSE; } } @@ -781,24 +779,24 @@ connect_error: SPA_POD_PROP_RANGE_MIN_MAX,type,3,__VA_ARGS__) static void -on_format_changed (PinosListener *listener, - PinosStream *stream, +on_format_changed (struct pw_listener *listener, + struct pw_stream *stream, SpaFormat *format) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_format_changed); + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, stream_format_changed); GstCaps *caps; gboolean res; - PinosContext *ctx = stream->context; + struct pw_context *ctx = stream->context; if (format == NULL) { - GST_DEBUG_OBJECT (pinossrc, "clear format"); - pinos_stream_finish_format (pinossrc->stream, SPA_RESULT_OK, NULL, 0); + GST_DEBUG_OBJECT (pwsrc, "clear format"); + pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, NULL, 0); return; } caps = gst_caps_from_format (format); - GST_DEBUG_OBJECT (pinossrc, "we got format %" GST_PTR_FORMAT, caps); - res = gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps); + GST_DEBUG_OBJECT (pwsrc, "we got format %" GST_PTR_FORMAT, caps); + res = gst_base_src_set_caps (GST_BASE_SRC (pwsrc), caps); gst_caps_unref (caps); if (res) { @@ -820,43 +818,43 @@ on_format_changed (PinosListener *listener, PROP (&f[1], ctx->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader))); params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam); - GST_DEBUG_OBJECT (pinossrc, "doing finish format"); - pinos_stream_finish_format (pinossrc->stream, SPA_RESULT_OK, params, 2); + GST_DEBUG_OBJECT (pwsrc, "doing finish format"); + pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, params, 2); } else { - GST_WARNING_OBJECT (pinossrc, "finish format with error"); - pinos_stream_finish_format (pinossrc->stream, SPA_RESULT_INVALID_MEDIA_TYPE, NULL, 0); + GST_WARNING_OBJECT (pwsrc, "finish format with error"); + pw_stream_finish_format (pwsrc->stream, SPA_RESULT_INVALID_MEDIA_TYPE, NULL, 0); } } static gboolean -gst_pinos_src_unlock (GstBaseSrc * basesrc) +gst_pipewire_src_unlock (GstBaseSrc * basesrc) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (basesrc); - pinos_thread_main_loop_lock (pinossrc->main_loop); - GST_DEBUG_OBJECT (pinossrc, "setting flushing"); - pinossrc->flushing = TRUE; - pinos_thread_main_loop_signal (pinossrc->main_loop, FALSE); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_lock (pwsrc->main_loop); + GST_DEBUG_OBJECT (pwsrc, "setting flushing"); + pwsrc->flushing = TRUE; + pw_thread_main_loop_signal (pwsrc->main_loop, FALSE); + pw_thread_main_loop_unlock (pwsrc->main_loop); return TRUE; } static gboolean -gst_pinos_src_unlock_stop (GstBaseSrc * basesrc) +gst_pipewire_src_unlock_stop (GstBaseSrc * basesrc) { - GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc); + GstPipeWireSrc *pwsrc = GST_PIPEWIRE_SRC (basesrc); - pinos_thread_main_loop_lock (pinossrc->main_loop); - GST_DEBUG_OBJECT (pinossrc, "unsetting flushing"); - pinossrc->flushing = FALSE; - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_lock (pwsrc->main_loop); + GST_DEBUG_OBJECT (pwsrc, "unsetting flushing"); + pwsrc->flushing = FALSE; + pw_thread_main_loop_unlock (pwsrc->main_loop); return TRUE; } static gboolean -gst_pinos_src_event (GstBaseSrc * src, GstEvent * event) +gst_pipewire_src_event (GstBaseSrc * src, GstEvent * event) { gboolean res = FALSE; @@ -871,23 +869,23 @@ gst_pinos_src_event (GstBaseSrc * src, GstEvent * event) &running_time, &all_headers, &count); #if 0 - pinos_buffer_builder_init (&b); + pw_buffer_builder_init (&b); refresh.last_id = 0; refresh.request_type = all_headers ? 1 : 0; refresh.pts = running_time; - pinos_buffer_builder_add_refresh_request (&b, &refresh); + pw_buffer_builder_add_refresh_request (&b, &refresh); - pinos_buffer_builder_end (&b, &pbuf); + pw_buffer_builder_end (&b, &pbuf); - GST_OBJECT_LOCK (pinossrc); - if (pinossrc->stream_state == PINOS_STREAM_STATE_STREAMING) { - GST_DEBUG_OBJECT (pinossrc, "send refresh request"); - pinos_stream_send_buffer (pinossrc->stream, &pbuf); + GST_OBJECT_LOCK (pwsrc); + if (pwsrc->stream_state == PW_STREAM_STATE_STREAMING) { + GST_DEBUG_OBJECT (pwsrc, "send refresh request"); + pw_stream_send_buffer (pwsrc->stream, &pbuf); } - GST_OBJECT_UNLOCK (pinossrc); + GST_OBJECT_UNLOCK (pwsrc); - pinos_buffer_unref (&pbuf); + pw_buffer_unref (&pbuf); #endif res = TRUE; } else { @@ -902,20 +900,20 @@ gst_pinos_src_event (GstBaseSrc * src, GstEvent * event) } static gboolean -gst_pinos_src_query (GstBaseSrc * src, GstQuery * query) +gst_pipewire_src_query (GstBaseSrc * src, GstQuery * query) { gboolean res = FALSE; - GstPinosSrc *pinossrc; + GstPipeWireSrc *pwsrc; - pinossrc = GST_PINOS_SRC (src); + pwsrc = GST_PIPEWIRE_SRC (src); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_LATENCY: - GST_OBJECT_LOCK (pinossrc); - pinossrc->min_latency = 10000000; - pinossrc->max_latency = GST_CLOCK_TIME_NONE; - gst_query_set_latency (query, pinossrc->is_live, pinossrc->min_latency, pinossrc->max_latency); - GST_OBJECT_UNLOCK (pinossrc); + GST_OBJECT_LOCK (pwsrc); + pwsrc->min_latency = 10000000; + pwsrc->max_latency = GST_CLOCK_TIME_NONE; + gst_query_set_latency (query, pwsrc->is_live, pwsrc->min_latency, pwsrc->max_latency); + GST_OBJECT_UNLOCK (pwsrc); res = TRUE; break; default: @@ -926,40 +924,40 @@ gst_pinos_src_query (GstBaseSrc * src, GstQuery * query) } static GstFlowReturn -gst_pinos_src_create (GstPushSrc * psrc, GstBuffer ** buffer) +gst_pipewire_src_create (GstPushSrc * psrc, GstBuffer ** buffer) { - GstPinosSrc *pinossrc; + GstPipeWireSrc *pwsrc; GstClockTime pts, dts, base_time; - pinossrc = GST_PINOS_SRC (psrc); + pwsrc = GST_PIPEWIRE_SRC (psrc); - if (!pinossrc->negotiated) + if (!pwsrc->negotiated) goto not_negotiated; - pinos_thread_main_loop_lock (pinossrc->main_loop); + pw_thread_main_loop_lock (pwsrc->main_loop); while (TRUE) { - PinosStreamState state; + enum pw_stream_state state; - if (pinossrc->flushing) + if (pwsrc->flushing) goto streaming_stopped; - state = pinossrc->stream->state; - if (state == PINOS_STREAM_STATE_ERROR) + state = pwsrc->stream->state; + if (state == PW_STREAM_STATE_ERROR) goto streaming_error; - if (state != PINOS_STREAM_STATE_STREAMING) + if (state != PW_STREAM_STATE_STREAMING) goto streaming_stopped; - *buffer = g_queue_pop_head (&pinossrc->queue); + *buffer = g_queue_pop_head (&pwsrc->queue); GST_DEBUG ("popped buffer %p", *buffer); if (*buffer != NULL) break; - pinos_thread_main_loop_wait (pinossrc->main_loop); + pw_thread_main_loop_wait (pwsrc->main_loop); } - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); - if (pinossrc->is_live) + if (pwsrc->is_live) base_time = GST_ELEMENT_CAST (psrc)->base_time; else base_time = 0; @@ -988,56 +986,56 @@ not_negotiated: } streaming_error: { - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); return GST_FLOW_ERROR; } streaming_stopped: { - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); return GST_FLOW_FLUSHING; } } static gboolean -gst_pinos_src_start (GstBaseSrc * basesrc) +gst_pipewire_src_start (GstBaseSrc * basesrc) { return TRUE; } static gboolean -gst_pinos_src_stop (GstBaseSrc * basesrc) +gst_pipewire_src_stop (GstBaseSrc * basesrc) { - GstPinosSrc *pinossrc; + GstPipeWireSrc *pwsrc; - pinossrc = GST_PINOS_SRC (basesrc); + pwsrc = GST_PIPEWIRE_SRC (basesrc); - pinos_thread_main_loop_lock (pinossrc->main_loop); - clear_queue (pinossrc); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_lock (pwsrc->main_loop); + clear_queue (pwsrc); + pw_thread_main_loop_unlock (pwsrc->main_loop); return TRUE; } static void -on_ctx_state_changed (PinosListener *listener, - PinosContext *ctx) +on_ctx_state_changed (struct pw_listener *listener, + struct pw_context *ctx) { - GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, ctx_state_changed); - PinosContextState state = ctx->state; + GstPipeWireSrc *pwsrc = SPA_CONTAINER_OF (listener, GstPipeWireSrc, ctx_state_changed); + enum pw_context_state state = ctx->state; - GST_DEBUG ("got context state %s", pinos_context_state_as_string (state)); + GST_DEBUG ("got context state %s", pw_context_state_as_string (state)); switch (state) { - case PINOS_CONTEXT_STATE_UNCONNECTED: - case PINOS_CONTEXT_STATE_CONNECTING: - case PINOS_CONTEXT_STATE_CONNECTED: + case PW_CONTEXT_STATE_UNCONNECTED: + case PW_CONTEXT_STATE_CONNECTING: + case PW_CONTEXT_STATE_CONNECTED: break; - case PINOS_CONTEXT_STATE_ERROR: - GST_ELEMENT_ERROR (pinossrc, RESOURCE, FAILED, + case PW_CONTEXT_STATE_ERROR: + GST_ELEMENT_ERROR (pwsrc, RESOURCE, FAILED, ("context error: %s", ctx->error), (NULL)); break; } - pinos_thread_main_loop_signal (pinossrc->main_loop, FALSE); + pw_thread_main_loop_signal (pwsrc->main_loop, FALSE); } static gboolean @@ -1045,105 +1043,105 @@ copy_properties (GQuark field_id, const GValue *value, gpointer user_data) { - PinosProperties *properties = user_data; + struct pw_properties *properties = user_data; if (G_VALUE_HOLDS_STRING (value)) - pinos_properties_set (properties, - g_quark_to_string (field_id), - g_value_get_string (value)); + pw_properties_set (properties, + g_quark_to_string (field_id), + g_value_get_string (value)); return TRUE; } static gboolean -gst_pinos_src_open (GstPinosSrc * pinossrc) +gst_pipewire_src_open (GstPipeWireSrc * pwsrc) { - PinosProperties *props; + struct pw_properties *props; - if (pinos_thread_main_loop_start (pinossrc->main_loop) != SPA_RESULT_OK) + if (pw_thread_main_loop_start (pwsrc->main_loop) != SPA_RESULT_OK) goto mainloop_failed; - pinos_thread_main_loop_lock (pinossrc->main_loop); - pinossrc->ctx = pinos_context_new (pinossrc->loop, g_get_application_name (), NULL); + pw_thread_main_loop_lock (pwsrc->main_loop); + pwsrc->ctx = pw_context_new (pwsrc->loop, g_get_application_name (), NULL); - pinos_signal_add (&pinossrc->ctx->state_changed, &pinossrc->ctx_state_changed, on_ctx_state_changed); + pw_signal_add (&pwsrc->ctx->state_changed, &pwsrc->ctx_state_changed, on_ctx_state_changed); - pinos_context_connect (pinossrc->ctx, PINOS_CONTEXT_FLAG_NO_REGISTRY); + pw_context_connect (pwsrc->ctx, PW_CONTEXT_FLAG_NO_REGISTRY); while (TRUE) { - PinosContextState state = pinossrc->ctx->state; + enum pw_context_state state = pwsrc->ctx->state; - GST_DEBUG ("waiting for CONNECTED, now %s", pinos_context_state_as_string (state)); - if (state == PINOS_CONTEXT_STATE_CONNECTED) + GST_DEBUG ("waiting for CONNECTED, now %s", pw_context_state_as_string (state)); + if (state == PW_CONTEXT_STATE_CONNECTED) break; - if (state == PINOS_CONTEXT_STATE_ERROR) + if (state == PW_CONTEXT_STATE_ERROR) goto connect_error; - pinos_thread_main_loop_wait (pinossrc->main_loop); + pw_thread_main_loop_wait (pwsrc->main_loop); } - if (pinossrc->properties) { - props = pinos_properties_new (NULL, NULL); - gst_structure_foreach (pinossrc->properties, copy_properties, props); + if (pwsrc->properties) { + props = pw_properties_new (NULL, NULL); + gst_structure_foreach (pwsrc->properties, copy_properties, props); } else { props = NULL; } - pinossrc->stream = pinos_stream_new (pinossrc->ctx, pinossrc->client_name, props); + pwsrc->stream = pw_stream_new (pwsrc->ctx, pwsrc->client_name, props); - pinos_signal_add (&pinossrc->stream->state_changed, &pinossrc->stream_state_changed, on_state_changed); - pinos_signal_add (&pinossrc->stream->format_changed, &pinossrc->stream_format_changed, on_format_changed); - pinos_signal_add (&pinossrc->stream->add_buffer, &pinossrc->stream_add_buffer, on_add_buffer); - pinos_signal_add (&pinossrc->stream->remove_buffer, &pinossrc->stream_remove_buffer, on_remove_buffer); - pinos_signal_add (&pinossrc->stream->new_buffer, &pinossrc->stream_new_buffer, on_new_buffer); + pw_signal_add (&pwsrc->stream->state_changed, &pwsrc->stream_state_changed, on_state_changed); + pw_signal_add (&pwsrc->stream->format_changed, &pwsrc->stream_format_changed, on_format_changed); + pw_signal_add (&pwsrc->stream->add_buffer, &pwsrc->stream_add_buffer, on_add_buffer); + pw_signal_add (&pwsrc->stream->remove_buffer, &pwsrc->stream_remove_buffer, on_remove_buffer); + pw_signal_add (&pwsrc->stream->new_buffer, &pwsrc->stream_new_buffer, on_new_buffer); - pinossrc->clock = gst_pinos_clock_new (pinossrc->stream); - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pwsrc->clock = gst_pipewire_clock_new (pwsrc->stream); + pw_thread_main_loop_unlock (pwsrc->main_loop); return TRUE; /* ERRORS */ mainloop_failed: { - GST_ELEMENT_ERROR (pinossrc, RESOURCE, FAILED, ("error starting mainloop"), (NULL)); + GST_ELEMENT_ERROR (pwsrc, RESOURCE, FAILED, ("error starting mainloop"), (NULL)); return FALSE; } connect_error: { - pinos_thread_main_loop_unlock (pinossrc->main_loop); + pw_thread_main_loop_unlock (pwsrc->main_loop); return FALSE; } } static void -gst_pinos_src_close (GstPinosSrc * pinossrc) +gst_pipewire_src_close (GstPipeWireSrc * pwsrc) { - clear_queue (pinossrc); + clear_queue (pwsrc); - pinos_thread_main_loop_stop (pinossrc->main_loop); + pw_thread_main_loop_stop (pwsrc->main_loop); - g_hash_table_remove_all (pinossrc->buf_ids); + g_hash_table_remove_all (pwsrc->buf_ids); - pinos_stream_destroy (pinossrc->stream); - pinossrc->stream = NULL; + pw_stream_destroy (pwsrc->stream); + pwsrc->stream = NULL; - pinos_context_destroy (pinossrc->ctx); - pinossrc->ctx = NULL; + pw_context_destroy (pwsrc->ctx); + pwsrc->ctx = NULL; - GST_OBJECT_LOCK (pinossrc); - g_clear_object (&pinossrc->clock); - GST_OBJECT_UNLOCK (pinossrc); + GST_OBJECT_LOCK (pwsrc); + g_clear_object (&pwsrc->clock); + GST_OBJECT_UNLOCK (pwsrc); } static GstStateChangeReturn -gst_pinos_src_change_state (GstElement * element, GstStateChange transition) +gst_pipewire_src_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret; - GstPinosSrc *this = GST_PINOS_SRC_CAST (element); + GstPipeWireSrc *this = GST_PIPEWIRE_SRC_CAST (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: - if (!gst_pinos_src_open (this)) + if (!gst_pipewire_src_open (this)) goto open_failed; break; case GST_STATE_CHANGE_READY_TO_PAUSED: @@ -1162,7 +1160,7 @@ gst_pinos_src_change_state (GstElement * element, GstStateChange transition) switch (transition) { case GST_STATE_CHANGE_READY_TO_PAUSED: - if (wait_negotiated (this) == PINOS_STREAM_STATE_ERROR) + if (wait_negotiated (this) == PW_STREAM_STATE_ERROR) goto open_failed; if (gst_base_src_is_live (GST_BASE_SRC (element))) @@ -1174,7 +1172,7 @@ gst_pinos_src_change_state (GstElement * element, GstStateChange transition) this->negotiated = FALSE; break; case GST_STATE_CHANGE_READY_TO_NULL: - gst_pinos_src_close (this); + gst_pipewire_src_close (this); break; default: break; diff --git a/pinos/gst/gstpinossrc.h b/pipewire/gst/gstpipewiresrc.h similarity index 51% rename from pinos/gst/gstpinossrc.h rename to pipewire/gst/gstpipewiresrc.h index 91270d01c..c3a15db28 100644 --- a/pinos/gst/gstpinossrc.h +++ b/pipewire/gst/gstpipewiresrc.h @@ -17,38 +17,38 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __GST_PINOS_SRC_H__ -#define __GST_PINOS_SRC_H__ +#ifndef __GST_PIPEWIRE_SRC_H__ +#define __GST_PIPEWIRE_SRC_H__ #include #include -#include +#include G_BEGIN_DECLS -#define GST_TYPE_PINOS_SRC \ - (gst_pinos_src_get_type()) -#define GST_PINOS_SRC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_SRC,GstPinosSrc)) -#define GST_PINOS_SRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_SRC,GstPinosSrcClass)) -#define GST_IS_PINOS_SRC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_SRC)) -#define GST_IS_PINOS_SRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_SRC)) -#define GST_PINOS_SRC_CAST(obj) \ - ((GstPinosSrc *) (obj)) +#define GST_TYPE_PIPEWIRE_SRC \ + (gst_pipewire_src_get_type()) +#define GST_PIPEWIRE_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PIPEWIRE_SRC,GstPipeWireSrc)) +#define GST_PIPEWIRE_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PIPEWIRE_SRC,GstPipeWireSrcClass)) +#define GST_IS_PIPEWIRE_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PIPEWIRE_SRC)) +#define GST_IS_PIPEWIRE_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PIPEWIRE_SRC)) +#define GST_PIPEWIRE_SRC_CAST(obj) \ + ((GstPipeWireSrc *) (obj)) -typedef struct _GstPinosSrc GstPinosSrc; -typedef struct _GstPinosSrcClass GstPinosSrcClass; +typedef struct _GstPipeWireSrc GstPipeWireSrc; +typedef struct _GstPipeWireSrcClass GstPipeWireSrcClass; /** - * GstPinosSrc: + * GstPipeWireSrc: * * Opaque data structure. */ -struct _GstPinosSrc { +struct _GstPipeWireSrc { GstPushSrc element; /*< private >*/ @@ -64,18 +64,18 @@ struct _GstPinosSrc { GstClockTime min_latency; GstClockTime max_latency; - PinosLoop *loop; - PinosThreadMainLoop *main_loop; + struct pw_loop *loop; + struct pw_thread_main_loop *main_loop; - PinosContext *ctx; - PinosListener ctx_state_changed; + struct pw_context *ctx; + struct pw_listener ctx_state_changed; - PinosStream *stream; - PinosListener stream_state_changed; - PinosListener stream_format_changed; - PinosListener stream_add_buffer; - PinosListener stream_remove_buffer; - PinosListener stream_new_buffer; + struct pw_stream *stream; + struct pw_listener stream_state_changed; + struct pw_listener stream_format_changed; + struct pw_listener stream_add_buffer; + struct pw_listener stream_remove_buffer; + struct pw_listener stream_new_buffer; GstAllocator *fd_allocator; GstStructure *properties; @@ -85,12 +85,12 @@ struct _GstPinosSrc { GstClock *clock; }; -struct _GstPinosSrcClass { +struct _GstPipeWireSrcClass { GstPushSrcClass parent_class; }; -GType gst_pinos_src_get_type (void); +GType gst_pipewire_src_get_type (void); G_END_DECLS -#endif /* __GST_PINOS_SRC_H__ */ +#endif /* __GST_PIPEWIRE_SRC_H__ */ diff --git a/pipewire/gst/meson.build b/pipewire/gst/meson.build new file mode 100644 index 000000000..b1569fd57 --- /dev/null +++ b/pipewire/gst/meson.build @@ -0,0 +1,31 @@ +pipewire_gst_sources = [ + 'gstpipewire.c', + 'gstpipewireclock.c', + 'gstpipewiredeviceprovider.c', + 'gstpipewireformat.c', + 'gstpipewirepool.c', + 'gstpipewiresink.c', + 'gstpipewiresrc.c', +] + +pipewire_gst_headers = [ + 'gstpipewireclock.h', + 'gstpipewiredeviceprovider.h', + 'gstpipewireformat.h', + 'gstpipewirepool.h', + 'gstpipewiresink.h', + 'gstpipewiresrc.h', +] + +pipewire_gst_c_args = [ + '-DHAVE_CONFIG_H', +] + +pipewire_gst = shared_library('gstpipewire', + pipewire_gst_sources, + c_args : pipewire_gst_c_args, + include_directories : [configinc, spa_inc], + dependencies : [gobject_dep, glib_dep, gio_dep, gst_dep, pipewire_dep, pipewirecore_dep], + install : true, + install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')), +) diff --git a/pinos/meson.build b/pipewire/meson.build similarity index 88% rename from pinos/meson.build rename to pipewire/meson.build index 08940dcec..6be00b460 100644 --- a/pinos/meson.build +++ b/pipewire/meson.build @@ -1,5 +1,4 @@ -subdir('dbus') subdir('client') subdir('server') subdir('daemon') diff --git a/pipewire/modules/meson.build b/pipewire/modules/meson.build new file mode 100644 index 000000000..bb8143bc4 --- /dev/null +++ b/pipewire/modules/meson.build @@ -0,0 +1,61 @@ +#subdir('gst') +subdir('spa') + +pipewire_module_c_args = [ + '-DHAVE_CONFIG_H', + '-D_GNU_SOURCE', +] + +pipewire_module_flatpak = shared_library('pipewire-module-flatpak', [ 'module-flatpak.c' ], + c_args : pipewire_module_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : modules_install_dir, + dependencies : [dbus_dep, mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) + +pipewire_module_autolink = shared_library('pipewire-module-autolink', [ 'module-autolink.c' ], + c_args : pipewire_module_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : modules_install_dir, + dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) + +pipewire_module_mixer = shared_library('pipewire-module-mixer', [ 'module-mixer.c' ], + c_args : pipewire_module_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : modules_install_dir, + dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) + +#pipewire_module_protocol_dbus = shared_library('pipewire-module-protocol-dbus', [ 'module-protocol-dbus.c', gdbus_target ], +# c_args : pipewire_module_c_args, +# include_directories : [configinc, spa_inc], +# link_with : spalib, +# install : true, +# install_dir : modules_install_dir, +# dependencies : [glib_dep, gio_dep, mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +#) + +pipewire_module_protocol_native = shared_library('pipewire-module-protocol-native', [ 'module-protocol-native.c' ], + c_args : pipewire_module_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : modules_install_dir, + dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) + +pipewire_module_suspend_on_idle = shared_library('pipewire-module-suspend-on-idle', [ 'module-suspend-on-idle.c' ], + c_args : pipewire_module_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : modules_install_dir, + dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) diff --git a/pipewire/modules/module-autolink.c b/pipewire/modules/module-autolink.c new file mode 100644 index 000000000..2a28abfaf --- /dev/null +++ b/pipewire/modules/module-autolink.c @@ -0,0 +1,442 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "config.h" + +#include "pipewire/client/interfaces.h" +#include "pipewire/server/core.h" +#include "pipewire/server/module.h" +#include "pipewire/server/client-node.h" + +struct impl { + struct pw_core *core; + struct pw_properties *properties; + + struct pw_listener global_added; + struct pw_listener global_removed; + + SpaList client_list; +}; + +struct client_info { + struct impl *impl; + struct pw_client *client; + SpaList link; + struct pw_listener resource_added; + struct pw_listener resource_removed; + SpaList node_list; +}; + +struct node_info { + struct impl *impl; + struct client_info *info; + struct pw_node *node; + struct pw_resource *resource; + SpaList link; + struct pw_listener state_changed; + struct pw_listener port_added; + struct pw_listener port_removed; + struct pw_listener port_unlinked; + struct pw_listener link_state_changed; +}; + +static struct node_info * +find_node_info (struct client_info *cinfo, struct pw_node *node) +{ + struct node_info *info; + + spa_list_for_each (info, &cinfo->node_list, link) { + if (info->node == node) + return info; + } + return NULL; +} + +static struct client_info * +find_client_info (struct impl *impl, struct pw_client *client) +{ + struct client_info *info; + + spa_list_for_each (info, &impl->client_list, link) { + if (info->client == client) + return info; + } + return NULL; +} + +static void +node_info_free (struct node_info *info) +{ + spa_list_remove (&info->link); + pw_signal_remove (&info->state_changed); + pw_signal_remove (&info->port_added); + pw_signal_remove (&info->port_removed); + pw_signal_remove (&info->port_unlinked); + pw_signal_remove (&info->link_state_changed); + free (info); +} + +static void +client_info_free (struct client_info *cinfo) +{ + struct node_info *info, *tmp; + + spa_list_remove (&cinfo->link); + pw_signal_remove (&cinfo->resource_added); + pw_signal_remove (&cinfo->resource_removed); + + spa_list_for_each_safe (info, tmp, &cinfo->node_list, link) + node_info_free (info); + + free (cinfo); +} + +static void try_link_port (struct pw_node *node, struct pw_port *port, struct node_info *info); + +static void +on_link_port_unlinked (struct pw_listener *listener, + struct pw_link *link, + struct pw_port *port) +{ + struct node_info *info = SPA_CONTAINER_OF (listener, struct node_info, port_unlinked); + struct impl *impl = info->impl; + + pw_log_debug ("module %p: link %p: port %p unlinked", impl, link, port); + if (port->direction == PW_DIRECTION_OUTPUT && link->input) + try_link_port (link->input->node, link->input, info); +} + +static void +on_link_state_changed (struct pw_listener *listener, + struct pw_link *link, + enum pw_link_state old, + enum pw_link_state state) +{ + struct node_info *info = SPA_CONTAINER_OF (listener, struct node_info, link_state_changed); + struct impl *impl = info->impl; + + switch (state) { + case PW_LINK_STATE_ERROR: + { + struct pw_resource *resource; + + pw_log_debug ("module %p: link %p: state error: %s", impl, link, link->error); + + spa_list_for_each (resource, &link->resource_list, link) { + pw_core_notify_error (resource->client->core_resource, + resource->id, + SPA_RESULT_ERROR, + link->error); + } + if (info->info->client) { + pw_core_notify_error (info->info->client->core_resource, + info->resource->id, + SPA_RESULT_ERROR, + link->error); + } + break; + } + + case PW_LINK_STATE_UNLINKED: + pw_log_debug ("module %p: link %p: unlinked", impl, link); + break; + + case PW_LINK_STATE_INIT: + case PW_LINK_STATE_NEGOTIATING: + case PW_LINK_STATE_ALLOCATING: + case PW_LINK_STATE_PAUSED: + case PW_LINK_STATE_RUNNING: + break; + } +} + +static void +try_link_port (struct pw_node *node, + struct pw_port *port, + struct node_info *info) +{ + struct impl *impl = info->impl; + struct pw_properties *props; + const char *str; + uint32_t path_id; + char *error = NULL; + struct pw_link *link; + struct pw_port *target; + + props = node->properties; + if (props == NULL) { + pw_log_debug ("module %p: node has no properties", impl); + return; + } + + str = pw_properties_get (props, "pipewire.target.node"); + if (str != NULL) + path_id = atoi (str); + else { + str = pw_properties_get (props, "pipewire.autoconnect"); + if (str == NULL || atoi (str) == 0) { + pw_log_debug ("module %p: node does not need autoconnect", impl); + return; + } + path_id = SPA_ID_INVALID; + } + + pw_log_debug ("module %p: try to find and link to node '%d'", impl, path_id); + + target = pw_core_find_port (impl->core, + port, + path_id, + NULL, + 0, + NULL, + &error); + if (target == NULL) + goto error; + + if (port->direction == PW_DIRECTION_OUTPUT) + link = pw_port_link (port, target, NULL, NULL, &error); + else + link = pw_port_link (target, port, NULL, NULL, &error); + + if (link == NULL) + goto error; + + pw_signal_add (&link->port_unlinked, &info->port_unlinked, on_link_port_unlinked); + pw_signal_add (&link->state_changed, &info->link_state_changed, on_link_state_changed); + + pw_link_activate (link); + + return; + +error: + { + pw_log_error ("module %p: can't link node '%s'", impl, error); + if (info->info->client && info->info->client->core_resource) { + pw_core_notify_error (info->info->client->core_resource, + info->resource->id, + SPA_RESULT_ERROR, + error); + } + free (error); + return; + } +} + +static void +on_port_added (struct pw_listener *listener, + struct pw_node *node, + struct pw_port *port) +{ + struct node_info *info = SPA_CONTAINER_OF (listener, struct node_info, port_added); + + try_link_port (node, port, info); +} + +static void +on_port_removed (struct pw_listener *listener, + struct pw_node *node, + struct pw_port *port) +{ +} + +static void +on_node_created (struct pw_node *node, + struct node_info *info) +{ + struct pw_port *port; + + spa_list_for_each (port, &node->input_ports, link) + on_port_added (&info->port_added, node, port); + + spa_list_for_each (port, &node->output_ports, link) + on_port_added (&info->port_added, node, port); +} + +static void +on_state_changed (struct pw_listener *listener, + struct pw_node *node, + enum pw_node_state old, + enum pw_node_state state) +{ + struct node_info *info = SPA_CONTAINER_OF (listener, struct node_info, state_changed); + + if (old == PW_NODE_STATE_CREATING && state == PW_NODE_STATE_SUSPENDED) + on_node_created (node, info); +} + +static void +on_node_added (struct impl *impl, + struct pw_node *node, + struct pw_resource *resource, + struct client_info *cinfo) +{ + struct node_info *info; + + info = calloc (1, sizeof (struct node_info)); + info->impl = impl; + info->node = node; + info->resource = resource; + info->info = cinfo; + spa_list_insert (cinfo->node_list.prev, &info->link); + + spa_list_init (&info->port_unlinked.link); + spa_list_init (&info->link_state_changed.link); + pw_signal_add (&node->port_added, &info->port_added, on_port_added); + pw_signal_add (&node->port_removed, &info->port_removed, on_port_removed); + pw_signal_add (&node->state_changed, &info->state_changed, on_state_changed); + + pw_log_debug ("module %p: node %p added", impl, node); + + if (node->state > PW_NODE_STATE_CREATING) + on_node_created (node, info); +} + +static void +on_resource_added (struct pw_listener *listener, + struct pw_client *client, + struct pw_resource *resource) +{ + struct client_info *cinfo = SPA_CONTAINER_OF (listener, struct client_info, resource_added); + struct impl *impl = cinfo->impl; + + if (resource->type == impl->core->type.client_node) { + struct pw_client_node *cnode = resource->object; + on_node_added (impl, cnode->node, resource, cinfo); + } +} + +static void +on_resource_removed (struct pw_listener *listener, + struct pw_client *client, + struct pw_resource *resource) +{ + struct client_info *cinfo = SPA_CONTAINER_OF (listener, struct client_info, resource_removed); + struct impl *impl = cinfo->impl; + + if (resource->type == impl->core->type.client_node) { + struct pw_client_node *cnode = resource->object; + struct node_info *ninfo; + + if ((ninfo = find_node_info (cinfo, cnode->node))) + node_info_free (ninfo); + + pw_log_debug ("module %p: node %p removed", impl, cnode->node); + } +} + +static void +on_global_added (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) +{ + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added); + + if (global->type == impl->core->type.client) { + struct pw_client *client = global->object; + struct client_info *cinfo; + + cinfo = calloc (1, sizeof (struct client_info)); + cinfo->impl = impl; + cinfo->client = global->object; + spa_list_init (&cinfo->node_list); + + spa_list_insert (impl->client_list.prev, &cinfo->link); + + pw_signal_add (&client->resource_added, &cinfo->resource_added, on_resource_added); + pw_signal_add (&client->resource_removed, &cinfo->resource_removed, on_resource_removed); + + pw_log_debug ("module %p: client %p added", impl, cinfo->client); + } +} + +static void +on_global_removed (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) +{ + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_removed); + + if (global->type == impl->core->type.client) { + struct pw_client *client = global->object; + struct client_info *cinfo; + + if ((cinfo = find_client_info (impl, client))) + client_info_free (cinfo); + + pw_log_debug ("module %p: client %p removed", impl, client); + } +} + +/** + * module_new: + * @core: #struct pw_core + * @properties: #struct pw_properties + * + * Make a new #struct impl object with given @properties + * + * Returns: a new #struct impl + */ +static struct impl * +module_new (struct pw_core *core, + struct pw_properties *properties) +{ + struct impl *impl; + + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("module %p: new", impl); + + impl->core = core; + impl->properties = properties; + + spa_list_init (&impl->client_list); + + pw_signal_add (&core->global_added, &impl->global_added, on_global_added); + pw_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); + + return impl; +} + +#if 0 +static void +module_destroy (struct impl *impl) +{ + pw_log_debug ("module %p: destroy", impl); + + pw_global_destroy (impl->global); + + pw_signal_remove (&impl->global_added); + pw_signal_remove (&impl->global_removed); + pw_signal_remove (&impl->port_added); + pw_signal_remove (&impl->port_removed); + pw_signal_remove (&impl->port_unlinked); + pw_signal_remove (&impl->link_state_changed); + free (impl); +} +#endif + +bool +pipewire__module_init (struct pw_module * module, const char * args) +{ + module->user_data = module_new (module->core, NULL); + return true; +} diff --git a/pinos/modules/module-flatpak.c b/pipewire/modules/module-flatpak.c similarity index 69% rename from pinos/modules/module-flatpak.c rename to pipewire/modules/module-flatpak.c index 402fabb24..a605356e9 100644 --- a/pinos/modules/module-flatpak.c +++ b/pipewire/modules/module-flatpak.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -29,45 +29,45 @@ #include -#include "pinos/client/utils.h" -#include "pinos/server/core.h" -#include "pinos/server/module.h" +#include "pipewire/client/utils.h" +#include "pipewire/server/core.h" +#include "pipewire/server/module.h" -typedef struct { - PinosCore *core; - PinosProperties *properties; +struct impl { + struct pw_core *core; + struct pw_properties *properties; DBusConnection *bus; - PinosListener global_added; - PinosListener global_removed; + struct pw_listener global_added; + struct pw_listener global_removed; SpaList client_list; - PinosAccess access; + struct pw_access access; SpaSource *dispatch_event; -} ModuleImpl; +}; -typedef struct { - ModuleImpl *impl; +struct client_info { + struct impl *impl; SpaList link; - PinosClient *client; + struct pw_client *client; bool is_sandboxed; SpaList async_pending; -} ClientInfo; +}; -typedef struct { +struct async_pending { SpaList link; bool handled; - ClientInfo *info; + struct client_info *info; char *handle; - PinosAccessData *access_data; -} AsyncPending; + struct pw_access_data *access_data; +}; -static ClientInfo * -find_client_info (ModuleImpl *impl, PinosClient *client) +static struct client_info * +find_client_info (struct impl *impl, struct pw_client *client) { - ClientInfo *info; + struct client_info *info; spa_list_for_each (info, &impl->client_list, link) { if (info->client == client) @@ -77,31 +77,31 @@ find_client_info (ModuleImpl *impl, PinosClient *client) } static void -close_request (AsyncPending *p) +close_request (struct async_pending *p) { DBusMessage *m = NULL; - ModuleImpl *impl = p->info->impl; + struct impl *impl = p->info->impl; - pinos_log_debug ("pending %p: handle %s", p, p->handle); + pw_log_debug ("pending %p: handle %s", p, p->handle); if (!(m = dbus_message_new_method_call ("org.freedesktop.portal.Request", p->handle, "org.freedesktop.portal.Request", "Close"))) { - pinos_log_error ("Failed to create message"); + pw_log_error ("Failed to create message"); return; } if (!dbus_connection_send (impl->bus, m, NULL)) - pinos_log_error ("Failed to send message"); + pw_log_error ("Failed to send message"); dbus_message_unref(m); } -static AsyncPending * -find_pending (ClientInfo *cinfo, const char *handle) +static struct async_pending * +find_pending (struct client_info *cinfo, const char *handle) { - AsyncPending *p; + struct async_pending *p; spa_list_for_each (p, &cinfo->async_pending, link) { if (strcmp (p->handle, handle) == 0) @@ -111,25 +111,25 @@ find_pending (ClientInfo *cinfo, const char *handle) } static void -free_pending (PinosAccessData *d) +free_pending (struct pw_access_data *d) { - AsyncPending *p = d->user_data; + struct async_pending *p = d->user_data; if (!p->handled) close_request(p); - pinos_log_debug ("pending %p: handle %s", p, p->handle); + pw_log_debug ("pending %p: handle %s", p, p->handle); spa_list_remove (&p->link); free (p->handle); } static void -add_pending (ClientInfo *cinfo, const char *handle, PinosAccessData *access_data) +add_pending (struct client_info *cinfo, const char *handle, struct pw_access_data *access_data) { - AsyncPending *p; - PinosAccessData *ad; + struct async_pending *p; + struct pw_access_data *ad; - ad = access_data->async_copy (access_data, sizeof (AsyncPending)); + ad = access_data->async_copy (access_data, sizeof (struct async_pending)); ad->free_cb = free_pending; p = ad->user_data; @@ -137,15 +137,15 @@ add_pending (ClientInfo *cinfo, const char *handle, PinosAccessData *access_data p->handle = strdup (handle); p->access_data = ad; p->handled = false; - pinos_log_debug ("pending %p: handle %s", p, handle); + pw_log_debug ("pending %p: handle %s", p, handle); spa_list_insert (cinfo->async_pending.prev, &p->link); } static void -client_info_free (ClientInfo *cinfo) +client_info_free (struct client_info *cinfo) { - AsyncPending *p, *tmp; + struct async_pending *p, *tmp; spa_list_for_each_safe (p, tmp, &cinfo->async_pending, link) { p->access_data->res = SPA_RESULT_NO_PERMISSION; @@ -156,7 +156,7 @@ client_info_free (ClientInfo *cinfo) } static bool -client_is_sandboxed (PinosClient *cl) +client_is_sandboxed (struct pw_client *cl) { char data[2048], *ptr; size_t n, size; @@ -167,10 +167,10 @@ client_is_sandboxed (PinosClient *cl) pid_t pid; if (cl->ucred_valid) { - pinos_log_info ("client has trusted pid %d", cl->ucred.pid); + pw_log_info ("client has trusted pid %d", cl->ucred.pid); } else { - pinos_log_info ("no trusted pid found, assuming not sandboxed\n"); + pw_log_info ("no trusted pid found, assuming not sandboxed\n"); return false; } @@ -202,11 +202,11 @@ client_is_sandboxed (PinosClient *cl) close (fd); result = false; - while ((current = pinos_split_walk (data, "\n", &n, &state)) != NULL) { + while ((current = pw_split_walk (data, "\n", &n, &state)) != NULL) { if (strncmp (current, "1:name=systemd:", strlen ("1:name=systemd:")) == 0) { const char *p = strstr (current, "flatpak-"); if (p && p - current < n) { - pinos_log_info ("found a flatpak cgroup, assuming sandboxed\n"); + pw_log_info ("found a flatpak cgroup, assuming sandboxed\n"); result = true; break; } @@ -216,9 +216,9 @@ client_is_sandboxed (PinosClient *cl) } static bool -check_global_owner (PinosCore *core, - PinosClient *client, - PinosGlobal *global) +check_global_owner (struct pw_core *core, + struct pw_client *client, + struct pw_global *global) { if (global == NULL) return false; @@ -233,12 +233,12 @@ check_global_owner (PinosCore *core, } static SpaResult -do_view_global (PinosAccess *access, - PinosClient *client, - PinosGlobal *global) +do_view_global (struct pw_access *access, + struct pw_client *client, + struct pw_global *global) { if (global->type == client->core->type.link) { - PinosLink *link = global->object; + struct pw_link *link = global->object; /* we must be able to see both nodes */ if (link->output && !check_global_owner (client->core, client, link->output->node->global)) @@ -254,14 +254,14 @@ do_view_global (PinosAccess *access, } static SpaResult -do_create_node (PinosAccess *access, - PinosAccessData *data, +do_create_node (struct pw_access *access, + struct pw_access_data *data, const char *factory_name, const char *name, - PinosProperties *properties) + struct pw_properties *properties) { - ModuleImpl *impl = SPA_CONTAINER_OF (access, ModuleImpl, access); - ClientInfo *cinfo = find_client_info (impl, data->resource->client); + struct impl *impl = SPA_CONTAINER_OF (access, struct impl, access); + struct client_info *cinfo = find_client_info (impl, data->resource->client); if (cinfo->is_sandboxed) data->res = SPA_RESULT_NO_PERMISSION; @@ -276,20 +276,20 @@ do_create_node (PinosAccess *access, static DBusHandlerResult portal_response (DBusConnection *connection, DBusMessage *msg, void *user_data) { - ClientInfo *cinfo = user_data; + struct client_info *cinfo = user_data; if (dbus_message_is_signal (msg, "org.freedesktop.portal.Request", "Response")) { uint32_t response = 2; DBusError error; - AsyncPending *p; - PinosAccessData *d; + struct async_pending *p; + struct pw_access_data *d; dbus_error_init (&error); dbus_connection_remove_filter (connection, portal_response, cinfo); if (!dbus_message_get_args (msg, &error, DBUS_TYPE_UINT32, &response, DBUS_TYPE_INVALID)) { - pinos_log_error("failed to parse Response: %s", error.message); + pw_log_error("failed to parse Response: %s", error.message); dbus_error_free(&error); } @@ -300,7 +300,7 @@ portal_response (DBusConnection *connection, DBusMessage *msg, void *user_data) p->handled = true; d = p->access_data; - pinos_log_debug ("portal check result: %d", response); + pw_log_debug ("portal check result: %d", response); d->res = response == 0 ? SPA_RESULT_OK : SPA_RESULT_NO_PERMISSION; d->complete_cb (d); @@ -311,13 +311,13 @@ portal_response (DBusConnection *connection, DBusMessage *msg, void *user_data) } static SpaResult -do_create_client_node (PinosAccess *access, - PinosAccessData *data, +do_create_client_node (struct pw_access *access, + struct pw_access_data *data, const char *name, - PinosProperties *properties) + struct pw_properties *properties) { - ModuleImpl *impl = SPA_CONTAINER_OF (access, ModuleImpl, access); - ClientInfo *cinfo = find_client_info (impl, data->resource->client); + struct impl *impl = SPA_CONTAINER_OF (access, struct impl, access); + struct client_info *cinfo = find_client_info (impl, data->resource->client); DBusMessage *m = NULL, *r = NULL; DBusError error; pid_t pid; @@ -332,7 +332,7 @@ do_create_client_node (PinosAccess *access, return SPA_RESULT_OK; } - pinos_log_info ("ask portal for client %p", cinfo->client); + pw_log_info ("ask portal for client %p", cinfo->client); dbus_error_init(&error); @@ -382,28 +382,28 @@ do_create_client_node (PinosAccess *access, return SPA_RESULT_RETURN_ASYNC (0); no_method_call: - pinos_log_error ("Failed to create message"); + pw_log_error ("Failed to create message"); return SPA_RESULT_NO_PERMISSION; message_failed: dbus_message_unref(m); return SPA_RESULT_NO_PERMISSION; send_failed: - pinos_log_error ("Failed to call portal: %s", error.message); + pw_log_error ("Failed to call portal: %s", error.message); dbus_error_free(&error); dbus_message_unref(m); return SPA_RESULT_NO_PERMISSION; parse_failed: - pinos_log_error ("Failed to parse AccessDevice result: %s", error.message); + pw_log_error ("Failed to parse AccessDevice result: %s", error.message); dbus_error_free (&error); dbus_message_unref (r); return SPA_RESULT_NO_PERMISSION; subscribe_failed: - pinos_log_error ("Failed to subscribe to Request signal: %s", error.message); + pw_log_error ("Failed to subscribe to Request signal: %s", error.message); dbus_error_free(&error); return SPA_RESULT_NO_PERMISSION; } -static PinosAccess access_checks = +static struct pw_access access_checks = { do_view_global, do_create_node, @@ -411,17 +411,17 @@ static PinosAccess access_checks = }; static void -on_global_added (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) +on_global_added (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) { - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_added); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added); if (global->type == impl->core->type.client) { - PinosClient *client = global->object; - ClientInfo *cinfo; + struct pw_client *client = global->object; + struct client_info *cinfo; - cinfo = calloc (1, sizeof (ClientInfo)); + cinfo = calloc (1, sizeof (struct client_info)); cinfo->impl = impl; cinfo->client = client; cinfo->is_sandboxed = client_is_sandboxed (client); @@ -430,43 +430,43 @@ on_global_added (PinosListener *listener, spa_list_insert (impl->client_list.prev, &cinfo->link); - pinos_log_debug ("module %p: client %p added", impl, client); + pw_log_debug ("module %p: client %p added", impl, client); } } static void -on_global_removed (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) +on_global_removed (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) { - ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_removed); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_removed); if (global->type == impl->core->type.client) { - PinosClient *client = global->object; - ClientInfo *cinfo; + struct pw_client *client = global->object; + struct client_info *cinfo; if ((cinfo = find_client_info (impl, client))) client_info_free (cinfo); - pinos_log_debug ("module %p: client %p removed", impl, client); + pw_log_debug ("module %p: client %p removed", impl, client); } } static void dispatch_cb (SpaLoopUtils *utils, SpaSource *source, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; if (dbus_connection_dispatch (impl->bus) == DBUS_DISPATCH_COMPLETE) - pinos_loop_enable_idle (impl->core->main_loop->loop, source, false); + pw_loop_enable_idle (impl->core->main_loop->loop, source, false); } static void dispatch_status (DBusConnection *conn, DBusDispatchStatus status, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; - pinos_loop_enable_idle (impl->core->main_loop->loop, + pw_loop_enable_idle (impl->core->main_loop->loop, impl->dispatch_event, status == DBUS_DISPATCH_COMPLETE ? false : true); } @@ -518,7 +518,7 @@ handle_io_event (SpaLoopUtils *utils, DBusWatch *watch = userdata; if (!dbus_watch_get_enabled (watch)) { - pinos_log_warn("Asked to handle disabled watch: %p %i", (void*) watch, fd); + pw_log_warn("Asked to handle disabled watch: %p %i", (void*) watch, fd); return; } dbus_watch_handle (watch, io_to_dbus (mask)); @@ -527,14 +527,14 @@ handle_io_event (SpaLoopUtils *utils, static dbus_bool_t add_watch (DBusWatch *watch, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; - pinos_log_debug ("add watch %p %d", watch, dbus_watch_get_unix_fd (watch)); + pw_log_debug ("add watch %p %d", watch, dbus_watch_get_unix_fd (watch)); /* we dup because dbus tends to add the same fd multiple times and our epoll * implementation does not like that */ - source = pinos_loop_add_io (impl->core->main_loop->loop, + source = pw_loop_add_io (impl->core->main_loop->loop, dup (dbus_watch_get_unix_fd (watch)), dbus_to_io (watch), true, @@ -548,22 +548,22 @@ add_watch (DBusWatch *watch, void *userdata) static void remove_watch (DBusWatch *watch, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; if ((source = dbus_watch_get_data (watch))) - pinos_loop_destroy_source (impl->core->main_loop->loop, source); + pw_loop_destroy_source (impl->core->main_loop->loop, source); } static void toggle_watch (DBusWatch *watch, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; source = dbus_watch_get_data (watch); - pinos_loop_update_io (impl->core->main_loop->loop, + pw_loop_update_io (impl->core->main_loop->loop, source, dbus_to_io (watch)); } @@ -588,7 +588,7 @@ handle_timer_event (SpaLoopUtils *utils, SpaSource *source, void *userdata) static dbus_bool_t add_timeout (DBusTimeout *timeout, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; struct timespec ts; uint64_t t; @@ -596,7 +596,7 @@ add_timeout (DBusTimeout *timeout, void *userdata) if (!dbus_timeout_get_enabled (timeout)) return FALSE; - source = pinos_loop_add_timer (impl->core->main_loop->loop, + source = pw_loop_add_timer (impl->core->main_loop->loop, handle_timer_event, timeout); @@ -605,7 +605,7 @@ add_timeout (DBusTimeout *timeout, void *userdata) t = dbus_timeout_get_interval (timeout) * SPA_NSEC_PER_MSEC; ts.tv_sec = t / SPA_NSEC_PER_SEC; ts.tv_nsec = t % SPA_NSEC_PER_SEC; - pinos_loop_update_timer (impl->core->main_loop->loop, + pw_loop_update_timer (impl->core->main_loop->loop, source, &ts, NULL, @@ -616,17 +616,17 @@ add_timeout (DBusTimeout *timeout, void *userdata) static void remove_timeout (DBusTimeout *timeout, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; if ((source = dbus_timeout_get_data (timeout))) - pinos_loop_destroy_source (impl->core->main_loop->loop, source); + pw_loop_destroy_source (impl->core->main_loop->loop, source); } static void toggle_timeout (DBusTimeout *timeout, void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; SpaSource *source; struct timespec ts, *tsp; @@ -641,30 +641,30 @@ toggle_timeout (DBusTimeout *timeout, void *userdata) else { tsp = NULL; } - pinos_loop_update_timer (impl->core->main_loop->loop, source, tsp, NULL, false); + pw_loop_update_timer (impl->core->main_loop->loop, source, tsp, NULL, false); } static void wakeup_main (void *userdata) { - ModuleImpl *impl = userdata; + struct impl *impl = userdata; - pinos_loop_enable_idle (impl->core->main_loop->loop, + pw_loop_enable_idle (impl->core->main_loop->loop, impl->dispatch_event, true); } -static ModuleImpl * -module_new (PinosCore *core, - PinosProperties *properties) +static struct impl * +module_new (struct pw_core *core, + struct pw_properties *properties) { - ModuleImpl *impl; + struct impl *impl; DBusError error; dbus_error_init(&error); - impl = calloc (1, sizeof (ModuleImpl)); - pinos_log_debug ("module %p: new", impl); + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("module %p: new", impl); impl->core = core; impl->properties = properties; @@ -674,7 +674,7 @@ module_new (PinosCore *core, if (impl->bus == NULL) goto error; - impl->dispatch_event = pinos_loop_add_idle (core->main_loop->loop, + impl->dispatch_event = pw_loop_add_idle (core->main_loop->loop, false, dispatch_cb, impl); @@ -689,22 +689,22 @@ module_new (PinosCore *core, spa_list_init (&impl->client_list); - pinos_signal_add (&core->global_added, &impl->global_added, on_global_added); - pinos_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); + pw_signal_add (&core->global_added, &impl->global_added, on_global_added); + pw_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); return impl; error: - pinos_log_error ("Failed to connect to system bus: %s", error.message); + pw_log_error ("Failed to connect to system bus: %s", error.message); dbus_error_free (&error); return NULL; } #if 0 static void -module_destroy (ModuleImpl *impl) +module_destroy (struct impl *impl) { - pinos_log_debug ("module %p: destroy", impl); + pw_log_debug ("module %p: destroy", impl); dbus_connection_close (impl->bus); dbus_connection_unref (impl->bus); @@ -713,7 +713,7 @@ module_destroy (ModuleImpl *impl) #endif bool -pinos__module_init (PinosModule * module, const char * args) +pipewire__module_init (struct pw_module * module, const char * args) { module_new (module->core, NULL); return true; diff --git a/pinos/modules/module-mixer.c b/pipewire/modules/module-mixer.c similarity index 72% rename from pinos/modules/module-mixer.c rename to pipewire/modules/module-mixer.c index 9e50d1c50..4920ddd42 100644 --- a/pinos/modules/module-mixer.c +++ b/pipewire/modules/module-mixer.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -24,24 +24,21 @@ #include "config.h" -#include "pinos/server/core.h" -#include "pinos/server/module.h" +#include "pipewire/server/core.h" +#include "pipewire/server/module.h" #define AUDIOMIXER_LIB "build/spa/plugins/audiomixer/libspa-audiomixer.so" -typedef struct { - PinosCore *core; - PinosProperties *properties; +struct impl { + struct pw_core *core; + struct pw_properties *properties; void *hnd; const SpaHandleFactory *factory; - - PinosListener check_send; - PinosListener check_dispatch; -} ModuleImpl; +}; static const SpaHandleFactory * -find_factory (ModuleImpl *impl) +find_factory (struct impl *impl) { SpaEnumHandleFactoryFunc enum_func; uint32_t index; @@ -49,18 +46,18 @@ find_factory (ModuleImpl *impl) SpaResult res; if ((impl->hnd = dlopen (AUDIOMIXER_LIB, RTLD_NOW)) == NULL) { - pinos_log_error ("can't load %s: %s", AUDIOMIXER_LIB, dlerror()); + pw_log_error ("can't load %s: %s", AUDIOMIXER_LIB, dlerror()); return NULL; } if ((enum_func = dlsym (impl->hnd, "spa_enum_handle_factory")) == NULL) { - pinos_log_error ("can't find enum function"); + pw_log_error ("can't find enum function"); goto no_symbol; } for (index = 0; ; index++) { if ((res = enum_func (&factory, index)) < 0) { if (res != SPA_RESULT_ENUM_END) - pinos_log_error ("can't enumerate factories: %d", res); + pw_log_error ("can't enumerate factories: %d", res); goto enum_failed; } if (strcmp (factory->name, "audiomixer") == 0) @@ -75,15 +72,15 @@ no_symbol: return NULL; } -static PinosNode * -make_node (ModuleImpl *impl) +static struct pw_node * +make_node (struct impl *impl) { SpaHandle *handle; SpaResult res; void *iface; SpaNode *spa_node; SpaClock *spa_clock; - PinosNode *node; + struct pw_node *node; handle = calloc (1, impl->factory->size); if ((res = spa_handle_factory_init (impl->factory, @@ -91,13 +88,13 @@ make_node (ModuleImpl *impl) NULL, impl->core->support, impl->core->n_support)) < 0) { - pinos_log_error ("can't make factory instance: %d", res); + pw_log_error ("can't make factory instance: %d", res); goto init_failed; } if ((res = spa_handle_get_interface (handle, impl->core->type.spa_node, &iface)) < 0) { - pinos_log_error ("can't get interface %d", res); + pw_log_error ("can't get interface %d", res); goto interface_failed; } spa_node = iface; @@ -109,7 +106,7 @@ make_node (ModuleImpl *impl) } spa_clock = iface; - node = pinos_node_new (impl->core, + node = pw_node_new (impl->core, NULL, "audiomixer", false, @@ -125,15 +122,15 @@ init_failed: return NULL; } -static ModuleImpl * -module_new (PinosCore *core, - PinosProperties *properties) +static struct impl * +module_new (struct pw_core *core, + struct pw_properties *properties) { - ModuleImpl *impl; - PinosNode *n; + struct impl *impl; + struct pw_node *n; - impl = calloc (1, sizeof (ModuleImpl)); - pinos_log_debug ("module %p: new", impl); + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("module %p: new", impl); impl->core = core; impl->properties = properties; @@ -143,8 +140,8 @@ module_new (PinosCore *core, spa_list_for_each (n, &core->node_list, link) { const char *str; char *error; - PinosNode *node; - PinosPort *ip, *op; + struct pw_node *node; + struct pw_port *ip, *op; if (n->global == NULL) continue; @@ -152,37 +149,37 @@ module_new (PinosCore *core, if (n->properties == NULL) continue; - if ((str = pinos_properties_get (n->properties, "media.class")) == NULL) + if ((str = pw_properties_get (n->properties, "media.class")) == NULL) continue; if (strcmp (str, "Audio/Sink") != 0) continue; - if ((ip = pinos_node_get_free_port (n, PINOS_DIRECTION_INPUT)) == NULL) + if ((ip = pw_node_get_free_port (n, PW_DIRECTION_INPUT)) == NULL) continue; node = make_node (impl); - op = pinos_node_get_free_port (node, PINOS_DIRECTION_OUTPUT); + op = pw_node_get_free_port (node, PW_DIRECTION_OUTPUT); if (op == NULL) continue; - pinos_port_link (op, ip, NULL, NULL, &error); + pw_port_link (op, ip, NULL, NULL, &error); } return impl; } #if 0 static void -module_destroy (ModuleImpl *impl) +module_destroy (struct impl *impl) { - pinos_log_debug ("module %p: destroy", impl); + pw_log_debug ("module %p: destroy", impl); free (impl); } #endif bool -pinos__module_init (PinosModule * module, const char * args) +pipewire__module_init (struct pw_module * module, const char * args) { module_new (module->core, NULL); return true; diff --git a/pinos/modules/module-protocol-dbus.c b/pipewire/modules/module-protocol-dbus.c similarity index 52% rename from pinos/modules/module-protocol-dbus.c rename to pipewire/modules/module-protocol-dbus.c index 499ca7fed..ae0cdde8a 100644 --- a/pinos/modules/module-protocol-dbus.c +++ b/pipewire/modules/module-protocol-dbus.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -27,34 +27,34 @@ #include "config.h" -#include "pinos/client/pinos.h" -#include "pinos/client/log.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/log.h" -#include "pinos/server/core.h" -#include "pinos/server/node.h" -#include "pinos/server/module.h" -#include "pinos/server/client-node.h" -#include "pinos/server/client.h" -#include "pinos/server/resource.h" -#include "pinos/server/link.h" -#include "pinos/server/node-factory.h" -#include "pinos/server/data-loop.h" -#include "pinos/server/main-loop.h" +#include "pipewire/server/core.h" +#include "pipewire/server/node.h" +#include "pipewire/server/module.h" +#include "pipewire/server/client-node.h" +#include "pipewire/server/client.h" +#include "pipewire/server/resource.h" +#include "pipewire/server/link.h" +#include "pipewire/server/node-factory.h" +#include "pipewire/server/data-loop.h" +#include "pipewire/server/main-loop.h" -#include "pinos/dbus/org-pinos.h" +#include "pipewire/dbus/org-pipewire.h" -#define PINOS_DBUS_SERVICE "org.pinos" -#define PINOS_DBUS_OBJECT_PREFIX "/org/pinos" -#define PINOS_DBUS_OBJECT_SERVER PINOS_DBUS_OBJECT_PREFIX "/server" -#define PINOS_DBUS_OBJECT_CLIENT PINOS_DBUS_OBJECT_PREFIX "/client" -#define PINOS_DBUS_OBJECT_NODE PINOS_DBUS_OBJECT_PREFIX "/node" -#define PINOS_DBUS_OBJECT_LINK PINOS_DBUS_OBJECT_PREFIX "/link" +#define PIPEWIRE_DBUS_SERVICE "org.pipewire" +#define PIPEWIRE_DBUS_OBJECT_PREFIX "/org/pipewire" +#define PIPEWIRE_DBUS_OBJECT_SERVER PIPEWIRE_DBUS_OBJECT_PREFIX "/server" +#define PIPEWIRE_DBUS_OBJECT_CLIENT PIPEWIRE_DBUS_OBJECT_PREFIX "/client" +#define PIPEWIRE_DBUS_OBJECT_NODE PIPEWIRE_DBUS_OBJECT_PREFIX "/node" +#define PIPEWIRE_DBUS_OBJECT_LINK PIPEWIRE_DBUS_OBJECT_PREFIX "/link" -typedef struct { - PinosCore *core; +struct impl { + struct pw_core *core; SpaList link; - PinosProperties *properties; + struct pw_properties *properties; GDBusConnection *connection; GDBusObjectManagerServer *server_manager; @@ -62,49 +62,49 @@ typedef struct { SpaList client_list; SpaList object_list; - PinosListener global_added; - PinosListener global_removed; -} PinosProtocolDBus; + struct pw_listener global_added; + struct pw_listener global_removed; +}; -typedef struct { - PinosProtocolDBus *impl; - SpaList link; - PinosGlobal *global; - void *iface; - PinosObjectSkeleton *skel; - const gchar *object_path; - PinosDestroy destroy; -} PinosProtocolDBusObject; - -typedef struct { - PinosProtocolDBusObject parent; +struct object { + struct impl *impl; SpaList link; - guint id; -} PinosProtocolDBusServer; + struct pw_global *global; + void *iface; + PipeWireObjectSkeleton *skel; + const gchar *object_path; + pw_destroy_t destroy; +}; -typedef struct { - PinosProtocolDBusObject parent; - SpaList link; - gchar *sender; - guint id; -} PinosProtocolDBusClient; +struct server { + struct object parent; + SpaList link; + guint id; +}; -typedef struct { - PinosProtocolDBusObject parent; - PinosListener state_changed; -} PinosProtocolDBusNode; +struct client { + struct object parent; + SpaList link; + gchar *sender; + guint id; +}; + +struct node { + struct object parent; + struct pw_listener state_changed; +}; static void -object_export (PinosProtocolDBusObject *this) +object_export (struct object *this) { g_dbus_object_manager_server_export (this->impl->server_manager, G_DBUS_OBJECT_SKELETON (this->skel)); this->object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (this->skel)); - pinos_log_debug ("protocol-dbus %p: export object %s", this->impl, this->object_path); + pw_log_debug ("protocol-dbus %p: export object %s", this->impl, this->object_path); } static void -object_unexport (PinosProtocolDBusObject *this) +object_unexport (struct object *this) { if (this->object_path) g_dbus_object_manager_server_unexport (this->impl->server_manager, this->object_path); @@ -112,14 +112,14 @@ object_unexport (PinosProtocolDBusObject *this) static void * object_new (size_t size, - PinosProtocolDBus *impl, - PinosGlobal *global, + struct impl *impl, + struct pw_global *global, void *iface, - PinosObjectSkeleton *skel, + PipeWireObjectSkeleton *skel, bool export, - PinosDestroy destroy) + pw_destroy_t destroy) { - PinosProtocolDBusObject *this; + struct object *this; this = calloc (1, size); this->impl = impl; @@ -137,7 +137,7 @@ object_new (size_t size, } static void -object_destroy (PinosProtocolDBusObject *this) +object_destroy (struct object *this) { spa_list_remove (&this->link); @@ -150,11 +150,11 @@ object_destroy (PinosProtocolDBusObject *this) free (this); } -static PinosProtocolDBusObject * -find_object (PinosProtocolDBus *impl, +static struct object * +find_object (struct impl *impl, void *object) { - PinosProtocolDBusObject *obj; + struct object *obj; spa_list_for_each (obj, &impl->object_list, link) { if (obj->global->object == object) return obj; @@ -163,7 +163,7 @@ find_object (PinosProtocolDBus *impl, } #if 0 -struct _PinosProperties { +struct _struct pw_properties { GHashTable *hashtable; }; @@ -175,7 +175,7 @@ add_to_variant (const gchar *key, const gchar *value, GVariantBuilder *b) #endif static void -pinos_properties_init_builder (PinosProperties *properties, +pw_properties_init_builder (struct pw_properties *properties, GVariantBuilder *builder) { g_variant_builder_init (builder, G_VARIANT_TYPE ("a{sv}")); @@ -183,22 +183,22 @@ pinos_properties_init_builder (PinosProperties *properties, } static GVariant * -pinos_properties_to_variant (PinosProperties *properties) +pw_properties_to_variant (struct pw_properties *properties) { GVariantBuilder builder; - pinos_properties_init_builder (properties, &builder); + pw_properties_init_builder (properties, &builder); return g_variant_builder_end (&builder); } -static PinosProperties * -pinos_properties_from_variant (GVariant *variant) +static struct pw_properties * +pw_properties_from_variant (GVariant *variant) { - PinosProperties *props; + struct pw_properties *props; GVariantIter iter; //GVariant *value; //gchar *key; - props = pinos_properties_new (NULL, NULL); + props = pw_properties_new (NULL, NULL); g_variant_iter_init (&iter, variant); // while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) @@ -215,13 +215,13 @@ client_name_appeared_handler (GDBusConnection *connection, const gchar *name_owner, gpointer user_data) { - PinosProtocolDBusClient *this = user_data; - pinos_log_debug ("client %p: appeared %s %s", this, name, name_owner); + struct client *this = user_data; + pw_log_debug ("client %p: appeared %s %s", this, name, name_owner); object_export (&this->parent); } static void -client_destroy (PinosProtocolDBusClient *this) +client_destroy (struct client *this) { if (this->sender) { spa_list_remove (&this->link); @@ -234,26 +234,26 @@ client_name_vanished_handler (GDBusConnection *connection, const gchar *name, gpointer user_data) { - PinosProtocolDBusClient *this = user_data; - pinos_log_debug ("client %p: vanished %s", this, name); + struct client *this = user_data; + pw_log_debug ("client %p: vanished %s", this, name); g_bus_unwatch_name (this->id); /* destroying the client here will trigger the global_removed, which * will then destroy our wrapper */ - pinos_client_destroy (this->parent.global->object); + pw_client_destroy (this->parent.global->object); } -static PinosProtocolDBusClient * -client_new (PinosProtocolDBus *impl, +static struct client * +client_new (struct impl *impl, const char *sender) { - PinosProtocolDBusClient *this; - PinosClient *client; + struct client *this; + struct pw_client *client; - client = pinos_client_new (impl->core, NULL, NULL); + client = pw_client_new (impl->core, NULL, NULL); - if ((this = (PinosProtocolDBusClient *) find_object (impl, client))) { - pinos_client1_set_sender (this->parent.iface, sender); + if ((this = (struct client *) find_object (impl, client))) { + pipewire_client1_set_sender (this->parent.iface, sender); this->sender = strdup (sender); this->id = g_bus_watch_name_on_connection (impl->connection, @@ -269,12 +269,12 @@ client_new (PinosProtocolDBus *impl, return this; } -static PinosClient * -sender_get_client (PinosProtocolDBus *impl, +static struct pw_client * +sender_get_client (struct impl *impl, const char *sender, bool create) { - PinosProtocolDBusClient *client; + struct client *client; spa_list_for_each (client, &impl->client_list, link) { if (strcmp (client->sender, sender) == 0) @@ -289,37 +289,37 @@ sender_get_client (PinosProtocolDBus *impl, } static bool -handle_create_node (PinosDaemon1 *interface, +handle_create_node (PipeWireDaemon1 *interface, GDBusMethodInvocation *invocation, const char *arg_factory_name, const char *arg_name, GVariant *arg_properties, gpointer user_data) { - PinosProtocolDBus *impl = user_data; - PinosNodeFactory *factory; - PinosNode *node; - PinosClient *client; + struct impl *impl = user_data; + struct pw_node_factory *factory; + struct pw_node *node; + struct pw_client *client; const char *sender, *object_path; - PinosProperties *props; - PinosProtocolDBusObject *object; + struct pw_properties *props; + struct object *object; sender = g_dbus_method_invocation_get_sender (invocation); client = sender_get_client (impl, sender, TRUE); - pinos_log_debug ("protocol-dbus %p: create node: %s", impl, sender); + pw_log_debug ("protocol-dbus %p: create node: %s", impl, sender); - props = pinos_properties_from_variant (arg_properties); + props = pw_properties_from_variant (arg_properties); - factory = pinos_core_find_node_factory (impl->core, arg_factory_name); + factory = pw_core_find_node_factory (impl->core, arg_factory_name); if (factory == NULL) goto no_factory; - node = pinos_node_factory_create_node (factory, + node = pw_node_factory_create_node (factory, client, arg_name, props); - pinos_properties_free (props); + pw_properties_free (props); if (node == NULL) goto no_node; @@ -328,14 +328,14 @@ handle_create_node (PinosDaemon1 *interface, if (object == NULL) goto object_failed; - pinos_resource_new (client, + pw_resource_new (client, SPA_ID_INVALID, impl->core->type.node, node, - (PinosDestroy) pinos_node_destroy); + (pw_destroy_t) pw_node_destroy); object_path = object->object_path; - pinos_log_debug ("protocol-dbus %p: added node %p with path %s", impl, node, object_path); + pw_log_debug ("protocol-dbus %p: added node %p with path %s", impl, node, object_path); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", object_path)); return TRUE; @@ -343,73 +343,73 @@ handle_create_node (PinosDaemon1 *interface, /* ERRORS */ no_factory: { - pinos_log_debug ("protocol-dbus %p: could not find factory named %s", impl, arg_factory_name); + pw_log_debug ("protocol-dbus %p: could not find factory named %s", impl, arg_factory_name); g_dbus_method_invocation_return_dbus_error (invocation, - "org.pinos.Error", "can't find factory"); + "org.pipewire.Error", "can't find factory"); return TRUE; } no_node: { - pinos_log_debug ("protocol-dbus %p: could not create node named %s from factory %s", impl, arg_name, arg_factory_name); + pw_log_debug ("protocol-dbus %p: could not create node named %s from factory %s", impl, arg_name, arg_factory_name); g_dbus_method_invocation_return_dbus_error (invocation, - "org.pinos.Error", "can't create node"); + "org.pipewire.Error", "can't create node"); return TRUE; } object_failed: { - pinos_log_debug ("protocol-dbus %p: could not create dbus object", impl); + pw_log_debug ("protocol-dbus %p: could not create dbus object", impl); g_dbus_method_invocation_return_dbus_error (invocation, - "org.pinos.Error", "can't create object"); + "org.pipewire.Error", "can't create object"); return TRUE; } } static void -on_node_state_changed (PinosListener *listener, - PinosNode *node, - PinosNodeState old, - PinosNodeState state) +on_node_state_changed (struct pw_listener *listener, + struct pw_node *node, + enum pw_node_state old, + enum pw_node_state state) { - PinosProtocolDBusNode *object = SPA_CONTAINER_OF (listener, PinosProtocolDBusNode, state_changed); + struct node *object = SPA_CONTAINER_OF (listener, struct node, state_changed); - pinos_log_debug ("protocol-dbus %p: node %p state change %s -> %s", object->parent.impl, node, - pinos_node_state_as_string (old), - pinos_node_state_as_string (state)); + pw_log_debug ("protocol-dbus %p: node %p state change %s -> %s", object->parent.impl, node, + pw_node_state_as_string (old), + pw_node_state_as_string (state)); - pinos_node1_set_state (object->parent.iface, node->state); + pipewire_node1_set_state (object->parent.iface, node->state); } static bool -handle_create_client_node (PinosDaemon1 *interface, +handle_create_client_node (PipeWireDaemon1 *interface, GDBusMethodInvocation *invocation, const char *arg_name, GVariant *arg_properties, gpointer user_data) { - PinosProtocolDBus *impl = user_data; - PinosClientNode *node; - PinosClient *client; + struct impl *impl = user_data; + struct pw_client_node *node; + struct pw_client *client; SpaResult res; const char *sender, *object_path, *target_node; - PinosProperties *props; + struct pw_properties *props; GError *error = NULL; GUnixFDList *fdlist; int ctrl_fd, data_rfd, data_wfd; int ctrl_idx, data_ridx, data_widx; - PinosProtocolDBusObject *object; + struct object *object; int fd[2]; sender = g_dbus_method_invocation_get_sender (invocation); client = sender_get_client (impl, sender, TRUE); - pinos_log_debug ("protocol-dbus %p: create client-node: %s", impl, sender); - props = pinos_properties_from_variant (arg_properties); + pw_log_debug ("protocol-dbus %p: create client-node: %s", impl, sender); + props = pw_properties_from_variant (arg_properties); - target_node = pinos_properties_get (props, "pinos.target.node"); + target_node = pw_properties_get (props, "pipewire.target.node"); if (target_node) { - if (strncmp (target_node, "/org/pinos/node_", strlen ("/org/pinos/node_")) == 0) { - pinos_properties_setf (props, "pinos.target.node", "%s", - target_node + strlen ("/org/pinos/node_")); + if (strncmp (target_node, "/org/pipewire/node_", strlen ("/org/pipewire/node_")) == 0) { + pw_properties_setf (props, "pipewire.target.node", "%s", + target_node + strlen ("/org/pipewire/node_")); } } @@ -418,7 +418,7 @@ handle_create_client_node (PinosDaemon1 *interface, ctrl_fd = fd[1]; - node = pinos_client_node_new (client, + node = pw_client_node_new (client, SPA_ID_INVALID, arg_name, props); @@ -427,11 +427,11 @@ handle_create_client_node (PinosDaemon1 *interface, if (object == NULL) goto object_failed; - if ((res = pinos_client_node_get_fds (node, &data_rfd, &data_wfd)) < 0) + if ((res = pw_client_node_get_fds (node, &data_rfd, &data_wfd)) < 0) goto no_socket; object_path = object->object_path; - pinos_log_debug ("protocol-dbus %p: add client-node %p, %s", impl, node, object_path); + pw_log_debug ("protocol-dbus %p: add client-node %p, %s", impl, node, object_path); fdlist = g_unix_fd_list_new (); ctrl_idx = g_unix_fd_list_append (fdlist, ctrl_fd, &error); @@ -446,18 +446,18 @@ handle_create_client_node (PinosDaemon1 *interface, object_failed: { - pinos_log_debug ("protocol-dbus %p: could not create object", impl); + pw_log_debug ("protocol-dbus %p: could not create object", impl); goto exit_error; } no_socket_pair: { - pinos_log_debug ("protocol-dbus %p: could not create socketpair: %s", impl, strerror (errno)); + pw_log_debug ("protocol-dbus %p: could not create socketpair: %s", impl, strerror (errno)); goto exit_error; } no_socket: { - pinos_log_debug ("protocol-dbus %p: could not create socket: %s", impl, strerror (errno)); - pinos_client_node_destroy (node); + pw_log_debug ("protocol-dbus %p: could not create socket: %s", impl, strerror (errno)); + pw_client_node_destroy (node); goto exit_error; } exit_error: @@ -473,7 +473,7 @@ bus_acquired_handler (GDBusConnection *connection, const char *name, gpointer user_data) { - PinosProtocolDBus *impl = user_data; + struct impl *impl = user_data; GDBusObjectManagerServer *manager = impl->server_manager; impl->connection = connection; @@ -492,7 +492,7 @@ name_lost_handler (GDBusConnection *connection, const char *name, gpointer user_data) { - PinosProtocolDBus *impl = user_data; + struct impl *impl = user_data; GDBusObjectManagerServer *manager = impl->server_manager; g_dbus_object_manager_server_set_connection (manager, connection); @@ -500,13 +500,13 @@ name_lost_handler (GDBusConnection *connection, } static bool -handle_node_remove (PinosNode1 *interface, +handle_node_remove (PipeWireNode1 *interface, GDBusMethodInvocation *invocation, gpointer user_data) { - PinosNode *this = user_data; + struct pw_node *this = user_data; - pinos_log_debug ("node %p: remove", this); + pw_log_debug ("node %p: remove", this); g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); @@ -514,90 +514,90 @@ handle_node_remove (PinosNode1 *interface, } static void -on_global_added (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) +on_global_added (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) { - PinosProtocolDBus *impl = SPA_CONTAINER_OF (listener, PinosProtocolDBus, global_added); - PinosObjectSkeleton *skel; + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added); + PipeWireObjectSkeleton *skel; if (global->type == impl->core->type.client) { - PinosClient1 *iface; - PinosClient *client = global->object; - PinosProperties *props = client->properties; + PipeWireClient1 *iface; + struct pw_client *client = global->object; + struct pw_properties *props = client->properties; char *path; - asprintf (&path, "%s_%u", PINOS_DBUS_OBJECT_CLIENT, global->id); - skel = pinos_object_skeleton_new (path); + asprintf (&path, "%s_%u", PIPEWIRE_DBUS_OBJECT_CLIENT, global->id); + skel = pipewire_object_skeleton_new (path); free (path); - iface = pinos_client1_skeleton_new (); - pinos_client1_set_properties (iface, props ? pinos_properties_to_variant (props) : NULL); - pinos_object_skeleton_set_client1 (skel, iface); + iface = pipewire_client1_skeleton_new (); + pipewire_client1_set_properties (iface, props ? pw_properties_to_variant (props) : NULL); + pipewire_object_skeleton_set_client1 (skel, iface); - object_new (sizeof (PinosProtocolDBusClient), + object_new (sizeof (struct client), impl, global, iface, skel, false, - (PinosDestroy) client_destroy); + (pw_destroy_t) client_destroy); } else if (global->type == impl->core->type.node) { - PinosNode1 *iface; - PinosNode *node = global->object; - PinosProperties *props = node->properties; + PipeWireNode1 *iface; + struct pw_node *node = global->object; + struct pw_properties *props = node->properties; char *path; - PinosProtocolDBusNode *obj; + struct node *obj; - asprintf (&path, "%s_%u", PINOS_DBUS_OBJECT_NODE, global->id); - skel = pinos_object_skeleton_new (path); + asprintf (&path, "%s_%u", PIPEWIRE_DBUS_OBJECT_NODE, global->id); + skel = pipewire_object_skeleton_new (path); free (path); - iface = pinos_node1_skeleton_new (); + iface = pipewire_node1_skeleton_new (); g_signal_connect (iface, "handle-remove", (GCallback) handle_node_remove, node); - pinos_node1_set_state (iface, node->state); - pinos_node1_set_owner (iface, "/"); - pinos_node1_set_name (iface, node->name); - pinos_node1_set_properties (iface, props ? pinos_properties_to_variant (props) : NULL); - pinos_object_skeleton_set_node1 (skel, iface); + pipewire_node1_set_state (iface, node->state); + pipewire_node1_set_owner (iface, "/"); + pipewire_node1_set_name (iface, node->name); + pipewire_node1_set_properties (iface, props ? pw_properties_to_variant (props) : NULL); + pipewire_object_skeleton_set_node1 (skel, iface); - obj = object_new (sizeof (PinosProtocolDBusNode), + obj = object_new (sizeof (struct node), impl, global, iface, skel, true, NULL); - pinos_signal_add (&node->state_changed, &obj->state_changed, on_node_state_changed); + pw_signal_add (&node->state_changed, &obj->state_changed, on_node_state_changed); } else if (global->object == impl) { - PinosProtocolDBus *proto = global->object; - PinosProtocolDBusServer *server; - PinosDaemon1 *iface; + struct impl *proto = global->object; + struct server *server; + PipeWireDaemon1 *iface; char *path; - iface = pinos_daemon1_skeleton_new (); + iface = pipewire_daemon1_skeleton_new (); g_signal_connect (iface, "handle-create-node", (GCallback) handle_create_node, proto); g_signal_connect (iface, "handle-create-client-node", (GCallback) handle_create_client_node, proto); - asprintf (&path, "%s_%u", PINOS_DBUS_OBJECT_SERVER, global->id); - skel = pinos_object_skeleton_new (path); + asprintf (&path, "%s_%u", PIPEWIRE_DBUS_OBJECT_SERVER, global->id); + skel = pipewire_object_skeleton_new (path); free (path); - pinos_daemon1_set_user_name (iface, g_get_user_name ()); - pinos_daemon1_set_host_name (iface, g_get_host_name ()); - pinos_daemon1_set_version (iface, PACKAGE_VERSION); - pinos_daemon1_set_name (iface, PACKAGE_NAME); - pinos_daemon1_set_cookie (iface, g_random_int()); - pinos_daemon1_set_properties (iface, proto->properties ? - pinos_properties_to_variant (proto->properties): + pipewire_daemon1_set_user_name (iface, g_get_user_name ()); + pipewire_daemon1_set_host_name (iface, g_get_host_name ()); + pipewire_daemon1_set_version (iface, PACKAGE_VERSION); + pipewire_daemon1_set_name (iface, PACKAGE_NAME); + pipewire_daemon1_set_cookie (iface, g_random_int()); + pipewire_daemon1_set_properties (iface, proto->properties ? + pw_properties_to_variant (proto->properties): NULL); - pinos_object_skeleton_set_daemon1 (skel, iface); + pipewire_object_skeleton_set_daemon1 (skel, iface); - server = object_new (sizeof (PinosProtocolDBusServer), + server = object_new (sizeof (struct server), impl, global, iface, @@ -605,7 +605,7 @@ on_global_added (PinosListener *listener, true, NULL); server->id = g_bus_own_name (G_BUS_TYPE_SESSION, - PINOS_DBUS_SERVICE, + PIPEWIRE_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_REPLACE, bus_acquired_handler, name_acquired_handler, @@ -613,36 +613,36 @@ on_global_added (PinosListener *listener, proto, NULL); } else if (global->type == impl->core->type.link) { - PinosLink1 *iface; - PinosLink *link = global->object; - PinosProtocolDBusObject *obj; + PipeWireLink1 *iface; + struct pw_link *link = global->object; + struct object *obj; char *path; - asprintf (&path, "%s_%u", PINOS_DBUS_OBJECT_LINK, global->id); - skel = pinos_object_skeleton_new (path); + asprintf (&path, "%s_%u", PIPEWIRE_DBUS_OBJECT_LINK, global->id); + skel = pipewire_object_skeleton_new (path); free (path); - iface = pinos_link1_skeleton_new (); + iface = pipewire_link1_skeleton_new (); obj = link->output ? find_object (impl, link->output->node) : NULL; if (obj) { - pinos_link1_set_output_node (iface, obj->object_path); - pinos_link1_set_output_port (iface, link->output->port_id); + pipewire_link1_set_output_node (iface, obj->object_path); + pipewire_link1_set_output_port (iface, link->output->port_id); } else { - pinos_link1_set_output_node (iface, "/"); - pinos_link1_set_output_port (iface, SPA_ID_INVALID); + pipewire_link1_set_output_node (iface, "/"); + pipewire_link1_set_output_port (iface, SPA_ID_INVALID); } obj = link->input ? find_object (impl, link->input->node) : NULL; if (obj) { - pinos_link1_set_input_node (iface, obj->object_path); - pinos_link1_set_input_port (iface, link->input->port_id); + pipewire_link1_set_input_node (iface, obj->object_path); + pipewire_link1_set_input_port (iface, link->input->port_id); } else { - pinos_link1_set_output_node (iface, "/"); - pinos_link1_set_output_port (iface, SPA_ID_INVALID); + pipewire_link1_set_output_node (iface, "/"); + pipewire_link1_set_output_port (iface, SPA_ID_INVALID); } - pinos_object_skeleton_set_link1 (skel, iface); + pipewire_object_skeleton_set_link1 (skel, iface); - object_new (sizeof (PinosProtocolDBusObject), + object_new (sizeof (struct object), impl, global, iface, @@ -653,25 +653,25 @@ on_global_added (PinosListener *listener, } static void -on_global_removed (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) +on_global_removed (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) { - PinosProtocolDBus *impl = SPA_CONTAINER_OF (listener, PinosProtocolDBus, global_removed); - PinosProtocolDBusObject *object; + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_removed); + struct object *object; if ((object = find_object (impl, global->object))) object_destroy (object); } -static PinosProtocolDBus * -pinos_protocol_dbus_new (PinosCore *core, - PinosProperties *properties) +static struct impl * +pw_protocol_dbus_new (struct pw_core *core, + struct pw_properties *properties) { - PinosProtocolDBus *impl; + struct impl *impl; - impl = calloc (1, sizeof (PinosProtocolDBus)); - pinos_log_debug ("protocol-dbus %p: new", impl); + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("protocol-dbus %p: new", impl); impl->core = core; impl->properties = properties; @@ -679,23 +679,23 @@ pinos_protocol_dbus_new (PinosCore *core, spa_list_init (&impl->client_list); spa_list_init (&impl->object_list); - pinos_signal_add (&core->global_added, &impl->global_added, on_global_added); - pinos_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); + pw_signal_add (&core->global_added, &impl->global_added, on_global_added); + pw_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); - impl->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX); + impl->server_manager = g_dbus_object_manager_server_new (PIPEWIRE_DBUS_OBJECT_PREFIX); return impl; } #if 0 static void -pinos_protocol_dbus_destroy (PinosProtocolDBus *impl) +pw_protocol_dbus_destroy (struct impl *impl) { - PinosProtocolDBusObject *object, *tmp; + struct object *object, *tmp; - pinos_log_debug ("protocol-dbus %p: destroy", impl); + pw_log_debug ("protocol-dbus %p: destroy", impl); - pinos_global_destroy (impl->global); + pw_global_destroy (impl->global); spa_list_for_each_safe (object, tmp, &impl->object_list, link) object_destroy (object); @@ -705,9 +705,9 @@ pinos_protocol_dbus_destroy (PinosProtocolDBus *impl) g_bus_unown_name (impl->id); #endif - pinos_signal_remove (&impl->global_added); - pinos_signal_remove (&impl->global_removed); - pinos_signal_remove (&impl->node_state_changed); + pw_signal_remove (&impl->global_added); + pw_signal_remove (&impl->global_removed); + pw_signal_remove (&impl->node_state_changed); g_clear_object (&impl->server_manager); @@ -716,8 +716,8 @@ pinos_protocol_dbus_destroy (PinosProtocolDBus *impl) #endif bool -pinos__module_init (PinosModule * module, const char * args) +pipewire__module_init (struct pw_module * module, const char * args) { - pinos_protocol_dbus_new (module->core, NULL); + pw_protocol_dbus_new (module->core, NULL); return TRUE; } diff --git a/pinos/modules/module-protocol-native.c b/pipewire/modules/module-protocol-native.c similarity index 52% rename from pinos/modules/module-protocol-native.c rename to pipewire/modules/module-protocol-native.c index 0fcba30c9..947ffc30a 100644 --- a/pinos/modules/module-protocol-native.c +++ b/pipewire/modules/module-protocol-native.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -29,21 +29,21 @@ #include "config.h" -#include "pinos/client/pinos.h" -#include "pinos/client/log.h" -#include "pinos/client/interfaces.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/log.h" +#include "pipewire/client/interfaces.h" -#include "pinos/server/core.h" -#include "pinos/server/protocol-native.h" -#include "pinos/server/node.h" -#include "pinos/server/module.h" -#include "pinos/server/client-node.h" -#include "pinos/server/client.h" -#include "pinos/server/resource.h" -#include "pinos/server/link.h" -#include "pinos/server/node-factory.h" -#include "pinos/server/data-loop.h" -#include "pinos/server/main-loop.h" +#include "pipewire/server/core.h" +#include "pipewire/server/protocol-native.h" +#include "pipewire/server/node.h" +#include "pipewire/server/module.h" +#include "pipewire/server/client-node.h" +#include "pipewire/server/client.h" +#include "pipewire/server/resource.h" +#include "pipewire/server/link.h" +#include "pipewire/server/node-factory.h" +#include "pipewire/server/data-loop.h" +#include "pipewire/server/main-loop.h" #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX 108 @@ -52,71 +52,71 @@ #define LOCK_SUFFIX ".lock" #define LOCK_SUFFIXLEN 5 -typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size); +typedef bool (*demarshal_func_t) (void *object, void *data, size_t size); -typedef struct { +struct socket { int fd; int fd_lock; struct sockaddr_un addr; char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN]; - PinosLoop *loop; + struct pw_loop *loop; SpaSource *source; char *core_name; SpaList link; -} Socket; +}; -typedef struct { - PinosCore *core; - SpaList link; +struct impl { + struct pw_core *core; + SpaList link; - PinosProperties *properties; + struct pw_properties *properties; SpaList socket_list; SpaList client_list; - PinosListener before_iterate; -} PinosProtocolNative; + struct pw_listener before_iterate; +}; -typedef struct { - PinosProtocolNative *impl; - SpaList link; - PinosClient *client; - int fd; - SpaSource *source; - PinosConnection *connection; - PinosListener resource_added; -} PinosProtocolNativeClient; +struct native_client { + struct impl *impl; + SpaList link; + struct pw_client *client; + int fd; + SpaSource *source; + struct pw_connection *connection; + struct pw_listener resource_added; +}; static void -client_destroy (PinosProtocolNativeClient *this) +client_destroy (struct native_client *this) { - pinos_loop_destroy_source (this->impl->core->main_loop->loop, - this->source); - pinos_client_destroy (this->client); + pw_loop_destroy_source (this->impl->core->main_loop->loop, + this->source); + pw_client_destroy (this->client); spa_list_remove (&this->link); - pinos_connection_destroy (this->connection); + pw_connection_destroy (this->connection); close (this->fd); free (this); } static void -on_resource_added (PinosListener *listener, - PinosClient *client, - PinosResource *resource) +on_resource_added (struct pw_listener *listener, + struct pw_client *client, + struct pw_resource *resource) { - pinos_protocol_native_server_setup (resource); + pw_protocol_native_server_setup (resource); } static void -on_before_iterate (PinosListener *listener, - PinosLoop *loop) +on_before_iterate (struct pw_listener *listener, + struct pw_loop *loop) { - PinosProtocolNative *this = SPA_CONTAINER_OF (listener, PinosProtocolNative, before_iterate); - PinosProtocolNativeClient *client, *tmp; + struct impl *this = SPA_CONTAINER_OF (listener, struct impl, before_iterate); + struct native_client *client, *tmp; spa_list_for_each_safe (client, tmp, &this->client_list, link) - pinos_connection_flush (client->connection); + pw_connection_flush (client->connection); } static void @@ -126,40 +126,40 @@ connection_data (SpaLoopUtils *utils, SpaIO mask, void *data) { - PinosProtocolNativeClient *client = data; - PinosConnection *conn = client->connection; + struct native_client *client = data; + struct pw_connection *conn = client->connection; uint8_t opcode; uint32_t id; uint32_t size; - PinosClient *c = client->client; + struct pw_client *c = client->client; void *message; if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { - pinos_log_error ("protocol-native %p: got connection error", client->impl); + pw_log_error ("protocol-native %p: got connection error", client->impl); client_destroy (client); return; } if (mask & SPA_IO_IN) { - while (pinos_connection_get_next (conn, &opcode, &id, &message, &size)) { - PinosResource *resource; - const PinosDemarshalFunc *demarshal; + while (pw_connection_get_next (conn, &opcode, &id, &message, &size)) { + struct pw_resource *resource; + const demarshal_func_t *demarshal; - pinos_log_trace ("protocol-native %p: got message %d from %u", client->impl, opcode, id); + pw_log_trace ("protocol-native %p: got message %d from %u", client->impl, opcode, id); - resource = pinos_map_lookup (&c->objects, id); + resource = pw_map_lookup (&c->objects, id); if (resource == NULL) { - pinos_log_error ("protocol-native %p: unknown resource %u", client->impl, id); + pw_log_error ("protocol-native %p: unknown resource %u", client->impl, id); continue; } if (opcode >= resource->iface->n_methods) { - pinos_log_error ("protocol-native %p: invalid method %u", client->impl, opcode); + pw_log_error ("protocol-native %p: invalid method %u", client->impl, opcode); client_destroy (client); break; } demarshal = resource->iface->methods; if (!demarshal[opcode] || !demarshal[opcode] (resource, message, size)) { - pinos_log_error ("protocol-native %p: invalid message received", client->impl); + pw_log_error ("protocol-native %p: invalid message received", client->impl); client_destroy (client); break; } @@ -167,43 +167,43 @@ connection_data (SpaLoopUtils *utils, } } -static PinosProtocolNativeClient * -client_new (PinosProtocolNative *impl, - int fd) +static struct native_client * +client_new (struct impl *impl, + int fd) { - PinosProtocolNativeClient *this; - PinosClient *client; + struct native_client *this; + struct pw_client *client; socklen_t len; struct ucred ucred, *ucredp; - this = calloc (1, sizeof (PinosProtocolNativeClient)); + this = calloc (1, sizeof (struct native_client)); if (this == NULL) goto no_native_client; this->impl = impl; this->fd = fd; - this->source = pinos_loop_add_io (impl->core->main_loop->loop, - this->fd, - SPA_IO_ERR | SPA_IO_HUP, - false, - connection_data, - this); + this->source = pw_loop_add_io (impl->core->main_loop->loop, + this->fd, + SPA_IO_ERR | SPA_IO_HUP, + false, + connection_data, + this); if (this->source == NULL) goto no_source; - this->connection = pinos_connection_new (fd); + this->connection = pw_connection_new (fd); if (this->connection == NULL) goto no_connection; len = sizeof (ucred); if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) { - pinos_log_error ("no peercred: %m"); + pw_log_error ("no peercred: %m"); ucredp = NULL; } else { ucredp = &ucred; } - client = pinos_client_new (impl->core, ucredp, NULL); + client = pw_client_new (impl->core, ucredp, NULL); if (client == NULL) goto no_client; @@ -213,33 +213,33 @@ client_new (PinosProtocolNative *impl, spa_list_insert (impl->client_list.prev, &this->link); - pinos_signal_add (&client->resource_added, - &this->resource_added, - on_resource_added); + pw_signal_add (&client->resource_added, + &this->resource_added, + on_resource_added); - pinos_global_bind (impl->core->global, - client, - 0, - 0); + pw_global_bind (impl->core->global, + client, + 0, + 0); return this; no_client: - pinos_connection_destroy (this->connection); + pw_connection_destroy (this->connection); no_connection: - pinos_loop_destroy_source (impl->core->main_loop->loop, - this->source); + pw_loop_destroy_source (impl->core->main_loop->loop, + this->source); no_source: free (this); no_native_client: return NULL; } -static Socket * +static struct socket * create_socket (void) { - Socket *s; + struct socket *s; - if ((s = calloc(1, sizeof (Socket))) == NULL) + if ((s = calloc(1, sizeof (struct socket))) == NULL) return NULL; s->fd = -1; @@ -248,10 +248,10 @@ create_socket (void) } static void -destroy_socket (Socket *s) +destroy_socket (struct socket *s) { if (s->source) - pinos_loop_destroy_source (s->loop, s->source); + pw_loop_destroy_source (s->loop, s->source); if (s->addr.sun_path[0]) unlink (s->addr.sun_path); if (s->fd >= 0) @@ -264,13 +264,13 @@ destroy_socket (Socket *s) } static bool -init_socket_name (Socket *s, const char *name) +init_socket_name (struct socket *s, const char *name) { int name_size; const char *runtime_dir; if ((runtime_dir = getenv ("XDG_RUNTIME_DIR")) == NULL) { - pinos_log_error ("XDG_RUNTIME_DIR not set in the environment"); + pw_log_error ("XDG_RUNTIME_DIR not set in the environment"); return false; } @@ -281,7 +281,7 @@ init_socket_name (Socket *s, const char *name) s->core_name = (s->addr.sun_path + name_size - 1) - strlen (name); if (name_size > (int)sizeof (s->addr.sun_path)) { - pinos_log_error ("socket path \"%s/%s\" plus null terminator exceeds 108 bytes", + pw_log_error ("socket path \"%s/%s\" plus null terminator exceeds 108 bytes", runtime_dir, name); *s->addr.sun_path = 0; return false; @@ -290,7 +290,7 @@ init_socket_name (Socket *s, const char *name) } static bool -lock_socket (Socket *s) +lock_socket (struct socket *s) { struct stat socket_stat; @@ -301,18 +301,18 @@ lock_socket (Socket *s) (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)); if (s->fd_lock < 0) { - pinos_log_error ("unable to open lockfile %s check permissions", s->lock_addr); + pw_log_error ("unable to open lockfile %s check permissions", s->lock_addr); goto err; } if (flock (s->fd_lock, LOCK_EX | LOCK_NB) < 0) { - pinos_log_error ("unable to lock lockfile %s, maybe another daemon is running", s->lock_addr); + pw_log_error ("unable to lock lockfile %s, maybe another daemon is running", s->lock_addr); goto err_fd; } if (stat (s->addr.sun_path, &socket_stat) < 0 ) { if (errno != ENOENT) { - pinos_log_error ("did not manage to stat file %s\n", s->addr.sun_path); + pw_log_error ("did not manage to stat file %s\n", s->addr.sun_path); goto err_fd; } } else if (socket_stat.st_mode & S_IWUSR || @@ -337,8 +337,8 @@ socket_data (SpaLoopUtils *utils, SpaIO mask, void *data) { - PinosProtocolNative *impl = data; - PinosProtocolNativeClient *client; + struct impl *impl = data; + struct native_client *client; struct sockaddr_un name; socklen_t length; int client_fd; @@ -346,24 +346,24 @@ socket_data (SpaLoopUtils *utils, length = sizeof (name); client_fd = accept4 (fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC); if (client_fd < 0) { - pinos_log_error ("failed to accept: %m"); + pw_log_error ("failed to accept: %m"); return; } client = client_new (impl, client_fd); if (client == NULL) { - pinos_log_error ("failed to create client"); + pw_log_error ("failed to create client"); close (client_fd); return; } - pinos_loop_update_io (impl->core->main_loop->loop, - client->source, - SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP); + pw_loop_update_io (impl->core->main_loop->loop, + client->source, + SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP); } static bool -add_socket (PinosProtocolNative *impl, Socket *s) +add_socket (struct impl *impl, struct socket *s) { socklen_t size; @@ -372,22 +372,22 @@ add_socket (PinosProtocolNative *impl, Socket *s) size = offsetof (struct sockaddr_un, sun_path) + strlen (s->addr.sun_path); if (bind (s->fd, (struct sockaddr *) &s->addr, size) < 0) { - pinos_log_error ("bind() failed with error: %m"); + pw_log_error ("bind() failed with error: %m"); return false; } if (listen (s->fd, 128) < 0) { - pinos_log_error ("listen() failed with error: %m"); + pw_log_error ("listen() failed with error: %m"); return false; } s->loop = impl->core->main_loop->loop; - s->source = pinos_loop_add_io (s->loop, - s->fd, - SPA_IO_IN, - false, - socket_data, - impl); + s->source = pw_loop_add_io (s->loop, + s->fd, + SPA_IO_IN, + false, + socket_data, + impl); if (s->source == NULL) return false; @@ -397,27 +397,27 @@ add_socket (PinosProtocolNative *impl, Socket *s) } -static PinosProtocolNative * -pinos_protocol_native_new (PinosCore *core, - PinosProperties *properties) +static struct impl * +pw_protocol_native_new (struct pw_core *core, + struct pw_properties *properties) { - PinosProtocolNative *impl; - Socket *s; + struct impl *impl; + struct socket *s; const char *name; - impl = calloc (1, sizeof (PinosProtocolNative)); - pinos_log_debug ("protocol-native %p: new", impl); + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("protocol-native %p: new", impl); impl->core = core; impl->properties = properties; name = NULL; if (impl->properties) - name = pinos_properties_get (impl->properties, "pinos.core.name"); + name = pw_properties_get (impl->properties, "pipewire.core.name"); if (name == NULL) - name = getenv ("PINOS_CORE"); + name = getenv ("PIPEWIRE_CORE"); if (name == NULL) - name = "pinos-0"; + name = "pipewire-0"; s = create_socket (); @@ -433,9 +433,9 @@ pinos_protocol_native_new (PinosCore *core, if (!add_socket (impl, s)) goto error; - pinos_signal_add (&impl->core->main_loop->loop->before_iterate, - &impl->before_iterate, - on_before_iterate); + pw_signal_add (&impl->core->main_loop->loop->before_iterate, + &impl->before_iterate, + on_before_iterate); return impl; @@ -447,15 +447,15 @@ error: #if 0 static void -pinos_protocol_native_destroy (PinosProtocolNative *impl) +pw_protocol_native_destroy (struct impl *impl) { - PinosProtocolNativeObject *object, *tmp; + struct impl *object, *tmp; - pinos_log_debug ("protocol-native %p: destroy", impl); + pw_log_debug ("protocol-native %p: destroy", impl); - pinos_signal_remove (&impl->before_iterate); + pw_signal_remove (&impl->before_iterate); - pinos_global_destroy (impl->global); + pw_global_destroy (impl->global); spa_list_for_each_safe (object, tmp, &impl->object_list, link) object_destroy (object); @@ -465,8 +465,8 @@ pinos_protocol_native_destroy (PinosProtocolNative *impl) #endif bool -pinos__module_init (PinosModule * module, const char * args) +pipewire__module_init (struct pw_module * module, const char * args) { - pinos_protocol_native_new (module->core, NULL); + pw_protocol_native_new (module->core, NULL); return true; } diff --git a/pipewire/modules/module-suspend-on-idle.c b/pipewire/modules/module-suspend-on-idle.c new file mode 100644 index 000000000..28182e70e --- /dev/null +++ b/pipewire/modules/module-suspend-on-idle.c @@ -0,0 +1,215 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "config.h" + +#include "pipewire/server/core.h" +#include "pipewire/server/module.h" + +struct impl { + struct pw_core *core; + struct pw_properties *properties; + + struct pw_listener global_added; + struct pw_listener global_removed; + + SpaList node_list; +}; + +typedef struct { + struct impl *impl; + struct pw_node *node; + SpaList link; + struct pw_listener node_state_request; + struct pw_listener node_state_changed; + SpaSource *idle_timeout; +} NodeInfo; + +static NodeInfo * +find_node_info (struct impl *impl, struct pw_node *node) +{ + NodeInfo *info; + + spa_list_for_each (info, &impl->node_list, link) { + if (info->node == node) + return info; + } + return NULL; +} + +static void +remove_idle_timeout (NodeInfo *info) +{ + if (info->idle_timeout) { + pw_loop_destroy_source (info->impl->core->main_loop->loop, info->idle_timeout); + info->idle_timeout = NULL; + } +} + +static void +node_info_free (NodeInfo *info) +{ + spa_list_remove (&info->link); + remove_idle_timeout (info); + pw_signal_remove (&info->node_state_request); + pw_signal_remove (&info->node_state_changed); + free (info); +} + +static void +idle_timeout (SpaLoopUtils *utils, + SpaSource *source, + void *data) +{ + NodeInfo *info = data; + + pw_log_debug ("module %p: node %p idle timeout", info->impl, info->node); + remove_idle_timeout (info); + pw_node_set_state (info->node, PW_NODE_STATE_SUSPENDED); +} + +static void +on_node_state_request (struct pw_listener *listener, + struct pw_node *node, + enum pw_node_state state) +{ + NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, node_state_request); + remove_idle_timeout (info); +} + +static void +on_node_state_changed (struct pw_listener *listener, + struct pw_node *node, + enum pw_node_state old, + enum pw_node_state state) +{ + NodeInfo *info = SPA_CONTAINER_OF (listener, NodeInfo, node_state_changed); + struct impl *impl = info->impl; + + if (state != PW_NODE_STATE_IDLE) { + remove_idle_timeout (info); + } else { + struct timespec value; + + pw_log_debug ("module %p: node %p became idle", impl, node); + info->idle_timeout = pw_loop_add_timer (impl->core->main_loop->loop, + idle_timeout, + info); + value.tv_sec = 3; + value.tv_nsec = 0; + pw_loop_update_timer (impl->core->main_loop->loop, + info->idle_timeout, + &value, + NULL, + false); + } +} + +static void +on_global_added (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) +{ + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added); + + if (global->type == impl->core->type.node) { + struct pw_node *node = global->object; + NodeInfo *info; + + info = calloc (1, sizeof (NodeInfo)); + info->impl = impl; + info->node = node; + spa_list_insert (impl->node_list.prev, &info->link); + pw_signal_add (&node->state_request, &info->node_state_request, on_node_state_request); + pw_signal_add (&node->state_changed, &info->node_state_changed, on_node_state_changed); + + pw_log_debug ("module %p: node %p added", impl, node); + } +} + +static void +on_global_removed (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) +{ + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_removed); + + if (global->type == impl->core->type.node) { + struct pw_node *node = global->object; + NodeInfo *info; + + if ((info = find_node_info (impl, node))) + node_info_free (info); + + pw_log_debug ("module %p: node %p removed", impl, node); + } +} + + +/** + * module_new: + * @core: #struct pw_core + * @properties: #struct pw_properties + * + * Make a new #struct impl object with given @properties + * + * Returns: a new #struct impl + */ +static struct impl * +module_new (struct pw_core *core, + struct pw_properties *properties) +{ + struct impl *impl; + + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("module %p: new", impl); + + impl->core = core; + impl->properties = properties; + + spa_list_init (&impl->node_list); + + pw_signal_add (&core->global_added, &impl->global_added, on_global_added); + pw_signal_add (&core->global_removed, &impl->global_removed, on_global_removed); + + return impl; +} + +#if 0 +static void +module_destroy (struct impl *impl) +{ + pw_log_debug ("module %p: destroy", impl); + + pw_global_destroy (impl->global); + + free (impl); +} +#endif + +bool +pipewire__module_init (struct pw_module * module, const char * args) +{ + module_new (module->core, NULL); + return true; +} diff --git a/pipewire/modules/spa/meson.build b/pipewire/modules/spa/meson.build new file mode 100644 index 000000000..cc75a4e75 --- /dev/null +++ b/pipewire/modules/spa/meson.build @@ -0,0 +1,24 @@ +pipewire_module_spa_headers = [ + 'spa-node.h', + 'spa-monitor.h', +] + +pipewire_module_spa_sources = [ + 'module.c', + 'spa-node.c', + 'spa-monitor.c', +] + +pipewire_module_spa_c_args = [ + '-DHAVE_CONFIG_H', + '-D_GNU_SOURCE', +] + +pipewire_module_spa = shared_library('pipewire-module-spa', pipewire_module_spa_sources, + c_args : pipewire_module_spa_c_args, + include_directories : [configinc, spa_inc], + link_with : spalib, + install : true, + install_dir : '@0@/pipewire-0.1'.format(get_option('libdir')), + dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], +) diff --git a/pinos/modules/spa/module.c b/pipewire/modules/spa/module.c similarity index 75% rename from pinos/modules/spa/module.c rename to pipewire/modules/spa/module.c index 96291d98a..d4558b2ab 100644 --- a/pinos/modules/spa/module.c +++ b/pipewire/modules/spa/module.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -23,33 +23,33 @@ #include -#include -#include -#include +#include +#include +#include #include "spa-monitor.h" #include "spa-node.h" static SpaResult -setup_video_node (PinosCore *core, SpaNode *spa_node, PinosProperties *pinos_props) { +setup_video_node (struct pw_core *core, SpaNode *spa_node, struct pw_properties *pw_props) { SpaResult res; SpaProps *props; SpaPODProp *prop; const char *pattern, *pattern_type; /* Retrieve pattern property */ - pattern = pinos_properties_get (pinos_props, "pattern"); + pattern = pw_properties_get (pw_props, "pattern"); if (strcmp (pattern, "smpte-snow") == 0) { pattern_type = SPA_TYPE_PROPS__patternType ":smpte-snow"; } else if (strcmp (pattern, "snow") == 0) { pattern_type = SPA_TYPE_PROPS__patternType ":snow"; } else { - pinos_log_debug ("Unrecognized pattern"); + pw_log_debug ("Unrecognized pattern"); return SPA_RESULT_ERROR; } if ((res = spa_node_get_props (spa_node, &props)) != SPA_RESULT_OK) { - pinos_log_debug ("spa_node_get_props failed: %d", res); + pw_log_debug ("spa_node_get_props failed: %d", res); return SPA_RESULT_ERROR; } @@ -59,7 +59,7 @@ setup_video_node (PinosCore *core, SpaNode *spa_node, PinosProperties *pinos_pro } if ((res = spa_node_set_props (spa_node, props)) != SPA_RESULT_OK) { - pinos_log_debug ("spa_node_set_props failed: %d", res); + pw_log_debug ("spa_node_set_props failed: %d", res); return SPA_RESULT_ERROR; } @@ -67,9 +67,9 @@ setup_video_node (PinosCore *core, SpaNode *spa_node, PinosProperties *pinos_pro } bool -pinos__module_init (PinosModule * module, const char * args) +pipewire__module_init (struct pw_module * module, const char * args) { - PinosProperties *video_props = NULL, *audio_props = NULL; + struct pw_properties *video_props = NULL, *audio_props = NULL; if (args != NULL) { char **tmp_argv; @@ -77,7 +77,7 @@ pinos__module_init (PinosModule * module, const char * args) int n_tokens; int opt = 0; - tmp_argv = pinos_split_strv (args, " \t", INT_MAX, &n_tokens); + tmp_argv = pw_split_strv (args, " \t", INT_MAX, &n_tokens); argv = malloc ((n_tokens+1) * sizeof (char *)); /* getopt expects name of executable on the first place of argv */ @@ -87,7 +87,7 @@ pinos__module_init (PinosModule * module, const char * args) argv[i] = tmp_argv[i-1]; } - video_props = pinos_properties_new ("media.class", "Video/Source", NULL); + video_props = pw_properties_new ("media.class", "Video/Source", NULL); static struct option long_options[] = { {"filter", required_argument, 0, 'f' }, @@ -99,38 +99,38 @@ pinos__module_init (PinosModule * module, const char * args) while ((opt = getopt_long (n_tokens+1, argv, "p:r:f:", long_options, NULL)) != -1) { switch (opt) { case 'f': - pinos_properties_set (video_props, "filter", optarg); + pw_properties_set (video_props, "filter", optarg); break; case 'p': - pinos_properties_set (video_props, "pattern", optarg); + pw_properties_set (video_props, "pattern", optarg); break; case 'r': - pinos_properties_set (video_props, "resolution", optarg); + pw_properties_set (video_props, "resolution", optarg); break; default: break; } } free (argv); - pinos_free_strv (tmp_argv); + pw_free_strv (tmp_argv); } - pinos_spa_monitor_load (module->core, + pw_spa_monitor_load (module->core, "build/spa/plugins/alsa/libspa-alsa.so", "alsa-monitor", "alsa"); - pinos_spa_monitor_load (module->core, + pw_spa_monitor_load (module->core, "build/spa/plugins/v4l2/libspa-v4l2.so", "v4l2-monitor", "v4l2"); - audio_props = pinos_properties_new ("media.class", "Audio/Source", NULL); - pinos_spa_node_load (module->core, + audio_props = pw_properties_new ("media.class", "Audio/Source", NULL); + pw_spa_node_load (module->core, "build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc", "audiotestsrc", audio_props, NULL); - pinos_spa_node_load (module->core, + pw_spa_node_load (module->core, "build/spa/plugins/videotestsrc/libspa-videotestsrc.so", "videotestsrc", "videotestsrc", diff --git a/pinos/modules/spa/spa-monitor.c b/pipewire/modules/spa/spa-monitor.c similarity index 67% rename from pinos/modules/spa/spa-monitor.c rename to pipewire/modules/spa/spa-monitor.c index e0697e0ad..66a458710 100644 --- a/pinos/modules/spa/spa-monitor.c +++ b/pipewire/modules/spa/spa-monitor.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -29,39 +29,38 @@ #include #include #include -#include -#include +#include +#include #include "spa-monitor.h" -typedef struct +struct monitor_item { char *id; SpaList link; - PinosNode *node; -} PinosSpaMonitorItem; + struct pw_node *node; +}; -typedef struct -{ - PinosSpaMonitor this; +struct impl { + struct pw_spa_monitor this; - PinosCore *core; + struct pw_core *core; void *hnd; SpaList item_list; -} PinosSpaMonitorImpl; +}; static void -add_item (PinosSpaMonitor *this, SpaMonitorItem *item) +add_item (struct pw_spa_monitor *this, SpaMonitorItem *item) { - PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); SpaResult res; SpaHandle *handle; - PinosSpaMonitorItem *mitem; + struct monitor_item *mitem; void *node_iface; void *clock_iface; - PinosProperties *props = NULL; + struct pw_properties *props = NULL; const char *name, *id, *klass; SpaHandleFactory *factory; SpaPOD *info = NULL; @@ -74,9 +73,9 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item) impl->core->type.monitor.info, SPA_POD_TYPE_STRUCT, &info, 0); - pinos_log_debug ("monitor %p: add: \"%s\" (%s)", this, name, id); + pw_log_debug ("monitor %p: add: \"%s\" (%s)", this, name, id); - props = pinos_properties_new (NULL, NULL); + props = pw_properties_new (NULL, NULL); if (info) { SpaPODIter it; @@ -86,10 +85,10 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item) const char *key, *val; if (!spa_pod_iter_get (&it, SPA_POD_TYPE_STRING, &key, SPA_POD_TYPE_STRING, &val, 0)) break; - pinos_properties_set (props, key, val); + pw_properties_set (props, key, val); } } - pinos_properties_set (props, "media.class", klass); + pw_properties_set (props, "media.class", klass); handle = calloc (1, factory->size); if ((res = spa_handle_factory_init (factory, @@ -97,37 +96,37 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item) &props->dict, impl->core->support, impl->core->n_support)) < 0) { - pinos_log_error ("can't make factory instance: %d", res); + pw_log_error ("can't make factory instance: %d", res); return; } if ((res = spa_handle_get_interface (handle, impl->core->type.spa_node, &node_iface)) < 0) { - pinos_log_error ("can't get NODE interface: %d", res); + pw_log_error ("can't get NODE interface: %d", res); return; } if ((res = spa_handle_get_interface (handle, impl->core->type.spa_clock, &clock_iface)) < 0) { - pinos_log_info ("no CLOCK interface: %d", res); + pw_log_info ("no CLOCK interface: %d", res); } - mitem = calloc (1, sizeof (PinosSpaMonitorItem)); + mitem = calloc (1, sizeof (struct monitor_item)); mitem->id = strdup (id); - mitem->node = pinos_node_new (impl->core, - NULL, - name, - false, - node_iface, - clock_iface, - props); + mitem->node = pw_node_new (impl->core, + NULL, + name, + false, + node_iface, + clock_iface, + props); spa_list_insert (impl->item_list.prev, &mitem->link); } -static PinosSpaMonitorItem * -find_item (PinosSpaMonitor *this, - const char *id) +static struct monitor_item * +find_item (struct pw_spa_monitor *this, + const char *id) { - PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this); - PinosSpaMonitorItem *mitem; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct monitor_item *mitem; spa_list_for_each (mitem, &impl->item_list, link) { if (strcmp (mitem->id, id) == 0) { @@ -138,19 +137,19 @@ find_item (PinosSpaMonitor *this, } void -destroy_item (PinosSpaMonitorItem *mitem) +destroy_item (struct monitor_item *mitem) { - pinos_node_destroy (mitem->node); + pw_node_destroy (mitem->node); spa_list_remove (&mitem->link); free (mitem->id); free (mitem); } static void -remove_item (PinosSpaMonitor *this, SpaMonitorItem *item) +remove_item (struct pw_spa_monitor *this, SpaMonitorItem *item) { - PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this); - PinosSpaMonitorItem *mitem; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct monitor_item *mitem; const char *name, *id; spa_pod_object_query (item, @@ -158,7 +157,7 @@ remove_item (PinosSpaMonitor *this, SpaMonitorItem *item) impl->core->type.monitor.id, SPA_POD_TYPE_STRING, &id, 0); - pinos_log_debug ("monitor %p: remove: \"%s\" (%s)", this, name, id); + pw_log_debug ("monitor %p: remove: \"%s\" (%s)", this, name, id); mitem = find_item (this, id); if (mitem) destroy_item (mitem); @@ -169,8 +168,8 @@ on_monitor_event (SpaMonitor *monitor, SpaEventMonitor *event, void *user_data) { - PinosSpaMonitor *this = user_data; - PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this); + struct pw_spa_monitor *this = user_data; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); if (SPA_EVENT_TYPE (event) == impl->core->type.monitor.Added) { SpaMonitorItem *item = SPA_POD_CONTENTS (SpaEvent, event); @@ -188,20 +187,20 @@ on_monitor_event (SpaMonitor *monitor, impl->core->type.monitor.name, SPA_POD_TYPE_STRING, &name, 0); - pinos_log_debug ("monitor %p: changed: \"%s\"", this, name); + pw_log_debug ("monitor %p: changed: \"%s\"", this, name); } } static void -update_monitor (PinosCore *core, - const char *name) +update_monitor (struct pw_core *core, + const char *name) { const char *monitors; SpaDictItem item; SpaDict dict = SPA_DICT_INIT(1, &item); if (core->properties) - monitors = pinos_properties_get (core->properties, "monitors"); + monitors = pw_properties_get (core->properties, "monitors"); else monitors = NULL; @@ -211,20 +210,20 @@ update_monitor (PinosCore *core, else asprintf ((char**)&item.value, "%s,%s", monitors, name); - pinos_core_update_properties (core, &dict); + pw_core_update_properties (core, &dict); if (monitors != NULL) free ((void*)item.value); } -PinosSpaMonitor * -pinos_spa_monitor_load (PinosCore *core, - const char *lib, - const char *factory_name, - const char *system_name) +struct pw_spa_monitor * +pw_spa_monitor_load (struct pw_core *core, + const char *lib, + const char *factory_name, + const char *system_name) { - PinosSpaMonitorImpl *impl; - PinosSpaMonitor *this; + struct impl *impl; + struct pw_spa_monitor *this; SpaHandle *handle; SpaResult res; void *iface; @@ -234,18 +233,18 @@ pinos_spa_monitor_load (PinosCore *core, const SpaHandleFactory *factory; if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) { - pinos_log_error ("can't load %s: %s", lib, dlerror()); + pw_log_error ("can't load %s: %s", lib, dlerror()); return NULL; } if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) { - pinos_log_error ("can't find enum function"); + pw_log_error ("can't find enum function"); goto no_symbol; } for (index = 0;; index++) { if ((res = enum_func (&factory, index)) < 0) { if (res != SPA_RESULT_ENUM_END) - pinos_log_error ("can't enumerate factories: %d", res); + pw_log_error ("can't enumerate factories: %d", res); goto enum_failed; } if (strcmp (factory->name, factory_name) == 0) @@ -257,23 +256,23 @@ pinos_spa_monitor_load (PinosCore *core, NULL, core->support, core->n_support)) < 0) { - pinos_log_error ("can't make factory instance: %d", res); + pw_log_error ("can't make factory instance: %d", res); goto init_failed; } if ((res = spa_handle_get_interface (handle, core->type.spa_monitor, &iface)) < 0) { free (handle); - pinos_log_error ("can't get MONITOR interface: %d", res); + pw_log_error ("can't get MONITOR interface: %d", res); goto interface_failed; } - impl = calloc (1, sizeof (PinosSpaMonitorImpl)); + impl = calloc (1, sizeof (struct impl)); impl->core = core; impl->hnd = hnd; this = &impl->this; - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); this->monitor = iface; this->lib = strdup (lib); this->factory_name = strdup (factory_name); @@ -290,7 +289,7 @@ pinos_spa_monitor_load (PinosCore *core, if ((res = spa_monitor_enum_items (this->monitor, &item, index)) < 0) { if (res != SPA_RESULT_ENUM_END) - pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res); + pw_log_debug ("spa_monitor_enum_items: got error %d\n", res); break; } add_item (this, item); @@ -311,13 +310,13 @@ no_symbol: } void -pinos_spa_monitor_destroy (PinosSpaMonitor * monitor) +pw_spa_monitor_destroy (struct pw_spa_monitor * monitor) { - PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaMonitorImpl, this); - PinosSpaMonitorItem *mitem, *tmp; + struct impl *impl = SPA_CONTAINER_OF (monitor, struct impl, this); + struct monitor_item *mitem, *tmp; - pinos_log_debug ("spa-monitor %p: dispose", impl); - pinos_signal_emit (&monitor->destroy_signal, monitor); + pw_log_debug ("spa-monitor %p: dispose", impl); + pw_signal_emit (&monitor->destroy_signal, monitor); spa_list_for_each_safe (mitem, tmp, &impl->item_list, link) destroy_item (mitem); diff --git a/pinos/modules/spa/spa-monitor.h b/pipewire/modules/spa/spa-monitor.h similarity index 60% rename from pinos/modules/spa/spa-monitor.h rename to pipewire/modules/spa/spa-monitor.h index f628ed5ef..ebba3067d 100644 --- a/pinos/modules/spa/spa-monitor.h +++ b/pipewire/modules/spa/spa-monitor.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,19 +17,17 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_SPA_MONITOR_H__ -#define __PINOS_SPA_MONITOR_H__ +#ifndef __PIPEWIRE_SPA_MONITOR_H__ +#define __PIPEWIRE_SPA_MONITOR_H__ -#include +#include #include #ifdef __cplusplus extern "C" { #endif -typedef struct _PinosSpaMonitor PinosSpaMonitor; - -struct _PinosSpaMonitor { +struct pw_spa_monitor { SpaMonitor *monitor; char *lib; @@ -37,17 +35,17 @@ struct _PinosSpaMonitor { char *system_name; SpaHandle *handle; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, PinosSpaMonitor *monitor)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, struct pw_spa_monitor *monitor)); }; -PinosSpaMonitor * pinos_spa_monitor_load (PinosCore *core, - const char *lib, - const char *factory_name, - const char *system_name); -void pinos_spa_monitor_destroy (PinosSpaMonitor *monitor); +struct pw_spa_monitor * pw_spa_monitor_load (struct pw_core *core, + const char *lib, + const char *factory_name, + const char *system_name); +void pw_spa_monitor_destroy (struct pw_spa_monitor *monitor); #ifdef __cplusplus } #endif -#endif /* __PINOS_SPA_MONITOR_H__ */ +#endif /* __PIPEWIRE_SPA_MONITOR_H__ */ diff --git a/pinos/modules/spa/spa-node.c b/pipewire/modules/spa/spa-node.c similarity index 68% rename from pinos/modules/spa/spa-node.c rename to pipewire/modules/spa/spa-node.c index c7eaf4048..597e07105 100644 --- a/pinos/modules/spa/spa-node.c +++ b/pipewire/modules/spa/spa-node.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -25,23 +25,23 @@ #include "spa-node.h" -typedef struct { - PinosSpaNode this; - PinosCore *core; +struct impl { + struct pw_spa_node this; + struct pw_core *core; void *hnd; -} PinosSpaNodeImpl; +}; -PinosSpaNode * -pinos_spa_node_load (PinosCore *core, - const char *lib, - const char *factory_name, - const char *name, - PinosProperties *properties, - SetupNode setup_func) +struct pw_spa_node * +pw_spa_node_load (struct pw_core *core, + const char *lib, + const char *factory_name, + const char *name, + struct pw_properties *properties, + setup_node_t setup_func) { - PinosSpaNode *this; - PinosSpaNodeImpl *impl; + struct pw_spa_node *this; + struct impl *impl; SpaNode *spa_node; SpaClock *spa_clock; SpaResult res; @@ -53,18 +53,18 @@ pinos_spa_node_load (PinosCore *core, void *iface; if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) { - pinos_log_error ("can't load %s: %s", lib, dlerror()); + pw_log_error ("can't load %s: %s", lib, dlerror()); return NULL; } if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) { - pinos_log_error ("can't find enum function"); + pw_log_error ("can't find enum function"); goto no_symbol; } for (index = 0; ; index++) { if ((res = enum_func (&factory, index)) < 0) { if (res != SPA_RESULT_ENUM_END) - pinos_log_error ("can't enumerate factories: %d", res); + pw_log_error ("can't enumerate factories: %d", res); goto enum_failed; } if (strcmp (factory->name, factory_name) == 0) @@ -77,13 +77,13 @@ pinos_spa_node_load (PinosCore *core, NULL, core->support, core->n_support)) < 0) { - pinos_log_error ("can't make factory instance: %d", res); + pw_log_error ("can't make factory instance: %d", res); goto init_failed; } if ((res = spa_handle_get_interface (handle, core->type.spa_node, &iface)) < 0) { - pinos_log_error ("can't get interface %d", res); + pw_log_error ("can't get interface %d", res); goto interface_failed; } spa_node = iface; @@ -95,24 +95,24 @@ pinos_spa_node_load (PinosCore *core, } spa_clock = iface; - impl = calloc (1, sizeof (PinosSpaNodeImpl)); + impl = calloc (1, sizeof (struct impl)); impl->core = core; impl->hnd = hnd; this = &impl->this; if (setup_func != NULL) { if (setup_func (core, spa_node, properties) != SPA_RESULT_OK) { - pinos_log_debug ("Unrecognized properties"); + pw_log_debug ("Unrecognized properties"); } } - this->node = pinos_node_new (core, - NULL, - name, - false, - spa_node, - spa_clock, - properties); + this->node = pw_node_new (core, + NULL, + name, + false, + spa_node, + spa_clock, + properties); this->lib = strdup (lib); this->factory_name = strdup (factory_name); this->handle = handle; @@ -130,14 +130,14 @@ no_symbol: } void -pinos_spa_node_destroy (PinosSpaNode * node) +pw_spa_node_destroy (struct pw_spa_node * node) { - PinosSpaNodeImpl *impl = SPA_CONTAINER_OF (node, PinosSpaNodeImpl, this); + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); - pinos_log_debug ("spa-node %p: destroy", impl); - pinos_signal_emit (&node->destroy_signal, node); + pw_log_debug ("spa-node %p: destroy", impl); + pw_signal_emit (&node->destroy_signal, node); - pinos_node_destroy (node->node); + pw_node_destroy (node->node); spa_handle_clear (node->handle); free (node->handle); diff --git a/pipewire/modules/spa/spa-node.h b/pipewire/modules/spa/spa-node.h new file mode 100644 index 000000000..ae7386221 --- /dev/null +++ b/pipewire/modules/spa/spa-node.h @@ -0,0 +1,55 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_SPA_NODE_H__ +#define __PIPEWIRE_SPA_NODE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct pw_spa_node { + struct pw_node *node; + + char *lib; + char *factory_name; + SpaHandle *handle; + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_spa_node *node)); +}; + +typedef SpaResult (*setup_node_t) (struct pw_core *core, + SpaNode *spa_node, + struct pw_properties *pw_props); + +struct pw_spa_node * pw_spa_node_load (struct pw_core *core, + const char *lib, + const char *factory_name, + const char *name, + struct pw_properties *properties, + setup_node_t setup_func); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_SPA_NODE_H__ */ diff --git a/pinos/server/access.c b/pipewire/server/access.c similarity index 94% rename from pinos/server/access.c rename to pipewire/server/access.c index 593fb3905..e60de5257 100644 --- a/pinos/server/access.c +++ b/pipewire/server/access.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,4 +17,4 @@ * Boston, MA 02110-1301, USA. */ -#include "pinos/server/core.h" +#include "pipewire/server/core.h" diff --git a/pipewire/server/access.h b/pipewire/server/access.h new file mode 100644 index 000000000..24dee42cb --- /dev/null +++ b/pipewire/server/access.h @@ -0,0 +1,69 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_ACCESS_H__ +#define __PIPEWIRE_ACCESS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPEWIRE_TYPE__Access "PipeWire:Object:Access" +#define PIPEWIRE_TYPE_ACCESS_BASE PIPEWIRE_TYPE__Access ":" + +#include +#include +#include + +struct pw_access_data { + SpaResult res; + struct pw_resource *resource; + + void * (*async_copy) (struct pw_access_data *data, size_t size); + void (*complete_cb) (struct pw_access_data *data); + void (*free_cb) (struct pw_access_data *data); + void * user_data; +}; + + +/** + * struct pw_access: + * + * PipeWire Access support struct. + */ +struct pw_access { + SpaResult (*view_global) (struct pw_access *access, + struct pw_client *client, + struct pw_global *global); + SpaResult (*create_node) (struct pw_access *access, + struct pw_access_data *data, + const char *factory_name, + const char *name, + struct pw_properties *properties); + SpaResult (*create_client_node) (struct pw_access *access, + struct pw_access_data *data, + const char *name, + struct pw_properties *properties); +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_ACCESS_H__ */ diff --git a/pinos/server/client-node.c b/pipewire/server/client-node.c similarity index 76% rename from pinos/server/client-node.c rename to pipewire/server/client-node.c index d142708a3..bde38bbea 100644 --- a/pinos/server/client-node.c +++ b/pipewire/server/client-node.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -28,17 +28,16 @@ #include #include - -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" -#include "pinos/client/transport.h" - -#include "pinos/server/core.h" -#include "pinos/server/client-node.h" - #include "spa/node.h" #include "spa/format-builder.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" +#include "pipewire/client/transport.h" + +#include "pipewire/server/core.h" +#include "pipewire/server/client-node.h" + #define MAX_INPUTS 64 #define MAX_OUTPUTS 64 @@ -56,11 +55,7 @@ #define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers) -typedef struct _SpaProxy SpaProxy; -typedef struct _ProxyBuffer ProxyBuffer; -typedef struct _PinosClientNodeImpl PinosClientNodeImpl; - -struct _ProxyBuffer { +struct proxy_buffer { SpaBuffer *outbuf; SpaBuffer buffer; SpaMeta metas[4]; @@ -70,7 +65,7 @@ struct _ProxyBuffer { bool outstanding; }; -typedef struct { +struct proxy_port { bool valid; SpaPortInfo info; SpaFormat *format; @@ -80,18 +75,18 @@ typedef struct { SpaParam **params; SpaPortIO *io; - uint32_t n_buffers; - ProxyBuffer buffers[MAX_BUFFERS]; + uint32_t n_buffers; + struct proxy_buffer buffers[MAX_BUFFERS]; - uint32_t buffer_mem_id; - PinosMemblock buffer_mem; -} SpaProxyPort; + uint32_t buffer_mem_id; + struct pw_memblock buffer_mem; +}; -struct _SpaProxy +struct proxy { SpaNode node; - PinosClientNodeImpl *impl; + struct impl *impl; SpaTypeMap *map; SpaLog *log; @@ -101,7 +96,7 @@ struct _SpaProxy SpaNodeCallbacks callbacks; void *user_data; - PinosResource *resource; + struct pw_resource *resource; SpaSource data_source; int writefd; @@ -110,39 +105,38 @@ struct _SpaProxy uint32_t n_inputs; uint32_t max_outputs; uint32_t n_outputs; - SpaProxyPort in_ports[MAX_INPUTS]; - SpaProxyPort out_ports[MAX_OUTPUTS]; + struct proxy_port in_ports[MAX_INPUTS]; + struct proxy_port out_ports[MAX_OUTPUTS]; uint8_t format_buffer[1024]; uint32_t seq; }; -struct _PinosClientNodeImpl -{ - PinosClientNode this; +struct impl { + struct pw_client_node this; - PinosCore *core; + struct pw_core *core; - SpaProxy proxy; + struct proxy proxy; - PinosTransport *transport; + struct pw_transport *transport; - PinosListener node_free; - PinosListener initialized; - PinosListener loop_changed; - PinosListener global_added; + struct pw_listener node_free; + struct pw_listener initialized; + struct pw_listener loop_changed; + struct pw_listener global_added; int fds[2]; int other_fds[2]; }; static SpaResult -clear_buffers (SpaProxy *this, SpaProxyPort *port) +clear_buffers (struct proxy *this, struct proxy_port *port) { if (port->n_buffers) { spa_log_info (this->log, "proxy %p: clear buffers", this); - pinos_memblock_free (&port->buffer_mem); + pw_memblock_free (&port->buffer_mem); port->n_buffers = 0; } @@ -164,28 +158,28 @@ spa_proxy_node_set_props (SpaNode *node, } static inline void -do_flush (SpaProxy *this) +do_flush (struct proxy *this) { uint64_t cmd = 1; write (this->writefd, &cmd, 8); } static inline void -send_need_input (SpaProxy *this) +send_need_input (struct proxy *this) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (this, PinosClientNodeImpl, proxy); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy); - pinos_transport_add_event (impl->transport, + pw_transport_add_event (impl->transport, &SPA_EVENT_INIT (impl->core->type.event_transport.NeedInput)); do_flush (this); } static inline void -send_have_output (SpaProxy *this) +send_have_output (struct proxy *this) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (this, PinosClientNodeImpl, proxy); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy); - pinos_transport_add_event (impl->transport, + pw_transport_add_event (impl->transport, &SPA_EVENT_INIT (impl->core->type.event_transport.HaveOutput)); do_flush (this); } @@ -194,14 +188,14 @@ static SpaResult spa_proxy_node_send_command (SpaNode *node, SpaCommand *command) { - SpaProxy *this; + struct proxy *this; SpaResult res = SPA_RESULT_OK; - PinosCore *core; + struct pw_core *core; if (node == NULL || command == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (this->resource == NULL) return SPA_RESULT_OK; @@ -209,13 +203,13 @@ spa_proxy_node_send_command (SpaNode *node, core = this->impl->core; if (SPA_COMMAND_TYPE (command) == core->type.command_node.ClockUpdate) { - pinos_client_node_notify_node_command (this->resource, + pw_client_node_notify_node_command (this->resource, this->seq++, command); } else { /* send start */ - pinos_client_node_notify_node_command (this->resource, + pw_client_node_notify_node_command (this->resource, this->seq, command); if (SPA_COMMAND_TYPE (command) == core->type.command_node.Start) @@ -232,12 +226,12 @@ spa_proxy_node_set_callbacks (SpaNode *node, size_t callbacks_size, void *user_data) { - SpaProxy *this; + struct proxy *this; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); this->callbacks = *callbacks; this->user_data = user_data; @@ -251,12 +245,12 @@ spa_proxy_node_get_n_ports (SpaNode *node, uint32_t *n_output_ports, uint32_t *max_output_ports) { - SpaProxy *this; + struct proxy *this; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (n_input_ports) *n_input_ports = this->n_inputs; @@ -277,13 +271,13 @@ spa_proxy_node_get_port_ids (SpaNode *node, uint32_t n_output_ports, uint32_t *output_ids) { - SpaProxy *this; + struct proxy *this; int c, i; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (input_ids) { for (c = 0, i = 0; i < MAX_INPUTS && c < n_input_ports; i++) { @@ -301,7 +295,7 @@ spa_proxy_node_get_port_ids (SpaNode *node, } static void -do_update_port (SpaProxy *this, +do_update_port (struct proxy *this, SpaDirection direction, uint32_t port_id, uint32_t change_mask, @@ -312,7 +306,7 @@ do_update_port (SpaProxy *this, const SpaParam **params, const SpaPortInfo *info) { - SpaProxyPort *port; + struct proxy_port *port; uint32_t i; if (direction == SPA_DIRECTION_INPUT) { @@ -321,7 +315,7 @@ do_update_port (SpaProxy *this, port = &this->out_ports[port_id]; } - if (change_mask & PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) { + if (change_mask & PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) { for (i = 0; i < port->n_formats; i++) free (port->formats[i]); port->n_formats = n_possible_formats; @@ -329,13 +323,13 @@ do_update_port (SpaProxy *this, for (i = 0; i < port->n_formats; i++) port->formats[i] = spa_format_copy (possible_formats[i]); } - if (change_mask & PINOS_MESSAGE_PORT_UPDATE_FORMAT) { + if (change_mask & PW_MESSAGE_PORT_UPDATE_FORMAT) { if (port->format) free (port->format); port->format = spa_format_copy (format); } - if (change_mask & PINOS_MESSAGE_PORT_UPDATE_PARAMS) { + if (change_mask & PW_MESSAGE_PORT_UPDATE_PARAMS) { for (i = 0; i < port->n_params; i++) free (port->params[i]); port->n_params = n_params; @@ -344,7 +338,7 @@ do_update_port (SpaProxy *this, port->params[i] = spa_param_copy (params[i]); } - if (change_mask & PINOS_MESSAGE_PORT_UPDATE_INFO && info) + if (change_mask & PW_MESSAGE_PORT_UPDATE_INFO && info) port->info = *info; if (!port->valid) { @@ -360,18 +354,18 @@ do_update_port (SpaProxy *this, } static void -clear_port (SpaProxy *this, - SpaProxyPort *port, +clear_port (struct proxy *this, + struct proxy_port *port, SpaDirection direction, uint32_t port_id) { do_update_port (this, direction, port_id, - PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | - PINOS_MESSAGE_PORT_UPDATE_FORMAT | - PINOS_MESSAGE_PORT_UPDATE_PARAMS | - PINOS_MESSAGE_PORT_UPDATE_INFO, + PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | + PW_MESSAGE_PORT_UPDATE_FORMAT | + PW_MESSAGE_PORT_UPDATE_PARAMS | + PW_MESSAGE_PORT_UPDATE_INFO, 0, NULL, NULL, @@ -382,11 +376,11 @@ clear_port (SpaProxy *this, } static void -do_uninit_port (SpaProxy *this, +do_uninit_port (struct proxy *this, SpaDirection direction, uint32_t port_id) { - SpaProxyPort *port; + struct proxy_port *port; spa_log_info (this->log, "proxy %p: removing port %d", this, port_id); if (direction == SPA_DIRECTION_INPUT) { @@ -405,13 +399,13 @@ spa_proxy_node_add_port (SpaNode *node, SpaDirection direction, uint32_t port_id) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_FREE_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -427,12 +421,12 @@ spa_proxy_node_remove_port (SpaNode *node, SpaDirection direction, uint32_t port_id) { - SpaProxy *this; + struct proxy *this; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -450,8 +444,8 @@ spa_proxy_node_port_enum_formats (SpaNode *node, const SpaFormat *filter, uint32_t index) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; SpaFormat *fmt; SpaPODBuilder b = { NULL, }; SpaResult res; @@ -460,7 +454,7 @@ spa_proxy_node_port_enum_formats (SpaNode *node, if (node == NULL || format == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -492,12 +486,12 @@ spa_proxy_node_port_set_format (SpaNode *node, uint32_t flags, const SpaFormat *format) { - SpaProxy *this; + struct proxy *this; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -505,7 +499,7 @@ spa_proxy_node_port_set_format (SpaNode *node, if (this->resource == NULL) return SPA_RESULT_OK; - pinos_client_node_notify_set_format (this->resource, + pw_client_node_notify_set_format (this->resource, this->seq, direction, port_id, @@ -521,13 +515,13 @@ spa_proxy_node_port_get_format (SpaNode *node, uint32_t port_id, const SpaFormat **format) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; if (node == NULL || format == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -548,13 +542,13 @@ spa_proxy_node_port_get_info (SpaNode *node, uint32_t port_id, const SpaPortInfo **info) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; if (node == NULL || info == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -573,13 +567,13 @@ spa_proxy_node_port_enum_params (SpaNode *node, uint32_t index, SpaParam **param) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS); - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT); @@ -608,13 +602,13 @@ spa_proxy_node_port_set_io (SpaNode *node, uint32_t port_id, SpaPortIO *io) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -632,15 +626,15 @@ spa_proxy_node_port_use_buffers (SpaNode *node, SpaBuffer **buffers, uint32_t n_buffers) { - SpaProxy *this; - PinosClientNodeImpl *impl; - SpaProxyPort *port; + struct proxy *this; + struct impl *impl; + struct proxy_port *port; uint32_t i, j; size_t n_mem; - PinosClientNodeBuffer *mb; + struct pw_client_node_buffer *mb; SpaMetaShared *msh; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); impl = this->impl; spa_log_info (this->log, "proxy %p: use buffers %p %u", this, buffers, n_buffers); @@ -655,7 +649,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, clear_buffers (this, port); if (n_buffers > 0) { - mb = alloca (n_buffers * sizeof (PinosClientNodeBuffer)); + mb = alloca (n_buffers * sizeof (struct pw_client_node_buffer)); } else { mb = NULL; } @@ -667,7 +661,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, n_mem = 0; for (i = 0; i < n_buffers; i++) { - ProxyBuffer *b = &port->buffers[i]; + struct proxy_buffer *b = &port->buffers[i]; msh = spa_buffer_find_meta (buffers[i], impl->core->type.meta.Shared); if (msh == NULL) { @@ -685,7 +679,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, mb[i].offset = 0; mb[i].size = msh->size; - pinos_client_node_notify_add_mem (this->resource, + pw_client_node_notify_add_mem (this->resource, direction, port_id, mb[i].mem_id, @@ -706,7 +700,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, if (d->type == impl->core->type.data.DmaBuf || d->type == impl->core->type.data.MemFd) { - pinos_client_node_notify_add_mem (this->resource, + pw_client_node_notify_add_mem (this->resource, direction, port_id, n_mem, @@ -731,7 +725,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, } } - pinos_client_node_notify_use_buffers (this->resource, + pw_client_node_notify_use_buffers (this->resource, this->seq, direction, port_id, @@ -750,13 +744,13 @@ spa_proxy_node_port_alloc_buffers (SpaNode *node, SpaBuffer **buffers, uint32_t *n_buffers) { - SpaProxy *this; - SpaProxyPort *port; + struct proxy *this; + struct proxy_port *port; if (node == NULL || buffers == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -774,13 +768,13 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node, uint32_t port_id, uint32_t buffer_id) { - SpaProxy *this; - PinosClientNodeImpl *impl; + struct proxy *this; + struct impl *impl; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); impl = this->impl; if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id)) @@ -788,9 +782,9 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node, spa_log_trace (this->log, "reuse buffer %d", buffer_id); { - PinosEventTransportReuseBuffer rb = PINOS_EVENT_TRANSPORT_REUSE_BUFFER_INIT + struct pw_event_transport_reuse_buffer rb = PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT (impl->core->type.event_transport.ReuseBuffer, port_id, buffer_id); - pinos_transport_add_event (impl->transport, (SpaEvent *)&rb); + pw_transport_add_event (impl->transport, (SpaEvent *)&rb); } return SPA_RESULT_OK; @@ -802,12 +796,12 @@ spa_proxy_node_port_send_command (SpaNode *node, uint32_t port_id, SpaCommand *command) { - SpaProxy *this; + struct proxy *this; if (node == NULL || command == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); spa_log_warn (this->log, "unhandled command %d", SPA_COMMAND_TYPE (command)); return SPA_RESULT_NOT_IMPLEMENTED; @@ -816,14 +810,14 @@ spa_proxy_node_port_send_command (SpaNode *node, static SpaResult spa_proxy_node_process_input (SpaNode *node) { - PinosClientNodeImpl *impl; - SpaProxy *this; + struct impl *impl; + struct proxy *this; int i; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); impl = this->impl; for (i = 0; i < MAX_INPUTS; i++) { @@ -832,7 +826,7 @@ spa_proxy_node_process_input (SpaNode *node) if (!io) continue; - pinos_log_trace ("%d %d", io->status, io->buffer_id); + pw_log_trace ("%d %d", io->status, io->buffer_id); impl->transport->inputs[i] = *io; io->status = SPA_RESULT_OK; @@ -845,12 +839,12 @@ spa_proxy_node_process_input (SpaNode *node) static SpaResult spa_proxy_node_process_output (SpaNode *node) { - SpaProxy *this; - PinosClientNodeImpl *impl; + struct proxy *this; + struct impl *impl; int i; bool send_need = false, flush = false; - this = SPA_CONTAINER_OF (node, SpaProxy, node); + this = SPA_CONTAINER_OF (node, struct proxy, node); impl = this->impl; for (i = 0; i < MAX_OUTPUTS; i++) { @@ -860,12 +854,12 @@ spa_proxy_node_process_output (SpaNode *node) continue; if (io->buffer_id != SPA_ID_INVALID) { - PinosEventTransportReuseBuffer rb = - PINOS_EVENT_TRANSPORT_REUSE_BUFFER_INIT (impl->core->type.event_transport.ReuseBuffer, i, io->buffer_id); + struct pw_event_transport_reuse_buffer rb = + PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT (impl->core->type.event_transport.ReuseBuffer, i, io->buffer_id); spa_log_trace (this->log, "reuse buffer %d", io->buffer_id); - pinos_transport_add_event (impl->transport, (SpaEvent *)&rb); + pw_transport_add_event (impl->transport, (SpaEvent *)&rb); io->buffer_id = SPA_ID_INVALID; flush = true; } @@ -873,7 +867,7 @@ spa_proxy_node_process_output (SpaNode *node) tmp = impl->transport->outputs[i]; impl->transport->outputs[i] = *io; - pinos_log_trace ("%d %d %d %d", io->status, io->buffer_id, tmp.status, tmp.buffer_id); + pw_log_trace ("%d %d %d %d", io->status, io->buffer_id, tmp.status, tmp.buffer_id); if (io->status == SPA_RESULT_NEED_BUFFER) send_need = true; @@ -889,10 +883,10 @@ spa_proxy_node_process_output (SpaNode *node) } static SpaResult -handle_node_event (SpaProxy *this, +handle_node_event (struct proxy *this, SpaEvent *event) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (this, PinosClientNodeImpl, proxy); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy); int i; if (SPA_EVENT_TYPE (event) == impl->core->type.event_transport.HaveOutput) { @@ -903,7 +897,7 @@ handle_node_event (SpaProxy *this, continue; *io = impl->transport->outputs[i]; - pinos_log_trace ("%d %d", io->status, io->buffer_id); + pw_log_trace ("%d %d", io->status, io->buffer_id); } this->callbacks.have_output (&this->node, this->user_data); } @@ -911,7 +905,7 @@ handle_node_event (SpaProxy *this, this->callbacks.need_input (&this->node, this->user_data); } else if (SPA_EVENT_TYPE (event) == impl->core->type.event_transport.ReuseBuffer) { - PinosEventTransportReuseBuffer *p = (PinosEventTransportReuseBuffer *) event; + struct pw_event_transport_reuse_buffer *p = (struct pw_event_transport_reuse_buffer *) event; this->callbacks.reuse_buffer (&this->node, p->body.port_id.value, p->body.buffer_id.value, this->user_data); } return SPA_RESULT_OK; @@ -924,14 +918,14 @@ client_node_update (void *object, uint32_t max_output_ports, const SpaProps *props) { - PinosResource *resource = object; - PinosClientNode *node = resource->object; - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (node, PinosClientNodeImpl, this); - SpaProxy *this = &impl->proxy; + struct pw_resource *resource = object; + struct pw_client_node *node = resource->object; + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); + struct proxy *this = &impl->proxy; - if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS) + if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_INPUTS) this->max_inputs = max_input_ports; - if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) + if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) this->max_outputs = max_output_ports; spa_log_info (this->log, "proxy %p: got node update max_in %u, max_out %u", this, @@ -950,10 +944,10 @@ client_node_port_update (void *object, const SpaParam **params, const SpaPortInfo *info) { - PinosResource *resource = object; - PinosClientNode *node = resource->object; - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (node, PinosClientNodeImpl, this); - SpaProxy *this = &impl->proxy; + struct pw_resource *resource = object; + struct pw_client_node *node = resource->object; + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); + struct proxy *this = &impl->proxy; bool remove; spa_log_info (this->log, "proxy %p: got port update", this); @@ -982,10 +976,10 @@ static void client_node_event (void *object, SpaEvent *event) { - PinosResource *resource = object; - PinosClientNode *node = resource->object; - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (node, PinosClientNodeImpl, this); - SpaProxy *this = &impl->proxy; + struct pw_resource *resource = object; + struct pw_client_node *node = resource->object; + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); + struct proxy *this = &impl->proxy; this->callbacks.event (&this->node, event, this->user_data); } @@ -993,12 +987,12 @@ client_node_event (void *object, static void client_node_destroy (void *object) { - PinosResource *resource = object; - PinosClientNode *node = resource->object; - pinos_client_node_destroy (node); + struct pw_resource *resource = object; + struct pw_client_node *node = resource->object; + pw_client_node_destroy (node); } -static PinosClientNodeMethods client_node_methods = { +static struct pw_client_node_methods client_node_methods = { &client_node_update, &client_node_port_update, &client_node_event, @@ -1008,8 +1002,8 @@ static PinosClientNodeMethods client_node_methods = { static void proxy_on_data_fd_events (SpaSource *source) { - SpaProxy *this = source->data; - PinosClientNodeImpl *impl = this->impl; + struct proxy *this = source->data; + struct impl *impl = this->impl; if (source->rmask & (SPA_IO_ERR | SPA_IO_HUP)) { spa_log_warn (this->log, "proxy %p: got error", this); @@ -1022,9 +1016,9 @@ proxy_on_data_fd_events (SpaSource *source) read (this->data_source.fd, &cmd, 8); - while (pinos_transport_next_event (impl->transport, &event) == SPA_RESULT_OK) { + while (pw_transport_next_event (impl->transport, &event) == SPA_RESULT_OK) { SpaEvent *ev = alloca (SPA_POD_SIZE (&event)); - pinos_transport_parse_event (impl->transport, ev); + pw_transport_parse_event (impl->transport, ev); handle_node_event (this, ev); } } @@ -1057,7 +1051,7 @@ static const SpaNode proxy_node = { }; static SpaResult -proxy_init (SpaProxy *this, +proxy_init (struct proxy *this, SpaDict *info, const SpaSupport *support, uint32_t n_support) @@ -1091,49 +1085,49 @@ proxy_init (SpaProxy *this, } static void -on_initialized (PinosListener *listener, - PinosNode *node) +on_initialized (struct pw_listener *listener, + struct pw_node *node) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (listener, PinosClientNodeImpl, initialized); - PinosClientNode *this = &impl->this; - PinosTransportInfo info; + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, initialized); + struct pw_client_node *this = &impl->this; + struct pw_transport_info info; if (this->resource == NULL) return; - impl->transport = pinos_transport_new (node->max_input_ports, + impl->transport = pw_transport_new (node->max_input_ports, node->max_output_ports); impl->transport->area->n_inputs = node->n_input_ports; impl->transport->area->n_outputs = node->n_output_ports; - pinos_transport_get_info (impl->transport, &info); - pinos_client_node_notify_transport (this->resource, + pw_transport_get_info (impl->transport, &info); + pw_client_node_notify_transport (this->resource, info.memfd, info.offset, info.size); } static void -on_loop_changed (PinosListener *listener, - PinosNode *node) +on_loop_changed (struct pw_listener *listener, + struct pw_node *node) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (listener, PinosClientNodeImpl, loop_changed); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, loop_changed); impl->proxy.data_loop = node->data_loop->loop->loop; } static void -on_global_added (PinosListener *listener, - PinosCore *core, - PinosGlobal *global) +on_global_added (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (listener, PinosClientNodeImpl, global_added); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added); if (global->object == impl->this.node) global->owner = impl->this.client; } static SpaResult -proxy_clear (SpaProxy *this) +proxy_clear (struct proxy *this) { uint32_t i; @@ -1150,40 +1144,40 @@ proxy_clear (SpaProxy *this) } static void -client_node_resource_destroy (PinosResource *resource) +client_node_resource_destroy (struct pw_resource *resource) { - PinosClientNode *this = resource->object; - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (this, PinosClientNodeImpl, this); - SpaProxy *proxy = &impl->proxy; + struct pw_client_node *this = resource->object; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct proxy *proxy = &impl->proxy; - pinos_log_debug ("client-node %p: destroy", impl); - pinos_signal_emit (&this->destroy_signal, this); + pw_log_debug ("client-node %p: destroy", impl); + pw_signal_emit (&this->destroy_signal, this); impl->proxy.resource = this->resource = NULL; - pinos_signal_remove (&impl->global_added); - pinos_signal_remove (&impl->loop_changed); - pinos_signal_remove (&impl->initialized); + pw_signal_remove (&impl->global_added); + pw_signal_remove (&impl->loop_changed); + pw_signal_remove (&impl->initialized); if (proxy->data_source.fd != -1) spa_loop_remove_source (proxy->data_loop, &proxy->data_source); - pinos_node_destroy (this->node); + pw_node_destroy (this->node); } static void -on_node_free (PinosListener *listener, - PinosNode *node) +on_node_free (struct pw_listener *listener, + struct pw_node *node) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (listener, PinosClientNodeImpl, node_free); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, node_free); - pinos_log_debug ("client-node %p: free", &impl->this); + pw_log_debug ("client-node %p: free", &impl->this); proxy_clear (&impl->proxy); - pinos_signal_remove (&impl->node_free); + pw_signal_remove (&impl->node_free); if (impl->transport) - pinos_transport_destroy (impl->transport); + pw_transport_destroy (impl->transport); if (impl->fds[0] != -1) close (impl->fds[0]); @@ -1193,25 +1187,26 @@ on_node_free (PinosListener *listener, } /** - * pinos_client_node_new: - * @daemon: a #PinosDaemon + * pw_client_node_new: + * @client: a #pw_client + * @id: an id * @name: a name * @properties: extra properties * - * Create a new #PinosNode. + * Create a new #struct pw_node. * - * Returns: a new #PinosNode + * Returns: a new #struct pw_node */ -PinosClientNode * -pinos_client_node_new (PinosClient *client, - uint32_t id, - const char *name, - PinosProperties *properties) +struct pw_client_node * +pw_client_node_new (struct pw_client *client, + uint32_t id, + const char *name, + struct pw_properties *properties) { - PinosClientNodeImpl *impl; - PinosClientNode *this; + struct impl *impl; + struct pw_client_node *this; - impl = calloc (1, sizeof (PinosClientNodeImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; @@ -1220,13 +1215,13 @@ pinos_client_node_new (PinosClient *client, impl->core = client->core; impl->fds[0] = impl->fds[1] = -1; - pinos_log_debug ("client-node %p: new", impl); + pw_log_debug ("client-node %p: new", impl); - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); proxy_init (&impl->proxy, NULL, client->core->support, client->core->n_support); - this->node = pinos_node_new (client->core, + this->node = pw_node_new (client->core, client, name, true, @@ -1238,29 +1233,29 @@ pinos_client_node_new (PinosClient *client, impl->proxy.impl = impl; - this->resource = pinos_resource_new (client, + this->resource = pw_resource_new (client, id, client->core->type.client_node, this, - (PinosDestroy) client_node_resource_destroy); + (pw_destroy_t) client_node_resource_destroy); if (this->resource == NULL) goto error_no_resource; impl->proxy.resource = this->resource; - pinos_signal_add (&this->node->free_signal, + pw_signal_add (&this->node->free_signal, &impl->node_free, on_node_free); - pinos_signal_add (&this->node->initialized, + pw_signal_add (&this->node->initialized, &impl->initialized, on_initialized); - pinos_signal_add (&this->node->loop_changed, + pw_signal_add (&this->node->loop_changed, &impl->loop_changed, on_loop_changed); - pinos_signal_add (&impl->core->global_added, + pw_signal_add (&impl->core->global_added, &impl->global_added, on_global_added); @@ -1269,7 +1264,7 @@ pinos_client_node_new (PinosClient *client, return this; error_no_resource: - pinos_node_destroy (this->node); + pw_node_destroy (this->node); error_no_node: proxy_clear (&impl->proxy); free (impl); @@ -1277,14 +1272,14 @@ error_no_node: } void -pinos_client_node_destroy (PinosClientNode * this) +pw_client_node_destroy (struct pw_client_node * this) { - pinos_resource_destroy (this->resource); + pw_resource_destroy (this->resource); } /** - * pinos_client_node_get_fds: - * @node: a #PinosClientNode + * pw_client_node_get_fds: + * @node: a #struct pw_client_node * @readfd: an fd for reading * @writefd: an fd for writing * @@ -1293,11 +1288,11 @@ pinos_client_node_destroy (PinosClientNode * this) * Returns: %SPA_RESULT_OK on success */ SpaResult -pinos_client_node_get_fds (PinosClientNode *this, +pw_client_node_get_fds (struct pw_client_node *this, int *readfd, int *writefd) { - PinosClientNodeImpl *impl = SPA_CONTAINER_OF (this, PinosClientNodeImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); if (impl->fds[0] == -1) { #if 0 @@ -1318,7 +1313,7 @@ pinos_client_node_get_fds (PinosClientNode *this, #endif spa_loop_add_source (impl->proxy.data_loop, &impl->proxy.data_source); - pinos_log_debug ("client-node %p: add data fd %d", this, impl->proxy.data_source.fd); + pw_log_debug ("client-node %p: add data fd %d", this, impl->proxy.data_source.fd); } *readfd = impl->other_fds[0]; *writefd = impl->other_fds[1]; diff --git a/pipewire/server/client-node.h b/pipewire/server/client-node.h new file mode 100644 index 000000000..874026941 --- /dev/null +++ b/pipewire/server/client-node.h @@ -0,0 +1,61 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_CLIENT_NODE_H__ +#define __PIPEWIRE_CLIENT_NODE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPEWIRE_TYPE__ClientNode "PipeWire:Object:ClientNode" +#define PIPEWIRE_TYPE_CLIENT_NODE_BASE PIPEWIRE_TYPE__ClientNode ":" + +/** + * pw_client_node: + * + * PipeWire client node interface + */ +struct pw_client_node { + struct pw_node *node; + + struct pw_client *client; + struct pw_resource *resource; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_client_node *node)); +}; + +struct pw_client_node * pw_client_node_new (struct pw_client *client, + uint32_t id, + const char *name, + struct pw_properties *properties); +void pw_client_node_destroy (struct pw_client_node *node); + +SpaResult pw_client_node_get_fds (struct pw_client_node *node, + int *readfd, + int *writefd); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_CLIENT_NODE_H__ */ diff --git a/pinos/server/client.c b/pipewire/server/client.c similarity index 54% rename from pinos/server/client.c rename to pipewire/server/client.c index cad2a2544..7ea104a70 100644 --- a/pinos/server/client.c +++ b/pipewire/server/client.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,34 +19,34 @@ #include -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" -#include "pinos/server/client.h" -#include "pinos/server/resource.h" +#include "pipewire/server/client.h" +#include "pipewire/server/resource.h" -typedef struct +struct impl { - PinosClient this; -} PinosClientImpl; + struct pw_client this; +}; static void client_unbind_func (void *data) { - PinosResource *resource = data; + struct pw_resource *resource = data; spa_list_remove (&resource->link); } static SpaResult -client_bind_func (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +client_bind_func (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { - PinosClient *this = global->object; - PinosResource *resource; + struct pw_client *this = global->object; + struct pw_resource *resource; - resource = pinos_resource_new (client, + resource = pw_resource_new (client, id, global->type, global->object, @@ -54,18 +54,18 @@ client_bind_func (PinosGlobal *global, if (resource == NULL) goto no_mem; - pinos_log_debug ("client %p: bound to %d", global->object, resource->id); + pw_log_debug ("client %p: bound to %d", global->object, resource->id); spa_list_insert (this->resource_list.prev, &resource->link); this->info.change_mask = ~0; - pinos_client_notify_info (resource, &this->info); + pw_client_notify_info (resource, &this->info); return SPA_RESULT_OK; no_mem: - pinos_log_error ("can't create client resource"); - pinos_core_notify_error (client->core_resource, + pw_log_error ("can't create client resource"); + pw_core_notify_error (client->core_resource, client->core_resource->id, SPA_RESULT_NO_MEMORY, "no memory"); @@ -73,27 +73,27 @@ no_mem: } /** - * pinos_client_new: - * @daemon: a #PinosDaemon + * pw_client_new: + * @core: a #pw_core * @properties: extra client properties * - * Make a new #PinosClient object and register it to @core + * Make a new #struct pw_client object and register it to @core * - * Returns: a new #PinosClient + * Returns: a new #struct pw_client */ -PinosClient * -pinos_client_new (PinosCore *core, - struct ucred *ucred, - PinosProperties *properties) +struct pw_client * +pw_client_new (struct pw_core *core, + struct ucred *ucred, + struct pw_properties *properties) { - PinosClient *this; - PinosClientImpl *impl; + struct pw_client *this; + struct impl *impl; - impl = calloc (1, sizeof (PinosClientImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; - pinos_log_debug ("client %p: new", impl); + pw_log_debug ("client %p: new", impl); this = &impl->this; this->core = core; @@ -102,17 +102,17 @@ pinos_client_new (PinosCore *core, this->properties = properties; spa_list_init (&this->resource_list); - pinos_signal_init (&this->properties_changed); - pinos_signal_init (&this->resource_added); - pinos_signal_init (&this->resource_removed); + pw_signal_init (&this->properties_changed); + pw_signal_init (&this->resource_added); + pw_signal_init (&this->resource_removed); - pinos_map_init (&this->objects, 0, 32); - pinos_map_init (&this->types, 0, 32); - pinos_signal_init (&this->destroy_signal); + pw_map_init (&this->objects, 0, 32); + pw_map_init (&this->types, 0, 32); + pw_signal_init (&this->destroy_signal); spa_list_insert (core->client_list.prev, &this->link); - pinos_core_add_global (core, + pw_core_add_global (core, this, core->type.client, 0, @@ -130,55 +130,55 @@ static void destroy_resource (void *object, void *data) { - pinos_resource_destroy (object); + pw_resource_destroy (object); } /** - * pinos_client_destroy: - * @client: a #PinosClient + * pw_client_destroy: + * @client: a #struct pw_client * * Trigger removal of @client */ void -pinos_client_destroy (PinosClient * client) +pw_client_destroy (struct pw_client * client) { - PinosResource *resource, *tmp; - PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, this); + struct pw_resource *resource, *tmp; + struct impl *impl = SPA_CONTAINER_OF (client, struct impl, this); - pinos_log_debug ("client %p: destroy", client); - pinos_signal_emit (&client->destroy_signal, client); + pw_log_debug ("client %p: destroy", client); + pw_signal_emit (&client->destroy_signal, client); spa_list_remove (&client->link); - pinos_global_destroy (client->global); + pw_global_destroy (client->global); spa_list_for_each_safe (resource, tmp, &client->resource_list, link) - pinos_resource_destroy (resource); + pw_resource_destroy (resource); - pinos_map_for_each (&client->objects, destroy_resource, client); + pw_map_for_each (&client->objects, destroy_resource, client); - pinos_log_debug ("client %p: free", impl); - pinos_map_clear (&client->objects); + pw_log_debug ("client %p: free", impl); + pw_map_clear (&client->objects); if (client->properties) - pinos_properties_free (client->properties); + pw_properties_free (client->properties); free (impl); } void -pinos_client_update_properties (PinosClient *client, - const SpaDict *dict) +pw_client_update_properties (struct pw_client *client, + const SpaDict *dict) { - PinosResource *resource; + struct pw_resource *resource; if (client->properties == NULL) { if (dict) - client->properties = pinos_properties_new_dict (dict); + client->properties = pw_properties_new_dict (dict); } else { uint32_t i; for (i = 0; i < dict->n_items; i++) - pinos_properties_set (client->properties, + pw_properties_set (client->properties, dict->items[i].key, dict->items[i].value); } @@ -186,9 +186,9 @@ pinos_client_update_properties (PinosClient *client, client->info.change_mask = 1 << 0; client->info.props = client->properties ? &client->properties->dict : NULL; - pinos_signal_emit (&client->properties_changed, client); + pw_signal_emit (&client->properties_changed, client); spa_list_for_each (resource, &client->resource_list, link) { - pinos_client_notify_info (resource, &client->info); + pw_client_notify_info (resource, &client->info); } } diff --git a/pipewire/server/client.h b/pipewire/server/client.h new file mode 100644 index 000000000..b5a10cea0 --- /dev/null +++ b/pipewire/server/client.h @@ -0,0 +1,86 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_CLIENT_H__ +#define __PIPEWIRE_CLIENT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include + +#include +#include + +/** + * pw_client: + * + * PipeWire client object class. + */ +struct pw_client { + struct pw_core *core; + SpaList link; + struct pw_global *global; + + struct pw_properties *properties; + PW_SIGNAL (properties_changed, (struct pw_listener *listener, + struct pw_client *client)); + + struct pw_client_info info; + bool ucred_valid; + struct ucred ucred; + + void *protocol_private; + + struct pw_resource *core_resource; + + struct pw_map objects; + uint32_t n_types; + struct pw_map types; + + SpaList resource_list; + PW_SIGNAL (resource_added, (struct pw_listener *listener, + struct pw_client *client, + struct pw_resource *resource)); + PW_SIGNAL (resource_removed, (struct pw_listener *listener, + struct pw_client *client, + struct pw_resource *resource)); + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_client *client)); +}; + +struct pw_client * pw_client_new (struct pw_core *core, + struct ucred *ucred, + struct pw_properties *properties); +void pw_client_destroy (struct pw_client *client); + +void pw_client_update_properties (struct pw_client *client, + const SpaDict *dict); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_CLIENT_H__ */ diff --git a/pinos/server/command.c b/pipewire/server/command.c similarity index 58% rename from pinos/server/command.c rename to pipewire/server/command.c index 7661064c8..a5a6a7632 100644 --- a/pinos/server/command.c +++ b/pipewire/server/command.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -20,59 +20,58 @@ #include -#include -#include -#include +#include +#include +#include #include "command.h" -typedef bool (*PinosCommandFunc) (PinosCommand *command, - PinosCore *core, - char **err); +typedef bool (*pw_command_func_t) (struct pw_command *command, + struct pw_core *core, + char **err); -static bool execute_command_module_load (PinosCommand *command, - PinosCore *core, - char **err); +static bool execute_command_module_load (struct pw_command *command, + struct pw_core *core, + char **err); -typedef PinosCommand * (*PinosCommandParseFunc) (const char *line, +typedef struct pw_command * (*pw_command_parse_func_t) (const char *line, char **err); -static PinosCommand * parse_command_module_load (const char *line, +static struct pw_command * parse_command_module_load (const char *line, char **err); -typedef struct -{ - PinosCommand this; +struct impl { + struct pw_command this; - PinosCommandFunc func; + pw_command_func_t func; char **args; int n_args; -} PinosCommandImpl; +}; -typedef struct _CommandParse +struct command_parse { const char *name; - PinosCommandParseFunc func; -} CommandParse; + pw_command_parse_func_t func; +}; -static const CommandParse parsers[] = { +static const struct command_parse parsers[] = { {"load-module", parse_command_module_load}, {NULL, NULL} }; static const char whitespace[] = " \t"; -static PinosCommand * +static struct pw_command * parse_command_module_load (const char * line, char ** err) { - PinosCommandImpl *impl; + struct impl *impl; - impl = calloc (1, sizeof (PinosCommandImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) goto no_mem; impl->func = execute_command_module_load; - impl->args = pinos_split_strv (line, whitespace, 3, &impl->n_args); + impl->args = pw_split_strv (line, whitespace, 3, &impl->n_args); if (impl->args[1] == NULL) goto no_module; @@ -83,7 +82,7 @@ parse_command_module_load (const char * line, char ** err) no_module: asprintf (err, "%s requires a module name", impl->args[0]); - pinos_free_strv (impl->args); + pw_free_strv (impl->args); return NULL; no_mem: asprintf (err, "no memory"); @@ -91,50 +90,50 @@ no_mem: } static bool -execute_command_module_load (PinosCommand *command, - PinosCore *core, - char **err) +execute_command_module_load (struct pw_command *command, + struct pw_core *core, + char **err) { - PinosCommandImpl *impl = SPA_CONTAINER_OF (command, PinosCommandImpl, this); + struct impl *impl = SPA_CONTAINER_OF (command, struct impl, this); - return pinos_module_load (core, + return pw_module_load (core, impl->args[1], impl->args[2], err) != NULL; } /** - * pinos_command_free: - * @command: A #PinosCommand + * pw_command_free: + * @command: A #struct pw_command * * Free all resources assicated with @command. */ void -pinos_command_free (PinosCommand * command) +pw_command_free (struct pw_command * command) { - PinosCommandImpl *impl = SPA_CONTAINER_OF (command, PinosCommandImpl, this); + struct impl *impl = SPA_CONTAINER_OF (command, struct impl, this); spa_list_remove (&command->link); - pinos_free_strv (impl->args); + pw_free_strv (impl->args); free (impl); } /** - * pinos_command_parse: + * pw_command_parse: * @line: command line to parse * @err: Return location for an error * * Parses a command line, @line, and return the parsed command. - * A command can later be executed with pinos_command_run(). + * A command can later be executed with pw_command_run(). * * Returns: The command or %NULL when @err is set. */ -PinosCommand * -pinos_command_parse (const char *line, - char **err) +struct pw_command * +pw_command_parse (const char *line, + char **err) { - PinosCommand *command = NULL; - const CommandParse *parse; + struct pw_command *command = NULL; + const struct command_parse *parse; char *name; size_t len; @@ -156,9 +155,9 @@ out: } /** - * pinos_command_run: - * @command: A #PinosCommand - * @core: A #PinosCore + * pw_command_run: + * @command: A #struct pw_comman + * @core: A #struct pw_core * @err: Return location for a #GError, or %NULL * * Run @command. @@ -166,27 +165,27 @@ out: * Returns: %true if @command was executed successfully, %false otherwise. */ bool -pinos_command_run (PinosCommand *command, - PinosCore *core, - char **err) +pw_command_run (struct pw_command *command, + struct pw_core *core, + char **err) { - PinosCommandImpl *impl = SPA_CONTAINER_OF (command, PinosCommandImpl, this); + struct impl *impl = SPA_CONTAINER_OF (command, struct impl, this); return impl->func (command, core, err); } /** - * pinos_command_get_name: - * @command: A #PinosCommand + * pw_command_get_name: + * @command: A #struct pw_command * * Get the name of @command. * * Returns: The name of @command. */ const char * -pinos_command_get_name (PinosCommand * command) +pw_command_get_name (struct pw_command * command) { - PinosCommandImpl *impl = SPA_CONTAINER_OF (command, PinosCommandImpl, this); + struct impl *impl = SPA_CONTAINER_OF (command, struct impl, this); return impl->args[0]; } diff --git a/pinos/server/command.h b/pipewire/server/command.h similarity index 59% rename from pinos/server/command.h rename to pipewire/server/command.h index ac502b04d..9c8189c8e 100644 --- a/pinos/server/command.h +++ b/pipewire/server/command.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -18,33 +18,30 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_COMMAND_H__ -#define __PINOS_COMMAND_H__ +#ifndef __PIPEWIRE_COMMAND_H__ +#define __PIPEWIRE_COMMAND_H__ #ifdef __cplusplus extern "C" { #endif -#include +#include -typedef struct _PinosCommand PinosCommand; - - -struct _PinosCommand { +struct pw_command { SpaList link; const char *name; }; -void pinos_command_free (PinosCommand *command); -PinosCommand * pinos_command_parse (const char *line, - char **err); -bool pinos_command_run (PinosCommand *command, - PinosCore *core, - char **err); +struct pw_command * pw_command_parse (const char *line, + char **err); +void pw_command_free (struct pw_command *command); +bool pw_command_run (struct pw_command *command, + struct pw_core *core, + char **err); #ifdef __cplusplus } #endif -#endif /* __PINOS_COMMAND_H__ */ +#endif /* __PIPEWIRE_COMMAND_H__ */ diff --git a/pinos/server/core.c b/pipewire/server/core.c similarity index 51% rename from pinos/server/core.c rename to pipewire/server/core.c index 154b36bed..d71e7e40b 100644 --- a/pinos/server/core.c +++ b/pipewire/server/core.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -18,25 +18,24 @@ */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -typedef struct { - PinosGlobal this; - PinosBindFunc bind; -} PinosGlobalImpl; +struct global_impl { + struct pw_global this; + pw_bind_func_t bind; +}; -typedef struct { - PinosCore this; +struct impl { + struct pw_core this; SpaSupport support[4]; - -} PinosCoreImpl; +}; #define ACCESS_VIEW_GLOBAL(client,global) (client->core->access == NULL || \ client->core->access->view_global (client->core->access, \ @@ -47,10 +46,10 @@ registry_bind (void *object, uint32_t id, uint32_t new_id) { - PinosResource *resource = object; - PinosClient *client = resource->client; - PinosCore *core = resource->core; - PinosGlobal *global; + struct pw_resource *resource = object; + struct pw_client *client = resource->client; + struct pw_core *core = resource->core; + struct pw_global *global; spa_list_for_each (global, &core->global_list, link) if (global->id == id) @@ -62,29 +61,29 @@ registry_bind (void *object, if (!ACCESS_VIEW_GLOBAL (client, global)) goto no_id; - pinos_log_debug ("global %p: bind object id %d to %d", global, id, new_id); - pinos_global_bind (global, client, 0, new_id); + pw_log_debug ("global %p: bind object id %d to %d", global, id, new_id); + pw_global_bind (global, client, 0, new_id); return; no_id: - pinos_log_debug ("registry %p: no global with id %u to bind to %u", resource, id, new_id); + pw_log_debug ("registry %p: no global with id %u to bind to %u", resource, id, new_id); /* unmark the new_id the map, the client does not yet know about the failed * bind and will choose the next id, which we would refuse when we don't mark * new_id as 'used and freed' */ - pinos_map_insert_at (&client->objects, new_id, NULL); - pinos_core_notify_remove_id (client->core_resource, new_id); + pw_map_insert_at (&client->objects, new_id, NULL); + pw_core_notify_remove_id (client->core_resource, new_id); return; } -static PinosRegistryMethods registry_methods = { +static struct pw_registry_methods registry_methods = { ®istry_bind }; static void destroy_registry_resource (void *object) { - PinosResource *resource = object; + struct pw_resource *resource = object; spa_list_remove (&resource->link); } @@ -92,31 +91,31 @@ static void core_client_update (void *object, const SpaDict *props) { - PinosResource *resource = object; + struct pw_resource *resource = object; - pinos_client_update_properties (resource->client, props); + pw_client_update_properties (resource->client, props); } static void core_sync (void *object, uint32_t seq) { - PinosResource *resource = object; + struct pw_resource *resource = object; - pinos_core_notify_done (resource, seq); + pw_core_notify_done (resource, seq); } static void core_get_registry (void *object, uint32_t new_id) { - PinosResource *resource = object; - PinosClient *client = resource->client; - PinosCore *this = resource->core; - PinosGlobal *global; - PinosResource *registry_resource; + struct pw_resource *resource = object; + struct pw_client *client = resource->client; + struct pw_core *this = resource->core; + struct pw_global *global; + struct pw_resource *registry_resource; - registry_resource = pinos_resource_new (client, + registry_resource = pw_resource_new (client, new_id, this->type.registry, this, @@ -130,7 +129,7 @@ core_get_registry (void *object, spa_list_for_each (global, &this->global_list, link) { if (ACCESS_VIEW_GLOBAL (client, global)) - pinos_registry_notify_global (registry_resource, + pw_registry_notify_global (registry_resource, global->id, spa_type_map_get_type (this->type.map, global->type)); } @@ -138,8 +137,8 @@ core_get_registry (void *object, return; no_mem: - pinos_log_error ("can't create registry resource"); - pinos_core_notify_error (client->core_resource, + pw_log_error ("can't create registry resource"); + pw_core_notify_error (client->core_resource, resource->id, SPA_RESULT_NO_MEMORY, "no memory"); @@ -152,40 +151,40 @@ core_create_node (void *object, const SpaDict *props, uint32_t new_id) { - PinosResource *resource = object; - PinosClient *client = resource->client; + struct pw_resource *resource = object; + struct pw_client *client = resource->client; - pinos_core_notify_error (client->core_resource, + pw_core_notify_error (client->core_resource, resource->id, SPA_RESULT_NOT_IMPLEMENTED, "not implemented"); } -typedef struct { - PinosAccessData data; +struct access_create_client_node { + struct pw_access_data data; char *name; - PinosProperties *properties; + struct pw_properties *properties; uint32_t new_id; bool async; -} AccessCreateClientNode; +}; static void * -async_create_client_node_copy (PinosAccessData *data, size_t size) +async_create_client_node_copy (struct pw_access_data *data, size_t size) { - AccessCreateClientNode *d; + struct access_create_client_node *d; - d = calloc (1, sizeof (AccessCreateClientNode) + size); - memcpy (d, data, sizeof (AccessCreateClientNode)); + d = calloc (1, sizeof (struct access_create_client_node) + size); + memcpy (d, data, sizeof (struct access_create_client_node)); d->name = strdup (d->name); d->async = true; - d->data.user_data = SPA_MEMBER (d, sizeof (AccessCreateClientNode), void); + d->data.user_data = SPA_MEMBER (d, sizeof (struct access_create_client_node), void); return d; } static void -async_create_client_node_free (PinosAccessData *data) +async_create_client_node_free (struct pw_access_data *data) { - AccessCreateClientNode *d = (AccessCreateClientNode *) data; + struct access_create_client_node *d = (struct access_create_client_node *) data; if (d->async) { if (d->data.free_cb) @@ -196,51 +195,51 @@ async_create_client_node_free (PinosAccessData *data) } static void -async_create_client_node_complete (PinosAccessData *data) +async_create_client_node_complete (struct pw_access_data *data) { - AccessCreateClientNode *d = (AccessCreateClientNode *) data; - PinosResource *resource = d->data.resource; - PinosClient *client = resource->client; - PinosClientNode *node; + struct access_create_client_node *d = (struct access_create_client_node *) data; + struct pw_resource *resource = d->data.resource; + struct pw_client *client = resource->client; + struct pw_client_node *node; SpaResult res; int readfd, writefd; if (data->res != SPA_RESULT_OK) goto denied; - node = pinos_client_node_new (client, - d->new_id, - d->name, - d->properties); + node = pw_client_node_new (client, + d->new_id, + d->name, + d->properties); if (node == NULL) goto no_mem; - if ((res = pinos_client_node_get_fds (node, &readfd, &writefd)) < 0) { - pinos_core_notify_error (client->core_resource, - resource->id, - SPA_RESULT_ERROR, - "can't get data fds"); + if ((res = pw_client_node_get_fds (node, &readfd, &writefd)) < 0) { + pw_core_notify_error (client->core_resource, + resource->id, + SPA_RESULT_ERROR, + "can't get data fds"); return; } - pinos_client_node_notify_done (node->resource, - readfd, - writefd); + pw_client_node_notify_done (node->resource, + readfd, + writefd); goto done; no_mem: - pinos_log_error ("can't create client node"); - pinos_core_notify_error (client->core_resource, - resource->id, - SPA_RESULT_NO_MEMORY, - "no memory"); + pw_log_error ("can't create client node"); + pw_core_notify_error (client->core_resource, + resource->id, + SPA_RESULT_NO_MEMORY, + "no memory"); goto done; denied: - pinos_log_error ("create client node refused"); - pinos_core_notify_error (client->core_resource, - resource->id, - SPA_RESULT_NO_PERMISSION, - "operation not allowed"); + pw_log_error ("create client node refused"); + pw_core_notify_error (client->core_resource, + resource->id, + SPA_RESULT_NO_PERMISSION, + "operation not allowed"); done: async_create_client_node_free (&d->data); return; @@ -252,20 +251,20 @@ core_create_client_node (void *object, const SpaDict *props, uint32_t new_id) { - PinosResource *resource = object; - PinosClient *client = resource->client; + struct pw_resource *resource = object; + struct pw_client *client = resource->client; int i; - PinosProperties *properties; - AccessCreateClientNode access_data; + struct pw_properties *properties; + struct access_create_client_node access_data; SpaResult res; - properties = pinos_properties_new (NULL, NULL); + properties = pw_properties_new (NULL, NULL); if (properties == NULL) goto no_mem; for (i = 0; i < props->n_items; i++) { - pinos_properties_set (properties, props->items[i].key, - props->items[i].value); + pw_properties_set (properties, props->items[i].key, + props->items[i].value); } access_data.data.resource = resource; @@ -291,11 +290,11 @@ core_create_client_node (void *object, return; no_mem: - pinos_log_error ("can't create client node"); - pinos_core_notify_error (client->core_resource, - resource->id, - SPA_RESULT_NO_MEMORY, - "no memory"); + pw_log_error ("can't create client node"); + pw_core_notify_error (client->core_resource, + resource->id, + SPA_RESULT_NO_MEMORY, + "no memory"); return; } @@ -305,19 +304,19 @@ core_update_types (void *object, uint32_t n_types, const char **types) { - PinosResource *resource = object; - PinosCore *this = resource->core; - PinosClient *client = resource->client; + struct pw_resource *resource = object; + struct pw_core *this = resource->core; + struct pw_client *client = resource->client; int i; for (i = 0; i < n_types; i++, first_id++) { uint32_t this_id = spa_type_map_get_id (this->type.map, types[i]); - if (!pinos_map_insert_at (&client->types, first_id, PINOS_MAP_ID_TO_PTR (this_id))) - pinos_log_error ("can't add type for client"); + if (!pw_map_insert_at (&client->types, first_id, PW_MAP_ID_TO_PTR (this_id))) + pw_log_error ("can't add type for client"); } } -static PinosCoreMethods core_methods = { +static struct pw_core_methods core_methods = { &core_client_update, &core_sync, &core_get_registry, @@ -329,25 +328,25 @@ static PinosCoreMethods core_methods = { static void core_unbind_func (void *data) { - PinosResource *resource = data; + struct pw_resource *resource = data; resource->client->core_resource = NULL; spa_list_remove (&resource->link); } static SpaResult -core_bind_func (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +core_bind_func (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { - PinosCore *this = global->object; - PinosResource *resource; + struct pw_core *this = global->object; + struct pw_resource *resource; - resource = pinos_resource_new (client, - id, - global->type, - global->object, - core_unbind_func); + resource = pw_resource_new (client, + id, + global->type, + global->object, + core_unbind_func); if (resource == NULL) goto no_mem; @@ -356,44 +355,44 @@ core_bind_func (PinosGlobal *global, spa_list_insert (this->resource_list.prev, &resource->link); client->core_resource = resource; - pinos_log_debug ("core %p: bound to %d", global->object, resource->id); + pw_log_debug ("core %p: bound to %d", global->object, resource->id); - this->info.change_mask = PINOS_CORE_CHANGE_MASK_ALL; - pinos_core_notify_info (resource, &this->info); + this->info.change_mask = PW_CORE_CHANGE_MASK_ALL; + pw_core_notify_info (resource, &this->info); return SPA_RESULT_OK; no_mem: - pinos_log_error ("can't create core resource"); + pw_log_error ("can't create core resource"); return SPA_RESULT_NO_MEMORY; } -PinosCore * -pinos_core_new (PinosMainLoop *main_loop, - PinosProperties *properties) +struct pw_core * +pw_core_new (struct pw_main_loop *main_loop, + struct pw_properties *properties) { - PinosCoreImpl *impl; - PinosCore *this; + struct impl *impl; + struct pw_core *this; - impl = calloc (1, sizeof (PinosCoreImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; this = &impl->this; - this->data_loop = pinos_data_loop_new (); + this->data_loop = pw_data_loop_new (); if (this->data_loop == NULL) goto no_data_loop; this->main_loop = main_loop; this->properties = properties; - pinos_type_init (&this->type); - pinos_map_init (&this->objects, 128, 32); + pw_type_init (&this->type); + pw_map_init (&this->objects, 128, 32); impl->support[0].type = SPA_TYPE__TypeMap; impl->support[0].data = this->type.map; impl->support[1].type = SPA_TYPE__Log; - impl->support[1].data = pinos_log_get (); + impl->support[1].data = pw_log_get (); impl->support[2].type = SPA_TYPE_LOOP__DataLoop; impl->support[2].data = this->data_loop->loop->loop; impl->support[3].type = SPA_TYPE_LOOP__MainLoop; @@ -401,7 +400,7 @@ pinos_core_new (PinosMainLoop *main_loop, this->support = impl->support; this->n_support = 4; - pinos_data_loop_start (this->data_loop); + pw_data_loop_start (this->data_loop); spa_list_init (&this->resource_list); spa_list_init (&this->registry_resource_list); @@ -410,24 +409,24 @@ pinos_core_new (PinosMainLoop *main_loop, spa_list_init (&this->node_list); spa_list_init (&this->node_factory_list); spa_list_init (&this->link_list); - pinos_signal_init (&this->destroy_signal); - pinos_signal_init (&this->global_added); - pinos_signal_init (&this->global_removed); + pw_signal_init (&this->destroy_signal); + pw_signal_init (&this->global_added); + pw_signal_init (&this->global_removed); - pinos_core_add_global (this, - NULL, - this->type.core, - 0, - this, - core_bind_func, - &this->global); + pw_core_add_global (this, + NULL, + this->type.core, + 0, + this, + core_bind_func, + &this->global); this->info.id = this->global->id; this->info.change_mask = 0; - this->info.user_name = pinos_get_user_name (); - this->info.host_name = pinos_get_host_name (); + this->info.user_name = pw_get_user_name (); + this->info.host_name = pw_get_host_name (); this->info.version = "0"; - this->info.name = "pinos-0"; + this->info.name = "pipewire-0"; srandom (time (NULL)); this->info.cookie = random (); this->info.props = this->properties ? &this->properties->dict : NULL; @@ -440,36 +439,36 @@ no_data_loop: } void -pinos_core_destroy (PinosCore *core) +pw_core_destroy (struct pw_core *core) { - PinosCoreImpl *impl = SPA_CONTAINER_OF (core, PinosCoreImpl, this); + struct impl *impl = SPA_CONTAINER_OF (core, struct impl, this); - pinos_log_debug ("core %p: destroy", core); - pinos_signal_emit (&core->destroy_signal, core); + pw_log_debug ("core %p: destroy", core); + pw_signal_emit (&core->destroy_signal, core); - pinos_data_loop_destroy (core->data_loop); + pw_data_loop_destroy (core->data_loop); - pinos_map_clear (&core->objects); + pw_map_clear (&core->objects); - pinos_log_debug ("core %p: free", core); + pw_log_debug ("core %p: free", core); free (impl); } bool -pinos_core_add_global (PinosCore *core, - PinosClient *owner, - uint32_t type, - uint32_t version, - void *object, - PinosBindFunc bind, - PinosGlobal **global) +pw_core_add_global (struct pw_core *core, + struct pw_client *owner, + uint32_t type, + uint32_t version, + void *object, + pw_bind_func_t bind, + struct pw_global **global) { - PinosGlobalImpl *impl; - PinosGlobal *this; - PinosResource *registry; + struct global_impl *impl; + struct pw_global *this; + struct pw_resource *registry; const char *type_name; - impl = calloc (1, sizeof (PinosGlobalImpl)); + impl = calloc (1, sizeof (struct global_impl)); if (impl == NULL) return false; @@ -483,133 +482,133 @@ pinos_core_add_global (PinosCore *core, this->object = object; *global = this; - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); - this->id = pinos_map_insert_new (&core->objects, this); + this->id = pw_map_insert_new (&core->objects, this); spa_list_insert (core->global_list.prev, &this->link); - pinos_signal_emit (&core->global_added, core, this); + pw_signal_emit (&core->global_added, core, this); type_name = spa_type_map_get_type (core->type.map, this->type); - pinos_log_debug ("global %p: new %u %s, owner %p", this, this->id, type_name, owner); + pw_log_debug ("global %p: new %u %s, owner %p", this, this->id, type_name, owner); spa_list_for_each (registry, &core->registry_resource_list, link) if (ACCESS_VIEW_GLOBAL (registry->client, this)) - pinos_registry_notify_global (registry, - this->id, - type_name); + pw_registry_notify_global (registry, + this->id, + type_name); return true; } SpaResult -pinos_global_bind (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +pw_global_bind (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { SpaResult res; - PinosGlobalImpl *impl = SPA_CONTAINER_OF (global, PinosGlobalImpl, this); + struct global_impl *impl = SPA_CONTAINER_OF (global, struct global_impl, this); if (impl->bind) { res = impl->bind (global, client, version, id); } else { res = SPA_RESULT_NOT_IMPLEMENTED; - pinos_core_notify_error (client->core_resource, - client->core_resource->id, - res, - "can't bind object id %d", id); + pw_core_notify_error (client->core_resource, + client->core_resource->id, + res, + "can't bind object id %d", id); } return res; } void -pinos_global_destroy (PinosGlobal *global) +pw_global_destroy (struct pw_global *global) { - PinosCore *core = global->core; - PinosResource *registry; + struct pw_core *core = global->core; + struct pw_resource *registry; - pinos_log_debug ("global %p: destroy %u", global, global->id); - pinos_signal_emit (&global->destroy_signal, global); + pw_log_debug ("global %p: destroy %u", global, global->id); + pw_signal_emit (&global->destroy_signal, global); spa_list_for_each (registry, &core->registry_resource_list, link) if (ACCESS_VIEW_GLOBAL (registry->client, global)) - pinos_registry_notify_global_remove (registry, global->id); + pw_registry_notify_global_remove (registry, global->id); - pinos_map_remove (&core->objects, global->id); + pw_map_remove (&core->objects, global->id); spa_list_remove (&global->link); - pinos_signal_emit (&core->global_removed, core, global); + pw_signal_emit (&core->global_removed, core, global); - pinos_log_debug ("global %p: free", global); + pw_log_debug ("global %p: free", global); free (global); } void -pinos_core_update_properties (PinosCore *core, - const SpaDict *dict) +pw_core_update_properties (struct pw_core *core, + const SpaDict *dict) { - PinosResource *resource; + struct pw_resource *resource; if (core->properties == NULL) { if (dict) - core->properties = pinos_properties_new_dict (dict); + core->properties = pw_properties_new_dict (dict); } else if (dict != &core->properties->dict) { uint32_t i; for (i = 0; i < dict->n_items; i++) - pinos_properties_set (core->properties, - dict->items[i].key, - dict->items[i].value); + pw_properties_set (core->properties, + dict->items[i].key, + dict->items[i].value); } - core->info.change_mask = PINOS_CORE_CHANGE_MASK_PROPS; + core->info.change_mask = PW_CORE_CHANGE_MASK_PROPS; core->info.props = core->properties ? &core->properties->dict : NULL; spa_list_for_each (resource, &core->resource_list, link) { - pinos_core_notify_info (resource, &core->info); + pw_core_notify_info (resource, &core->info); } } -PinosPort * -pinos_core_find_port (PinosCore *core, - PinosPort *other_port, - uint32_t id, - PinosProperties *props, - uint32_t n_format_filters, - SpaFormat **format_filters, - char **error) +struct pw_port * +pw_core_find_port (struct pw_core *core, + struct pw_port *other_port, + uint32_t id, + struct pw_properties *props, + uint32_t n_format_filters, + SpaFormat **format_filters, + char **error) { - PinosPort *best = NULL; + struct pw_port *best = NULL; bool have_id; - PinosNode *n; + struct pw_node *n; have_id = id != SPA_ID_INVALID; - pinos_log_debug ("id \"%u\", %d", id, have_id); + pw_log_debug ("id \"%u\", %d", id, have_id); spa_list_for_each (n, &core->node_list, link) { if (n->global == NULL) continue; - pinos_log_debug ("node id \"%d\"", n->global->id); + pw_log_debug ("node id \"%d\"", n->global->id); if (have_id) { if (n->global->id == id) { - pinos_log_debug ("id \"%u\" matches node %p", id, n); + pw_log_debug ("id \"%u\" matches node %p", id, n); - best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction)); + best = pw_node_get_free_port (n, pw_direction_reverse (other_port->direction)); if (best) break; } } else { - PinosPort *p, *pin, *pout; + struct pw_port *p, *pin, *pout; - p = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction)); + p = pw_node_get_free_port (n, pw_direction_reverse (other_port->direction)); if (p == NULL) continue; - if (p->direction == PINOS_DIRECTION_OUTPUT) { + if (p->direction == PW_DIRECTION_OUTPUT) { pin = other_port; pout = p; } else { @@ -617,13 +616,13 @@ pinos_core_find_port (PinosCore *core, pout = other_port; } - if (pinos_core_find_format (core, - pout, - pin, - props, - n_format_filters, - format_filters, - error) == NULL) + if (pw_core_find_format (core, + pout, + pin, + props, + n_format_filters, + format_filters, + error) == NULL) continue; best = p; @@ -636,13 +635,13 @@ pinos_core_find_port (PinosCore *core, } SpaFormat * -pinos_core_find_format (PinosCore *core, - PinosPort *output, - PinosPort *input, - PinosProperties *props, - uint32_t n_format_filters, - SpaFormat **format_filterss, - char **error) +pw_core_find_format (struct pw_core *core, + struct pw_port *output, + struct pw_port *input, + struct pw_properties *props, + uint32_t n_format_filters, + SpaFormat **format_filterss, + char **error) { uint32_t out_state, in_state; SpaResult res; @@ -652,14 +651,14 @@ pinos_core_find_format (PinosCore *core, out_state = output->state; in_state = input->state; - pinos_log_debug ("core %p: finding best format %d %d", core, out_state, in_state); + pw_log_debug ("core %p: finding best format %d %d", core, out_state, in_state); - if (out_state > PINOS_PORT_STATE_CONFIGURE && output->node->state == PINOS_NODE_STATE_IDLE) - out_state = PINOS_PORT_STATE_CONFIGURE; - if (in_state > PINOS_PORT_STATE_CONFIGURE && input->node->state == PINOS_NODE_STATE_IDLE) - in_state = PINOS_PORT_STATE_CONFIGURE; + if (out_state > PW_PORT_STATE_CONFIGURE && output->node->state == PW_NODE_STATE_IDLE) + out_state = PW_PORT_STATE_CONFIGURE; + if (in_state > PW_PORT_STATE_CONFIGURE && input->node->state == PW_NODE_STATE_IDLE) + in_state = PW_PORT_STATE_CONFIGURE; - if (in_state == PINOS_PORT_STATE_CONFIGURE && out_state > PINOS_PORT_STATE_CONFIGURE) { + if (in_state == PW_PORT_STATE_CONFIGURE && out_state > PW_PORT_STATE_CONFIGURE) { /* only input needs format */ if ((res = spa_node_port_get_format (output->node->node, SPA_DIRECTION_OUTPUT, @@ -668,7 +667,7 @@ pinos_core_find_format (PinosCore *core, asprintf (error, "error get output format: %d", res); goto error; } - } else if (out_state == PINOS_PORT_STATE_CONFIGURE && in_state > PINOS_PORT_STATE_CONFIGURE) { + } else if (out_state == PW_PORT_STATE_CONFIGURE && in_state > PW_PORT_STATE_CONFIGURE) { /* only output needs format */ if ((res = spa_node_port_get_format (input->node->node, SPA_DIRECTION_INPUT, @@ -677,10 +676,10 @@ pinos_core_find_format (PinosCore *core, asprintf (error, "error get input format: %d", res); goto error; } - } else if (in_state == PINOS_PORT_STATE_CONFIGURE && out_state == PINOS_PORT_STATE_CONFIGURE) { + } else if (in_state == PW_PORT_STATE_CONFIGURE && out_state == PW_PORT_STATE_CONFIGURE) { again: /* both ports need a format */ - pinos_log_debug ("core %p: finding best format", core); + pw_log_debug ("core %p: finding best format", core); if ((res = spa_node_port_enum_formats (input->node->node, SPA_DIRECTION_INPUT, input->port_id, @@ -692,8 +691,8 @@ again: goto error; } } - pinos_log_debug ("Try filter: %p", filter); - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) + pw_log_debug ("Try filter: %p", filter); + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) spa_debug_format (filter, core->type.map); if ((res = spa_node_port_enum_formats (output->node->node, @@ -710,8 +709,8 @@ again: asprintf (error, "error output enum formats: %d", res); goto error; } - pinos_log_debug ("Got filtered:"); - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) + pw_log_debug ("Got filtered:"); + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) spa_debug_format (format, core->type.map); spa_format_fixate (format); @@ -729,11 +728,11 @@ error: return NULL; } -PinosNodeFactory * -pinos_core_find_node_factory (PinosCore *core, - const char *name) +struct pw_node_factory * +pw_core_find_node_factory (struct pw_core *core, + const char *name) { - PinosNodeFactory *factory; + struct pw_node_factory *factory; spa_list_for_each (factory, &core->node_factory_list, link) { if (strcmp (factory->name, name) == 0) diff --git a/pipewire/server/core.h b/pipewire/server/core.h new file mode 100644 index 000000000..182014023 --- /dev/null +++ b/pipewire/server/core.h @@ -0,0 +1,144 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_CORE_H__ +#define __PIPEWIRE_CORE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct pw_global; + +#include +#include +#include +#include +#include +#include +#include + +typedef SpaResult (*pw_bind_func_t) (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id); + +struct pw_global { + struct pw_core *core; + struct pw_client *owner; + + SpaList link; + uint32_t id; + uint32_t type; + uint32_t version; + void *object; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_global *global)); +}; + +/** + * struct pw_core: + * + * PipeWire core object class. + */ +struct pw_core { + struct pw_global *global; + + struct pw_core_info info; + + struct pw_properties *properties; + + struct pw_type type; + struct pw_access *access; + + struct pw_map objects; + + SpaList resource_list; + SpaList registry_resource_list; + SpaList global_list; + SpaList client_list; + SpaList node_list; + SpaList node_factory_list; + SpaList link_list; + + struct pw_main_loop *main_loop; + struct pw_data_loop *data_loop; + + SpaSupport *support; + uint32_t n_support; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_core *core)); + + PW_SIGNAL (global_added, (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global)); + PW_SIGNAL (global_removed, (struct pw_listener *listener, + struct pw_core *core, + struct pw_global *global)); +}; + +struct pw_core * pw_core_new (struct pw_main_loop *main_loop, + struct pw_properties *props); +void pw_core_destroy (struct pw_core *core); + +void pw_core_update_properties (struct pw_core *core, + const SpaDict *dict); + +bool pw_core_add_global (struct pw_core *core, + struct pw_client *owner, + uint32_t type, + uint32_t version, + void *object, + pw_bind_func_t bind, + struct pw_global **global); + +SpaResult pw_global_bind (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id); +void pw_global_destroy (struct pw_global *global); + +SpaFormat * pw_core_find_format (struct pw_core *core, + struct pw_port *output, + struct pw_port *input, + struct pw_properties *props, + uint32_t n_format_filters, + SpaFormat **format_filters, + char **error); + +struct pw_port * pw_core_find_port (struct pw_core *core, + struct pw_port *other_port, + uint32_t id, + struct pw_properties *props, + uint32_t n_format_filters, + SpaFormat **format_filters, + char **error); + +struct pw_node_factory * pw_core_find_node_factory (struct pw_core *core, + const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_CORE_H__ */ diff --git a/pinos/server/data-loop.c b/pipewire/server/data-loop.c similarity index 52% rename from pinos/server/data-loop.c rename to pipewire/server/data-loop.c index 759a43f0b..d073f7ce4 100644 --- a/pinos/server/data-loop.c +++ b/pipewire/server/data-loop.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -28,26 +28,25 @@ #include #include -#include "pinos/client/log.h" -#include "pinos/client/rtkit.h" -#include "pinos/server/data-loop.h" +#include "pipewire/client/log.h" +#include "pipewire/client/rtkit.h" +#include "pipewire/server/data-loop.h" -typedef struct +struct impl { - PinosDataLoop this; + struct pw_data_loop this; SpaSource *event; bool running; pthread_t thread; -} PinosDataLoopImpl; - +}; static void -make_realtime (PinosDataLoop *this) +make_realtime (struct pw_data_loop *this) { struct sched_param sp; - PinosRTKitBus *system_bus; + struct pw_rtkit_bus *system_bus; struct rlimit rl; int r, rtprio; long long rttime; @@ -59,52 +58,52 @@ make_realtime (PinosDataLoop *this) sp.sched_priority = rtprio; if (pthread_setschedparam (pthread_self(), SCHED_OTHER|SCHED_RESET_ON_FORK, &sp) == 0) { - pinos_log_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked."); + pw_log_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked."); return; } - system_bus = pinos_rtkit_bus_get_system (); + system_bus = pw_rtkit_bus_get_system (); rl.rlim_cur = rl.rlim_max = rttime; if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) - pinos_log_debug ("setrlimit() failed: %s", strerror (errno)); + pw_log_debug ("setrlimit() failed: %s", strerror (errno)); if (rttime >= 0) { r = getrlimit (RLIMIT_RTTIME, &rl); if (r >= 0 && (long long) rl.rlim_max > rttime) { - pinos_log_debug ("Clamping rlimit-rttime to %lld for RealtimeKit", rttime); + pw_log_debug ("Clamping rlimit-rttime to %lld for RealtimeKit", rttime); rl.rlim_cur = rl.rlim_max = rttime; if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) - pinos_log_debug ("setrlimit() failed: %s", strerror (errno)); + pw_log_debug ("setrlimit() failed: %s", strerror (errno)); } } - if ((r = pinos_rtkit_make_realtime (system_bus, 0, rtprio)) < 0) { - pinos_log_debug ("could not make thread realtime: %s", strerror (r)); + if ((r = pw_rtkit_make_realtime (system_bus, 0, rtprio)) < 0) { + pw_log_debug ("could not make thread realtime: %s", strerror (r)); } else { - pinos_log_debug ("thread made realtime"); + pw_log_debug ("thread made realtime"); } - pinos_rtkit_bus_free (system_bus); + pw_rtkit_bus_free (system_bus); } static void * do_loop (void *user_data) { - PinosDataLoopImpl *impl = user_data; - PinosDataLoop *this = &impl->this; + struct impl *impl = user_data; + struct pw_data_loop *this = &impl->this; SpaResult res; make_realtime (this); - pinos_log_debug ("data-loop %p: enter thread", this); - pinos_loop_enter (impl->this.loop); + pw_log_debug ("data-loop %p: enter thread", this); + pw_loop_enter (impl->this.loop); while (impl->running) { - if ((res = pinos_loop_iterate (this->loop, -1)) < 0) - pinos_log_warn ("data-loop %p: iterate error %d", this, res); + if ((res = pw_loop_iterate (this->loop, -1)) < 0) + pw_log_warn ("data-loop %p: iterate error %d", this, res); } - pinos_log_debug ("data-loop %p: leave thread", this); - pinos_loop_leave (impl->this.loop); + pw_log_debug ("data-loop %p: leave thread", this); + pw_loop_leave (impl->this.loop); return NULL; } @@ -115,37 +114,37 @@ do_stop (SpaLoopUtils *utils, SpaSource *source, void *data) { - PinosDataLoopImpl *impl = data; + struct impl *impl = data; impl->running = false; } /** - * pinos_data_loop_new: + * pw_data_loop_new: * - * Create a new #PinosDataLoop. + * Create a new #struct pw_data_loop. * - * Returns: a new #PinosDataLoop + * Returns: a new #struct pw_data_loop */ -PinosDataLoop * -pinos_data_loop_new (void) +struct pw_data_loop * +pw_data_loop_new (void) { - PinosDataLoopImpl *impl; - PinosDataLoop *this; + struct impl *impl; + struct pw_data_loop *this; - impl = calloc (1, sizeof (PinosDataLoopImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; - pinos_log_debug ("data-loop %p: new", impl); + pw_log_debug ("data-loop %p: new", impl); this = &impl->this; - this->loop = pinos_loop_new (); + this->loop = pw_loop_new (); if (this->loop == NULL) goto no_loop; - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); - impl->event = pinos_loop_add_event (this->loop, + impl->event = pw_loop_add_event (this->loop, do_stop, impl); return this; @@ -156,31 +155,31 @@ no_loop: } void -pinos_data_loop_destroy (PinosDataLoop *loop) +pw_data_loop_destroy (struct pw_data_loop *loop) { - PinosDataLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosDataLoopImpl, this); + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); - pinos_log_debug ("data-loop %p: destroy", impl); - pinos_signal_emit (&loop->destroy_signal, loop); + pw_log_debug ("data-loop %p: destroy", impl); + pw_signal_emit (&loop->destroy_signal, loop); - pinos_data_loop_stop (loop); + pw_data_loop_stop (loop); - pinos_loop_destroy_source (loop->loop, impl->event); - pinos_loop_destroy (loop->loop); + pw_loop_destroy_source (loop->loop, impl->event); + pw_loop_destroy (loop->loop); free (impl); } SpaResult -pinos_data_loop_start (PinosDataLoop *loop) +pw_data_loop_start (struct pw_data_loop *loop) { - PinosDataLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosDataLoopImpl, this); + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); if (!impl->running) { int err; impl->running = true; if ((err = pthread_create (&impl->thread, NULL, do_loop, impl)) != 0) { - pinos_log_warn ("data-loop %p: can't create thread: %s", impl, strerror (err)); + pw_log_warn ("data-loop %p: can't create thread: %s", impl, strerror (err)); impl->running = false; return SPA_RESULT_ERROR; } @@ -189,12 +188,12 @@ pinos_data_loop_start (PinosDataLoop *loop) } SpaResult -pinos_data_loop_stop (PinosDataLoop *loop) +pw_data_loop_stop (struct pw_data_loop *loop) { - PinosDataLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosDataLoopImpl, this); + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); if (impl->running) { - pinos_loop_signal_event (impl->this.loop, impl->event); + pw_loop_signal_event (impl->this.loop, impl->event); pthread_join (impl->thread, NULL); } @@ -202,8 +201,8 @@ pinos_data_loop_stop (PinosDataLoop *loop) } bool -pinos_data_loop_in_thread (PinosDataLoop *loop) +pw_data_loop_in_thread (struct pw_data_loop *loop) { - PinosDataLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosDataLoopImpl, this); + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); return pthread_equal (impl->thread, pthread_self()); } diff --git a/pinos/server/data-loop.h b/pipewire/server/data-loop.h similarity index 54% rename from pinos/server/data-loop.h rename to pipewire/server/data-loop.h index 5cee3a9ba..7bb6e98b2 100644 --- a/pinos/server/data-loop.h +++ b/pipewire/server/data-loop.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,39 +17,37 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_DATA_LOOP_H__ -#define __PINOS_DATA_LOOP_H__ +#ifndef __PIPEWIRE_DATA_LOOP_H__ +#define __PIPEWIRE_DATA_LOOP_H__ #ifdef __cplusplus extern "C" { #endif -#include - -typedef struct _PinosDataLoop PinosDataLoop; +#include /** - * PinosDataLoop: + * pw_data_loop: * - * Pinos rt-loop object. + * PipeWire rt-loop object. */ -struct _PinosDataLoop { - PinosLoop *loop; +struct pw_data_loop { + struct pw_loop *loop; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosDataLoop *loop)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_data_loop *loop)); }; -PinosDataLoop * pinos_data_loop_new (void); -void pinos_data_loop_destroy (PinosDataLoop *loop); +struct pw_data_loop * pw_data_loop_new (void); +void pw_data_loop_destroy (struct pw_data_loop *loop); -SpaResult pinos_data_loop_start (PinosDataLoop *loop); -SpaResult pinos_data_loop_stop (PinosDataLoop *loop); +SpaResult pw_data_loop_start (struct pw_data_loop *loop); +SpaResult pw_data_loop_stop (struct pw_data_loop *loop); -bool pinos_data_loop_in_thread (PinosDataLoop *loop); +bool pw_data_loop_in_thread (struct pw_data_loop *loop); #ifdef __cplusplus } #endif -#endif /* __PINOS_DATA_LOOP_H__ */ +#endif /* __PIPEWIRE_DATA_LOOP_H__ */ diff --git a/pinos/server/link.c b/pipewire/server/link.c similarity index 58% rename from pinos/server/link.c rename to pipewire/server/link.c index 18164b75d..b1137836d 100644 --- a/pinos/server/link.c +++ b/pipewire/server/link.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -25,47 +25,46 @@ #include -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" -#include "pinos/server/link.h" -#include "pinos/server/work-queue.h" +#include "pipewire/server/link.h" +#include "pipewire/server/work-queue.h" #define MAX_BUFFERS 16 -typedef struct -{ - PinosLink this; +struct impl { + struct pw_link this; int refcount; - PinosWorkQueue *work; + struct pw_work_queue *work; SpaFormat **format_filter; - PinosProperties *properties; + struct pw_properties *properties; - PinosListener input_port_destroy; - PinosListener input_async_complete; - PinosListener output_port_destroy; - PinosListener output_async_complete; + struct pw_listener input_port_destroy; + struct pw_listener input_async_complete; + struct pw_listener output_port_destroy; + struct pw_listener output_async_complete; void *buffer_owner; - PinosMemblock buffer_mem; + struct pw_memblock buffer_mem; SpaBuffer **buffers; uint32_t n_buffers; -} PinosLinkImpl; +}; static void -pinos_link_update_state (PinosLink *link, - PinosLinkState state, - char *error) +pw_link_update_state (struct pw_link *link, + enum pw_link_state state, + char *error) { - PinosLinkState old = link->state; + enum pw_link_state old = link->state; if (state != old) { - pinos_log_debug ("link %p: update state %s -> %s (%s)", link, - pinos_link_state_as_string (old), - pinos_link_state_as_string (state), + pw_log_debug ("link %p: update state %s -> %s (%s)", link, + pw_link_state_as_string (old), + pw_link_state_as_string (state), error); link->state = state; @@ -73,7 +72,7 @@ pinos_link_update_state (PinosLink *link, free (link->error); link->error = error; - pinos_signal_emit (&link->state_changed, link, old, state); + pw_signal_emit (&link->state_changed, link, old, state); } } @@ -83,13 +82,13 @@ complete_ready (void *obj, SpaResult res, uint32_t id) { - PinosPort *port = data; + struct pw_port *port = data; if (SPA_RESULT_IS_OK (res)) { - port->state = PINOS_PORT_STATE_READY; - pinos_log_debug ("port %p: state READY", port); + port->state = PW_PORT_STATE_READY; + pw_log_debug ("port %p: state READY", port); } else - pinos_log_warn ("port %p: failed to go to READY", port); + pw_log_warn ("port %p: failed to go to READY", port); } static void @@ -98,13 +97,13 @@ complete_paused (void *obj, SpaResult res, uint32_t id) { - PinosPort *port = data; + struct pw_port *port = data; if (SPA_RESULT_IS_OK (res)) { - port->state = PINOS_PORT_STATE_PAUSED; - pinos_log_debug ("port %p: state PAUSED", port); + port->state = PW_PORT_STATE_PAUSED; + pw_log_debug ("port %p: state PAUSED", port); } else - pinos_log_warn ("port %p: failed to go to PAUSED", port); + pw_log_warn ("port %p: failed to go to PAUSED", port); } static void @@ -113,53 +112,53 @@ complete_streaming (void *obj, SpaResult res, uint32_t id) { - PinosPort *port = data; + struct pw_port *port = data; if (SPA_RESULT_IS_OK (res)) { - port->state = PINOS_PORT_STATE_STREAMING; - pinos_log_debug ("port %p: state STREAMING", port); + port->state = PW_PORT_STATE_STREAMING; + pw_log_debug ("port %p: state STREAMING", port); } else - pinos_log_warn ("port %p: failed to go to STREAMING", port); + pw_log_warn ("port %p: failed to go to STREAMING", port); } static SpaResult -do_negotiate (PinosLink *this, uint32_t in_state, uint32_t out_state) +do_negotiate (struct pw_link *this, uint32_t in_state, uint32_t out_state) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); SpaResult res = SPA_RESULT_ERROR, res2; SpaFormat *format; char *error = NULL; - if (in_state != PINOS_PORT_STATE_CONFIGURE && out_state != PINOS_PORT_STATE_CONFIGURE) + if (in_state != PW_PORT_STATE_CONFIGURE && out_state != PW_PORT_STATE_CONFIGURE) return SPA_RESULT_OK; - pinos_link_update_state (this, PINOS_LINK_STATE_NEGOTIATING, NULL); + pw_link_update_state (this, PW_LINK_STATE_NEGOTIATING, NULL); - format = pinos_core_find_format (this->core, - this->output, - this->input, - NULL, - 0, - NULL, - &error); + format = pw_core_find_format (this->core, + this->output, + this->input, + NULL, + 0, + NULL, + &error); if (format == NULL) goto error; - if (out_state > PINOS_PORT_STATE_CONFIGURE && this->output->node->state == PINOS_NODE_STATE_IDLE) { - pinos_node_set_state (this->output->node, PINOS_NODE_STATE_SUSPENDED); - out_state = PINOS_PORT_STATE_CONFIGURE; + if (out_state > PW_PORT_STATE_CONFIGURE && this->output->node->state == PW_NODE_STATE_IDLE) { + pw_node_set_state (this->output->node, PW_NODE_STATE_SUSPENDED); + out_state = PW_PORT_STATE_CONFIGURE; } - if (in_state > PINOS_PORT_STATE_CONFIGURE && this->input->node->state == PINOS_NODE_STATE_IDLE) { - pinos_node_set_state (this->input->node, PINOS_NODE_STATE_SUSPENDED); - in_state = PINOS_PORT_STATE_CONFIGURE; + if (in_state > PW_PORT_STATE_CONFIGURE && this->input->node->state == PW_NODE_STATE_IDLE) { + pw_node_set_state (this->input->node, PW_NODE_STATE_SUSPENDED); + in_state = PW_PORT_STATE_CONFIGURE; } - pinos_log_debug ("link %p: doing set format", this); - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) + pw_log_debug ("link %p: doing set format", this); + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) spa_debug_format (format, this->core->type.map); - if (out_state == PINOS_PORT_STATE_CONFIGURE) { - pinos_log_debug ("link %p: doing set format on output", this); + if (out_state == PW_PORT_STATE_CONFIGURE) { + pw_log_debug ("link %p: doing set format on output", this); if ((res = spa_node_port_set_format (this->output->node->node, SPA_DIRECTION_OUTPUT, this->output->port_id, @@ -168,10 +167,10 @@ do_negotiate (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error set output format: %d", res); goto error; } - pinos_work_queue_add (impl->work, this->output->node, res, complete_ready, this->output); + pw_work_queue_add (impl->work, this->output->node, res, complete_ready, this->output); } - if (in_state == PINOS_PORT_STATE_CONFIGURE) { - pinos_log_debug ("link %p: doing set format on input", this); + if (in_state == PW_PORT_STATE_CONFIGURE) { + pw_log_debug ("link %p: doing set format on input", this); if ((res2 = spa_node_port_set_format (this->input->node->node, SPA_DIRECTION_INPUT, this->input->port_id, @@ -180,14 +179,14 @@ do_negotiate (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error set input format: %d", res2); goto error; } - pinos_work_queue_add (impl->work, this->input->node, res2, complete_ready, this->input); + pw_work_queue_add (impl->work, this->input->node, res2, complete_ready, this->input); res = res2 != SPA_RESULT_OK ? res2 : res; } return res; error: { - pinos_link_update_state (this, PINOS_LINK_STATE_ERROR, error); + pw_link_update_state (this, PW_LINK_STATE_ERROR, error); return res; } } @@ -205,7 +204,7 @@ find_param (SpaParam **params, int n_params, uint32_t type) } static SpaParam * -find_meta_enable (PinosCore *core, SpaParam **params, int n_params, uint32_t type) +find_meta_enable (struct pw_core *core, SpaParam **params, int n_params, uint32_t type) { uint32_t i; @@ -225,14 +224,14 @@ find_meta_enable (PinosCore *core, SpaParam **params, int n_params, uint32_t typ } static SpaBuffer ** -alloc_buffers (PinosLink *this, - uint32_t n_buffers, - uint32_t n_params, - SpaParam **params, - uint32_t n_datas, - size_t *data_sizes, - ssize_t *data_strides, - PinosMemblock *mem) +alloc_buffers (struct pw_link *this, + uint32_t n_buffers, + uint32_t n_params, + SpaParam **params, + uint32_t n_datas, + size_t *data_sizes, + ssize_t *data_strides, + struct pw_memblock *mem) { SpaBuffer **buffers, *bp; uint32_t i; @@ -267,7 +266,7 @@ alloc_buffers (PinosLink *this, 0) != 2) continue; - pinos_log_debug ("link %p: enable meta %d %d", this, type, size); + pw_log_debug ("link %p: enable meta %d %d", this, type, size); metas[n_metas].type = type; metas[n_metas].size = size; @@ -289,12 +288,11 @@ alloc_buffers (PinosLink *this, /* pointer to buffer structures */ bp = SPA_MEMBER (buffers, n_buffers * sizeof (SpaBuffer *), SpaBuffer); - pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD | - PINOS_MEMBLOCK_FLAG_MAP_READWRITE | - PINOS_MEMBLOCK_FLAG_SEAL, - n_buffers * data_size, - mem); - + pw_memblock_alloc (PW_MEMBLOCK_FLAG_WITH_FD | + PW_MEMBLOCK_FLAG_MAP_READWRITE | + PW_MEMBLOCK_FLAG_SEAL, + n_buffers * data_size, + mem); for (i = 0; i < n_buffers; i++) { int j; @@ -361,12 +359,12 @@ alloc_buffers (PinosLink *this, } static int -spa_node_param_filter (PinosLink *this, - SpaNode *in_node, - uint32_t in_port, - SpaNode *out_node, - uint32_t out_port, - SpaPODBuilder *result) +spa_node_param_filter (struct pw_link *this, + SpaNode *in_node, + uint32_t in_port, + SpaNode *out_node, + uint32_t out_port, + SpaPODBuilder *result) { SpaResult res; SpaParam *oparam, *iparam; @@ -376,7 +374,7 @@ spa_node_param_filter (PinosLink *this, if (spa_node_port_enum_params (in_node, SPA_DIRECTION_INPUT, in_port, iidx, &iparam) < 0) break; - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) spa_debug_param (iparam, this->core->type.map); for (oidx = 0; ; oidx++) { @@ -386,7 +384,7 @@ spa_node_param_filter (PinosLink *this, if (spa_node_port_enum_params (out_node, SPA_DIRECTION_OUTPUT, out_port, oidx, &oparam) < 0) break; - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) spa_debug_param (oparam, this->core->type.map); if (iparam->body.body.type != oparam->body.body.type) @@ -411,20 +409,20 @@ spa_node_param_filter (PinosLink *this, } static SpaResult -do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) +do_allocation (struct pw_link *this, uint32_t in_state, uint32_t out_state) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); SpaResult res; const SpaPortInfo *iinfo, *oinfo; uint32_t in_flags, out_flags; char *error = NULL; - if (in_state != PINOS_PORT_STATE_READY && out_state != PINOS_PORT_STATE_READY) + if (in_state != PW_PORT_STATE_READY && out_state != PW_PORT_STATE_READY) return SPA_RESULT_OK; - pinos_link_update_state (this, PINOS_LINK_STATE_ALLOCATING, NULL); + pw_link_update_state (this, PW_LINK_STATE_ALLOCATING, NULL); - pinos_log_debug ("link %p: doing alloc buffers %p %p", this, this->output->node, this->input->node); + pw_log_debug ("link %p: doing alloc buffers %p %p", this, this->output->node, this->input->node); /* find out what's possible */ if ((res = spa_node_port_get_info (this->output->node->node, SPA_DIRECTION_OUTPUT, @@ -445,12 +443,12 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) out_flags = oinfo->flags; if (out_flags & SPA_PORT_INFO_FLAG_LIVE) { - pinos_log_debug ("setting link as live"); + pw_log_debug ("setting link as live"); this->output->node->live = true; this->input->node->live = true; } - if (in_state == PINOS_PORT_STATE_READY && out_state == PINOS_PORT_STATE_READY) { + if (in_state == PW_PORT_STATE_READY && out_state == PW_PORT_STATE_READY) { if ((out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) && (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) { out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS; @@ -472,18 +470,18 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) res = SPA_RESULT_ERROR; goto error; } - } else if (in_state == PINOS_PORT_STATE_READY && out_state > PINOS_PORT_STATE_READY) { + } else if (in_state == PW_PORT_STATE_READY && out_state > PW_PORT_STATE_READY) { out_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; in_flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS; - } else if (out_state == PINOS_PORT_STATE_READY && in_state > PINOS_PORT_STATE_READY) { + } else if (out_state == PW_PORT_STATE_READY && in_state > PW_PORT_STATE_READY) { in_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; out_flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS; } else { - pinos_log_debug ("link %p: delay allocation, state %d %d", this, in_state, out_state); + pw_log_debug ("link %p: delay allocation, state %d %d", this, in_state, out_state); return SPA_RESULT_OK; } - if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) { + if (pw_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) { spa_debug_port_info (oinfo, this->core->type.map); spa_debug_port_info (iinfo, this->core->type.map); } @@ -555,14 +553,14 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) impl->n_buffers = this->output->n_buffers; impl->buffers = this->output->buffers; impl->buffer_owner = this->output; - pinos_log_debug ("reusing %d output buffers %p", impl->n_buffers, impl->buffers); + pw_log_debug ("reusing %d output buffers %p", impl->n_buffers, impl->buffers); } else if (this->input->n_buffers) { out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; in_flags = 0; impl->n_buffers = this->input->n_buffers; impl->buffers = this->input->buffers; impl->buffer_owner = this->input; - pinos_log_debug ("reusing %d input buffers %p", impl->n_buffers, impl->buffers); + pw_log_debug ("reusing %d input buffers %p", impl->n_buffers, impl->buffers); } else { size_t data_sizes[1]; ssize_t data_strides[1]; @@ -581,7 +579,7 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) data_strides, &impl->buffer_mem); - pinos_log_debug ("allocating %d input buffers %p", impl->n_buffers, impl->buffers); + pw_log_debug ("allocating %d input buffers %p", impl->n_buffers, impl->buffers); } if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) { @@ -593,13 +591,13 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error alloc output buffers: %d", res); goto error; } - pinos_work_queue_add (impl->work, this->output->node, res, complete_paused, this->output); + pw_work_queue_add (impl->work, this->output->node, res, complete_paused, this->output); this->output->buffers = impl->buffers; this->output->n_buffers = impl->n_buffers; this->output->allocated = true; this->output->buffer_mem = impl->buffer_mem; impl->buffer_owner = this->output; - pinos_log_debug ("allocated %d buffers %p from output port", impl->n_buffers, impl->buffers); + pw_log_debug ("allocated %d buffers %p from output port", impl->n_buffers, impl->buffers); } else if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) { if ((res = spa_node_port_alloc_buffers (this->input->node->node, SPA_DIRECTION_INPUT, @@ -609,18 +607,18 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error alloc input buffers: %d", res); goto error; } - pinos_work_queue_add (impl->work, this->input->node, res, complete_paused, this->input); + pw_work_queue_add (impl->work, this->input->node, res, complete_paused, this->input); this->input->buffers = impl->buffers; this->input->n_buffers = impl->n_buffers; this->input->allocated = true; this->input->buffer_mem = impl->buffer_mem; impl->buffer_owner = this->input; - pinos_log_debug ("allocated %d buffers %p from input port", impl->n_buffers, impl->buffers); + pw_log_debug ("allocated %d buffers %p from input port", impl->n_buffers, impl->buffers); } } if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) { - pinos_log_debug ("using %d buffers %p on input port", impl->n_buffers, impl->buffers); + pw_log_debug ("using %d buffers %p on input port", impl->n_buffers, impl->buffers); if ((res = spa_node_port_use_buffers (this->input->node->node, SPA_DIRECTION_INPUT, this->input->port_id, @@ -629,13 +627,13 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error use input buffers: %d", res); goto error; } - pinos_work_queue_add (impl->work, this->input->node, res, complete_paused, this->input); + pw_work_queue_add (impl->work, this->input->node, res, complete_paused, this->input); this->input->buffers = impl->buffers; this->input->n_buffers = impl->n_buffers; this->input->allocated = false; } else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) { - pinos_log_debug ("using %d buffers %p on output port", impl->n_buffers, impl->buffers); + pw_log_debug ("using %d buffers %p on output port", impl->n_buffers, impl->buffers); if ((res = spa_node_port_use_buffers (this->output->node->node, SPA_DIRECTION_OUTPUT, this->output->port_id, @@ -644,7 +642,7 @@ do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state) asprintf (&error, "error use output buffers: %d", res); goto error; } - pinos_work_queue_add (impl->work, this->output->node, res, complete_paused, this->output); + pw_work_queue_add (impl->work, this->output->node, res, complete_paused, this->output); this->output->buffers = impl->buffers; this->output->n_buffers = impl->n_buffers; this->output->allocated = false; @@ -663,62 +661,62 @@ error: this->input->buffers = NULL; this->input->n_buffers = 0; this->input->allocated = false; - pinos_link_update_state (this, PINOS_LINK_STATE_ERROR, error); + pw_link_update_state (this, PW_LINK_STATE_ERROR, error); return res; } } static SpaResult -do_start (PinosLink *this, uint32_t in_state, uint32_t out_state) +do_start (struct pw_link *this, uint32_t in_state, uint32_t out_state) { SpaResult res = SPA_RESULT_OK; - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); - if (in_state < PINOS_PORT_STATE_PAUSED || out_state < PINOS_PORT_STATE_PAUSED) + if (in_state < PW_PORT_STATE_PAUSED || out_state < PW_PORT_STATE_PAUSED) return SPA_RESULT_OK; - else if (in_state == PINOS_PORT_STATE_STREAMING && out_state == PINOS_PORT_STATE_STREAMING) { - pinos_link_update_state (this, PINOS_LINK_STATE_RUNNING, NULL); + else if (in_state == PW_PORT_STATE_STREAMING && out_state == PW_PORT_STATE_STREAMING) { + pw_link_update_state (this, PW_LINK_STATE_RUNNING, NULL); } else { - pinos_link_update_state (this, PINOS_LINK_STATE_PAUSED, NULL); + pw_link_update_state (this, PW_LINK_STATE_PAUSED, NULL); - if (in_state == PINOS_PORT_STATE_PAUSED) { - res = pinos_node_set_state (this->input->node, PINOS_NODE_STATE_RUNNING); - pinos_work_queue_add (impl->work, this->input->node, res, complete_streaming, this->input); + if (in_state == PW_PORT_STATE_PAUSED) { + res = pw_node_set_state (this->input->node, PW_NODE_STATE_RUNNING); + pw_work_queue_add (impl->work, this->input->node, res, complete_streaming, this->input); } - if (out_state == PINOS_PORT_STATE_PAUSED) { - res = pinos_node_set_state (this->output->node, PINOS_NODE_STATE_RUNNING); - pinos_work_queue_add (impl->work, this->output->node, res, complete_streaming, this->output); + if (out_state == PW_PORT_STATE_PAUSED) { + res = pw_node_set_state (this->output->node, PW_NODE_STATE_RUNNING); + pw_work_queue_add (impl->work, this->output->node, res, complete_streaming, this->output); } } return res; } static SpaResult -check_states (PinosLink *this, - void *user_data, - SpaResult res) +check_states (struct pw_link *this, + void *user_data, + SpaResult res) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); uint32_t in_state, out_state; - if (this->state == PINOS_LINK_STATE_ERROR) + if (this->state == PW_LINK_STATE_ERROR) return SPA_RESULT_ERROR; if (this->input == NULL || this->output == NULL) return SPA_RESULT_OK; - if (this->input->node->state == PINOS_NODE_STATE_ERROR || - this->output->node->state == PINOS_NODE_STATE_ERROR) + if (this->input->node->state == PW_NODE_STATE_ERROR || + this->output->node->state == PW_NODE_STATE_ERROR) return SPA_RESULT_ERROR; in_state = this->input->state; out_state = this->output->state; - if (in_state == PINOS_PORT_STATE_STREAMING && - out_state == PINOS_PORT_STATE_STREAMING) + if (in_state == PW_PORT_STATE_STREAMING && + out_state == PW_PORT_STATE_STREAMING) return SPA_RESULT_OK; - pinos_log_debug ("link %p: input state %d, output state %d", this, in_state, out_state); + pw_log_debug ("link %p: input state %d, output state %d", this, in_state, out_state); if ((res = do_negotiate (this, in_state, out_state)) != SPA_RESULT_OK) goto exit; @@ -731,59 +729,59 @@ check_states (PinosLink *this, exit: if (SPA_RESULT_IS_ERROR (res)) { - pinos_log_debug ("link %p: got error result %d", this, res); + pw_log_debug ("link %p: got error result %d", this, res); return res; } - pinos_work_queue_add (impl->work, - this, - SPA_RESULT_WAIT_SYNC, - (PinosWorkFunc) check_states, - this); + pw_work_queue_add (impl->work, + this, + SPA_RESULT_WAIT_SYNC, + (pw_work_func_t) check_states, + this); return res; } static void -on_input_async_complete_notify (PinosListener *listener, - PinosNode *node, +on_input_async_complete_notify (struct pw_listener *listener, + struct pw_node *node, uint32_t seq, SpaResult res) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (listener, PinosLinkImpl, input_async_complete); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, input_async_complete); - pinos_log_debug ("link %p: node %p async complete %d %d", impl, node, seq, res); - pinos_work_queue_complete (impl->work, node, seq, res); + pw_log_debug ("link %p: node %p async complete %d %d", impl, node, seq, res); + pw_work_queue_complete (impl->work, node, seq, res); } static void -on_output_async_complete_notify (PinosListener *listener, - PinosNode *node, +on_output_async_complete_notify (struct pw_listener *listener, + struct pw_node *node, uint32_t seq, SpaResult res) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (listener, PinosLinkImpl, output_async_complete); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, output_async_complete); - pinos_log_debug ("link %p: node %p async complete %d %d", impl, node, seq, res); - pinos_work_queue_complete (impl->work, node, seq, res); + pw_log_debug ("link %p: node %p async complete %d %d", impl, node, seq, res); + pw_work_queue_complete (impl->work, node, seq, res); } static void -on_port_destroy (PinosLink *this, - PinosPort *port) +on_port_destroy (struct pw_link *this, + struct pw_port *port) { - PinosLinkImpl *impl = (PinosLinkImpl *) this; - PinosPort *other; + struct impl *impl = (struct impl *) this; + struct pw_port *other; if (port == this->input) { - pinos_log_debug ("link %p: input port destroyed %p", this, port); - pinos_signal_remove (&impl->input_port_destroy); - pinos_signal_remove (&impl->input_async_complete); + pw_log_debug ("link %p: input port destroyed %p", this, port); + pw_signal_remove (&impl->input_port_destroy); + pw_signal_remove (&impl->input_async_complete); this->input = NULL; other = this->output; } else if (port == this->output) { - pinos_log_debug ("link %p: output port destroyed %p", this, port); - pinos_signal_remove (&impl->output_port_destroy); - pinos_signal_remove (&impl->output_async_complete); + pw_log_debug ("link %p: output port destroyed %p", this, port); + pw_signal_remove (&impl->output_port_destroy); + pw_signal_remove (&impl->output_async_complete); this->output = NULL; other = this->input; } else @@ -793,66 +791,66 @@ on_port_destroy (PinosLink *this, impl->buffers = NULL; impl->n_buffers = 0; - pinos_log_debug ("link %p: clear input allocated buffers on port %p", this, other); - pinos_port_clear_buffers (other); + pw_log_debug ("link %p: clear input allocated buffers on port %p", this, other); + pw_port_clear_buffers (other); } - pinos_signal_emit (&this->port_unlinked, this, port); + pw_signal_emit (&this->port_unlinked, this, port); - pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED, NULL); - pinos_link_destroy (this); + pw_link_update_state (this, PW_LINK_STATE_UNLINKED, NULL); + pw_link_destroy (this); } static void -on_input_port_destroy (PinosListener *listener, - PinosPort *port) +on_input_port_destroy (struct pw_listener *listener, + struct pw_port *port) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (listener, PinosLinkImpl, input_port_destroy); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, input_port_destroy); on_port_destroy (&impl->this, port); } static void -on_output_port_destroy (PinosListener *listener, - PinosPort *port) +on_output_port_destroy (struct pw_listener *listener, + struct pw_port *port) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (listener, PinosLinkImpl, output_port_destroy); + struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, output_port_destroy); on_port_destroy (&impl->this, port); } bool -pinos_link_activate (PinosLink *this) +pw_link_activate (struct pw_link *this) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); - pinos_log_debug ("link %p: activate", this); - pinos_work_queue_add (impl->work, - this, - SPA_RESULT_WAIT_SYNC, - (PinosWorkFunc) check_states, - this); + pw_log_debug ("link %p: activate", this); + pw_work_queue_add (impl->work, + this, + SPA_RESULT_WAIT_SYNC, + (pw_work_func_t) check_states, + this); return true; } bool -pinos_pinos_link_deactivate (PinosLink *this) +pw_link_deactivate (struct pw_link *this) { return true; } static void -pinos_link_free (PinosLink *link) +pw_link_free (struct pw_link *link) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (link, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (link, struct impl, this); - pinos_log_debug ("link %p: free", link); - pinos_signal_emit (&link->free_signal, link); + pw_log_debug ("link %p: free", link); + pw_signal_emit (&link->free_signal, link); - pinos_work_queue_destroy (impl->work); + pw_work_queue_destroy (impl->work); if (impl->buffer_owner == link) - pinos_memblock_free (&impl->buffer_mem); + pw_memblock_free (&impl->buffer_mem); free (impl); } @@ -860,38 +858,38 @@ pinos_link_free (PinosLink *link) static void link_unbind_func (void *data) { - PinosResource *resource = data; - PinosLink *this = resource->object; - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct pw_resource *resource = data; + struct pw_link *this = resource->object; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); spa_list_remove (&resource->link); if (--impl->refcount == 0) - pinos_link_free (this); + pw_link_free (this); } static SpaResult -link_bind_func (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +link_bind_func (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { - PinosLink *this = global->object; - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); - PinosResource *resource; - PinosLinkInfo info; + struct pw_link *this = global->object; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct pw_resource *resource; + struct pw_link_info info; - resource = pinos_resource_new (client, - id, - global->type, - global->object, - link_unbind_func); + resource = pw_resource_new (client, + id, + global->type, + global->object, + link_unbind_func); if (resource == NULL) goto no_mem; impl->refcount++; - pinos_log_debug ("link %p: bound to %d", global->object, resource->id); + pw_log_debug ("link %p: bound to %d", global->object, resource->id); spa_list_insert (this->resource_list.prev, &resource->link); @@ -902,114 +900,114 @@ link_bind_func (PinosGlobal *global, info.input_node_id = this->input ? this->input->node->global->id : -1; info.input_port_id = this->input ? this->input->port_id : -1; - pinos_link_notify_info (resource, &info); + pw_link_notify_info (resource, &info); return SPA_RESULT_OK; no_mem: - pinos_log_error ("can't create link resource"); - pinos_core_notify_error (client->core_resource, - client->core_resource->id, - SPA_RESULT_NO_MEMORY, - "no memory"); + pw_log_error ("can't create link resource"); + pw_core_notify_error (client->core_resource, + client->core_resource->id, + SPA_RESULT_NO_MEMORY, + "no memory"); return SPA_RESULT_NO_MEMORY; } -PinosLink * -pinos_link_new (PinosCore *core, - PinosPort *output, - PinosPort *input, - SpaFormat **format_filter, - PinosProperties *properties) +struct pw_link * +pw_link_new (struct pw_core *core, + struct pw_port *output, + struct pw_port *input, + SpaFormat **format_filter, + struct pw_properties *properties) { - PinosLinkImpl *impl; - PinosLink *this; + struct impl *impl; + struct pw_link *this; - impl = calloc (1, sizeof (PinosLinkImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; this = &impl->this; - pinos_log_debug ("link %p: new", this); + pw_log_debug ("link %p: new", this); - impl->work = pinos_work_queue_new (core->main_loop->loop); + impl->work = pw_work_queue_new (core->main_loop->loop); this->core = core; this->properties = properties; - this->state = PINOS_LINK_STATE_INIT; + this->state = PW_LINK_STATE_INIT; impl->refcount = 1; this->input = input; this->output = output; spa_list_init (&this->resource_list); - pinos_signal_init (&this->port_unlinked); - pinos_signal_init (&this->state_changed); - pinos_signal_init (&this->destroy_signal); - pinos_signal_init (&this->free_signal); + pw_signal_init (&this->port_unlinked); + pw_signal_init (&this->state_changed); + pw_signal_init (&this->destroy_signal); + pw_signal_init (&this->free_signal); impl->format_filter = format_filter; - pinos_signal_add (&this->input->destroy_signal, - &impl->input_port_destroy, - on_input_port_destroy); + pw_signal_add (&this->input->destroy_signal, + &impl->input_port_destroy, + on_input_port_destroy); - pinos_signal_add (&this->input->node->async_complete, - &impl->input_async_complete, - on_input_async_complete_notify); + pw_signal_add (&this->input->node->async_complete, + &impl->input_async_complete, + on_input_async_complete_notify); - pinos_signal_add (&this->output->destroy_signal, - &impl->output_port_destroy, - on_output_port_destroy); + pw_signal_add (&this->output->destroy_signal, + &impl->output_port_destroy, + on_output_port_destroy); - pinos_signal_add (&this->output->node->async_complete, - &impl->output_async_complete, - on_output_async_complete_notify); + pw_signal_add (&this->output->node->async_complete, + &impl->output_async_complete, + on_output_async_complete_notify); - pinos_log_debug ("link %p: constructed %p:%d -> %p:%d", impl, - this->output->node, this->output->port_id, - this->input->node, this->input->port_id); + pw_log_debug ("link %p: constructed %p:%d -> %p:%d", impl, + this->output->node, this->output->port_id, + this->input->node, this->input->port_id); spa_list_insert (core->link_list.prev, &this->link); - pinos_core_add_global (core, - NULL, - core->type.link, - 0, - this, - link_bind_func, - &this->global); + pw_core_add_global (core, + NULL, + core->type.link, + 0, + this, + link_bind_func, + &this->global); return this; } static void -clear_port_buffers (PinosLink *link, PinosPort *port) +clear_port_buffers (struct pw_link *link, struct pw_port *port) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (link, PinosLinkImpl, this); + struct impl *impl = SPA_CONTAINER_OF (link, struct impl, this); - if (impl->buffer_owner != port && port->state > PINOS_PORT_STATE_READY) { - pinos_log_debug ("link %p: clear buffers on port %p", link, port); + if (impl->buffer_owner != port && port->state > PW_PORT_STATE_READY) { + pw_log_debug ("link %p: clear buffers on port %p", link, port); spa_node_port_use_buffers (port->node->node, port->direction, port->port_id, NULL, 0); port->buffers = NULL; port->n_buffers = 0; - port->state = PINOS_PORT_STATE_READY; - pinos_log_debug ("port %p: state READY", port); + port->state = PW_PORT_STATE_READY; + pw_log_debug ("port %p: state READY", port); } } static SpaResult -do_link_remove_done (SpaLoop *loop, - bool async, - uint32_t seq, - size_t size, - void *data, - void *user_data) +do_link_remove_done (SpaLoop *loop, + bool async, + uint32_t seq, + size_t size, + void *data, + void *user_data) { - PinosLink *this = user_data; - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); + struct pw_link *this = user_data; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); if (this->input) { spa_list_remove (&this->input_link); @@ -1019,8 +1017,8 @@ do_link_remove_done (SpaLoop *loop, if (this->input->node->n_used_input_links == 0 && this->input->node->n_used_output_links == 0 && - this->input->node->state > PINOS_NODE_STATE_IDLE) - pinos_node_update_state (this->input->node, PINOS_NODE_STATE_IDLE, NULL); + this->input->node->state > PW_NODE_STATE_IDLE) + pw_node_update_state (this->input->node, PW_NODE_STATE_IDLE, NULL); this->input = NULL; } @@ -1032,13 +1030,13 @@ do_link_remove_done (SpaLoop *loop, if (this->output->node->n_used_input_links == 0 && this->output->node->n_used_output_links == 0 && - this->output->node->state > PINOS_NODE_STATE_IDLE) - pinos_node_update_state (this->output->node, PINOS_NODE_STATE_IDLE, NULL); + this->output->node->state > PW_NODE_STATE_IDLE) + pw_node_update_state (this->output->node, PW_NODE_STATE_IDLE, NULL); this->output = NULL; } if (--impl->refcount == 0) - pinos_link_free (this); + pw_link_free (this); return SPA_RESULT_OK; } @@ -1052,75 +1050,75 @@ do_link_remove (SpaLoop *loop, void *user_data) { SpaResult res; - PinosLink *this = user_data; + struct pw_link *this = user_data; if (this->rt.input) { spa_list_remove (&this->rt.input_link); if (spa_list_is_empty (&this->rt.input->rt.links)) - pinos_port_pause_rt (this->rt.input); + pw_port_pause_rt (this->rt.input); this->rt.input = NULL; } if (this->rt.output) { spa_list_remove (&this->rt.output_link); if (spa_list_is_empty (&this->rt.output->rt.links)) - pinos_port_pause_rt (this->rt.output); + pw_port_pause_rt (this->rt.output); this->rt.output = NULL; } - res = pinos_loop_invoke (this->core->main_loop->loop, - do_link_remove_done, - seq, - 0, - NULL, - this); + res = pw_loop_invoke (this->core->main_loop->loop, + do_link_remove_done, + seq, + 0, + NULL, + this); return res; } /** - * pinos_link_destroy: - * @link: a #PinosLink + * pw_link_destroy: + * @link: a #struct pw_link * * Trigger removal of @link */ void -pinos_link_destroy (PinosLink * this) +pw_link_destroy (struct pw_link * this) { - PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); - PinosResource *resource, *tmp; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct pw_resource *resource, *tmp; - pinos_log_debug ("link %p: destroy", impl); - pinos_signal_emit (&this->destroy_signal, this); + pw_log_debug ("link %p: destroy", impl); + pw_signal_emit (&this->destroy_signal, this); - pinos_global_destroy (this->global); + pw_global_destroy (this->global); spa_list_remove (&this->link); spa_list_for_each_safe (resource, tmp, &this->resource_list, link) - pinos_resource_destroy (resource); + pw_resource_destroy (resource); if (this->input) { - pinos_signal_remove (&impl->input_port_destroy); - pinos_signal_remove (&impl->input_async_complete); + pw_signal_remove (&impl->input_port_destroy); + pw_signal_remove (&impl->input_async_complete); impl->refcount++; - pinos_loop_invoke (this->input->node->data_loop->loop, - do_link_remove, - 1, - 0, - NULL, - this); + pw_loop_invoke (this->input->node->data_loop->loop, + do_link_remove, + 1, + 0, + NULL, + this); } if (this->output) { - pinos_signal_remove (&impl->output_port_destroy); - pinos_signal_remove (&impl->output_async_complete); + pw_signal_remove (&impl->output_port_destroy); + pw_signal_remove (&impl->output_async_complete); impl->refcount++; - pinos_loop_invoke (this->output->node->data_loop->loop, - do_link_remove, - 2, - 0, - NULL, - this); + pw_loop_invoke (this->output->node->data_loop->loop, + do_link_remove, + 2, + 0, + NULL, + this); } if (--impl->refcount == 0) - pinos_link_free (this); + pw_link_free (this); } diff --git a/pipewire/server/link.h b/pipewire/server/link.h new file mode 100644 index 000000000..f2b730250 --- /dev/null +++ b/pipewire/server/link.h @@ -0,0 +1,93 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_LINK_H__ +#define __PIPEWIRE_LINK_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include +#include +#include + +/** + * pw_link: + * + * PipeWire link interface. + */ +struct pw_link { + struct pw_core *core; + SpaList link; + struct pw_global *global; + + struct pw_properties *properties; + + enum pw_link_state state; + char *error; + PW_SIGNAL (state_changed, (struct pw_listener *listener, + struct pw_link *link, + enum pw_link_state old, + enum pw_link_state state)); + + PW_SIGNAL (destroy_signal, (struct pw_listener *, + struct pw_link *)); + PW_SIGNAL (free_signal, (struct pw_listener *, + struct pw_link *)); + + SpaList resource_list; + + struct pw_port *output; + SpaList output_link; + struct pw_port *input; + SpaList input_link; + PW_SIGNAL (port_unlinked, (struct pw_listener *listener, + struct pw_link *link, + struct pw_port *port)); + + struct { + uint32_t in_ready; + struct pw_port *input; + struct pw_port *output; + SpaList input_link; + SpaList output_link; + } rt; +}; + + +struct pw_link * pw_link_new (struct pw_core *core, + struct pw_port *output, + struct pw_port *input, + SpaFormat **format_filter, + struct pw_properties *properties); +void pw_link_destroy (struct pw_link *link); + +bool pw_link_activate (struct pw_link *link); +bool pw_link_deactivate (struct pw_link *link); + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_LINK_H__ */ diff --git a/pipewire/server/main-loop.c b/pipewire/server/main-loop.c new file mode 100644 index 000000000..f5ea5ecee --- /dev/null +++ b/pipewire/server/main-loop.c @@ -0,0 +1,116 @@ +/* PipeWire + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include "spa/list.h" +#include "spa/ringbuffer.h" +#include "pipewire/client/log.h" +#include "pipewire/server/main-loop.h" + +struct impl { + struct pw_main_loop this; + + bool running; +}; + +/** + * pw_main_loop_new: + * + * Create a new #struct pw_main_loop. + * + * Returns: a new #struct pw_main_loop + */ +struct pw_main_loop * +pw_main_loop_new (void) +{ + struct impl *impl; + struct pw_main_loop *this; + + impl = calloc (1, sizeof (struct impl)); + if (impl == NULL) + return NULL; + + pw_log_debug ("main-loop %p: new", impl); + this = &impl->this; + + this->loop = pw_loop_new (); + if (this->loop == NULL) + goto no_loop; + + pw_signal_init (&this->destroy_signal); + + return this; + +no_loop: + free (impl); + return NULL; +} + +void +pw_main_loop_destroy (struct pw_main_loop *loop) +{ + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); + + pw_log_debug ("main-loop %p: destroy", impl); + pw_signal_emit (&loop->destroy_signal, loop); + + pw_loop_destroy (loop->loop); + + free (impl); +} + +/** + * pw_main_loop_quit: + * @loop: a #struct pw_main_loop + * + * Stop the running @loop. + */ +void +pw_main_loop_quit (struct pw_main_loop *loop) +{ + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); + pw_log_debug ("main-loop %p: quit", impl); + impl->running = false; +} + +/** + * pw_main_loop_run: + * @loop: a #struct pw_main_loop + * + * Start running @loop. This function blocks until pw_main_loop_quit() + * has been called. + */ +void +pw_main_loop_run (struct pw_main_loop *loop) +{ + struct impl *impl = SPA_CONTAINER_OF (loop, struct impl, this); + + pw_log_debug ("main-loop %p: run", impl); + + impl->running = true; + pw_loop_enter (loop->loop); + while (impl->running) { + pw_loop_iterate (loop->loop, -1); + } + pw_loop_leave (loop->loop); +} diff --git a/pinos/server/main-loop.h b/pipewire/server/main-loop.h similarity index 56% rename from pinos/server/main-loop.h rename to pipewire/server/main-loop.h index 0be90dc7b..807f1cb77 100644 --- a/pinos/server/main-loop.h +++ b/pipewire/server/main-loop.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,38 +17,36 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_MAIN_LOOP_H__ -#define __PINOS_MAIN_LOOP_H__ +#ifndef __PIPEWIRE_MAIN_LOOP_H__ +#define __PIPEWIRE_MAIN_LOOP_H__ #ifdef __cplusplus extern "C" { #endif #include -#include - -typedef struct _PinosMainLoop PinosMainLoop; +#include /** - * PinosMainLoop: + * pa_main_loop: * - * Pinos main-loop interface. + * PipeWire main-loop interface. */ -struct _PinosMainLoop { - PinosLoop *loop; +struct pw_main_loop { + struct pw_loop *loop; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosMainLoop *loop)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_main_loop *loop)); }; -PinosMainLoop * pinos_main_loop_new (void); -void pinos_main_loop_destroy (PinosMainLoop *loop); +struct pw_main_loop * pw_main_loop_new (void); +void pw_main_loop_destroy (struct pw_main_loop *loop); -void pinos_main_loop_run (PinosMainLoop *loop); -void pinos_main_loop_quit (PinosMainLoop *loop); +void pw_main_loop_run (struct pw_main_loop *loop); +void pw_main_loop_quit (struct pw_main_loop *loop); #ifdef __cplusplus } #endif -#endif /* __PINOS_MAIN_LOOP_H__ */ +#endif /* __PIPEWIRE_MAIN_LOOP_H__ */ diff --git a/pinos/server/meson.build b/pipewire/server/meson.build similarity index 67% rename from pinos/server/meson.build rename to pipewire/server/meson.build index 0f4ef7e1a..6ec68938b 100644 --- a/pinos/server/meson.build +++ b/pipewire/server/meson.build @@ -1,4 +1,4 @@ -pinoscore_headers = [ +pipewirecore_headers = [ 'access.h', 'client.h', 'client-node.h', @@ -16,7 +16,7 @@ pinoscore_headers = [ 'work-queue.h', ] -pinoscore_sources = [ +pipewirecore_sources = [ 'access.c', 'client.c', 'client-node.c', @@ -34,23 +34,23 @@ pinoscore_sources = [ 'work-queue.c', ] -libpinoscore_c_args = [ +libpipewirecore_c_args = [ '-DHAVE_CONFIG_H', '-D_GNU_SOURCE', ] -libpinoscore = shared_library('pinoscore', pinoscore_sources, +libpipewirecore = shared_library('pipewirecore', pipewirecore_sources, version : libversion, soversion : soversion, - c_args : libpinoscore_c_args, + c_args : libpipewirecore_c_args, include_directories : [configinc, spa_inc], link_with : spalib, install : true, - dependencies : [mathlib, dl_lib, pinos_dep], + dependencies : [mathlib, dl_lib, pipewire_dep], ) -pinoscore_dep = declare_dependency(link_with : libpinoscore, +pipewirecore_dep = declare_dependency(link_with : libpipewirecore, include_directories : [configinc, spa_inc], - dependencies : [pinos_dep], + dependencies : [pipewire_dep], ) diff --git a/pinos/server/module.c b/pipewire/server/module.c similarity index 59% rename from pinos/server/module.c rename to pipewire/server/module.c index b62c626ae..9d9f182cd 100644 --- a/pinos/server/module.c +++ b/pipewire/server/module.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -28,18 +28,17 @@ #include -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" -#include "pinos/client/utils.h" -#include "pinos/server/module.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" +#include "pipewire/client/utils.h" +#include "pipewire/server/module.h" -#define PINOS_SYMBOL_MODULE_INIT "pinos__module_init" +#define PIPEWIRE_SYMBOL_MODULE_INIT "pipewire__module_init" -typedef struct -{ - PinosModule this; +struct impl { + struct pw_module this; void *hnd; -} PinosModuleImpl; +}; static char * find_module (const char * path, const char *name) @@ -63,7 +62,7 @@ find_module (const char * path, const char *name) dir = opendir (path); if (dir == NULL) { - pinos_log_warn ("could not open %s: %s", path, strerror (errno)); + pw_log_warn ("could not open %s: %s", path, strerror (errno)); return NULL; } @@ -91,78 +90,78 @@ find_module (const char * path, const char *name) } static SpaResult -module_bind_func (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +module_bind_func (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { - PinosModule *this = global->object; - PinosResource *resource; + struct pw_module *this = global->object; + struct pw_resource *resource; - resource = pinos_resource_new (client, - id, - global->type, - global->object, - NULL); + resource = pw_resource_new (client, + id, + global->type, + global->object, + NULL); if (resource == NULL) goto no_mem; - pinos_log_debug ("module %p: bound to %d", global->object, resource->id); + pw_log_debug ("module %p: bound to %d", global->object, resource->id); this->info.change_mask = ~0; - pinos_module_notify_info (resource, &this->info); + pw_module_notify_info (resource, &this->info); return SPA_RESULT_OK; no_mem: - pinos_log_error ("can't create module resource"); - pinos_core_notify_error (client->core_resource, - client->core_resource->id, - SPA_RESULT_NO_MEMORY, - "no memory"); + pw_log_error ("can't create module resource"); + pw_core_notify_error (client->core_resource, + client->core_resource->id, + SPA_RESULT_NO_MEMORY, + "no memory"); return SPA_RESULT_NO_MEMORY; } /** - * pinos_module_load: - * @core: a #PinosCore + * pw_module_load: + * @core: a #struct pw_core * @name: name of the module to load * @args: A string with arguments for the module * @err: Return location for an error string, or %NULL * * Load module with @name. * - * Returns: A #PinosModule if the module could be loaded, or %NULL on failure. + * Returns: A #struct pw_module if the module could be loaded, or %NULL on failure. */ -PinosModule * -pinos_module_load (PinosCore *core, - const char *name, - const char *args, - char **err) +struct pw_module * +pw_module_load (struct pw_core *core, + const char *name, + const char *args, + char **err) { - PinosModule *this; - PinosModuleImpl *impl; + struct pw_module *this; + struct impl *impl; void *hnd; char *filename = NULL; const char *module_dir; - PinosModuleInitFunc init_func; + pw_module_init_func_t init_func; - module_dir = getenv ("PINOS_MODULE_DIR"); + module_dir = getenv ("PIPEWIRE_MODULE_DIR"); if (module_dir != NULL) { char **l; int i, n_paths; - pinos_log_debug ("PINOS_MODULE_DIR set to: %s", module_dir); + pw_log_debug ("PIPEWIRE_MODULE_DIR set to: %s", module_dir); - l = pinos_split_strv (module_dir, "/", 0, &n_paths); + l = pw_split_strv (module_dir, "/", 0, &n_paths); for (i = 0; l[i] != NULL; i++) { filename = find_module (l[i], name); if (filename != NULL) break; } - pinos_free_strv (l); + pw_free_strv (l); } else { - pinos_log_debug ("moduledir set to: %s", MODULEDIR); + pw_log_debug ("moduledir set to: %s", MODULEDIR); filename = find_module (MODULEDIR, name); } @@ -170,17 +169,17 @@ pinos_module_load (PinosCore *core, if (filename == NULL) goto not_found; - pinos_log_debug ("trying to load module: %s (%s)", name, filename); + pw_log_debug ("trying to load module: %s (%s)", name, filename); hnd = dlopen (filename, RTLD_NOW | RTLD_LOCAL); if (hnd == NULL) goto open_failed; - if ((init_func = dlsym (hnd, PINOS_SYMBOL_MODULE_INIT)) == NULL) - goto no_pinos_module; + if ((init_func = dlsym (hnd, PIPEWIRE_SYMBOL_MODULE_INIT)) == NULL) + goto no_pw_module; - impl = calloc (1, sizeof (PinosModuleImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) goto no_mem; @@ -192,13 +191,13 @@ pinos_module_load (PinosCore *core, if (!init_func (this, (char *) args)) goto init_failed; - pinos_core_add_global (core, - NULL, - core->type.module, - 0, - impl, - module_bind_func, - &this->global); + pw_core_add_global (core, + NULL, + core->type.module, + 0, + impl, + module_bind_func, + &this->global); this->info.id = this->global->id; this->info.name = name ? strdup (name) : NULL; @@ -206,7 +205,7 @@ pinos_module_load (PinosCore *core, this->info.args = args ? strdup (args) : NULL; this->info.props = NULL; - pinos_log_debug ("loaded module: %s", this->info.name); + pw_log_debug ("loaded module: %s", this->info.name); return this; @@ -222,9 +221,9 @@ open_failed: return NULL; } no_mem: -no_pinos_module: +no_pw_module: { - asprintf (err, "\"%s\" is not a pinos module", name); + asprintf (err, "\"%s\" is not a pipewire module", name); dlclose (hnd); free (filename); return NULL; @@ -232,17 +231,17 @@ no_pinos_module: init_failed: { asprintf (err, "\"%s\" failed to initialize", name); - pinos_module_destroy (this); + pw_module_destroy (this); return NULL; } } void -pinos_module_destroy (PinosModule *this) +pw_module_destroy (struct pw_module *this) { - PinosModuleImpl *impl = SPA_CONTAINER_OF (this, PinosModuleImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); - pinos_signal_emit (&this->destroy_signal, this); + pw_signal_emit (&this->destroy_signal, this); if (this->info.name) free ((char*)this->info.name); diff --git a/pinos/server/module.h b/pipewire/server/module.h similarity index 57% rename from pinos/server/module.h rename to pipewire/server/module.h index b413500d2..a27ab5c29 100644 --- a/pinos/server/module.h +++ b/pipewire/server/module.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications * @author Linus Svensson * @@ -18,33 +18,31 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_MODULE_H__ -#define __PINOS_MODULE_H__ +#ifndef __PIPEWIRE_MODULE_H__ +#define __PIPEWIRE_MODULE_H__ #ifdef __cplusplus extern "C" { #endif -#include +#include -typedef struct _PinosModule PinosModule; +struct pw_module { + struct pw_core *core; + SpaList link; + struct pw_global *global; -struct _PinosModule { - PinosCore *core; - SpaList link; - PinosGlobal *global; - - PinosModuleInfo info; + struct pw_module_info info; void *user_data; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosModule *module)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_module *module)); }; /** - * PinosModuleInitFunc: - * @module: A #PinosModule + * pw_module_init_func_t: + * @module: A #struct pw_module * @args: Arguments to the module * * A module should provide an init function with this signature. This function @@ -52,16 +50,16 @@ struct _PinosModule { * * Returns: %true on success, %false otherwise */ -typedef bool (*PinosModuleInitFunc) (PinosModule *module, char *args); +typedef bool (*pw_module_init_func_t) (struct pw_module *module, char *args); -PinosModule * pinos_module_load (PinosCore *core, - const char *name, - const char *args, - char **err); -void pinos_module_destroy (PinosModule *module); +struct pw_module * pw_module_load (struct pw_core *core, + const char *name, + const char *args, + char **err); +void pw_module_destroy (struct pw_module *module); #ifdef __cplusplus } #endif -#endif /* __PINOS_MODULE_H__ */ +#endif /* __PIPEWIRE_MODULE_H__ */ diff --git a/pinos/server/node-factory.c b/pipewire/server/node-factory.c similarity index 89% rename from pinos/server/node-factory.c rename to pipewire/server/node-factory.c index 5443b742f..ae4cbafe3 100644 --- a/pinos/server/node-factory.c +++ b/pipewire/server/node-factory.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications AB * * This library is free software; you can redistribute it and/or @@ -17,5 +17,5 @@ * Boston, MA 02110-1301, USA. */ -#include "pinos/client/pinos.h" -#include "pinos/server/node-factory.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/server/node-factory.h" diff --git a/pinos/server/node-factory.h b/pipewire/server/node-factory.h similarity index 50% rename from pinos/server/node-factory.h rename to pipewire/server/node-factory.h index ea474b43b..b959fc74f 100644 --- a/pinos/server/node-factory.h +++ b/pipewire/server/node-factory.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Axis Communications AB * * This library is free software; you can redistribute it and/or @@ -17,43 +17,41 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_NODE_FACTORY_H__ -#define __PINOS_NODE_FACTORY_H__ +#ifndef __PIPEWIRE_NODE_FACTORY_H__ +#define __PIPEWIRE_NODE_FACTORY_H__ #ifdef __cplusplus extern "C" { #endif -#define PINOS_TYPE__NodeFactory "Pinos:Object:NodeFactory" -#define PINOS_TYPE_NODE_FACTORY_BASE PINOS_TYPE__NodeFactory ":" +#define PIPEWIRE_TYPE__NodeFactory "PipeWire:Object:NodeFactory" +#define PIPEWIRE_TYPE_NODE_FACTORY_BASE PIPEWIRE_TYPE__NodeFactory ":" -typedef struct _PinosNodeFactory PinosNodeFactory; - -#include -#include +#include +#include /** - * PinosNodeFactory: + * pw_node_factory: * - * Pinos node factory interface. + * PipeWire node factory interface. */ -struct _PinosNodeFactory { - PinosCore *core; - SpaList link; - PinosGlobal *global; +struct pw_node_factory { + struct pw_core *core; + SpaList link; + struct pw_global *global; const char *name; - PinosNode * (*create_node) (PinosNodeFactory *factory, - PinosClient *client, - const char *name, - PinosProperties *properties); + struct pw_node * (*create_node) (struct pw_node_factory *factory, + struct pw_client *client, + const char *name, + struct pw_properties *properties); }; -#define pinos_node_factory_create_node(f,...) (f)->create_node((f),__VA_ARGS__) +#define pw_node_factory_create_node(f,...) (f)->create_node((f),__VA_ARGS__) #ifdef __cplusplus } #endif -#endif /* __PINOS_NODE_FACTORY_H__ */ +#endif /* __PIPEWIRE_NODE_FACTORY_H__ */ diff --git a/pinos/server/node.c b/pipewire/server/node.c similarity index 58% rename from pinos/server/node.c rename to pipewire/server/node.c index af38977c7..9052e814b 100644 --- a/pinos/server/node.c +++ b/pipewire/server/node.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -21,29 +21,28 @@ #include #include -#include "pinos/client/pinos.h" -#include "pinos/client/interfaces.h" +#include "pipewire/client/pipewire.h" +#include "pipewire/client/interfaces.h" -#include "pinos/server/node.h" -#include "pinos/server/data-loop.h" -#include "pinos/server/main-loop.h" -#include "pinos/server/work-queue.h" +#include "pipewire/server/node.h" +#include "pipewire/server/data-loop.h" +#include "pipewire/server/main-loop.h" +#include "pipewire/server/work-queue.h" -typedef struct -{ - PinosNode this; +struct impl { + struct pw_node this; - PinosWorkQueue *work; + struct pw_work_queue *work; bool async_init; -} PinosNodeImpl; +}; -static void init_complete (PinosNode *this); +static void init_complete (struct pw_node *this); static void -update_port_ids (PinosNode *node) +update_port_ids (struct pw_node *node) { - PinosNodeImpl *impl = SPA_CONTAINER_OF (node, PinosNodeImpl, this); + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); uint32_t *input_port_ids, *output_port_ids; uint32_t n_input_ports, n_output_ports, max_input_ports, max_output_ports; uint32_t i; @@ -64,8 +63,8 @@ update_port_ids (PinosNode *node) node->n_output_ports = n_output_ports; node->max_output_ports = max_output_ports; - node->input_port_map = calloc (max_input_ports, sizeof (PinosPort *)); - node->output_port_map = calloc (max_output_ports, sizeof (PinosPort *)); + node->input_port_map = calloc (max_input_ports, sizeof (struct pw_port *)); + node->output_port_map = calloc (max_output_ports, sizeof (struct pw_port *)); input_port_ids = alloca (sizeof (uint32_t) * n_input_ports); output_port_ids = alloca (sizeof (uint32_t) * n_output_ports); @@ -76,43 +75,44 @@ update_port_ids (PinosNode *node) max_output_ports, output_port_ids); - pinos_log_debug ("node %p: update_port ids %u/%u, %u/%u", node, + pw_log_debug ("node %p: update_port ids %u/%u, %u/%u", node, n_input_ports, max_input_ports, n_output_ports, max_output_ports); i = 0; ports = &node->input_ports; while (true) { - PinosPort *p = (ports == &node->input_ports) ? NULL : SPA_CONTAINER_OF (ports, PinosPort, link); + struct pw_port *p = (ports == &node->input_ports) ? NULL : + SPA_CONTAINER_OF (ports, struct pw_port, link); if (p && i < n_input_ports && p->port_id == input_port_ids[i]) { node->input_port_map[p->port_id] = p; - pinos_log_debug ("node %p: exiting input port %d", node, input_port_ids[i]); + pw_log_debug ("node %p: exiting input port %d", node, input_port_ids[i]); i++; ports = ports->next; } else if ((p && i < n_input_ports && input_port_ids[i] < p->port_id) || i < n_input_ports) { - PinosPort *np; - pinos_log_debug ("node %p: input port added %d", node, input_port_ids[i]); + struct pw_port *np; + pw_log_debug ("node %p: input port added %d", node, input_port_ids[i]); - np = pinos_port_new (node, PINOS_DIRECTION_INPUT, input_port_ids[i]); + np = pw_port_new (node, PW_DIRECTION_INPUT, input_port_ids[i]); if ((res = spa_node_port_set_io (node->node, SPA_DIRECTION_INPUT, np->port_id, &np->io)) < 0) - pinos_log_warn ("node %p: can't set input IO %d", node, res); + pw_log_warn ("node %p: can't set input IO %d", node, res); spa_list_insert (ports, &np->link); ports = np->link.next; node->input_port_map[np->port_id] = np; if (!impl->async_init) - pinos_signal_emit (&node->port_added, node, np); + pw_signal_emit (&node->port_added, node, np); i++; } else if (p) { node->input_port_map[p->port_id] = NULL; ports = ports->next; if (!impl->async_init) - pinos_signal_emit (&node->port_removed, node, p); - pinos_log_debug ("node %p: input port removed %d", node, p->port_id); - pinos_port_destroy (p); + pw_signal_emit (&node->port_removed, node, p); + pw_log_debug ("node %p: input port removed %d", node, p->port_id); + pw_port_destroy (p); } else { - pinos_log_debug ("node %p: no more input ports", node); + pw_log_debug ("node %p: no more input ports", node); break; } } @@ -120,108 +120,109 @@ update_port_ids (PinosNode *node) i = 0; ports = &node->output_ports; while (true) { - PinosPort *p = (ports == &node->output_ports) ? NULL : SPA_CONTAINER_OF (ports, PinosPort, link); + struct pw_port *p = (ports == &node->output_ports) ? NULL : + SPA_CONTAINER_OF (ports, struct pw_port, link); if (p && i < n_output_ports && p->port_id == output_port_ids[i]) { - pinos_log_debug ("node %p: exiting output port %d", node, output_port_ids[i]); + pw_log_debug ("node %p: exiting output port %d", node, output_port_ids[i]); i++; ports = ports->next; node->output_port_map[p->port_id] = p; } else if ((p && i < n_output_ports && output_port_ids[i] < p->port_id) || i < n_output_ports) { - PinosPort *np; - pinos_log_debug ("node %p: output port added %d", node, output_port_ids[i]); + struct pw_port *np; + pw_log_debug ("node %p: output port added %d", node, output_port_ids[i]); - np = pinos_port_new (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]); + np = pw_port_new (node, PW_DIRECTION_OUTPUT, output_port_ids[i]); if ((res = spa_node_port_set_io (node->node, SPA_DIRECTION_OUTPUT, np->port_id, &np->io)) < 0) - pinos_log_warn ("node %p: can't set output IO %d", node, res); + pw_log_warn ("node %p: can't set output IO %d", node, res); spa_list_insert (ports, &np->link); ports = np->link.next; node->output_port_map[np->port_id] = np; if (!impl->async_init) - pinos_signal_emit (&node->port_added, node, np); + pw_signal_emit (&node->port_added, node, np); i++; } else if (p) { node->output_port_map[p->port_id] = NULL; ports = ports->next; if (!impl->async_init) - pinos_signal_emit (&node->port_removed, node, p); - pinos_log_debug ("node %p: output port removed %d", node, p->port_id); - pinos_port_destroy (p); + pw_signal_emit (&node->port_removed, node, p); + pw_log_debug ("node %p: output port removed %d", node, p->port_id); + pw_port_destroy (p); } else { - pinos_log_debug ("node %p: no more output ports", node); + pw_log_debug ("node %p: no more output ports", node); break; } } - pinos_signal_emit (&node->initialized, node); + pw_signal_emit (&node->initialized, node); } static SpaResult -pause_node (PinosNode *this) +pause_node (struct pw_node *this) { SpaResult res; - if (this->state <= PINOS_NODE_STATE_IDLE) + if (this->state <= PW_NODE_STATE_IDLE) return SPA_RESULT_OK; - pinos_log_debug ("node %p: pause node", this); + pw_log_debug ("node %p: pause node", this); if ((res = spa_node_send_command (this->node, &SPA_COMMAND_INIT (this->core->type.command_node.Pause))) < 0) - pinos_log_debug ("got error %d", res); + pw_log_debug ("got error %d", res); return res; } static SpaResult -start_node (PinosNode *this) +start_node (struct pw_node *this) { SpaResult res; - pinos_log_debug ("node %p: start node", this); + pw_log_debug ("node %p: start node", this); if ((res = spa_node_send_command (this->node, &SPA_COMMAND_INIT (this->core->type.command_node.Start))) < 0) - pinos_log_debug ("got error %d", res); + pw_log_debug ("got error %d", res); return res; } static SpaResult -suspend_node (PinosNode *this) +suspend_node (struct pw_node *this) { SpaResult res = SPA_RESULT_OK; - PinosPort *p; + struct pw_port *p; - pinos_log_debug ("node %p: suspend node", this); + pw_log_debug ("node %p: suspend node", this); spa_list_for_each (p, &this->input_ports, link) { if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port_id, 0, NULL)) < 0) - pinos_log_warn ("error unset format input: %d", res); + pw_log_warn ("error unset format input: %d", res); p->buffers = NULL; p->n_buffers = 0; if (p->allocated) - pinos_memblock_free (&p->buffer_mem); + pw_memblock_free (&p->buffer_mem); p->allocated = false; - p->state = PINOS_PORT_STATE_CONFIGURE; + p->state = PW_PORT_STATE_CONFIGURE; } spa_list_for_each (p, &this->output_ports, link) { if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port_id, 0, NULL)) < 0) - pinos_log_warn ("error unset format output: %d", res); + pw_log_warn ("error unset format output: %d", res); p->buffers = NULL; p->n_buffers = 0; if (p->allocated) - pinos_memblock_free (&p->buffer_mem); + pw_memblock_free (&p->buffer_mem); p->allocated = false; - p->state = PINOS_PORT_STATE_CONFIGURE; + p->state = PW_PORT_STATE_CONFIGURE; } return res; } static void -send_clock_update (PinosNode *this) +send_clock_update (struct pw_node *this) { SpaResult res; SpaCommandNodeClockUpdate cu = @@ -249,24 +250,24 @@ send_clock_update (PinosNode *this) } if ((res = spa_node_send_command (this->node, (SpaCommand *)&cu)) < 0) - pinos_log_debug ("got error %d", res); + pw_log_debug ("got error %d", res); } static SpaResult -do_pull (PinosNode *this) +do_pull (struct pw_node *this) { SpaResult res = SPA_RESULT_OK; - PinosPort *inport; + struct pw_port *inport; bool have_output = false; spa_list_for_each (inport, &this->input_ports, link) { - PinosLink *link; - PinosPort *outport; + struct pw_link *link; + struct pw_port *outport; SpaPortIO *pi; SpaPortIO *po; pi = &inport->io; - pinos_log_trace ("node %p: need input port %d, %d %d", this, + pw_log_trace ("node %p: need input port %d, %d %d", this, inport->port_id, pi->buffer_id, pi->status); if (pi->status != SPA_RESULT_NEED_BUFFER) @@ -283,27 +284,27 @@ do_pull (PinosNode *this) *po = *pi; pi->buffer_id = SPA_ID_INVALID; - pinos_log_trace ("node %p: process output %p %d", outport->node, po, po->buffer_id); + pw_log_trace ("node %p: process output %p %d", outport->node, po, po->buffer_id); res = spa_node_process_output (outport->node->node); if (res == SPA_RESULT_NEED_BUFFER) { res = do_pull (outport->node); - pinos_log_trace ("node %p: pull return %d", outport->node, res); + pw_log_trace ("node %p: pull return %d", outport->node, res); } else if (res == SPA_RESULT_HAVE_BUFFER) { *pi = *po; - pinos_log_trace ("node %p: have output %d %d", this, pi->status, pi->buffer_id); + pw_log_trace ("node %p: have output %d %d", this, pi->status, pi->buffer_id); have_output = true; } else if (res < 0) { - pinos_log_warn ("node %p: got process output %d", outport->node, res); + pw_log_warn ("node %p: got process output %d", outport->node, res); } } } if (have_output) { - pinos_log_trace ("node %p: doing process input", this); + pw_log_trace ("node %p: doing process input", this); res = spa_node_process_input (this->node); } return res; @@ -312,15 +313,15 @@ do_pull (PinosNode *this) static void on_node_event (SpaNode *node, SpaEvent *event, void *user_data) { - PinosNode *this = user_data; - PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this); + struct pw_node *this = user_data; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); if (SPA_EVENT_TYPE (event) == this->core->type.event_node.AsyncComplete) { SpaEventNodeAsyncComplete *ac = (SpaEventNodeAsyncComplete *) event; - pinos_log_debug ("node %p: async complete event %d %d", this, ac->body.seq.value, ac->body.res.value); - pinos_work_queue_complete (impl->work, this, ac->body.seq.value, ac->body.res.value); - pinos_signal_emit (&this->async_complete, this, ac->body.seq.value, ac->body.res.value); + pw_log_debug ("node %p: async complete event %d %d", this, ac->body.seq.value, ac->body.res.value); + pw_work_queue_complete (impl->work, this, ac->body.seq.value, ac->body.res.value); + pw_signal_emit (&this->async_complete, this, ac->body.seq.value, ac->body.res.value); } else if (SPA_EVENT_TYPE (event) == this->core->type.event_node.RequestClockUpdate) { send_clock_update (this); @@ -330,7 +331,7 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data) static void on_node_need_input (SpaNode *node, void *user_data) { - PinosNode *this = user_data; + struct pw_node *this = user_data; do_pull (this); } @@ -338,22 +339,22 @@ on_node_need_input (SpaNode *node, void *user_data) static void on_node_have_output (SpaNode *node, void *user_data) { - PinosNode *this = user_data; + struct pw_node *this = user_data; SpaResult res; - PinosPort *outport; + struct pw_port *outport; spa_list_for_each (outport, &this->output_ports, link) { - PinosLink *link; + struct pw_link *link; SpaPortIO *po; po = &outport->io; if (po->buffer_id == SPA_ID_INVALID) continue; - pinos_log_trace ("node %p: have output %d", this, po->buffer_id); + pw_log_trace ("node %p: have output %d", this, po->buffer_id); spa_list_for_each (link, &outport->rt.links, rt.output_link) { - PinosPort *inport; + struct pw_port *inport; if (link->rt.input == NULL || link->rt.output == NULL) continue; @@ -361,10 +362,10 @@ on_node_have_output (SpaNode *node, void *user_data) inport = link->rt.input; inport->io = *po; - pinos_log_trace ("node %p: do process input %d", this, po->buffer_id); + pw_log_trace ("node %p: do process input %d", this, po->buffer_id); if ((res = spa_node_process_input (inport->node->node)) < 0) - pinos_log_warn ("node %p: got process input %d", inport->node, res); + pw_log_warn ("node %p: got process input %d", inport->node, res); } po->status = SPA_RESULT_NEED_BUFFER; @@ -375,14 +376,14 @@ on_node_have_output (SpaNode *node, void *user_data) static void on_node_reuse_buffer (SpaNode *node, uint32_t port_id, uint32_t buffer_id, void *user_data) { - PinosNode *this = user_data; - PinosPort *inport; + struct pw_node *this = user_data; + struct pw_port *inport; - pinos_log_trace ("node %p: reuse buffer %u", this, buffer_id); + pw_log_trace ("node %p: reuse buffer %u", this, buffer_id); spa_list_for_each (inport, &this->input_ports, link) { - PinosLink *link; - PinosPort *outport; + struct pw_link *link; + struct pw_port *outport; spa_list_for_each (link, &inport->rt.links, rt.input_link) { if (link->rt.input == NULL || link->rt.output == NULL) @@ -397,30 +398,30 @@ on_node_reuse_buffer (SpaNode *node, uint32_t port_id, uint32_t buffer_id, void static void node_unbind_func (void *data) { - PinosResource *resource = data; + struct pw_resource *resource = data; spa_list_remove (&resource->link); } static SpaResult -node_bind_func (PinosGlobal *global, - PinosClient *client, - uint32_t version, - uint32_t id) +node_bind_func (struct pw_global *global, + struct pw_client *client, + uint32_t version, + uint32_t id) { - PinosNode *this = global->object; - PinosResource *resource; - PinosNodeInfo info; + struct pw_node *this = global->object; + struct pw_resource *resource; + struct pw_node_info info; int i; - resource = pinos_resource_new (client, - id, - global->type, - global->object, - node_unbind_func); + resource = pw_resource_new (client, + id, + global->type, + global->object, + node_unbind_func); if (resource == NULL) goto no_mem; - pinos_log_debug ("node %p: bound to %d", this, resource->id); + pw_log_debug ("node %p: bound to %d", this, resource->id); spa_list_insert (this->resource_list.prev, &resource->link); @@ -465,7 +466,7 @@ node_bind_func (PinosGlobal *global, info.error = this->error; info.props = this->properties ? &this->properties->dict : NULL; - pinos_node_notify_info (resource, &info); + pw_node_notify_info (resource, &info); if (info.input_formats) { for (i = 0; i < info.n_input_formats; i++) @@ -482,41 +483,41 @@ node_bind_func (PinosGlobal *global, return SPA_RESULT_OK; no_mem: - pinos_log_error ("can't create node resource"); - pinos_core_notify_error (client->core_resource, - client->core_resource->id, - SPA_RESULT_NO_MEMORY, - "no memory"); + pw_log_error ("can't create node resource"); + pw_core_notify_error (client->core_resource, + client->core_resource->id, + SPA_RESULT_NO_MEMORY, + "no memory"); return SPA_RESULT_NO_MEMORY; } static void -init_complete (PinosNode *this) +init_complete (struct pw_node *this) { - PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this); + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); update_port_ids (this); - pinos_log_debug ("node %p: init completed", this); + pw_log_debug ("node %p: init completed", this); impl->async_init = false; spa_list_insert (this->core->node_list.prev, &this->link); - pinos_core_add_global (this->core, - this->owner, - this->core->type.node, - 0, - this, - node_bind_func, - &this->global); + pw_core_add_global (this->core, + this->owner, + this->core->type.node, + 0, + this, + node_bind_func, + &this->global); - pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED, NULL); + pw_node_update_state (this, PW_NODE_STATE_SUSPENDED, NULL); } void -pinos_node_set_data_loop (PinosNode *node, - PinosDataLoop *loop) +pw_node_set_data_loop (struct pw_node *node, + struct pw_data_loop *loop) { node->data_loop = loop; - pinos_signal_emit (&node->loop_changed, node); + pw_signal_emit (&node->loop_changed, node); } static const SpaNodeCallbacks node_callbacks = { @@ -526,28 +527,28 @@ static const SpaNodeCallbacks node_callbacks = { &on_node_reuse_buffer, }; -PinosNode * -pinos_node_new (PinosCore *core, - PinosClient *owner, - const char *name, - bool async, - SpaNode *node, - SpaClock *clock, - PinosProperties *properties) +struct pw_node * +pw_node_new (struct pw_core *core, + struct pw_client *owner, + const char *name, + bool async, + SpaNode *node, + SpaClock *clock, + struct pw_properties *properties) { - PinosNodeImpl *impl; - PinosNode *this; + struct impl *impl; + struct pw_node *this; - impl = calloc (1, sizeof (PinosNodeImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; this = &impl->this; this->core = core; this->owner = owner; - pinos_log_debug ("node %p: new, owner %p", this, owner); + pw_log_debug ("node %p: new, owner %p", this, owner); - impl->work = pinos_work_queue_new (this->core->main_loop->loop); + impl->work = pw_work_queue_new (this->core->main_loop->loop); this->name = strdup (name); this->properties = properties; @@ -559,19 +560,19 @@ pinos_node_new (PinosCore *core, spa_list_init (&this->resource_list); if (spa_node_set_callbacks (this->node, &node_callbacks, sizeof (node_callbacks), this) < 0) - pinos_log_warn ("node %p: error setting callback", this); + pw_log_warn ("node %p: error setting callback", this); - pinos_signal_init (&this->destroy_signal); - pinos_signal_init (&this->port_added); - pinos_signal_init (&this->port_removed); - pinos_signal_init (&this->state_request); - pinos_signal_init (&this->state_changed); - pinos_signal_init (&this->free_signal); - pinos_signal_init (&this->async_complete); - pinos_signal_init (&this->initialized); - pinos_signal_init (&this->loop_changed); + pw_signal_init (&this->destroy_signal); + pw_signal_init (&this->port_added); + pw_signal_init (&this->port_removed); + pw_signal_init (&this->state_request); + pw_signal_init (&this->state_changed); + pw_signal_init (&this->free_signal); + pw_signal_init (&this->async_complete); + pw_signal_init (&this->initialized); + pw_signal_init (&this->loop_changed); - this->state = PINOS_NODE_STATE_CREATING; + this->state = PW_NODE_STATE_CREATING; spa_list_init (&this->input_ports); spa_list_init (&this->output_ports); @@ -580,24 +581,24 @@ pinos_node_new (PinosCore *core, uint32_t i; if (this->properties == NULL) - this->properties = pinos_properties_new (NULL, NULL); + this->properties = pw_properties_new (NULL, NULL); if (this->properties) goto no_mem; for (i = 0; i < this->node->info->n_items; i++) - pinos_properties_set (this->properties, - this->node->info->items[i].key, - this->node->info->items[i].value); + pw_properties_set (this->properties, + this->node->info->items[i].key, + this->node->info->items[i].value); } impl->async_init = async; if (async) { - pinos_work_queue_add (impl->work, - this, - SPA_RESULT_RETURN_ASYNC (0), - (PinosWorkFunc) init_complete, - NULL); + pw_work_queue_add (impl->work, + this, + SPA_RESULT_RETURN_ASYNC (0), + (pw_work_func_t) init_complete, + NULL); } else { init_complete (this); } @@ -618,21 +619,21 @@ do_node_remove_done (SpaLoop *loop, void *data, void *user_data) { - PinosNode *this = user_data; - PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this); - PinosPort *port, *tmp; + struct pw_node *this = user_data; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct pw_port *port, *tmp; - pinos_log_debug ("node %p: remove done, destroy ports", this); + pw_log_debug ("node %p: remove done, destroy ports", this); spa_list_for_each_safe (port, tmp, &this->input_ports, link) - pinos_port_destroy (port); + pw_port_destroy (port); spa_list_for_each_safe (port, tmp, &this->output_ports, link) - pinos_port_destroy (port); + pw_port_destroy (port); - pinos_log_debug ("node %p: free", this); - pinos_signal_emit (&this->free_signal, this); + pw_log_debug ("node %p: free", this); + pw_signal_emit (&this->free_signal, this); - pinos_work_queue_destroy (impl->work); + pw_work_queue_destroy (impl->work); if (this->input_port_map) free (this->input_port_map); @@ -642,7 +643,7 @@ do_node_remove_done (SpaLoop *loop, free (this->name); free (this->error); if (this->properties) - pinos_properties_free (this->properties); + pw_properties_free (this->properties); free (impl); return SPA_RESULT_OK; @@ -656,91 +657,91 @@ do_node_remove (SpaLoop *loop, void *data, void *user_data) { - PinosNode *this = user_data; - PinosPort *port, *tmp; + struct pw_node *this = user_data; + struct pw_port *port, *tmp; SpaResult res; pause_node (this); spa_list_for_each_safe (port, tmp, &this->input_ports, link) { - PinosLink *link, *tlink; + struct pw_link *link, *tlink; spa_list_for_each_safe (link, tlink, &port->rt.links, rt.input_link) { - pinos_port_pause_rt (link->rt.input); + pw_port_pause_rt (link->rt.input); spa_list_remove (&link->rt.input_link); link->rt.input = NULL; } } spa_list_for_each_safe (port, tmp, &this->output_ports, link) { - PinosLink *link, *tlink; + struct pw_link *link, *tlink; spa_list_for_each_safe (link, tlink, &port->rt.links, rt.output_link) { - pinos_port_pause_rt (link->rt.output); + pw_port_pause_rt (link->rt.output); spa_list_remove (&link->rt.output_link); link->rt.output = NULL; } } - res = pinos_loop_invoke (this->core->main_loop->loop, - do_node_remove_done, - seq, - 0, - NULL, - this); + res = pw_loop_invoke (this->core->main_loop->loop, + do_node_remove_done, + seq, + 0, + NULL, + this); return res; } /** - * pinos_node_destroy: - * @node: a #PinosNode + * pw_node_destroy: + * @node: a #struct pw_node * * Remove @node. This will stop the transfer on the node and * free the resources allocated by @node. */ void -pinos_node_destroy (PinosNode * this) +pw_node_destroy (struct pw_node * this) { - PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this); - PinosResource *resource, *tmp; + struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this); + struct pw_resource *resource, *tmp; - pinos_log_debug ("node %p: destroy", impl); - pinos_signal_emit (&this->destroy_signal, this); + pw_log_debug ("node %p: destroy", impl); + pw_signal_emit (&this->destroy_signal, this); if (!impl->async_init) { spa_list_remove (&this->link); - pinos_global_destroy (this->global); + pw_global_destroy (this->global); } spa_list_for_each_safe (resource, tmp, &this->resource_list, link) - pinos_resource_destroy (resource); + pw_resource_destroy (resource); - pinos_loop_invoke (this->data_loop->loop, - do_node_remove, - 1, - 0, - NULL, - this); + pw_loop_invoke (this->data_loop->loop, + do_node_remove, + 1, + 0, + NULL, + this); } /** - * pinos_node_get_free_port: - * @node: a #PinosNode - * @direction: a #PinosDirection + * pw_node_get_free_port: + * @node: a #struct pw_node + * @direction: a #enum pw_direction * * Find a new unused port in @node with @direction * * Returns: the new port or %NULL on error */ -PinosPort * -pinos_node_get_free_port (PinosNode *node, - PinosDirection direction) +struct pw_port * +pw_node_get_free_port (struct pw_node *node, + enum pw_direction direction) { uint32_t *n_ports, max_ports; SpaList *ports; - PinosPort *port = NULL, *p, **portmap; + struct pw_port *port = NULL, *p, **portmap; SpaResult res; int i; - if (direction == PINOS_DIRECTION_INPUT) { + if (direction == PW_DIRECTION_INPUT) { max_ports = node->max_input_ports; n_ports = &node->n_input_ports; ports = &node->input_ports; @@ -752,7 +753,7 @@ pinos_node_get_free_port (PinosNode *node, portmap = node->output_port_map; } - pinos_log_debug ("node %p: direction %d max %u, n %u", node, direction, max_ports, *n_ports); + pw_log_debug ("node %p: direction %d max %u, n %u", node, direction, max_ports, *n_ports); spa_list_for_each (p, ports, link) { if (spa_list_is_empty (&p->links)) { @@ -766,12 +767,12 @@ pinos_node_get_free_port (PinosNode *node, if (*n_ports < max_ports) { for (i = 0; i < max_ports && port == NULL; i++) { if (portmap[i] == NULL) { - pinos_log_debug ("node %p: creating port direction %d %u", node, direction, i); - port = portmap[i] = pinos_port_new (node, direction, i); + pw_log_debug ("node %p: creating port direction %d %u", node, direction, i); + port = portmap[i] = pw_port_new (node, direction, i); spa_list_insert (ports, &port->link); (*n_ports)++; if ((res = spa_node_add_port (node->node, direction, i)) < 0) { - pinos_log_error ("node %p: could not add port %d", node, i); + pw_log_error ("node %p: could not add port %d", node, i); } else { spa_node_port_set_io (node->node, direction, i, &port->io); @@ -780,8 +781,8 @@ pinos_node_get_free_port (PinosNode *node, } } else { /* for output we can reuse an existing port */ - if (direction == PINOS_DIRECTION_OUTPUT && !spa_list_is_empty (ports)) { - port = spa_list_first (ports, PinosPort, link); + if (direction == PW_DIRECTION_OUTPUT && !spa_list_is_empty (ports)) { + port = spa_list_first (ports, struct pw_port, link); } } } @@ -790,121 +791,121 @@ pinos_node_get_free_port (PinosNode *node, } static void -on_state_complete (PinosNode *node, - void *data, - SpaResult res) +on_state_complete (struct pw_node *node, + void *data, + SpaResult res) { - PinosNodeState state = SPA_PTR_TO_INT (data); + enum pw_node_state state = SPA_PTR_TO_INT (data); char *error = NULL; - pinos_log_debug ("node %p: state complete %d", node, res); + pw_log_debug ("node %p: state complete %d", node, res); if (SPA_RESULT_IS_ERROR (res)) { asprintf (&error, "error changing node state: %d", res); - state = PINOS_NODE_STATE_ERROR; + state = PW_NODE_STATE_ERROR; } - pinos_node_update_state (node, state, error); + pw_node_update_state (node, state, error); } static void -node_activate (PinosNode *this) +node_activate (struct pw_node *this) { - PinosPort *port; + struct pw_port *port; spa_list_for_each (port, &this->input_ports, link) { - PinosLink *link; + struct pw_link *link; spa_list_for_each (link, &port->links, input_link) - pinos_link_activate (link); + pw_link_activate (link); } spa_list_for_each (port, &this->output_ports, link) { - PinosLink *link; + struct pw_link *link; spa_list_for_each (link, &port->links, output_link) - pinos_link_activate (link); + pw_link_activate (link); } } /** - * pinos_node_set_state: - * @node: a #PinosNode - * @state: a #PinosNodeState + * pw_node_set_state: + * @node: a #struct pw_node + * @state: a #enum pw_node_state * * Set the state of @node to @state. * * Returns: a #SpaResult */ SpaResult -pinos_node_set_state (PinosNode *node, - PinosNodeState state) +pw_node_set_state (struct pw_node *node, + enum pw_node_state state) { SpaResult res = SPA_RESULT_OK; - PinosNodeImpl *impl = SPA_CONTAINER_OF (node, PinosNodeImpl, this); + struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this); - pinos_signal_emit (&node->state_request, node, state); + pw_signal_emit (&node->state_request, node, state); - pinos_log_debug ("node %p: set state %s", node, pinos_node_state_as_string (state)); + pw_log_debug ("node %p: set state %s", node, pw_node_state_as_string (state)); switch (state) { - case PINOS_NODE_STATE_CREATING: + case PW_NODE_STATE_CREATING: return SPA_RESULT_ERROR; - case PINOS_NODE_STATE_SUSPENDED: + case PW_NODE_STATE_SUSPENDED: res = suspend_node (node); break; - case PINOS_NODE_STATE_IDLE: + case PW_NODE_STATE_IDLE: res = pause_node (node); break; - case PINOS_NODE_STATE_RUNNING: + case PW_NODE_STATE_RUNNING: node_activate (node); send_clock_update (node); res = start_node (node); break; - case PINOS_NODE_STATE_ERROR: + case PW_NODE_STATE_ERROR: break; } if (SPA_RESULT_IS_ERROR (res)) return res; - pinos_work_queue_add (impl->work, - node, - res, - (PinosWorkFunc) on_state_complete, - SPA_INT_TO_PTR (state)); + pw_work_queue_add (impl->work, + node, + res, + (pw_work_func_t) on_state_complete, + SPA_INT_TO_PTR (state)); return res; } /** - * pinos_node_update_state: - * @node: a #PinosNode - * @state: a #PinosNodeState - * @error: error when @state is #PINOS_NODE_STATE_ERROR + * pw_node_update_state: + * @node: a #struct pw_node + * @state: a #enum pw_node_state + * @error: error when @state is #PW_NODE_STATE_ERROR * * Update the state of a node. This method is used from * inside @node itself. */ void -pinos_node_update_state (PinosNode *node, - PinosNodeState state, - char *error) +pw_node_update_state (struct pw_node *node, + enum pw_node_state state, + char *error) { - PinosNodeState old; + enum pw_node_state old; old = node->state; if (old != state) { - PinosNodeInfo info; - PinosResource *resource; + struct pw_node_info info; + struct pw_resource *resource; - pinos_log_debug ("node %p: update state from %s -> %s", node, - pinos_node_state_as_string (old), - pinos_node_state_as_string (state)); + pw_log_debug ("node %p: update state from %s -> %s", node, + pw_node_state_as_string (old), + pw_node_state_as_string (state)); if (node->error) free (node->error); node->error = error; node->state = state; - pinos_signal_emit (&node->state_changed, node, old, state); + pw_signal_emit (&node->state_changed, node, old, state); spa_zero (info); info.change_mask = 1 << 5; @@ -914,7 +915,7 @@ pinos_node_update_state (PinosNode *node, spa_list_for_each (resource, &node->resource_list, link) { /* global is only set when there are resources */ info.id = node->global->id; - pinos_node_notify_info (resource, &info); + pw_node_notify_info (resource, &info); } } } diff --git a/pipewire/server/node.h b/pipewire/server/node.h new file mode 100644 index 000000000..663891e97 --- /dev/null +++ b/pipewire/server/node.h @@ -0,0 +1,136 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_NODE_H__ +#define __PIPEWIRE_NODE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPEWIRE_TYPE__Node "PipeWire:Object:Node" +#define PIPEWIRE_TYPE_NODE_BASE PIPEWIRE_TYPE__Node ":" + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +/** + * pw_node: + * + * PipeWire node class. + */ +struct pw_node { + struct pw_core *core; + SpaList link; + struct pw_global *global; + + struct pw_client *owner; + char *name; + struct pw_properties *properties; + enum pw_node_state state; + char *error; + PW_SIGNAL (state_request, (struct pw_listener *listener, + struct pw_node *object, + enum pw_node_state state)); + PW_SIGNAL (state_changed, (struct pw_listener *listener, + struct pw_node *object, + enum pw_node_state old, + enum pw_node_state state)); + + SpaHandle *handle; + SpaNode *node; + bool live; + SpaClock *clock; + + SpaList resource_list; + + PW_SIGNAL (initialized, (struct pw_listener *listener, + struct pw_node *object)); + + uint32_t max_input_ports; + uint32_t n_input_ports; + SpaList input_ports; + struct pw_port **input_port_map; + uint32_t n_used_input_links; + + uint32_t max_output_ports; + uint32_t n_output_ports; + SpaList output_ports; + struct pw_port **output_port_map; + uint32_t n_used_output_links; + + PW_SIGNAL (port_added, (struct pw_listener *listener, + struct pw_node *node, + struct pw_port *port)); + PW_SIGNAL (port_removed, (struct pw_listener *listener, + struct pw_node *node, + struct pw_port *port)); + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_node *object)); + PW_SIGNAL (free_signal, (struct pw_listener *listener, + struct pw_node *object)); + + PW_SIGNAL (async_complete, (struct pw_listener *listener, + struct pw_node *node, + uint32_t seq, + SpaResult res)); + + struct pw_data_loop *data_loop; + PW_SIGNAL (loop_changed, (struct pw_listener *listener, + struct pw_node *object)); +}; + +struct pw_node * pw_node_new (struct pw_core *core, + struct pw_client *owner, + const char *name, + bool async, + SpaNode *node, + SpaClock *clock, + struct pw_properties *properties); +void pw_node_destroy (struct pw_node *node); + + +void pw_node_set_data_loop (struct pw_node *node, + struct pw_data_loop *loop); + +struct pw_port * pw_node_get_free_port (struct pw_node *node, + enum pw_direction direction); + +SpaResult pw_node_set_state (struct pw_node *node, + enum pw_node_state state); +void pw_node_update_state (struct pw_node *node, + enum pw_node_state state, + char *error); + +#ifdef __cplusplus +} +#endif + + +#endif /* __PIPEWIRE_NODE_H__ */ diff --git a/pinos/server/port.c b/pipewire/server/port.c similarity index 55% rename from pinos/server/port.c rename to pipewire/server/port.c index 74f695519..03e8e2c80 100644 --- a/pinos/server/port.c +++ b/pipewire/server/port.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -21,26 +21,26 @@ #include #include -#include "pinos/client/pinos.h" +#include "pipewire/client/pipewire.h" -#include "pinos/server/port.h" +#include "pipewire/server/port.h" -typedef struct +struct impl { - PinosPort this; + struct pw_port this; uint32_t seq; -} PinosPortImpl; +}; -PinosPort * -pinos_port_new (PinosNode *node, - PinosDirection direction, - uint32_t port_id) +struct pw_port * +pw_port_new (struct pw_node *node, + enum pw_direction direction, + uint32_t port_id) { - PinosPortImpl *impl; - PinosPort *this; + struct impl *impl; + struct pw_port *this; - impl = calloc (1, sizeof (PinosPortImpl)); + impl = calloc (1, sizeof (struct impl)); if (impl == NULL) return NULL; @@ -48,23 +48,23 @@ pinos_port_new (PinosNode *node, this->node = node; this->direction = direction; this->port_id = port_id; - this->state = PINOS_PORT_STATE_CONFIGURE; + this->state = PW_PORT_STATE_CONFIGURE; this->io.status = SPA_RESULT_OK; this->io.buffer_id = SPA_ID_INVALID; spa_list_init (&this->links); spa_list_init (&this->rt.links); - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); return this; } void -pinos_port_destroy (PinosPort *port) +pw_port_destroy (struct pw_port *port) { - pinos_log_debug ("port %p: destroy", port); + pw_log_debug ("port %p: destroy", port); - pinos_signal_emit (&port->destroy_signal, port); + pw_signal_emit (&port->destroy_signal, port); spa_list_remove (&port->link); @@ -79,10 +79,10 @@ do_add_link (SpaLoop *loop, void *data, void *user_data) { - PinosPort *this = user_data; - PinosLink *link = ((PinosLink**)data)[0]; + struct pw_port *this = user_data; + struct pw_link *link = ((struct pw_link**)data)[0]; - if (this->direction == PINOS_DIRECTION_INPUT) { + if (this->direction == PW_DIRECTION_INPUT) { spa_list_insert (this->rt.links.prev, &link->rt.input_link); link->rt.input = this; } @@ -94,10 +94,10 @@ do_add_link (SpaLoop *loop, return SPA_RESULT_OK; } -static PinosLink * -find_link (PinosPort *output_port, PinosPort *input_port) +static struct pw_link * +find_link (struct pw_port *output_port, struct pw_port *input_port) { - PinosLink *pl; + struct pw_link *pl; spa_list_for_each (pl, &output_port->links, output_link) { if (pl->input == input_port) @@ -106,15 +106,15 @@ find_link (PinosPort *output_port, PinosPort *input_port) return NULL; } -PinosLink * -pinos_port_get_link (PinosPort *output_port, - PinosPort *input_port) +struct pw_link * +pw_port_get_link (struct pw_port *output_port, + struct pw_port *input_port) { return find_link (output_port, input_port); } /** - * pinos_port_link: + * pw_port_link: * @output_port: an output port * @input_port: an input port * @format_filter: a format filter @@ -125,22 +125,22 @@ pinos_port_get_link (PinosPort *output_port, * * If the ports were already linked, the existing links will be returned. * - * Returns: a new #PinosLink or %NULL and @error is set. + * Returns: a new #struct pw_link or %NULL and @error is set. */ -PinosLink * -pinos_port_link (PinosPort *output_port, - PinosPort *input_port, - SpaFormat **format_filter, - PinosProperties *properties, - char **error) +struct pw_link * +pw_port_link (struct pw_port *output_port, + struct pw_port *input_port, + SpaFormat **format_filter, + struct pw_properties *properties, + char **error) { - PinosNode *input_node, *output_node; - PinosLink *link; + struct pw_node *input_node, *output_node; + struct pw_link *link; output_node = output_port->node; input_node = input_port->node; - pinos_log_debug ("port link %p:%u -> %p:%u", output_node, output_port->port_id, input_node, input_port->port_id); + pw_log_debug ("port link %p:%u -> %p:%u", output_node, output_port->port_id, input_node, input_port->port_id); if (output_node == input_node) goto same_node; @@ -154,13 +154,13 @@ pinos_port_link (PinosPort *output_port, input_node->live = output_node->live; if (output_node->clock) input_node->clock = output_node->clock; - pinos_log_debug ("node %p: clock %p, live %d", output_node, output_node->clock, output_node->live); + pw_log_debug ("node %p: clock %p, live %d", output_node, output_node->clock, output_node->live); - link = pinos_link_new (output_node->core, - output_port, - input_port, - format_filter, - properties); + link = pw_link_new (output_node->core, + output_port, + input_port, + format_filter, + properties); if (link == NULL) goto no_mem; @@ -170,18 +170,18 @@ pinos_port_link (PinosPort *output_port, output_node->n_used_output_links++; input_node->n_used_input_links++; - pinos_loop_invoke (output_node->data_loop->loop, - do_add_link, - SPA_ID_INVALID, - sizeof (PinosLink *), - &link, - output_port); - pinos_loop_invoke (input_node->data_loop->loop, - do_add_link, - SPA_ID_INVALID, - sizeof (PinosLink *), - &link, - input_port); + pw_loop_invoke (output_node->data_loop->loop, + do_add_link, + SPA_ID_INVALID, + sizeof (struct pw_link *), + &link, + output_port); + pw_loop_invoke (input_node->data_loop->loop, + do_add_link, + SPA_ID_INVALID, + sizeof (struct pw_link *), + &link, + input_port); } return link; @@ -200,19 +200,19 @@ no_mem: } SpaResult -pinos_port_pause_rt (PinosPort *port) +pw_port_pause_rt (struct pw_port *port) { SpaResult res; - if (port->state <= PINOS_PORT_STATE_PAUSED) + if (port->state <= PW_PORT_STATE_PAUSED) return SPA_RESULT_OK; res = spa_node_port_send_command (port->node->node, port->direction, port->port_id, &SPA_COMMAND_INIT (port->node->core->type.command_node.Pause)); - port->state = PINOS_PORT_STATE_PAUSED; - pinos_log_debug ("port %p: state PAUSED", port); + port->state = PW_PORT_STATE_PAUSED; + pw_log_debug ("port %p: state PAUSED", port); return res; } @@ -224,12 +224,12 @@ do_remove_link_done (SpaLoop *loop, void *data, void *user_data) { - PinosPort *port = user_data; - PinosNode *node = port->node; - PinosLink *link = ((PinosLink**)data)[0]; + struct pw_port *port = user_data; + struct pw_node *node = port->node; + struct pw_link *link = ((struct pw_link**)data)[0]; - pinos_log_debug ("port %p: finish unlink", port); - if (port->direction == PINOS_DIRECTION_OUTPUT) { + pw_log_debug ("port %p: finish unlink", port); + if (port->direction == PW_DIRECTION_OUTPUT) { if (link->output) { spa_list_remove (&link->output_link); node->n_used_output_links--; @@ -243,21 +243,21 @@ do_remove_link_done (SpaLoop *loop, } } - if (!port->allocated && port->state > PINOS_PORT_STATE_READY) { - pinos_log_debug ("port %p: clear buffers on port", port); + if (!port->allocated && port->state > PW_PORT_STATE_READY) { + pw_log_debug ("port %p: clear buffers on port", port); spa_node_port_use_buffers (port->node->node, port->direction, port->port_id, NULL, 0); port->buffers = NULL; port->n_buffers = 0; - port->state = PINOS_PORT_STATE_READY; - pinos_log_debug ("port %p: state READY", port); + port->state = PW_PORT_STATE_READY; + pw_log_debug ("port %p: state READY", port); } if (node->n_used_output_links == 0 && node->n_used_input_links == 0) { - pinos_node_update_state (node, PINOS_NODE_STATE_IDLE, NULL); + pw_node_update_state (node, PW_NODE_STATE_IDLE, NULL); } return SPA_RESULT_OK; @@ -271,44 +271,44 @@ do_remove_link (SpaLoop *loop, void *data, void *user_data) { - PinosPort *port = user_data; - PinosNode *this = port->node; - PinosLink *link = ((PinosLink**)data)[0]; + struct pw_port *port = user_data; + struct pw_node *this = port->node; + struct pw_link *link = ((struct pw_link**)data)[0]; SpaResult res; - if (port->direction == PINOS_DIRECTION_INPUT) { - pinos_port_pause_rt (link->rt.input); + if (port->direction == PW_DIRECTION_INPUT) { + pw_port_pause_rt (link->rt.input); spa_list_remove (&link->rt.input_link); link->rt.input = NULL; } else { - pinos_port_pause_rt (link->rt.output); + pw_port_pause_rt (link->rt.output); spa_list_remove (&link->rt.output_link); link->rt.output = NULL; } - res = pinos_loop_invoke (this->core->main_loop->loop, - do_remove_link_done, - seq, - sizeof (PinosLink *), - &link, - port); + res = pw_loop_invoke (this->core->main_loop->loop, + do_remove_link_done, + seq, + sizeof (struct pw_link *), + &link, + port); return res; } SpaResult -pinos_port_unlink (PinosPort *port, PinosLink *link) +pw_port_unlink (struct pw_port *port, struct pw_link *link) { SpaResult res; - PinosPortImpl *impl = SPA_CONTAINER_OF (port, PinosPortImpl, this); + struct impl *impl = SPA_CONTAINER_OF (port, struct impl, this); - pinos_log_debug ("port %p: start unlink %p", port, link); + pw_log_debug ("port %p: start unlink %p", port, link); - res = pinos_loop_invoke (port->node->data_loop->loop, - do_remove_link, - impl->seq++, - sizeof (PinosLink *), - &link, - port); + res = pw_loop_invoke (port->node->data_loop->loop, + do_remove_link, + impl->seq++, + sizeof (struct pw_link *), + &link, + port); return res; } @@ -320,21 +320,21 @@ do_clear_buffers_done (SpaLoop *loop, void *data, void *user_data) { - PinosPort *port = user_data; + struct pw_port *port = user_data; SpaResult res; - if (port->state <= PINOS_PORT_STATE_READY) + if (port->state <= PW_PORT_STATE_READY) return SPA_RESULT_OK; - pinos_log_debug ("port %p: clear buffers finish", port); + pw_log_debug ("port %p: clear buffers finish", port); res = spa_node_port_use_buffers (port->node->node, port->direction, port->port_id, NULL, 0); port->buffers = NULL; port->n_buffers = 0; - port->state = PINOS_PORT_STATE_READY; - pinos_log_debug ("port %p: state READY", port); + port->state = PW_PORT_STATE_READY; + pw_log_debug ("port %p: state READY", port); return res; } @@ -347,31 +347,31 @@ do_clear_buffers (SpaLoop *loop, void *data, void *user_data) { - PinosPort *port = user_data; - PinosNode *node = port->node; + struct pw_port *port = user_data; + struct pw_node *node = port->node; SpaResult res; - pinos_port_pause_rt (port); + pw_port_pause_rt (port); - res = pinos_loop_invoke (node->core->main_loop->loop, - do_clear_buffers_done, - seq, - 0, NULL, - port); + res = pw_loop_invoke (node->core->main_loop->loop, + do_clear_buffers_done, + seq, + 0, NULL, + port); return res; } SpaResult -pinos_port_clear_buffers (PinosPort *port) +pw_port_clear_buffers (struct pw_port *port) { SpaResult res; - PinosPortImpl *impl = SPA_CONTAINER_OF (port, PinosPortImpl, this); + struct impl *impl = SPA_CONTAINER_OF (port, struct impl, this); - pinos_log_debug ("port %p: clear buffers", port); - res = pinos_loop_invoke (port->node->data_loop->loop, - do_clear_buffers, - impl->seq++, - 0, NULL, - port); + pw_log_debug ("port %p: clear buffers", port); + res = pw_loop_invoke (port->node->data_loop->loop, + do_clear_buffers, + impl->seq++, + 0, NULL, + port); return res; } diff --git a/pipewire/server/port.h b/pipewire/server/port.h new file mode 100644 index 000000000..17b5365a5 --- /dev/null +++ b/pipewire/server/port.h @@ -0,0 +1,92 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_PORT_H__ +#define __PIPEWIRE_PORT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPEWIRE_TYPE__Port "PipeWire:Object:Port" +#define PIPEWIRE_TYPE_PORT_BASE PIPEWIRE_TYPE__Port ":" + +#include + +#include +#include + +#include +#include + +enum pw_port_state { + PW_PORT_STATE_ERROR = -1, + PW_PORT_STATE_INIT = 0, + PW_PORT_STATE_CONFIGURE = 1, + PW_PORT_STATE_READY = 2, + PW_PORT_STATE_PAUSED = 3, + PW_PORT_STATE_STREAMING = 4, +}; + +struct pw_port { + SpaList link; + + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, struct pw_port *)); + + struct pw_node *node; + enum pw_direction direction; + uint32_t port_id; + enum pw_port_state state; + SpaPortIO io; + + bool allocated; + struct pw_memblock buffer_mem; + SpaBuffer **buffers; + uint32_t n_buffers; + + SpaList links; + + struct { + SpaList links; + } rt; +}; + +struct pw_port * pw_port_new (struct pw_node *node, + enum pw_direction direction, + uint32_t port_id); +void pw_port_destroy (struct pw_port *port); + + +struct pw_link * pw_port_link (struct pw_port *output_port, + struct pw_port *input_port, + SpaFormat **format_filter, + struct pw_properties *properties, + char **error); +SpaResult pw_port_unlink (struct pw_port *port, + struct pw_link *link); + +SpaResult pw_port_pause_rt (struct pw_port *port); +SpaResult pw_port_clear_buffers (struct pw_port *port); + + +#ifdef __cplusplus +} +#endif + +#endif /* __PIPEWIRE_PORT_H__ */ diff --git a/pinos/server/protocol-native.c b/pipewire/server/protocol-native.c similarity index 64% rename from pinos/server/protocol-native.c rename to pipewire/server/protocol-native.c index 343e96867..14a04669c 100644 --- a/pinos/server/protocol-native.c +++ b/pipewire/server/protocol-native.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -20,16 +20,16 @@ #include "spa/pod-iter.h" -#include "pinos/client/interfaces.h" -#include "pinos/server/resource.h" -#include "pinos/server/protocol-native.h" +#include "pipewire/client/interfaces.h" +#include "pipewire/server/resource.h" +#include "pipewire/server/protocol-native.h" -typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size); +typedef bool (*demarshal_func_t) (void *object, void *data, size_t size); -typedef struct { +struct builder { SpaPODBuilder b; - PinosConnection *connection; -} Builder; + struct pw_connection *connection; +}; static uint32_t write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size) @@ -39,17 +39,17 @@ write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size) if (b->size <= b->offset) { b->size = SPA_ROUND_UP_N (b->offset + size, 4096); - b->data = pinos_connection_begin_write (((Builder*)b)->connection, b->size); + b->data = pw_connection_begin_write (((struct builder*)b)->connection, b->size); } memcpy (b->data + ref, data, size); return ref; } static void -core_update_map (PinosClient *client) +core_update_map (struct pw_client *client) { uint32_t diff, base, i; - PinosCore *core = client->core; + struct pw_core *core = client->core; const char **types; base = client->n_types; @@ -61,20 +61,20 @@ core_update_map (PinosClient *client) for (i = 0; i < diff; i++, base++) types[i] = spa_type_map_get_type (core->type.map, base); - pinos_core_notify_update_types (client->core_resource, - client->n_types, - diff, - types); + pw_core_notify_update_types (client->core_resource, + client->n_types, + diff, + types); client->n_types += diff; } static void -core_marshal_info (void *object, - PinosCoreInfo *info) +core_marshal_info (void *object, + struct pw_core_info *info) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -101,16 +101,16 @@ core_marshal_info (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_INFO, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CORE_EVENT_INFO, b.b.offset); } static void core_marshal_done (void *object, uint32_t seq) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -118,7 +118,7 @@ core_marshal_done (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_INT, seq); - pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_DONE, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CORE_EVENT_DONE, b.b.offset); } static void @@ -127,10 +127,10 @@ core_marshal_error (void *object, SpaResult res, const char *error, ...) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; char buffer[128]; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; va_list ap; @@ -145,16 +145,16 @@ core_marshal_error (void *object, SPA_POD_TYPE_INT, res, SPA_POD_TYPE_STRING, buffer); - pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_ERROR, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CORE_EVENT_ERROR, b.b.offset); } static void core_marshal_remove_id (void *object, uint32_t id) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -162,7 +162,7 @@ core_marshal_remove_id (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_INT, id); - pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_REMOVE_ID, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CORE_EVENT_REMOVE_ID, b.b.offset); } static void @@ -171,9 +171,9 @@ core_marshal_update_types (void *object, uint32_t n_types, const char **types) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i; @@ -189,7 +189,7 @@ core_marshal_update_types (void *object, spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_UPDATE_TYPES, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CORE_EVENT_UPDATE_TYPES, b.b.offset); } static bool @@ -197,7 +197,7 @@ core_demarshal_client_update (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaDict props; SpaPODIter it; uint32_t i; @@ -216,7 +216,7 @@ core_demarshal_client_update (void *object, 0)) return false; } - ((PinosCoreMethods*)resource->implementation)->client_update (resource, &props); + ((struct pw_core_methods*)resource->implementation)->client_update (resource, &props); return true; } @@ -225,7 +225,7 @@ core_demarshal_sync (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t seq; @@ -235,7 +235,7 @@ core_demarshal_sync (void *object, 0)) return false; - ((PinosCoreMethods*)resource->implementation)->sync (resource, seq); + ((struct pw_core_methods*)resource->implementation)->sync (resource, seq); return true; } @@ -244,7 +244,7 @@ core_demarshal_get_registry (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; int32_t new_id; @@ -254,7 +254,7 @@ core_demarshal_get_registry (void *object, 0)) return false; - ((PinosCoreMethods*)resource->implementation)->get_registry (resource, new_id); + ((struct pw_core_methods*)resource->implementation)->get_registry (resource, new_id); return true; } @@ -263,7 +263,7 @@ core_demarshal_create_node (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t new_id, i; const char *factory_name, *name; @@ -288,7 +288,7 @@ core_demarshal_create_node (void *object, if (!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((PinosCoreMethods*)resource->implementation)->create_node (resource, + ((struct pw_core_methods*)resource->implementation)->create_node (resource, factory_name, name, &props, @@ -301,7 +301,7 @@ core_demarshal_create_client_node (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t new_id, i; const char *name; @@ -325,7 +325,7 @@ core_demarshal_create_client_node (void *object, if (!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((PinosCoreMethods*)resource->implementation)->create_client_node (resource, + ((struct pw_core_methods*)resource->implementation)->create_client_node (resource, name, &props, new_id); @@ -337,7 +337,7 @@ core_demarshal_update_types (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t first_id, n_types; const char **types; @@ -355,7 +355,7 @@ core_demarshal_update_types (void *object, if (!spa_pod_iter_get (&it, SPA_POD_TYPE_STRING, &types[i], 0)) return false; } - ((PinosCoreMethods*)resource->implementation)->update_types (resource, first_id, n_types, types); + ((struct pw_core_methods*)resource->implementation)->update_types (resource, first_id, n_types, types); return true; } @@ -364,9 +364,9 @@ registry_marshal_global (void *object, uint32_t id, const char *type) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -375,16 +375,16 @@ registry_marshal_global (void *object, SPA_POD_TYPE_INT, id, SPA_POD_TYPE_STRING, type); - pinos_connection_end_write (connection, resource->id, PINOS_REGISTRY_EVENT_GLOBAL, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_REGISTRY_EVENT_GLOBAL, b.b.offset); } static void registry_marshal_global_remove (void *object, uint32_t id) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -392,7 +392,7 @@ registry_marshal_global_remove (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_INT, id); - pinos_connection_end_write (connection, resource->id, PINOS_REGISTRY_EVENT_GLOBAL_REMOVE, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_REGISTRY_EVENT_GLOBAL_REMOVE, b.b.offset); } static bool @@ -400,7 +400,7 @@ registry_demarshal_bind (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t id, new_id; @@ -411,17 +411,17 @@ registry_demarshal_bind (void *object, 0)) return false; - ((PinosRegistryMethods*)resource->implementation)->bind (resource, id, new_id); + ((struct pw_registry_methods*)resource->implementation)->bind (resource, id, new_id); return true; } static void -module_marshal_info (void *object, - PinosModuleInfo *info) +module_marshal_info (void *object, + struct pw_module_info *info) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -446,16 +446,16 @@ module_marshal_info (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_MODULE_EVENT_INFO, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_MODULE_EVENT_INFO, b.b.offset); } static void -node_marshal_info (void *object, - PinosNodeInfo *info) +node_marshal_info (void *object, + struct pw_node_info *info) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -495,16 +495,16 @@ node_marshal_info (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_NODE_EVENT_INFO, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_NODE_EVENT_INFO, b.b.offset); } static void -client_marshal_info (void *object, - PinosClientInfo *info) +client_marshal_info (void *object, + struct pw_client_info *info) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, n_items; @@ -525,7 +525,7 @@ client_marshal_info (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_EVENT_INFO, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_EVENT_INFO, b.b.offset); } static void @@ -533,27 +533,27 @@ client_node_marshal_done (void *object, int readfd, int writefd) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); spa_pod_builder_struct (&b.b, &f, - SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, readfd), - SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, writefd)); + SPA_POD_TYPE_INT, pw_connection_add_fd (connection, readfd), + SPA_POD_TYPE_INT, pw_connection_add_fd (connection, writefd)); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_DONE, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_DONE, b.b.offset); } static void client_node_marshal_event (void *object, const SpaEvent *event) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -561,7 +561,7 @@ client_node_marshal_event (void *object, spa_pod_builder_struct (&b.b, &f, SPA_POD_TYPE_POD, event); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_EVENT, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_EVENT, b.b.offset); } static void @@ -570,9 +570,9 @@ client_node_marshal_add_port (void *object, SpaDirection direction, uint32_t port_id) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -582,7 +582,7 @@ client_node_marshal_add_port (void *object, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_ADD_PORT, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_ADD_PORT, b.b.offset); } static void @@ -591,9 +591,9 @@ client_node_marshal_remove_port (void *object, SpaDirection direction, uint32_t port_id) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -603,7 +603,7 @@ client_node_marshal_remove_port (void *object, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_REMOVE_PORT, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_REMOVE_PORT, b.b.offset); } static void @@ -614,9 +614,9 @@ client_node_marshal_set_format (void *object, uint32_t flags, const SpaFormat *format) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -628,7 +628,7 @@ client_node_marshal_set_format (void *object, SPA_POD_TYPE_INT, flags, SPA_POD_TYPE_POD, format); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_SET_FORMAT, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_SET_FORMAT, b.b.offset); } static void @@ -638,9 +638,9 @@ client_node_marshal_set_property (void *object, uint32_t size, const void *value) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -650,7 +650,7 @@ client_node_marshal_set_property (void *object, SPA_POD_TYPE_INT, id, SPA_POD_TYPE_BYTES, value, size); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_SET_PROPERTY, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_SET_PROPERTY, b.b.offset); } static void @@ -664,9 +664,9 @@ client_node_marshal_add_mem (void *object, uint32_t offset, uint32_t size) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -676,25 +676,25 @@ client_node_marshal_add_mem (void *object, SPA_POD_TYPE_INT, port_id, SPA_POD_TYPE_INT, mem_id, SPA_POD_TYPE_ID, type, - SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, memfd), + SPA_POD_TYPE_INT, pw_connection_add_fd (connection, memfd), SPA_POD_TYPE_INT, flags, SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_ADD_MEM, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_ADD_MEM, b.b.offset); } static void -client_node_marshal_use_buffers (void *object, - uint32_t seq, - SpaDirection direction, - uint32_t port_id, - uint32_t n_buffers, - PinosClientNodeBuffer *buffers) +client_node_marshal_use_buffers (void *object, + uint32_t seq, + SpaDirection direction, + uint32_t port_id, + uint32_t n_buffers, + struct pw_client_node_buffer *buffers) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; uint32_t i, j; @@ -736,7 +736,7 @@ client_node_marshal_use_buffers (void *object, } spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_USE_BUFFERS, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_USE_BUFFERS, b.b.offset); } static void @@ -744,9 +744,9 @@ client_node_marshal_node_command (void *object, uint32_t seq, const SpaCommand *command) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -755,7 +755,7 @@ client_node_marshal_node_command (void *object, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_POD, command); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_NODE_COMMAND, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_NODE_COMMAND, b.b.offset); } static void @@ -763,9 +763,9 @@ client_node_marshal_port_command (void *object, uint32_t port_id, const SpaCommand *command) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -774,7 +774,7 @@ client_node_marshal_port_command (void *object, SPA_POD_TYPE_INT, port_id, SPA_POD_TYPE_POD, command); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_PORT_COMMAND, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_PORT_COMMAND, b.b.offset); } static void @@ -783,19 +783,19 @@ client_node_marshal_transport (void *object, uint32_t offset, uint32_t size) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); spa_pod_builder_struct (&b.b, &f, - SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, memfd), + SPA_POD_TYPE_INT, pw_connection_add_fd (connection, memfd), SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size); - pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_TRANSPORT, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_CLIENT_NODE_EVENT_TRANSPORT, b.b.offset); } static bool @@ -803,13 +803,13 @@ client_node_demarshal_update (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t change_mask, max_input_ports, max_output_ports; const SpaProps *props; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &change_mask, SPA_POD_TYPE_INT, &max_input_ports, @@ -818,7 +818,7 @@ client_node_demarshal_update (void *object, 0)) return false; - ((PinosClientNodeMethods*)resource->implementation)->update (resource, change_mask, max_input_ports, max_output_ports, props); + ((struct pw_client_node_methods*)resource->implementation)->update (resource, change_mask, max_input_ports, max_output_ports, props); return true; } @@ -827,7 +827,7 @@ client_node_demarshal_port_update (void *object, void *data, size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; uint32_t i, direction, port_id, change_mask, n_possible_formats, n_params; const SpaParam **params = NULL; @@ -836,7 +836,7 @@ client_node_demarshal_port_update (void *object, SpaPOD *ipod; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &direction, SPA_POD_TYPE_INT, &port_id, @@ -878,7 +878,7 @@ client_node_demarshal_port_update (void *object, return false; } - ((PinosClientNodeMethods*)resource->implementation)->port_update (resource, + ((struct pw_client_node_methods*)resource->implementation)->port_update (resource, direction, port_id, change_mask, @@ -893,44 +893,44 @@ client_node_demarshal_port_update (void *object, static bool client_node_demarshal_event (void *object, - void *data, - size_t size) + void *data, + size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; SpaEvent *event; if (!spa_pod_iter_struct (&it, data, size) || - !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || + !pw_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) || !spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &event, 0)) return false; - ((PinosClientNodeMethods*)resource->implementation)->event (resource, event); + ((struct pw_client_node_methods*)resource->implementation)->event (resource, event); return true; } static bool client_node_demarshal_destroy (void *object, - void *data, - size_t size) + void *data, + size_t size) { - PinosResource *resource = object; + struct pw_resource *resource = object; SpaPODIter it; if (!spa_pod_iter_struct (&it, data, size)) return false; - ((PinosClientNodeMethods*)resource->implementation)->destroy (resource); + ((struct pw_client_node_methods*)resource->implementation)->destroy (resource); return true; } static void -link_marshal_info (void *object, - PinosLinkInfo *info) +link_marshal_info (void *object, + struct pw_link_info *info) { - PinosResource *resource = object; - PinosConnection *connection = resource->client->protocol_private; - Builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; + struct pw_resource *resource = object; + struct pw_connection *connection = resource->client->protocol_private; + struct builder b = { { NULL, 0, 0, NULL, write_pod }, connection }; SpaPODFrame f; core_update_map (resource->client); @@ -943,10 +943,10 @@ link_marshal_info (void *object, SPA_POD_TYPE_INT, info->input_node_id, SPA_POD_TYPE_INT, info->input_port_id); - pinos_connection_end_write (connection, resource->id, PINOS_LINK_EVENT_INFO, b.b.offset); + pw_connection_end_write (connection, resource->id, PW_LINK_EVENT_INFO, b.b.offset); } -static const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = { +static const demarshal_func_t pw_protocol_native_server_core_demarshal[] = { &core_demarshal_client_update, &core_demarshal_sync, &core_demarshal_get_registry, @@ -955,7 +955,7 @@ static const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = &core_demarshal_update_types }; -static const PinosCoreEvents pinos_protocol_native_server_core_events = { +static const struct pw_core_events pw_protocol_native_server_core_events = { &core_marshal_info, &core_marshal_done, &core_marshal_error, @@ -963,60 +963,60 @@ static const PinosCoreEvents pinos_protocol_native_server_core_events = { &core_marshal_update_types }; -const PinosInterface pinos_protocol_native_server_core_interface = { - PINOS_CORE_METHOD_NUM, pinos_protocol_native_server_core_demarshal, - PINOS_CORE_EVENT_NUM, &pinos_protocol_native_server_core_events, +const struct pw_interface pw_protocol_native_server_core_interface = { + PW_CORE_METHOD_NUM, pw_protocol_native_server_core_demarshal, + PW_CORE_EVENT_NUM, &pw_protocol_native_server_core_events, }; -static const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[] = { +static const demarshal_func_t pw_protocol_native_server_registry_demarshal[] = { ®istry_demarshal_bind, }; -static const PinosRegistryEvents pinos_protocol_native_server_registry_events = { +static const struct pw_registry_events pw_protocol_native_server_registry_events = { ®istry_marshal_global, ®istry_marshal_global_remove, }; -const PinosInterface pinos_protocol_native_server_registry_interface = { - PINOS_REGISTRY_METHOD_NUM, pinos_protocol_native_server_registry_demarshal, - PINOS_REGISTRY_EVENT_NUM, &pinos_protocol_native_server_registry_events, +const struct pw_interface pw_protocol_native_server_registry_interface = { + PW_REGISTRY_METHOD_NUM, pw_protocol_native_server_registry_demarshal, + PW_REGISTRY_EVENT_NUM, &pw_protocol_native_server_registry_events, }; -static const PinosModuleEvents pinos_protocol_native_server_module_events = { +static const struct pw_module_events pw_protocol_native_server_module_events = { &module_marshal_info, }; -const PinosInterface pinos_protocol_native_server_module_interface = { +const struct pw_interface pw_protocol_native_server_module_interface = { 0, NULL, - PINOS_MODULE_EVENT_NUM, &pinos_protocol_native_server_module_events, + PW_MODULE_EVENT_NUM, &pw_protocol_native_server_module_events, }; -static const PinosNodeEvents pinos_protocol_native_server_node_events = { +static const struct pw_node_events pw_protocol_native_server_node_events = { &node_marshal_info, }; -const PinosInterface pinos_protocol_native_server_node_interface = { +const struct pw_interface pw_protocol_native_server_node_interface = { 0, NULL, - PINOS_NODE_EVENT_NUM, &pinos_protocol_native_server_node_events, + PW_NODE_EVENT_NUM, &pw_protocol_native_server_node_events, }; -static const PinosClientEvents pinos_protocol_native_server_client_events = { +static const struct pw_client_events pw_protocol_native_server_client_events = { &client_marshal_info, }; -const PinosInterface pinos_protocol_native_server_client_interface = { +const struct pw_interface pw_protocol_native_server_client_interface = { 0, NULL, - PINOS_CLIENT_EVENT_NUM, &pinos_protocol_native_server_client_events, + PW_CLIENT_EVENT_NUM, &pw_protocol_native_server_client_events, }; -static const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[] = { +static const demarshal_func_t pw_protocol_native_server_client_node_demarshal[] = { &client_node_demarshal_update, &client_node_demarshal_port_update, &client_node_demarshal_event, &client_node_demarshal_destroy, }; -static const PinosClientNodeEvents pinos_protocol_native_server_client_node_events = { +static const struct pw_client_node_events pw_protocol_native_server_client_node_events = { &client_node_marshal_done, &client_node_marshal_event, &client_node_marshal_add_port, @@ -1030,44 +1030,44 @@ static const PinosClientNodeEvents pinos_protocol_native_server_client_node_even &client_node_marshal_transport, }; -const PinosInterface pinos_protocol_native_server_client_node_interface = { - PINOS_CLIENT_NODE_METHOD_NUM, &pinos_protocol_native_server_client_node_demarshal, - PINOS_CLIENT_NODE_EVENT_NUM, &pinos_protocol_native_server_client_node_events, +const struct pw_interface pw_protocol_native_server_client_node_interface = { + PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_server_client_node_demarshal, + PW_CLIENT_NODE_EVENT_NUM, &pw_protocol_native_server_client_node_events, }; -static const PinosLinkEvents pinos_protocol_native_server_link_events = { +static const struct pw_link_events pw_protocol_native_server_link_events = { &link_marshal_info, }; -const PinosInterface pinos_protocol_native_server_link_interface = { +const struct pw_interface pw_protocol_native_server_link_interface = { 0, NULL, - PINOS_LINK_EVENT_NUM, &pinos_protocol_native_server_link_events, + PW_LINK_EVENT_NUM, &pw_protocol_native_server_link_events, }; bool -pinos_protocol_native_server_setup (PinosResource *resource) +pw_protocol_native_server_setup (struct pw_resource *resource) { - const PinosInterface *iface; + const struct pw_interface *iface; if (resource->type == resource->core->type.core) { - iface = &pinos_protocol_native_server_core_interface; + iface = &pw_protocol_native_server_core_interface; } else if (resource->type == resource->core->type.registry) { - iface = &pinos_protocol_native_server_registry_interface; + iface = &pw_protocol_native_server_registry_interface; } else if (resource->type == resource->core->type.module) { - iface = &pinos_protocol_native_server_module_interface; + iface = &pw_protocol_native_server_module_interface; } else if (resource->type == resource->core->type.node) { - iface = &pinos_protocol_native_server_node_interface; + iface = &pw_protocol_native_server_node_interface; } else if (resource->type == resource->core->type.client) { - iface = &pinos_protocol_native_server_client_interface; + iface = &pw_protocol_native_server_client_interface; } else if (resource->type == resource->core->type.client_node) { - iface = &pinos_protocol_native_server_client_node_interface; + iface = &pw_protocol_native_server_client_node_interface; } else if (resource->type == resource->core->type.link) { - iface = &pinos_protocol_native_server_link_interface; + iface = &pw_protocol_native_server_link_interface; } else return false; resource->iface = iface; diff --git a/pinos/server/protocol-native.h b/pipewire/server/protocol-native.h similarity index 87% rename from pinos/server/protocol-native.h rename to pipewire/server/protocol-native.h index 8e81b15f1..c31de684e 100644 --- a/pinos/server/protocol-native.h +++ b/pipewire/server/protocol-native.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2017 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,6 +17,6 @@ * Boston, MA 02110-1301, USA. */ -#include "pinos/client/pinos.h" +#include "pipewire/client/pipewire.h" -bool pinos_protocol_native_server_setup (PinosResource *resource); +bool pw_protocol_native_server_setup (struct pw_resource *resource); diff --git a/pipewire/server/resource.c b/pipewire/server/resource.c new file mode 100644 index 000000000..d5b6901c1 --- /dev/null +++ b/pipewire/server/resource.c @@ -0,0 +1,88 @@ +/* PipeWire + * Copyright (C) 2015 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include + +#include "pipewire/client/interfaces.h" +#include "pipewire/server/resource.h" + +struct impl { + struct pw_resource this; +}; + +struct pw_resource * +pw_resource_new (struct pw_client *client, + uint32_t id, + uint32_t type, + void *object, + pw_destroy_t destroy) +{ + struct impl *impl; + struct pw_resource *this; + + impl = calloc (1, sizeof (struct impl)); + if (impl == NULL) + return NULL; + + this = &impl->this; + this->core = client->core; + this->client = client; + this->type = type; + this->object = object; + this->destroy = destroy; + + pw_signal_init (&this->destroy_signal); + + if (id == SPA_ID_INVALID) { + this->id = pw_map_insert_new (&client->objects, this); + } else if (!pw_map_insert_at (&client->objects, id, this)) + goto in_use; + + this->id = id; + + pw_log_debug ("resource %p: new for client %p id %u", this, client, this->id); + pw_signal_emit (&client->resource_added, client, this); + + return this; + +in_use: + pw_log_debug ("resource %p: id %u in use for client %p", this, id, client); + free (impl); + return NULL; +} + +void +pw_resource_destroy (struct pw_resource *resource) +{ + struct pw_client *client = resource->client; + + pw_log_trace ("resource %p: destroy %u", resource, resource->id); + pw_signal_emit (&resource->destroy_signal, resource); + + pw_map_insert_at (&client->objects, resource->id, NULL); + pw_signal_emit (&client->resource_removed, client, resource); + + if (resource->destroy) + resource->destroy (resource); + + if (client->core_resource) + pw_core_notify_remove_id (client->core_resource, resource->id); + + free (resource); +} diff --git a/pinos/server/resource.h b/pipewire/server/resource.h similarity index 53% rename from pinos/server/resource.h rename to pipewire/server/resource.h index 49c35ecf1..05e0a592f 100644 --- a/pinos/server/resource.h +++ b/pipewire/server/resource.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,53 +17,50 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_RESOURCE_H__ -#define __PINOS_RESOURCE_H__ +#ifndef __PIPEWIRE_RESOURCE_H__ +#define __PIPEWIRE_RESOURCE_H__ #ifdef __cplusplus extern "C" { #endif -#define PINOS_TYPE__Resource "Pinos:Object:Resource" -#define PINOS_TYPE_RESOURCE_BASE PINOS_TYPE__Resource ":" - -typedef struct _PinosResource PinosResource; +#define PIPEWIRE_TYPE__Resource "PipeWire:Object:Resource" +#define PIPEWIRE_TYPE_RESOURCE_BASE PIPEWIRE_TYPE__Resource ":" #include -#include +#include +#include -#include +typedef void (*pw_destroy_t) (void *object); -typedef void (*PinosDestroy) (void *object); +struct pw_resource { + struct pw_core *core; + SpaList link; -struct _PinosResource { - PinosCore *core; - SpaList link; - - PinosClient *client; + struct pw_client *client; uint32_t id; uint32_t type; void *object; - PinosDestroy destroy; + pw_destroy_t destroy; - const PinosInterface *iface; - const void *implementation; + const struct pw_interface *iface; + const void *implementation; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosResource *resource)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_resource *resource)); }; -PinosResource * pinos_resource_new (PinosClient *client, - uint32_t id, - uint32_t type, - void *object, - PinosDestroy destroy); -void pinos_resource_destroy (PinosResource *resource); +struct pw_resource * pw_resource_new (struct pw_client *client, + uint32_t id, + uint32_t type, + void *object, + pw_destroy_t destroy); +void pw_resource_destroy (struct pw_resource *resource); #ifdef __cplusplus } #endif -#endif /* __PINOS_RESOURCE_H__ */ +#endif /* __PIPEWIRE_RESOURCE_H__ */ diff --git a/pinos/server/work-queue.c b/pipewire/server/work-queue.c similarity index 51% rename from pinos/server/work-queue.c rename to pipewire/server/work-queue.c index 9ef6b904f..8fac03227 100644 --- a/pinos/server/work-queue.c +++ b/pipewire/server/work-queue.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -20,24 +20,21 @@ #include #include -#include "pinos/client/log.h" -#include "pinos/server/work-queue.h" +#include "pipewire/client/log.h" +#include "pipewire/server/work-queue.h" -typedef struct _WorkItem WorkItem; - -struct _WorkItem { +struct work_item { uint32_t id; void *obj; uint32_t seq; SpaResult res; - PinosWorkFunc func; + pw_work_func_t func; void *data; SpaList link; }; -typedef struct -{ - PinosWorkQueue this; +struct impl { + struct pw_work_queue this; SpaSource *wakeup; uint32_t counter; @@ -45,7 +42,7 @@ typedef struct SpaList work_list; SpaList free_list; int n_queued; -} PinosWorkQueueImpl; +}; static void @@ -53,19 +50,20 @@ process_work_queue (SpaLoopUtils *utils, SpaSource *source, void *data) { - PinosWorkQueueImpl *impl = data; - PinosWorkQueue *this = &impl->this; - WorkItem *item, *tmp; + struct impl *impl = data; + struct pw_work_queue *this = &impl->this; + struct work_item *item, *tmp; spa_list_for_each_safe (item, tmp, &impl->work_list, link) { if (item->seq != SPA_ID_INVALID) { - pinos_log_debug ("work-queue %p: %d waiting for item %p %d", this, impl->n_queued, + pw_log_debug ("work-queue %p: %d waiting for item %p %d", this, impl->n_queued, item->obj, item->seq); continue; } - if (item->res == SPA_RESULT_WAIT_SYNC && item != spa_list_first (&impl->work_list, WorkItem, link)) { - pinos_log_debug ("work-queue %p: %d sync item %p not head", this, impl->n_queued, + if (item->res == SPA_RESULT_WAIT_SYNC && + item != spa_list_first (&impl->work_list, struct work_item, link)) { + pw_log_debug ("work-queue %p: %d sync item %p not head", this, impl->n_queued, item->obj); continue; } @@ -74,7 +72,7 @@ process_work_queue (SpaLoopUtils *utils, impl->n_queued--; if (item->func) { - pinos_log_debug ("work-queue %p: %d process work item %p %d %d", this, impl->n_queued, + pw_log_debug ("work-queue %p: %d process work item %p %d %d", this, impl->n_queued, item->obj, item->seq, item->res); item->func (item->obj, item->data, item->res, item->id); } @@ -83,28 +81,28 @@ process_work_queue (SpaLoopUtils *utils, } /** - * pinos_data_loop_new: + * pw_work_queue_new: * - * Create a new #PinosWorkQueue. + * Create a new #struct pw_work_queue. * - * Returns: a new #PinosWorkQueue + * Returns: a new #struct pw_work_queue */ -PinosWorkQueue * -pinos_work_queue_new (PinosLoop *loop) +struct pw_work_queue * +pw_work_queue_new (struct pw_loop *loop) { - PinosWorkQueueImpl *impl; - PinosWorkQueue *this; + struct impl *impl; + struct pw_work_queue *this; - impl = calloc (1, sizeof (PinosWorkQueueImpl)); - pinos_log_debug ("work-queue %p: new", impl); + impl = calloc (1, sizeof (struct impl)); + pw_log_debug ("work-queue %p: new", impl); this = &impl->this; this->loop = loop; - pinos_signal_init (&this->destroy_signal); + pw_signal_init (&this->destroy_signal); - impl->wakeup = pinos_loop_add_event (this->loop, - process_work_queue, - impl); + impl->wakeup = pw_loop_add_event (this->loop, + process_work_queue, + impl); spa_list_init (&impl->work_list); spa_list_init (&impl->free_list); @@ -113,18 +111,18 @@ pinos_work_queue_new (PinosLoop *loop) } void -pinos_work_queue_destroy (PinosWorkQueue * queue) +pw_work_queue_destroy (struct pw_work_queue * queue) { - PinosWorkQueueImpl *impl = SPA_CONTAINER_OF (queue, PinosWorkQueueImpl, this); - WorkItem *item, *tmp; + struct impl *impl = SPA_CONTAINER_OF (queue, struct impl, this); + struct work_item *item, *tmp; - pinos_log_debug ("work-queue %p: destroy", impl); - pinos_signal_emit (&queue->destroy_signal, queue); + pw_log_debug ("work-queue %p: destroy", impl); + pw_signal_emit (&queue->destroy_signal, queue); - pinos_loop_destroy_source (queue->loop, impl->wakeup); + pw_loop_destroy_source (queue->loop, impl->wakeup); spa_list_for_each_safe (item, tmp, &impl->work_list, link) { - pinos_log_warn ("work-queue %p: cancel work item %p %d %d", queue, + pw_log_warn ("work-queue %p: cancel work item %p %d %d", queue, item->obj, item->seq, item->res); free (item); } @@ -135,21 +133,21 @@ pinos_work_queue_destroy (PinosWorkQueue * queue) } uint32_t -pinos_work_queue_add (PinosWorkQueue *queue, - void *obj, - SpaResult res, - PinosWorkFunc func, - void *data) +pw_work_queue_add (struct pw_work_queue *queue, + void *obj, + SpaResult res, + pw_work_func_t func, + void *data) { - PinosWorkQueueImpl *impl = SPA_CONTAINER_OF (queue, PinosWorkQueueImpl, this); - WorkItem *item; + struct impl *impl = SPA_CONTAINER_OF (queue, struct impl, this); + struct work_item *item; bool have_work = false; if (!spa_list_is_empty (&impl->free_list)) { - item = spa_list_first (&impl->free_list, WorkItem, link); + item = spa_list_first (&impl->free_list, struct work_item, link); spa_list_remove (&item->link); } else { - item = malloc (sizeof (WorkItem)); + item = malloc (sizeof (struct work_item)); if (item == NULL) return SPA_ID_INVALID; } @@ -161,9 +159,9 @@ pinos_work_queue_add (PinosWorkQueue *queue, if (SPA_RESULT_IS_ASYNC (res)) { item->seq = SPA_RESULT_ASYNC_SEQ (res); item->res = res; - pinos_log_debug ("work-queue %p: defer async %d for object %p", queue, item->seq, obj); + pw_log_debug ("work-queue %p: defer async %d for object %p", queue, item->seq, obj); } else if (res == SPA_RESULT_WAIT_SYNC) { - pinos_log_debug ("work-queue %p: wait sync object %p", queue, obj); + pw_log_debug ("work-queue %p: wait sync object %p", queue, obj); item->seq = SPA_ID_INVALID; item->res = res; have_work = true; @@ -171,60 +169,60 @@ pinos_work_queue_add (PinosWorkQueue *queue, item->seq = SPA_ID_INVALID; item->res = res; have_work = true; - pinos_log_debug ("work-queue %p: defer object %p", queue, obj); + pw_log_debug ("work-queue %p: defer object %p", queue, obj); } spa_list_insert (impl->work_list.prev, &item->link); impl->n_queued++; if (have_work) - pinos_loop_signal_event (impl->this.loop, impl->wakeup); + pw_loop_signal_event (impl->this.loop, impl->wakeup); return item->id; } void -pinos_work_queue_cancel (PinosWorkQueue *queue, - void *obj, - uint32_t id) +pw_work_queue_cancel (struct pw_work_queue *queue, + void *obj, + uint32_t id) { - PinosWorkQueueImpl *impl = SPA_CONTAINER_OF (queue, PinosWorkQueueImpl, this); + struct impl *impl = SPA_CONTAINER_OF (queue, struct impl, this); bool have_work = false; - WorkItem *item; + struct work_item *item; spa_list_for_each (item, &impl->work_list, link) { if ((id == SPA_ID_INVALID || item->id == id) && (obj == NULL || item->obj == obj)) { - pinos_log_debug ("work-queue %p: cancel defer %d for object %p", queue, item->seq, item->obj); + pw_log_debug ("work-queue %p: cancel defer %d for object %p", queue, item->seq, item->obj); item->seq = SPA_ID_INVALID; item->func = NULL; have_work = true; } } if (have_work) - pinos_loop_signal_event (impl->this.loop, impl->wakeup); + pw_loop_signal_event (impl->this.loop, impl->wakeup); } bool -pinos_work_queue_complete (PinosWorkQueue *queue, - void *obj, - uint32_t seq, - SpaResult res) +pw_work_queue_complete (struct pw_work_queue *queue, + void *obj, + uint32_t seq, + SpaResult res) { - WorkItem *item; - PinosWorkQueueImpl *impl = SPA_CONTAINER_OF (queue, PinosWorkQueueImpl, this); + struct work_item *item; + struct impl *impl = SPA_CONTAINER_OF (queue, struct impl, this); bool have_work = false; spa_list_for_each (item, &impl->work_list, link) { if (item->obj == obj && item->seq == seq) { - pinos_log_debug ("work-queue %p: found defered %d for object %p", queue, seq, obj); + pw_log_debug ("work-queue %p: found defered %d for object %p", queue, seq, obj); item->seq = SPA_ID_INVALID; item->res = res; have_work = true; } } if (!have_work) { - pinos_log_debug ("work-queue %p: no defered %d found for object %p", queue, seq, obj); + pw_log_debug ("work-queue %p: no defered %d found for object %p", queue, seq, obj); } else { - pinos_loop_signal_event (impl->this.loop, impl->wakeup); + pw_loop_signal_event (impl->this.loop, impl->wakeup); } return have_work; } diff --git a/pinos/server/work-queue.h b/pipewire/server/work-queue.h similarity index 53% rename from pinos/server/work-queue.h rename to pipewire/server/work-queue.h index 3440e2d21..d8e84c490 100644 --- a/pinos/server/work-queue.h +++ b/pipewire/server/work-queue.h @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -17,52 +17,50 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_WORK_QUEUE_H__ -#define __PINOS_WORK_QUEUE_H__ +#ifndef __PIPEWIRE_WORK_QUEUE_H__ +#define __PIPEWIRE_WORK_QUEUE_H__ #ifdef __cplusplus extern "C" { #endif -#include +#include -typedef struct _PinosWorkQueue PinosWorkQueue; - -typedef void (*PinosWorkFunc) (void *obj, - void *data, - SpaResult res, - uint32_t id); +typedef void (*pw_work_func_t) (void *obj, + void *data, + SpaResult res, + uint32_t id); /** - * PinosWorkQueue: + * pw_work_queue: * - * Pinos work queue object. + * PipeWire work queue object. */ -struct _PinosWorkQueue { - PinosLoop *loop; +struct pw_work_queue { + struct pw_loop *loop; - PINOS_SIGNAL (destroy_signal, (PinosListener *listener, - PinosWorkQueue *queue)); + PW_SIGNAL (destroy_signal, (struct pw_listener *listener, + struct pw_work_queue *queue)); }; -PinosWorkQueue * pinos_work_queue_new (PinosLoop *loop); -void pinos_work_queue_destroy (PinosWorkQueue *queue); +struct pw_work_queue * pw_work_queue_new (struct pw_loop *loop); +void pw_work_queue_destroy (struct pw_work_queue *queue); -uint32_t pinos_work_queue_add (PinosWorkQueue *queue, - void *obj, - SpaResult res, - PinosWorkFunc func, - void *data); -void pinos_work_queue_cancel (PinosWorkQueue *queue, - void *obj, - uint32_t id); -bool pinos_work_queue_complete (PinosWorkQueue *queue, - void *obj, - uint32_t seq, - SpaResult res); +uint32_t pw_work_queue_add (struct pw_work_queue *queue, + void *obj, + SpaResult res, + pw_work_func_t func, + void *data); +void pw_work_queue_cancel (struct pw_work_queue *queue, + void *obj, + uint32_t id); +bool pw_work_queue_complete (struct pw_work_queue *queue, + void *obj, + uint32_t seq, + SpaResult res); #ifdef __cplusplus } #endif -#endif /* __PINOS_WORK_QUEUE_H__ */ +#endif /* __PIPEWIRE_WORK_QUEUE_H__ */ diff --git a/pipewire/tools/meson.build b/pipewire/tools/meson.build new file mode 100644 index 000000000..ca8e467f9 --- /dev/null +++ b/pipewire/tools/meson.build @@ -0,0 +1,5 @@ +executable('pipewire-monitor', + 'pipewire-monitor.c', + install: true, + dependencies : [pipewire_dep], +) diff --git a/pinos/tools/pinos-monitor.c b/pipewire/tools/pipewire-monitor.c similarity index 56% rename from pinos/tools/pinos-monitor.c rename to pipewire/tools/pipewire-monitor.c index fc9777155..98cf4b9a3 100644 --- a/pinos/tools/pinos-monitor.c +++ b/pipewire/tools/pipewire-monitor.c @@ -1,4 +1,4 @@ -/* Pinos +/* PipeWire * Copyright (C) 2015 Wim Taymans * * This library is free software; you can redistribute it and/or @@ -19,18 +19,18 @@ #include -#include -#include +#include +#include #include -typedef struct { +struct data { bool running; - PinosLoop *loop; - PinosContext *context; + struct pw_loop *loop; + struct pw_context *context; - PinosListener on_state_changed; - PinosListener on_subscription; -} Data; + struct pw_listener on_state_changed; + struct pw_listener on_subscription; +}; static void print_properties (SpaDict *props, char mark) @@ -46,26 +46,26 @@ print_properties (SpaDict *props, char mark) } } -typedef struct { +struct dumpdata { bool print_mark; bool print_all; -} DumpData; +}; #define MARK_CHANGE(f) ((data->print_mark && ((info)->change_mask & (1 << (f)))) ? '*' : ' ') static void -dump_core_info (PinosContext *c, - SpaResult res, - const PinosCoreInfo *info, - void *user_data) +dump_core_info (struct pw_context *c, + SpaResult res, + const struct pw_core_info *info, + void *user_data) { - DumpData *data = user_data; + struct dumpdata *data = user_data; if (info == NULL) return; printf ("\tid: %u\n", info->id); - printf ("\ttype: %s\n", PINOS_TYPE__Core); + printf ("\ttype: %s\n", PIPEWIRE_TYPE__Core); if (data->print_all) { printf ("%c\tuser-name: \"%s\"\n", MARK_CHANGE (0), info->user_name); printf ("%c\thost-name: \"%s\"\n", MARK_CHANGE (1), info->host_name); @@ -77,30 +77,30 @@ dump_core_info (PinosContext *c, } static void -dump_client_info (PinosContext *c, - SpaResult res, - const PinosClientInfo *info, - void *user_data) +dump_client_info (struct pw_context *c, + SpaResult res, + const struct pw_client_info *info, + void *user_data) { - DumpData *data = user_data; + struct dumpdata *data = user_data; if (info == NULL) return; printf ("\tid: %u\n", info->id); - printf ("\ttype: %s\n", PINOS_TYPE__Client); + printf ("\ttype: %s\n", PIPEWIRE_TYPE__Client); if (data->print_all) { print_properties (info->props, MARK_CHANGE (0)); } } static void -dump_node_info (PinosContext *c, - SpaResult res, - const PinosNodeInfo *info, - void *user_data) +dump_node_info (struct pw_context *c, + SpaResult res, + const struct pw_node_info *info, + void *user_data) { - DumpData *data = user_data; + struct dumpdata *data = user_data; if (info == NULL) { if (res != SPA_RESULT_ENUM_END) @@ -109,7 +109,7 @@ dump_node_info (PinosContext *c, } printf ("\tid: %u\n", info->id); - printf ("\ttype: %s\n", PINOS_TYPE__Node); + printf ("\ttype: %s\n", PIPEWIRE_TYPE__Node); if (data->print_all) { int i; @@ -124,8 +124,8 @@ dump_node_info (PinosContext *c, for (i = 0; i < info->n_output_formats; i++) spa_debug_format (info->output_formats[i], c->type.map); - printf ("%c\tstate: \"%s\"", MARK_CHANGE (5), pinos_node_state_as_string (info->state)); - if (info->state == PINOS_NODE_STATE_ERROR && info->error) + printf ("%c\tstate: \"%s\"", MARK_CHANGE (5), pw_node_state_as_string (info->state)); + if (info->state == PW_NODE_STATE_ERROR && info->error) printf (" \"%s\"\n", info->error); else printf ("\n"); @@ -134,12 +134,12 @@ dump_node_info (PinosContext *c, } static void -dump_module_info (PinosContext *c, +dump_module_info (struct pw_context *c, SpaResult res, - const PinosModuleInfo *info, + const struct pw_module_info *info, void *user_data) { - DumpData *data = user_data; + struct dumpdata *data = user_data; if (info == NULL) { if (res != SPA_RESULT_ENUM_END) @@ -148,7 +148,7 @@ dump_module_info (PinosContext *c, } printf ("\tid: %u\n", info->id); - printf ("\ttype: %s\n", PINOS_TYPE__Module); + printf ("\ttype: %s\n", PIPEWIRE_TYPE__Module); if (data->print_all) { printf ("%c\tname: \"%s\"\n", MARK_CHANGE (0), info->name); printf ("%c\tfilename: \"%s\"\n", MARK_CHANGE (1), info->filename); @@ -158,12 +158,12 @@ dump_module_info (PinosContext *c, } static void -dump_link_info (PinosContext *c, - SpaResult res, - const PinosLinkInfo *info, - void *user_data) +dump_link_info (struct pw_context *c, + SpaResult res, + const struct pw_link_info *info, + void *user_data) { - DumpData *data = user_data; + struct dumpdata *data = user_data; if (info == NULL) { if (res != SPA_RESULT_ENUM_END) @@ -172,7 +172,7 @@ dump_link_info (PinosContext *c, } printf ("\tid: %u\n", info->id); - printf ("\ttype: %s\n", PINOS_TYPE__Link); + printf ("\ttype: %s\n", PIPEWIRE_TYPE__Link); if (data->print_all) { printf ("%c\toutput-node-id: %u\n", MARK_CHANGE (0), info->output_node_id); printf ("%c\toutput-port-id: %u\n", MARK_CHANGE (1), info->output_port_id); @@ -182,35 +182,35 @@ dump_link_info (PinosContext *c, } static void -dump_object (PinosContext *context, +dump_object (struct pw_context *context, uint32_t type, uint32_t id, - DumpData *data) + struct dumpdata *data) { if (type == context->type.core) { - pinos_context_get_core_info (context, - dump_core_info, - data); + pw_context_get_core_info (context, + dump_core_info, + data); } else if (type == context->type.node) { - pinos_context_get_node_info_by_id (context, - id, - dump_node_info, - data); + pw_context_get_node_info_by_id (context, + id, + dump_node_info, + data); } else if (type == context->type.module) { - pinos_context_get_module_info_by_id (context, - id, - dump_module_info, - data); + pw_context_get_module_info_by_id (context, + id, + dump_module_info, + data); } else if (type == context->type.client) { - pinos_context_get_client_info_by_id (context, - id, - dump_client_info, - data); + pw_context_get_client_info_by_id (context, + id, + dump_client_info, + data); } else if (type == context->type.link) { - pinos_context_get_link_info_by_id (context, - id, - dump_link_info, - data); + pw_context_get_link_info_by_id (context, + id, + dump_link_info, + data); } else { printf ("\tid: %u\n", id); } @@ -219,30 +219,30 @@ dump_object (PinosContext *context, } static void -on_subscription (PinosListener *listener, - PinosContext *context, - PinosSubscriptionEvent event, - uint32_t type, - uint32_t id) +on_subscription (struct pw_listener *listener, + struct pw_context *context, + enum pw_subscription_event event, + uint32_t type, + uint32_t id) { - DumpData dd; + struct dumpdata dd; switch (event) { - case PINOS_SUBSCRIPTION_EVENT_NEW: + case PW_SUBSCRIPTION_EVENT_NEW: printf ("added:\n"); dd.print_mark = false; dd.print_all = true; dump_object (context, type, id, &dd); break; - case PINOS_SUBSCRIPTION_EVENT_CHANGE: + case PW_SUBSCRIPTION_EVENT_CHANGE: printf ("changed:\n"); dd.print_mark = true; dd.print_all = true; dump_object (context, type, id, &dd); break; - case PINOS_SUBSCRIPTION_EVENT_REMOVE: + case PW_SUBSCRIPTION_EVENT_REMOVE: printf ("removed:\n"); dd.print_mark = false; dd.print_all = false; @@ -252,19 +252,19 @@ on_subscription (PinosListener *listener, } static void -on_state_changed (PinosListener *listener, - PinosContext *context) +on_state_changed (struct pw_listener *listener, + struct pw_context *context) { - Data *data = SPA_CONTAINER_OF (listener, Data, on_state_changed); + struct data *data = SPA_CONTAINER_OF (listener, struct data, on_state_changed); switch (context->state) { - case PINOS_CONTEXT_STATE_ERROR: + case PW_CONTEXT_STATE_ERROR: printf ("context error: %s\n", context->error); data->running = false; break; default: - printf ("context state: \"%s\"\n", pinos_context_state_as_string (context->state)); + printf ("context state: \"%s\"\n", pw_context_state_as_string (context->state)); break; } } @@ -272,32 +272,32 @@ on_state_changed (PinosListener *listener, int main (int argc, char *argv[]) { - Data data; + struct data data; - pinos_init (&argc, &argv); + pw_init (&argc, &argv); - data.loop = pinos_loop_new (); + data.loop = pw_loop_new (); data.running = true; - data.context = pinos_context_new (data.loop, "pinos-monitor", NULL); + data.context = pw_context_new (data.loop, "pipewire-monitor", NULL); - pinos_signal_add (&data.context->state_changed, - &data.on_state_changed, - on_state_changed); + pw_signal_add (&data.context->state_changed, + &data.on_state_changed, + on_state_changed); - pinos_signal_add (&data.context->subscription, - &data.on_subscription, - on_subscription); + pw_signal_add (&data.context->subscription, + &data.on_subscription, + on_subscription); - pinos_context_connect (data.context, 0); + pw_context_connect (data.context, 0); - pinos_loop_enter (data.loop); + pw_loop_enter (data.loop); while (data.running) { - pinos_loop_iterate (data.loop, -1); + pw_loop_iterate (data.loop, -1); } - pinos_loop_leave (data.loop); + pw_loop_leave (data.loop); - pinos_context_destroy (data.context); - pinos_loop_destroy (data.loop); + pw_context_destroy (data.context); + pw_loop_destroy (data.loop); return 0; } diff --git a/pkgconfig/libpinos.pc.in b/pkgconfig/libpipewire.pc.in similarity index 66% rename from pkgconfig/libpinos.pc.in rename to pkgconfig/libpipewire.pc.in index 52a5895bd..de38a4eb2 100644 --- a/pkgconfig/libpinos.pc.in +++ b/pkgconfig/libpipewire.pc.in @@ -4,8 +4,8 @@ libdir=@libdir@ includedir=@includedir@/ moduledir=@moduledir@ -Name: libpinos -Description: Pinos Client Interface +Name: libpipewire +Description: PipeWire Client Interface Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lpinos +Libs: -L${libdir} -lpipewire Cflags: -I${includedir} -D_REENTRANT diff --git a/pkgconfig/meson.build b/pkgconfig/meson.build index e32c70ad0..f3159bc49 100644 --- a/pkgconfig/meson.build +++ b/pkgconfig/meson.build @@ -4,13 +4,13 @@ pkgconf.set('prefix', get_option('prefix')) pkgconf.set('exec_prefix', '${prefix}') pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir'))) pkgconf.set('includedir', '${prefix}/@0@'.format(get_option('includedir'))) -pkgconf.set('PINOS_API_VERSION', apiversion) -pkgconf.set('VERSION', pinos_version) +pkgconf.set('PIPEWIRE_API_VERSION', apiversion) +pkgconf.set('VERSION', pipewire_version) pkg_install_dir = '@0@/pkgconfig'.format(get_option('libdir')) pkg_files = [ - 'libpinos', + 'libpipewire', 'libspa', ] diff --git a/po/POTFILES.in b/po/POTFILES.in index 18e8b57b3..9b3a6df37 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,2 +1,2 @@ -pinos/daemon/main.c -pinos/daemon/pinos.desktop.in +pipewire/daemon/main.c +pipewire/daemon/pipewire.desktop.in diff --git a/spa/include/spa/meson.build b/spa/include/spa/meson.build index a75801315..1d088687b 100644 --- a/spa/include/spa/meson.build +++ b/spa/include/spa/meson.build @@ -1,5 +1,4 @@ spa_headers = [ - 'alloc-param.h', 'buffer.h', 'clock.h', 'command.h', @@ -17,6 +16,8 @@ spa_headers = [ 'meta.h', 'monitor.h', 'node.h', + 'param.h', + 'param-alloc.h', 'plugin.h', 'pod.h', 'pod-builder.h', diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index 8101efb16..c94227a5d 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -537,7 +537,7 @@ main (int argc, char *argv[]) data.data_loop.remove_source = do_remove_source; data.data_loop.invoke = do_invoke; - if ((str = getenv ("PINOS_DEBUG"))) + if ((str = getenv ("SPA_DEBUG"))) data.log->level = atoi (str); data.support[0].type = SPA_TYPE__TypeMap; diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 211296770..0091a8185 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -632,7 +632,7 @@ main (int argc, char *argv[]) spa_graph_init (&data.graph); - if ((str = getenv ("PINOS_DEBUG"))) + if ((str = getenv ("SPA_DEBUG"))) data.log->level = atoi (str); data.support[0].type = SPA_TYPE__TypeMap; diff --git a/spa/tests/test-perf.c b/spa/tests/test-perf.c index 2bd1dbb9d..99d0e5ccd 100644 --- a/spa/tests/test-perf.c +++ b/spa/tests/test-perf.c @@ -544,7 +544,7 @@ main (int argc, char *argv[]) data.data_loop.remove_source = do_remove_source; data.data_loop.invoke = do_invoke; - if ((str = getenv ("PINOS_DEBUG"))) + if ((str = getenv ("SPA_DEBUG"))) data.log->level = atoi (str); data.mode = argc > 1 ? atoi (argv[1]) : MODE_SYNC_PUSH; diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index c85868131..a053b62ee 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -472,7 +472,7 @@ main (int argc, char *argv[]) data.data_loop.remove_source = do_remove_source; data.data_loop.invoke = do_invoke; - if ((str = getenv ("PINOS_DEBUG"))) + if ((str = getenv ("SPA_DEBUG"))) data.log->level = atoi (str); data.support[0].type = SPA_TYPE__TypeMap; diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index 78ad981fc..846845cfc 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -553,7 +553,7 @@ main (int argc, char *argv[]) data.map = spa_type_map_get_default (); data.log = spa_log_get_default (); - if ((str = getenv ("PINOS_DEBUG"))) + if ((str = getenv ("SPA_DEBUG"))) data.log->level = atoi (str); data.data_loop.size = sizeof (SpaLoop); diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index 887b13f2c..9462f54c1 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -1,4 +1,4 @@ -/* Pinos +/* Simple Plugin API * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index 0a285603f..fc66ca131 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -1,4 +1,4 @@ -/* Pinos +/* Simple Plugin API * Copyright (C) 2016 Wim Taymans * * This library is free software; you can redistribute it and/or