comparison simpletv.c @ 5:8b6b46a1261d

- Move to 5.x+ includes - XFree the Xv image - Ask the WM to keep the window aspect 4:3
author darius
date Tue, 28 Jun 2005 13:12:39 +0000
parents 8d7d1680db7d
children f0cbbe964629
comparison
equal deleted inserted replaced
4:8f7cda8e4af8 5:8b6b46a1261d
44 #include <sys/mman.h> 44 #include <sys/mman.h>
45 #include <sys/fcntl.h> 45 #include <sys/fcntl.h>
46 #include <sys/time.h> 46 #include <sys/time.h>
47 #include <libgen.h> 47 #include <libgen.h>
48 #include <sys/soundcard.h> 48 #include <sys/soundcard.h>
49 #include <machine/ioctl_bt848.h> 49 #include <dev/bktr/ioctl_bt848.h>
50 #include <machine/ioctl_meteor.h> 50 #include <dev/bktr/ioctl_meteor.h>
51 #include <machine/param.h> 51 #include <machine/param.h>
52 #include <sys/types.h> 52 #include <sys/types.h>
53 #include <sys/ipc.h> 53 #include <sys/ipc.h>
54 #include <sys/shm.h> 54 #include <sys/shm.h>
55 #include <X11/Xlib.h> 55 #include <X11/Xlib.h>
145 geo.rows = height; 145 geo.rows = height;
146 geo.columns = width; 146 geo.columns = width;
147 geo.frames = 1; 147 geo.frames = 1;
148 #ifdef USE_XVIMAGES 148 #ifdef USE_XVIMAGES
149 /* Should be YUV_12, but 422 actually gives a synced picture. Though */ 149 /* Should be YUV_12, but 422 actually gives a synced picture. Though */
150
151 /* geo.oformat = METEOR_GEO_YUV_12; */
152 geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; 150 geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
153 /* geo.oformat = METEOR_GEO_YUV_12; */
154 #else 151 #else
155 geo.oformat = METEOR_GEO_RGB24; 152 geo.oformat = METEOR_GEO_RGB24;
156 #endif 153 #endif
157 154
158 /* switch from interlaced capture to single field capture if */ 155 /* switch from interlaced capture to single field capture if */
357 Window root; 354 Window root;
358 XVisualInfo vinfo_pref; 355 XVisualInfo vinfo_pref;
359 int num_vis; 356 int num_vis;
360 XPixmapFormatValues *pf; 357 XPixmapFormatValues *pf;
361 int num_pf , pfi, i, j; 358 int num_pf , pfi, i, j;
362 359 XSizeHints sz_hint;
360
363 disp = XOpenDisplay(NULL); 361 disp = XOpenDisplay(NULL);
364 if (!disp) { 362 if (!disp) {
365 fprintf(stderr, "X-Error: unable to connect to display\n"); 363 fprintf(stderr, "X-Error: unable to connect to display\n");
366 exit(1); 364 exit(1);
367 } 365 }
383 XSetForeground(disp, gc, 0); 381 XSetForeground(disp, gc, 0);
384 XSetBackground(disp, gc, 1); 382 XSetBackground(disp, gc, 1);
385 383
386 XMapWindow(disp, win); 384 XMapWindow(disp, win);
387 cmap = DefaultColormap(disp, scr); 385 cmap = DefaultColormap(disp, scr);
386
387 sz_hint.flags = PAspect;
388 sz_hint.min_aspect.x = width;
389 sz_hint.min_aspect.y = height;
390 sz_hint.max_aspect.x = width;
391 sz_hint.max_aspect.y = height;
392
393 /* set min height/width to 4 to avoid off by one errors */
394 sz_hint.min_width = sz_hint.min_height = 4;
395 sz_hint.flags |= PMinSize;
396 XSetWMNormalHints(disp, win, &sz_hint);
397
388 XSync(disp, False); 398 XSync(disp, False);
389 399
390 /* Setup with Xv extension */ 400 /* Setup with Xv extension */
391 xv_adaptor = -1; 401 xv_adaptor = -1;
392 xv_format_id = -1; 402 xv_format_id = -1;
414 } 424 }
415 assert(xv_adaptor >= 0); 425 assert(xv_adaptor >= 0);
416 426
417 /* Create an image to captured frames */ 427 /* Create an image to captured frames */
418 #ifdef USE_XVIMAGES 428 #ifdef USE_XVIMAGES
419 yuv_im age = XvShmCreateImage(disp, xv_adaptors[xv_adaptor].base_id, 429 yuv_image = XvShmCreateImage(disp, xv_adaptors[xv_adaptor].base_id,
420 xv_format_id, 0, w, h, &shminfo); 430 xv_format_id, 0, w, h, &shminfo);
421 if (!yuv_image) 431 if (!yuv_image)
422 fprintf(stderr, "X-Error: unable to create XvShm XImage\n"); 432 fprintf(stderr, "X-Error: unable to create XvShm XImage\n");
423 433
424 shminfo.shmid = shmget(IPC_PRIVATE, yuv_image->data_size, IPC_CREAT | 0777); 434 shminfo.shmid = shmget(IPC_PRIVATE, yuv_image->data_size, IPC_CREAT | 0777);
425 if (shminfo.shmid == -1) 435 if (shminfo.shmid == -1)
426 fprintf(stderr, "SharedMemory Error: unable to get identifier\n"); 436 fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
427 437
428 shminfo.shmaddr = yuv_image->data = shmat(shminfo.shmid, 0, 0); 438 shminfo.shmaddr = yuv_image->data = shmat(shminfo.shmid, 0, 0);
439 yuv_image->data = shminfo.shmaddr;
429 #else 440 #else
430 rgb_image = XShmCreateImage(disp, vis, depth, ZPixmap, NULL, &shminfo, w, h); 441 rgb_image = XShmCreateImage(disp, vis, depth, ZPixmap, NULL, &shminfo, w, h);
431 if (!rgb_image) 442 if (!rgb_image)
432 fprintf(stderr, "X-Error: unable to create XShm XImage\n"); 443 fprintf(stderr, "X-Error: unable to create XShm XImage\n");
433 444
467 478
468 /*--------------------------------------------------------------------------*/ 479 /*--------------------------------------------------------------------------*/
469 480
470 void 481 void
471 X_Shutdown() { 482 X_Shutdown() {
483 #ifdef USE_XVIMAGES
472 XShmDetach(disp, &shminfo); 484 XShmDetach(disp, &shminfo);
473 #ifdef USE_XVIMAGES 485 shmctl(shminfo.shmid, IPC_RMID, 0);
474 #warning How do we destroy an XvImage? 486 shmdt(shminfo.shmaddr);
487 XFree(yuv_image);
475 #else 488 #else
476 XDestroyImage(rgb_image); 489 XDestroyImage(rgb_image);
477 #endif 490 #endif
478 shmdt(shminfo.shmaddr); 491 shmdt(shminfo.shmaddr);
479 shmctl(shminfo.shmid, IPC_RMID, 0); 492 shmctl(shminfo.shmid, IPC_RMID, 0);