📄 main.c
字号:
/* * main.c * * ============================================================================ * Copyright (c) Texas Instruments Inc 2005 * * Use of this software is controlled by the terms and conditions found in the * license agreement under which this software has been supplied or provided. * ============================================================================ */#include <stdio.h>#include <stdlib.h>#include <getopt.h>#include <unistd.h>#include <string.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <fcntl.h>#include <linux/fb.h> // devfb#include "interface.h"/* Custom Davinci FBDEV defines */#define VID0_INDEX 0#define VID1_INDEX 1#define ZOOM_1X 0#define ZOOM_2X 1#define ZOOM_4X 2struct Zoom_Params{ u_int32_t WindowID; u_int32_t Zoom_H; u_int32_t Zoom_V;};#define FBIO_SETZOOM _IOW('F', 0x24, struct Zoom_Params)#define FBIO_WAITFORVSYNC _IOW('F', 0x20, u_int32_t)#define FBIO_GETSTD _IOR('F', 0x25, u_int32_t)/* Video window to show diagram on */#define FBVID_DEVICE "/dev/fb/3"#define OSD_DEVICE "/dev/fb/0"#define ATTR_DEVICE "/dev/fb/2"#define UYVY_BLACK 0x10801080enum InitLevels { SCREENINITIALIZED = 1};/* Global variable declarations for this application */pthread_mutex_t dataMutex;GlobalData gbl = { NULL, NTSC };static int startLevel = 0;static int launch = 0;/****************************************************************************** * drawDiagram ******************************************************************************/int drawDiagram(char *diagram){ struct fb_var_screeninfo varInfo; struct Zoom_Params zoom; int fd; int size; int i; int fileFd; int numBytes; char *src; char *dst; fd = open(FBVID_DEVICE, O_RDWR); if (fd == -1) { ERR("Failed to open fb device %s (%s)\n", FBVID_DEVICE, strerror(errno)); return FAILURE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &varInfo) == -1) { ERR("Failed FBIOGET_VSCREENINFO on %s (%s)\n", FBVID_DEVICE, strerror(errno)); return FAILURE; } varInfo.yoffset = 0; /* Swap the working buffer for the displayed buffer */ if (ioctl(fd, FBIOPAN_DISPLAY, &varInfo) == -1) { ERR("Failed FBIOPAN_DISPLAY (%s)\n", strerror(errno)); return FAILURE; } size = varInfo.xres * varInfo.yres * varInfo.bits_per_pixel / 8; dst = (char *) mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); /* Map the video buffer to user space */ if (dst == MAP_FAILED) { ERR("Failed mmap on %s (%s)\n", FBVID_DEVICE, strerror(errno)); return FAILURE; } fileFd = open(diagram, O_RDONLY); if (fileFd == -1) { ERR("Failed to open demo diagram file (%s)\n", strerror(errno)); return FAILURE; } src = malloc(size); if (src == NULL) { ERR("Failed to allocate memory for diagram\n"); return FAILURE; } numBytes = read(fileFd, src, size); if (numBytes != size) { ERR("Error reading data from diagram file (%s)\n", strerror(errno)); return FAILURE; } for (i=0; i<size; i++) { dst[i] = src[i]; } zoom.WindowID = VID1_INDEX; zoom.Zoom_H = ZOOM_1X; zoom.Zoom_V = ZOOM_1X; if (ioctl(fd, FBIO_SETZOOM, &zoom)) { ERR("Failed setting zoom parameters\n"); return FAILURE; } free(src); munmap(src, size); close(fd); close(fileFd); return SUCCESS;}/****************************************************************************** * screenInit ******************************************************************************/static int screenInit(void){ struct fb_var_screeninfo varInfo; int fd; int std; unsigned short *display; fd = open(OSD_DEVICE, O_RDWR); if (fd == -1) { ERR("Failed to open fb device %s\n", OSD_DEVICE); return FAILURE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &varInfo) == -1) { ERR("Failed ioctl FBIOGET_VSCREENINFO on %s\n", OSD_DEVICE); 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) { setYFactor(NTSC); } else { setYFactor(PAL); } /* Try the requested size */ varInfo.xres = SCREEN_WIDTH; varInfo.yres = SCREEN_HEIGHT; varInfo.bits_per_pixel = SCREEN_BPP; if (ioctl(fd, FBIOPUT_VSCREENINFO, &varInfo) == -1) { ERR("Failed ioctl FBIOPUT_VSCREENINFO on %s\n", OSD_DEVICE); return FAILURE; } if (varInfo.xres != SCREEN_WIDTH || varInfo.yres != SCREEN_HEIGHT || varInfo.bits_per_pixel != SCREEN_BPP) { ERR("Failed to get the requested screen size: %dx%d at %d bpp\n", SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); } display = (unsigned short *) mmap(NULL, SCREEN_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (display == MAP_FAILED) { ERR("Failed mmap on %s\n", OSD_DEVICE); return FAILURE; } setDisplay(display); return fd;}/****************************************************************************** * setOsdTransparency ******************************************************************************/int setOsdTransparency(unsigned char trans){ struct fb_var_screeninfo vInfo; unsigned short *attrDisplay; int attrSize; int fd; fd = open(ATTR_DEVICE, O_RDWR); if (fd == -1) { ERR("Failed to open attribute window %s\n", ATTR_DEVICE); return FAILURE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &vInfo) == -1) { ERR("Error reading variable information.\n"); return FAILURE; } /* One nibble per pixel */ attrSize = vInfo.xres_virtual * vInfo.yres / 2; attrDisplay = (unsigned short *) mmap(NULL, attrSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (attrDisplay == MAP_FAILED) { ERR("Failed mmap on %s\n", ATTR_DEVICE); return FAILURE; } /* Fill the window with the new attribute value */ memset(attrDisplay, trans, attrSize); munmap(attrDisplay, attrSize); close(fd); return SUCCESS;}/****************************************************************************** * launchDemo ******************************************************************************/int launchDemo(DemoEnv *envp){ char *argv[10]; char *extension; /* Note that the malloc:s are freed up by execv */ switch (envp->demoSelect) { /* Launch encodedecode demo */ case ENCDEC: argv[0] = malloc(strlen("./encodedecode") + 1); if (argv[0] == NULL) { return FAILURE; } strcpy(argv[0], "./encodedecode"); argv[1] = malloc(strlen("-i" + 1)); if (argv[1] == NULL) { return FAILURE; } strcpy(argv[1], "-i"); argv[2] = malloc(strlen("-r" + 1)); if (argv[2] == NULL) { return FAILURE; } strcpy(argv[2], "-r"); if (envp->resolution == ZOOM) { argv[3] = malloc(strlen("ZOOM") + 1); if (argv[3] == NULL) { return FAILURE; } strcpy(argv[3], "ZOOM"); } else { argv[3] = malloc(strlen("CIF") + 1); if (argv[3] == NULL) { return FAILURE; } strcpy(argv[3], "CIF"); } argv[4] = NULL; if (execv("./encodedecode", argv) == -1) { return FAILURE; } break; /* Launch encode demo */ case ENC: argv[0] = malloc(strlen("./encode") + 1); if (argv[0] == NULL) { return FAILURE; } strcpy(argv[0], "./encode"); argv[1] = malloc(strlen("-i" + 1)); if (argv[1] == NULL) { return FAILURE; } strcpy(argv[1], "-i"); argv[2] = malloc(strlen("-v") + 1); if (argv[2] == NULL) { return FAILURE; } strcpy(argv[2], "-v");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -