static gboolean gst_visual_setup (GstAudioVisualizer * bscope) { GstVisual *visual = GST_VISUAL (bscope); gint depth; gst_visual_clear_actors (visual); /* FIXME: we need to know how many bits we actually have in memory */ depth = bscope->vinfo.finfo->pixel_stride[0]; if (bscope->vinfo.finfo->bits >= 8) { depth *= 8; } visual->actor = visual_actor_new (GST_VISUAL_GET_CLASS (visual)->plugin->info->plugname); visual->video = visual_video_new (); visual->audio = visual_audio_new (); /* can't have a play without actors */ if (!visual->actor || !visual->video) goto no_actors; if (visual_actor_realize (visual->actor) != 0) goto no_realize; visual_actor_set_video (visual->actor, visual->video); visual_video_set_depth (visual->video, visual_video_depth_enum_from_value (depth)); visual_video_set_dimension (visual->video, GST_VIDEO_INFO_WIDTH (&bscope->vinfo), GST_VIDEO_INFO_HEIGHT (&bscope->vinfo)); visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE); GST_DEBUG_OBJECT (visual, "WxH: %dx%d, bpp: %d, depth: %d", GST_VIDEO_INFO_WIDTH (&bscope->vinfo), GST_VIDEO_INFO_HEIGHT (&bscope->vinfo), visual->video->bpp, depth); return TRUE; /* ERRORS */ no_actors: { GST_ELEMENT_ERROR (visual, LIBRARY, INIT, (NULL), ("could not create actors")); gst_visual_clear_actors (visual); return FALSE; } no_realize: { GST_ELEMENT_ERROR (visual, LIBRARY, INIT, (NULL), ("could not realize actor")); gst_visual_clear_actors (visual); return FALSE; } }
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) { 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); }
static int native_getvideo (SADisplay *display, VisVideo *screen) { SDLNative *native = SDL_NATIVE (display->native); SDL_Surface *sdlscreen = native->screen; if (native->requested_depth == VISUAL_VIDEO_DEPTH_GL) visual_video_set_depth (screen, VISUAL_VIDEO_DEPTH_GL); else visual_video_set_depth (screen, visual_video_depth_enum_from_value (sdlscreen->format->BitsPerPixel)); visual_video_set_dimension (screen, sdlscreen->w, sdlscreen->h); visual_video_set_pitch (screen, sdlscreen->pitch); visual_video_set_buffer (screen, sdlscreen->pixels); return 0; }
static gboolean gst_visual_src_setcaps (GstPad * pad, GstCaps * caps) { GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad)); GstStructure *structure; gint depth, pitch; structure = gst_caps_get_structure (caps, 0); GST_DEBUG_OBJECT (visual, "src pad got caps %" GST_PTR_FORMAT, caps); if (!gst_structure_get_int (structure, "width", &visual->width)) goto error; if (!gst_structure_get_int (structure, "height", &visual->height)) goto error; if (!gst_structure_get_int (structure, "bpp", &depth)) goto error; if (!gst_structure_get_fraction (structure, "framerate", &visual->fps_n, &visual->fps_d)) goto error; visual_video_set_depth (visual->video, visual_video_depth_enum_from_value (depth)); visual_video_set_dimension (visual->video, visual->width, visual->height); pitch = GST_ROUND_UP_4 (visual->width * visual->video->bpp); visual_video_set_pitch (visual->video, pitch); visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE); /* precalc some values */ visual->outsize = visual->video->height * pitch; visual->spf = gst_util_uint64_scale_int (visual->rate, visual->fps_d, visual->fps_n); visual->duration = gst_util_uint64_scale_int (GST_SECOND, visual->fps_d, visual->fps_n); gst_object_unref (visual); return TRUE; /* ERRORS */ error: { GST_DEBUG_OBJECT (visual, "error parsing caps"); gst_object_unref (visual); return FALSE; } }
static VisVideo *visvideo_from_gdkpixbuf (GdkPixbuf *src) { int width = gdk_pixbuf_get_width (src); int height = gdk_pixbuf_get_height (src); VisVideoDepth depth = visual_video_depth_enum_from_value (gdk_pixbuf_get_n_channels (src) * 8); /* Wrap GdkPixbuf's pixel buffer in VisVideo */ VisVideo *bgr = visual_video_new_wrap_buffer (gdk_pixbuf_get_pixels (src), FALSE, width, height, depth, gdk_pixbuf_get_rowstride (src)); /* Flip RGB byte order */ VisVideo *target = visual_video_new_with_buffer (width, height, depth); visual_video_flip_pixel_bytes (target, bgr); visual_video_unref (bgr); return target; }
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; }