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

📄 vo_x11.c

📁 DawnLightPlayer,一个新的基于ffmpeg的全功能播放器
💻 C
字号:
/********************************************** * Dawn Light Player * *   vo_x11.c * * Created by maddrone * 16:31:36 02/27/08 CST * * $Id: vo_x11.c 171 2008-03-21 08:00:10Z kf701 $ **********************************************/#if ENABLE_VO_X11#include <X11/Xlib.h>#include <X11/Xutil.h>#include "swscale.h"#include "avoutput.h"#include "avdecode.h"#include "avinput.h"#include "cmdutils.h"#include "global.h"static pthread_mutex_t vo_mutex;static void vo_lock_init(){	pthread_mutex_init(&vo_mutex,NULL);}static void vo_lock_free(){	pthread_mutex_destroy(&vo_mutex);}static void vo_lock(){	pthread_mutex_lock(&vo_mutex);}static void vo_unlock(){	pthread_mutex_unlock(&vo_mutex);}static Display *Xdisplay = NULL;static int Xscreen;static Window Xvowin = None;static GC Xvogc = NULL, Xfgc = NULL;static XImage *Ximg = NULL;static int dx = 200, dy = 200, dw, dh;static char *Xtitle = "Dawn Light Player";static int src_pic_fmt;static int my_pic_fmt = PIX_FMT_RGB32; /* fix me, from Ximg */static AVPicture *my_pic;static int vo_x11_vfmt2rgb(AVPicture *dst, AVPicture *src){	static struct SwsContext *img_convert_ctx;	img_convert_ctx = sws_getCachedContext(img_convert_ctx,	                                       dw, dh, src_pic_fmt,	                                       dw, dh, my_pic_fmt, SWS_BICUBIC, NULL, NULL, NULL);	sws_scale(img_convert_ctx, src->data, src->linesize,	          0, dh, dst->data, dst->linesize);	return 0;}static int vo_x11_init(){	int ret, xdepth;	unsigned long xswamask;	Window xrootwin;	XGCValues xgcv;	XSetWindowAttributes xswa;	XSizeHints hint;	XEvent xev;	XVisualInfo xvinfo;	xswamask = CWBackingStore | CWBorderPixel;	src_pic_fmt = dlpctxp->pixfmt;	dw = dlpctxp->pwidth;	dh = dlpctxp->pheight;	Xdisplay = XOpenDisplay(NULL);	if ( !Xdisplay )	{		av_log(NULL, AV_LOG_ERROR, "X11,%d: XOpenDisplay\n", __LINE__);		return -1;	}	Xscreen = DefaultScreen(Xdisplay);	xrootwin = RootWindow(Xdisplay, Xscreen);	/* Make window center */	dx = ( DisplayWidth(Xdisplay, Xscreen) - dw ) / 2;	dy = ( DisplayHeight(Xdisplay, Xscreen) - dh ) / 2;	xdepth = XDefaultDepth(Xdisplay, 0);	if ( !XMatchVisualInfo(Xdisplay, Xscreen, xdepth, DirectColor, &xvinfo) )		XMatchVisualInfo(Xdisplay, Xscreen, xdepth, TrueColor, &xvinfo);	xswa.background_pixel = 0;	xswa.border_pixel = 0;	xswa.backing_store = Always;	xswa.bit_gravity = StaticGravity;	Xvowin = XCreateWindow(Xdisplay, xrootwin, dx, dy, dw, dh, 0, xdepth,	                       CopyFromParent, xvinfo.visual, xswamask, &xswa);	Xfgc = XCreateGC(Xdisplay, Xvowin, 0, 0);	XSetForeground(Xdisplay, Xfgc, 0);	XStoreName(Xdisplay, Xvowin, Xtitle);	XSelectInput(Xdisplay, Xvowin, StructureNotifyMask);	hint.x = dx;	hint.y = dy;	hint.width = dw;	hint.height = dh;	hint.flags = PPosition | PSize;	XSetStandardProperties(Xdisplay, Xvowin, Xtitle, Xtitle, None, NULL, 0, &hint);	XMapWindow(Xdisplay, Xvowin);	XClearWindow(Xdisplay, Xvowin);	do	{		XNextEvent(Xdisplay, &xev);	}	while (xev.type != MapNotify || xev.xmap.event != Xvowin);	XSelectInput(Xdisplay, Xvowin, NoEventMask);	XSync(Xdisplay, False);	XSelectInput(Xdisplay, Xvowin,	             StructureNotifyMask | KeyPressMask | ExposureMask);	XSync(Xdisplay, False);	Xvogc = XCreateGC(Xdisplay, xrootwin, 0L, &xgcv);	Ximg = XCreateImage(Xdisplay, xvinfo.visual,	                    xdepth, ZPixmap, 0, NULL, dw, dh, 8, 0);	/*-----------------------------------------------------------------------------	 *  my picture for rgb	 *-----------------------------------------------------------------------------*/	my_pic = av_mallocz(sizeof(AVPicture));	ret = avpicture_alloc(my_pic, my_pic_fmt, dw, dh);	if ( -1 == ret )	{		av_log(NULL, AV_LOG_ERROR, "avpicture alloc error\n");		return -1;	}	vo_lock_init();	return 0;}static void toggle_full_screen(void){	vo_lock();	av_log(NULL, AV_LOG_ERROR, "VO X11 not support full screen now!\n");	vo_unlock();}static void vo_x11_display(AVPicture* pic){	vo_lock();	vo_x11_vfmt2rgb( my_pic, pic );	Ximg->data = my_pic->data[0];	XPutImage(Xdisplay, Xvowin, Xvogc, Ximg,	          0, 0, 0, 0, dw, dh);	vo_unlock();}static void vo_x11_event_loop(){	XEvent event;	while (1)	{		XNextEvent(Xdisplay, &event);		switch (event.type)		{		case KeyPress:		{			KeySym key = XKeycodeToKeysym(Xdisplay, event.xkey.keycode, 0);			if ( XK_Escape == key || XK_q == key )				dlp_exit(-2);			else if ( XK_9 == key )				dlp_sub_volume();			else if ( XK_0 == key )				dlp_add_volume();			else if ( XK_p == key || XK_space == key )				dlp_pause_play();			else if ( XK_Left == key )				dlp_seek(-10);			else if ( XK_Right == key )				dlp_seek(10);			else if ( XK_Page_Up == key )				dlp_seek(-60);			else if ( XK_Page_Down == key )				dlp_seek(60);			else if ( XK_h == key )				show_ui_key();			else if ( XK_f == key )				toggle_full_screen();			else if ( XK_s == key )				dlp_screen_shot();			break;		}		default:			break;		}	}}static int vo_x11_uninit(void){	vo_lock();	if (Xfgc)	{		XFreeGC(Xdisplay, Xfgc);		Xfgc = NULL;	}	if (Xvogc)	{		XSetBackground(Xdisplay, Xvogc, 0);		XFreeGC(Xdisplay, Xvogc);		Xvogc = NULL;	}	if (Xvowin != None)	{		XEvent xev;		XClearWindow(Xdisplay, Xvowin);		XUnmapWindow(Xdisplay, Xvowin);		XDestroyWindow(Xdisplay, Xvowin);		do		{			XNextEvent(Xdisplay, &xev);		}		while ( xev.type != DestroyNotify		        || xev.xdestroywindow.event != Xvowin );		Xvowin = None;	}	if (Ximg)	{		Ximg->data = NULL;		XDestroyImage(Ximg);		Ximg = NULL;	}	avpicture_free(my_pic);	av_free(my_pic);	my_pic = NULL;	vo_lock_free();	return 0;}vo_t vo_x11 ={	.id = VO_ID_X11,	.name = "x11",	.vo_init = vo_x11_init,	.vo_uninit = vo_x11_uninit,	.vo_display = vo_x11_display,	.vo_event_loop = vo_x11_event_loop,};#endif /* ENABLE_VO_X11 */

⌨️ 快捷键说明

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