Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 4408:291832d8d984
added constant-qscale encoding support with lavc, fixed slightly incorrect definition for the vme lavc option
author | rfelker |
---|---|
date | Tue, 29 Jan 2002 16:27:21 +0000 |
parents | ed5b85b713a3 |
children | df8e0f71cc3c |
rev | line source |
---|---|
100 | 1 |
2 //#define SHOW_TIME | |
1 | 3 |
4 /* | |
5 * video_out_xmga.c | |
6 * | |
7 * Copyright (C) Zoltan Ponekker - Jan 2001 | |
8 * | |
9 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | |
10 * | |
11 * mpeg2dec is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2, or (at your option) | |
14 * any later version. | |
15 * | |
16 * mpeg2dec is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with GNU Make; see the file COPYING. If not, write to | |
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 */ | |
26 | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 | |
31 #include "config.h" | |
32 #include "video_out.h" | |
33 #include "video_out_internal.h" | |
34 | |
35 LIBVO_EXTERN( xmga ) | |
36 | |
37 #include <sys/ioctl.h> | |
38 #include <unistd.h> | |
39 #include <fcntl.h> | |
40 #include <sys/mman.h> | |
41 | |
42 #include "drivers/mga_vid.h" | |
43 | |
44 #include <X11/Xlib.h> | |
45 #include <X11/Xutil.h> | |
46 #include <errno.h> | |
47 | |
4017 | 48 #ifdef HAVE_XINERAMA |
49 #include <X11/extensions/Xinerama.h> | |
50 #endif | |
51 | |
31 | 52 #include "x11_common.h" |
616 | 53 #include "sub.h" |
2057 | 54 #include "aspect.h" |
31 | 55 |
182 | 56 #ifdef SHOW_TIME |
100 | 57 #include "../linux/timer.h" |
58 static unsigned int timer=0; | |
59 static unsigned int timerd=0; | |
60 #endif | |
61 | |
1 | 62 static vo_info_t vo_info = |
63 { | |
64 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)", | |
65 "xmga", | |
66 "Zoltan Ponekker <pontscho@makacs.poliod.hu>", | |
67 "" | |
68 }; | |
69 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
70 //static Display * mDisplay; |
1 | 71 static Window mWindow; |
72 static GC mGC; | |
73 static XGCValues wGCV; | |
74 | |
75 static XImage * myximage; | |
76 | |
77 static uint32_t mDepth, bpp, mode; | |
78 static XWindowAttributes attribs; | |
79 static uint32_t X_already_started=0; | |
80 | |
81 static uint32_t wndHeight; | |
82 static uint32_t wndWidth; | |
83 static uint32_t wndX; | |
84 static uint32_t wndY; | |
85 | |
86 static uint32_t fgColor; | |
87 | |
88 static uint32_t mvHeight; | |
89 static uint32_t mvWidth; | |
90 | |
91 static Window mRoot; | |
92 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth; | |
93 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen; | |
94 | |
1783 | 95 #ifdef HAVE_NEW_GUI |
723 | 96 static uint32_t mdwidth,mdheight; |
97 #endif | |
98 | |
1 | 99 static XSetWindowAttributes xWAttribs; |
100 | |
101 #include "mga_common.c" | |
102 | |
103 static void mDrawColorKey( void ) | |
104 { | |
105 XSetForeground( mDisplay,mGC,fgColor ); | |
106 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) ); | |
107 XFlush( mDisplay ); | |
108 } | |
109 | |
120 | 110 static void set_window(){ |
111 | |
1783 | 112 #ifdef HAVE_NEW_GUI |
723 | 113 if ( vo_window != None ) |
114 { | |
115 mFullscreen=0; | |
116 dwidth=mdwidth; dheight=mdheight; | |
1852 | 117 if ( ( vo_dwidth == vo_screenwidth )&&( vo_dheight == vo_screenheight ) ) |
723 | 118 { |
119 mFullscreen=1; | |
120 dwidth=vo_screenwidth; | |
121 dheight=vo_screenwidth * mdheight / mdwidth; | |
122 } | |
123 } | |
124 #endif | |
125 | |
1852 | 126 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); |
127 drwX=0; drwY=0; // drwWidth=wndWidth; drwHeight=wndHeight; | |
128 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot ); | |
129 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); | |
130 | |
3558 | 131 aspect(&dwidth,&dheight,A_NOZOOM); |
120 | 132 if ( mFullscreen ) |
133 { | |
3558 | 134 aspect(&dwidth,&dheight,A_ZOOM); |
120 | 135 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; |
136 drwcX+=drwX; | |
137 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
138 drwcY+=drwY; | |
139 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
140 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
1852 | 141 fprintf( stderr,"[xmga-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
120 | 142 } |
143 | |
144 mDrawColorKey(); | |
145 | |
4017 | 146 #ifdef HAVE_XINERAMA |
147 if(XineramaIsActive(mDisplay)) | |
148 { | |
149 XineramaScreenInfo *screens; | |
150 int num_screens; | |
151 int i; | |
152 | |
153 screens = XineramaQueryScreens(mDisplay,&num_screens); | |
154 | |
155 /* find the screen we are on */ | |
156 i = 0; | |
157 while(!(screens[i].x_org <= drwcX && screens[i].y_org <= drwcY && | |
158 screens[i].x_org + screens[i].width >= drwcX && | |
159 screens[i].y_org + screens[i].height >= drwcY )) | |
160 { | |
161 i++; | |
162 } | |
163 | |
164 /* set drwcX and drwcY to the right values */ | |
165 drwcX = drwcX - screens[i].x_org; | |
166 drwcY = drwcY - screens[i].y_org; | |
167 XFree(screens); | |
168 } | |
169 | |
170 #endif | |
120 | 171 mga_vid_config.x_org=drwcX; |
172 mga_vid_config.y_org=drwcY; | |
173 mga_vid_config.dest_width=drwWidth; | |
174 mga_vid_config.dest_height=drwHeight; | |
175 | |
176 } | |
177 | |
31 | 178 static void check_events(void) |
1 | 179 { |
4303 | 180 int e=vo_x11_check_events(mDisplay); |
181 if ( !(e&VO_EVENT_RESIZE) && !(e&VO_EVENT_EXPOSE) ) return; | |
182 if(e&VO_EVENT_EXPOSE) mDrawColorKey(); | |
183 set_window(); | |
184 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) | |
185 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); | |
1 | 186 } |
187 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
188 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
189 { vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);} |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
190 |
31 | 191 static void flip_page(void){ |
182 | 192 #ifdef SHOW_TIME |
100 | 193 unsigned int t; |
194 t=GetTimer(); | |
195 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); | |
196 timerd=t-timer; | |
197 timer=t; | |
182 | 198 #endif |
100 | 199 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
200 vo_mga_flip_page(); |
31 | 201 } |
1 | 202 |
203 static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format ) | |
204 { | |
205 char * frame_mem; | |
56 | 206 // uint32_t frame_size; |
927 | 207 // int mScreen; |
1 | 208 unsigned int fg, bg; |
209 char * mTitle=(title == NULL) ? "XMGA render" : title; | |
210 char * name=":0.0"; | |
211 XSizeHints hint; | |
212 XVisualInfo vinfo; | |
213 XEvent xev; | |
214 | |
215 XGCValues xgcv; | |
216 unsigned long xswamask; | |
217 | |
1210 | 218 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
219 | |
220 f = open(devname,O_RDWR); | |
221 if(f == -1) | |
222 { | |
1637 | 223 perror("open"); |
1210 | 224 printf("Couldn't open %s\n",devname); |
225 return(-1); | |
226 } | |
1 | 227 |
228 switch(format) | |
229 { | |
182 | 230 case IMGFMT_YV12: |
56 | 231 mga_vid_config.format=MGA_VID_FORMAT_YV12; |
182 | 232 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; |
56 | 233 break; |
470 | 234 case IMGFMT_I420: |
235 mga_vid_config.format=MGA_VID_FORMAT_I420; | |
236 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
237 break; | |
238 case IMGFMT_IYUV: | |
239 mga_vid_config.format=MGA_VID_FORMAT_IYUV; | |
240 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
241 break; | |
56 | 242 case IMGFMT_YUY2: |
243 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 244 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 245 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
246 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
247 mga_vid_config.format=MGA_VID_FORMAT_UYVY; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
248 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
249 break; |
614 | 250 default: printf("mga: invalid output format %0X\n",format); return (-1); |
1 | 251 } |
252 | |
253 if ( X_already_started ) return -1; | |
254 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
255 if (!vo_init()) return -1; |
1 | 256 |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
257 aspect_save_orig(width,height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
258 aspect_save_prescale(d_width,d_height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
259 aspect_save_screenres(vo_screenwidth,vo_screenheight); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
260 |
1 | 261 mvWidth=width; mvHeight=height; |
262 | |
263 wndX=0; wndY=0; | |
264 wndWidth=d_width; wndHeight=d_height; | |
1783 | 265 #ifdef HAVE_NEW_GUI |
1852 | 266 // mdwidth=d_width; mdheight=d_height; |
267 mdwidth=width; mdheight=height; | |
723 | 268 #endif |
844 | 269 mFullscreen=fullscreen&1; |
1 | 270 |
271 switch ( vo_depthonscreen ) | |
272 { | |
273 case 32: | |
274 case 24: fgColor=0x00ff00ffL; break; | |
275 case 16: fgColor=0xf81fL; break; | |
276 case 15: fgColor=0x7c1fL; break; | |
614 | 277 default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; |
1 | 278 } |
279 | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
280 aspect(&d_width,&d_height,A_NOZOOM); |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
281 #ifdef HAVE_NEW_GUI |
723 | 282 if ( vo_window == None ) |
283 { | |
284 #endif | |
844 | 285 if ( mFullscreen ) |
723 | 286 { |
287 wndWidth=vo_screenwidth; | |
288 wndHeight=vo_screenheight; | |
2039 | 289 #ifdef X11_FULLSCREEN |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
290 aspect(&d_width,&d_height,A_ZOOM); |
2039 | 291 #endif |
723 | 292 } |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
293 dwidth=d_width; dheight=d_height; |
723 | 294 |
295 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
296 mDepth=attribs.depth; | |
297 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
298 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
299 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
300 xWAttribs.background_pixel=0; | |
301 xWAttribs.border_pixel=0; | |
302 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask; | |
303 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; | |
1 | 304 |
3847 | 305 if ( WinID>=0 ){ |
306 mWindow = WinID ? ((Window)WinID) : RootWindow(mDisplay,mScreen); | |
307 XUnmapWindow( mDisplay,mWindow ); | |
308 XChangeWindowAttributes( mDisplay,mWindow,xswamask,&xWAttribs); | |
309 } else | |
723 | 310 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ), |
311 wndX,wndY, | |
312 wndWidth,wndHeight, | |
313 xWAttribs.border_pixel, | |
314 mDepth, | |
315 InputOutput, | |
316 vinfo.visual,xswamask,&xWAttribs ); | |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
927
diff
changeset
|
317 vo_x11_classhint( mDisplay,mWindow,"xmga" ); |
723 | 318 vo_hidecursor(mDisplay,mWindow); |
319 | |
844 | 320 if ( mFullscreen ) vo_x11_decoration( mDisplay,mWindow,0 ); |
1 | 321 |
723 | 322 XGetNormalHints( mDisplay,mWindow,&hint ); |
323 hint.x=wndX; hint.y=wndY; | |
324 hint.width=wndWidth; hint.height=wndHeight; | |
325 hint.base_width=wndWidth; hint.base_height=wndHeight; | |
326 hint.flags=USPosition | USSize; | |
327 XSetNormalHints( mDisplay,mWindow,&hint ); | |
328 XStoreName( mDisplay,mWindow,mTitle ); | |
329 XMapWindow( mDisplay,mWindow ); | |
3990 | 330 #ifdef HAVE_XINERAMA |
331 vo_x11_xinerama_move(mDisplay,mWindow); | |
332 #endif | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
333 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV ); |
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
334 #ifdef HAVE_NEW_GUI |
723 | 335 } |
336 else | |
337 { | |
338 mWindow=vo_window; | |
1852 | 339 // fprintf( stderr,"[xmga] width: %d height: %d d_width: %d d_height: %d\n",width,height,d_width,d_height ); |
340 // if ( vo_screenwidth != d_width ) | |
341 // { | |
342 // XMoveWindow( mDisplay,mWindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 ); | |
343 // XResizeWindow( mDisplay,mWindow,d_width,d_height ); | |
344 // } | |
345 // else mFullscreen=1; | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
346 mGC=vo_gc; //XCreateGC( mDisplay,mWindow,GCForeground,&wGCV ); |
723 | 347 } |
348 #endif | |
1 | 349 |
120 | 350 set_window(); |
1 | 351 |
352 mga_vid_config.src_width=width; | |
353 mga_vid_config.src_height=height; | |
354 | |
355 mga_vid_config.colkey_on=1; | |
356 mga_vid_config.colkey_red=255; | |
357 mga_vid_config.colkey_green=0; | |
358 mga_vid_config.colkey_blue=255; | |
359 | |
56 | 360 if(mga_init()) return -1; |
1852 | 361 |
362 set_window(); | |
1 | 363 |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
364 #ifdef HAVE_NEW_GUI |
723 | 365 if ( vo_window == None ) |
366 #endif | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
367 { |
723 | 368 XFlush( mDisplay ); |
369 XSync( mDisplay,False ); | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
370 } |
4316 | 371 |
372 saver_off(mDisplay); | |
324 | 373 |
1 | 374 return 0; |
375 } | |
376 | |
377 static const vo_info_t* get_info( void ) | |
378 { return &vo_info; } | |
379 | |
380 | |
381 static void | |
382 uninit(void) | |
383 { | |
4316 | 384 saver_on(mDisplay); |
1852 | 385 #ifdef HAVE_NEW_GUI |
386 if ( vo_window == None ) | |
387 #endif | |
1924 | 388 { |
389 XDestroyWindow( mDisplay,mWindow ); | |
390 } | |
1637 | 391 mga_uninit(); |
392 printf("vo: uninit!\n"); | |
1 | 393 } |
4352 | 394 |
395 static uint32_t preinit(const char *arg) | |
396 { | |
397 return 0; | |
398 } | |
399 | |
400 static void query_vaa(vo_vaa_t *vaa) | |
401 { | |
402 memset(vaa,0,sizeof(vo_vaa_t)); | |
403 } |