static void rd_init(const char *fname) { port = xstrdup(fname); db(1, "Opening port...\n"); if (fd = gbser_init(port), NULL == fd) { fatal(MYNAME ": Can't initialise port \"%s\"\n", port); } dev_type = guess_device(); if (UNKNOWN == dev_type) { fatal(MYNAME ": Can't determine device type\n"); } }
static int preinit(const char *arg) { vo_zr2_priv_t *p = &priv; const char *dev = NULL; char *dev_arg = NULL, *norm_arg = NULL; int norm = VIDEO_MODE_AUTO, prebuf = 0; const opt_t subopts[] = { /* don't want warnings with -Wall... */ { "dev", OPT_ARG_MSTRZ, &dev_arg, NULL }, { "prebuf", OPT_ARG_BOOL, &prebuf, pbc }, { "norm", OPT_ARG_MSTRZ, &norm_arg, nc }, { NULL, 0, NULL, NULL } }; VERBOSE("preinit() called with arg: %s\n", arg); memset(p, 0, sizeof(*p)); /* set defaults */ p->vdes = -1; if (subopt_parse(arg, subopts)) { mp_msg(MSGT_VO, MSGL_FATAL, "Allowed suboptions for -vo zr2 are:\n" "- dev=DEVICE (default: %s)\n" "- norm=PAL|NTSC|SECAM|auto (default: auto)\n" "- prebuf/noprebuf (default:" " noprebuf)\n" "\n" "Example: mplayer -vo zr2:dev=/dev/video1:" "norm=PAL movie.avi\n\n" , guess_device(NULL, 0)); free(norm_arg); free(dev_arg); return -1; } /* interpret the strings we got from subopt_parse */ if (norm_arg) { norm = get_norm(norm_arg); free(norm_arg); } if (dev_arg) dev = dev_arg; dev = guess_device(dev, 1); if (!dev) { free(dev_arg); uninit(); return 1; } p->vdes = open(dev, O_RDWR); if (p->vdes < 0) { ERROR("error opening %s: %s\n", dev, strerror(errno)); free(dev_arg); uninit(); return 1; } free(dev_arg); /* check if we really are dealing with a zoran card */ if (ioctl(p->vdes, MJPIOC_G_PARAMS, &p->zp) < 0) { ERROR("%s probably is not a DC10(+)/buz/lml33\n", dev); uninit(); return 1; } VERBOSE("kernel driver version %d.%d, current norm is %s\n", p->zp.major_version, p->zp.minor_version, normstring(p->zp.norm)); /* changing the norm in the zoran_params and MJPIOC_S_PARAMS * does nothing the last time I tried, so bail out if the norm * is not correct */ if (norm != VIDEO_MODE_AUTO && p->zp.norm != norm) { ERROR("mplayer currently can't change the video norm, " "change it with (eg.) XawTV and retry.\n"); uninit(); return 1; } /* gather useful information */ if (ioctl(p->vdes, VIDIOCGCAP, &p->vc) < 0) { ERROR("error getting video capabilities from %s\n", dev); uninit(); return 1; } VERBOSE("card reports maxwidth=%d, maxheight=%d\n", p->vc.maxwidth, p->vc.maxheight); /* according to the mjpegtools source, some cards return a bogus * vc.maxwidth, correct it here. If a new zoran card appears with a * maxwidth different 640, 720 or 768 this code may lead to problems */ if (p->vc.maxwidth != 640 && p->vc.maxwidth != 768) { VERBOSE("card probably reported bogus width (%d), " "changing to 720\n", p->vc.maxwidth); p->vc.maxwidth = 720; } p->zrq.count = ZR2_MJPEG_NBUFFERS; p->zrq.size = ZR2_MJPEG_SIZE; if (ioctl(p->vdes, MJPIOC_REQBUFS, &p->zrq)) { ERROR("error requesting %d buffers of size %d\n", ZR2_MJPEG_NBUFFERS, ZR2_MJPEG_NBUFFERS); uninit(); return 1; } VERBOSE("got %ld buffers of size %ld (wanted %d buffers of size %d)\n", p->zrq.count, p->zrq.size, ZR2_MJPEG_NBUFFERS, ZR2_MJPEG_SIZE); p->buf = (unsigned char*)mmap(0, p->zrq.count*p->zrq.size, PROT_READ|PROT_WRITE, MAP_SHARED, p->vdes, 0); if (p->buf == MAP_FAILED) { ERROR("error mapping requested buffers: %s", strerror(errno)); uninit(); return 1; } return 0; }