source: svn/zas_dstar/pdrivers/video_out_sdl.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
File size: 6.3 KB
Line 
1/*
2 * video_out_sdl.c
3 *
4 * Copyright (C) 2000-2003 Ryan C. Gordon <icculus@lokigames.com> and
5 *                         Dominik Schnitzer <aeneas@linuxvideo.org>
6 *
7 * SDL info, source, and binaries can be found at http://www.libsdl.org/
8 *
9 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
10 * See http://libmpeg2.sourceforge.net/ for updates.
11 *
12 * mpeg2dec is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * mpeg2dec is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27//#include "config.h"
28
29#define SCALE_FACTOR    2
30#define SCALE_SHIFT     (SCALE_FACTOR>>1)
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include "SDL.h"
36#include <inttypes.h>
37
38#include "dsthallocal.h"
39#include "mpeg2priv.h"
40#if 0
41#include "video_out.h"
42#include "vo_internal.h"
43#endif
44extern void DD_GFX_UpdateScreen(void);
45
46#define MAX_OVERLAY_TABLE       36
47
48//extern DS_U32 DD_GFX_GetPhysicalFrameBuffer(void);
49extern DS_U32 DD_GFX_GetVideoFrameBuffer(void);
50
51static SDL_Overlay *private_overlay = (SDL_Overlay *)NULL;
52static int i_overlay_idx = 0;
53static SDL_Overlay *overlay_table[MAX_OVERLAY_TABLE] = { (SDL_Overlay *)NULL };
54
55void sdl_setup_fbuf (sdl_instance_t * _instance,
56                unsigned char ** buf, void ** id)
57{
58    sdl_instance_t * instance = (sdl_instance_t *) _instance;
59    SDL_Overlay * overlay;
60
61    if ( private_overlay == (SDL_Overlay *)NULL )
62    {
63        int i;
64       
65        private_overlay = SDL_CreateYUVOverlay (instance->width>>SCALE_SHIFT, instance->height>>SCALE_SHIFT,
66                                          SDL_YV12_OVERLAY, instance->surface);
67        for (i=0; i<MAX_OVERLAY_TABLE; i++)
68            overlay_table[i] = SDL_CreateYUVOverlay (instance->width, instance->height,
69                                          SDL_YV12_OVERLAY, instance->surface);
70        i_overlay_idx = 0;
71    }
72
73#if 0
74    *id = overlay = SDL_CreateYUVOverlay (instance->width, instance->height,
75                                          SDL_YV12_OVERLAY, instance->surface);
76#else
77    *id = overlay = overlay_table[i_overlay_idx++];
78    if ( i_overlay_idx >= MAX_OVERLAY_TABLE )
79        i_overlay_idx = 0;
80#endif
81        if ( overlay == NULL )
82        {
83            printf("SDL_CreateYUVOverlay: %s\n", SDL_GetError());
84            fprintf(stderr, "!!! cannot allocate overlay.\n");
85            return;
86        }
87       
88    buf[0] = overlay->pixels[0];
89    buf[1] = overlay->pixels[2];
90    buf[2] = overlay->pixels[1];
91    if (((long)buf[0] & 15) || ((long)buf[1] & 15) || ((long)buf[2] & 15)) {
92            fprintf (stderr, "Unaligned buffers. Anyone know how to fix this ?\n");
93            return;
94    }
95}
96
97void sdl_start_fbuf (sdl_instance_t * instance,
98                            const unsigned char* buf, void * id)
99{
100    if ( instance->surface == NULL )
101        return;
102
103    SDL_LockYUVOverlay ((SDL_Overlay *) id);
104}
105
106void sdl_draw_frame (sdl_instance_t * _instance,
107                            const unsigned char * buf, void * id)
108{
109    sdl_instance_t * instance = (sdl_instance_t *) _instance;
110    SDL_Overlay * overlay = (SDL_Overlay *) id;
111//    SDL_Event event;
112    int n, x, y;
113    int sw, sh, dw, dh;
114    unsigned char *dp, *sp;
115
116    if ( instance->surface == NULL )
117        return;
118       
119#if 0
120    while (SDL_PollEvent (&event))
121        if (event.type == SDL_VIDEORESIZE)
122            instance->surface =
123                SDL_SetVideoMode (event.resize.w, event.resize.h,
124                                  instance->bpp, instance->sdlflags);
125#endif
126
127    for (n=0; n<3; n++)
128    {
129        dp = private_overlay->pixels[n];
130        dw = private_overlay->pitches[n];
131        dh = private_overlay->h;
132
133        sp = overlay->pixels[n];
134        sw = overlay->pitches[n];
135        sh = overlay->h;
136
137        for (y=0; y<dh; y++)
138        {
139            for (x=0; x<dw; x++)
140            {
141                dp[x+y*dw] = sp[(x+y*sw)<<SCALE_SHIFT];
142            }
143        }
144    }
145
146//    SDL_DisplayYUVOverlay (overlay, &(instance->surface->clip_rect));
147      SDL_DisplayYUVOverlay (private_overlay, &(instance->surface->clip_rect));
148      //SDL_Flip( instance->surface );
149      //DD_GFX_UpdateScreen();
150      DHL_GFX_UpdateScreen(0);
151}
152
153void sdl_discard (sdl_instance_t * _instance,
154                         const unsigned * buf, void * id)
155{
156    if ( _instance->surface == NULL )
157        return;
158
159    SDL_UnlockYUVOverlay ((SDL_Overlay *) id);
160    //SDL_FreeYUVOverlay ((SDL_Overlay *) id);
161}
162
163int sdl_setup (sdl_instance_t * _instance, unsigned int width,
164                      unsigned int height, unsigned int chroma_width,
165                      unsigned int chroma_height)
166{
167    sdl_instance_t * instance;
168
169    instance = (sdl_instance_t *) _instance;
170
171    instance->width = width;
172    instance->height = height;
173    //instance->surface = SDL_SetVideoMode (width>>SCALE_SHIFT, height>>SCALE_SHIFT, instance->bpp, instance->sdlflags);
174    //instance->surface = SDL_GetVideoSurface();
175    instance->surface = (SDL_Surface *)DD_GFX_GetVideoFrameBuffer();
176    if (! (instance->surface)) {
177            fprintf (stderr, "sdl could not set the desired video mode\n");
178            return 1;
179    }
180
181//    result->convert = NULL;
182    return 0;
183}
184
185void sdl_discard_all_buffer(sdl_instance_t *instance)
186{
187    if ( private_overlay )
188    {
189        int i;
190
191        SDL_FreeYUVOverlay( private_overlay );
192        private_overlay = (SDL_Overlay *)NULL;
193
194        for (i=0; i<MAX_OVERLAY_TABLE; i++)
195        {
196            SDL_FreeYUVOverlay( overlay_table[i] );
197            overlay_table[i] = (SDL_Overlay *)NULL;
198        }
199       
200        i_overlay_idx = 0;
201    }
202}
203
204sdl_instance_t *sdl_open(int width, int height)
205{
206    sdl_instance_t *p;
207   
208    p = (sdl_instance_t *)malloc(sizeof(sdl_instance_t));
209    if ( !p )
210    {
211        fprintf(stderr, "!!! cannot allocate sdl_instance_t\n");
212        return (sdl_instance_t *)NULL;
213    }
214
215#if 0
216    if (SDL_Init (SDL_INIT_VIDEO)) {
217        fprintf (stderr, "sdl video initialization failed.\n");
218        return NULL;
219    }
220#endif
221
222    memset(p, 0, sizeof(sdl_instance_t));
223    p->bpp = 32;
224    p->sdlflags = SDL_HWSURFACE | SDL_RESIZABLE;
225    //p->width = width;
226    //p->height = height;
227   
228    return p;
229}
Note: See TracBrowser for help on using the repository browser.