⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unichrome_vid.c

📁 linux下的MPEG1
💻 C
📖 第 1 页 / 共 2 页
字号:
	else	{		// Enable extended FIFO		outb(0x17, 0x3c4); outb(0x2f, 0x3c5);		outb(0x16, 0x3c4); outb((mclk_save[0] & 0xf0) | 0x14, 0x3c5);		outb(0x18, 0x3c4); outb(0x56, 0x3c5);		*extfifo_on = 1;	}}static void uc_ovl_vcmd_wait(volatile uint8_t* vio){	while ((VIDEO_IN(vio, V_COMPOSE_MODE)		& (V1_COMMAND_FIRE | V3_COMMAND_FIRE)));}int vixProbe(int verbose, int force){	pciinfo_t lst[MAX_PCI_DEVICES];	unsigned i,num_pci;	int err;	err = pci_scan(lst,&num_pci);	if(err)	{		printf("[unichrome] Error occurred during pci scan: %s\n",strerror(err));		return err;	}	else	{		err = ENXIO;		for(i=0; i < num_pci; i++)		{			if(lst[i].vendor == VENDOR_VIA2)			{				int idx;				const char *dname;				idx = find_chip(lst[i].device);				if(idx == -1)					continue;				dname = pci_device_name(VENDOR_VIA2, lst[i].device);				dname = dname ? dname : "Unknown chip";				printf("[unichrome] Found chip: %s\n", dname);				uc_cap.device_id = lst[i].device;				err = 0;				memcpy(&pci_info, &lst[i], sizeof(pciinfo_t));				break;			}		}	}	if(err && verbose) printf("[unichrome] Can't find chip\n");		return err;}int vixInit(const char *args){	long tmp;	uc_mem = map_phys_mem(pci_info.base0, 0x800000); 	enable_app_io();	outb(0x2f, 0x3c4);	tmp = inb(0x3c5) << 0x18;	vio = map_phys_mem(tmp,0x1000);	outb(0x16, 0x3c4); mclk_save[0] = inb(0x3c5);	outb(0x17, 0x3c4); mclk_save[1] = inb(0x3c5);	outb(0x18, 0x3c4); mclk_save[2] = inb(0x3c5);	uc_grkey.ckey.blue  = 0x00;	uc_grkey.ckey.green = 0x00;	uc_grkey.ckey.red   = 0x00;#ifdef DEBUG_LOGFILE	logfile=fopen("/tmp/uc_vidix.log","w");#endif	return 0;}void vixDestroy(void){#ifdef DEBUG_LOGFILE	if(logfile)		fclose(logfile);#endif	outb(0x16, 0x3c4); outb(mclk_save[0], 0x3c5);	outb(0x17, 0x3c4); outb(mclk_save[1], 0x3c5);	outb(0x18, 0x3c4); outb(mclk_save[2], 0x3c5);	disable_app_io();	unmap_phys_mem(uc_mem, 0x800000); 	unmap_phys_mem(vio, 0x1000);}int vixGetCapability(vidix_capability_t *to){	memcpy(to, &uc_cap, sizeof(vidix_capability_t));	return 0;}static int is_supported_fourcc(uint32_t fourcc){	switch(fourcc)	{		case IMGFMT_YV12:		case IMGFMT_I420:		case IMGFMT_UYVY:		case IMGFMT_YVYU:		case IMGFMT_YUY2:		case IMGFMT_BGR15:		case IMGFMT_BGR16:		case IMGFMT_BGR32:			return 1;		default:			return 0;	}}int vixQueryFourcc(vidix_fourcc_t *to){	if(is_supported_fourcc(to->fourcc))	{		to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP |			VID_DEPTH_4BPP | VID_DEPTH_8BPP |			VID_DEPTH_12BPP| VID_DEPTH_15BPP|			VID_DEPTH_16BPP| VID_DEPTH_24BPP|			VID_DEPTH_32BPP;		to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY;		return 0;	}	else		to->depth = to->flags = 0;	return ENOSYS;}int vixGetGrKeys(vidix_grkey_t *grkey){	memcpy(grkey, &uc_grkey, sizeof(vidix_grkey_t));	return(0);}int vixSetGrKeys(const vidix_grkey_t *grkey){	unsigned long dwCompose = VIDEO_IN(vio, V_COMPOSE_MODE) & ~0x0f;	memcpy(&uc_grkey, grkey, sizeof(vidix_grkey_t));	if (uc_grkey.ckey.op != CKEY_FALSE)	{		// Set colorkey		// (how do I detect BPP in hardware??)		unsigned long ckey;		if (1)	// Assume 16-bit graphics		{			ckey = (grkey->ckey.blue & 0x1f)				| ((grkey->ckey.green & 0x3f) << 5)				| ((grkey->ckey.red & 0x1f) << 11);		}		else		{			ckey = (grkey->ckey.blue)				| (grkey->ckey.green << 8)				| (grkey->ckey.red << 16);		}		VIDEO_OUT(vio, V_COLOR_KEY, ckey);		dwCompose |= SELECT_VIDEO_IF_COLOR_KEY;	}	// Execute the changes	VIDEO_OUT(vio, V_COMPOSE_MODE, dwCompose | V1_COMMAND_FIRE);	return(0);}vidix_video_eq_t equal ={	VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | VEQ_CAP_HUE,	300, 100, 0, 0, 0, 0, 0, 0};int vixPlaybackGetEq( vidix_video_eq_t * eq){	memcpy(eq,&equal,sizeof(vidix_video_eq_t));	return 0;}int vixPlaybackSetEq( const vidix_video_eq_t * eq){	return 0;}static int YOffs,UOffs,VOffs;int vixConfigPlayback(vidix_playback_t *info){	int src_w, drw_w;	int src_h, drw_h;	long base0, pitch;	int uv_size, swap_uv;	unsigned int i;	int extfifo_on;	// Overlay register settings	uint32_t win_start, win_end;	uint32_t zoom, mini;	uint32_t dcount, falign, qwfetch;	uint32_t v_ctrl, fifo_ctrl;	if(!is_supported_fourcc(info->fourcc))		return -1;	src_w = info->src.w;	src_h = info->src.h;	drw_w = info->dest.w;	drw_h = info->dest.h;	// Setup FIFO	uc_ovl_setup_fifo(&extfifo_on, src_w);	// Get image format, FIFO size, etc.	uc_ovl_map_v1_control(info->fourcc, src_w, 3, extfifo_on,		&v_ctrl, &fifo_ctrl);	// Setup layer window	win_start = (info->dest.x << 16) | info->dest.y;	win_end = ((info->dest.x + drw_w - 1) << 16) |		(info->dest.y + drw_h - 1);	// Get scaling and data-fetch parameters	zoom = 0;	mini = 0;	uc_ovl_map_vzoom(src_h, drw_h, &zoom, &mini);	uc_ovl_map_hzoom(src_w, drw_w, &zoom, &mini, &falign, &dcount);	qwfetch = uc_ovl_map_qwfetch(info->fourcc, src_w);	// Calculate buffer sizes	swap_uv = 0;	switch(info->fourcc)	{		default:		case IMGFMT_YV12:			swap_uv = 1;		case IMGFMT_I420:		case IMGFMT_UYVY:		case IMGFMT_YVYU:			pitch = ALIGN_TO (src_w, 32);			uv_size = (pitch >> 1) * (src_h >> 1);			break;		case IMGFMT_YUY2:		case IMGFMT_BGR15:		case IMGFMT_BGR16:			pitch = ALIGN_TO (src_w << 1, 32);			uv_size = 0;			break;		case IMGFMT_BGR32:			pitch = ALIGN_TO (src_w << 2, 32);			uv_size = 0;			break;	}	if ((src_w > 4096) || (src_h > 4096) ||		(src_w < 32) || (src_h < 1) || (pitch > 0x1fff))	{		printf("[unichrome] Layer size out of bounds\n");	}	// Calculate offsets	info->offset.y = 0;	info->offset.v = info->offset.y + pitch * src_h;	info->offset.u = info->offset.v + uv_size;	info->frame_size = info->offset.u + uv_size;	YOffs = info->offset.y;	UOffs = (swap_uv ? info->offset.v : info->offset.u);	VOffs = (swap_uv ? info->offset.u : info->offset.v);	/* Assume we have 2 MB to play with */	info->num_frames = FRAMEBUFFER_SIZE / info->frame_size;	if(info->num_frames > VID_PLAY_MAXFRAMES)		info->num_frames = VID_PLAY_MAXFRAMES;	/* Start at 6 MB. Let's hope it's not in use. */	base0 = FRAMEBUFFER_START;	info->dga_addr = uc_mem + base0;	info->dest.pitch.y = 32;	info->dest.pitch.u = 32;	info->dest.pitch.v = 32;	for(i = 0; i < info->num_frames; i++)	{		info->offsets[i] = info->frame_size * i;		frames[i] = base0+info->offsets[i];	}	// Write to the hardware	uc_ovl_vcmd_wait(vio);	// Configure diy_pitchlay parameters now	if (v_ctrl & V1_COLORSPACE_SIGN)	{		VIDEO_OUT (vio, V1_ColorSpaceReg_2, ColorSpaceValue_2);		VIDEO_OUT (vio, V1_ColorSpaceReg_1, ColorSpaceValue_1);	}	VIDEO_OUT(vio, V1_CONTROL, v_ctrl);	VIDEO_OUT(vio, V_FIFO_CONTROL, fifo_ctrl);	VIDEO_OUT(vio, V1_WIN_START_Y, win_start);	VIDEO_OUT(vio, V1_WIN_END_Y, win_end);	VIDEO_OUT(vio, V1_SOURCE_HEIGHT, (src_h << 16) | dcount);	VIDEO_OUT(vio, V12_QWORD_PER_LINE, qwfetch << 20);	VIDEO_OUT(vio, V1_STRIDE, pitch | ((pitch >> 1) << 16));	VIDEO_OUT(vio, V1_MINI_CONTROL, mini);	VIDEO_OUT(vio, V1_ZOOM_CONTROL, zoom);		// Configure buffer address and execute the changes now!	vixPlaybackFrameSelect(0);	return 0;}int vixPlaybackOn(void){	LOGWRITE("Enable overlay\n");	// Turn on overlay	VIDEO_OUT(vio, V1_CONTROL, VIDEO_IN(vio, V1_CONTROL) | V1_ENABLE);	// Execute the changes	VIDEO_OUT(vio, V_COMPOSE_MODE,		VIDEO_IN(vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE);	return 0;}int vixPlaybackOff(void){        LOGWRITE("Disable overlay\n"); 	uc_ovl_vcmd_wait(vio);	// Restore FIFO	VIDEO_OUT(vio, V_FIFO_CONTROL, UC_MAP_V1_FIFO_CONTROL(16,12,8));	// Turn off overlay	VIDEO_OUT(vio, V1_CONTROL, VIDEO_IN(vio, V1_CONTROL) & ~V1_ENABLE);	// Execute the changes	VIDEO_OUT(vio, V_COMPOSE_MODE,		VIDEO_IN(vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE);	return 0;}int vixPlaybackFrameSelect(unsigned int frame){        LOGWRITE("Frame select\n"); 	uc_ovl_vcmd_wait(vio);	// Configure buffer address	VIDEO_OUT(vio, V1_STARTADDR_Y0, frames[frame]+YOffs);	VIDEO_OUT(vio, V1_STARTADDR_CB0, frames[frame]+UOffs);	VIDEO_OUT(vio, V1_STARTADDR_CR0, frames[frame]+VOffs);		// Execute the changes	VIDEO_OUT(vio, V_COMPOSE_MODE,		VIDEO_IN(vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -