Exemplo n.º 1
0
int main (int argc, char **argv)
{
	VisVideo *dest, *src;
	int i;

	visual_init (&argc, &argv);

	dest = visual_video_new ();
	visual_video_set_depth (dest, DEPTH);
	visual_video_set_dimension (dest, 640, 400);
	visual_video_allocate_buffer (dest);

	src = visual_video_new ();
	visual_video_set_depth (src, DEPTH);
	visual_video_set_dimension (src, 320, 200);
	visual_video_allocate_buffer (src);

	for (i = 0; i < TIMES; i++)
		visual_video_scale (dest, src, INTERPOL);

	printf ("Scale bench overlay %d times, depth %d, interpol %d\n", TIMES,
			DEPTH, INTERPOL);

	return EXIT_SUCCESS;
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
    static void
    init( int &argc, char **&argv )
    {
        VisVideoDepth depth;

        visual_init( &argc, &argv );

        bin    = visual_bin_new ();
        depth  = visual_video_depth_enum_from_value( 24 );

        if( !plugin ) plugin = visual_actor_get_next_by_name( 0 );
        if( !plugin ) exit( "Actor plugin not found!" );

        visual_bin_set_supported_depth( bin, VISUAL_VIDEO_DEPTH_ALL );

        if( NULL == (video = visual_video_new()) )       exit( "Cannot create a video surface" );
        if( visual_video_set_depth( video, depth ) < 0 ) exit( "Cannot set video depth" );

        visual_video_set_dimension( video, 320, 200 );

        if( visual_bin_set_video( bin, video ) ) exit( "Cannot set video" );

        visual_bin_connect_by_names( bin, (char*)plugin, 0 );

        if( visual_bin_get_depth( bin ) == VISUAL_VIDEO_DEPTH_GL )
        {
            visual_video_set_depth( video, VISUAL_VIDEO_DEPTH_GL );
            pluginIsGL = true;
        }

        SDL::create( 320, 200 );

        SDL_WM_SetCaption( plugin, 0 );

        /* Called so the flag is set to false, seen we create the initial environment here */
        visual_bin_depth_changed( bin );

        VisInput *input = visual_bin_get_input( bin );
        if( visual_input_set_callback( input, upload_callback, NULL ) < 0 ) exit( "Cannot set input plugin callback" );

        visual_bin_switch_set_style( bin, VISUAL_SWITCH_STYLE_MORPH );
        visual_bin_switch_set_automatic( bin, true );
        visual_bin_switch_set_steps( bin, 100 );

        visual_bin_realize( bin );
        visual_bin_sync( bin, false );

        std::cout << "[PANA] Libvisual version " << visual_get_version() << '\n';
        std::cout << "[PANA] bpp: " << video->bpp << std::endl;
        std::cout << "[PANA]  GL: "  << (pluginIsGL ? "true\n" : "false\n");
    }
int main (int argc, char **argv)
{
	float rate = 0.0;
	VisMorph *morph;
	VisAudio audio;
	VisVideo *dest, *src1, *src2;
	int i;

	visual_init (&argc, &argv);

	if (argc < 2)
		morph = visual_morph_new ("alphablend");
	else
		morph = visual_morph_new (argv[1]);

	visual_morph_realize (morph);

	dest = visual_video_new ();

	visual_video_set_depth (dest, DEPTH);
	visual_video_set_dimension (dest, 640, 400);
	visual_video_allocate_buffer (dest);

	src1 = visual_video_new ();
	src2 = visual_video_new ();

	visual_video_copy_attrs (src1, dest);
	visual_video_copy_attrs (src2, dest);

	visual_video_allocate_buffer (src1);
	visual_video_allocate_buffer (src2);

	visual_morph_set_video (morph, dest);
	for (i = 0; i < TIMES; i++) {
		visual_morph_set_rate (morph, rate);
		visual_morph_run (morph, &audio, src1, src2);

		rate += 0.1;

		if (rate > 1.0)
			rate = 0.0;
	}

	printf ("Morph throughput bench %d times depthBPP %d morph: %s\n", TIMES, dest->bpp,
			(visual_plugin_get_info (visual_morph_get_plugin (morph)))->plugname);

	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int main (int argc, char **argv)
{
	VisVideo *dest, *src;
	int i;
	
	visual_init (&argc, &argv);

	dest = visual_video_new ();
	visual_video_set_depth (dest, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (dest, 640, 400);
	visual_video_allocate_buffer (dest);

	src = visual_video_new ();
	visual_video_clone (src, dest);
	visual_video_allocate_buffer (src);

	for (i = 0; i < TIMES; i++)
		visual_video_blit_overlay (dest, src, 0, 0, TRUE);

	printf ("Blit overlay %d times\n", TIMES);
}
Exemplo n.º 6
0
int main (int argc, char **argv)
{
	char *d1, *d2;
	VisVideo *dest, *src;
	VisVideoDepth depth1, depth2;
	int i;

	visual_init (&argc, &argv);

	if (argc > 2) {
		d1 = argv[1];
		d2 = argv[2];
	} else {
		d1 = strdup("32");
		d2 = strdup("16");
	}

	depth1 = visual_video_depth_enum_from_value(atoi(d1));
	depth2 = visual_video_depth_enum_from_value(atoi(d2));

	dest = visual_video_new ();
	visual_video_set_depth (dest, depth1);
	visual_video_set_dimension (dest, 640, 400);
	visual_video_set_palette (dest, visual_palette_new (256));
	visual_video_allocate_buffer (dest);

	src = visual_video_new ();
	visual_video_set_depth (src, depth2);
	visual_video_set_dimension (src, 640, 400);
	visual_video_set_palette (src, visual_palette_new (256));
	visual_video_allocate_buffer (src);

	for (i = 0; i < TIMES; i++)
		visual_video_depth_transform (dest, src);

	printf ("Depth transformed %d times from %s to %s\n", TIMES, d1, d2);
}
Exemplo n.º 7
0
static void check_init()
  {
  char * argv = { "libgmerlin" };
  char ** argvp = &argv;
  int argc = 1;
  pthread_mutex_lock(&lv_initialized_mutex);
  if(lv_initialized)
    {
    pthread_mutex_unlock(&lv_initialized_mutex);
    return;
    }
  
  /* Initialize the library */
  visual_init(&argc, &argvp);
  
  /* Set the log callbacks */
  visual_log_set_info_handler(log_info, NULL);
  visual_log_set_warning_handler(log_warning, NULL);
  visual_log_set_critical_handler(log_warning, NULL);
  visual_log_set_error_handler(log_error, NULL);
  
  lv_initialized = 1;
  pthread_mutex_unlock(&lv_initialized_mutex);
  }
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
/* Main stuff */
int main (int argc, char *argv[])
{
	int width = 1000, height = 600;
	int i, j;
	int freeze = 0;
	int depthflag = 0;
	int alpha = 190;
	int xoff = 0, yoff = -90;
	int sxsize = 1000;
	int sysize = 700;
	int interpol = VISUAL_VIDEO_SCALE_NEAREST;
        int frames = 0;
	VisTime start, end;
		
	bpp = 4;
	sdl_init (width, height);

	scrbuf = malloc (screen->pitch * screen->h);
	memset (scrbuf, 0, screen->pitch * screen->h);

	SDL_Event event;

	visual_init (&argc, &argv);
	
	if (argc > 1)
		actor = visual_actor_new (argv[1]);
	else
		actor = visual_actor_new ("corona");

	visual_actor_realize (actor);

	video = visual_video_new ();

	if (argc > 2)
		video = visual_bitmap_load_new_video (argv[2]);
	else
		video = visual_bitmap_load_new_video ("bg.bmp");

	actvid = visual_video_new ();
	visual_actor_set_video (actor, actvid);
	visual_video_set_depth (actvid, visual_video_depth_get_highest (visual_actor_get_supported_depth (actor)));
	visual_video_set_dimension (actvid, width, height);
	visual_video_allocate_buffer (actvid);

	visual_actor_video_negotiate (actor, 0, FALSE, FALSE);

	video32 = visual_video_new ();
	visual_video_set_depth (video32, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (video32, video->width, video->height);
	visual_video_allocate_buffer (video32);
	
	scalevid = visual_video_new ();
	visual_video_set_depth (scalevid, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (scalevid, sxsize, sysize);
	visual_video_allocate_buffer (scalevid);

	sdlvid = visual_video_new ();
	visual_video_set_depth (sdlvid, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (sdlvid, screen->w, screen->h);
	visual_video_set_pitch (sdlvid, screen->pitch);
	visual_video_set_buffer (sdlvid, scrbuf);
	
	input = visual_input_new ("xmms2");
	visual_input_realize (input);

	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
        
	visual_time_get (&start);
	
	while (1) {
		visual_input_run (input);
		visual_actor_run (actor, input->audio);
	
		/* place on screen */
//		visual_video_blit_overlay (sdlvid, video, 0, 0, FALSE);
	
		if (sxsize < 0)
			sxsize = 0;

		if (sysize < 0)
			sysize = 0;
		
		if (sxsize != scalevid->width || sysize != scalevid->height) {
			visual_video_set_dimension (scalevid, sxsize, sysize);
			visual_video_allocate_buffer (scalevid);
		}

		visual_video_depth_transform (video32, video);


//		visual_video_alpha_fill (sdlvid, 0);
		
//		visual_video_alpha_fill (video32, alpha);
//		visual_video_alpha_color (video32, 0, 0, 0, 255);
	

		do_alpha (video32, alpha);
		visual_video_scale (scalevid, video32, interpol);

		
		visual_video_blit_overlay (sdlvid, actvid, 0, 0, FALSE);
		visual_video_blit_overlay (sdlvid, scalevid, xoff, yoff, TRUE);

		sdl_draw_buf ();
		frames++;
		
		while (SDL_PollEvent (&event)) {
			switch (event.type) {
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym) {
						case SDLK_F11:
							SDL_WM_ToggleFullScreen (screen);
							break;

						case SDLK_UP:
							yoff -= 10;

							break;

						case SDLK_DOWN:
							yoff += 10;

							break;
						
						case SDLK_LEFT:
							xoff -= 10;

							break;

						case SDLK_RIGHT:
							xoff += 10;

							break;
						
						case SDLK_q:
							sysize -= 10;

							break;

						case SDLK_a:
							sysize += 10;

							break;
						
						case SDLK_z:
							sxsize -= 10;

							break;

						case SDLK_x:
							sxsize += 10;

							break;

						case SDLK_i:
							if (interpol == VISUAL_VIDEO_SCALE_NEAREST)
								interpol = VISUAL_VIDEO_SCALE_BILINEAR;
							else
								interpol = VISUAL_VIDEO_SCALE_NEAREST;
							
							break;

						case SDLK_o:
							alpha -= 8;
							if (alpha < 0)
								alpha = 0;

							break;

						case SDLK_p:
							alpha += 8;
							if (alpha > 255)
								alpha = 255;

							break;
							
						case SDLK_ESCAPE:
							goto out;
							break;
					}
					break;

				case SDL_VIDEORESIZE:
					sdl_size_request (event.resize.w, event.resize.h);
					break;

				case SDL_QUIT:
					goto out;
					break;
			}
		}
	}
out:
	visual_time_get (&end);
	
	VisTime diff;

	visual_time_difference (&diff, &start, &end);


	printf ("Ran: %d:%d, drawn %d frames\n",
			diff.tv_sec, diff.tv_usec, frames);

	SDL_Quit ();
}
Exemplo n.º 10
0
static gboolean
plugin_init (GstPlugin * plugin)
{
  guint i, count;
  VisList *list;

  GST_DEBUG_CATEGORY_INIT (libvisual_debug, "libvisual", 0,
      "libvisual audio visualisations");

#ifdef LIBVISUAL_PLUGINSBASEDIR
  gst_plugin_add_dependency_simple (plugin, "HOME/.libvisual/actor",
      LIBVISUAL_PLUGINSBASEDIR "/actor", NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
#endif

  visual_log_set_verboseness (VISUAL_LOG_VERBOSENESS_LOW);
  visual_log_set_info_handler (libvisual_log_handler, (void *) GST_LEVEL_INFO);
  visual_log_set_warning_handler (libvisual_log_handler,
      (void *) GST_LEVEL_WARNING);
  visual_log_set_critical_handler (libvisual_log_handler,
      (void *) GST_LEVEL_ERROR);
  visual_log_set_error_handler (libvisual_log_handler,
      (void *) GST_LEVEL_ERROR);

  if (!visual_is_initialized ())
    if (visual_init (NULL, NULL) != 0)
      return FALSE;

  list = visual_actor_get_list ();

#if !defined(VISUAL_API_VERSION)
  count = visual_list_count (list);
#elif VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
  count = visual_collection_size (VISUAL_COLLECTION (list));
#endif

  for (i = 0; i < count; i++) {
    VisPluginRef *ref = visual_list_get (list, i);
    VisPluginData *visplugin = NULL;
    gboolean skip = FALSE;
    GType type;
    gchar *name;
    GTypeInfo info = {
      sizeof (GstVisualClass),
      NULL,
      NULL,
      gst_visual_class_init,
      NULL,
      ref,
      sizeof (GstVisual),
      0,
      NULL
    };

    visplugin = visual_plugin_load (ref);

    if (ref->info->plugname == NULL)
      continue;

    /* Blacklist some plugins */
    if (strcmp (ref->info->plugname, "gstreamer") == 0 ||
        strcmp (ref->info->plugname, "gdkpixbuf") == 0) {
      skip = TRUE;
    } else {
      /* Ignore plugins that only support GL output for now */
      skip = gst_visual_actor_plugin_is_gl (visplugin->info->plugin,
          visplugin->info->plugname);
    }

    visual_plugin_unload (visplugin);

    if (!skip) {
      name = g_strdup_printf ("GstVisual%s", ref->info->plugname);
      make_valid_name (name);
      type = g_type_register_static (GST_TYPE_VISUAL, name, &info, 0);
      g_free (name);

      name = g_strdup_printf ("libvisual_%s", ref->info->plugname);
      make_valid_name (name);
      if (!gst_element_register (plugin, name, GST_RANK_NONE, type)) {
        g_free (name);
        return FALSE;
      }
      g_free (name);
    }
  }

  return TRUE;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
int
main(int argc, char *argv[])
{
  FILE *fp;
  Recog *recog;
  Jconf *jconf;

  /* inihibit system log output (default: stdout) */
  //jlog_set_output(NULL);
  /* output system log to a file */
  // FILE *fp = fopen(logfile, "w"); jlog_set_output(fp);

  /* if no option argument, output julius usage and exit */
  if (argc == 1) {
    fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION);
    j_put_version(stderr);
    fprintf(stderr, "Try '-setting' for built-in engine configuration.\n");
    fprintf(stderr, "Try '-help' for run time options.\n");
    return -1;
  }

  /* add application options */
  record_add_option();
  module_add_option();
  charconv_add_option();
  j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore);
  j_add_option("-logfile", 1, 1, "output log to file", opt_logfile);
  j_add_option("-nolog", 0, 0, "not output any log", opt_nolog);
  j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile);
  j_add_option("-help", 0, 0, "display this help", opt_help);
  j_add_option("--help", 0, 0, "display this help", opt_help);

  /* create a configuration variables container */
  jconf = j_jconf_new();
  // j_config_load_file(jconf, jconffile);
  if (j_config_load_args(jconf, argc, argv) == -1) {
    fprintf(stderr, "Try `-help' for more information.\n");
    return -1;
  }

  /* output system log to a file */
  if (nolog) {
    jlog_set_output(NULL);
  } else if (logfile) {
    fp = fopen(logfile, "w");
    jlog_set_output(fp);
  }

  /* here you can set/modify any parameter in the jconf before setup */
  // jconf->input.input_speech = SP_MIC;

  /* Fixate jconf parameters: it checks whether the jconf parameters
     are suitable for recognition or not, and set some internal
     parameters according to the values for recognition.  Modifying
     a value in jconf after this function may be errorous.
  */
  if (j_jconf_finalize(jconf) == FALSE) {
    if (logfile) fclose(fp);
    return -1;
  }

  /* create a recognition instance */
  recog = j_recog_new();
  /* assign configuration to the instance */
  recog->jconf = jconf;
  /* load all files according to the configurations */
  if (j_load_all(recog, jconf) == FALSE) {
    fprintf(stderr, "ERROR: Error in loading model\n");
    if (logfile) fclose(fp);
    return -1;
  }
  
#ifdef USER_LM_TEST
  {
    PROCESS_LM *lm;
    for(lm=recog->lmlist;lm;lm=lm->next) {
      if (lm->lmtype == LM_PROB) {
	j_regist_user_lm_func(lm, my_uni, my_bi, my_lm);
      }
    }
#endif

  /* checkout for recognition: build lexicon tree, allocate cache */
  if (j_final_fusion(recog) == FALSE) {
    fprintf(stderr, "ERROR: Error while setup work area for recognition\n");
    j_recog_free(recog);
    if (logfile) fclose(fp);
    return -1;
  }
  
  /* Set up some application functions */
  /* set character conversion mode */
  if (charconv_setup() == FALSE) {
    if (logfile) fclose(fp);
    return -1;
  }
  if (is_module_mode()) {
    /* set up for module mode */
    /* register result output callback functions to network module */
    module_setup(recog, NULL);
  } else {
    /* register result output callback functions to stdout */
    setup_output_tty(recog, NULL);
  }
  /* if -outfile option specified, callbacks for file output will be
     regitered */
  if (outfile_enabled) {
    if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) {
      setup_output_file(recog, NULL);
    } else {
      fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n");
      outfile_enabled = FALSE;
    }
  }

  /* setup recording if option was specified */
  record_setup(recog, NULL);

  /* on module connect with client */
  if (is_module_mode()) module_server();

  /* initialize and standby the specified audio input source */
  /* for microphone or other threaded input, ad-in thread starts here */
  if (j_adin_init(recog) == FALSE) return;

  /* output system information to log */
  j_recog_info(recog);

#ifdef VISUALIZE
  /* Visualize: initialize GTK */
  visual_init(recog);
  callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL);
  callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL);
  callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL);
  callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL);
  /* below should be called at result */
  visual2_best(now, winfo);
  /* 音声取り込みはコールバックで新規作成 */
  /* 第2パスで認識結果出力時に以下を実行 */
  visual2_best(now, recog->model->winfo);
#endif
  
  /* if no grammar specified on startup, start with pause status */
  {
    RecogProcess *r;
    boolean ok_p;
    ok_p = TRUE;
    for(r=recog->process_list;r;r=r->next) {
      if (r->lmtype == LM_DFA) {
	if (r->lm->winfo == NULL) { /* stop when no grammar found */
	  j_request_pause(recog);
	}
      }
    }
  }

  /* enter recongnition loop */
  main_recognition_stream_loop(recog);

  /* end proc */
  if (is_module_mode()) module_disconnect();

  /* release all */
  j_recog_free(recog);

  if (logfile) fclose(fp);
  return(0);
}
Exemplo n.º 13
0
int
main( int argc, char** argv )
{
    if( argc <= 1 || std::strcmp( argv[1], "--list" ) == 0 )
    {
        visual_init( &argc, &argv );

        #if 0
        VisList *list = visual_actor_get_list();

        for( VisListEntry *entry = list->head->next; entry != list->tail; entry = entry->next )
        {
            VisPluginInfo *info = static_cast<VisActor*>(entry->data)->plugin->ref->info;

            std::cout << info->name << '|' << info->about << std::endl;
        }
        #endif

        const char *plugin = 0;

        while( (plugin = visual_actor_get_next_by_name( plugin )) )
            std::cout << plugin << '\n';

        std::exit( 0 );
    }
    else if( argc == 3 )
        Vis::plugin = argv[2];


    //connect to socket
    const int sockfd = tryConnect( argv[1] );

    //register fd/pid combo with Pana
    {
        pid_t pid = ::getpid();
        char  buf[32] = "REG";
        *(pid_t*)&buf[4] = pid;

        ::send( sockfd, buf, 4 + sizeof(pid_t), 0 );
    }

    //init
    SDL::init();
    Vis::init( argc, argv );


    //main loop
    // 1. we sleep for a bit, listening for messages from Pana
    // 2. render a frame

    timeval tv;
    fd_set  fds;
    int     nbytes = 0;
    uint    render_time = 0;

    while( nbytes != -1 && SDL::event_handler() )
    {
        //set the time to wait
        tv.tv_sec  = 0;
        tv.tv_usec = render_time > 16 ? 0 : (16 - render_time) * 1000; //60Hz

        //get select to watch the right file descriptor
        FD_ZERO( &fds );
        FD_SET( sockfd, &fds );

        ::select( sockfd+1, &fds, 0, 0, &tv );

        if( FD_ISSET( sockfd, &fds) ) {
            //Pana sent us some data

            char command[16];
            ::recv( sockfd, command, 16, 0 );

            if( std::strcmp( command, "fullscreen" ) == 0 )
                SDL::toggleFullScreen();
        }

        //request pcm data
        ::send( sockfd, "PCM", 4, 0 );
        nbytes = ::recv( sockfd, Vis::pcm_data, 1024 * sizeof( int16_t ), 0 );

        render_time = LibVisual::render();
    }

    ::close( sockfd );

    return 0;
}
Exemplo n.º 14
0
/* Main stuff */
int main (int argc, char *argv[])
{
	int width = 1000, height = 600;
	int i, j;
	int freeze = 0;
	int depthflag = 0;
	int alpha = 128;

	bpp = 4;
	sdl_init (width, height);

	scrbuf = malloc (screen->pitch * screen->h);
	memset (scrbuf, 0, screen->pitch * screen->h);

	SDL_Event event;

	visual_init (&argc, &argv);
	
	if (argc > 1)
		actor = visual_actor_new (argv[1]);
	else
		actor = visual_actor_new ("G-Force");

	visual_actor_realize (actor);

	video = visual_video_new ();
	
	visual_actor_set_video (actor, video);
	visual_video_set_depth (video, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (video, 256, 256);
	visual_video_allocate_buffer (video);

	visual_actor_video_negotiate (actor, 0, FALSE, FALSE);

	scalevid = visual_video_new ();
	visual_video_set_depth (scalevid, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (scalevid, 300, 400);
	visual_video_allocate_buffer (scalevid);

	sdlvid = visual_video_new ();
	visual_video_set_depth (sdlvid, VISUAL_VIDEO_DEPTH_32BIT);
	visual_video_set_dimension (sdlvid, screen->w, screen->h);
	visual_video_set_pitch (sdlvid, screen->pitch);
	visual_video_set_buffer (sdlvid, scrbuf);
	
	input = visual_input_new ("alsa");
	visual_input_realize (input);
	
	while (1) {
		visual_input_run (input);
		visual_actor_run (actor, input->audio);
		
		/* place on screen */
		visual_video_blit_overlay (sdlvid, video, 0, 0, FALSE);

		visual_video_set_palette (scalevid, visual_actor_get_palette (actor));	

		visual_video_scale (scalevid, video, VISUAL_VIDEO_SCALE_BILINEAR);

		visual_video_blit_overlay (sdlvid, scalevid, 256, 0, FALSE);

		sdl_draw_buf ();
		
		usleep (5000);
		
		while (SDL_PollEvent (&event)) {
			switch (event.type) {
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym) {
						case SDLK_F11:
							sdl_fullscreen_toggle ();
							break;

						case SDLK_q:
							alpha -= 8;
							if (alpha < 0)
								alpha = 0;

							break;

						case SDLK_a:
							alpha += 8;
							if (alpha > 255)
								alpha = 255;

							break;
						
						case SDLK_ESCAPE:
							goto out;
							break;
					}
					break;

				case SDL_VIDEORESIZE:
					sdl_size_request (event.resize.w, event.resize.h);
					break;

				case SDL_QUIT:
					goto out;
					break;
			}
		}
	}
out:
	SDL_Quit ();
}