int main (int argc, char **argv) { // print warm welcome std::cerr << argv[0] << " v0.1\n"; // initialize libvisual once (this is meant to be called only once, // visual_init() after visual_quit() results in undefined state) visual_log_set_verbosity(VISUAL_LOG_DEBUG); visual_init (&argc, &argv); try { // parse commandline arguments if (_parse_args(argc, argv) != EXIT_SUCCESS) throw std::runtime_error ("Failed to parse arguments"); // create new VisBin for video output VisBin *bin = visual_bin_new(); visual_bin_set_supported_depth(bin, VISUAL_VIDEO_DEPTH_ALL); visual_bin_switch_set_style(bin, VISUAL_SWITCH_STYLE_MORPH); // initialize actor plugin std::cerr << "Loading actor '" << actor_name << "'...\n"; VisActor *actor = visual_actor_new (actor_name.c_str ()); if (!actor) throw std::runtime_error ("Failed to load actor '" + actor_name + "'"); // Set random seed if (have_seed) { VisPluginData *plugin_data = visual_actor_get_plugin(actor); VisRandomContext *r_context = visual_plugin_get_random_context (plugin_data); visual_random_context_set_seed (r_context, seed); seed++; } // initialize input plugin std::cerr << "Loading input '" << input_name << "'...\n"; VisInput *input = visual_input_new(input_name.c_str()); if (!input) { throw std::runtime_error ("Failed to load input '" + input_name + "'"); } // Pick the best display depth int depthflag = visual_actor_get_supported_depth (actor); VisVideoDepth depth; if (depthflag == VISUAL_VIDEO_DEPTH_GL) { depth = visual_video_depth_get_highest (depthflag); } else { depth = visual_video_depth_get_highest_nogl (depthflag); } visual_bin_set_depth (bin, depth); VisVideoAttributeOptions const* vidoptions = visual_actor_get_video_attribute_options(actor); // initialize display SADisplay display (driver_name); // create display display.create(depth, vidoptions, width, height, true); VisVideo *video = display.get_video(); if(!video) throw std::runtime_error("Failed to get VisVideo from display"); // put it all together visual_bin_connect(bin, actor, input); visual_bin_set_video(bin, video); visual_bin_realize(bin); visual_bin_sync(bin, FALSE); visual_bin_depth_changed(bin); // get a queue to handle events VisEventQueue localqueue; // main loop bool running = true; bool visible = true; while (running) { LV::Event ev; // Handle all events display.drain_events(localqueue); LV::EventQueue* pluginqueue = visual_plugin_get_eventqueue(visual_actor_get_plugin (bin->actor)); while (localqueue.poll(ev)) { if(ev.type != VISUAL_EVENT_RESIZE) pluginqueue->add (ev); switch (ev.type) { case VISUAL_EVENT_PARAM: { break; } case VISUAL_EVENT_RESIZE: { display.lock(); width = ev.event.resize.width; height = ev.event.resize.height; display.create(depth, vidoptions, width, height, true); video = display.get_video (); visual_bin_set_video (bin, video); visual_actor_video_negotiate (bin->actor, depth, FALSE, FALSE); display.unlock(); break; } case VISUAL_EVENT_MOUSEMOTION: { break; } case VISUAL_EVENT_MOUSEBUTTONDOWN: { // switch to next actor v_cycleActor(1); v_cycleMorph(); visual_bin_set_morph_by_name(bin, morph_name.c_str()); visual_bin_switch_actor_by_name(bin, actor_name.c_str()); // get new actor actor = visual_bin_get_actor(bin); // handle depth of new actor depthflag = visual_actor_get_supported_depth(actor); if (depthflag == VISUAL_VIDEO_DEPTH_GL) { visual_bin_set_depth(bin, VISUAL_VIDEO_DEPTH_GL); } else { depth = visual_video_depth_get_highest(depthflag); if ((bin->depthflag & depth) > 0) visual_bin_set_depth(bin, depth); else visual_bin_set_depth(bin, visual_video_depth_get_highest_nogl(bin->depthflag)); } bin->depthforcedmain = bin->depth; break; } case VISUAL_EVENT_MOUSEBUTTONUP: { break; } case VISUAL_EVENT_KEYDOWN: { switch(ev.event.keyboard.keysym.sym) { case VKEY_ESCAPE: { running = false; break; } case VKEY_TAB: { break; } default: break; } break; } case VISUAL_EVENT_KEYUP: { break; } case VISUAL_EVENT_QUIT: { running = FALSE; break; } case VISUAL_EVENT_VISIBILITY: { visible = ev.event.visibility.is_visible; break; } default: { break; } } } if (visual_bin_depth_changed(bin)) { display.lock(); display.create(depth, vidoptions, width, height, true); VisVideo *video = display.get_video(); visual_bin_set_video(bin, video); visual_bin_sync(bin, TRUE); display.unlock(); } // Do a run cycle if (!visible) continue; display.lock(); visual_bin_run(bin); display.unlock(); display.update_all(); display.set_fps_limit(framerate); } } catch (std::exception& error) { std::cerr << error.what () << std::endl; } //printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display)); visual_quit (); return EXIT_SUCCESS; }
int bg_lv_load(bg_plugin_handle_t * ret, const char * name, int plugin_flags, const char * window_id) { lv_priv_t * priv; int i; bg_visualization_plugin_t * p; VisVideoAttributeOptions *vidoptions; check_init(); /* Set up callbacks */ p = calloc(1, sizeof(*p)); ret->plugin_nc = (bg_plugin_common_t*)p; ret->plugin = ret->plugin_nc; if(plugin_flags & BG_PLUGIN_VISUALIZE_GL) { p->open_win = open_gl_lv; p->draw_frame = draw_frame_gl_lv; p->show_frame = show_frame_lv; } else { p->open_ov = open_ov_lv; p->draw_frame = draw_frame_ov_lv; } p->update = update_lv; p->close = close_lv; p->set_callbacks = set_callbacks_lv; p->common.get_parameters = get_parameters_lv; p->common.set_parameter = set_parameter_lv; /* Set up private data */ priv = calloc(1, sizeof(*priv)); ret->priv = priv; priv->audio = visual_audio_new(); #if 0 priv->ov_callbacks.data = priv; priv->ov_callbacks.key_callback = key_callback; priv->ov_callbacks.key_release_callback = key_release_callback; priv->ov_callbacks.button_callback = button_callback; priv->ov_callbacks.button_release_callback = button_release_callback; priv->ov_callbacks.motion_callback = motion_callback; #endif /* Remove gmerlin added prefix from the plugin name */ priv->actor = visual_actor_new(name + 7); if(plugin_flags & BG_PLUGIN_VISUALIZE_GL) { priv->win = bg_x11_window_create(window_id); priv->window_callbacks.data = priv; priv->window_callbacks.size_changed = size_changed; priv->window_callbacks.key_callback = key_callback; priv->window_callbacks.key_release_callback = key_release_callback; priv->window_callbacks.button_callback = button_callback; priv->window_callbacks.button_release_callback = button_release_callback; priv->window_callbacks.motion_callback = motion_callback; /* Create an OpenGL context. For this, we need the OpenGL attributes */ vidoptions = visual_actor_get_video_attribute_options(priv->actor); for(i = 0; i < VISUAL_GL_ATTRIBUTE_LAST; i++) { if((vidoptions->gl_attributes[i].mutated) && (bg_attributes[i] >= 0)) { bg_x11_window_set_gl_attribute(priv->win, bg_attributes[i], vidoptions->gl_attributes[i].value); } } /* Set bogus dimensions, will be corrected by the size_callback */ bg_x11_window_set_size(priv->win, 640, 480); bg_x11_window_realize(priv->win); bg_x11_window_start_gl(priv->win); bg_x11_window_set_gl(priv->win); } visual_actor_realize(priv->actor); if(plugin_flags & BG_PLUGIN_VISUALIZE_GL) bg_x11_window_unset_gl(priv->win); priv->parameters = create_parameters(priv->actor, &priv->widgets, &priv->params); priv->video = visual_video_new(); return 1; }
int main (int argc, char **argv) { SADisplay *display; VisVideo *video; VisInput *input; VisActor *actor; VisEventQueue *localqueue; VisVideoAttributeOptions *vidoptions; int running = TRUE; int fullscreen = FALSE; int visible = TRUE; int depth; //visual_mem_alloc_install_vtable (visual_mem_alloc_vtable_profile ()); visual_init (&argc, &argv); display = display_new (sdl_driver_new ()); /* Libvisual stuff */ if (argc > 1) actor = visual_actor_new (argv[1]); else actor = visual_actor_new ("projectM"); if (argc > 3) { depth = visual_video_depth_enum_from_value (atoi (argv[3])); } else depth = visual_video_depth_get_highest (visual_actor_get_supported_depth (actor)); vidoptions = visual_actor_get_video_attribute_options (actor); display_create (display, depth, vidoptions, 480, 360, TRUE); visual_actor_realize (actor); video = display_get_video (display); visual_actor_set_video (actor, video); visual_actor_video_negotiate (actor, 0, FALSE, FALSE); if (argc > 2) input = visual_input_new (argv[2]); else input = visual_input_new ("alsa"); visual_input_realize (input); localqueue = visual_event_queue_new (); while (running) { VisEventQueue *pluginqueue; VisEvent *ev; /* Handle all events */ display_drain_events (display, localqueue); pluginqueue = visual_plugin_get_eventqueue (visual_actor_get_plugin (actor)); while (visual_event_queue_poll_by_reference (localqueue, &ev)) { if (ev->type != VISUAL_EVENT_RESIZE) visual_event_queue_add (pluginqueue, ev); switch (ev->type) { case VISUAL_EVENT_RESIZE: video = display_get_video (display); visual_actor_set_video (actor, video); visual_actor_video_negotiate (actor, depth, FALSE, FALSE); break; case VISUAL_EVENT_MOUSEMOTION: break; case VISUAL_EVENT_MOUSEBUTTONDOWN: break; case VISUAL_EVENT_MOUSEBUTTONUP: break; case VISUAL_EVENT_KEYDOWN: switch (ev->event.keyboard.keysym.sym) { case VKEY_ESCAPE: running = FALSE; break; case VKEY_TAB: fullscreen = !fullscreen; display_set_fullscreen (display, fullscreen, TRUE); /* Resync video */ video = display_get_video (display); visual_actor_set_video (actor, video); visual_actor_video_negotiate (actor, depth, FALSE, FALSE); break; default: printf ("key: %c\n", ev->event.keyboard.keysym.sym); break; } break; case VISUAL_EVENT_KEYUP: break; case VISUAL_EVENT_QUIT: running = FALSE; break; case VISUAL_EVENT_VISIBILITY: visible = ev->event.visibility.is_visible; break; default: break; } } if (visible == FALSE) { visual_input_run (input); visual_time_usleep (10000); continue; } /* Do a run cycle */ visual_input_run (input); display_lock (display); visual_actor_run (actor, input->audio); display_unlock (display); display_update_all (display); display_fps_limit (display, 30); } /* Termination procedure */ display_set_fullscreen (display, FALSE, TRUE); display_close (display); visual_quit (); //visual_mem_alloc_profile (); printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display)); return 0; }
bg_plugin_info_t * bg_lv_get_info(const char * filename) { int i; VisVideoAttributeOptions *vidoptions; bg_x11_window_t * win; bg_plugin_info_t * ret; VisPluginRef * ref; VisList * list; VisActor * actor; VisPluginInfo * info; char * tmp_string; const char * actor_name = NULL; check_init(); list = visual_plugin_get_registry(); /* Find out if there is a plugin matching the filename */ while((actor_name = visual_actor_get_next_by_name(actor_name))) { ref = visual_plugin_find(list, actor_name); if(ref && !strcmp(ref->file, filename)) break; } if(!actor_name) return NULL; actor = visual_actor_new(actor_name); if(!actor) return NULL; ret = calloc(1, sizeof(*ret)); info = visual_plugin_get_info(visual_actor_get_plugin(actor)); ret->name = bg_sprintf("vis_lv_%s", actor_name); ret->long_name = gavl_strdup(info->name); ret->type = BG_PLUGIN_VISUALIZATION; ret->api = BG_PLUGIN_API_LV; ret->description = bg_sprintf(TR("libvisual plugin")); ret->module_filename = gavl_strdup(filename); /* Optional info */ if(info->author && *info->author) { tmp_string = bg_sprintf(TR("\nAuthor: %s"), info->author); ret->description = gavl_strcat(ret->description, tmp_string); free(tmp_string); } if(info->version && *info->version) { tmp_string = bg_sprintf(TR("\nVersion: %s"), info->version); ret->description = gavl_strcat(ret->description, tmp_string); free(tmp_string); } if(info->about && *info->about) { tmp_string = bg_sprintf(TR("\nAbout: %s"), info->about); ret->description = gavl_strcat(ret->description, tmp_string); free(tmp_string); } if(info->help && *info->help) { tmp_string = bg_sprintf(TR("\nHelp: %s"), info->help); ret->description = gavl_strcat(ret->description, tmp_string); free(tmp_string); } if(info->license && *info->license) { tmp_string = bg_sprintf(TR("\nLicense: %s"), info->license); ret->description = gavl_strcat(ret->description, tmp_string); free(tmp_string); } /* Check out if it's an OpenGL plugin */ if(visual_actor_get_supported_depth(actor) & VISUAL_VIDEO_DEPTH_GL) { ret->flags |= BG_PLUGIN_VISUALIZE_GL; win = bg_x11_window_create(NULL); /* Create an OpenGL context. For this, we need the OpenGL attributes */ vidoptions = visual_actor_get_video_attribute_options(actor); for(i = 0; i < VISUAL_GL_ATTRIBUTE_LAST; i++) { if((vidoptions->gl_attributes[i].mutated) && (bg_attributes[i] >= 0)) { bg_x11_window_set_gl_attribute(win, bg_attributes[i], vidoptions->gl_attributes[i].value); } } /* Set bogus dimensions, will be corrected by the size_callback */ bg_x11_window_set_size(win, 640, 480); bg_x11_window_realize(win); if(!bg_x11_window_start_gl(win)) { ret->flags |= BG_PLUGIN_UNSUPPORTED; } else bg_x11_window_set_gl(win); } else { ret->flags |= BG_PLUGIN_VISUALIZE_FRAME; win = NULL; } ret->priority = 1; /* Must realize the actor to get the parameters */ if(!(ret->flags & BG_PLUGIN_UNSUPPORTED)) { visual_actor_realize(actor); ret->parameters = create_parameters(actor, NULL, NULL); visual_object_unref(VISUAL_OBJECT(actor)); } if(win) { bg_x11_window_unset_gl(win); bg_x11_window_stop_gl(win); bg_x11_window_destroy(win); } return ret; }