vo_sdl.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,734 行 · 第 1/4 页

C
1,734
字号
		/*if((strcmp(priv->driver, "dga") == 0) && (priv->mode)) {			if( mp_msg_test(MSGT_VO,MSGL_V) ) {				printf("SDL: using software-surface\n"); }			priv->sdlflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;			priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;		}			else {	*/			if( mp_msg_test(MSGT_VO,MSGL_V) ) {	 			mp_msg(MSGT_VO,MSGL_V, "SDL: using hardware-surface\n"); }			priv->sdlflags = SDL_HWSURFACE|SDL_RESIZABLE/*|SDL_ANYFORMAT*/;			priv->sdlfullflags = SDL_HWSURFACE|SDL_FULLSCREEN/*|SDL_ANYFORMAT*/;			// XXX:FIXME: ASYNCBLIT should be enabled for SMP systems		//}		#endif	#if !defined( AMIGA ) && !defined( MACOSX ) 	priv->sdlfullflags |= SDL_DOUBLEBUF;		if (vo_doublebuffering)	    priv->sdlflags |= SDL_DOUBLEBUF;#endif		/* Setup Keyrepeats (500/30 are defaults) */	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);	/* get information about the graphics adapter */	vidInfo = SDL_GetVideoInfo ();		/* collect all fullscreen & hardware modes available */	if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) {		/* non hardware accelerated fullscreen modes */		priv->sdlfullflags &= ~SDL_HWSURFACE; 		priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags);	}		/* test for normal resizeable & windowed hardware accellerated surfaces */	if (!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) {				/* test for NON hardware accelerated resizeable surfaces - poor you. 		 * That's all we have. If this fails there's nothing left.		 * Theoretically there could be Fullscreenmodes left - we ignore this for now.		 */		priv->sdlflags &= ~SDL_HWSURFACE;		if ((!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) && (!priv->fullmodes)) {			mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SDL_CouldntGetAnyAcceptableSDLModeForOutput);			return -1;		}	}															   /* YUV overlays need at least 16-bit color depth, but the    * display might less. The SDL AAlib target says it can only do    * 8-bits, for example. So, if the display is less than 16-bits,    * we'll force the BPP to 16, and pray that SDL can emulate for us.    */	priv->bpp = vidInfo->vfmt->BitsPerPixel;	if (priv->mode == YUV && priv->bpp < 16) {		if( mp_msg_test(MSGT_VO,MSGL_V) ) 		    mp_msg(MSGT_VO,MSGL_V, "SDL: Your SDL display target wants to be at a color "                           "depth of (%d), but we need it to be at least 16 "                           "bits, so we need to emulate 16-bit color. This is "                           "going to slow things down; you might want to "                           "increase your display's color depth, if possible.\n",                           priv->bpp);		priv->bpp = 16;  	}		/* We don't want those in our event queue. 	 * We use SDL_KEYUP cause SDL_KEYDOWN seems to cause problems	 * with keys need to be pressed twice, to be recognized.	 */#ifndef BUGGY_SDL	SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);//	SDL_EventState(SDL_QUIT, SDL_IGNORE);	SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);	SDL_EventState(SDL_USEREVENT, SDL_IGNORE);#endif		/* Success! */	return 0;}/** * Close SDL, Cleanups, Free Memory * *    params : *plugin *   returns : non-zero on success, zero on error. **/static int sdl_close (void){	struct sdl_priv_s *priv = &sdl_priv;	if (priv->fullmode)	    SDL_ShowCursor(1);	/* Cleanup YUV Overlay structure */	if (priv->overlay) {		SDL_FreeYUVOverlay(priv->overlay);		priv->overlay=NULL;	}	/* Free RGB Surface */	if (priv->rgbsurface) {		SDL_FreeSurface(priv->rgbsurface);		priv->rgbsurface=NULL;	}	/* Free our blitting surface */	if (priv->surface) {		SDL_FreeSurface(priv->surface);		priv->surface=NULL;	}		/* DON'T attempt to free the fullscreen modes array. SDL_Quit* does this for us */		return 0;}/** * Do aspect ratio calculations * *   params : srcw == sourcewidth *            srch == sourceheight *            dstw == destinationwidth *            dsth == destinationheight * *  returns : SDL_Rect structure with new x and y, w and h **/#if 0static SDL_Rect aspect(int srcw, int srch, int dstw, int dsth) {	SDL_Rect newres;	if( mp_msg_test(MSGT_VO,MSGL_V) ) {	 	mp_msg(MSGT_VO,MSGL_V, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres.w, newres.h, newres.x, newres.y); }	newres.h = ((float)dstw / (float)srcw * (float)srch) * ((float)dsth/((float)dstw/(MONITOR_ASPECT)));	if(newres.h > dsth) {		newres.w = ((float)dsth / (float)newres.h) * dstw;		newres.h = dsth;		newres.x = (dstw - newres.w) / 2;		newres.y = 0;	}	else {		newres.w = dstw;		newres.x = 0;		newres.y = (dsth - newres.h) / 2;	}		if( mp_msg_test(MSGT_VO,MSGL_V) ) {		mp_msg(MSGT_VO,MSGL_V, "SDL Mode: %d:  %d x %d\n", i, priv->fullmodes[i]->w, priv->fullmodes[i]->h); }	return newres;}#endif/** * Sets the specified fullscreen mode. * *   params : mode == index of the desired fullscreen mode *  returns : doesn't return **/#if 0static void set_fullmode (int mode){	struct sdl_priv_s *priv = &sdl_priv;	SDL_Surface *newsurface = NULL;	int haspect, waspect = 0;		/* if we haven't set a fullmode yet, default to the lowest res fullmode first */	if (mode < 0) 		mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1;	/* Calculate proper aspect ratio for fullscreen	 * Height smaller than expected: add horizontal black bars (haspect)*/	haspect = (priv->width * (float) ((float) priv->fullmodes[mode]->h / (float) priv->fullmodes[mode]->w) - priv->height) * (float) ((float) priv->fullmodes[mode]->w / (float) priv->width);	/* Height bigger than expected: add vertical black bars (waspect)*/	if (haspect < 0) {		haspect = 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */		waspect = priv->fullmodes[mode]->w - ((float) ((float) priv->fullmodes[mode]->h / (float) priv->height) * (float) priv->width);	}	//	printf ("W-Aspect: %i  H-Aspect: %i\n", waspect, haspect);		/* change to given fullscreen mode and hide the mouse cursor */	newsurface = SDL_SetVideoMode(priv->fullmodes[mode]->w - waspect, priv->fullmodes[mode]->h - haspect, priv->bpp, priv->sdlfullflags);		/* if we were successfull hide the mouse cursor and save the mode */	if (newsurface) {		if (priv->surface)	    	    SDL_FreeSurface(priv->surface);		priv->surface = newsurface;		SDL_ShowCursor(0);	}}#endif/* Set video mode. Not fullscreen */static void set_video_mode(int width, int height, int bpp, uint32_t sdlflags){	struct sdl_priv_s *priv = &sdl_priv;    SDL_Surface* newsurface;        if(priv->rgbsurface)	SDL_FreeSurface(priv->rgbsurface);    else if(priv->overlay)	SDL_FreeYUVOverlay(priv->overlay);     priv->rgbsurface = NULL;    priv->overlay = NULL;     newsurface = SDL_SetVideoMode(width, height, bpp, sdlflags);    if(newsurface) {        /* priv->surface will be NULL the first time this function is called. */        if(priv->surface)            SDL_FreeSurface(priv->surface);        priv->surface = newsurface;        priv->dstwidth = width;        priv->dstheight = height;        setup_surfaces();    }    else        mp_msg(MSGT_VO,MSGL_WARN, "set_video_mode: SDL_SetVideoMode failed: %s\n", SDL_GetError());}static void set_fullmode (int mode) {	struct sdl_priv_s *priv = &sdl_priv;	SDL_Surface *newsurface = NULL; 	int screen_surface_w, screen_surface_h;	 	if(priv->rgbsurface)	        SDL_FreeSurface(priv->rgbsurface); 	else if(priv->overlay)	        SDL_FreeYUVOverlay(priv->overlay);  	priv->rgbsurface = NULL; 	priv->overlay = NULL; 	/* if we haven't set a fullmode yet, default to the lowest res fullmode first */	/* But select a mode where the full video enter */	if(priv->X && priv->fulltype & VOFLAG_FULLSCREEN) {		screen_surface_w = priv->XWidth;		screen_surface_h = priv->XHeight;	}	else if (mode < 0) {        int i,j,imax;		mode = 0; // Default to the biggest mode avaible		if ( mp_msg_test(MSGT_VO,MSGL_V) ) for(i=0;priv->fullmodes[i];++i) 	           mp_msg(MSGT_VO,MSGL_V, "SDL Mode: %d:  %d x %d\n", i, priv->fullmodes[i]->w, priv->fullmodes[i]->h);		for(i = findArrayEnd(priv->fullmodes) - 1; i >=0; i--) {		  if( (priv->fullmodes[i]->w >= priv->dstwidth) && 		      (priv->fullmodes[i]->h >= priv->dstheight) ) {		      imax = i;		      for (j = findArrayEnd(priv->fullmodes) - 1; j >=0; j--) {			  if (priv->fullmodes[j]->w > priv->fullmodes[imax]->w			      && priv->fullmodes[j]->h == priv->fullmodes[imax]->h)			      imax = j;		      }		      mode = imax;		      break;		    }		  }		if ( mp_msg_test(MSGT_VO,MSGL_V) ) {			mp_msg(MSGT_VO,MSGL_V, "SET SDL Mode: %d:  %d x %d\n", mode, priv->fullmodes[mode]->w, priv->fullmodes[mode]->h); }		priv->fullmode = mode;        screen_surface_h = priv->fullmodes[mode]->h;        screen_surface_w = priv->fullmodes[mode]->w;	}    else {       screen_surface_h = priv->fullmodes[mode]->h;       screen_surface_w = priv->fullmodes[mode]->w;	}		aspect_save_screenres(screen_surface_w, screen_surface_h);	/* calculate new video size/aspect */	if(priv->mode == YUV) {        if(priv->fulltype&VOFLAG_FULLSCREEN)		aspect_save_screenres(priv->XWidth, priv->XHeight);        aspect(&priv->dstwidth, &priv->dstheight, A_ZOOM);	}	/* try to change to given fullscreenmode */	newsurface = SDL_SetVideoMode(priv->dstwidth, screen_surface_h, priv->bpp,                                  priv->sdlfullflags);	/*	 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to 	 * destroy the datastructure previously retrived, so we need to 	 * re-assign it.  The comment in sdl_close() seems to imply that we 	 * should not free() anything.	 */	#ifdef SYS_DARWIN	{	const SDL_VideoInfo *vidInfo = NULL;	vidInfo = SDL_GetVideoInfo ();	/* collect all fullscreen & hardware modes available */	if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) {	    /* non hardware accelerated fullscreen modes */	    priv->sdlfullflags &= ~SDL_HWSURFACE;	    priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags);	}	}	#endif		/* if creation of new surface was successfull, save it and hide mouse cursor */	if(newsurface) {		if (priv->surface)	    	    SDL_FreeSurface(priv->surface);		priv->surface = newsurface;		SDL_ShowCursor(0);        SDL_SRF_LOCK(priv->surface, -1)        SDL_FillRect(priv->surface, NULL, 0);        SDL_SRF_UNLOCK(priv->surface)        setup_surfaces();	}		    else        mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SDL_SetVideoModeFailedFull, SDL_GetError());}/** * Initialize an SDL surface and an SDL YUV overlay. * *    params : width  == width of video we'll be displaying. *             height == height of video we'll be displaying. *             fullscreen == want to be fullscreen? *             title == Title for window titlebar. *   returns : non-zero on success, zero on error. **/static intconfig(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)//static int sdl_setup (int width, int height){	struct sdl_priv_s *priv = &sdl_priv;    switch(format){        case IMGFMT_I420:            mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SDL_MappingI420ToIYUV);            format = SDL_IYUV_OVERLAY;		case IMGFMT_YV12:		case IMGFMT_IYUV:		case IMGFMT_YUY2:		case IMGFMT_UYVY:		case IMGFMT_YVYU:            priv->mode = YUV;            break;		case IMGFMT_BGR15:			case IMGFMT_BGR16:			case IMGFMT_BGR24:			case IMGFMT_BGR32:				priv->mode = BGR;			break;        case IMGFMT_RGB15:	        case IMGFMT_RGB16:	        case IMGFMT_RGB24:			case IMGFMT_RGB32:				priv->mode = RGB;			break;		default: 			mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SDL_UnsupportedImageFormat,format);			return -1;	}    if ( vo_config_count ) sdl_close();    if( mp_msg_test(MSGT_VO,MSGL_V) ) {      mp_msg(MSGT_VO,MSGL_V, "SDL: Using 0x%X (%s) image format\n", format, vo_format_name(format)); }        if(priv->mode != YUV) {		priv->sdlflags |= SDL_ANYFORMAT;		priv->sdlfullflags |= SDL_ANYFORMAT;	}    /* SDL can only scale YUV data */    if(priv->mode == RGB || priv->mode == BGR) {        d_width = width;        d_height = height;    }    aspect_save_orig(width,height);	aspect_save_prescale(d_width ? d_width : width, d_height ? d_height : height);	/* Save the original Image size */    priv->width  = width;    priv->height = height;    priv->dstwidth  = d_width ? d_width : width;    priv->dstheight = d_height ? d_height : height;    priv->format = format;    	if (sdl_open(NULL, NULL) != 0)	    return -1;	/* Set output window title */	SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title);	//SDL_WM_SetCaption (title, title);    if(priv->X) {	aspect_save_screenres(priv->XWidth,priv->XHeight);	aspect(&priv->dstwidth,&priv->dstheight,A_NOZOOM);    }    	priv->windowsize.w = priv->dstwidth;  	priv->windowsize.h = priv->dstheight;        	/* bit 0 (0x01) means fullscreen (-fs)	 * bit 1 (0x02) means mode switching (-vm)	 * bit 2 (0x04) enables software scaling (-zoom)	 * bit 3 (0x08) enables flipping (-flip)	 *///      printf("SDL: flags are set to: %i\n", flags);//	printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height);	if(flags&VOFLAG_FLIPPING) {		if( mp_msg_test(MSGT_VO,MSGL_V) ) {			mp_msg(MSGT_VO,MSGL_V, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n"); }		priv->flip = 1; 	}	if(flags&VOFLAG_FULLSCREEN) {	  	if( mp_msg_test(MSGT_VO,MSGL_V) ) { 	  	    mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen without modeswitching\n");}

⌨️ 快捷键说明

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