From: <jo...@so...> - 2005-02-27 01:39:25
|
Thanks for the advice, I created a small test program that runs, though I have some issues: 1. The program displays, but doesn't react to the music using alsa input. mplayer plug-in fails with: > libvisual ERROR: ./example: inp_mplayer_init(): \ > Could not open file '/home/jon/.mplayer/mplayer-af_export': No such file > or directory I'm unable to test with others. The examples from CVS failed similarly 1. When a plug-in is 8-bit, is it always palette based or can it be gray scale. How do I determine? 2. Take a look at display(), are my assumptions about color representation good? Does plug-in's use alpha channel? 3. Why doesn't visual_actor_new("foobar") return NULL if "foobar" doesn't exist? 4. Looking at the source. Why does the for-loop printing input names work (commented out), but the one printing actor names SIGSEGV? A last observation. There exists a function visual_video_new_with_buffer() which will create a VisVideo object and allocate a buffer. However I have found no way to re-size the VisVideo object which will also re-size the buffer. I have to do this with visual_video_allocate_buffer() (btw. the docs doesn't mention that this _reallocates_ under certain circumstances.) Personally, IMHO, I find it a bit inconsistent, the object does keep track of whether or not it's in charge of buffer resizing and could very well perform the re-size within visual_video_set_dimension(). Just my $0.02. If you're interested, when I get it to work properly I could create a short tutorial. However it would need to be reviewed as there probably would be some mistakes. Best, Jon Øyvind Kjellman Don't know if the list allows attachments so here's the code: makefile: ========= CC = gcc CFLAGS = -g -std=c99 LIBS = -L/usr/X11R6/lib -lpthread -lm -ldl -lvisual -lglut example: example.c $(CC) $(CFLAGS) $(LIBS) -o $@ $< clean: rm example example.c: ========== #include <GL/glut.h> #include <GL/gl.h> #include <libvisual/libvisual.h> #include <string.h> #include <stdlib.h> VisInput* input = NULL; VisActor* actor = NULL; VisVideo* video = NULL; VisBin* bin = NULL; VisVideoDepth depth = VISUAL_VIDEO_DEPTH_ERROR; GLuint window = 0, width = 640, height = 480; int use_gl = 0; /* Standard glut keyboard function. * Kills the program on any keypress. */ void key_func(unsigned char k, int x, int y) { glutDestroyWindow(window); exit(0); } /* Standard glut resize function. */ void resize(int w, int h) { width = w; height = h; glViewport(0, 0, width, height); if(visual_video_set_dimension(video, width, height) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to resize video."); if(!use_gl) /* visual_video_set_dimension doesn't resize the buffer so ... */ if(visual_video_allocate_buffer(video) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to resize buffer."); /* This lets actor know about the format change. */ if(visual_actor_video_negotiate(actor, 0, FALSE, FALSE) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "actor/video negotiation failed."); } /* Standard glut display function. */ void display() { glClear(GL_COLOR_BUFFER_BIT); /* This renders. */ visual_bin_run(bin); if(!use_gl) { /* We have to render video's buffer. */ GLenum format = GL_R3_G3_B2; /* Reasonable safety against reads outside of the buffer. */ switch(visual_video_bpp_from_depth(depth)) { case 4: format = GL_RGBA; break; case 3: format = GL_RGB; break; case 2: format = GL_RGBA4; break; /* case 1: defaults */ } glDrawPixels(width, height, format, GL_UNSIGNED_BYTE, (void*)video->pixels); } glutSwapBuffers(); glutPostRedisplay(); } int main(int argc, char** argv) { /* GLUT initialization */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(100, 100); glutInitWindowSize(width, height); window = glutCreateWindow("LibVisual example"); glutDisplayFunc(display); glutReshapeFunc(resize); glutKeyboardFunc(key_func); /* We init libvisual after glut since some plug-ins need * OpenGL during initialization. */ if(visual_init(&argc, &argv) < 0) visual_log(VISUAL_LOG_ERROR, "Couldn't initialize Libvisual."); char* input_name = NULL; char* actor_name = NULL; for(int i = 1; i < argc; ++i) { if(strcmp(argv[i], "--actor") == 0 && i+1 < argc) actor_name = argv[++i]; else if(strcmp(argv[i], "--input") == 0 && i+1 < argc) input_name = argv[++i]; else if(strcmp(argv[i], "--help") == 0) { printf("LibVisual example.\n"); printf("Use --actor and --input flags to specify\nplug-in and source from list below.\n"); printf("\nAvaiable inputs:\n"); VisListEntry* i; for(i = visual_input_get_list()->head; i; i = i->next) printf("%s\n", ((VisPluginRef*)i->data)->info->name); printf("\nAvaiable actors:\n"); /* for(i = visual_actor_get_list()->head; i; i = i->next) printf("%s\n", ((VisActor*)i->data)->plugin->info->plugname);*/ for(char* name = visual_actor_get_next_by_name_nogl(NULL); name; name = visual_actor_get_next_by_name_nogl(name)) printf("%s\n", name); for(char* name = visual_actor_get_next_by_name_gl(NULL); name; name = visual_actor_get_next_by_name_gl(name)) printf("%s (OpenGL)\n", name); return 0; } } if(!actor_name) actor_name = "oinksie"; /* Default actor */ if(!input_name) input_name = "alsa"; /* Default input */ if((input = visual_input_new(input_name)) == NULL) visual_log(VISUAL_LOG_ERROR, "No input loaded."); /* initializes input plug-in */ if(visual_input_realize(input) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to realize input."); if((actor = visual_actor_new(actor_name)) == NULL) visual_log(VISUAL_LOG_ERROR, "No actor loaded."); /* initializes actor plug-in */ if(visual_actor_realize(actor) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to realize actor."); depth = visual_actor_get_supported_depth(actor); if(depth == VISUAL_VIDEO_DEPTH_NONE || depth == VISUAL_VIDEO_DEPTH_ERROR) visual_log(VISUAL_LOG_ERROR, "Received fubar depthflag."); if(!(depth & VISUAL_VIDEO_DEPTH_GL)) { if(depth & VISUAL_VIDEO_DEPTH_32BIT) depth &= VISUAL_VIDEO_DEPTH_32BIT; else if(depth & VISUAL_VIDEO_DEPTH_24BIT) depth &= VISUAL_VIDEO_DEPTH_24BIT; else if(depth & VISUAL_VIDEO_DEPTH_16BIT) depth &= VISUAL_VIDEO_DEPTH_16BIT; else if(depth & VISUAL_VIDEO_DEPTH_8BIT) depth &= VISUAL_VIDEO_DEPTH_8BIT; visual_log(VISUAL_LOG_INFO, "Using %d bit framebuffer.", visual_video_bpp_from_depth(depth) * 8); } else { depth &= VISUAL_VIDEO_DEPTH_GL; use_gl = 1; visual_log(VISUAL_LOG_INFO, "Using OpenGL plug-in."); } if(!use_gl) { /* Plugin isn't OpenGL */ video = visual_video_new_with_buffer(width, height, depth); } else { video = visual_video_new(); if(visual_video_set_depth(video, depth) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to set depth on video."); } if(visual_actor_set_video(actor, video) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "Unable to set video for actor."); /* This lets actor know about the format of video. */ if(visual_actor_video_negotiate(actor, 0, FALSE, FALSE) != VISUAL_OK) visual_log(VISUAL_LOG_ERROR, "actor/video negotiation failed."); /* Associate input with actor. */ bin = visual_bin_new(); visual_bin_connect(bin, actor, input); visual_bin_realize(bin); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(use_gl) glFrustum(-0.5, 0.5, -0.5, 0.5, 0.1, 10000); else glOrtho(-1, 1, -1, 1, 0.1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Enters the main (Free)GLUT processing loop. */ glutMainLoop(); return 0; } |