static void on_unit_description_activated (CamUnitManagerWidget *mw, CamUnitDescription *udesc, void *user_data) { state_t *self = user_data; cam_unit_chain_add_unit_by_id (self->chain, cam_unit_description_get_unit_id(udesc)); }
int main(int argc, char **argv) { g_type_init(); CamUnit *resize_unit = NULL; CamUnit *faulty_unit = NULL; CamUnitChain * chain = NULL; const char *input_id = NULL; state_t s; memset (&s, 0, sizeof (s)); sprintf (s.filename, "snapshot-output.ppm"); // create the GLib mainloop s.mainloop = g_main_loop_new (NULL, FALSE); s.lcm = lcm_create ("udpm://?transmit_only=true"); if (!s.lcm) { fprintf (stderr, "Couldn't create LCM\n"); goto failed; } // create the image processing chain chain = cam_unit_chain_new (); // abort if no input unit was specified if (argc < 2) { print_usage_and_inputs (argv[0], chain->manager); goto failed; } input_id = argv[1]; // instantiate the input unit if (! cam_unit_chain_add_unit_by_id (chain, input_id)) { fprintf (stderr, "Oh no! Couldn't create input unit [%s].\n\n", input_id); print_usage_and_inputs (argv[0], chain->manager); goto failed; } // create a unit to convert the input data to 8-bit RGB cam_unit_chain_add_unit_by_id (chain, "convert.to_rgb8"); resize_unit = cam_unit_chain_add_unit_by_id (chain, "filter.ipp.resize"); // cam_unit_set_control_boolean (resize_unit, "aspect-lock", FALSE); cam_unit_set_control_int (resize_unit, "width", 64); // cam_unit_set_control_int (resize_unit, "height", 64); // start the image processing chain faulty_unit = cam_unit_chain_all_units_stream_init (chain); // did everything start up correctly? if (faulty_unit) { fprintf (stderr, "Unit [%s] is not streaming, aborting...\n", cam_unit_get_name (faulty_unit)); goto failed; } // attach the chain to the glib event loop. cam_unit_chain_attach_glib (chain, 1000, NULL); // subscribe to be notified when an image has made its way through the // chain g_signal_connect (G_OBJECT (chain), "frame-ready", G_CALLBACK (on_frame_ready), &s); s.next_publish_utime = _timestamp_now (); // run g_main_loop_run (s.mainloop); // cleanup g_main_loop_unref (s.mainloop); cam_unit_chain_all_units_stream_shutdown (chain); g_object_unref (chain); return 0; failed: g_main_loop_unref (s.mainloop); cam_unit_chain_all_units_stream_shutdown (chain); g_object_unref (chain); return 1; }