📄 init_osd0.c
字号:
#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <asm/page.h>#include <linux/fb.h>#include "davinci_fb.h"#define NUM_BUFS 2#define SCREEN_BPP 16#define D1_WIDTH 720#define D1_HEIGHT (((480) * yfactor) / 10)#define D1_LINE_WIDTH (D1_WIDTH * SCREEN_BPP / 8)#define D1_FRAME_SIZE (D1_LINE_WIDTH * D1_HEIGHT)/* Scaling factors for the video standards */#define PAL 12#define NTSC 10#define UYVY_BLACK 0x10801080/* Custom Davinci FBDEV defines */#define VID0_INDEX 0#define VID1_INDEX 1#define ZOOM_1X 0#define ZOOM_2X 1#define ZOOM_4X 2static int yfactor = 1;/****************************************************************************** * initDisplayDevice ******************************************************************************/static int initDisplayDevice(char *displays[]){ struct fb_var_screeninfo varInfo; struct Zoom_Params zoom; unsigned int *buf; int fd; int i; int std; fd = open(OSD_DEVICE, O_RDWR); if (fd == -1) { ERR("Failed to open fb device %s (%s)\n", OSD_DEVICE, strerror(errno)); return FAILURE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &varInfo) == -1) { ERR("Failed FBIOGET_VSCREENINFO on %s (%s)\n", OSD_DEVICE, strerror(errno)); return FAILURE; } if (ioctl(fd, FBIO_GETSTD, &std) == -1) { ERR("Failed to get video standard from display device driver\n"); return FAILURE; } if ((std >> 16) == 0x1) { yfactor = NTSC; } else { yfactor = PAL; } varInfo.xres = D1_WIDTH; varInfo.yres = D1_HEIGHT; varInfo.bits_per_pixel = SCREEN_BPP; if (ioctl(fd, FBIOPUT_VSCREENINFO, &varInfo) == -1) { ERR("Failed FBIOPUT_VSCREENINFO on %s (%s)\n", OSD_DEVICE, strerror(errno)); return FAILURE; } if (varInfo.xres != D1_WIDTH || varInfo.yres != D1_HEIGHT || varInfo.bits_per_pixel != SCREEN_BPP) { ERR("Failed to get the requested screen size: %dx%d at %d bpp\n", D1_WIDTH, D1_HEIGHT, SCREEN_BPP); return FAILURE; } /* Map the video buffer to user space */ displays[0] = (char *) mmap (NULL, D1_FRAME_SIZE * NUM_BUFS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (displays[0] == MAP_FAILED) { ERR("Failed mmap on %s (%s)\n", OSD_DEVICE, strerror(errno)); return FAILURE; } /* Clear the video buffers */ buf = (unsigned int *) displays[0]; for (i=0; i<D1_FRAME_SIZE * NUM_BUFS / sizeof(unsigned int); i++) { buf[i] = UYVY_BLACK; } for (i=0; i<NUM_BUFS-1; i++) { displays[i+1] = displays[i] + D1_FRAME_SIZE; } return fd;}int init_osd0(){ int fbFd; char *displays[NUM_BUFS]; double randnum; short randcolor; fbFd = initDisplayDevice(displays); if (fbFd == FAILURE) { ERR("init display device: %s error.\n", OSD_DEVICE); return FAILURE; } srandom(time(NULL)); randnum = random(); randcolor = 1 + (unsigned char) (255.0 * randnum / (float)(RAND_MAX + 1.0)); DBG("rand:%f[0x%x], randcolor: %d\n", randnum, RAND_MAX, randcolor); memset(displays[0],randcolor,D1_FRAME_SIZE * NUM_BUFS); close(fbFd); return SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -