Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libvo / vo_dxr3.c
bloba4e012894e8016ff558e20ad0d7082be424afe69
1 /*
2 * DXR3/H+ video output
4 * Copyright (C) 2002-2003 David Holm <david@realityrift.com>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/em8300.h>
24 #include <sys/ioctl.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/select.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <stdio.h>
34 #include <time.h>
35 #include <math.h>
37 #include "config.h"
38 #include "mp_msg.h"
39 #include "fastmemcpy.h"
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "aspect.h"
44 #include "spuenc.h"
45 #include "sub.h"
46 #ifdef CONFIG_X11
47 #include "x11_common.h"
48 #endif
49 #include "libavutil/avstring.h"
51 #define SPU_SUPPORT
53 static const vo_info_t info =
55 "DXR3/H+ video out",
56 "dxr3",
57 "David Holm <dholm@iname.com>",
60 const LIBVO_EXTERN (dxr3)
62 /* Resolutions and positions */
63 static int v_width, v_height;
64 static int s_width, s_height;
65 static int osd_w, osd_h;
66 static int img_format;
68 /* Configuration values
69 * Don't declare these static, they
70 * should be accessible from the gui.
72 int dxr3_prebuf = 0;
73 int dxr3_newsync = 0;
74 int dxr3_overlay = 0;
75 int dxr3_device_num = 0;
76 int dxr3_norm = 0;
78 #define MAX_STR_SIZE 80 /* length for the static strings */
80 /* File descriptors */
81 static int fd_control = -1;
82 static int fd_video = -1;
83 static int fd_spu = -1;
84 static char fdv_name[MAX_STR_SIZE];
85 static char fds_name[MAX_STR_SIZE];
87 #ifdef SPU_SUPPORT
88 /* on screen display/subpics */
89 static char *osdpicbuf;
90 static int osdpicbuf_w;
91 static int osdpicbuf_h;
92 static int disposd;
93 static encodedata *spued;
94 static encodedata *spubuf;
95 #endif
98 /* Static variable used in ioctl's */
99 static int ioval;
100 static int prev_pts;
101 static int pts_offset;
102 static int old_vmode = -1;
105 /* Begin overlay.h */
107 Simple analog overlay API for DXR3/H+ linux driver.
109 Henrik Johansson
113 /* Pattern drawing callback used by the calibration functions.
114 The function is expected to:
115 Clear the entire screen.
116 Fill the screen with color bgcol (0xRRGGBB)
117 Draw a rectangle at (xpos,ypos) of size (width,height) in fgcol (0xRRGGBB)
120 typedef int (*pattern_drawer_cb)(int fgcol, int bgcol,
121 int xpos, int ypos, int width, int height, void *arg);
123 struct coeff {
124 float k,m;
127 typedef struct {
128 int dev;
130 int xres, yres,depth;
131 int xoffset,yoffset,xcorr;
132 int jitter;
133 int stability;
134 int keycolor;
135 struct coeff colcal_upper[3];
136 struct coeff colcal_lower[3];
137 float color_interval;
139 pattern_drawer_cb draw_pattern;
140 void *dp_arg;
141 } overlay_t;
144 static overlay_t *overlay_init(int dev);
145 static int overlay_release(overlay_t *);
147 static int overlay_read_state(overlay_t *o, char *path);
148 static int overlay_write_state(overlay_t *o, char *path);
150 static int overlay_set_screen(overlay_t *o, int xres, int yres, int depth);
151 static int overlay_set_mode(overlay_t *o, int mode);
152 static int overlay_set_attribute(overlay_t *o, int attribute, int val);
153 static int overlay_set_keycolor(overlay_t *o, int color);
154 static int overlay_set_window(overlay_t *o, int xpos,int ypos,int width,int height);
155 static int overlay_set_bcs(overlay_t *o, int brightness, int contrast, int saturation);
157 static int overlay_autocalibrate(overlay_t *o, pattern_drawer_cb pd, void *arg);
158 static void overlay_update_params(overlay_t *o);
159 static int overlay_signalmode(overlay_t *o, int mode);
160 /* End overlay.h */
163 #ifdef CONFIG_X11
164 #define KEY_COLOR 0x80a040
165 static XWindowAttributes xwin_attribs;
166 static overlay_t *overlay_data;
167 #endif
170 /* Functions for working with the em8300's internal clock */
171 /* End of internal clock functions */
173 static int control(uint32_t request, void *data)
175 switch (request) {
176 case VOCTRL_SET_SPU_PALETTE:
177 if (ioctl(fd_spu, EM8300_IOCTL_SPU_SETPALETTE, data) < 0) {
178 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Unable to load new SPU palette!\n");
179 return VO_ERROR;
181 return VO_TRUE;
182 #ifdef CONFIG_X11
183 case VOCTRL_ONTOP:
184 vo_x11_ontop();
185 return VO_TRUE;
186 case VOCTRL_FULLSCREEN:
187 if (dxr3_overlay) {
188 vo_x11_fullscreen();
189 overlay_signalmode(overlay_data,
190 vo_fs ? EM8300_OVERLAY_SIGNAL_ONLY :
191 EM8300_OVERLAY_SIGNAL_WITH_VGA);
192 return VO_TRUE;
194 return VO_FALSE;
195 #endif
196 case VOCTRL_RESUME:
197 if (dxr3_newsync) {
198 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
199 pts_offset = vo_pts - (ioval << 1);
200 if (pts_offset < 0) {
201 pts_offset = 0;
205 if (dxr3_prebuf) {
206 ioval = EM8300_PLAYMODE_PLAY;
207 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
208 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to set playmode!\n");
211 return VO_TRUE;
212 case VOCTRL_PAUSE:
213 if (dxr3_prebuf) {
214 ioval = EM8300_PLAYMODE_PAUSED;
215 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
216 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to set playmode!\n");
219 return VO_TRUE;
220 case VOCTRL_RESET:
221 if (dxr3_prebuf) {
222 close(fd_video);
223 fd_video = open(fdv_name, O_WRONLY);
224 close(fd_spu);
225 fd_spu = open(fds_name, O_WRONLY);
226 fsync(fd_video);
227 fsync(fd_spu);
229 return VO_TRUE;
230 case VOCTRL_QUERY_FORMAT:
232 uint32_t flag = 0;
234 if (*((uint32_t*)data) != IMGFMT_MPEGPES)
235 return 0;
237 flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_SPU;
238 if (dxr3_prebuf)
239 flag |= VFCAP_TIMER;
240 return flag;
242 case VOCTRL_SET_EQUALIZER:
244 em8300_bcs_t bcs;
245 struct voctrl_set_equalizer_args *args = data;
247 if (ioctl(fd_control, EM8300_IOCTL_GETBCS, &bcs) < 0)
248 return VO_FALSE;
249 if (!strcasecmp(args->name, "brightness"))
250 bcs.brightness = (args->value+100)*5;
251 else if (!strcasecmp(args->name, "contrast"))
252 bcs.contrast = (args->value+100)*5;
253 else if (!strcasecmp(args->name, "saturation"))
254 bcs.saturation = (args->value+100)*5;
255 else return VO_FALSE;
257 if (ioctl(fd_control, EM8300_IOCTL_SETBCS, &bcs) < 0)
258 return VO_FALSE;
259 return VO_TRUE;
261 case VOCTRL_GET_EQUALIZER:
263 em8300_bcs_t bcs;
264 struct voctrl_get_equalizer_args *args = data;
266 if (ioctl(fd_control, EM8300_IOCTL_GETBCS, &bcs) < 0)
267 return VO_FALSE;
269 if (!strcasecmp(args->name, "brightness"))
270 *args->valueptr = (bcs.brightness/5)-100;
271 else if (!strcasecmp(args->name, "contrast"))
272 *args->valueptr = (bcs.contrast/5)-100;
273 else if (!strcasecmp(args->name, "saturation"))
274 *args->valueptr = (bcs.saturation/5)-100;
275 else return VO_FALSE;
277 return VO_TRUE;
280 return VO_NOTIMPL;
283 void calculate_cvals(unsigned long mask, int *shift, int *prec)
285 /* Calculate shift and precision */
286 (*shift) = 0;
287 (*prec) = 0;
289 while (!(mask & 0x1)) {
290 (*shift)++;
291 mask >>= 1;
294 while (mask & 0x1) {
295 (*prec)++;
296 mask >>= 1;
300 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
302 int tmp1, tmp2, size;
303 em8300_register_t reg;
305 /* Softzoom turned on, downscale */
306 /* This activates the subpicture processor, you can safely disable this and still send */
307 /* broken subpics to the em8300, if it's enabled and you send broken subpics you will end */
308 /* up in a lockup */
309 ioval = EM8300_SPUMODE_ON;
310 if (ioctl(fd_control, EM8300_IOCTL_SET_SPUMODE, &ioval) < 0) {
311 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to set subpicture mode!\n");
312 uninit();
313 return -1;
316 /* Set the playmode to play (just in case another app has set it to something else) */
317 ioval = EM8300_PLAYMODE_PLAY;
318 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
319 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to set playmode!\n");
322 /* Start em8300 prebuffering and sync engine */
323 reg.microcode_register = 1;
324 reg.reg = 0;
325 reg.val = MVCOMMAND_SYNC;
326 ioctl(fd_control, EM8300_IOCTL_WRITEREG, &reg);
328 /* Clean buffer by syncing it */
329 ioval = EM8300_SUBDEVICE_VIDEO;
330 ioctl(fd_control, EM8300_IOCTL_FLUSH, &ioval);
331 ioval = EM8300_SUBDEVICE_AUDIO;
332 ioctl(fd_control, EM8300_IOCTL_FLUSH, &ioval);
334 /* Sync the video device to make sure the buffers are empty
335 * and set the playback speed to normal. Also reset the
336 * em8300 internal clock.
338 fsync(fd_video);
339 ioval = 0x900;
340 ioctl(fd_control, EM8300_IOCTL_SCR_SETSPEED, &ioval);
342 /* Store some variables statically that we need later in another scope */
343 img_format = format;
344 v_width = width;
345 v_height = height;
347 /* Set monitor_aspect to avoid jitter */
348 monitor_aspect = (float) width / (float) height;
350 if (ioctl(fd_control, EM8300_IOCTL_GET_VIDEOMODE, &old_vmode) < 0) {
351 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to get TV norm!\n");
352 old_vmode = -1;
355 /* adjust TV norm */
356 if (dxr3_norm != 0) {
357 if (dxr3_norm == 5) {
358 ioval = EM8300_VIDEOMODE_NTSC;
359 } else if (dxr3_norm == 4) {
360 ioval = EM8300_VIDEOMODE_PAL60;
361 } else if (dxr3_norm == 3) {
362 ioval = EM8300_VIDEOMODE_PAL;
363 } else if (dxr3_norm == 2) {
364 if (vo_fps > 28) {
365 ioval = EM8300_VIDEOMODE_PAL60;
366 } else {
367 ioval = EM8300_VIDEOMODE_PAL;
370 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Auto-selected TV norm by framerate: ");
371 ioval == EM8300_VIDEOMODE_PAL60 ? mp_msg(MSGT_VO,MSGL_INFO, "PAL-60") : mp_msg(MSGT_VO,MSGL_INFO, "PAL");
372 printf(".\n");
373 } else {
374 if (vo_fps > 28) {
375 ioval = EM8300_VIDEOMODE_NTSC;
376 } else {
377 ioval = EM8300_VIDEOMODE_PAL;
380 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Auto-selected TV norm by framerate: ");
381 ioval == EM8300_VIDEOMODE_NTSC ? mp_msg(MSGT_VO,MSGL_INFO, "NTSC") : mp_msg(MSGT_VO,MSGL_INFO, "PAL");
382 printf(".\n");
385 if (old_vmode != ioval) {
386 if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &ioval) < 0) {
387 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to set TV norm!\n");
393 /* libavcodec requires a width and height that is x|16 */
394 aspect_save_orig(width, height);
395 aspect_save_prescale(d_width, d_height);
396 ioctl(fd_control, EM8300_IOCTL_GET_VIDEOMODE, &ioval);
397 if (ioval == EM8300_VIDEOMODE_NTSC) {
398 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Setting up for NTSC.\n");
399 aspect_save_screenres(352, 240);
400 } else {
401 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Setting up for PAL/SECAM.\n");
402 aspect_save_screenres(352, 288);
404 aspect(&s_width, &s_height, A_ZOOM);
405 s_width -= s_width % 16;
406 s_height -= s_height % 16;
408 /* Try to figure out whether to use widescreen output or not */
409 /* Anamorphic widescreen modes makes this a pain in the ass */
410 tmp1 = abs(d_height - ((d_width / 4) * 3));
411 tmp2 = abs(d_height - (int) (d_width / 2.35));
412 if (tmp1 < tmp2) {
413 ioval = EM8300_ASPECTRATIO_4_3;
414 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Setting aspect ratio to 4:3.\n");
415 } else {
416 ioval = EM8300_ASPECTRATIO_16_9;
417 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Setting aspect ratio to 16:9.\n");
419 ioctl(fd_control, EM8300_IOCTL_SET_ASPECTRATIO, &ioval);
421 #ifdef SPU_SUPPORT
422 #ifdef CONFIG_FREETYPE
423 if (ioval == EM8300_ASPECTRATIO_16_9) {
424 s_width *= d_height*1.78/s_height*(d_width*1.0/d_height)/2.35;
425 } else {
426 s_width *= 0.84;
428 //printf("VO: [dxr3] sw/sh:dw/dh ->%i,%i,%i,%i\n",s_width,s_height,d_width,d_height);
429 #else
430 s_width*=2;
431 s_height*=2;
432 #endif
434 osdpicbuf = calloc( 1,s_width * s_height);
435 if (osdpicbuf == NULL) {
436 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] out of memory\n");
437 return -1;
439 spued = malloc(sizeof(encodedata));
440 if (spued == NULL) {
441 free( osdpicbuf );
442 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] out of memory\n");
443 return -1;
445 spubuf = malloc(sizeof(encodedata));
446 if (spubuf == NULL) {
447 free( osdpicbuf );
448 free( spued );
449 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] out of memory\n");
450 return -1;
452 osd_w = s_width;
453 osd_h = s_height;
454 osdpicbuf_w = s_width;
455 osdpicbuf_h = s_height;
457 spubuf->count=0;
458 pixbuf_encode_rle( 0,0,osdpicbuf_w,osdpicbuf_h - 1,osdpicbuf,osdpicbuf_w,spubuf );
460 #endif
462 #ifdef CONFIG_X11
463 if (dxr3_overlay) {
464 XVisualInfo vinfo;
465 XSetWindowAttributes xswa;
466 XSizeHints hint;
467 unsigned long xswamask;
468 Colormap cmap;
469 XColor key_color;
470 Window junkwindow;
471 Screen *scr;
472 int depth, red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec, acq_color;
473 em8300_overlay_screen_t ovlscr;
474 em8300_attribute_t ovlattr;
476 vo_dx = (vo_screenwidth - d_width) / 2;
477 vo_dy = (vo_screenheight - d_height) / 2;
478 vo_dwidth = d_width;
479 vo_dheight = d_height;
481 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &xwin_attribs);
482 depth = xwin_attribs.depth;
483 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
484 depth = 24;
486 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
487 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
488 d_width, d_height, flags,
489 CopyFromParent, "Viewing Window", title);
490 xswa.background_pixel = KEY_COLOR;
491 xswa.border_pixel = 0;
492 xswamask = CWBackPixel | CWBorderPixel;
493 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
496 /* Start setting up overlay */
497 XGetWindowAttributes(mDisplay, mRootWin, &xwin_attribs);
498 overlay_set_screen(overlay_data, xwin_attribs.width, xwin_attribs.height, xwin_attribs.depth);
499 overlay_read_state(overlay_data, NULL);
501 /* Allocate keycolor */
502 cmap = vo_x11_create_colormap(&vinfo);
503 calculate_cvals(vinfo.red_mask, &red_shift, &red_prec);
504 calculate_cvals(vinfo.green_mask, &green_shift, &green_prec);
505 calculate_cvals(vinfo.blue_mask, &blue_shift, &blue_prec);
507 key_color.red = ((KEY_COLOR >> 16) & 0xff) * 256;
508 key_color.green = ((KEY_COLOR >> 8) & 0xff) * 256;
509 key_color.blue = (KEY_COLOR & 0xff) * 256;
510 key_color.pixel = (((key_color.red >> (16 - red_prec)) << red_shift) +
511 ((key_color.green >> (16 - green_prec)) << green_shift) +
512 ((key_color.blue >> (16 - blue_prec)) << blue_shift));
513 key_color.flags = DoRed | DoGreen | DoBlue;
514 if (!XAllocColor(mDisplay, cmap, &key_color)) {
515 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Unable to allocate keycolor!\n");
516 return -1;
519 acq_color = ((key_color.red / 256) << 16) | ((key_color.green / 256) << 8) | key_color.blue;
520 if (key_color.pixel != KEY_COLOR) {
521 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Unable to allocate exact keycolor, using closest match (0x%lx).\n", key_color.pixel);
524 /* Set keycolor and activate overlay */
525 XSetWindowBackground(mDisplay, vo_window, key_color.pixel);
526 XClearWindow(mDisplay, vo_window);
527 overlay_set_keycolor(overlay_data, key_color.pixel);
528 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OVERLAY);
529 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_RECTANGLE);
531 #endif
533 return 0;
536 static void draw_alpha(int x, int y, int w, int h, unsigned char* src, unsigned char *srca, int srcstride)
538 #ifdef SPU_SUPPORT
539 unsigned char *buf = &osdpicbuf[(y * osdpicbuf_w) + x];
540 int by = 0;
541 register int lx, ly;
542 register int stride = 0;
544 for (ly = 0; ly < h - 1; ly++)
546 for(lx = 0; lx < w; lx++ )
547 if ( ( srca[stride + lx] )&&( src[stride + lx] >= 128 ) ) buf[by + lx] = 3;
548 by+=osdpicbuf_w;
549 stride+=srcstride;
551 pixbuf_encode_rle(x, y, osdpicbuf_w, osdpicbuf_h - 1, osdpicbuf, osdpicbuf_w, spued);
552 #endif
555 extern int vo_osd_changed_flag;
556 extern mp_osd_obj_t* vo_osd_list;
558 static void draw_osd(void)
560 #ifdef SPU_SUPPORT
561 static int cleared = 0;
562 int changed = 0;
564 if ((disposd % 15) == 0)
567 mp_osd_obj_t* obj = vo_osd_list;
568 vo_update_osd( osd_w,osd_h );
569 while( obj )
571 if ( obj->flags & OSDFLAG_VISIBLE ) { changed=1; break; }
572 obj=obj->next;
575 if ( changed )
577 vo_draw_text(osd_w, osd_h, draw_alpha);
578 memset(osdpicbuf, 0, s_width * s_height);
579 cleared=0;
581 else
583 if ( !cleared )
585 spued->count=spubuf->count;
586 fast_memcpy( spued->data,spubuf->data,DATASIZE );
587 cleared=1;
592 /* could stand some check here to see if the subpic hasn't changed
593 * as if it hasn't and we re-send it it will "blink" as the last one
594 * is turned off, and the new one (same one) is turned on
596 /* Subpics are not stable yet =(
597 expect lockups if you enable */
598 write(fd_spu, spued->data, spued->count);
600 disposd++;
601 #endif
605 static int draw_frame(uint8_t * src[])
607 vo_mpegpes_t *p = (vo_mpegpes_t *) src[0];
609 #ifdef SPU_SUPPORT
610 if (p->id == 0x20) {
611 write(fd_spu, p->data, p->size);
612 } else
613 #endif
614 write(fd_video, p->data, p->size);
615 return 0;
618 static void flip_page(void)
620 #ifdef CONFIG_X11
621 if (dxr3_overlay) {
622 int event = vo_x11_check_events(mDisplay);
623 if (event & VO_EVENT_RESIZE) {
624 Window junkwindow;
625 XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs);
626 XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow);
627 overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height);
629 if (event & VO_EVENT_EXPOSE) {
630 Window junkwindow;
631 XSetWindowBackground(mDisplay, vo_window, KEY_COLOR);
632 XClearWindow(mDisplay, vo_window);
633 XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs);
634 XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow);
635 overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height);
638 #endif
640 if (dxr3_newsync) {
641 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
642 ioval <<= 1;
643 if (vo_pts == 0) {
644 ioval = 0;
645 ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval);
646 pts_offset = 0;
647 } else if ((vo_pts - pts_offset) < (ioval - 7200) || (vo_pts - pts_offset) > (ioval + 7200)) {
648 ioval = (vo_pts + pts_offset) >> 1;
649 ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval);
650 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
651 pts_offset = vo_pts - (ioval << 1);
652 if (pts_offset < 0) {
653 pts_offset = 0;
656 ioval = vo_pts + pts_offset;
657 ioctl(fd_video, EM8300_IOCTL_SPU_SETPTS, &ioval);
658 ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &ioval);
659 prev_pts = vo_pts;
660 } else if (dxr3_prebuf) {
661 ioctl(fd_spu, EM8300_IOCTL_SPU_SETPTS, &vo_pts);
662 ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts);
666 static int draw_slice(uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0)
668 return -1;
671 static void uninit(void)
673 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Uninitializing.\n");
674 #ifdef CONFIG_X11
675 if (dxr3_overlay) {
676 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OFF);
677 overlay_release(overlay_data);
679 vo_x11_uninit();
682 #endif
683 if (old_vmode != -1) {
684 if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &old_vmode) < 0) {
685 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed restoring TV norm!\n");
689 if (fd_video) {
690 close(fd_video);
692 if (fd_spu) {
693 close(fd_spu);
695 if (fd_control) {
696 close(fd_control);
698 #ifdef SPU_SUPPORT
699 if(osdpicbuf) {
700 free(osdpicbuf);
702 if(spued) {
703 free(spued);
705 #endif
708 static void check_events(void)
712 static int preinit(const char *arg)
714 char devname[MAX_STR_SIZE];
715 int fdflags = O_WRONLY;
717 /* Parse commandline */
718 while (arg) {
719 if (!strncmp("prebuf", arg, 6) && !dxr3_prebuf) {
720 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Enabling prebuffering.\n");
721 dxr3_prebuf = 1;
722 } else if (!strncmp("sync", arg, 4) && !dxr3_newsync) {
723 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Using new sync engine.\n");
724 dxr3_newsync = 1;
725 } else if (!strncmp("overlay", arg, 7) && !dxr3_overlay) {
726 #ifdef CONFIG_X11
727 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Using overlay.\n");
728 dxr3_overlay = 1;
729 #else
730 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Error: Overlay requires compiling with X11 libs/headers installed.\n");
731 #endif
732 } else if (!strncmp("norm=", arg, 5)) {
733 arg += 5;
734 // dxr3_norm is 0 (-> don't change norm) by default
735 // but maybe someone changes this in the future
737 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Will set TV norm to: ");
739 if (*arg == '5') {
740 dxr3_norm = 5;
741 mp_msg(MSGT_VO,MSGL_INFO, "NTSC");
742 } else if (*arg == '4') {
743 dxr3_norm = 4;
744 mp_msg(MSGT_VO,MSGL_INFO, "PAL-60");
745 } else if (*arg == '3') {
746 dxr3_norm = 3;
747 mp_msg(MSGT_VO,MSGL_INFO, "PAL");
748 } else if (*arg == '2') {
749 dxr3_norm = 2;
750 mp_tmsg(MSGT_VO,MSGL_INFO, "auto-adjust to movie framerate (PAL/PAL-60)");
751 } else if (*arg == '1') {
752 dxr3_norm = 1;
753 mp_tmsg(MSGT_VO,MSGL_INFO, "auto-adjust to movie framerate (PAL/NTSC)");
754 } else if (*arg == '0') {
755 dxr3_norm = 0;
756 mp_tmsg(MSGT_VO,MSGL_INFO, "Use current norm.");
757 } else {
758 dxr3_norm = 0;
759 mp_tmsg(MSGT_VO,MSGL_INFO, "Unknown norm supplied. Use current norm.");
762 mp_msg(MSGT_VO,MSGL_INFO, ".\n");
763 } else if (arg[0] == '0' || arg[0] == '1' || arg[0] == '2' || arg[0] == '3') {
764 dxr3_device_num = arg[0];
767 arg = strchr(arg, ':');
768 if (arg) {
769 arg++;
774 /* Open the control interface */
775 sprintf(devname, "/dev/em8300-%d", dxr3_device_num);
776 fd_control = open(devname, fdflags);
777 if (fd_control < 1) {
778 /* Fall back to old naming scheme */
779 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Error opening %s for writing, trying /dev/em8300 instead.\n", devname);
780 sprintf(devname, "/dev/em8300");
781 fd_control = open(devname, fdflags);
782 if (fd_control < 1) {
783 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Error opening /dev/em8300 for writing as well!\nBailing out.\n");
784 return -1;
786 } else {
787 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Opened: %s.\n", devname);
790 /* Open the video interface */
791 sprintf(devname, "/dev/em8300_mv-%d", dxr3_device_num);
792 fd_video = open(devname, fdflags);
793 if (fd_video < 0) {
794 /* Fall back to old naming scheme */
795 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_mv instead.\n", devname);
796 sprintf(devname, "/dev/em8300_mv");
797 fd_video = open(devname, fdflags);
798 if (fd_video < 0) {
799 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Error opening /dev/em8300_mv for writing as well!\nBailing out.\n");
800 uninit();
801 return -1;
803 } else {
804 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Opened: %s.\n", devname);
806 strcpy(fdv_name, devname);
808 /* Open the subpicture interface */
809 sprintf(devname, "/dev/em8300_sp-%d", dxr3_device_num);
810 fd_spu = open(devname, fdflags);
811 if (fd_spu < 0) {
812 /* Fall back to old naming scheme */
813 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_sp instead.\n", devname);
814 sprintf(devname, "/dev/em8300_sp");
815 fd_spu = open(devname, fdflags);
816 if (fd_spu < 0) {
817 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Error opening /dev/em8300_sp for writing as well!\nBailing out.\n");
818 uninit();
819 return -1;
821 } else {
822 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Opened: %s.\n", devname);
824 strcpy(fds_name, devname);
826 #ifdef CONFIG_X11
827 if (dxr3_overlay) {
829 /* Fucked up hack needed to enable overlay.
830 * Will be removed as soon as I figure out
831 * how to make it work like it should
833 Display *dpy;
834 overlay_t *ov;
835 XWindowAttributes attribs;
837 dpy = XOpenDisplay(NULL);
838 if (!dpy) {
839 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Unable to open display during overlay hack setup!\n");
840 return -1;
842 XGetWindowAttributes(dpy, RootWindow(dpy, DefaultScreen(dpy)), &attribs);
843 ov = overlay_init(fd_control);
844 overlay_set_screen(ov, attribs.width, attribs.height, PlanesOfScreen(ScreenOfDisplay(dpy, 0)));
845 overlay_read_state(ov, NULL);
846 overlay_set_keycolor(ov, KEY_COLOR);
847 overlay_set_mode(ov, EM8300_OVERLAY_MODE_OVERLAY);
848 overlay_set_mode(ov, EM8300_OVERLAY_MODE_RECTANGLE);
849 overlay_release(ov);
850 XCloseDisplay(dpy);
851 /* End of fucked up hack */
853 /* Initialize overlay and X11 */
854 overlay_data = overlay_init(fd_control);
855 if (!vo_init()) {
856 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Unable to init X11!\n");
857 return -1;
860 #endif
862 if (dxr3_newsync) {
863 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
864 pts_offset = vo_pts - (ioval << 1);
865 if (pts_offset < 0) {
866 pts_offset = 0;
870 return 0;
873 /* Begin overlay.c */
874 static int update_parameters(overlay_t *o)
876 overlay_set_attribute(o, EM9010_ATTRIBUTE_XOFFSET, o->xoffset);
877 overlay_set_attribute(o, EM9010_ATTRIBUTE_YOFFSET, o->yoffset);
878 overlay_set_attribute(o, EM9010_ATTRIBUTE_XCORR, o->xcorr);
879 overlay_set_attribute(o, EM9010_ATTRIBUTE_STABILITY, o->stability);
880 overlay_set_attribute(o, EM9010_ATTRIBUTE_JITTER, o->jitter);
881 return 0;
884 static int overlay_set_attribute(overlay_t *o, int attribute, int value)
886 em8300_attribute_t attr;
888 attr.attribute = attribute;
889 attr.value = value;
890 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SET_ATTRIBUTE, &attr)==-1)
892 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed setting overlay attribute.\n");
893 return -1;
896 return 0;
899 static overlay_t *overlay_init(int dev)
901 overlay_t *o;
903 o = malloc(sizeof(overlay_t));
905 if(!o)
906 return NULL;
908 memset(o,0,sizeof(overlay_t));
910 o->dev = dev;
911 o->xres = 1280; o->yres=1024; o->xcorr=1000;
912 o->color_interval=10;
914 return o;
917 static int overlay_release(overlay_t *o)
919 if(o)
920 free(o);
922 return 0;
924 #define TYPE_INT 1
925 #define TYPE_XINT 2
926 #define TYPE_COEFF 3
927 #define TYPE_FLOAT 4
929 struct lut_entry {
930 char *name;
931 int type;
932 void *ptr;
935 static struct lut_entry *new_lookuptable(overlay_t *o)
937 struct lut_entry m[] = {
938 {"xoffset", TYPE_INT, &o->xoffset},
939 {"yoffset", TYPE_INT, &o->yoffset},
940 {"xcorr", TYPE_INT, &o->xcorr},
941 {"jitter", TYPE_INT, &o->jitter},
942 {"stability", TYPE_INT, &o->stability},
943 {"keycolor", TYPE_XINT, &o->keycolor},
944 {"colcal_upper", TYPE_COEFF, &o->colcal_upper[0]},
945 {"colcal_lower", TYPE_COEFF, &o->colcal_lower[0]},
946 {"color_interval", TYPE_FLOAT, &o->color_interval},
947 {0,0,0}
948 },*p;
950 p = malloc(sizeof(m));
951 memcpy(p,m,sizeof(m));
952 return p;
955 static int lookup_parameter(overlay_t *o, struct lut_entry *lut, char *name, void **ptr, int *type) {
956 int i;
958 for(i=0; lut[i].name; i++) {
959 if(!strcmp(name,lut[i].name)) {
960 *ptr = lut[i].ptr;
961 *type = lut[i].type;
962 return 1;
965 return 0;
968 static int overlay_read_state(overlay_t *o, char *p)
970 char *a,*tok;
971 char path[128],fname[128],tmp[128],line[256];
972 FILE *fp;
973 struct lut_entry *lut;
974 void *ptr;
975 int type;
976 int j;
978 if(!p) {
979 av_strlcpy(fname, getenv("HOME"), sizeof( fname ));
980 av_strlcat(fname,"/.overlay", sizeof( fname ));
981 } else
982 av_strlcpy(fname, p, sizeof( fname ));
984 sprintf(tmp,"/res_%dx%dx%d",o->xres,o->yres,o->depth);
985 av_strlcat(fname, tmp, sizeof( fname ));
987 if(!(fp=fopen(fname,"r")))
988 return -1;
990 lut = new_lookuptable(o);
992 while(!feof(fp)) {
993 if(!fgets(line,256,fp))
994 break;
995 tok=strtok(line," ");
996 if(lookup_parameter(o,lut,tok,&ptr,&type)) {
997 tok=strtok(NULL," ");
998 switch(type) {
999 case TYPE_INT:
1000 sscanf(tok,"%d",(int *)ptr);
1001 break;
1002 case TYPE_XINT:
1003 sscanf(tok,"%x",(int *)ptr);
1004 break;
1005 case TYPE_FLOAT:
1006 sscanf(tok,"%f",(float *)ptr);
1007 break;
1008 case TYPE_COEFF:
1009 for(j=0;j<3;j++) {
1010 sscanf(tok,"%f",&((struct coeff *)ptr)[j].k);
1011 tok=strtok(NULL," ");
1012 sscanf(tok,"%f",&((struct coeff *)ptr)[j].m);
1013 tok=strtok(NULL," ");
1015 break;
1021 update_parameters(o);
1023 free(lut);
1024 fclose(fp);
1025 return 0;
1028 static void overlay_update_params(overlay_t *o) {
1029 update_parameters(o);
1032 static int overlay_write_state(overlay_t *o, char *p)
1034 char *a;
1035 char path[128],fname[128],tmp[128];
1036 FILE *fp;
1037 char line[256],*tok;
1038 struct lut_entry *lut;
1039 int i,j;
1041 if(!p) {
1042 av_strlcpy(fname, getenv("HOME"), sizeof( fname ));
1043 av_strlcat(fname,"/.overlay", sizeof( fname ));
1044 } else
1045 av_strlcpy(fname, p, sizeof( fname ));
1047 if(access(fname, W_OK|X_OK|R_OK)) {
1048 if(mkdir(fname,0766))
1049 return -1;
1052 sprintf(tmp,"/res_%dx%dx%d",o->xres,o->yres,o->depth);
1053 av_strlcat(fname, tmp, sizeof( fname ));
1055 if(!(fp=fopen(fname,"w")))
1056 return -1;
1058 lut = new_lookuptable(o);
1060 for(i=0; lut[i].name; i++) {
1061 fprintf(fp,"%s ",lut[i].name);
1062 switch(lut[i].type) {
1063 case TYPE_INT:
1064 fprintf(fp,"%d\n",*(int *)lut[i].ptr);
1065 break;
1066 case TYPE_XINT:
1067 fprintf(fp,"%06x\n",*(int *)lut[i].ptr);
1068 break;
1069 case TYPE_FLOAT:
1070 fprintf(fp,"%f\n",*(float *)lut[i].ptr);
1071 break;
1072 case TYPE_COEFF:
1073 for(j=0;j<3;j++)
1074 fprintf(fp,"%f %f ",((struct coeff *)lut[i].ptr)[j].k,
1075 ((struct coeff *)lut[i].ptr)[j].m);
1076 fprintf(fp,"\n");
1077 break;
1081 fclose(fp);
1082 return 0;
1085 static int overlay_set_screen(overlay_t *o, int xres, int yres, int depth)
1087 em8300_overlay_screen_t scr;
1089 o->xres = xres;
1090 o->yres = yres;
1091 o->depth = depth;
1093 scr.xsize = xres;
1094 scr.ysize = yres;
1096 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETSCREEN, &scr)==-1)
1098 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed setting overlay screen!\nExiting.\n");
1099 return -1;
1101 return 0;
1104 static int overlay_set_mode(overlay_t *o, int mode)
1106 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETMODE, &mode)==-1) {
1107 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed enabling overlay!\nExiting.\n");
1108 return -1;
1110 return 0;
1113 static int overlay_set_window(overlay_t *o, int xpos,int ypos,int width,int height)
1115 em8300_overlay_window_t win;
1116 win.xpos = xpos;
1117 win.ypos = ypos;
1118 win.width = width;
1119 win.height = height;
1121 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETWINDOW, &win)==-1)
1123 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed resizing overlay window!\n");
1124 return -1;
1126 return 0;
1129 static int overlay_set_bcs(overlay_t *o, int brightness, int contrast, int saturation)
1131 em8300_bcs_t bcs;
1132 bcs.brightness = brightness;
1133 bcs.contrast = contrast;
1134 bcs.saturation = saturation;
1136 if (ioctl(o->dev, EM8300_IOCTL_GETBCS, &bcs)==-1)
1138 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed setting overlay bcs!\n");
1139 return -1;
1141 return 0;
1144 static int col_interp(float x, struct coeff c)
1146 float y;
1147 y = x*c.k + c.m;
1148 if(y > 255)
1149 y = 255;
1150 if(y < 0)
1151 y = 0;
1152 return rint(y);
1155 static int overlay_set_keycolor(overlay_t *o, int color) {
1156 int r = (color & 0xff0000) >> 16;
1157 int g = (color & 0x00ff00) >> 8;
1158 int b = (color & 0x0000ff);
1159 float ru,gu,bu;
1160 float rl,gl,bl;
1161 int upper,lower;
1163 ru = r+o->color_interval;
1164 gu = g+o->color_interval;
1165 bu = b+o->color_interval;
1167 rl = r-o->color_interval;
1168 gl = g-o->color_interval;
1169 bl = b-o->color_interval;
1171 upper = (col_interp(ru, o->colcal_upper[0]) << 16) |
1172 (col_interp(gu, o->colcal_upper[1]) << 8) |
1173 (col_interp(bu, o->colcal_upper[2]));
1175 lower = (col_interp(rl, o->colcal_lower[0]) << 16) |
1176 (col_interp(gl, o->colcal_lower[1]) << 8) |
1177 (col_interp(bl, o->colcal_lower[2]));
1179 //printf("0x%06x 0x%06x\n",upper,lower);
1180 overlay_set_attribute(o,EM9010_ATTRIBUTE_KEYCOLOR_UPPER,upper);
1181 overlay_set_attribute(o,EM9010_ATTRIBUTE_KEYCOLOR_LOWER,lower);
1182 return 0;
1185 static void least_sq_fit(int *x, int *y, int n, float *k, float *m)
1187 float sx=0,sy=0,sxx=0,sxy=0;
1188 float delta,b;
1189 int i;
1191 for(i=0; i < n; i++) {
1192 sx=sx+x[i];
1193 sy=sy+y[i];
1194 sxx=sxx+x[i]*x[i];
1195 sxy=sxy+x[i]*y[i];
1198 delta=sxx*n-sx*sx;
1200 *m=(sxx*sy-sx*sxy)/delta;
1201 *k=(sxy*n-sx*sy)/delta;
1204 static int overlay_autocalibrate(overlay_t *o, pattern_drawer_cb pd, void *arg)
1206 em8300_overlay_calibrate_t cal;
1207 em8300_overlay_window_t win;
1208 int x[256],r[256],g[256],b[256],n;
1209 float k,m;
1211 int i;
1213 o->draw_pattern=pd;
1214 o->dp_arg = arg;
1216 overlay_set_mode(o, EM8300_OVERLAY_MODE_OVERLAY);
1217 overlay_set_screen(o, o->xres, o->yres, o->depth);
1219 /* Calibrate Y-offset */
1221 o->draw_pattern(0x0000ff, 0, 0, 0, 355, 1, o->dp_arg);
1223 cal.cal_mode = EM8300_OVERLAY_CALMODE_YOFFSET;
1224 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1226 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed getting overlay Y-offset values!\nExiting.\n");
1227 return -1;
1229 o->yoffset = cal.result;
1230 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Yoffset: %d.\n",cal.result);
1232 /* Calibrate X-offset */
1234 o->draw_pattern(0x0000ff, 0, 0, 0, 2, 288, o->dp_arg);
1236 cal.cal_mode = EM8300_OVERLAY_CALMODE_XOFFSET;
1237 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1239 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed getting overlay X-offset values!\nExiting.\n");
1240 return -1;
1242 o->xoffset = cal.result;
1243 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Xoffset: %d.\n",cal.result);
1245 /* Calibrate X scale correction */
1247 o->draw_pattern(0x0000ff, 0, 355, 0, 2, 288, o->dp_arg);
1249 cal.cal_mode = EM8300_OVERLAY_CALMODE_XCORRECTION;
1250 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1252 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed getting overlay X scale correction!\nExiting.\n");
1253 return -1;
1255 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_DXR3] Xcorrection: %d.\n",cal.result);
1256 o->xcorr = cal.result;
1258 win.xpos = 10;
1259 win.ypos = 10;
1260 win.width = o->xres-20;
1261 win.height = o->yres-20;
1262 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETWINDOW, &win)==-1) {
1263 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_DXR3] Failed resizing overlay window!\n");
1264 exit(1);
1267 /* Calibrate key color upper limit */
1269 for(i=128,n=0; i <= 0xff; i+=4) {
1270 o->draw_pattern(i | (i << 8) | (i << 16), 0,
1271 (o->xres-200)/2,0,200,o->yres,o->dp_arg);
1273 cal.arg = i;
1274 cal.arg2 = 1;
1275 cal.cal_mode = EM8300_OVERLAY_CALMODE_COLOR;
1277 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1279 return -1 ;
1282 x[n] = i;
1283 r[n] = (cal.result>>16)&0xff;
1284 g[n] = (cal.result>>8)&0xff;
1285 b[n] = (cal.result)&0xff;
1286 n++;
1289 least_sq_fit(x,r,n,&o->colcal_upper[0].k,&o->colcal_upper[0].m);
1290 least_sq_fit(x,g,n,&o->colcal_upper[1].k,&o->colcal_upper[1].m);
1291 least_sq_fit(x,b,n,&o->colcal_upper[2].k,&o->colcal_upper[2].m);
1293 /* Calibrate key color lower limit */
1295 for(i=128,n=0; i <= 0xff; i+=4) {
1296 o->draw_pattern(i | (i << 8) | (i << 16), 0xffffff,
1297 (o->xres-200)/2,0,200,o->yres, o->dp_arg);
1299 cal.arg = i;
1300 cal.arg2 = 2;
1301 cal.cal_mode = EM8300_OVERLAY_CALMODE_COLOR;
1303 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1305 return -1 ;
1307 x[n] = i;
1308 r[n] = (cal.result>>16)&0xff;
1309 g[n] = (cal.result>>8)&0xff;
1310 b[n] = (cal.result)&0xff;
1311 n++;
1314 least_sq_fit(x,r,n,&o->colcal_lower[0].k,&o->colcal_lower[0].m);
1315 least_sq_fit(x,g,n,&o->colcal_lower[1].k,&o->colcal_lower[1].m);
1316 least_sq_fit(x,b,n,&o->colcal_lower[2].k,&o->colcal_lower[2].m);
1318 overlay_set_mode(o, EM8300_OVERLAY_MODE_OFF);
1320 return 0;
1324 static int overlay_signalmode(overlay_t *o, int mode) {
1325 if(ioctl(o->dev, EM8300_IOCTL_OVERLAY_SIGNALMODE, &mode) ==-1) {
1326 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_DXR3] Failed to set signal mix!\n");
1327 return -1;
1329 return 0;
1331 /* End overlay.c */