Re: Problem with dbus in custom application based on Cheese sourcecode



Jostein Austvik Jacobsen schrieb:
> Hi
> 
> I'm trying to modify Cheese for a webcam capture application of my own.
> I simply need to fetch images from a webcam at the highest possible rate
> for further processing in my own program (embedded, no GUI), and Cheese
> seems compatible with a wide range of cameras and has well-written code.
> 
If you don't need to UI, why don'T us sue gstreamer directly. Either with an own
pipeline, or have a look at camerabin element, that just landed in gst-plugins-bad.

Stefan

>
> From how I understand the code, I will want to connect to the GstElement
> webcam_source_bin and write my own GStreamer sink if I want access to
> the webcam... Unfortunately I'm new to GLib, GObjects and GStreamer, but
> I've been reading up on it for a couple of days now and have
> successfully modified and compiled Cheese (If it still can be called
> that) without warnings, errors or any GUI dependencies (GTK, GDK, etc.).
> However, it won't execute as I had hoped. I have further removed as much
> as possible of the code, includes and linked libraries to narrow down
> the possible sources of error without changing the error I get.
> Compiling and running Cheese without modification works flawlessly.
> 
> To reproduce the error, I compile my modified cheese.c with:
> 
> gcc -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
> -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -g -Wall -c -o
> cheese.o cheese.c
> gcc -g -O2 -Wall -o cheese cheese.o -pthread -ldbus-glib-1
> -lgstinterfaces-0.10
> 
> And this is my current cheese.c:
> 
> ---------- cheese.c ----------
> #include <dbus/dbus-glib-bindings.h>
> #include <stdio.h>
> #include <glib/gi18n.h>
> 
> G_BEGIN_DECLS
> 
> typedef struct {
>   GObjectClass parent_class;
>   DBusGConnection *connection;
> } CheeseDbusClass;
> 
> typedef struct _CheeseDbus {
>   GObject parent;
> } CheeseDbus;
> 
> #define CHEESE_TYPE_DBUS (cheese_dbus_get_type ())
> #define CHEESE_DBUS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),
> CHEESE_TYPE_DBUS, CheeseDbusClass))
> 
> GType       cheese_dbus_get_type (void);
> CheeseDbus *cheese_dbus_new (void);
> 
> void     cheese_dbus_set_window (gpointer);
> gboolean cheese_dbus_notify (void);
> 
> G_END_DECLS
> 
> G_BEGIN_DECLS
> 
> #define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
> 
> extern void dbus_glib_marshal_cheese_dbus_BOOLEAN__POINTER (GClosure    
> *closure,
>                                                             GValue      
> *return_value,
>                                                            
> guint         n_param_values,
>                                                             const GValue
> *param_values,
>                                                            
> gpointer      invocation_hint,
>                                                            
> gpointer      marshal_data);
> void
> dbus_glib_marshal_cheese_dbus_BOOLEAN__POINTER (GClosure     *closure,
>                                                 GValue      
> *return_value G_GNUC_UNUSED,
>                                                 guint        
> n_param_values,
>                                                 const GValue *param_values,
>                                                 gpointer     
> invocation_hint G_GNUC_UNUSED,
>                                                 gpointer      marshal_data)
> {
>   typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer     data1,
>                                                      gpointer     arg_1,
>                                                      gpointer     data2);
>   register GMarshalFunc_BOOLEAN__POINTER callback;
>   register GCClosure *cc = (GCClosure*) closure;
>   register gpointer data1, data2;
>   gboolean v_return;
> 
>   g_return_if_fail (return_value != NULL);
>   g_return_if_fail (n_param_values == 2);
> 
>   if (G_CCLOSURE_SWAP_DATA (closure))
>     {
>       data1 = closure->data;
>       data2 = g_value_peek_pointer (param_values + 0);
>     }
>   else
>     {
>       data1 = g_value_peek_pointer (param_values + 0);
>       data2 = closure->data;
>     }
>   callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ?
> marshal_data : cc->callback);
> 
>   v_return = callback (data1,
>                        g_marshal_value_peek_pointer (param_values + 1),
>                        data2);
> 
>   g_value_set_boolean (return_value, v_return);
> }
> 
> G_END_DECLS
> 
> static const DBusGMethodInfo dbus_glib_cheese_dbus_methods[] = {
>   { (GCallback) cheese_dbus_notify,
> dbus_glib_marshal_cheese_dbus_BOOLEAN__POINTER, 0 },
> };
> 
> const DBusGObjectInfo dbus_glib_cheese_dbus_object_info = {
>   0,
>   dbus_glib_cheese_dbus_methods,
>   1,
> "org.gnome.Cheese\0notify\0S\0\0\0",
> "\0",
> "\0"
> };
> 
> gpointer window_pointer;
> 
> G_DEFINE_TYPE (CheeseDbus, cheese_dbus, G_TYPE_OBJECT);
> 
> void cheese_dbus_set_window (gpointer data) {
>   if (data != NULL)
>     window_pointer = data;
> }
> 
> gboolean cheese_dbus_notify () {
>   return TRUE;
> }
> 
> void cheese_dbus_class_init (CheeseDbusClass *klass) {
>   GError *error = NULL;
> 
>   /* Init the DBus connection, per-klass */
>   klass->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
>   if (klass->connection == NULL) {
>     g_warning ("Unable to connect to dbus: %s", error->message);
>     g_error_free (error);
>     return;
>   }
> 
>   dbus_g_object_type_install_info (CHEESE_TYPE_DBUS,
> &dbus_glib_cheese_dbus_object_info);
> }
> 
> void cheese_dbus_init (CheeseDbus *server) {
>   CheeseDbusClass *klass = CHEESE_DBUS_GET_CLASS (server);
> 
>   /* Register DBUS path */
>   dbus_g_connection_register_g_object (klass->connection,
> "/org/gnome/cheese", G_OBJECT (server));
> }
> 
> CheeseDbus* cheese_dbus_new () {
>   CheeseDbus      *server;
>   GError          *error = NULL;
>   DBusGProxy      *proxy;
>   guint            request_ret;
>   CheeseDbusClass *klass;
> 
>   server = g_object_new (CHEESE_TYPE_DBUS, NULL);
> 
>   klass = CHEESE_DBUS_GET_CLASS (server);
> 
>   /* Register the service name, the constant here are defined in
> dbus-glib-bindings.h */
>   proxy = dbus_g_proxy_new_for_name (klass->connection,
> DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
> 
>   if (!org_freedesktop_DBus_request_name (proxy, "org.gnome.Cheese", 0,
> &request_ret, &error)) {
>     g_warning ("Unable to register service: %s", error->message);
>     g_error_free (error);
>   }
> 
>   /* check if there is already a instance running -> exit*/
>   if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS || request_ret ==
> DBUS_REQUEST_NAME_REPLY_IN_QUEUE) {
>     g_warning ("Another instance of cheese is already running!");
>    
>     /* notify the other instance of cheese*/
>     proxy = dbus_g_proxy_new_for_name (klass->connection,
> "org.gnome.Cheese", "/org/gnome/cheese", "org.gnome.Cheese");
>    
>     if (!dbus_g_proxy_call (proxy, "notify", &error, G_TYPE_INVALID,
> G_TYPE_INVALID)) {
>       /* Method failed, the GError is set, let's warn everyone */
>       g_warning ("Notifying the other cheese instance failed: %s",
> error->message);
>       g_error_free (error);
>     }
>    
>     g_object_unref (server);
>     server = NULL;
>   }
>  
>   g_object_unref (proxy);
>  
>   return server;
> }
> 
> int main (int argc, char **argv) {
>   CheeseDbus *dbus_server;
>  
>   g_thread_init (NULL);
>  
>   dbus_server = cheese_dbus_new ();
>   if (dbus_server == NULL) {
>     printf("failed\n");
>     return -1;
>   }
>  
>   printf("success\n");
>   return 0;
> }
> --------------------
> 
> 
> The output I get is this:
> 
> $ ./cheese
> 
> (process:22856): GLib-GObject-CRITICAL **:
> /build/buildd/glib2.0-2.18.2/gobject/gtype.c:2458: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:22856): GLib-CRITICAL **: g_once_init_leave: assertion
> `initialization_value != 0' failed
> 
> (process:22856): GLib-GObject-CRITICAL **: g_object_new: assertion
> `G_TYPE_IS_OBJECT (object_type)' failed
> 
> 
> 
> Using gdb, I find that the error lies on line 131 (originally on line 94
> in cheese-dbus.c) which is the one that says "server = g_object_new
> (CHEESE_TYPE_DBUS, NULL);"
> 
> 
> Any idea what the problem is?
> 
> Regards
> Jostein A. Jacobsen
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Cheese-list mailing list
> Cheese-list gnome org
> http://mail.gnome.org/mailman/listinfo/cheese-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]