Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
video_out_sdl.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "config.h"
00028
00029 #ifdef LIBVO_SDL
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <SDL/SDL.h>
00035 #include <inttypes.h>
00036
00037 #include "video_out.h"
00038
00039 typedef struct {
00040 vo_instance_t vo;
00041 int width;
00042 int height;
00043 SDL_Surface * surface;
00044 Uint32 sdlflags;
00045 Uint8 bpp;
00046 } sdl_instance_t;
00047
00048 static void sdl_setup_fbuf (vo_instance_t * _instance,
00049 uint8_t ** buf, void ** id)
00050 {
00051 sdl_instance_t * instance = (sdl_instance_t *) _instance;
00052 SDL_Overlay * overlay;
00053
00054 *id = overlay = SDL_CreateYUVOverlay (instance->width, instance->height,
00055 SDL_YV12_OVERLAY, instance->surface);
00056 buf[0] = overlay->pixels[0];
00057 buf[1] = overlay->pixels[2];
00058 buf[2] = overlay->pixels[1];
00059 }
00060
00061 static void sdl_start_fbuf (vo_instance_t * instance,
00062 uint8_t * const * buf, void * id)
00063 {
00064 SDL_LockYUVOverlay ((SDL_Overlay *) id);
00065 }
00066
00067 static void sdl_draw_frame (vo_instance_t * _instance,
00068 uint8_t * const * buf, void * id)
00069 {
00070 sdl_instance_t * instance = (sdl_instance_t *) _instance;
00071 SDL_Overlay * overlay = (SDL_Overlay *) id;
00072 SDL_Event event;
00073
00074 while (SDL_PollEvent (&event))
00075 if (event.type == SDL_VIDEORESIZE)
00076 instance->surface =
00077 SDL_SetVideoMode (event.resize.w, event.resize.h,
00078 instance->bpp, instance->sdlflags);
00079 SDL_DisplayYUVOverlay (overlay, &(instance->surface->clip_rect));
00080 }
00081
00082 static void sdl_discard (vo_instance_t * _instance,
00083 uint8_t * const * buf, void * id)
00084 {
00085 SDL_UnlockYUVOverlay ((SDL_Overlay *) id);
00086 }
00087
00088 #if 0
00089 static void sdl_close (vo_instance_t * _instance)
00090 {
00091 sdl_instance_t * instance;
00092 int i;
00093
00094 instance = (sdl_instance_t *) _instance;
00095 for (i = 0; i < 3; i++)
00096 SDL_FreeYUVOverlay (instance->frame[i].overlay);
00097 SDL_FreeSurface (instance->surface);
00098 SDL_QuitSubSystem (SDL_INIT_VIDEO);
00099 }
00100 #endif
00101
00102 static int sdl_setup (vo_instance_t * _instance, int width, int height,
00103 vo_setup_result_t * result)
00104 {
00105 sdl_instance_t * instance;
00106
00107 instance = (sdl_instance_t *) _instance;
00108
00109 instance->width = width;
00110 instance->height = height;
00111 instance->surface = SDL_SetVideoMode (width, height, instance->bpp,
00112 instance->sdlflags);
00113 if (! (instance->surface)) {
00114 fprintf (stderr, "sdl could not set the desired video mode\n");
00115 return 1;
00116 }
00117
00118 result->convert = NULL;
00119 return 0;
00120 }
00121
00122 vo_instance_t * vo_sdl_open (void)
00123 {
00124 sdl_instance_t * instance;
00125 const SDL_VideoInfo * vidInfo;
00126
00127 instance = (sdl_instance_t *) malloc (sizeof (sdl_instance_t));
00128 if (instance == NULL)
00129 return NULL;
00130
00131 instance->vo.setup = sdl_setup;
00132 instance->vo.setup_fbuf = sdl_setup_fbuf;
00133 instance->vo.set_fbuf = NULL;
00134 instance->vo.start_fbuf = sdl_start_fbuf;
00135 instance->vo.discard = sdl_discard;
00136 instance->vo.draw = sdl_draw_frame;
00137 instance->vo.close = NULL;
00138 instance->sdlflags = SDL_HWSURFACE | SDL_RESIZABLE;
00139
00140 putenv("SDL_VIDEO_YUV_HWACCEL=1");
00141 putenv("SDL_VIDEO_X11_NODIRECTCOLOR=1");
00142
00143 if (SDL_Init (SDL_INIT_VIDEO)) {
00144 fprintf (stderr, "sdl video initialization failed.\n");
00145 return NULL;
00146 }
00147
00148 vidInfo = SDL_GetVideoInfo ();
00149 if (!SDL_ListModes (vidInfo->vfmt, SDL_HWSURFACE | SDL_RESIZABLE)) {
00150 instance->sdlflags = SDL_RESIZABLE;
00151 if (!SDL_ListModes (vidInfo->vfmt, SDL_RESIZABLE)) {
00152 fprintf (stderr, "sdl couldn't get any acceptable video mode\n");
00153 return NULL;
00154 }
00155 }
00156 instance->bpp = vidInfo->vfmt->BitsPerPixel;
00157 if (instance->bpp < 16) {
00158 fprintf(stderr, "sdl has to emulate a 16 bit surfaces, "
00159 "that will slow things down.\n");
00160 instance->bpp = 16;
00161 }
00162
00163 return (vo_instance_t *) instance;
00164 }
00165 #endif