--- mintv/mintv.cpp 2003/02/25 21:10:35 1.2 +++ mintv/mintv.cpp 2005/10/02 11:57:30 1.8 @@ -1,7 +1,7 @@ /* - * mintv.cpp - 50/60Hz video display using v4l and XVideo + * mintv.cpp - 50/60Hz noninterlaced video display using v4l and XVideo * - * Written in 2003 by Christian Bauer + * Written in 2003-2004 by Christian Bauer */ #include @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -31,17 +32,17 @@ static bool ntsc = false; const int PAL_WIDTH = 384; const int PAL_HEIGHT = 288; -const int NTSC_WIDTH = 320; +const int NTSC_WIDTH = 360; const int NTSC_HEIGHT = 240; -static int grab_width, grab_height; +static int grab_width = -1, grab_height; static int image_width, image_height; static int win_width, win_height; -const int PAL_FPS = 50; -const int NTSC_FPS = 60; +const double PAL_FPS = 50.0; +const double NTSC_FPS = 59.94; -static int fps; +static double fps; static int brightness = 50, contrast = 50, color = 50; @@ -284,7 +285,7 @@ static Boolean work_proc(XtPointer clien now = GetTicks_usec(); uint64 elapsed = now - prev; - int64 delay = 1000000 / fps - (now - prev); + int64 delay = int64(1000000.0 / fps) - (now - prev); #if LOGGING fprintf(log, "elapsed %Ld usec, delay %Ld usec\n", elapsed, delay); #endif @@ -321,6 +322,7 @@ int main(int argc, char **argv) {"help", 0, 0, 'h'}, {"ntsc", 0, 0, 'n'}, {"port", 1, 0, 'p'}, + {"width", 1, 0, 'w'}, {NULL, 0, 0, 0} }; @@ -328,33 +330,10 @@ int main(int argc, char **argv) log = fopen("log", "w"); #endif - // Init X11 - XtAppContext app_context; - app_shell = XtAppInitialize(&app_context, "mintv", NULL, 0, &argc, argv, NULL, NULL, 0); - dpy = XtDisplay(app_shell); - XtAppAddActions(app_context,actionTable, sizeof(actionTable) / sizeof(XtActionsRec)); - XtOverrideTranslations(app_shell, XtParseTranslationTable( - "WM_PROTOCOLS: quit()\n" - "q: quit()\n" - "1: select_channel_1()\n" - "2: select_channel_2()\n" - "KP_7: inc_brightness()\n" - "KP_4: reset_brightness()\n" - "KP_1: dec_brightness()\n" - "KP_8: inc_contrast()\n" - "KP_5: reset_contrast()\n" - "KP_2: dec_contrast()\n" - "KP_9: inc_color()\n" - "KP_6: reset_color()\n" - "KP_3: dec_color()" - )); - XtAddEventHandler(app_shell, StructureNotifyMask, True, resize_event, NULL); - wm = XInternAtom(XtDisplay(app_shell), "WM_DELETE_WINDOW", False); - // Parse options for (;;) { int c; - if ((c = getopt_long(argc, argv, "hnp:", long_opts,NULL)) == -1) + if ((c = getopt_long(argc, argv, "hnp:w:", long_opts, NULL)) == -1) break; switch (c) { @@ -366,14 +345,18 @@ int main(int argc, char **argv) case 'p': port = atoi(optarg); break; + case 'w': + grab_width = atoi(optarg); + break; case 'h': default: fprintf(stderr, - "50/60Hz video display application\n" + "50/60Hz video display application\n\n" "Options:\n" - " -h | --help this text\n" - " -n | --ntsc NTSC mode\n" - " -p | --port n Xv output port\n\n" + " -h | --help this text\n" + " -n | --ntsc NTSC mode\n" + " -p | --port n Xv output port\n" + " -w | --width n image width\n\n" "Keyboard commands:\n" " q quit\n" " 1/2 select channel\n" @@ -386,6 +369,30 @@ int main(int argc, char **argv) } } + // Init X11 + XtAppContext app_context; + app_shell = XtAppInitialize(&app_context, "mintv", NULL, 0, &argc, argv, NULL, NULL, 0); + dpy = XtDisplay(app_shell); + XtAppAddActions(app_context,actionTable, sizeof(actionTable) / sizeof(XtActionsRec)); + XtOverrideTranslations(app_shell, XtParseTranslationTable( + "WM_PROTOCOLS: quit()\n" + "q: quit()\n" + "Escape: quit()\n" + "1: select_channel_1()\n" + "2: select_channel_2()\n" + "KP_7: inc_brightness()\n" + "KP_4: reset_brightness()\n" + "KP_1: dec_brightness()\n" + "KP_8: inc_contrast()\n" + "KP_5: reset_contrast()\n" + "KP_2: dec_contrast()\n" + "KP_9: inc_color()\n" + "KP_6: reset_color()\n" + "KP_3: dec_color()" + )); + XtAddEventHandler(app_shell, StructureNotifyMask, True, resize_event, NULL); + wm = XInternAtom(XtDisplay(app_shell), "WM_DELETE_WINDOW", False); + // Xvideo available? unsigned ver, rel, req, ev, err, val; if (XvQueryExtension(dpy, &ver, &rel, &req, &ev, &err) != Success) { @@ -431,11 +438,13 @@ port_found: // Set grab and window dimensions if (ntsc) { - grab_width = NTSC_WIDTH; + if (grab_width == -1) + grab_width = NTSC_WIDTH; grab_height = NTSC_HEIGHT; fps = NTSC_FPS; } else { - grab_width = PAL_WIDTH; + if (grab_width == -1) + grab_width = PAL_WIDTH; grab_height = PAL_HEIGHT; fps = PAL_FPS; } @@ -456,11 +465,22 @@ port_found: XtRealizeWidget(app_shell); XtVaSetValues(app_shell, XtNtitle, "mintv", + XtNinput, True, NULL ); - XSetWMProtocols(XtDisplay(app_shell), XtWindow(app_shell), &wm, 1); + XSetWMProtocols(dpy, XtWindow(app_shell), &wm, 1); gc = XCreateGC(dpy, XtWindow(video), 0, NULL); + // Hide cursor + Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy)); + XColor black; + XParseColor(dpy, cmap, "#000000", &black); + XAllocColor(dpy, cmap, &black); + static char null_data[] = {0, 0, 0, 0, 0, 0, 0, 0}; + Pixmap null_pixmap = XCreateBitmapFromData(dpy, XtWindow(video), null_data, 8, 8); + Cursor null_cursor = XCreatePixmapCursor(dpy, null_pixmap, null_pixmap, &black, &black, 0, 0); + XDefineCursor(dpy, XtWindow(video), null_cursor); + // Set image format unsigned format = XV_FORMAT;