vo_dxr3.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,483 行 · 第 1/3 页
C
1,483 行
ioval = EM8300_VIDEOMODE_NTSC; } else { ioval = EM8300_VIDEOMODE_PAL; } mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoSelectedTVNormByFrameRate); ioval == EM8300_VIDEOMODE_NTSC ? mp_msg(MSGT_VO,MSGL_INFO, "NTSC") : mp_msg(MSGT_VO,MSGL_INFO, "PAL"); printf(".\n"); } if (old_vmode != ioval) { if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &ioval) < 0) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetTVNorm); } } } /* libavcodec requires a width and height that is x|16 */ aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); ioctl(fd_control, EM8300_IOCTL_GET_VIDEOMODE, &ioval); if (ioval == EM8300_VIDEOMODE_NTSC) { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingUpForNTSC); aspect_save_screenres(352, 240); } else { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingUpForPALSECAM); aspect_save_screenres(352, 288); } aspect(&s_width, &s_height, A_ZOOM); s_width -= s_width % 16; s_height -= s_height % 16; /* Try to figure out whether to use widescreen output or not */ /* Anamorphic widescreen modes makes this a pain in the ass */ tmp1 = abs(d_height - ((d_width / 4) * 3)); tmp2 = abs(d_height - (int) (d_width / 2.35)); if (tmp1 < tmp2) { ioval = EM8300_ASPECTRATIO_4_3; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingAspectRatioTo43); } else { ioval = EM8300_ASPECTRATIO_16_9; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingAspectRatioTo169); } ioctl(fd_control, EM8300_IOCTL_SET_ASPECTRATIO, &ioval);#ifdef SPU_SUPPORT#ifdef HAVE_FREETYPE if (ioval == EM8300_ASPECTRATIO_16_9) { s_width *= d_height*1.78/s_height*(d_width*1.0/d_height)/2.35; } else { s_width *= 0.84; } //printf("VO: [dxr3] sw/sh:dw/dh ->%i,%i,%i,%i\n",s_width,s_height,d_width,d_height);#else s_width*=2; s_height*=2;#endif osdpicbuf = calloc( 1,s_width * s_height); if (osdpicbuf == NULL) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory); return -1; } spued = (encodedata *) malloc(sizeof(encodedata)); if (spued == NULL) { free( osdpicbuf ); mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory); return -1; } spubuf = (encodedata *) malloc(sizeof(encodedata)); if (spubuf == NULL) { free( osdpicbuf ); free( spued ); mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory); return -1; } osd_w = s_width; osd_h = s_height; osdpicbuf_w = s_width; osdpicbuf_h = s_height; spubuf->count=0; pixbuf_encode_rle( 0,0,osdpicbuf_w,osdpicbuf_h - 1,osdpicbuf,osdpicbuf_w,spubuf );#endif#ifdef HAVE_X11 if (dxr3_overlay) { XVisualInfo vinfo; XSetWindowAttributes xswa; XSizeHints hint; unsigned long xswamask; Colormap cmap; XColor key_color; Window junkwindow; Screen *scr; int depth, red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec, acq_color; em8300_overlay_screen_t ovlscr; em8300_attribute_t ovlattr; vo_dx = (vo_screenwidth - d_width) / 2; vo_dy = (vo_screenheight - d_height) / 2; vo_dwidth = d_width; vo_dheight = d_height;#ifdef HAVE_NEW_GUI if (use_gui) { guiGetEvent(guiSetShVideo, 0); XSetWindowBackground(mDisplay, vo_window, KEY_COLOR); XClearWindow(mDisplay, vo_window); XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &xwin_attribs); depth = xwin_attribs.depth; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) { depth = 24; } XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); } else#endif { XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &xwin_attribs); depth = xwin_attribs.depth; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) { depth = 24; } XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags, CopyFromParent, "Viewing Window", title); xswa.background_pixel = KEY_COLOR; xswa.border_pixel = 0; xswamask = CWBackPixel | CWBorderPixel; XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); } /* Start setting up overlay */ XGetWindowAttributes(mDisplay, mRootWin, &xwin_attribs); overlay_set_screen(overlay_data, xwin_attribs.width, xwin_attribs.height, xwin_attribs.depth); overlay_read_state(overlay_data, NULL); /* Allocate keycolor */ cmap = vo_x11_create_colormap(&vinfo); calculate_cvals(vinfo.red_mask, &red_shift, &red_prec); calculate_cvals(vinfo.green_mask, &green_shift, &green_prec); calculate_cvals(vinfo.blue_mask, &blue_shift, &blue_prec); key_color.red = ((KEY_COLOR >> 16) & 0xff) * 256; key_color.green = ((KEY_COLOR >> 8) & 0xff) * 256; key_color.blue = (KEY_COLOR & 0xff) * 256; key_color.pixel = (((key_color.red >> (16 - red_prec)) << red_shift) + ((key_color.green >> (16 - green_prec)) << green_shift) + ((key_color.blue >> (16 - blue_prec)) << blue_shift)); key_color.flags = DoRed | DoGreen | DoBlue; if (!XAllocColor(mDisplay, cmap, &key_color)) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToAllocateKeycolor); return -1; } acq_color = ((key_color.red / 256) << 16) | ((key_color.green / 256) << 8) | key_color.blue; if (key_color.pixel != KEY_COLOR) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToAllocateExactKeycolor, key_color.pixel); } /* Set keycolor and activate overlay */ XSetWindowBackground(mDisplay, vo_window, key_color.pixel); XClearWindow(mDisplay, vo_window); overlay_set_keycolor(overlay_data, key_color.pixel); overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OVERLAY); overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_RECTANGLE); } if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop);#endif return 0;}static void draw_alpha(int x, int y, int w, int h, unsigned char* src, unsigned char *srca, int srcstride){#ifdef SPU_SUPPORT unsigned char *buf = &osdpicbuf[(y * osdpicbuf_w) + x]; int by = 0; register int lx, ly; register int stride = 0; for (ly = 0; ly < h - 1; ly++) { for(lx = 0; lx < w; lx++ ) if ( ( srca[stride + lx] )&&( src[stride + lx] >= 128 ) ) buf[by + lx] = 3; by+=osdpicbuf_w; stride+=srcstride; } pixbuf_encode_rle(x, y, osdpicbuf_w, osdpicbuf_h - 1, osdpicbuf, osdpicbuf_w, spued);#endif}extern int vo_osd_changed_flag;extern mp_osd_obj_t* vo_osd_list;static void draw_osd(void){#ifdef SPU_SUPPORT static int cleared = 0; int changed = 0; if ((disposd % 15) == 0) { { mp_osd_obj_t* obj = vo_osd_list; vo_update_osd( osd_w,osd_h ); while( obj ) { if ( obj->flags & OSDFLAG_VISIBLE ) { changed=1; break; } obj=obj->next; } } if ( changed ) { vo_draw_text(osd_w, osd_h, draw_alpha); memset(osdpicbuf, 0, s_width * s_height); cleared=0; } else { if ( !cleared ) { spued->count=spubuf->count; fast_memcpy( spued->data,spubuf->data,DATASIZE ); cleared=1; } } /* could stand some check here to see if the subpic hasn't changed * as if it hasn't and we re-send it it will "blink" as the last one * is turned off, and the new one (same one) is turned on *//* Subpics are not stable yet =( expect lockups if you enable */#if 1 write(fd_spu, spued->data, spued->count);#endif } disposd++;#endif}static int draw_frame(uint8_t * src[]){ vo_mpegpes_t *p = (vo_mpegpes_t *) src[0];#ifdef SPU_SUPPORT if (p->id == 0x20) { write(fd_spu, p->data, p->size); } else#endif write(fd_video, p->data, p->size); return 0;}static void flip_page(void){#ifdef HAVE_X11 if (dxr3_overlay) { int event = vo_x11_check_events(mDisplay); if (event & VO_EVENT_RESIZE) { Window junkwindow; XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs); XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow); overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height); } if (event & VO_EVENT_EXPOSE) { Window junkwindow; XSetWindowBackground(mDisplay, vo_window, KEY_COLOR); XClearWindow(mDisplay, vo_window); XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs); XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow); overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height); } }#endif if (dxr3_newsync) { ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval); ioval <<= 1; if (vo_pts == 0) { ioval = 0; ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval); pts_offset = 0; } else if ((vo_pts - pts_offset) < (ioval - 7200) || (vo_pts - pts_offset) > (ioval + 7200)) { ioval = (vo_pts + pts_offset) >> 1; ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval); ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval); pts_offset = vo_pts - (ioval << 1); if (pts_offset < 0) { pts_offset = 0; } } ioval = vo_pts + pts_offset; ioctl(fd_video, EM8300_IOCTL_SPU_SETPTS, &ioval); ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &ioval); prev_pts = vo_pts; } else if (dxr3_prebuf) { ioctl(fd_spu, EM8300_IOCTL_SPU_SETPTS, &vo_pts); ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts); }}static int draw_slice(uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0){ return -1;}static void uninit(void){ mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Uninitializing);#ifdef HAVE_X11 if (dxr3_overlay) { overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OFF); overlay_release(overlay_data); #ifdef HAVE_NEW_GUI if (!use_gui) {#endif vo_x11_uninit();#ifdef HAVE_NEW_GUI }#endif }#endif if (old_vmode != -1) { if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &old_vmode) < 0) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedRestoringTVNorm); } } if (fd_video) { close(fd_video); } if (fd_spu) { close(fd_spu); } if (fd_control) { close(fd_control); }#ifdef SPU_SUPPORT if(osdpicbuf) { free(osdpicbuf); } if(spued) { free(spued); }#endif}static void check_events(void){}static int preinit(const char *arg){ char devname[MAX_STR_SIZE]; int fdflags = O_WRONLY; /* Parse commandline */ while (arg) { if (!strncmp("prebuf", arg, 6) && !dxr3_prebuf) { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_EnablingPrebuffering); dxr3_prebuf = 1; } else if (!strncmp("sync", arg, 4) && !dxr3_newsync) { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UsingNewSyncEngine); dxr3_newsync = 1; } else if (!strncmp("overlay", arg, 7) && !dxr3_overlay) {#ifdef HAVE_X11 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UsingOverlay); dxr3_overlay = 1;#else mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorYouNeedToCompileMplayerWithX11);#endif } else if (!strncmp("norm=", arg, 5)) { arg += 5; // dxr3_norm is 0 (-> don't change norm) by default // but maybe someone changes this in the future mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_WillSetTVNormTo); if (*arg == '5') { dxr3_norm = 5; mp_msg(MSGT_VO,MSGL_INFO, "NTSC"); } else if (*arg == '4') { dxr3_norm = 4; mp_msg(MSGT_VO,MSGL_INFO, "PAL-60"); } else if (*arg == '3') { dxr3_norm = 3; mp_msg(MSGT_VO,MSGL_INFO, "PAL"); } else if (*arg == '2') { dxr3_norm = 2; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALPAL60); } else if (*arg == '1') { dxr3_norm = 1; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALNTSC); } else if (*arg == '0') { dxr3_norm = 0; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UseCurrentNorm); } else { dxr3_norm = 0; mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UseUnknownNormSuppliedCurrentNorm); } mp_msg(MSGT_VO,MSGL_INFO, ".\n"); } else if (arg[0] == '0' || arg[0] == '1' || arg[0] == '2' || arg[0] == '3') { dxr3_device_num = arg[0]; } arg = strchr(arg, ':'); if (arg) { arg++; } } /* Open the control interface */ sprintf(devname, "/dev/em8300-%d", dxr3_device_num); fd_control = open(devname, fdflags); if (fd_control < 1) { /* Fall back to old naming scheme */ mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTrying, devname); sprintf(devname, "/dev/em8300"); fd_control = open(devname, fdflags); if (fd_control < 1) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWell); return -1; } } else { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname); } /* Open the video interface */ sprintf(devname, "/dev/em8300_mv-%d", dxr3_device_num); fd_video = open(devname, fdflags); if (fd_video < 0) { /* Fall back to old naming scheme */ mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingMV, devname); sprintf(devname, "/dev/em8300_mv"); fd_video = open(devname, fdflags); if (fd_video < 0) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellMV); uninit(); return -1; } } else { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname); } strcpy(fdv_name, devname); /* Open the subpicture interface */ sprintf(devname, "/dev/em8300_sp-%d", dxr3_device_num); fd_spu = open(devname, fdflags); if (fd_spu < 0) { /* Fall back to old naming scheme */ mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingSP, devname); sprintf(devname, "/dev/em8300_sp"); fd_spu = open(devname, fdflags); if (fd_spu < 0) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellSP); uninit(); return -1; } } else { mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname); } strcpy(fds_name, devname); #ifdef HAVE_X11 if (dxr3_overlay) { /* Fucked up hack needed to enable overlay. * Will be removed as soon as I figure out * how to make it work like it should */ Display *dpy; overlay_t *ov; XWindowAttributes attribs; dpy = XOpenDisplay(NULL); if (!dpy) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToOpenDisplayDuringHackSetup); return -1; } XGetWindowAttributes(dpy, RootWindow(dpy, DefaultScreen(dpy)), &attribs); ov = overlay_init(fd_control); overlay_set_screen(ov, attribs.width, attribs.height, PlanesOfScreen(ScreenOfDisplay(dpy, 0))); overlay_read_state(ov, NULL);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?