src/video/photon/SDL_phyuv.c
changeset 0 74212992fb08
child 252 e8157fcb3114
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/photon/SDL_phyuv.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,659 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* This is the QNX Realtime Platform version for SDL YUV video overlays */
    1.32 +
    1.33 +#include <stdlib.h>
    1.34 +#include <string.h>
    1.35 +//#include <ncurses.h> //only for bool
    1.36 +#ifndef bool
    1.37 +#define bool char
    1.38 +#define TRUE 1
    1.39 +#define FALSE 0
    1.40 +#endif
    1.41 +#include <errno.h>
    1.42 +
    1.43 +#include <Ph.h>
    1.44 +#include <Pt.h>
    1.45 +
    1.46 +#include "SDL_error.h"
    1.47 +#include "SDL_video.h"
    1.48 +#include "SDL_phyuv_c.h"
    1.49 +#include "SDL_yuvfuncs.h"
    1.50 +
    1.51 +#if 0  //just for reference
    1.52 +/* YUV data formats			FourCC		   Layout		H sample (YUV)	V sample (YUV)	BPP */
    1.53 +#define Pg_VIDEO_FORMAT_IYU1		0x31555949	/* U2Y2Y2V2Y2Y2		144		111		12  */
    1.54 +#define Pg_VIDEO_FORMAT_IYU2		0x32555949	/* U4Y4V4U4Y4V4		111		111		24  */
    1.55 +#define Pg_VIDEO_FORMAT_UYVY		0x59565955	/* U8Y8V8Y8		122		111		16  */
    1.56 +#define Pg_VIDEO_FORMAT_YUY2		0x32595559	/* Y8U8Y8V8		122		111		16  */
    1.57 +#define Pg_VIDEO_FORMAT_YVYU		0x55595659	/* Y8V8Y8U8		122		111		16  */
    1.58 +#define Pg_VIDEO_FORMAT_V422		0x56343232	/* V8Y8U8Y8		122		111		16  */
    1.59 +#define Pg_VIDEO_FORMAT_CLJR		0x524a4c43	/* V6U6Y5Y5Y5Y5		133		111		8   */
    1.60 +#define Pg_VIDEO_FORMAT_YVU9		0x39555659	/* Planar YVU		144		144		9   */
    1.61 +#define Pg_VIDEO_FORMAT_YV12		0x32315659	/* Planar YUV		122		122		12  */
    1.62 +
    1.63 +/* There seems to be no FourCC that matches this */
    1.64 +#define Pg_VIDEO_FORMAT_YUV420		0x00000100	/* Planar YUV		122		111		16  */
    1.65 +
    1.66 +/* These formats are the same as YV12, except the U and V planes do not have to contiguously follow the Y plane */
    1.67 +/* but they're all the same to us, since we always have 3 plane pointers */
    1.68 +#define Pg_VIDEO_FORMAT_CLPL	Pg_VIDEO_FORMAT_YV12	/* Cirrus Logic Planar format */
    1.69 +#define Pg_VIDEO_FORMAT_VBPL	Pg_VIDEO_FORMAT_YV12	/* VooDoo Banshee planar format */
    1.70 +
    1.71 +#define SDL_YV12_OVERLAY	0x32315659	/* Planar mode: Y + V + U */
    1.72 +#define SDL_IYUV_OVERLAY	0x56555949	/* Planar mode: Y + U + V */
    1.73 +#define SDL_YUY2_OVERLAY	0x32595559	/* Packed mode: Y0+U0+Y1+V0 */
    1.74 +#define SDL_UYVY_OVERLAY	0x59565955	/* Packed mode: U0+Y0+V0+Y1 */
    1.75 +#define SDL_YVYU_OVERLAY	0x55595659	/* Packed mode: Y0+V0+Y1+U0 */
    1.76 +
    1.77 +#endif 
    1.78 +
    1.79 +
    1.80 +#define OVERLAY_STATE_UNINIT  0
    1.81 +#define OVERLAY_STATE_ACTIVE 1
    1.82 +
    1.83 +/* The functions used to manipulate software video overlays */
    1.84 +static struct private_yuvhwfuncs ph_yuvfuncs = {
    1.85 +	ph_LockYUVOverlay,
    1.86 +	ph_UnlockYUVOverlay,
    1.87 +	ph_DisplayYUVOverlay,
    1.88 +	ph_FreeYUVOverlay
    1.89 +};
    1.90 +
    1.91 +
    1.92 +typedef struct {
    1.93 +  int id;
    1.94 +  int width, height;
    1.95 +  int data_size;              /* bytes */
    1.96 +  int num_planes;
    1.97 +  int *pitches;               /* bytes */
    1.98 +  int *offsets;               /* bytes */
    1.99 +  char *data;
   1.100 +  void *obdata;     
   1.101 +} XvImage;
   1.102 +
   1.103 +
   1.104 +struct private_yuvhwdata {
   1.105 +	XvImage *image;	
   1.106 +	FRAMEDATA *CurrentFrameData;
   1.107 +	FRAMEDATA *FrameData0;
   1.108 +	FRAMEDATA *FrameData1;
   1.109 +	PgScalerProps_t	props;
   1.110 +	PgScalerCaps_t		caps;
   1.111 +	PgVideoChannel_t *channel;
   1.112 +	SDL_Rect CurrentWindow;
   1.113 +	long format;
   1.114 +	int screen_width;
   1.115 +	int screen_height ;
   1.116 +	int screen_bpp ;    //2
   1.117 +	bool planar;
   1.118 +	bool scaler_on ;
   1.119 +	int current;
   1.120 +	long YStride;
   1.121 +	long VStride;
   1.122 +	long UStride;
   1.123 +	long chromakey;
   1.124 +	unsigned long State;
   1.125 +	long flags;
   1.126 +};
   1.127 +
   1.128 +extern PgVideoChannel_t * PgCreateVideoChannel(unsigned type, unsigned flags);
   1.129 +extern int PgGetScalerCapabilities( PgVideoChannel_t *channel, int format_index, PgScalerCaps_t *vcaps );
   1.130 +extern int PgConfigScalerChannel(PgVideoChannel_t *channel, PgScalerProps_t *props);
   1.131 +extern void PgDestroyVideoChannel(PgVideoChannel_t *channel);
   1.132 +extern PgColor_t PgGetOverlayChromaColor(void);
   1.133 +
   1.134 +void
   1.135 +grab_ptrs2(PgVideoChannel_t *channel, FRAMEDATA *Frame0, FRAMEDATA *Frame1 )
   1.136 +{
   1.137 +
   1.138 +	/* Buffers have moved; re-obtain the pointers */
   1.139 +	Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
   1.140 +	Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
   1.141 +	Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
   1.142 +	Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
   1.143 +	Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
   1.144 +	Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
   1.145 +
   1.146 +}
   1.147 +
   1.148 +SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
   1.149 +{
   1.150 +	SDL_Overlay *overlay;
   1.151 +	struct private_yuvhwdata *hwdata;
   1.152 +	int xv_port;
   1.153 +	int rtncode;
   1.154 +//	PhRect_t rect;
   1.155 +//	PhSysInfo_t info;
   1.156 +//	PhRegion_t region;
   1.157 +//	short x, y;
   1.158 +	PtArg_t argt;
   1.159 +	int i =0;
   1.160 +//	bool bCont = TRUE;
   1.161 +	int Priority[20];
   1.162 +	int Type[20];
   1.163 +	int entries, select, highest;
   1.164 +
   1.165 +	PhDCSetCurrent(0);  //Need to set draw context to window esp. if we we in Offscreeen mode
   1.166 +
   1.167 +	/* Create the overlay structure */
   1.168 +	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
   1.169 +	if ( overlay == NULL ) {
   1.170 +		SDL_OutOfMemory();
   1.171 +		return(NULL);
   1.172 +	}
   1.173 +	memset(overlay, 0, (sizeof *overlay));
   1.174 +
   1.175 +	/* Fill in the basic members */
   1.176 +	overlay->format = format;
   1.177 +	overlay->w = width;
   1.178 +	overlay->h = height;
   1.179 +	
   1.180 +	/* Set up the YUV surface function structure */
   1.181 +	overlay->hwfuncs = &ph_yuvfuncs;
   1.182 +
   1.183 +	/* Create the pixel data and lookup tables */
   1.184 +	hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata);
   1.185 +	overlay->hwdata = hwdata;
   1.186 +	if ( hwdata == NULL ) {
   1.187 +		SDL_OutOfMemory();
   1.188 +		SDL_FreeYUVOverlay(overlay);
   1.189 +		return(NULL);
   1.190 +	}
   1.191 +	
   1.192 +		if (overlay->hwdata->channel == NULL)
   1.193 +	{
   1.194 +	
   1.195 +  
   1.196 +		if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
   1.197 +		{
   1.198 +			SDL_SetError("Create channel failed:%s\n", strerror( errno ));
   1.199 +			free(overlay->hwdata);
   1.200 +			free(overlay);
   1.201 +			return(NULL);
   1.202 +		}
   1.203 +#if 0
   1.204 +		overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps);
   1.205 +		PgGetScalerCapabilities(overlay->hwdata->channel, 0, &(overlay->hwdata->caps));
   1.206 +		if (overlay->hwdata->caps.flags & Pg_SCALER_CAP_DOUBLE_BUFFER)
   1.207 +			overlay->hwdata->props.flags |= Pg_SCALER_PROP_DOUBLE_BUFFER;
   1.208 +#endif	
   1.209 +	}
   1.210 +
   1.211 +overlay->hwdata->CurrentWindow.x = 0;
   1.212 +overlay->hwdata->CurrentWindow.y = 0;
   1.213 +overlay->hwdata->CurrentWindow.w = 320;
   1.214 +overlay->hwdata->CurrentWindow.h = 240;
   1.215 +
   1.216 +
   1.217 +
   1.218 +overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   1.219 +
   1.220 +overlay->hwdata->screen_bpp = 2;
   1.221 +overlay->hwdata->scaler_on = FALSE;
   1.222 +
   1.223 +overlay->hwdata->screen_width = 1024;
   1.224 +overlay->hwdata->screen_height  = 768;
   1.225 +
   1.226 +overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
   1.227 +overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
   1.228 +
   1.229 +overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
   1.230 +
   1.231 +
   1.232 +//Note you really don't need to do this for SDL as you are given a format, but this is a good example
   1.233 +
   1.234 +xv_port = -1;
   1.235 +i=0;
   1.236 +	
   1.237 +while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) 
   1.238 +{
   1.239 +
   1.240 +		if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YV12) //in SDL
   1.241 +		{
   1.242 +			
   1.243 +			Priority[i-1] = 0;
   1.244 +			Type[i-1] = Pg_VIDEO_FORMAT_YV12;
   1.245 +			if(format == Pg_VIDEO_FORMAT_YV12)
   1.246 +			{
   1.247 +				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YV12;
   1.248 +				xv_port = 1; //supported
   1.249 +				Priority[i-1] = 100; //force selected
   1.250 +			}
   1.251 +			
   1.252 +		}
   1.253 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVU9) //in SDL
   1.254 +		{
   1.255 +			
   1.256 +			Priority[i-1] = 0;
   1.257 +			Type[i-1] = Pg_VIDEO_FORMAT_YVU9;			
   1.258 +			if(format == Pg_VIDEO_FORMAT_YVU9)
   1.259 +			{
   1.260 +				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVU9;
   1.261 +				xv_port = 1; //supported
   1.262 +				Priority[i-1] = 100; //force selected
   1.263 +			}
   1.264 +			
   1.265 +		}
   1.266 +#if 0 //this part of SDL is YUV specific
   1.267 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB555)
   1.268 +		{
   1.269 +			
   1.270 +			Priority[i-1] = 3;
   1.271 +			Type[i-1] = Pg_VIDEO_FORMAT_RGB555;			
   1.272 +		}
   1.273 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB565)
   1.274 +		{
   1.275 +			
   1.276 +			Priority[i-1] =  2;
   1.277 +			Type[i-1] = Pg_VIDEO_FORMAT_RGB565;			
   1.278 +		}
   1.279 +		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_RGB8888)
   1.280 +		{
   1.281 +			
   1.282 +			Priority[i-1] = 1;
   1.283 +			Type[i-1] = Pg_VIDEO_FORMAT_RGB8888;			
   1.284 +		}
   1.285 +#endif
   1.286 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU1)
   1.287 +		{
   1.288 +			
   1.289 +			Priority[i-1] = 0;
   1.290 +			Type[i-1] = Pg_VIDEO_FORMAT_IYU1;
   1.291 +			
   1.292 +		}
   1.293 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU2)
   1.294 +		{
   1.295 +			
   1.296 +			Priority[i-1] = 0;
   1.297 +			Type[i-1] = Pg_VIDEO_FORMAT_IYU2;			
   1.298 +		}
   1.299 +
   1.300 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_UYVY) //in SDL
   1.301 +		{
   1.302 +			
   1.303 +			Priority[i-1] = 7;
   1.304 +			Type[i-1] = Pg_VIDEO_FORMAT_UYVY;
   1.305 +			if(format == Pg_VIDEO_FORMAT_UYVY)
   1.306 +			{
   1.307 +				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_UYVY;
   1.308 +				xv_port = 1; //supported
   1.309 +				Priority[i-1] = 100; //force selected
   1.310 +			}
   1.311 +			
   1.312 +		}
   1.313 +		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YUY2) //in SDL
   1.314 +		{
   1.315 +			
   1.316 +			Priority[i-1] = 8;
   1.317 +			Type[i-1] = Pg_VIDEO_FORMAT_YUY2;			
   1.318 +			if(format == Pg_VIDEO_FORMAT_YUY2)
   1.319 +			{
   1.320 +				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YUY2;
   1.321 +				xv_port = 1; //supported
   1.322 +				Priority[i-1] = 100; //force selected
   1.323 +			}
   1.324 +			
   1.325 +		}
   1.326 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVYU) //in SDL
   1.327 +		{
   1.328 +			
   1.329 +			Priority[i-1] = 4;
   1.330 +			Type[i-1] = Pg_VIDEO_FORMAT_YVYU;	
   1.331 +			
   1.332 +			if(format == Pg_VIDEO_FORMAT_YVYU)
   1.333 +			{
   1.334 +				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVYU;
   1.335 +				xv_port = 1; //supported
   1.336 +				Priority[i-1] = 100; //force selected
   1.337 +				
   1.338 +			}
   1.339 +		
   1.340 +		}
   1.341 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_V422)
   1.342 +		{
   1.343 +			
   1.344 +			Priority[i-1] = 5;
   1.345 +			Type[i-1] = Pg_VIDEO_FORMAT_V422;			
   1.346 +		}		
   1.347 +		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_CLJR)
   1.348 +		{
   1.349 +			
   1.350 +			Priority[i-1] = 6;
   1.351 +			Type[i-1] = Pg_VIDEO_FORMAT_CLJR;		
   1.352 +		}	
   1.353 +		else
   1.354 +		{
   1.355 +		
   1.356 +		Priority[i-1] = 0;
   1.357 +		}
   1.358 +			
   1.359 +overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
   1.360 +}
   1.361 +
   1.362 +	if ( xv_port == -1 )
   1.363 +	{
   1.364 +		SDL_SetError("No available video ports for requested format");
   1.365 +		return(NULL);
   1.366 +	}
   1.367 + 
   1.368 +//Pick the highest priority format
   1.369 +entries = i -2;
   1.370 +highest = Priority[0]; //make first entry top at begining
   1.371 +select = 0;
   1.372 +
   1.373 +for (i = 1; i < entries; i++)
   1.374 +{
   1.375 +
   1.376 +
   1.377 +   if(Priority[i] > highest)
   1.378 +   {
   1.379 +      highest = Priority[i];
   1.380 +      select  = i;
   1.381 +   }
   1.382 +} 
   1.383 +
   1.384 + 
   1.385 + 
   1.386 + overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps	);
   1.387 +PgGetScalerCapabilities(overlay->hwdata->channel, select, &(overlay->hwdata->caps));
   1.388 +overlay->hwdata->props.format = overlay->hwdata->caps.format ;
   1.389 +
   1.390 +    overlay->hwdata->format = overlay->hwdata->props.format;  //to make easier for apps to use
   1.391 +
   1.392 +
   1.393 +	overlay->hwdata->props.size = sizeof (overlay->hwdata->props);
   1.394 +    overlay->hwdata->props.src_dim.w = width;   
   1.395 +    overlay->hwdata->props.src_dim.h = height;   
   1.396 +	
   1.397 +	overlay->hwdata->chromakey = PgGetOverlayChromaColor();
   1.398 +
   1.399 +	// Set chromakey in video widget so we can see overlay data
   1.400 +	/* I don't know where the container widget is!!!, I guess it is in hidden->window*/
   1.401 +	
   1.402 +	PtEnter(0);
   1.403 +	PtSetArg( &argt, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0 );
   1.404 +	PtSetResources( window, 1, &argt ); 
   1.405 +	PtLeave(0);
   1.406 +
   1.407 +
   1.408 +	fflush( stderr );
   1.409 +
   1.410 +	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
   1.411 +	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
   1.412 +	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
   1.413 +	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
   1.414 +	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
   1.415 +		
   1.416 +
   1.417 +
   1.418 +	overlay->hwdata->props.flags =
   1.419 +	    ~Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER ;
   1.420 +
   1.421 +	if (overlay->hwdata->chromakey) {
   1.422 +		overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
   1.423 +		overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
   1.424 +		overlay->hwdata->props.color_key_mask = 0xffffff;
   1.425 +	} 
   1.426 +	else
   1.427 +	{
   1.428 +		overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
   1.429 +	}
   1.430 +
   1.431 +
   1.432 +	overlay->hwdata->scaler_on = FALSE;
   1.433 +
   1.434 +
   1.435 +
   1.436 + rtncode =    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));	
   1.437 +	switch(rtncode)
   1.438 +	{
   1.439 +	case -1:
   1.440 +		SDL_SetError("PgConfigScalerChannel failed\n");
   1.441 +		SDL_FreeYUVOverlay(overlay);
   1.442 +		return(NULL);
   1.443 +   		break;
   1.444 +	case 1:
   1.445 +		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.446 +		break;
   1.447 +	case 0:
   1.448 +	default:
   1.449 +   		break;
   1.450 +	}
   1.451 +
   1.452 +
   1.453 +	grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.454 +
   1.455 +if(overlay->hwdata->channel->yplane1 != NULL)			
   1.456 +	overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
   1.457 +if(overlay->hwdata->channel->uplane1 != NULL)			
   1.458 +	overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
   1.459 +if(overlay->hwdata->channel->vplane1 != NULL)			
   1.460 +	overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
   1.461 +
   1.462 +
   1.463 +	overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.464 +
   1.465 +
   1.466 +
   1.467 +	if (overlay->hwdata->current == -1)
   1.468 +	{
   1.469 +		SDL_SetError("PgNextFrame failed, bailing out\n");
   1.470 +		SDL_FreeYUVOverlay(overlay);
   1.471 +		return(NULL);
   1.472 +	}
   1.473 +        
   1.474 +        //set current frame for double buffering
   1.475 +	if(overlay->hwdata->current == 0)
   1.476 +	{
   1.477 +		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.478 +	}
   1.479 +	else
   1.480 +	{
   1.481 +		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.482 +	}
   1.483 +    
   1.484 +	overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
   1.485 +
   1.486 +
   1.487 +	/* We're all done.. */
   1.488 +	return(overlay);
   1.489 +}
   1.490 +
   1.491 +int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.492 +{
   1.493 +//int rtncode;
   1.494 +
   1.495 +if(overlay == NULL)
   1.496 +   return 0;
   1.497 +
   1.498 +//set current frame for double buffering
   1.499 +	if(overlay->hwdata->current == 0)
   1.500 +	{
   1.501 +		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.502 +	}
   1.503 +	else
   1.504 +	{
   1.505 +		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.506 +	}
   1.507 +
   1.508 +	//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
   1.509 +//Note this is defined as Uint8 **pixels;				/* Read-write */	
   1.510 +	overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
   1.511 +	overlay->pitches  = &overlay->hwdata->YStride;
   1.512 +		
   1.513 +	return(0);
   1.514 +}
   1.515 +
   1.516 +void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.517 +{
   1.518 +int rtncode;
   1.519 +
   1.520 +if(overlay == NULL)
   1.521 +   return ;
   1.522 +
   1.523 +		if(overlay->hwdata->scaler_on == FALSE) 
   1.524 +		{
   1.525 +			
   1.526 +		
   1.527 +		overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
   1.528 +        rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.529 +        	switch(rtncode)
   1.530 +			{
   1.531 +				case -1:
   1.532 +					SDL_SetError("PgConfigScalerChannel failed\n");
   1.533 +					SDL_FreeYUVOverlay(overlay);
   1.534 +   					break;
   1.535 +				case 1:
   1.536 +					grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.537 +					overlay->hwdata->scaler_on = TRUE;
   1.538 +					break;
   1.539 +				case 0:
   1.540 +					default:
   1.541 +					overlay->hwdata->scaler_on = TRUE;
   1.542 +   					break;
   1.543 +			}
   1.544 +//This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
   1.545 +//This means we might see a chromakey flicker at startup
   1.546 +		}
   1.547 +		overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.548 +
   1.549 +
   1.550 +	if (overlay->hwdata->current == -1) {
   1.551 +		SDL_SetError("PgNextVideoFrame failed\n");
   1.552 +		SDL_FreeYUVOverlay(overlay);	
   1.553 +		return;	
   1.554 +	}
   1.555 +
   1.556 +	overlay->pixels = NULL;
   1.557 +}
   1.558 +
   1.559 +int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
   1.560 +{
   1.561 +int rtncode;
   1.562 +
   1.563 +if(overlay == NULL)
   1.564 +   return 0;
   1.565 +
   1.566 +
   1.567 +	/*SDL_Rect CurrentWindow*/
   1.568 +//If CurrentWindow has change, move the viewport
   1.569 +if((overlay->hwdata->CurrentWindow.x != dstrect->x) ||
   1.570 +  (overlay->hwdata->CurrentWindow.y != dstrect->y) ||
   1.571 +  (overlay->hwdata->CurrentWindow.w != dstrect->w) ||
   1.572 +  (overlay->hwdata->CurrentWindow.h != dstrect->h))
   1.573 +{
   1.574 +		if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
   1.575 +		return -1;
   1.576 +
   1.577 +	overlay->hwdata->CurrentWindow.x = dstrect->x;
   1.578 +  	overlay->hwdata->CurrentWindow.y = dstrect->y;
   1.579 +  	overlay->hwdata->CurrentWindow.w = dstrect->w;
   1.580 +  	overlay->hwdata->CurrentWindow.h = dstrect->h;
   1.581 +
   1.582 +	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
   1.583 +	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
   1.584 +	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
   1.585 +	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
   1.586 +	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
   1.587 +
   1.588 +	
   1.589 +     rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.590 +
   1.591 +	switch(rtncode)
   1.592 +	{
   1.593 +	case -1:
   1.594 +		SDL_SetError("PgConfigScalerChannel failed\n");
   1.595 +		SDL_FreeYUVOverlay(overlay);
   1.596 +		return(0);
   1.597 +   		break;
   1.598 +	case 1:
   1.599 +		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.600 +		break;
   1.601 +	case 0:
   1.602 +	default:
   1.603 +   		break;
   1.604 +	}
   1.605 +}
   1.606 +
   1.607 +
   1.608 +//JB the X11 file did this. We do this in SDL_unlock, we need to confirm that lock and unlock are called for each frame!
   1.609 +//	XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
   1.610 +//	              hwdata->image, 0, 0, overlay->w, overlay->h,
   1.611 +//	              dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);	           
   1.612 +/*  This is what this call is
   1.613 +int XvShmPutImage (
   1.614 +   Display *dpy,
   1.615 +   XvPortID port,
   1.616 +   Drawable d,
   1.617 +   GC gc,
   1.618 +   XvImage *image,
   1.619 +   int src_x,
   1.620 +   int src_y,
   1.621 +   unsigned int src_w,
   1.622 +   unsigned int src_h,
   1.623 +   int dest_x, 
   1.624 +   int dest_y,
   1.625 +   unsigned int dest_w,
   1.626 +   unsigned int dest_h,
   1.627 +   Bool send_event
   1.628 +)
   1.629 +*/
   1.630 +
   1.631 +	return(0);
   1.632 +}
   1.633 +
   1.634 +void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.635 +{
   1.636 +	//struct private_yuvhwdata *hwdata;
   1.637 +
   1.638 +	if(overlay == NULL)
   1.639 +		return;
   1.640 +	
   1.641 +	if(overlay->hwdata == NULL)
   1.642 +		return;
   1.643 +	
   1.644 +	overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   1.645 +
   1.646 +	if( overlay->hwdata->channel == NULL )
   1.647 +	{
   1.648 +		return;
   1.649 +	}	
   1.650 +
   1.651 +	PgDestroyVideoChannel(overlay->hwdata->channel);
   1.652 +
   1.653 +	overlay->hwdata->channel = NULL;
   1.654 +	overlay->hwdata->CurrentFrameData = NULL;  
   1.655 +	
   1.656 +	free(overlay->hwdata->FrameData0);
   1.657 +	free(overlay->hwdata->FrameData1);
   1.658 +	overlay->hwdata->FrameData0 = NULL;
   1.659 +	overlay->hwdata->FrameData1 = NULL;
   1.660 +	free(overlay->hwdata);
   1.661 +
   1.662 +}