2 * vo_zr.c - playback on zoran cards
3 * Copyright (C) Rik Snel 2001,2002, License GNU GPL v2
15 #include <sys/types.h>
18 #include <sys/ioctl.h>
19 #include <linux/types.h>
20 #include <linux/videodev.h>
21 #include "videodev_mjpeg.h"
25 #include "video_out.h"
26 #include "video_out_internal.h"
29 #include "fastmemcpy.h"
33 static vo_info_t info
=
35 "Zoran ZR360[56]7/ZR36060 Driver (DC10(+)/buz/lml33/MatroxRR)",
37 "Rik Snel <rsnel@cube.dyndns.org>",
43 #define ZR_MAX_DEVICES 4
44 /* General variables */
54 static int zr_count
= 1;
55 static int zr_parsing
= 0;
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 */
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 */
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? */
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
) {
117 const char *devs
[] = {
129 if ((stat(devs
[i
], &vstat
) == 0) && S_ISCHR(vstat
.st_mode
))
132 mp_msg(MSGT_VO
, MSGL_V
, "zr: found video device %s\n", dev
);
135 } while (devs
[++i
] != NULL
);
139 mp_msg(MSGT_VO
, MSGL_ERR
, "zr: unable to find video device\n");
144 zr
->vdes
= open(dev
, O_RDWR
);
147 mp_msg(MSGT_VO
, MSGL_ERR
, "zr: error opening %s: %s\n",
148 dev
, strerror(errno
));
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
);
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");
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");
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
);
180 mp_msg(MSGT_VO
, MSGL_V
, "zr: MJPEG card reports maxwidth=%d, maxheight=%d\n", zr
->vc
.maxwidth
, zr
->vc
.maxheight
);
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
);
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
);
198 zr
->p
.decimation
= 0;
199 zr
->p
.HorDcm
= stretchx
;
200 zr
->p
.VerDcm
= stretchy
;
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;
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;
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");
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
);
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
);
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");
253 void uninit_zoran(zr_info_t
*zr
) {
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");
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");
272 int zr_geometry_sane(geo_t
*g
, unsigned int width
, unsigned int height
) {
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");
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");
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
);
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
);
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
;
308 if (format
!= IMGFMT_YV12
&& format
!= IMGFMT_YUY2
) {
309 printf("vo_zr called with wrong format");
312 for (i
= 0; i
< zr_count
; i
++) {
313 zr_info_t
*zr
= &zr_info
[i
];
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) {
334 } else if (zr
->vdec
== 4) {
339 } else if (g
->width
> zr
->vc
.maxwidth
/4 ||
340 g
->height
> zr
->vc
.maxheight
/4) {
346 } else if (zr
->vdec
== 4) {
348 mp_msg(MSGT_VO
, MSGL_WARN
, "zr: vertical decimation too high, changing to 2 (use -zrfd to keep vdec=4)\n");
355 } else if (zr
->hdec
== 4){
357 mp_msg(MSGT_VO
, MSGL_WARN
, "zr: horizontal decimation too high, changing to 2 (use -zrfd to keep hdec=4)\n");
363 /* output image is maximally stretched */
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
);
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
);
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
);
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)/
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 */
419 mp_msg(MSGT_VO
, MSGL_ERR
, "zr: Memory exhausted\n");
422 /* and make sure that the borders are _really_ black */
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
);
444 for (tmp
= 0; tmp
< 2*zr
->size
; tmp
+=4) {
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
,
462 zr
->y_stride
*zr
->fields
,
464 zr
->u_stride
*zr
->fields
,
466 zr
->v_stride
*zr
->fields
,
467 0, zr
->quality
, zr
->bw
);
470 mp_msg(MSGT_VO
, MSGL_FATAL
, "zr: internal inconsistency in vo_zr\n");
475 mp_msg(MSGT_VO
, MSGL_ERR
, "zr: error initializing the jpeg encoder\n");
479 if (init_zoran(zr
, stretchx
, stretchy
)) {
487 static void draw_osd(void) {
490 static void flip_page (void) {
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
;
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
;
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");
522 fwrite(buf+frame*zrq.size, 1, k, fp);
524 /*fp = fopen("test1.jpg", "r");
525 fread(buf+frame*zrq.size, 1, 2126, 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");
539 static int draw_frame(uint8_t * src
[]) {
542 //printf("draw frame called\n");
543 for (j
= 0; j
< zr_count
; j
++) {
544 zr_info_t
*zr
= &zr_info
[j
];
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
;
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
;
563 static void uninit(void) {
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 */
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
];
588 w
= wf
; h
= hf
; x
= xf
; y
= yf
;
591 src1
+= (g
->xoff
- x
)/2;
592 src2
+= (g
->xoff
- x
)/2;
594 if (w
< 0) break; //return 0;
599 if (x
+ w
> g
->width
) {
601 if (w
< 0) break; //return 0;
604 src
+= (g
->yoff
- y
)*stride
[0];
605 src1
+= ((g
->yoff
- y
)/2)*stride
[1];
606 src2
+= ((g
->yoff
- y
)/2)*stride
[2];
608 if (h
< 0) break; //return 0;
613 if (y
+ h
> g
->height
) {
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
;
620 for (i
= 0; i
< h
; i
++) {
621 if ((i
+ x
)%zr
->vdec
== 0) {
623 dst
+=zr
->image_width
;
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
+
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;
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
];
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;
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
);
666 } else if (!strcasecmp(opt
, "zrbw")) {
668 return ERR_OUT_OF_RANGE
;
672 } else if (!strcasecmp(opt
, "zrfd")) {
674 return ERR_OUT_OF_RANGE
;
678 } else if (!strcasecmp(opt
, "zrcrop")){
683 zr
= &zr_info
[zr_parsing
];
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
;
700 mp_msg(MSGT_VO
, MSGL_V
, "zr: cropping %s\n", param
);
702 }else if (!strcasecmp(opt
, "zrhdec")) {
704 if (i
!= 1 && i
!= 2 && i
!= 4) return ERR_OUT_OF_RANGE
;
707 }else if (!strcasecmp(opt
, "zrvdec")) {
709 if (i
!= 1 && i
!= 2 && i
!= 4) return ERR_OUT_OF_RANGE
;
712 }else if (!strcasecmp(opt
, "zrxdoff")) {
716 }else if (!strcasecmp(opt
, "zrydoff")) {
720 }else if (!strcasecmp(opt
, "zrquality")) {
722 if (i
< 1 || i
> 20) return ERR_OUT_OF_RANGE
;
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
;
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
;
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");
741 printf("Here are the zr options:\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"
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"
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];
784 if (!strcasecmp(param
, "zrdev")) {
788 } else if (!strcasecmp(param
, "zrbw"))
790 else if (!strcasecmp(param
, "zrfd"))
792 else if (!strcasecmp(param
, "zrcrop"))
793 zr
->g
.set
= zr
->g
.xoff
= zr
->g
.yoff
= 0;
794 else if (!strcasecmp(param
, "zrhdec"))
796 else if (!strcasecmp(param
, "zrvdec"))
798 else if (!strcasecmp(param
, "zrxdoff"))
800 else if (!strcasecmp(param
, "zrydoff"))
802 else if (!strcasecmp(param
, "zrquality"))
804 else if (!strcasecmp(param
, "zrnorm"))
805 zr
->norm
= VIDEO_MODE_AUTO
;
809 static int preinit(const char *arg
)
813 printf("vo_zr: Unknown subdevice: %s\n",arg
);
819 static int control(uint32_t request
, void *data
, ...)
822 case VOCTRL_QUERY_FORMAT
:
823 return query_format(*((uint32_t*)data
));