/* * video_out_sdl.c * * Copyright (C) 2000-2003 Ryan C. Gordon and * Dominik Schnitzer * * SDL info, source, and binaries can be found at http://www.libsdl.org/ * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * See http://libmpeg2.sourceforge.net/ for updates. * * mpeg2dec is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * mpeg2dec is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //#include "config.h" #define SCALE_FACTOR 2 #define SCALE_SHIFT (SCALE_FACTOR>>1) #include #include #include #include "SDL.h" #include #include "dsthallocal.h" #include "mpeg2priv.h" #if 0 #include "video_out.h" #include "vo_internal.h" #endif extern void DD_GFX_UpdateScreen(void); #define MAX_OVERLAY_TABLE 36 //extern DS_U32 DD_GFX_GetPhysicalFrameBuffer(void); extern DS_U32 DD_GFX_GetVideoFrameBuffer(void); static SDL_Overlay *private_overlay = (SDL_Overlay *)NULL; static int i_overlay_idx = 0; static SDL_Overlay *overlay_table[MAX_OVERLAY_TABLE] = { (SDL_Overlay *)NULL }; void sdl_setup_fbuf (sdl_instance_t * _instance, unsigned char ** buf, void ** id) { sdl_instance_t * instance = (sdl_instance_t *) _instance; SDL_Overlay * overlay; if ( private_overlay == (SDL_Overlay *)NULL ) { int i; private_overlay = SDL_CreateYUVOverlay (instance->width>>SCALE_SHIFT, instance->height>>SCALE_SHIFT, SDL_YV12_OVERLAY, instance->surface); for (i=0; iwidth, instance->height, SDL_YV12_OVERLAY, instance->surface); i_overlay_idx = 0; } #if 0 *id = overlay = SDL_CreateYUVOverlay (instance->width, instance->height, SDL_YV12_OVERLAY, instance->surface); #else *id = overlay = overlay_table[i_overlay_idx++]; if ( i_overlay_idx >= MAX_OVERLAY_TABLE ) i_overlay_idx = 0; #endif if ( overlay == NULL ) { printf("SDL_CreateYUVOverlay: %s\n", SDL_GetError()); fprintf(stderr, "!!! cannot allocate overlay.\n"); return; } buf[0] = overlay->pixels[0]; buf[1] = overlay->pixels[2]; buf[2] = overlay->pixels[1]; if (((long)buf[0] & 15) || ((long)buf[1] & 15) || ((long)buf[2] & 15)) { fprintf (stderr, "Unaligned buffers. Anyone know how to fix this ?\n"); return; } } void sdl_start_fbuf (sdl_instance_t * instance, const unsigned char* buf, void * id) { if ( instance->surface == NULL ) return; SDL_LockYUVOverlay ((SDL_Overlay *) id); } void sdl_draw_frame (sdl_instance_t * _instance, const unsigned char * buf, void * id) { sdl_instance_t * instance = (sdl_instance_t *) _instance; SDL_Overlay * overlay = (SDL_Overlay *) id; // SDL_Event event; int n, x, y; int sw, sh, dw, dh; unsigned char *dp, *sp; if ( instance->surface == NULL ) return; #if 0 while (SDL_PollEvent (&event)) if (event.type == SDL_VIDEORESIZE) instance->surface = SDL_SetVideoMode (event.resize.w, event.resize.h, instance->bpp, instance->sdlflags); #endif for (n=0; n<3; n++) { dp = private_overlay->pixels[n]; dw = private_overlay->pitches[n]; dh = private_overlay->h; sp = overlay->pixels[n]; sw = overlay->pitches[n]; sh = overlay->h; for (y=0; ysurface->clip_rect)); SDL_DisplayYUVOverlay (private_overlay, &(instance->surface->clip_rect)); //SDL_Flip( instance->surface ); //DD_GFX_UpdateScreen(); DHL_GFX_UpdateScreen(0); } void sdl_discard (sdl_instance_t * _instance, const unsigned * buf, void * id) { if ( _instance->surface == NULL ) return; SDL_UnlockYUVOverlay ((SDL_Overlay *) id); //SDL_FreeYUVOverlay ((SDL_Overlay *) id); } int sdl_setup (sdl_instance_t * _instance, unsigned int width, unsigned int height, unsigned int chroma_width, unsigned int chroma_height) { sdl_instance_t * instance; instance = (sdl_instance_t *) _instance; instance->width = width; instance->height = height; //instance->surface = SDL_SetVideoMode (width>>SCALE_SHIFT, height>>SCALE_SHIFT, instance->bpp, instance->sdlflags); //instance->surface = SDL_GetVideoSurface(); instance->surface = (SDL_Surface *)DD_GFX_GetVideoFrameBuffer(); if (! (instance->surface)) { fprintf (stderr, "sdl could not set the desired video mode\n"); return 1; } // result->convert = NULL; return 0; } void sdl_discard_all_buffer(sdl_instance_t *instance) { if ( private_overlay ) { int i; SDL_FreeYUVOverlay( private_overlay ); private_overlay = (SDL_Overlay *)NULL; for (i=0; ibpp = 32; p->sdlflags = SDL_HWSURFACE | SDL_RESIZABLE; //p->width = width; //p->height = height; return p; }