summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2016-11-24 17:40:26 +0100
committerWim Taymans <wtaymans@redhat.com>2016-11-24 17:40:26 +0100
commit4e94743906c9721f2696b34d6a91fa329887b7d9 (patch)
tree05bd0d6b4f18ccafce93eb8d7416034b4de929e9
parent27bba6f587a6a276f9052fe92feb6fa8595f33a4 (diff)
Use pinos loop for mainloop
Remove more glib stuff
-rw-r--r--meson.build1
-rw-r--r--pinos/client/format.c45
-rw-r--r--pinos/client/format.h37
-rw-r--r--pinos/client/meson.build28
-rw-r--r--pinos/client/properties.c2
-rw-r--r--pinos/client/stream.c37
-rw-r--r--pinos/daemon/meson.build2
-rw-r--r--pinos/modules/meson.build4
-rw-r--r--pinos/modules/spa/meson.build2
-rw-r--r--pinos/server/main-loop.c144
-rw-r--r--pinos/server/main-loop.h3
-rw-r--r--pinos/tools/meson.build2
12 files changed, 59 insertions, 248 deletions
diff --git a/meson.build b/meson.build
index 6fdb3c71..6dabc1b8 100644
--- a/meson.build
+++ b/meson.build
@@ -126,6 +126,7 @@ gio_dep = [dependency('gio-2.0'), dependency('gio-unix-2.0')]
mathlib = cc.find_library('m', required : false)
rt_lib = cc.find_library('rt', required : false) # clock_gettime
dl_lib = cc.find_library('dl', required : false)
+pthread_lib = cc.find_library('pthread', required : true)
gst_dep = [dependency('gstreamer-1.0'),
dependency('gstreamer-plugins-base-1.0'),
dependency('gstreamer-video-1.0'),
diff --git a/pinos/client/format.c b/pinos/client/format.c
deleted file mode 100644
index 6c3790d2..00000000
--- a/pinos/client/format.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Pinos
- * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
- *
- * 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 <pinos/client/pinos.h>
-#include <pinos/client/format.h>
-#include <pinos/client/serialize.h>
-
-static SpaFormat *
-format_copy (SpaFormat *format)
-{
- void *p;
- size_t size;
-
- if (format == NULL)
- return NULL;
-
- size = pinos_serialize_format_get_size (format);
- p = malloc (size);
- return pinos_serialize_format_copy_into (p, format);
-}
-
-static void
-format_free (SpaFormat *format)
-{
- g_free (format);
-}
-
-G_DEFINE_BOXED_TYPE (SpaFormat, spa_format,
- format_copy, format_free);
diff --git a/pinos/client/format.h b/pinos/client/format.h
deleted file mode 100644
index 3a7909d5..00000000
--- a/pinos/client/format.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Pinos
- * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
- *
- * 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_FORMAT_H__
-#define __PINOS_FORMAT_H__
-
-#include <glib-object.h>
-
-#include <spa/include/spa/format.h>
-
-G_BEGIN_DECLS
-
-#define SPA_TYPE_FORMAT (spa_format_get_type())
-
-GType spa_format_get_type (void);
-
-
-
-G_END_DECLS
-
-#endif /* __PINOS_FORMAT_H__ */
diff --git a/pinos/client/meson.build b/pinos/client/meson.build
index 14de25c1..2bafd6c7 100644
--- a/pinos/client/meson.build
+++ b/pinos/client/meson.build
@@ -1,7 +1,6 @@
pinos_headers = [
'array.h',
'context.h',
- 'format.h',
'introspect.h',
'log.h',
'loop.h',
@@ -21,7 +20,6 @@ pinos_headers = [
pinos_sources = [
'connection.c',
'context.c',
- 'format.c',
'introspect.c',
'log.c',
'loop.c',
@@ -36,28 +34,10 @@ pinos_sources = [
'thread-mainloop.c',
'transport.c',
'utils.c',
- gdbus_target,
]
install_headers(pinos_headers, subdir : 'pinos/client')
-mkenums = find_program('build_mkenum.py')
-glib_mkenums = find_program('glib-mkenums')
-
-enumtypes_h = custom_target('enumtypes_h',
- output : 'enumtypes.h',
- input : pinos_headers,
- install : true,
- install_dir : 'include/pinos/client',
- command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
-
-enumtypes_c = custom_target('enumtypes_c',
- output : 'enumtypes.c',
- input : pinos_headers,
- depends : [enumtypes_h],
- command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
-
-
libpinos_c_args = [
'-DHAVE_CONFIG_H',
'-D_GNU_SOURCE',
@@ -65,8 +45,6 @@ libpinos_c_args = [
]
-pinos_gen_sources = [enumtypes_h]
-
libpinos = shared_library('pinos', pinos_sources,
version : libversion,
soversion : soversion,
@@ -74,12 +52,10 @@ libpinos = shared_library('pinos', pinos_sources,
include_directories : [configinc, spa_inc],
link_with : spalib,
install : true,
- dependencies : [gobject_dep, gmodule_dep, glib_dep, gio_dep, mathlib],
+ dependencies : [glib_dep, gio_dep, mathlib, pthread_lib],
)
pinos_dep = declare_dependency(link_with : libpinos,
include_directories : [configinc, spa_inc],
- dependencies : [glib_dep, gobject_dep, gmodule_dep],
- # Everything that uses libpinos needs this built to compile
- sources : pinos_gen_sources,
+ dependencies : [glib_dep, pthread_lib],
)
diff --git a/pinos/client/properties.c b/pinos/client/properties.c
index 852107b0..0b7cd246 100644
--- a/pinos/client/properties.c
+++ b/pinos/client/properties.c
@@ -17,7 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
-#include <glib-object.h>
+#include <glib.h>
#include "pinos/client/pinos.h"
#include "pinos/client/properties.h"
diff --git a/pinos/client/stream.c b/pinos/client/stream.c
index 4e8663ac..73584b00 100644
--- a/pinos/client/stream.c
+++ b/pinos/client/stream.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <sys/mman.h>
#include <errno.h>
+#include <time.h>
#include "spa/lib/debug.h"
@@ -30,7 +31,6 @@
#include "pinos/client/connection.h"
#include "pinos/client/context.h"
#include "pinos/client/stream.h"
-#include "pinos/client/format.h"
#include "pinos/client/serialize.h"
#include "pinos/client/transport.h"
@@ -431,7 +431,7 @@ handle_rtnode_event (PinosStream *stream,
break;
if ((bid = find_buffer (stream, p->buffer_id))) {
- bid->used = FALSE;
+ bid->used = false;
pinos_signal_emit (&stream->new_buffer, stream, p->buffer_id);
}
break;
@@ -489,7 +489,7 @@ on_rtsocket_condition (SpaSource *source,
}
static void
-handle_socket (PinosStream *stream, gint rtfd)
+handle_socket (PinosStream *stream, int rtfd)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
struct timespec interval;
@@ -546,7 +546,7 @@ handle_node_event (PinosStream *stream,
}
}
-static gboolean
+static bool
handle_node_command (PinosStream *stream,
uint32_t seq,
SpaNodeCommand *command)
@@ -600,7 +600,7 @@ handle_node_command (PinosStream *stream,
break;
}
}
- return TRUE;
+ return true;
}
static SpaResult
@@ -658,7 +658,7 @@ stream_dispatch_func (void *object,
case PINOS_MESSAGE_SET_FORMAT:
{
PinosMessageSetFormat *p = message;
- gpointer mem;
+ void *mem;
if (impl->format)
free (impl->format);
@@ -736,7 +736,8 @@ stream_dispatch_func (void *object,
for (i = 0; i < b->n_datas; i++)
size += sizeof (SpaData);
- b = bid->buf = g_memdup (bid->buf_ptr, size);
+ b = bid->buf = malloc (size);
+ memcpy (b, bid->buf_ptr, size);
if (b->metas)
b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
@@ -750,7 +751,7 @@ stream_dispatch_func (void *object,
if (bid->id != len) {
pinos_log_warn ("unexpected id %u found, expected %u", bid->id, len);
- impl->in_order = FALSE;
+ impl->in_order = false;
}
pinos_log_debug ("add buffer %d %d %zd", mid->id, bid->id, p->buffers[i].offset);
@@ -858,13 +859,13 @@ stream_dispatch_func (void *object,
* signal and use pinos_stream_capture_buffer() to get the latest metadata and
* data.
*
- * Returns: %TRUE on success.
+ * Returns: %true on success.
*/
bool
pinos_stream_connect (PinosStream *stream,
PinosDirection direction,
PinosStreamMode mode,
- const gchar *port_path,
+ const char *port_path,
PinosStreamFlags flags,
unsigned int n_possible_formats,
SpaFormat **possible_formats)
@@ -928,7 +929,7 @@ pinos_stream_connect (PinosStream *stream,
* When @res indicates success, @params contain the parameters for the
* allocation state.
*
- * Returns: %TRUE on success
+ * Returns: %true on success
*/
bool
pinos_stream_finish_format (PinosStream *stream,
@@ -969,7 +970,7 @@ pinos_stream_finish_format (PinosStream *stream,
* Start capturing from @stream.
*
*
- * Returns: %TRUE on success.
+ * Returns: %true on success.
*/
bool
pinos_stream_start (PinosStream *stream)
@@ -983,7 +984,7 @@ pinos_stream_start (PinosStream *stream)
*
* Stop capturing from @stream.
*
- * Returns: %TRUE on success.
+ * Returns: %true on success.
*/
bool
pinos_stream_stop (PinosStream *stream)
@@ -997,7 +998,7 @@ pinos_stream_stop (PinosStream *stream)
*
* Disconnect @stream.
*
- * Returns: %TRUE on success
+ * Returns: %true on success
*/
bool
pinos_stream_disconnect (PinosStream *stream)
@@ -1056,7 +1057,7 @@ pinos_stream_get_empty_buffer (PinosStream *stream)
*
* Recycle the buffer with @id.
*
- * Returns: %TRUE on success.
+ * Returns: %true on success.
*/
bool
pinos_stream_recycle_buffer (PinosStream *stream,
@@ -1110,7 +1111,7 @@ pinos_stream_peek_buffer (PinosStream *stream,
* For provider streams, this function should be called whenever there is a new frame
* available.
*
- * Returns: %TRUE when @id was handled
+ * Returns: %true when @id was handled
*/
bool
pinos_stream_send_buffer (PinosStream *stream,
@@ -1118,12 +1119,12 @@ pinos_stream_send_buffer (PinosStream *stream,
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
BufferId *bid;
- guint i;
+ unsigned int i;
if ((bid = find_buffer (stream, id))) {
uint8_t cmd = PINOS_TRANSPORT_CMD_HAVE_DATA;
- bid->used = TRUE;
+ bid->used = true;
for (i = 0; i < bid->buf->n_datas; i++) {
bid->datas[i].size = bid->buf->datas[i].size;
}
diff --git a/pinos/daemon/meson.build b/pinos/daemon/meson.build
index b008b320..37877523 100644
--- a/pinos/daemon/meson.build
+++ b/pinos/daemon/meson.build
@@ -26,5 +26,5 @@ executable('pinos',
install: true,
c_args : pinos_c_args,
include_directories : [configinc, spa_inc],
- dependencies : [glib_dep, gobject_dep, gmodule_dep, pinos_dep, pinoscore_dep],
+ dependencies : [pinos_dep, pinoscore_dep],
)
diff --git a/pinos/modules/meson.build b/pinos/modules/meson.build
index 59c1e91f..16c65e4b 100644
--- a/pinos/modules/meson.build
+++ b/pinos/modules/meson.build
@@ -15,7 +15,7 @@ pinos_module_autolink = shared_library('pinos-module-autolink', [ 'module-autoli
dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep],
)
-pinos_module_protocol_dbus = shared_library('pinos-module-protocol-dbus', [ 'module-protocol-dbus.c' ],
+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, pinosinc, spa_inc],
link_with : spalib,
@@ -30,7 +30,7 @@ pinos_module_protocol_native = shared_library('pinos-module-protocol-native', [
link_with : spalib,
install : true,
install_dir : '@0@/pinos-0.1'.format(get_option('libdir')),
- dependencies : [gobject_dep, gmodule_dep, glib_dep, gio_dep, mathlib, dl_lib, pinos_dep, pinoscore_dep],
+ 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' ],
diff --git a/pinos/modules/spa/meson.build b/pinos/modules/spa/meson.build
index 009242bd..170e6196 100644
--- a/pinos/modules/spa/meson.build
+++ b/pinos/modules/spa/meson.build
@@ -20,5 +20,5 @@ pinos_module_spa = shared_library('pinos-module-spa', pinos_module_spa_sources,
link_with : spalib,
install : true,
install_dir : '@0@/pinos-0.1'.format(get_option('libdir')),
- dependencies : [gobject_dep, gmodule_dep, glib_dep, gio_dep, mathlib, dl_lib, pinos_dep, pinoscore_dep],
+ dependencies : [mathlib, dl_lib, pinos_dep, pinoscore_dep],
)
diff --git a/pinos/server/main-loop.c b/pinos/server/main-loop.c
index 95789e6a..16c97a62 100644
--- a/pinos/server/main-loop.c
+++ b/pinos/server/main-loop.c
@@ -46,115 +46,23 @@ typedef struct
{
PinosMainLoop this;
- PinosLoop *loop;
-
- GMainContext *context;
- GMainLoop *main_loop;
+ bool running;
+ SpaSource *wakeup;
uint32_t counter;
SpaList work_list;
SpaList free_list;
-
- gulong work_id;
} PinosMainLoopImpl;
-typedef struct {
- PinosMainLoopImpl *impl;
- SpaSource *source;
- guint id;
-} LoopData;
-
-static bool
-poll_event (GIOChannel *source,
- GIOCondition condition,
- void *user_data)
-{
- LoopData *data = user_data;
- SpaSource *s = data->source;
-
- s->rmask = 0;
- if (condition & G_IO_IN)
- s->rmask |= SPA_IO_IN;
- if (condition & G_IO_OUT)
- s->rmask |= SPA_IO_OUT;
- if (condition & G_IO_ERR)
- s->rmask |= SPA_IO_ERR;
- if (condition & G_IO_HUP)
- s->rmask |= SPA_IO_HUP;
- s->func (s);
-
- return TRUE;
-}
-
-static SpaResult
-do_add_source (SpaLoop *loop,
- SpaSource *source)
-{
- PinosMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosMainLoopImpl, loop);
- GIOChannel *channel;
- GSource *s;
- LoopData *data;
- GIOCondition cond;
-
- channel = g_io_channel_unix_new (source->fd);
-
- cond = 0;
- if (source->mask & SPA_IO_IN)
- cond |= G_IO_IN;
- if (source->mask & SPA_IO_OUT)
- cond |= G_IO_OUT;
- if (source->mask & SPA_IO_ERR)
- cond |= G_IO_ERR;
- if (source->mask & SPA_IO_HUP)
- cond |= G_IO_HUP;
-
- s = g_io_create_watch (channel, cond);
- g_io_channel_unref (channel);
-
- data = g_new0 (LoopData, 1);
- data->impl = impl;
- data->source = source;
-
- g_source_set_callback (s, (GSourceFunc) poll_event, data, g_free);
- data->id = g_source_attach (s, g_main_context_get_thread_default ());
- g_source_unref (s);
-
- source->loop_private = data;
- source->loop = loop;
-
- pinos_log_debug ("added main poll %d", data->id);
-
- return SPA_RESULT_OK;
-}
-
-static SpaResult
-do_update_source (SpaSource *source)
-{
- LoopData *data = source->loop_private;
- pinos_log_debug ("update main poll %d", data->id);
- return SPA_RESULT_OK;
-}
-
static void
-do_remove_source (SpaSource *source)
-{
- GSource *gsource;
- LoopData *data = source->loop_private;
-
- pinos_log_debug ("remove main poll %d", data->id);
- gsource = g_main_context_find_source_by_id (g_main_context_get_thread_default (), data->id);
- g_source_destroy (gsource);
-}
-
-static bool
-process_work_queue (PinosMainLoop *this)
+process_work_queue (SpaSource *source,
+ void *data)
{
- PinosMainLoopImpl *impl = SPA_CONTAINER_OF (this, PinosMainLoopImpl, this);
+ PinosMainLoopImpl *impl = data;
+ PinosMainLoop *this = &impl->this;
WorkItem *item, *tmp;
- impl->work_id = 0;
-
spa_list_for_each_safe (item, tmp, &impl->work_list, link) {
if (item->seq != SPA_ID_INVALID)
continue;
@@ -167,7 +75,6 @@ process_work_queue (PinosMainLoop *this)
}
spa_list_insert (impl->free_list.prev, &item->link);
}
- return false;
}
static uint32_t
@@ -204,8 +111,8 @@ do_add_work (PinosMainLoop *loop,
}
spa_list_insert (impl->work_list.prev, &item->link);
- if (impl->work_id == 0 && have_work)
- impl->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
+ if (have_work)
+ pinos_loop_signal_event (impl->this.loop, impl->wakeup);
return item->id;
}
@@ -237,8 +144,8 @@ main_loop_defer_cancel (PinosMainLoop *loop,
have_work = true;
}
}
- if (impl->work_id == 0 && have_work)
- impl->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
+ if (have_work)
+ pinos_loop_signal_event (impl->this.loop, impl->wakeup);
}
static bool
@@ -259,11 +166,11 @@ main_loop_defer_complete (PinosMainLoop *loop,
have_work = TRUE;
}
}
- if (!have_work)
+ if (!have_work) {
pinos_log_debug ("main-loop %p: no defered %d found for object %p", loop, seq, obj);
-
- if (impl->work_id == 0 && have_work)
- impl->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
+ } else {
+ pinos_loop_signal_event (impl->this.loop, impl->wakeup);
+ }
return have_work;
}
@@ -273,16 +180,21 @@ main_loop_quit (PinosMainLoop *loop)
{
PinosMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosMainLoopImpl, this);
pinos_log_debug ("main-loop %p: quit", impl);
- g_main_loop_quit (impl->main_loop);
+ impl->running = false;
}
static void
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);
- g_main_loop_run (impl->main_loop);
+ while (impl->running) {
+ pinos_loop_iterate (loop->loop, -1);
+ }
pinos_loop_leave (loop->loop);
}
@@ -304,12 +216,12 @@ pinos_main_loop_new (void)
this = &impl->this;
this->loop = pinos_loop_new ();
- this->loop->loop->add_source = do_add_source;
- this->loop->loop->update_source = do_update_source;
- this->loop->loop->remove_source = do_remove_source;
- impl->context = g_main_context_default ();
- impl->main_loop = g_main_loop_new (impl->context, false);
+ pinos_signal_init (&this->destroy_signal);
+
+ impl->wakeup = pinos_loop_add_event (this->loop,
+ process_work_queue,
+ impl);
this->run = main_loop_run;
this->quit = main_loop_quit;
@@ -330,9 +242,9 @@ pinos_main_loop_destroy (PinosMainLoop *loop)
WorkItem *item, *tmp;
pinos_log_debug ("main-loop %p: destroy", impl);
+ pinos_signal_emit (&loop->destroy_signal, loop);
- g_main_loop_unref (impl->main_loop);
-
+ pinos_loop_destroy_source (loop->loop, impl->wakeup);
pinos_loop_destroy (loop->loop);
spa_list_for_each_safe (item, tmp, &impl->free_list, link)
diff --git a/pinos/server/main-loop.h b/pinos/server/main-loop.h
index f73f6633..fe14e372 100644
--- a/pinos/server/main-loop.h
+++ b/pinos/server/main-loop.h
@@ -42,6 +42,9 @@ typedef void (*PinosDeferFunc) (void *obj,
struct _PinosMainLoop {
PinosLoop *loop;
+ PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
+ PinosMainLoop *loop));
+
void (*run) (PinosMainLoop *loop);
void (*quit) (PinosMainLoop *loop);
diff --git a/pinos/tools/meson.build b/pinos/tools/meson.build
index eed75e88..2588207e 100644
--- a/pinos/tools/meson.build
+++ b/pinos/tools/meson.build
@@ -1,5 +1,5 @@
executable('pinos-monitor',
'pinos-monitor.c',
install: true,
- dependencies : [glib_dep, gobject_dep, gmodule_dep, pinos_dep],
+ dependencies : [pinos_dep],
)