BufferManagerUnicap::BufferManagerUnicap(Filter const * const _filter, unsigned int _buffers, unsigned int _bufferSize, unicap_handle_t _handle, unicap_format_t _format) throw (std::bad_alloc) : Super(_filter, _buffers, _bufferSize, NULL), handle_(_handle), format_(_format) { // get device parameters const Video::DeviceParameters * devParams = dynamic_cast<DeviceParameters const *>(_filter->parameters()); camParams_ = &devParams->camera; MIRO_LOG_OSTR(LL_NOTICE, "\n camera parameters:\n" << *camParams_); // init callback structure callback_.index = 0; callback_.mutex = new Miro::Mutex(); callback_.condition = new Miro::Condition(*callback_.mutex); callback_.buffer = new unsigned char * [buffers()]; for (unsigned int i=0; i<buffers(); ++i) callback_.buffer[i] = bufferAddr(i); // register callback unicap_register_callback(handle_, UNICAP_EVENT_NEW_FRAME, (unicap_callback_t) newFrameCallback, (void*)&callback_); // Start the capture process on the device if( !SUCCESS( unicap_start_capture( handle_ ) ) ) throw Miro::Exception("DeviceUnicap: Failed to start capture on unicap device"); }
int main (int argc, char *argv[]) { unicap_handle_t handle; unicap_format_t format; /* Initialize */ gtk_init (&argc, &argv); g_thread_init(NULL); gdk_threads_init (); gtk_gl_init (&argc, &argv); init_extensions (); init_gl_resources (); handle = open_device(); set_format( handle ); unicap_get_format( handle, &format ); if( ( format.size.width != 640 ) || ( format.size.height != 480 ) ) { g_warning( "The default .cg file assumes a video format of 640x480 pixels. \nYou need to change the yuv.cg file to match your size.\n" ); } prepare_yuv_buffer(&yuvbuffer, &format); unicap_register_callback( handle, UNICAP_EVENT_NEW_FRAME, (unicap_callback_t)new_frame_cb, NULL ); unicap_start_capture( handle ); /* Gtk window & container */ GtkWindow *window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); glarea = gtk_drawing_area_new (); gtk_widget_set_size_request (GTK_WIDGET (glarea), WINDOW_WIDTH, WINDOW_HEIGHT); g_signal_connect (glarea, "expose-event", G_CALLBACK (on_expose), NULL); g_signal_connect (glarea, "configure-event", G_CALLBACK (on_configure), NULL); g_signal_connect (glarea, "map-event", G_CALLBACK (on_mapped), NULL); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); GdkGLConfig *gl_config; gl_config = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE); if (gl_config == NULL) g_critical ("Failed to setup a double-buffered RGB visual"); if (! gtk_widget_set_gl_capability (GTK_WIDGET (glarea), gl_config, NULL, TRUE, GDK_GL_RGBA_TYPE)) g_critical ("Failed to add gl capability"); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (glarea)); gtk_widget_show_all (GTK_WIDGET (window)); /* Main loop */ gtk_main (); return 0; }
//-------------------------------------------------------------------- void ofUCUtils::start_capture() { if(!deviceReady) return; int status = STATUS_SUCCESS; if (!SUCCESS ( status = unicap_register_callback (handle, UNICAP_EVENT_NEW_FRAME, (unicap_callback_t) new_frame_cb, (void *) this) ) ) ofLog(OF_ERROR,"ofUCUtils: error registering callback"); if (!SUCCESS ( status = unicap_start_capture (handle) ) ) ofLog(OF_ERROR,"ofUCUtils: error starting capture: %i,%i",status,STATUS_INVALID_HANDLE); }
int capture(unicap_handle_t handle) { unicap_format_t format = getformat(handle); volatile int framecounter = 1; int imagewidth; int imageheight; imagewidth = format.size.width; imageheight = format.size.height; nrOfPixel = imagewidth * imageheight; unicap_register_callback(handle, UNICAP_EVENT_NEW_FRAME, (unicap_callback_t)new_frame_cb, (void*)&framecounter); unicap_start_capture(handle); while (framecounter > 0) { usleep(100000); } unicap_stop_capture(handle); return 0; }