DOCS/man/hu/mplayer.1 synced with r18969
[mplayer/glamo.git] / libvo / vo_zr.c
blobf64bf419d23c3571ae0a62426ae6f70af5b63214
1 /*
2 * vo_zr.c - playback on zoran cards
3 * Copyright (C) Rik Snel 2001,2002, License GNU GPL v2
4 */
6 /* $Id$ */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <errno.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #include <sys/time.h>
17 #include <sys/mman.h>
18 #include <sys/ioctl.h>
19 #include <linux/types.h>
20 #include <linux/videodev.h>
21 #include "videodev_mjpeg.h"
23 #include "config.h"
25 #include "video_out.h"
26 #include "video_out_internal.h"
27 #include "mp_msg.h"
28 #include "m_option.h"
29 #include "fastmemcpy.h"
31 #include "jpeg_enc.h"
33 static vo_info_t info =
35 "Zoran ZR360[56]7/ZR36060 Driver (DC10(+)/buz/lml33/MatroxRR)",
36 "zr",
37 "Rik Snel <rsnel@cube.dyndns.org>",
41 LIBVO_EXTERN (zr)
43 #define ZR_MAX_DEVICES 4
44 /* General variables */
46 typedef struct {
47 int width;
48 int height;
49 int xoff;
50 int yoff;
51 int set;
52 } geo_t;
54 static int zr_count = 1;
55 static int zr_parsing = 0;
56 static int framenum;
58 typedef struct {
59 /* commandline args given for this device (and defaults) */
60 int vdec, hdec; /* requested decimation 1,2,4 */
61 int fd; /* force decimation */
62 int xdoff, ydoff; /* offset from upperleft of screen
63 * default is 'centered' */
64 int quality; /* jpeg quality 1=best, 20=bad */
65 geo_t g; /* view window (zrcrop) */
66 char *device; /* /dev/video1 */
67 int bw; /* if bw == 1, display in black&white */
68 int norm; /* PAL/NTSC */
70 /* buffers + pointers + info */
72 unsigned char *image;
73 int image_width, image_height, size;
74 int off_y, off_c, stride; /* for use by 'draw slice/frame' */
76 unsigned char *buf; /* the jpeg images will be placed here */
77 jpeg_enc_t *j;
78 unsigned char *y_data, *u_data, *v_data; /* used by the jpeg encoder */
79 int y_stride, u_stride, v_stride; /* these point somewhere in image */
81 /* information for (and about) the zoran card */
83 int vdes; /* file descriptor of card */
84 int frame, synco, queue; /* buffer management */
85 struct mjpeg_sync zs; /* state information */
86 struct mjpeg_params p;
87 struct mjpeg_requestbuffers zrq;
88 struct video_capability vc; /* max resolution and so on */
89 int fields, stretchy; /* must the *image be interlaced
90 or stretched to fit on the screen? */
91 } zr_info_t;
93 static zr_info_t zr_info[ZR_MAX_DEVICES] = {
94 {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0,
95 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
96 {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0,
97 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
98 {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0,
99 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0,
101 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
106 #define MJPEG_NBUFFERS 2
107 #define MJPEG_SIZE 1024*256
110 int zoran_getcap(zr_info_t *zr) {
111 char* dev = NULL;
113 if (zr->device)
114 dev = zr->device;
115 else {
116 struct stat vstat;
117 const char *devs[] = {
118 "/dev/video",
119 "/dev/video0",
120 "/dev/v4l/video0",
121 "/dev/v4l0",
122 "/dev/v4l",
123 NULL
125 int i = 0;
129 if ((stat(devs[i], &vstat) == 0) && S_ISCHR(vstat.st_mode))
131 dev = devs[i];
132 mp_msg(MSGT_VO, MSGL_V, "zr: found video device %s\n", dev);
133 break;
135 } while (devs[++i] != NULL);
137 if (!dev)
139 mp_msg(MSGT_VO, MSGL_ERR, "zr: unable to find video device\n");
140 return 1;
144 zr->vdes = open(dev, O_RDWR);
146 if (zr->vdes < 0) {
147 mp_msg(MSGT_VO, MSGL_ERR, "zr: error opening %s: %s\n",
148 dev, strerror(errno));
149 return 1;
152 /* before we can ask for the maximum resolution, we must set
153 * the correct tv norm */
155 if (ioctl(zr->vdes, MJPIOC_G_PARAMS, &zr->p) < 0) {
156 mp_msg(MSGT_VO, MSGL_ERR, "zr: device at %s is probably not a DC10(+)/buz/lml33\n", dev);
157 return 1;
160 if (zr->p.norm != zr->norm && zr->norm != VIDEO_MODE_AUTO) {
161 /* attempt to set requested norm */
162 zr->p.norm = zr->norm;
163 if (ioctl(zr->vdes, MJPIOC_S_PARAMS, &zr->p) < 0) {
164 mp_msg(MSGT_VO, MSGL_ERR,
165 "zr: unable to change video norm, use another program to change it (XawTV)\n");
166 return 1;
168 ioctl(zr->vdes, MJPIOC_G_PARAMS, &zr->p);
169 if (zr->norm != zr->p.norm) {
170 mp_msg(MSGT_VO, MSGL_ERR,
171 "zr: unable to change video norm, use another program to change it (XawTV)\n");
172 return 1;
176 if (ioctl(zr->vdes, VIDIOCGCAP, &zr->vc) < 0) {
177 mp_msg(MSGT_VO, MSGL_ERR, "zr: error getting video capabilities from %s\n", dev);
178 return 1;
180 mp_msg(MSGT_VO, MSGL_V, "zr: MJPEG card reports maxwidth=%d, maxheight=%d\n", zr->vc.maxwidth, zr->vc.maxheight);
182 return 0;
185 int init_zoran(zr_info_t *zr, int stretchx, int stretchy) {
186 /* center the image, and stretch it as far as possible (try to keep
187 * aspect) and check if it fits */
188 if (zr->image_width > zr->vc.maxwidth) {
189 mp_msg(MSGT_VO, MSGL_ERR, "zr: movie to be played is too wide, max width currenty %d\n", zr->vc.maxwidth);
190 return 1;
193 if (zr->image_height > zr->vc.maxheight) {
194 mp_msg(MSGT_VO, MSGL_ERR, "zr: movie to be played is too high, max height currenty %d\n", zr->vc.maxheight);
195 return 1;
198 zr->p.decimation = 0;
199 zr->p.HorDcm = stretchx;
200 zr->p.VerDcm = stretchy;
201 zr->p.TmpDcm = 1;
202 zr->p.field_per_buff = zr->fields;
203 if (zr->xdoff == -1) {
204 zr->p.img_x = (zr->vc.maxwidth -
205 zr->p.HorDcm*(int)zr->image_width/zr->hdec)/2;
206 } else {
207 zr->p.img_x = zr->xdoff;
209 if (zr->ydoff == -1) {
210 zr->p.img_y = (zr->vc.maxheight - zr->p.VerDcm*
211 (3-zr->fields)*(int)zr->image_height)/4;
212 } else {
213 zr->p.img_y = zr->ydoff;
215 zr->p.img_width = zr->p.HorDcm*zr->image_width/zr->hdec;
216 zr->p.img_height = zr->p.VerDcm*zr->image_height/zr->fields;
217 mp_msg(MSGT_VO, MSGL_V, "zr: geometry (after 'scaling'): %dx%d+%d+%d fields=%d, w=%d, h=%d\n", zr->p.img_width, (3-zr->fields)*zr->p.img_height, zr->p.img_x, zr->p.img_y, zr->fields, zr->image_width/zr->hdec, zr->image_height);
219 if (ioctl(zr->vdes, MJPIOC_S_PARAMS, &zr->p) < 0) {
220 mp_msg(MSGT_VO, MSGL_ERR, "zr: error setting display parameters\n");
221 return 1;
224 zr->zrq.count = MJPEG_NBUFFERS;
225 zr->zrq.size = MJPEG_SIZE;
227 if (ioctl(zr->vdes, MJPIOC_REQBUFS, &zr->zrq)) {
228 mp_msg(MSGT_VO, MSGL_ERR, "zr: error requesting %d buffers of size %d\n", zr->zrq.count, zr->zrq.size);
229 return 1;
232 /* the buffer count allocated may be different to the request */
233 zr->buf = (unsigned char*)mmap(0, zr->zrq.count*zr->zrq.size,
234 PROT_READ|PROT_WRITE, MAP_SHARED, zr->vdes, 0);
236 if (zr->buf == MAP_FAILED) {
237 mp_msg(MSGT_VO, MSGL_ERR, "zr: error requesting %d buffers of size %d\n", zr->zrq.count, zr->zrq.size);
238 return 1;
241 mp_msg(MSGT_VO, MSGL_V, "zr: got %d buffers of size %d (wanted %d buffers of size %d)\n", zr->zrq.count, zr->zrq.size, MJPEG_NBUFFERS, MJPEG_SIZE);
242 if (zr->zrq.count < MJPEG_NBUFFERS) {
243 mp_msg(MSGT_VO, MSGL_V, "zr: got not enough buffers\n");
244 return 1;
247 zr->queue = 0;
248 zr->synco = 0;
250 return 0;
253 void uninit_zoran(zr_info_t *zr) {
254 if (zr->image) {
255 free(zr->image);
256 zr->image=NULL;
258 while (zr->queue > zr->synco + 1) {
259 if (ioctl(zr->vdes, MJPIOC_SYNC, &zr->zs) < 0)
260 mp_msg(MSGT_VO, MSGL_ERR, "zr: error waiting for buffers to become free\n");
261 zr->synco++;
263 /* stop streaming */
264 zr->frame = -1;
265 if (ioctl(zr->vdes, MJPIOC_QBUF_PLAY, &zr->frame) < 0)
266 mp_msg(MSGT_VO, MSGL_ERR, "zr: error stopping playback of last frame\n");
267 if (munmap(zr->buf,zr->zrq.count*zr->zrq.size))
268 mp_msg(MSGT_VO, MSGL_ERR, "zr: error unmapping buffer\n");
269 close(zr->vdes);
272 int zr_geometry_sane(geo_t *g, unsigned int width, unsigned int height) {
273 if (g->set) {
274 if (g->width%2 != 0 || g->height%2 != 0 ||
275 g->xoff%2 != 0 || g->yoff%2 != 0) {
276 mp_msg(MSGT_VO, MSGL_ERR, "zr: arguments in -zrcrop must be multiples of 2\n");
277 return 1;
279 if (g->width <= 0 || g->height <= 0 ||
280 g->xoff < 0 || g->yoff < 0) {
281 mp_msg(MSGT_VO, MSGL_ERR, "zr: width and height must be positive and offset nonnegative\n");
282 return 1;
284 if (g->width + g->xoff > width) {
285 mp_msg(MSGT_VO, MSGL_ERR, "zr: width+xoffset (%d+%d>%d) is too big\n", g->width, g->xoff, width);
286 return 1;
288 if (g->height + g->yoff > height) {
289 mp_msg(MSGT_VO, MSGL_ERR, "zr: height+yoffset (%d+%d>%d) is too big\n", g->height, g->yoff, height);
290 return 1;
292 } else {
293 g->width = width;
294 g->height = height;
295 g->xoff = 0;
296 g->yoff = 0;
297 g->set = 1;
299 return 0;
303 static int config(uint32_t width, uint32_t height, uint32_t d_width,
304 uint32_t d_height, uint32_t flags, char *title, uint32_t format)
306 int i, tmp, stretchx, stretchy;
307 framenum = 0;
308 if (format != IMGFMT_YV12 && format != IMGFMT_YUY2) {
309 printf("vo_zr called with wrong format");
310 return 1;
312 for (i = 0; i < zr_count; i++) {
313 zr_info_t *zr = &zr_info[i];
314 geo_t *g = &zr->g;
316 zr->stride = 2*width;
317 if (zr_geometry_sane(g, width, height)) return 1;
319 /* we must know the maximum resolution of the device
320 * it differs for DC10+ and buz for example */
321 zoran_getcap(zr); /*must be called before init_zoran */
322 /* make the scaling decision
323 * we are capable of stretching the image in the horizontal
324 * direction by factors 1, 2 and 4
325 * we can stretch the image in the vertical direction by a
326 * factor of 1 and 2 AND we must decide about interlacing */
327 if (g->width > zr->vc.maxwidth/2 ||
328 g->height > zr->vc.maxheight/2) {
329 stretchx = 1;
330 stretchy = 1;
331 zr->fields = 2;
332 if (zr->vdec == 2) {
333 zr->fields = 1;
334 } else if (zr->vdec == 4) {
335 zr->fields = 1;
336 stretchy = 2;
338 stretchx = zr->hdec;
339 } else if (g->width > zr->vc.maxwidth/4 ||
340 g->height > zr->vc.maxheight/4) {
341 stretchx = 2;
342 stretchy = 1;
343 zr->fields = 1;
344 if (zr->vdec == 2) {
345 stretchy = 2;
346 } else if (zr->vdec == 4) {
347 if (!zr->fd) {
348 mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 2 (use -zrfd to keep vdec=4)\n");
349 zr->vdec = 2;
351 stretchy = 2;
353 if (zr->hdec == 2) {
354 stretchx = 4;
355 } else if (zr->hdec == 4){
356 if (!zr->fd) {
357 mp_msg(MSGT_VO, MSGL_WARN, "zr: horizontal decimation too high, changing to 2 (use -zrfd to keep hdec=4)\n");
358 zr->hdec = 2;
360 stretchx = 4;
362 } else {
363 /* output image is maximally stretched */
364 stretchx = 4;
365 stretchy = 2;
366 zr->fields = 1;
367 if (zr->vdec != 1 && !zr->fd) {
368 mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 1 (use -zrfd to keep vdec=%d)\n", zr->vdec);
369 zr->vdec = 1;
371 if (zr->hdec != 1 && !zr->fd) {
372 mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 1 (use -zrfd to keep hdec=%d)\n", zr->hdec);
373 zr->hdec = 1;
376 /* It can be that the original frame was too big for display,
377 * or that the width of the decimated image (for example) after
378 * padding up to a multiple of 16 has become too big. (orig
379 * width 720 (exactly right for the Buz) after decimation 360,
380 * after padding up to a multiple of 16 368, display 736 -> too
381 * large). In these situations we auto(re)crop. */
382 tmp = 16*((g->width - 1)/(zr->hdec*16) + 1);
383 if (stretchx*tmp > zr->vc.maxwidth) {
384 g->xoff += 2*((g->width - zr->hdec*(tmp-16))/4);
385 /* g->off must be a multiple of 2 */
386 g->width = zr->hdec*(tmp - 16);
387 g->set = 0; /* we abuse this field to
388 report that g has changed*/
390 tmp = 8*zr->fields*((g->height - 1)/(zr->vdec*zr->fields*8)+1);
391 if (stretchy*tmp > zr->vc.maxheight) {
392 g->yoff += 2*((g->height - zr->vdec*
393 (tmp - 8*zr->fields))/4);
394 g->height = zr->vdec*(tmp - 8*zr->fields);
395 g->set = 0;
397 if (!g->set)
398 mp_msg(MSGT_VO, MSGL_V, "zr: auto(re)cropping %dx%d+%d+%d to make the image fit on the screen\n", g->width, g->height, g->xoff, g->yoff);
400 /* the height must be a multiple of fields*8 and the width
401 * must be a multiple of 16 */
402 /* add some black borders to make it so, and center the image*/
403 zr->image_height = zr->fields*8*((g->height/zr->vdec - 1)/
404 (zr->fields*8) + 1);
405 zr->image_width = (zr->hdec*16)*((g->width - 1)/(zr->hdec*16) + 1);
406 zr->off_y = (zr->image_height - g->height/zr->vdec)/2;
407 if (zr->off_y%2 != 0) zr->off_y++;
408 zr->off_y *= zr->image_width;
409 zr->off_c = zr->off_y/4;
410 zr->off_y += (zr->image_width - g->width)/2;
411 if (zr->off_y%2 != 0) zr->off_y--;
412 zr->off_c += (zr->image_width - g->width)/4;
413 zr->size = zr->image_width*zr->image_height;
414 mp_msg(MSGT_VO, MSGL_V, "zr: input: %dx%d, cropped: %dx%d, output: %dx%d, off_y=%d, off_c=%d\n", width, height, g->width, g->height, zr->image_width, zr->image_height, zr->off_y, zr->off_c);
416 zr->image = malloc(2*zr->size); /* this buffer allows for YUV422 data,
417 * so it is a bit too big for YUV420 */
418 if (!zr->image) {
419 mp_msg(MSGT_VO, MSGL_ERR, "zr: Memory exhausted\n");
420 return 1;
422 /* and make sure that the borders are _really_ black */
423 switch (format) {
424 case IMGFMT_YV12:
425 memset(zr->image, 0, zr->size);
426 memset(zr->image + zr->size, 0x80, zr->size/4);
427 memset(zr->image + 3*zr->size/2, 0x80, zr->size/4);
428 zr->y_data = zr->image;
429 zr->u_data = zr->image + zr->size;
430 zr->v_data = zr->image + 3*zr->size/2;
432 zr->y_stride = zr->image_width;
433 zr->u_stride = zr->image_width/2;
434 zr->v_stride = zr->image_width/2;
436 zr->j = jpeg_enc_init(zr->image_width/zr->hdec,
437 zr->image_height/zr->fields,
438 zr->hdec, zr->y_stride*zr->fields,
439 zr->hdec, zr->u_stride*zr->fields,
440 zr->hdec, zr->v_stride*zr->fields,
441 1, zr->quality, zr->bw);
442 break;
443 case IMGFMT_YUY2:
444 for (tmp = 0; tmp < 2*zr->size; tmp+=4) {
445 zr->image[tmp] = 0;
446 zr->image[tmp+1] = 0x80;
447 zr->image[tmp+2] = 0;
448 zr->image[tmp+3] = 0x80;
451 zr->y_data = zr->image;
452 zr->u_data = zr->image + 1;
453 zr->v_data = zr->image + 3;
455 zr->y_stride = 2*zr->image_width;
456 zr->u_stride = 2*zr->image_width;
457 zr->v_stride = 2*zr->image_width;
459 zr->j = jpeg_enc_init(zr->image_width/zr->hdec,
460 zr->image_height/zr->fields,
461 zr->hdec*2,
462 zr->y_stride*zr->fields,
463 zr->hdec*4,
464 zr->u_stride*zr->fields,
465 zr->hdec*4,
466 zr->v_stride*zr->fields,
467 0, zr->quality, zr->bw);
468 break;
469 default:
470 mp_msg(MSGT_VO, MSGL_FATAL, "zr: internal inconsistency in vo_zr\n");
474 if (zr->j == NULL) {
475 mp_msg(MSGT_VO, MSGL_ERR, "zr: error initializing the jpeg encoder\n");
476 return 1;
479 if (init_zoran(zr, stretchx, stretchy)) {
480 return 1;
484 return 0;
487 static void draw_osd(void) {
490 static void flip_page (void) {
491 int i, j, k;
492 //FILE *fp;
493 //char filename[100];
494 /* do we have a free buffer? */
495 for (j = 0; j < zr_count; j++) {
496 zr_info_t *zr = &zr_info[j];
497 /* using MJPEG_NBUFFERS here, using the real number of
498 * buffers may give sync issues (real number of buffers
499 * is always sufficient) */
500 if (zr->queue-zr->synco < MJPEG_NBUFFERS) {
501 zr->frame = zr->queue;
502 } else {
503 if (ioctl(zr->vdes, MJPIOC_SYNC, &zr->zs) < 0)
504 mp_msg(MSGT_VO, MSGL_ERR, "zr: error waiting for buffers to become free\n");
505 zr->frame = zr->zs.frame;
506 zr->synco++;
508 k=0;
509 for (i = 0; i < zr->fields; i++)
510 k+=jpeg_enc_frame(zr->j, zr->y_data + i*zr->y_stride,
511 zr->u_data + i*zr->u_stride,
512 zr->v_data + i*zr->v_stride,
513 zr->buf + zr->frame*zr->zrq.size+k);
514 if (k > zr->zrq.size) mp_msg(MSGT_VO, MSGL_WARN, "zr: jpeg image too large for maximum buffer size. Lower the jpeg encoding\nquality or the resolution of the movie.\n");
516 /* Warning: Only the first jpeg image contains huffman- and
517 * quantisation tables, so don't expect files other than
518 * test0001.jpg to be readable */
519 /*sprintf(filename, "test%04d.jpg", framenum);
520 fp = fopen(filename, "w");
521 if (!fp) exit(1);
522 fwrite(buf+frame*zrq.size, 1, k, fp);
523 fclose(fp);*/
524 /*fp = fopen("test1.jpg", "r");
525 fread(buf+frame*zrq.size, 1, 2126, fp);
526 fclose(fp);*/
528 for (j = 0; j < zr_count; j++) {
529 zr_info_t *zr = &zr_info[j];
530 if (ioctl(zr->vdes, MJPIOC_QBUF_PLAY, &zr->frame) < 0)
531 mp_msg(MSGT_VO, MSGL_ERR, "zr: error queueing buffer for playback\n");
532 zr->queue++;
535 framenum++;
536 return;
539 static int draw_frame(uint8_t * src[]) {
540 int i, j;
541 char *source, *dest;
542 //printf("draw frame called\n");
543 for (j = 0; j < zr_count; j++) {
544 zr_info_t *zr = &zr_info[j];
545 geo_t *g = &zr->g;
546 source = src[0] + 2*g->yoff*zr->vdec*zr->stride + 2*g->xoff;
547 dest = zr->image + 2*zr->off_y;
548 for (i = 0; i < g->height/zr->vdec; i++) {
549 memcpy(dest, source, zr->image_width*2);
550 dest += 2*zr->image_width;
551 source += zr->vdec*zr->stride;
554 return 0;
557 static int query_format(uint32_t format) {
558 if(format==IMGFMT_YV12 || format==IMGFMT_YUY2)
559 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
560 return 0;
563 static void uninit(void) {
564 int j;
565 mp_msg(MSGT_VO, MSGL_V, "zr: uninit called\n");
566 for (j = 0; j < zr_count; j++) {
567 jpeg_enc_uninit(zr_info[j].j);
568 uninit_zoran(&zr_info[j]);
572 static void check_events(void) {
576 static int draw_slice(uint8_t *srcimg[], int stride[],
577 int wf, int hf, int xf, int yf) {
578 int i, j, w, h, x, y;
579 /* Apply 'geometry', crop unwanted parts */
580 uint8_t *dst;
581 //printf("before: w=%d, h=%d, x=%d, y=%d, src0=%p, src1=%p, src2=%p\n", w, h, x, y, srcimg[0], srcimg[1], srcimg[2]);
582 for (j = 0; j < zr_count; j++) {
583 uint8_t *src=srcimg[0];
584 uint8_t *src1=srcimg[1];
585 uint8_t *src2=srcimg[2];
586 zr_info_t *zr = &zr_info[j];
587 geo_t *g = &zr->g;
588 w = wf; h = hf; x = xf; y = yf;
589 if (x < g->xoff) {
590 src += g->xoff - x;
591 src1 += (g->xoff - x)/2;
592 src2 += (g->xoff - x)/2;
593 w -= g->xoff - x;
594 if (w < 0) break; //return 0;
595 x = 0 /*g.xoff*/;
596 } else {
597 x -= g->xoff;
599 if (x + w > g->width) {
600 w = g->width - x;
601 if (w < 0) break; //return 0;
603 if (y < g->yoff) {
604 src += (g->yoff - y)*stride[0];
605 src1 += ((g->yoff - y)/2)*stride[1];
606 src2 += ((g->yoff - y)/2)*stride[2];
607 h -= g->yoff - y;
608 if (h < 0) break; //return 0;
609 y = 0;
610 } else {
611 y -= g->yoff;
613 if (y + h > g->height) {
614 h = g->height - y;
615 if (h < 0) break; //return 0;
617 //printf("after: w=%d, h=%d, x=%d, y=%d, src0=%p, src1=%p, src2=%p\n", w, h, x, y, srcimg[0], srcimg[1], srcimg[2]);
618 dst=zr->image + zr->off_y + zr->image_width*(y/zr->vdec)+x;
619 // copy Y:
620 for (i = 0; i < h; i++) {
621 if ((i + x)%zr->vdec == 0) {
622 memcpy(dst,src,w);
623 dst+=zr->image_width;
625 src+=stride[0];
628 if (!zr->bw) {
629 // copy U+V:
630 uint8_t *dst1=zr->image + zr->size + zr->off_c+ (y/(zr->vdec*2))*zr->image_width/2+(x/2);
631 uint8_t *dst2=zr->image + 3*zr->size/2 + zr->off_c +
632 (y/(zr->vdec*2))*
633 zr->image_width/2+(x/2);
634 for (i = 0; i< h/2; i++) {
635 if ((i+x/2)%zr->vdec == 0) {
636 memcpy(dst1,src1,w/2);
637 memcpy(dst2,src2,w/2);
638 dst1+=zr->image_width/2;
639 dst2+=zr->image_width/2;
641 src1+=stride[1];
642 src2+=stride[2];
646 return 0;
650 /* copied and adapted from vo_aa_parseoption */
652 vo_zr_parseoption(m_option_t* conf, char *opt, char *param){
653 /* got an option starting with zr */
654 zr_info_t *zr = &zr_info[zr_parsing];
655 int i;
656 /* do WE need it ?, always */
657 if (!strcasecmp(opt, "zrdev")) {
658 if (param == NULL) return ERR_MISSING_PARAM;
659 //if ((i=getcolor(param))==-1) return ERR_OUT_OF_RANGE;
660 //aaopt_osdcolor=i;
661 free(zr->device);
662 zr->device = malloc(strlen(param)+1);
663 strcpy(zr->device, param);
664 mp_msg(MSGT_VO, MSGL_V, "zr: using device %s\n", zr->device);
665 return 1;
666 } else if (!strcasecmp(opt, "zrbw")) {
667 if (param != NULL) {
668 return ERR_OUT_OF_RANGE;
670 zr->bw = 1;
671 return 1;
672 } else if (!strcasecmp(opt, "zrfd")) {
673 if (param != NULL) {
674 return ERR_OUT_OF_RANGE;
676 zr->fd = 1;
677 return 1;
678 } else if (!strcasecmp(opt, "zrcrop")){
679 geo_t *g = &zr->g;
680 if (g->set == 1) {
681 zr_parsing++;
682 zr_count++;
683 zr = &zr_info[zr_parsing];
684 g = &zr->g;
685 if (zr_count > 4) {
686 mp_msg(MSGT_VO, MSGL_ERR, "zr: too many simultaneus display devices requested (max. is 4)\n");
687 return ERR_OUT_OF_RANGE;
690 if (param == NULL) return ERR_MISSING_PARAM;
691 if (sscanf(param, "%dx%d+%d+%d", &g->width, &g->height,
692 &g->xoff, &g->yoff) != 4) {
693 g->xoff = 0; g->yoff = 0;
694 if (sscanf(param, "%dx%d", &g->width, &g->height) != 2) {
695 mp_msg(MSGT_VO, MSGL_ERR, "zr: argument to -zrcrop must be of the form 352x288+16+0\n");
696 return ERR_OUT_OF_RANGE;
699 g->set = 1;
700 mp_msg(MSGT_VO, MSGL_V, "zr: cropping %s\n", param);
701 return 1;
702 }else if (!strcasecmp(opt, "zrhdec")) {
703 i = atoi(param);
704 if (i != 1 && i != 2 && i != 4) return ERR_OUT_OF_RANGE;
705 zr->hdec = i;
706 return 1;
707 }else if (!strcasecmp(opt, "zrvdec")) {
708 i = atoi(param);
709 if (i != 1 && i != 2 && i != 4) return ERR_OUT_OF_RANGE;
710 zr->vdec = i;
711 return 1;
712 }else if (!strcasecmp(opt, "zrxdoff")) {
713 i = atoi(param);
714 zr->xdoff = i;
715 return 1;
716 }else if (!strcasecmp(opt, "zrydoff")) {
717 i = atoi(param);
718 zr->ydoff = i;
719 return 1;
720 }else if (!strcasecmp(opt, "zrquality")) {
721 i = atoi(param);
722 if (i < 1 || i > 20) return ERR_OUT_OF_RANGE;
723 zr->quality = i;
724 return 1;
725 }else if (!strcasecmp(opt, "zrnorm")) {
726 if (param == NULL) return ERR_MISSING_PARAM;
727 if (!strcasecmp(param, "NTSC")) {
728 mp_msg(MSGT_VO, MSGL_V, "zr: Norm set to NTSC\n");
729 zr->norm = VIDEO_MODE_NTSC;
730 return 1;
731 } else if (!strcasecmp(param, "PAL")) {
732 mp_msg(MSGT_VO, MSGL_V, "zr: Norm set to PAL\n");
733 zr->norm = VIDEO_MODE_PAL;
734 return 1;
735 } else {
736 return ERR_OUT_OF_RANGE;
738 }else if (!strcasecmp(opt, "zrhelp")){
739 printf("Help for -vo zr: Zoran ZR360[56]7/ZR36060 based MJPEG capture/playback cards\n");
740 printf("\n");
741 printf("Here are the zr options:\n");
742 printf(
743 "\n"
744 " -zrcrop specify part of the input image that\n"
745 " you want to see as an x-style geometry string\n"
746 " example: -zrcrop 352x288+16+0\n"
747 " -zrvdec vertical decimation 1, 2 or 4\n"
748 " -zrhdec horizontal decimation 1, 2 or 4\n"
749 " -zrfd decimation is only done if the primitive\n"
750 " hardware upscaler can correct for the decimation,\n"
751 " this switch allows you to see the effects\n"
752 " of too much decimation\n"
753 " -zrbw display in black&white (speed increase)\n"
754 " -zrxdoff x offset from upper-left of TV screen (default is 'centered')\n"
755 " -zrydoff y offset from upper-left of TV screen (default is 'centered')\n"
756 " -zrquality jpeg compression quality [BEST] 1 - 20 [VERY BAD]\n"
757 " -zrdev playback device (example -zrdev /dev/video1)\n"
758 " -zrnorm specify norm PAL/NTSC (default: leave at current setting)\n"
759 "\n"
760 "Cinerama support: additional occurances of -zrcrop activate cinerama mode,\n"
761 "suppose you have a 704x272 movie, two DC10+ cards and two beamers (or tv's),\n"
762 "then you would issue the following command:\n\n"
763 "mplayer -vo zr -zrcrop 352x272+0+0 -zrdev /dev/video0 -zrcrop 352x272+352+0 \\\n"
764 " -zrdev /dev/video1 movie.avi\n\n"
765 "Options appearing after the second -zrcrop apply to the second card, it is\n"
766 "possible to dispay at a different jpeg quality or at different decimations.\n\n"
767 "The parameters -zrxdoff and -zrydoff can be used to align the two images.\n"
768 "The maximum number of zoran cards participating in cinerama is 4, so you can\n"
769 "build a 2x2 vidiwall. (untested for obvious reasons, the setup wit a buz and\n"
770 "a DC10+ (and no beamers) is tested, however)\n"
772 exit(0);
775 return ERR_NOT_AN_OPTION;
778 void vo_zr_revertoption(m_option_t* opt,char* param) {
780 zr_info_t *zr = &zr_info[1];
781 zr_count = 1;
782 zr_parsing = 0;
784 if (!strcasecmp(param, "zrdev")) {
785 if(zr->device)
786 free(zr->device);
787 zr->device=NULL;
788 } else if (!strcasecmp(param, "zrbw"))
789 zr->bw=0;
790 else if (!strcasecmp(param, "zrfd"))
791 zr->fd=0;
792 else if (!strcasecmp(param, "zrcrop"))
793 zr->g.set = zr->g.xoff = zr->g.yoff = 0;
794 else if (!strcasecmp(param, "zrhdec"))
795 zr->hdec = 1;
796 else if (!strcasecmp(param, "zrvdec"))
797 zr->vdec = 1;
798 else if (!strcasecmp(param, "zrxdoff"))
799 zr->xdoff = -1;
800 else if (!strcasecmp(param, "zrydoff"))
801 zr->ydoff = -1;
802 else if (!strcasecmp(param, "zrquality"))
803 zr->quality = 2;
804 else if (!strcasecmp(param, "zrnorm"))
805 zr->norm = VIDEO_MODE_AUTO;
809 static int preinit(const char *arg)
811 if(arg)
813 printf("vo_zr: Unknown subdevice: %s\n",arg);
814 return ENOSYS;
816 return 0;
819 static int control(uint32_t request, void *data, ...)
821 switch (request) {
822 case VOCTRL_QUERY_FORMAT:
823 return query_format(*((uint32_t*)data));
825 return VO_NOTIMPL;