2645
|
1 #define PES_MAX_SIZE 2048
|
|
2 /*
|
|
3 * vo_dxr3.c - DXR3/H+ video out
|
|
4 *
|
|
5 * Copyright (C) 2001 David Holm <dholm@iname.com>
|
|
6 *
|
|
7 * libav - MPEG-PS multiplexer, part of ffmpeg
|
|
8 * Copyright Gerard Lantau (see http://ffmpeg.sf.net)
|
|
9 *
|
|
10 */
|
|
11
|
|
12 #include "fastmemcpy.h"
|
|
13 #include <stdio.h>
|
|
14 #include <stdlib.h>
|
|
15 #include <string.h>
|
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <time.h>
|
|
19 #include <unistd.h>
|
|
20
|
|
21 #include <libdxr3/api.h>
|
|
22
|
|
23 #include "config.h"
|
|
24 #include "video_out.h"
|
|
25 #include "video_out_internal.h"
|
|
26
|
2732
|
27 #include "../postproc/rgb2rgb.h"
|
2645
|
28 #ifdef HAVE_MMX
|
|
29 #include "mmx.h"
|
|
30 #endif
|
|
31
|
|
32 LIBVO_EXTERN (dxr3)
|
|
33
|
|
34 #ifdef USE_LIBAVCODEC
|
|
35
|
|
36 #ifdef USE_LIBAVCODEC_SO
|
|
37 #include <libffmpeg/avcodec.h>
|
|
38 #else
|
|
39 #include "../libavcodec/avcodec.h"
|
|
40 #endif
|
|
41 static AVPicture picture;
|
|
42 static AVCodec *codec=NULL;
|
|
43 static AVCodecContext codec_context;
|
|
44 extern int avcodec_inited;
|
|
45 #endif
|
|
46
|
|
47 static unsigned char *picture_buf=NULL;
|
|
48 static unsigned char *outbuf=NULL;
|
|
49 static int outbuf_size = 100000;
|
|
50 static int s_pos_x,s_pos_y;
|
|
51 static int d_pos_x,d_pos_y;
|
|
52 static int osd_w,osd_h;
|
|
53 static uint32_t img_format = 0;
|
|
54
|
|
55 static vo_info_t vo_info =
|
|
56 {
|
|
57 "DXR3/H+ video out",
|
|
58 "dxr3",
|
|
59 "David Holm <dholm@iname.com>",
|
|
60 ""
|
|
61 };
|
|
62
|
|
63 static uint32_t
|
|
64 init(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format)
|
|
65 {
|
|
66 if( dxr3_get_status() == DXR3_STATUS_CLOSED )
|
|
67 {
|
|
68 if( dxr3_open( "/dev/em8300", "/etc/dxr3.ux" ) != 0 ) printf( "Error loading /dev/em8300 with /etc/dxr3.ux microcode file\n" );
|
|
69 printf( "DXR3 status: %s\n", dxr3_get_status() ? "opened":"closed" );
|
|
70 }
|
|
71 else
|
|
72 printf( "DXR3 already open\n" );
|
|
73
|
|
74 if( dxr3_set_playmode( DXR3_PLAYMODE_PLAY ) !=0 ) printf( "Error setting playmode of DXR3\n" );
|
|
75
|
|
76 img_format = format;
|
|
77 picture_buf=NULL;
|
|
78 if( format == IMGFMT_YV12 )
|
|
79 {
|
|
80 #ifdef USE_LIBAVCODEC
|
|
81
|
|
82 int size;
|
|
83
|
|
84 printf("Format: YV12\n");
|
|
85
|
|
86 if(!avcodec_inited){
|
|
87 avcodec_init();
|
|
88 avcodec_register_all();
|
|
89 avcodec_inited=1;
|
|
90 }
|
|
91
|
|
92 /* find the mpeg1 video encoder */
|
|
93 codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
|
|
94 if (!codec) {
|
|
95 fprintf(stderr, "mpeg1 codec not found\n");
|
|
96 return -1;
|
|
97 }
|
|
98
|
|
99 memset(&codec_context,0,sizeof(codec_context));
|
|
100 codec_context.bit_rate=100000; // not used
|
|
101 codec_context.frame_rate=25*FRAME_RATE_BASE; // !!!!!
|
|
102 codec_context.gop_size=0; // I frames only
|
|
103 codec_context.flags=CODEC_FLAG_QSCALE;
|
|
104 codec_context.quality=1; // quality! 1..31 (1=best,slowest)
|
|
105 codec_context.pix_fmt = PIX_FMT_RGB24;
|
|
106 if(width<=352 && height<=288){
|
|
107 codec_context.width=352;
|
|
108 codec_context.height=288;
|
|
109 } else
|
|
110 if(width<=352 && height<=576){
|
|
111 codec_context.width=352;
|
|
112 codec_context.height=576;
|
|
113 } else
|
|
114 if(width<=480 && height<=576){
|
|
115 codec_context.width=480;
|
|
116 codec_context.height=576;
|
|
117 } else
|
|
118 if(width<=544 && height<=576){
|
|
119 codec_context.width=544;
|
|
120 codec_context.height=576;
|
|
121 } else {
|
|
122 codec_context.width=704;
|
|
123 codec_context.height=576;
|
|
124 }
|
|
125
|
|
126 osd_w=s_width;
|
|
127 d_pos_x=(codec_context.width-(int)s_width)/2;
|
|
128 if(d_pos_x<0){
|
|
129 s_pos_x=-d_pos_x;d_pos_x=0;
|
|
130 osd_w=codec_context.width;
|
|
131 } else s_pos_x=0;
|
|
132
|
|
133 osd_h=s_height;
|
|
134 d_pos_y=(codec_context.height-(int)s_height)/2;
|
|
135 if(d_pos_y<0){
|
|
136 s_pos_y=-d_pos_y;d_pos_y=0;
|
|
137 osd_h=codec_context.height;
|
|
138 } else s_pos_y=0;
|
|
139
|
|
140 printf("[vo] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
|
|
141
|
|
142 /* open it */
|
|
143 if (avcodec_open(&codec_context, codec) < 0) {
|
|
144 fprintf(stderr, "could not open codec\n");
|
|
145 return -1;
|
|
146 }
|
|
147
|
|
148 outbuf_size=10000+width*height; // must be enough!
|
|
149 outbuf = malloc(outbuf_size);
|
|
150
|
|
151 size = codec_context.width*codec_context.height;
|
|
152 picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
|
|
153
|
|
154 picture.data[0] = picture_buf;
|
|
155 picture.data[1] = picture.data[0] + size;
|
|
156 picture.data[2] = picture.data[1] + size / 4;
|
|
157 picture.linesize[0] = codec_context.width;
|
|
158 picture.linesize[1] = codec_context.width / 2;
|
|
159 picture.linesize[2] = codec_context.width / 2;
|
|
160 return 0;
|
|
161 #endif
|
|
162 return -1;
|
|
163 }
|
|
164 else if(format==IMGFMT_MPEGPES)
|
|
165 {
|
|
166 printf( "Format: MPEG-PES\n" );
|
|
167 return 0;
|
|
168 }
|
|
169
|
|
170 printf( "Format: Unsupported\n" );
|
|
171 return -1;
|
|
172 }
|
|
173
|
|
174 static const vo_info_t*
|
|
175 get_info(void)
|
|
176 {
|
|
177 return &vo_info;
|
|
178 }
|
|
179
|
|
180 #ifdef USE_LIBAVCODEC
|
|
181 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
|
|
182 {
|
|
183 int x,y;
|
|
184 if( img_format == IMGFMT_YV12 )
|
|
185 vo_draw_alpha_yv12(w,h,src,srca,stride,picture.data[0]+(x0+d_pos_x)+(y0+d_pos_y)*picture.linesize[0],picture.linesize[0]);
|
|
186 }
|
|
187 #endif
|
|
188
|
|
189 static void draw_osd(void)
|
|
190 {
|
|
191 if( img_format == IMGFMT_YV12 )
|
|
192 {
|
|
193 #ifdef USE_LIBAVCODEC
|
|
194 vo_draw_text(osd_w,osd_h,draw_alpha);
|
|
195 #endif
|
|
196 }
|
|
197 }
|
|
198
|
|
199 static uint32_t draw_frame(uint8_t * src[])
|
|
200 {
|
|
201 int data_left;
|
|
202 if( img_format == IMGFMT_MPEGPES )
|
|
203 {
|
|
204 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
|
|
205
|
|
206 data_left = p->size;
|
|
207 while( data_left )
|
|
208 data_left -= dxr3_video_write( &((unsigned char*)p->data)[p->size-data_left], data_left );
|
|
209
|
|
210 return 0;
|
|
211 }
|
|
212 #ifdef USE_LIBAVCODEC
|
|
213 else if( img_format == IMGFMT_YV12 )
|
|
214 {
|
|
215 printf("ERROR: Uninplemented\n");
|
|
216 }
|
|
217 #endif
|
|
218
|
|
219 printf( "Error in draw_frame(...)" );
|
|
220 return -1;
|
|
221 }
|
|
222
|
|
223 static void flip_page (void)
|
|
224 {
|
|
225 #ifdef USE_LIBAVCODEC
|
|
226 if( img_format == IMGFMT_YV12 )
|
|
227 {
|
|
228 int out_size, tmp_size;
|
|
229 /* encode the image */
|
|
230 tmp_size = out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
|
|
231 while( out_size )
|
|
232 out_size -= dxr3_video_write( &outbuf[tmp_size-out_size], out_size );
|
|
233 }
|
|
234 #endif
|
|
235 }
|
|
236
|
|
237 static uint32_t draw_slice( uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0 )
|
|
238 {
|
|
239 int y;
|
|
240 unsigned char* s;
|
|
241 unsigned char* d;
|
|
242 int data_left;
|
|
243 vo_mpegpes_t *p = (vo_mpegpes_t *)srcimg[0];
|
|
244
|
|
245 if( img_format == IMGFMT_YV12 )
|
|
246 {
|
|
247 #ifdef USE_LIBAVCODEC
|
|
248 x0+=d_pos_x;
|
|
249 y0+=d_pos_y;
|
|
250 if(x0+w>picture.linesize[0]) w=picture.linesize[0]-x0; // !!
|
|
251 if(y0+h>codec_context.height) h=codec_context.height-y0;
|
|
252
|
|
253 // Y
|
|
254 s=srcimg[0]+s_pos_x+s_pos_y*stride[0];
|
|
255 d=picture.data[0]+x0+y0*picture.linesize[0];
|
|
256 for( y = 0; y < h; y++)
|
|
257 {
|
|
258 memcpy(d,s,w);
|
|
259 s+=stride[0];
|
|
260 d+=picture.linesize[0];
|
|
261 }
|
|
262
|
|
263 w/=2;h/=2;x0/=2;y0/=2;
|
|
264
|
|
265 // U
|
|
266 s=srcimg[1]+(s_pos_x/2)+(s_pos_y/2)*stride[1];
|
|
267 d=picture.data[1]+x0+y0*picture.linesize[1];
|
|
268 for( y = 0; y < h; y++)
|
|
269 {
|
|
270 memcpy(d,s,w);
|
|
271 s+=stride[1];
|
|
272 d+=picture.linesize[1];
|
|
273 }
|
|
274
|
|
275 // V
|
|
276 s=srcimg[2]+(s_pos_x/2)+(s_pos_y/2)*stride[2];
|
|
277 d=picture.data[2]+x0+y0*picture.linesize[2];
|
|
278 for(y=0;y<h;y++)
|
|
279 {
|
|
280 memcpy(d,s,w);
|
|
281 s+=stride[2];
|
|
282 d+=picture.linesize[2];
|
|
283 }
|
|
284
|
|
285 yuv2rgb_init( 24, MODE_RGB );
|
|
286 yuv2rgb( outbuf, srcimg[0], srcimg[1], srcimg[2], w, h, h*3, stride[0], stride[1] );
|
|
287 return 0;
|
|
288 #endif
|
|
289 printf( "You will need libavcodec of ffmpeg.so yo play this video\n" );
|
|
290 return -1;
|
|
291 }
|
|
292 else if( img_format == IMGFMT_MPEGPES )
|
|
293 {
|
|
294 data_left = p->size;
|
|
295 while( data_left )
|
|
296 data_left -= dxr3_video_write( &((unsigned char*)p->data)[p->size-data_left], data_left );
|
|
297 return 0;
|
|
298 }
|
|
299
|
|
300 return -1;
|
|
301 }
|
|
302
|
|
303
|
|
304 static uint32_t
|
|
305 query_format(uint32_t format)
|
|
306 {
|
|
307 if(format==IMGFMT_MPEGPES) return 1;
|
|
308 #ifdef USE_LIBAVCODEC
|
|
309 if(format==IMGFMT_YV12) return 1;
|
|
310 #endif
|
|
311 return 0;
|
|
312 }
|
|
313
|
|
314 static void
|
|
315 uninit(void)
|
|
316 {
|
|
317 #ifdef USE_LIBAVCODEC
|
|
318 if( img_format == IMGFMT_YV12 )
|
|
319 {
|
|
320 free(outbuf);
|
|
321 free(picture_buf);
|
|
322 }
|
|
323 #endif
|
|
324 dxr3_close( );
|
|
325 }
|
|
326
|
|
327
|
|
328 static void check_events(void)
|
|
329 {
|
|
330 }
|
|
331
|