[Mplayer-users] XVidMode example code
mgraffam at idsi.net
mgraffam at idsi.net
Thu Mar 22 22:35:28 CET 2001
Hello all ..
A few weeks ago, I posted to the list about having mplayer change the
current video mode when doing fullscreen work, Arpi responded by saying
that the developers didn't know how to do video mode changes under X,
and requested some example code, or a patch to libvo.
The idea is to switch the video mode down to the mode closest to the
resolution of the movie to provide a "zoomed" view.
Well, here is some example code. While in the process of writing it,
I can certainly see why the developers hadn't figured it out -- the
documentation is sketchy -- at times incorrect, and at other times
incomplete.
This code prints out the version number of the VidMode extension being
used, then prints out all available resolutions and finally switches
to 640x480.
Note that screen 0 is hardcoded into the source -- this should be
generalized, of course.
I'm posting the code here merely because the discussion originally
came up here, and I thought others might be interested in knowing
what came of it.
/*
Example of of the XF86 VidMode Extension calls
Michael Graffam <mgraffam at idsi.net>
LICENSE: this code is freeware and can be used for any
purpose whatsoever -- you can even say that you wrote it,
so feel free to cut and paste this directly into something
else if it will help.
COMPILE:
gcc -o xvidmode xvidmode.c -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm
NOTES: The XF86 VidMode Extension is very pooly documented.
This code has some comments that help explain how and why things
are done in a certain way (when I actually KNOW why, that is).
Please pay attention to the comments -- they will prevent a bit
of headache.
*/
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
#include <stdio.h>
#include <string.h>
static void help(void)
{
fprintf(stderr, "Usage: xvidmode [-display DISPLAY]\n");
exit(0);
}
int main(int argc, char **argv)
{
Display *dpy;
unsigned int ver, rev, eventB, errorB, reqB, h, v, ht,vt;
char *displayname = NULL;
int i,j;
int modecount;
/* The documentation says that XF86VidModeModeInfo wants a double
pointer. But the function definition says that it wants a triple
pointer. So, we declare a double and pass the address */
XF86VidModeModeInfo **modes;
if ((argc != 1) && (argc !=3))
help();
if (argc != 1) {
if (strcmp(argv[1], "-display"))
help();
displayname=argv[2];
}
if(!(dpy = XOpenDisplay(displayname)))
{
fprintf(stderr, "xvidmode: Unable to open display %s\n",
(displayname != NULL) ? displayname : XDisplayName(NULL));
exit(-1);
}
if (XF86VidModeQueryExtension(dpy,&eventB, &errorB))
{
XF86VidModeQueryVersion(dpy, &ver, &rev);
fprintf(stderr, "VidMode Extension version %i.%i\n", ver, rev);
}
else
{
fprintf(stderr,"xvidmode: No VidMode Extension on %s\n",
(displayname != NULL) ? displayname : XDisplayName(NULL));
exit(0);
}
XF86VidModeGetAllModeLines(dpy,0,&modecount, &modes);
j=0;
for (i=0; i<modecount; i++)
{
fprintf(stderr,"%dx%d\n", (*modes[i]).hdisplay, (*modes[i]).vdisplay);
if ( ((*modes[i]).hdisplay==640) && ((*modes[i]).vdisplay==480) )
j=i;
}
/* I don't know why this call needs to be made twice to actually
work, but a single call doesn't do anything. */
XF86VidModeSwitchToMode(dpy,0,modes[j]);
XF86VidModeSwitchToMode(dpy,0,modes[j]);
free(modes);
}
--
Michael Graffam (mgraffam at idsi.net)
_______________________________________________
Mplayer-users mailing list
Mplayer-users at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-users
More information about the MPlayer-users
mailing list