comparison libvo/vesa_lvo.c @ 2869:107d9e9e5bd1

New video output technique Linux Video Overlay: -vo vesa:lvo:drv_name (for example -vo vesa:lvo:/dev/radeon_vid or -vo vesa:lvo:/dev/mga_vid) Note: You don't need to have graphics screen before loading xxx_vid driver vo_vesa will switch to graphics mode before using of xxx_vid driver. So you can traditional start it from text-mode.
author nick
date Tue, 13 Nov 2001 17:13:33 +0000
parents
children 8350b8c25c02
comparison
equal deleted inserted replaced
2868:4a1802c5bbee 2869:107d9e9e5bd1
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 #include "../mmx_defs.h"
27
28 #define WIDTH_ALIGN 32 /* should be 16 for radeons */
29 #define NUM_FRAMES 2
30 static uint8_t *frames[NUM_FRAMES];
31
32 static int lvo_handler = -1;
33 static uint8_t *lvo_mem = NULL;
34 static uint8_t next_frame;
35 static mga_vid_config_t mga_vid_config;
36 static unsigned image_bpp,image_height,image_width;
37
38
39 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
40 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
41 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
42
43 int vlvo_init(const char *drvname,unsigned src_width,unsigned src_height,
44 unsigned x_org,unsigned y_org,unsigned dst_width,
45 unsigned dst_height,unsigned format,unsigned dest_bpp)
46 {
47 size_t i,awidth;
48 lvo_handler = open(drvname,O_RDWR);
49 if(lvo_handler == -1)
50 {
51 printf("Couldn't open %s\n",drvname);
52 return -1;
53 }
54 image_width = src_width;
55 image_height = src_height;
56 mga_vid_config.version=MGA_VID_VERSION;
57 mga_vid_config.format=format;
58 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
59 switch(format){
60 case IMGFMT_YV12:
61 case IMGFMT_I420:
62 case IMGFMT_IYUV:
63 image_bpp=16;
64 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
65 break;
66 case IMGFMT_YUY2:
67 case IMGFMT_UYVY:
68 image_bpp=16;
69 mga_vid_config.frame_size = awidth*src_height*2;
70 break;
71 case IMGFMT_RGB15:
72 case IMGFMT_BGR15:
73 case IMGFMT_RGB16:
74 case IMGFMT_BGR16:
75 image_bpp=16;
76 mga_vid_config.frame_size = awidth*src_height*2;
77 break;
78 case IMGFMT_RGB24:
79 case IMGFMT_BGR24:
80 image_bpp=24;
81 mga_vid_config.frame_size = awidth*src_height*3;
82 break;
83 case IMGFMT_RGB32:
84 case IMGFMT_BGR32:
85 image_bpp=32;
86 mga_vid_config.frame_size = awidth*src_height*4;
87 break;
88 default:
89 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format);
90 return -1;
91 }
92 mga_vid_config.colkey_on=0;
93 mga_vid_config.src_width = src_width;
94 mga_vid_config.src_height= src_height;
95 mga_vid_config.dest_width = dst_width;
96 mga_vid_config.dest_height= dst_height;
97 mga_vid_config.x_org=x_org;
98 mga_vid_config.y_org=y_org;
99 mga_vid_config.num_frames=NUM_FRAMES;
100 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
101 {
102 perror("Error in mga_vid_config ioctl()");
103 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n");
104 return -1;
105 }
106 ioctl(lvo_handler,MGA_VID_ON,0);
107
108 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
109 for(i=1;i<NUM_FRAMES;i++)
110 frames[i] = frames[i-1] + mga_vid_config.frame_size;
111 next_frame = 0;
112 lvo_mem = frames[next_frame];
113
114 /*clear the buffer*/
115 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
116 return 0;
117 }
118
119 void vlvo_term( void )
120 {
121 ioctl( lvo_handler,MGA_VID_OFF,0 );
122 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
123 if(lvo_handler != -1) close(lvo_handler);
124 }
125
126 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
127 {
128 uint8_t *src;
129 uint8_t *dest;
130 uint32_t bespitch,bespitch2;
131 int i;
132
133 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
134 bespitch2 = bespitch/2;
135
136 dest = lvo_mem + bespitch * y + x;
137 src = image[0];
138 for(i=0;i<h;i++){
139 memcpy(dest,src,w);
140 src+=stride[0];
141 dest += bespitch;
142 }
143
144 w/=2;h/=2;x/=2;y/=2;
145
146 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
147 src = image[1];
148 for(i=0;i<h;i++){
149 memcpy(dest,src,w);
150 src+=stride[1];
151 dest += bespitch2;
152 }
153
154 dest = lvo_mem + bespitch*mga_vid_config.src_height
155 + bespitch*mga_vid_config.src_height / 4
156 + bespitch2 * y + x;
157 src = image[2];
158 for(i=0;i<h;i++){
159 memcpy(dest,src,w);
160 src+=stride[2];
161 dest += bespitch2;
162 }
163
164 }
165
166 uint32_t vlvo_draw_frame(uint8_t *src[])
167 {
168 size_t i, ssize;
169 uint8_t *dest;
170 const uint8_t *sptr;
171 ssize = IMAGE_LINE_SIZE((image_bpp+7)/8);
172 dest = lvo_mem;
173 sptr = src[0];
174 for(i=0;i<image_height;i++)
175 {
176 memcpy(dest,sptr,ssize);
177 sptr += ssize;
178 dest += ssize;
179 }
180 }
181
182 void vlvo_flip_page(void)
183 {
184 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
185 next_frame=(next_frame+1)%mga_vid_config.num_frames;
186 lvo_mem=frames[next_frame];
187 }
188
189 void vlvo_draw_osd(void)
190 {
191 /* TODO: hw support */
192 }
193
194 uint32_t vlvo_query_info(uint32_t format)
195 {
196 return 1;
197 }