Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 3202:e9b18714e3dc
Minor optimization
author | nick |
---|---|
date | Thu, 29 Nov 2001 18:00:57 +0000 |
parents | c9f140f5a34e |
children | 1d2b2885bb8c |
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 | |
3202 | 27 #include "video_out.h" |
28 | |
3165 | 29 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */ |
2869 | 30 #define NUM_FRAMES 2 |
31 static uint8_t *frames[NUM_FRAMES]; | |
32 | |
33 static int lvo_handler = -1; | |
34 static uint8_t *lvo_mem = NULL; | |
35 static uint8_t next_frame; | |
36 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
|
37 static unsigned image_bpp,image_height,image_width,src_format; |
2952 | 38 extern int verbose; |
2869 | 39 |
40 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8) | |
41 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) ) | |
42 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size)) | |
43 | |
3202 | 44 extern vo_functions_t video_out_vesa; |
45 | |
2971 | 46 int vlvo_preinit(const char *drvname) |
47 { | |
3017 | 48 if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname); |
2971 | 49 lvo_handler = open(drvname,O_RDWR); |
50 if(lvo_handler == -1) | |
51 { | |
52 printf("vesa_lvo: Couldn't open '%s'\n",drvname); | |
53 return -1; | |
54 } | |
3202 | 55 /* we are able to tune up this stuff depend on fourcc format */ |
56 video_out_vesa.draw_slice=vlvo_draw_slice; | |
57 video_out_vesa.draw_frame=vlvo_draw_frame; | |
58 video_out_vesa.flip_page=vlvo_flip_page; | |
59 video_out_vesa.draw_osd=vlvo_draw_osd; | |
2971 | 60 return 0; |
61 } | |
62 | |
63 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 64 unsigned x_org,unsigned y_org,unsigned dst_width, |
65 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
66 { | |
67 size_t i,awidth; | |
3017 | 68 if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n"); |
2869 | 69 image_width = src_width; |
70 image_height = src_height; | |
71 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
|
72 src_format = mga_vid_config.format=format; |
2869 | 73 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
74 switch(format){ | |
75 case IMGFMT_YV12: | |
76 case IMGFMT_I420: | |
77 case IMGFMT_IYUV: | |
78 image_bpp=16; | |
79 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2; | |
80 break; | |
81 case IMGFMT_YUY2: | |
82 case IMGFMT_UYVY: | |
83 image_bpp=16; | |
84 mga_vid_config.frame_size = awidth*src_height*2; | |
85 break; | |
86 case IMGFMT_RGB15: | |
87 case IMGFMT_BGR15: | |
88 case IMGFMT_RGB16: | |
89 case IMGFMT_BGR16: | |
90 image_bpp=16; | |
91 mga_vid_config.frame_size = awidth*src_height*2; | |
92 break; | |
93 case IMGFMT_RGB24: | |
94 case IMGFMT_BGR24: | |
95 image_bpp=24; | |
96 mga_vid_config.frame_size = awidth*src_height*3; | |
97 break; | |
98 case IMGFMT_RGB32: | |
99 case IMGFMT_BGR32: | |
100 image_bpp=32; | |
101 mga_vid_config.frame_size = awidth*src_height*4; | |
102 break; | |
103 default: | |
104 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format); | |
105 return -1; | |
106 } | |
107 mga_vid_config.colkey_on=0; | |
108 mga_vid_config.src_width = src_width; | |
109 mga_vid_config.src_height= src_height; | |
110 mga_vid_config.dest_width = dst_width; | |
111 mga_vid_config.dest_height= dst_height; | |
112 mga_vid_config.x_org=x_org; | |
113 mga_vid_config.y_org=y_org; | |
114 mga_vid_config.num_frames=NUM_FRAMES; | |
115 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
116 { | |
2971 | 117 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
118 printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n"); | |
2869 | 119 return -1; |
120 } | |
121 ioctl(lvo_handler,MGA_VID_ON,0); | |
122 | |
123 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
124 for(i=1;i<NUM_FRAMES;i++) | |
125 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
126 next_frame = 0; | |
127 lvo_mem = frames[next_frame]; | |
128 | |
129 /*clear the buffer*/ | |
130 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
131 return 0; | |
132 } | |
133 | |
134 void vlvo_term( void ) | |
135 { | |
3017 | 136 if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n"); |
2869 | 137 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
138 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
139 if(lvo_handler != -1) close(lvo_handler); | |
140 } | |
141 | |
3165 | 142 uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) |
2869 | 143 { |
144 uint8_t *src; | |
145 uint8_t *dest; | |
3020 | 146 uint32_t bespitch,bespitch2; |
2869 | 147 int i; |
148 | |
149 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
150 bespitch2 = bespitch/2; | |
151 | |
152 dest = lvo_mem + bespitch * y + x; | |
153 src = image[0]; | |
154 for(i=0;i<h;i++){ | |
155 memcpy(dest,src,w); | |
156 src+=stride[0]; | |
157 dest += bespitch; | |
158 } | |
159 | |
160 w/=2;h/=2;x/=2;y/=2; | |
161 | |
162 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
163 src = image[1]; | |
164 for(i=0;i<h;i++){ | |
165 memcpy(dest,src,w); | |
166 src+=stride[1]; | |
167 dest += bespitch2; | |
168 } | |
169 | |
170 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
171 + bespitch*mga_vid_config.src_height / 4 | |
172 + bespitch2 * y + x; | |
173 src = image[2]; | |
174 for(i=0;i<h;i++){ | |
175 memcpy(dest,src,w); | |
176 src+=stride[2]; | |
177 dest += bespitch2; | |
178 } | |
3020 | 179 return 0; |
180 } | |
181 | |
182 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
183 { | |
184 if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n"); | |
3165 | 185 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) |
3202 | 186 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
|
187 else |
3202 | 188 { |
189 uint8_t *dst; | |
190 uint8_t bytpp; | |
191 bytpp = (image_bpp+7)/8; | |
192 dst = lvo_mem + (image_width * y + x)*bytpp; | |
193 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */ | |
194 memcpy(dst,image[0],mga_vid_config.frame_size); | |
195 } | |
2924 | 196 return 0; |
2869 | 197 } |
198 | |
3017 | 199 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 200 { |
3017 | 201 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
202 memcpy(lvo_mem,image[0],mga_vid_config.frame_size); | |
203 if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n"); | |
204 return 0; | |
2869 | 205 } |
206 | |
207 void vlvo_flip_page(void) | |
208 { | |
3017 | 209 if(verbose > 1) printf("vesa_lvo: vlvo_flip_page() was called\n"); |
2869 | 210 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
211 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
212 lvo_mem=frames[next_frame]; | |
213 } | |
214 | |
215 void vlvo_draw_osd(void) | |
216 { | |
3017 | 217 if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n"); |
2869 | 218 /* TODO: hw support */ |
219 } | |
220 | |
221 uint32_t vlvo_query_info(uint32_t format) | |
222 { | |
3017 | 223 if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); |
2869 | 224 return 1; |
225 } |