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

📄 video_out_x11_fix.c

📁 从 IEEE 1394总线接收传输流
💻 C
📖 第 1 页 / 共 2 页
字号:
    for (i = 0; i < 3; i++) {	while (instance->frame[i].wait_completion)	    x11_event (instance);	XDestroyImage (instance->frame[i].ximage);    }    destroy_shm (instance);}static void x11_close (vo_instance_t * _instance){    x11_instance_t * instance = (x11_instance_t *) _instance;    if (instance->teardown != NULL)	instance->teardown (instance);#ifdef LIBVO_XV    if (instance->adaptors)	XvFreeAdaptorInfo (instance->adaptorInfo);#endif    XClearWindow(tv_screen.display, tv_screen.window);    XFlush (tv_screen.display);    free (instance);}#ifdef LIBVO_XVstatic void xv_setup_fbuf (vo_instance_t * _instance,			   uint8_t ** buf, void ** id){    x11_instance_t * instance = (x11_instance_t *) _instance;    uint8_t * data;    data = (uint8_t *) instance->frame[instance->index].xvimage->data;    buf[0] = data + instance->frame[instance->index].xvimage->offsets[0];    buf[1] = data + instance->frame[instance->index].xvimage->offsets[2];    buf[2] = data + instance->frame[instance->index].xvimage->offsets[1];    *id = instance->frame + instance->index++;}static void xv_draw_frame (vo_instance_t * _instance,			   uint8_t * const * buf, void * id){    x11_frame_t * frame = (x11_frame_t *) id;    x11_instance_t * instance = (x11_instance_t *) _instance;    XWindowAttributes watt;    XGetWindowAttributes(tv_screen.display, tv_screen.window, &watt);#ifdef XV_BUG_WORKAROUND    if (reset_xv) {      reset_xv = 0;      XvShmPutImage (tv_screen.display, instance->port, tv_screen.window,		   tv_screen.gc, frame->xvimage, 1, 1,		   instance->width-1, instance->height-1, 1, 1,		   watt.width-1, watt.height-1, True);      XFlush (tv_screen.display);    }#endif    XvShmPutImage (tv_screen.display, instance->port, tv_screen.window,		   tv_screen.gc, frame->xvimage, 0, 0,		   instance->width, instance->height, 0, 0,		   watt.width, watt.height, True);    XFlush (tv_screen.display);    frame->wait_completion = 1;    tv_window_is_clear = 0;}static int xv_check_fourcc (x11_instance_t * instance, XvPortID port,			    int fourcc, const char * fourcc_str){    XvImageFormatValues * formatValues;    int formats;    int i;    formatValues = XvListImageFormats (tv_screen.display, port, &formats);    for (i = 0; i < formats; i++)	if ((formatValues[i].id == fourcc) &&	    (! (strcmp (formatValues[i].guid, fourcc_str)))) {	    XFree (formatValues);	    return 0;	}    XFree (formatValues);    return 1;}static int xv_check_extension (x11_instance_t * instance,			       int fourcc, const char * fourcc_str){    unsigned int i;    unsigned long j;    if (!instance->adaptorInfo) {	unsigned int version;	unsigned int release;	unsigned int dummy;	if ((XvQueryExtension (tv_screen.display, &version, &release,			       &dummy, &dummy, &dummy) != Success) ||	    (version < 2) || ((version == 2) && (release < 2))) {	    fprintf (stderr, "No xv extension\n");	    return 1;	}	XvQueryAdaptors (tv_screen.display, tv_screen.window,			 &instance->adaptors, &instance->adaptorInfo);    }    for (i = 0; i < instance->adaptors; i++)	if (instance->adaptorInfo[i].type & XvImageMask)	    for (j = 0; j < instance->adaptorInfo[i].num_ports; j++)		if ((! (xv_check_fourcc (instance,					 instance->adaptorInfo[i].base_id + j,					 fourcc, fourcc_str))) &&		    (XvGrabPort (tv_screen.display,				 instance->adaptorInfo[i].base_id + j,				 0) == Success)) {		    instance->port = instance->adaptorInfo[i].base_id + j;		    return 0;		}    fprintf (stderr, "Cannot find xv %s port\n", fourcc_str);    return 1;}static int xv_alloc_frames (x11_instance_t * instance, int size,			    int fourcc){    char * alloc;    int i = 0;    alloc = (char *) create_shm (instance, 3 * size);    if (alloc == NULL)	return 1;    while (i < 3) {	instance->frame[i].wait_completion = 0;	instance->frame[i].xvimage =	    XvShmCreateImage (tv_screen.display, instance->port, fourcc,			      alloc, instance->width, instance->height,			      &(instance->shminfo));	instance->frame[i].data = alloc;	alloc += size;	if ((instance->frame[i].xvimage == NULL) ||	    (instance->frame[i++].xvimage->data_size != size)) {	    while (--i >= 0)		XFree (instance->frame[i].xvimage);	    destroy_shm (instance);	    return 1;	}    }    return 0;}static void xv_teardown (x11_instance_t * instance){    int i;    for (i = 0; i < 3; i++) {	while (instance->frame[i].wait_completion)	    x11_event (instance);	XFree (instance->frame[i].xvimage);    }    destroy_shm (instance);    XvUngrabPort (tv_screen.display, instance->port, 0);}#endifstatic int common_setup (vo_instance_t * _instance, unsigned int width,			 unsigned int height, unsigned int chroma_width,			 unsigned int chroma_height,			 vo_setup_result_t * result){    x11_instance_t * instance = (x11_instance_t *) _instance;    if (instance->teardown != NULL)        instance->teardown (instance);    instance->vo.setup_fbuf = NULL;    instance->vo.start_fbuf = NULL;    instance->vo.set_fbuf = NULL;    instance->vo.draw = NULL;    instance->vo.discard = NULL;    instance->vo.close = x11_close;    instance->width = width;    instance->height = height;    instance->index = 0;    instance->teardown = NULL;    result->convert = NULL;#ifdef LIBVO_XV    if (instance->xv == 1 &&	(chroma_width == width >> 1) && (chroma_height == height >> 1) &&	!xv_check_extension (instance, FOURCC_YV12, "YV12") &&	!xv_alloc_frames (instance, 3 * width * height / 2, FOURCC_YV12)) {	instance->vo.setup_fbuf = xv_setup_fbuf;	instance->vo.start_fbuf = x11_start_fbuf;	instance->vo.draw = xv_draw_frame;	instance->teardown = xv_teardown;    } else if (instance->xv && (chroma_width == width >> 1) &&	       !xv_check_extension (instance, FOURCC_UYVY, "UYVY") &&	       !xv_alloc_frames (instance, 2 * width * height, FOURCC_UYVY)) {	instance->vo.setup_fbuf = x11_setup_fbuf;	instance->vo.start_fbuf = x11_start_fbuf;	instance->vo.draw = xv_draw_frame;	instance->teardown = xv_teardown;	result->convert = mpeg2convert_uyvy;    } else#endif    if (!x11_alloc_frames (instance)) {	int bpp;	instance->vo.setup_fbuf = x11_setup_fbuf;	instance->vo.start_fbuf = x11_start_fbuf;	instance->vo.draw = x11_draw_frame;	instance->teardown = x11_teardown;#ifdef WORDS_BIGENDIAN	if (instance->frame[0].ximage->byte_order != MSBFirst) {	    fprintf (stderr, "No support for non-native byte order\n");	    return 1;	}#else	if (instance->frame[0].ximage->byte_order != LSBFirst) {	    fprintf (stderr, "No support for non-native byte order\n");	    return 1;	}#endif	/*	 * depth in X11 terminology land is the number of bits used to	 * actually represent the colour.	 *	 * bpp in X11 land means how many bits in the frame buffer per	 * pixel.	 *	 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit	 *     color is 24 bit depth, but can be 24 bpp or 32 bpp.	 *	 * If we have blue in the lowest bit then "obviously" RGB	 * (the guy who wrote this convention never heard of endianness ?)	 */	bpp = ((tv_screen.vinfo.depth == 24) ?	       instance->frame[0].ximage->bits_per_pixel :	       tv_screen.vinfo.depth);	result->convert =	    mpeg2convert_rgb (((instance->frame[0].ximage->blue_mask & 1) ?			       MPEG2CONVERT_RGB : MPEG2CONVERT_BGR), bpp);	if (result->convert == NULL) {	    fprintf (stderr, "%dbpp not supported\n", bpp);	    return 1;	}    }    return 0;}static vo_instance_t * common_open (int xv){    x11_instance_t * instance;    instance = (x11_instance_t *) malloc (sizeof (x11_instance_t));    if (instance == NULL)	return NULL;    instance->vo.setup = common_setup;    instance->vo.close = (void (*) (vo_instance_t *)) free;    instance->teardown = NULL;#ifdef LIBVO_XV    instance->xv = xv;    instance->adaptors = 0;    instance->adaptorInfo = NULL;#endif    return (vo_instance_t *) instance;}vo_instance_t * vo_x11_fix_open (void){    return common_open (0);}#ifdef LIBVO_XVvo_instance_t * vo_xv_fix_open (void){    return common_open (1);}vo_instance_t * vo_xv2_fix_open (void){    return common_open (2);}#endifint init_video_out_tv(){#ifdef XV_BUG_WORKAROUND	reset_xv = 0;#endif	tv_window_is_clear = 1;//	if (open_display(&tv_screen, 768, 576)) /* startup with PAL resolution window */	if (open_display(&tv_screen, 720, 576)) /* startup with PAL (DVD) resolution window *///	if (open_display(&tv_screen, 720, 480)) /* startup with NTSC (DVD) resolution window *///	if (open_display(&tv_screen, 640, 480))		return 1;	return 0;}void done_video_out_tv(){	close_display(&tv_screen);}void clear_tv_window(){	if (!tv_window_is_clear) {		tv_window_is_clear = 1;		XClearWindow(tv_screen.display, tv_screen.window);		XFlush (tv_screen.display);#ifdef XV_BUG_WORKAROUND		reset_xv = 1;#endif	}}int resize_tv_window(unsigned int width, unsigned int height){	XResizeWindow(tv_screen.display, tv_screen.window, width, height);	XFlush (tv_screen.display);	return 0;}#endif

⌨️ 快捷键说明

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