Use pinos loop for mainloop

Remove more glib stuff
This commit is contained in:
Wim Taymans 2016-11-24 17:40:26 +01:00
parent 27bba6f587
commit 4e94743906
12 changed files with 59 additions and 248 deletions

View file

@ -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'),

View file

@ -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);

View file

@ -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__ */

View file

@ -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],
)

View file

@ -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"

View file

@ -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;
}

View file

@ -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],
)

View file

@ -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' ],

View file

@ -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],
)

View file

@ -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)
process_work_queue (SpaSource *source,
void *data)
{
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)
{
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)

View file

@ -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);

View file

@ -1,5 +1,5 @@
executable('pinos-monitor',
'pinos-monitor.c',
install: true,
dependencies : [glib_dep, gobject_dep, gmodule_dep, pinos_dep],
dependencies : [pinos_dep],
)