Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 3169:b6bb21d686cd
completed the summary displayed after running configure
(todo: optimization option to add)
author | pl |
---|---|
date | Tue, 27 Nov 2001 21:54:27 +0000 |
parents | c9f140f5a34e |
children | e9b18714e3dc |
rev | line source |
---|---|
2869 | 1 /* |
2 * vesa_lvo.c | |
3 * | |
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001 | |
5 * | |
6 * You can redistribute this file under terms and conditions | |
7 * of GNU General Public licence v2. | |
8 * | |
9 * This file contains vo_vesa interface to Linux Video Overlay. | |
10 * (Partly based on vo_mga.c from mplayer's package) | |
11 */ | |
12 | |
13 #include <inttypes.h> | |
14 #include <sys/ioctl.h> | |
15 #include <unistd.h> | |
16 #include <fcntl.h> | |
17 #include <sys/mman.h> | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include "vesa_lvo.h" | |
23 #include "img_format.h" | |
24 #include "../drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */ | |
25 #include "fastmemcpy.h" | |
26 | |
3165 | 27 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */ |
2869 | 28 #define NUM_FRAMES 2 |
29 static uint8_t *frames[NUM_FRAMES]; | |
30 | |
31 static int lvo_handler = -1; | |
32 static uint8_t *lvo_mem = NULL; | |
33 static uint8_t next_frame; | |
34 static mga_vid_config_t mga_vid_config; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
35 static unsigned image_bpp,image_height,image_width,src_format; |
2952 | 36 extern int verbose; |
2869 | 37 |
38 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8) | |
39 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) ) | |
40 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size)) | |
41 | |
2971 | 42 int vlvo_preinit(const char *drvname) |
43 { | |
3017 | 44 if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname); |
2971 | 45 lvo_handler = open(drvname,O_RDWR); |
46 if(lvo_handler == -1) | |
47 { | |
48 printf("vesa_lvo: Couldn't open '%s'\n",drvname); | |
49 return -1; | |
50 } | |
51 return 0; | |
52 } | |
53 | |
54 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 55 unsigned x_org,unsigned y_org,unsigned dst_width, |
56 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
57 { | |
58 size_t i,awidth; | |
3017 | 59 if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n"); |
2869 | 60 image_width = src_width; |
61 image_height = src_height; | |
62 mga_vid_config.version=MGA_VID_VERSION; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
63 src_format = mga_vid_config.format=format; |
2869 | 64 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
65 switch(format){ | |
66 case IMGFMT_YV12: | |
67 case IMGFMT_I420: | |
68 case IMGFMT_IYUV: | |
69 image_bpp=16; | |
70 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2; | |
71 break; | |
72 case IMGFMT_YUY2: | |
73 case IMGFMT_UYVY: | |
74 image_bpp=16; | |
75 mga_vid_config.frame_size = awidth*src_height*2; | |
76 break; | |
77 case IMGFMT_RGB15: | |
78 case IMGFMT_BGR15: | |
79 case IMGFMT_RGB16: | |
80 case IMGFMT_BGR16: | |
81 image_bpp=16; | |
82 mga_vid_config.frame_size = awidth*src_height*2; | |
83 break; | |
84 case IMGFMT_RGB24: | |
85 case IMGFMT_BGR24: | |
86 image_bpp=24; | |
87 mga_vid_config.frame_size = awidth*src_height*3; | |
88 break; | |
89 case IMGFMT_RGB32: | |
90 case IMGFMT_BGR32: | |
91 image_bpp=32; | |
92 mga_vid_config.frame_size = awidth*src_height*4; | |
93 break; | |
94 default: | |
95 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format); | |
96 return -1; | |
97 } | |
98 mga_vid_config.colkey_on=0; | |
99 mga_vid_config.src_width = src_width; | |
100 mga_vid_config.src_height= src_height; | |
101 mga_vid_config.dest_width = dst_width; | |
102 mga_vid_config.dest_height= dst_height; | |
103 mga_vid_config.x_org=x_org; | |
104 mga_vid_config.y_org=y_org; | |
105 mga_vid_config.num_frames=NUM_FRAMES; | |
106 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
107 { | |
2971 | 108 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
109 printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n"); | |
2869 | 110 return -1; |
111 } | |
112 ioctl(lvo_handler,MGA_VID_ON,0); | |
113 | |
114 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
115 for(i=1;i<NUM_FRAMES;i++) | |
116 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
117 next_frame = 0; | |
118 lvo_mem = frames[next_frame]; | |
119 | |
120 /*clear the buffer*/ | |
121 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
122 return 0; | |
123 } | |
124 | |
125 void vlvo_term( void ) | |
126 { | |
3017 | 127 if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n"); |
2869 | 128 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
129 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
130 if(lvo_handler != -1) close(lvo_handler); | |
131 } | |
132 | |
3165 | 133 uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) |
2869 | 134 { |
135 uint8_t *src; | |
136 uint8_t *dest; | |
3020 | 137 uint32_t bespitch,bespitch2; |
2869 | 138 int i; |
139 | |
140 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
141 bespitch2 = bespitch/2; | |
142 | |
143 dest = lvo_mem + bespitch * y + x; | |
144 src = image[0]; | |
145 for(i=0;i<h;i++){ | |
146 memcpy(dest,src,w); | |
147 src+=stride[0]; | |
148 dest += bespitch; | |
149 } | |
150 | |
151 w/=2;h/=2;x/=2;y/=2; | |
152 | |
153 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
154 src = image[1]; | |
155 for(i=0;i<h;i++){ | |
156 memcpy(dest,src,w); | |
157 src+=stride[1]; | |
158 dest += bespitch2; | |
159 } | |
160 | |
161 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
162 + bespitch*mga_vid_config.src_height / 4 | |
163 + bespitch2 * y + x; | |
164 src = image[2]; | |
165 for(i=0;i<h;i++){ | |
166 memcpy(dest,src,w); | |
167 src+=stride[2]; | |
168 dest += bespitch2; | |
169 } | |
3020 | 170 return 0; |
171 } | |
172 | |
173 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
174 { | |
2952 | 175 uint8_t *dst; |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
176 uint8_t bytpp; |
3020 | 177 if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n"); |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
178 bytpp = (image_bpp+7)/8; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
179 dst = lvo_mem + (image_width * y + x)*bytpp; |
3165 | 180 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) |
181 vlvo_draw_slice_420(image,stride,w,h,x,y); | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
182 else |
3165 | 183 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */ |
3017 | 184 memcpy(dst,image[0],mga_vid_config.frame_size); |
2924 | 185 return 0; |
2869 | 186 } |
187 | |
3017 | 188 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 189 { |
3017 | 190 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
191 memcpy(lvo_mem,image[0],mga_vid_config.frame_size); | |
192 if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n"); | |
193 return 0; | |
2869 | 194 } |
195 | |
196 void vlvo_flip_page(void) | |
197 { | |
3017 | 198 if(verbose > 1) printf("vesa_lvo: vlvo_flip_page() was called\n"); |
2869 | 199 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
200 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
201 lvo_mem=frames[next_frame]; | |
202 } | |
203 | |
204 void vlvo_draw_osd(void) | |
205 { | |
3017 | 206 if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n"); |
2869 | 207 /* TODO: hw support */ |
208 } | |
209 | |
210 uint32_t vlvo_query_info(uint32_t format) | |
211 { | |
3017 | 212 if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); |
2869 | 213 return 1; |
214 } |