Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

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  * video_out_sdl.c
00003  *
00004  * Copyright (C) 2000-2002 Ryan C. Gordon <icculus@lokigames.com> and
00005  *                         Dominik Schnitzer <aeneas@linuxvideo.org>
00006  *
00007  * SDL info, source, and binaries can be found at http://www.libsdl.org/
00008  *
00009  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
00010  * See http://libmpeg2.sourceforge.net/ for updates.
00011  *
00012  * mpeg2dec is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * mpeg2dec is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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; /* sdl_close; */
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
 

Powered by Plone

This site conforms to the following standards: