Beispiel #1
0
int main (int argc, char** argv)
{
    LV::System::init (argc, argv);
    visual_log_set_verbosity (VISUAL_LOG_ERROR);

    int exit_code = EXIT_SUCCESS;

    try {
        if (SDL_Init (SDL_INIT_VIDEO)) {
            throw std::runtime_error { std::string {"Failed to initialize SDL: "} + SDL_GetError () };
        }
        std::atexit (SDL_Quit);

        SimpleExample example;
        example.run ();
    }
    catch (std::exception& error) {
        std::cerr << "Error! " << error.what () << std::endl;
        exit_code = EXIT_FAILURE;
    }
    catch (...) {
        std::cerr << "Unknown error occurred\n";
        exit_code = EXIT_FAILURE;
    }

    LV::System::destroy ();

    return exit_code;
}
Beispiel #2
0
/** LibVisual.init() */
JNIEXPORT jboolean JNICALL Java_org_libvisual_android_LibVisual_init(JNIEnv * env, jobject  obj)
{
    if(visual_is_initialized())
                return JNI_TRUE;

    LOGI("LibVisual.init(): %s", visual_get_version());

#ifndef NDEBUG
    /* endless loop to wait for debugger to attach */
    int foo = 1;
    while(foo);
#endif
        
    /* register VisLog handler to make it log to android logcat */
    visual_log_set_handler(VISUAL_LOG_DEBUG, _log_handler, NULL);
    visual_log_set_handler(VISUAL_LOG_INFO, _log_handler, NULL);
    visual_log_set_handler(VISUAL_LOG_WARNING, _log_handler, NULL);
    visual_log_set_handler(VISUAL_LOG_CRITICAL, _log_handler, NULL);
    visual_log_set_handler(VISUAL_LOG_ERROR, _log_handler, NULL);
    visual_log_set_verbosity(VISUAL_LOG_DEBUG);


    /* initialize libvisual */
    char *v[] = { "lvclient", NULL };
    char **argv = v;
    int argc=1;
    visual_init(&argc,  &argv);

    /* add our plugin search path */
    visual_plugin_registry_add_path("/data/data/org.libvisual.android/lib");

        
    return JNI_TRUE;
}
Beispiel #3
0
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;
}
Beispiel #4
0
int main (int argc, char **argv)
{
    try {
        // print warm welcome
        std::cerr << visual_truncate_path (argv[0], 1) << " - "
                  << PACKAGE_STRING
                  << " (" << LV_REVISION << ") commandline tool - "
                  << PACKAGE_URL << "\n";

        // setup signal handlers
        setup_signal_handlers ();

        // default loglevel
        visual_log_set_verbosity (VISUAL_LOG_ERROR);

        // initialize LV
        Libvisual main {argc, argv};

        // parse commandline arguments
        int parse_result = parse_args (argc, argv);
        if (parse_result < 0) {
            throw std::runtime_error ("Failed to parse arguments");
        }
        if (parse_result > 0) {
            return EXIT_SUCCESS;
        }

        // Set system-wide random seed
        if (have_seed) {
            LV::System::instance()->set_rng_seed (seed);
        }

        // create new VisBin for video output
        LV::Bin bin;
        bin.set_supported_depth(VISUAL_VIDEO_DEPTH_ALL);
        bin.use_morph(false);

        // Let the bin manage plugins. There's a bug otherwise.
        if (!bin.connect(actor_name, input_name)) {
            throw std::runtime_error ("Failed to start pipeline with actor '" + actor_name + "' and input '" + input_name + "'");
        }

        auto actor = bin.get_actor();

        // Select output colour depth

        VisVideoDepth depth;
        int depthflag = actor->get_supported_depths ();

        // Pick the best display depth directly supported by non GL actor
        if(depthflag != VISUAL_VIDEO_DEPTH_GL)
        {
            if (color_depth == 0)
            {
                depth = visual_video_depth_get_highest_nogl (depthflag);
            }
            // Pick user chosen colordepth
            else
            {
                depth = visual_video_depth_from_bpp (color_depth);
            }
        }
        /* GL actor */
        else
        {
            depth = visual_video_depth_get_highest (depthflag);
        }

        bin.set_depth (depth);

        auto vidoptions = actor->get_video_attribute_options ();

        // initialize display
        Display display (driver_name);

        // create display
        auto video = display.create(depth, vidoptions, width, height, true);
        if(!video) {
            throw std::runtime_error("Failed to setup display for rendering");
        }

        // Set the display title
        display.set_title(_("lv-tool"));

        // put it all together
        bin.set_video(video);
        bin.realize();
        bin.sync(false);
        bin.depth_changed();

        bin.set_morph(morph_name);

        // get a queue to handle events
        LV::EventQueue localqueue;

        // rendering statistics
        uint64_t frames_drawn = 0;

        // frame rate control state
        uint64_t const frame_period_us = frame_rate > 0 ? VISUAL_USECS_PER_SEC / frame_rate : 0;
        LV::Time last_frame_time;
        bool draw_frame = true;

        // main loop
        bool running = true;
        //bool visible = true;

        while (running)
        {
            // Check if process termination was signaled
            if (terminate_process) {
                std::cerr << "Received signal to terminate process, exiting..\n";
                return EXIT_SUCCESS;
            }

            // Control frame rate
            if (frame_rate > 0) {
                if (frames_drawn > 0) {
                    draw_frame = (LV::Time::now () - last_frame_time).to_usecs () >= frame_period_us;
                }
            }

            if (draw_frame) {
                DisplayLock lock {display};

                // Draw audio data and render
                bin.run();

                // Display rendering
                display.update_all ();

                // Record frame time
                last_frame_time = LV::Time::now ();

                // All frames rendered?
                frames_drawn++;
                if (frame_count > 0 && frames_drawn >= frame_count) {
                    break;
                }

                // switch actor?
                if (actor_switch_after_frames > 0 &&
                    frames_drawn >= actor_switch_after_frames + actor_switch_framecount)
                {
                    actor_switch_framecount += actor_switch_after_frames;

                    actor_name = cycle_actor_name (actor_name, CycleDir::NEXT);
                    std::cerr << "Switching to actor '" << actor_name << "'...\n";
                    bin.switch_actor (actor_name);
                }
            }

            LV::Event ev;

            // Handle all events
            display.drain_events(localqueue);

            auto pluginqueue = visual_plugin_get_event_queue (bin.get_actor()->get_plugin ());

            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:
                    {
                        DisplayLock lock {display};

                        width = ev.event.resize.width;
                        height = ev.event.resize.height;

                        video = display.create(depth, vidoptions, width, height, true);
                        display.set_title(_("lv-tool"));

                        bin.set_video (video);
                        bin.sync(false);

                        break;
                    }

                    case VISUAL_EVENT_MOUSEMOTION:
                    {
                        break;
                    }

                    case VISUAL_EVENT_MOUSEBUTTONDOWN:
                    {
                        // switch to next actor
                        actor_name = cycle_actor_name (actor_name, CycleDir::NEXT);

                        std::cerr << "Switching to actor '" << actor_name << "'...\n";
                        bin.switch_actor (actor_name);

                        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 (bin.depth_changed())
            {
                DisplayLock lock {display};

                int depthflag = bin.get_depth();
                VisVideoDepth depth = visual_video_depth_get_highest(depthflag);

                display.create(depth, vidoptions, width, height, true);

                video = display.get_video();
                bin.set_video(video);

                bin.sync(true);
            }
        }

        return EXIT_SUCCESS;
    }
    catch (std::exception& error) {
        std::cerr << error.what () << std::endl;

        return EXIT_FAILURE;
    }
}