コード例 #1
0
ファイル: grabber-xv.cpp プロジェクト: pierz/vic
XvGrabber::XvGrabber() : capwin_(0), decimate_(0), grabID_(0)
{
	Tcl& tcl = Tcl::instance();

	if (getgrabber() < 0) {
		status_ = -1;
		return;
	}
		fprintf(stderr, "set to grab port\n");
	Display* dpy = Tk_Display(Tcl::instance().tkmain());
	if (XvGrabPort(dpy, grabID_, CurrentTime) != Success) {
		fprintf(stderr, "Unable to grab port\n");
		tcl.result("Unable to reserve grabber.");
		status_ = -1;
		return;
	}
}
コード例 #2
0
ファイル: X11Renderer.cpp プロジェクト: goodinges/Ciao-Chat
bool X11Renderer::InitVideoXv() {
	XvAdaptorInfo *ai;
	uint32_t adaptors;
	XvPortID xvP;
	int ret;

	ret = XvQueryAdaptors(m_pDisplay, DefaultRootWindow(m_pDisplay), &adaptors, &ai);
	if (ret != Success) {
		ERROR("XvQueryAdaptors failed");
		return false;
	}

	REND_DBG("adaptors: %d", adaptors);
    m_Port = 0;
	for (unsigned int i = 0; i < adaptors; i++) {
		REND_DBG("adaptor %d", adaptors);
		if ((ai[i].type & ( XvInputMask | XvImageMask)) == (XvInputMask | XvImageMask)) {
			for (xvP = ai[i].base_id; xvP<ai[i].base_id+ai[i].num_ports; xvP++ ) {
				REND_DBG("Port %d", xvP);
				if (XvGrabPort( m_pDisplay, xvP, CurrentTime ) == Success) {
					m_Port = xvP;
					REND_DBG("Got port %d\n", m_Port);
					break;
				}
			}
			if ( m_Port != 0 )
				break;
		}	
	}
	XvFreeAdaptorInfo(ai);

	if (!m_Port) {
		ERROR("Failed to grab port");
		return false;
	}

	m_pXvImage = XvCreateImage(m_pDisplay, m_Port, GUID_I420_PLANAR, NULL, m_VPar.width, m_VPar.height);

	if (!m_pXvImage) {
		ERROR("XvCreateImage failed");
		return false;
	}

	REND_DBG("Image data: 0x%x, size: %d", m_pXvImage->data, m_pXvImage->data_size);
	return true;
}
コード例 #3
0
ファイル: x11_app.cpp プロジェクト: premsasidharan/mmfcpp
XvPortID X11_app::get_xv_port()
{
    XvPortID port = 0;
    unsigned int count = 0;
    XvAdaptorInfo* info = 0;

    int status = XvQueryAdaptors(_display, XRootWindow(_display, _screen), &count, &info);
    for (int i = 0; i < (int)count; i++)
    {
        printf( "\n\tAdapter Name : %s, Port base id: 0x%x, Num of Ports: %ld\n", info[i].name, (unsigned int)info[i].base_id, info[i].num_ports);
        for (int j = 0; j < (int)info[j].num_ports; j++)
        {
            port = j+info[i].base_id;
            status = XvGrabPort(_display, port, CurrentTime);
            if (status == Success)
            {
                goto exit;
            }
        }
    }
exit:
    XvFreeAdaptorInfo(info);
    return port;
}
コード例 #4
0
ファイル: yuv_window.cpp プロジェクト: premsasidharan/mmfcpp
XvPortID Yuv_window::get_xv_port()
{
    XvPortID port = 0;
    unsigned int count = 0;
    XvAdaptorInfo* info = 0;

    int status = XvQueryAdaptors(QX11Info::display(), QX11Info::appRootWindow(), &count, &info);
    for (int i = 0; i < (int)count; i++)
    {
        printf( "\nAdapter Name : %s, Port base id: 0x%x, Num of Ports: %ld\n", info[i].name, (unsigned int)info[i].base_id, info[i].num_ports);
        for (int j = 0; j < (int)info[j].num_ports; j++)
        {
            port = j+info[i].base_id;
            status = XvGrabPort(QX11Info::display(), port, QX11Info::appUserTime());
            if (status == Success)
            {
                goto exit;
            }
        }
    }
exit:
    XvFreeAdaptorInfo(info);
    return port;
}
コード例 #5
0
int XVWindow::init(Display* dp, Window rootWindow, int x, int y, int windowWidth, int windowHeight, int imageWidth, int imageHeight) {

	// local variables needed for creation of window and initialization of XV extension
	unsigned int i;
	unsigned int ver, rel, req, ev, err, adapt;
	XSetWindowAttributes xswattributes;
	XWindowAttributes xwattributes;
	XVisualInfo xvinfo;
	XvAdaptorInfo *xvainfo;
	unsigned int candidateXVPort=0;
	unsigned int busyPorts=0;

	_display=dp;
	_rootWindow=rootWindow;
	_state.origLayer=0;

	// initialize atoms
	WM_DELETE_WINDOW = XInternAtom(_display, "WM_DELETE_WINDOW", False);
	XA_WIN_PROTOCOLS = XInternAtom(_display, "_WIN_PROTOCOLS", False);
	XA_NET_SUPPORTED = XInternAtom(_display, "_NET_SUPPORTED", False);
	XA_NET_WM_STATE = XInternAtom(_display, "_NET_WM_STATE", False);
	XA_NET_WM_STATE_FULLSCREEN = XInternAtom(_display, "_NET_WM_STATE_FULLSCREEN", False);
	XA_NET_WM_STATE_ABOVE = XInternAtom(_display, "_NET_WM_STATE_ABOVE", False);
	XA_NET_WM_STATE_STAYS_ON_TOP = XInternAtom(_display, "_NET_WM_STATE_STAYS_ON_TOP", False);
	XA_NET_WM_STATE_BELOW = XInternAtom(_display, "_NET_WM_STATE_BELOW", False);

	XGetWindowAttributes(_display, _rootWindow, &xwattributes);
	XMatchVisualInfo(_display, DefaultScreen(_display), xwattributes.depth, TrueColor, &xvinfo);

	// define window properties and create the window
	xswattributes.colormap = XCreateColormap(_display, _rootWindow, xvinfo.visual, AllocNone);
	xswattributes.event_mask = StructureNotifyMask | ExposureMask;
	xswattributes.background_pixel = 0;
	xswattributes.border_pixel = 0;
	_XVWindow = XCreateWindow(_display, _rootWindow, x, y, windowWidth, windowHeight, 0, xvinfo.depth,
	 	InputOutput, xvinfo.visual, CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &xswattributes);

	// define inputs events
	XSelectInput(_display, _XVWindow, StructureNotifyMask | KeyPressMask | ButtonPressMask);

	setSizeHints(DEFAULT_X,DEFAULT_Y, imageWidth, imageHeight, windowWidth, windowHeight);

	// map the window
	XMapWindow(_display, _XVWindow);

	XSetWMProtocols(_display, _XVWindow, &WM_DELETE_WINDOW,1);

	// check if SHM XV window is possible
	if (Success != XvQueryExtension(_display, &ver, &rel, &req, &ev, &err)) {
		LOG_DEBUG("[x11] XQueryExtension failed");
		return 0;
	}
	if (!XShmQueryExtension(_display)) {
		LOG_DEBUG("[x11] XQueryShmExtension failed");
		return 0;
	}
	if (Success != XvQueryAdaptors(_display, _rootWindow, &adapt, &xvainfo)) {
		LOG_DEBUG("[x11] XQueryAdaptor failed"); XFree(xvainfo);
		return 0;
	}

	// look for a usable XV port
	for (i = 0; i < adapt && _XVPort == 0; i++) {
		if ((xvainfo[i].type & XvInputMask) && (xvainfo[i].type & XvImageMask)) {
			for (candidateXVPort = xvainfo[i].base_id; candidateXVPort < xvainfo[i].base_id + xvainfo[i].num_ports; ++candidateXVPort)
				if (!XvGrabPort(_display, candidateXVPort, CurrentTime)) {
					_XVPort = candidateXVPort;
					break;
				} else {
					LOG_DEBUG("[x11] Could not grab port: " + String::fromNumber(candidateXVPort));
					++busyPorts;
				}
		}
	}
	XvFreeAdaptorInfo(xvainfo);

	if (!_XVPort) {
		if (busyPorts) {
			LOG_WARN("[x11] Could not find free Xvideo port - maybe another process is already using it.");
		} else {
			LOG_WARN("[x11] It seems there is no Xvideo support for your video card available.");
		}
		return 0;
	} else {
		LOG_WARN("[x11] Use XVideo port: " + String::fromNumber(_XVPort));
	}

	_gc = XCreateGC(_display, _XVWindow, 0, 0);

	// create the shared memory portion
	_XVImage = XvShmCreateImage(_display, _XVPort, GUID_I420_PLANAR, 0, imageWidth, imageHeight, &_XShmInfo);

	_XShmInfo.shmid = shmget(IPC_PRIVATE, _XVImage->data_size, IPC_CREAT | 0777);
	_XShmInfo.shmaddr = (char *) shmat(_XShmInfo.shmid, 0, 0);
	_XVImage->data = _XShmInfo.shmaddr;
	_XShmInfo.readOnly = False;
	if (!XShmAttach(_display, &_XShmInfo)) {
		LOG_WARN("[x11] XShmAttach failed");
		return 0;
	} else {
		_isInitialized = true;
	}

	// detect the window manager type
	_wmType=getWMType();

	return 1;
}
コード例 #6
0
ファイル: vo_xv.c プロジェクト: hroncok/mpv
static void draw_osd(struct vo *vo, struct osd_state *osd)
{
    struct xvctx *ctx = vo->priv;

    struct mp_image img = get_xv_buffer(vo, ctx->current_buf);

    struct mp_osd_res res = {
        .w = ctx->image_width,
        .h = ctx->image_height,
        .display_par = 1.0 / vo->aspdat.par,
    };

    osd_draw_on_image(osd, res, osd->vo_pts, 0, &img);
}

static void wait_for_completion(struct vo *vo, int max_outstanding)
{
#if HAVE_SHM
    struct xvctx *ctx = vo->priv;
    struct vo_x11_state *x11 = vo->x11;
    if (ctx->Shmem_Flag) {
        while (x11->ShmCompletionWaitCount > max_outstanding) {
            if (!ctx->Shm_Warned_Slow) {
                MP_WARN(vo, "X11 can't keep up! Waiting"
                        " for XShm completion events...\n");
                ctx->Shm_Warned_Slow = 1;
            }
            mp_sleep_us(1000);
            vo_x11_check_events(vo);
        }
    }
#endif
}

static void flip_page(struct vo *vo)
{
    struct xvctx *ctx = vo->priv;
    put_xvimage(vo, ctx->xvimage[ctx->current_buf]);

    /* remember the currently visible buffer */
    ctx->current_buf = (ctx->current_buf + 1) % ctx->num_buffers;

    if (!ctx->Shmem_Flag)
        XSync(vo->x11->display, False);
}

static mp_image_t *get_screenshot(struct vo *vo)
{
    struct xvctx *ctx = vo->priv;
    if (!ctx->original_image)
        return NULL;

    return mp_image_new_ref(ctx->original_image);
}

// Note: redraw_frame() can call this with NULL.
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
    struct xvctx *ctx = vo->priv;

    wait_for_completion(vo, ctx->num_buffers - 1);

    struct mp_image xv_buffer = get_xv_buffer(vo, ctx->current_buf);
    if (mpi) {
        mp_image_copy(&xv_buffer, mpi);
    } else {
        mp_image_clear(&xv_buffer, 0, 0, xv_buffer.w, xv_buffer.h);
    }

    mp_image_setrefp(&ctx->original_image, mpi);
}

static int redraw_frame(struct vo *vo)
{
    struct xvctx *ctx = vo->priv;

    draw_image(vo, ctx->original_image);
    return true;
}

static int query_format(struct vo *vo, uint32_t format)
{
    struct xvctx *ctx = vo->priv;
    uint32_t i;
    int flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;

    int fourcc = find_xv_format(format);
    if (fourcc) {
        for (i = 0; i < ctx->formats; i++) {
            if (ctx->fo[i].id == fourcc)
                return flag;
        }
    }
    return 0;
}

static void uninit(struct vo *vo)
{
    struct xvctx *ctx = vo->priv;
    int i;

    talloc_free(ctx->original_image);

    if (ctx->ai)
        XvFreeAdaptorInfo(ctx->ai);
    ctx->ai = NULL;
    if (ctx->fo) {
        XFree(ctx->fo);
        ctx->fo = NULL;
    }
    for (i = 0; i < ctx->num_buffers; i++)
        deallocate_xvimage(vo, i);
    // uninit() shouldn't get called unless initialization went past vo_init()
    vo_x11_uninit(vo);
}

static int preinit(struct vo *vo)
{
    XvPortID xv_p;
    int busy_ports = 0;
    unsigned int i;
    struct xvctx *ctx = vo->priv;
    int xv_adaptor = ctx->cfg_xv_adaptor;

    if (!vo_x11_init(vo))
        return -1;

    struct vo_x11_state *x11 = vo->x11;

    /* check for Xvideo extension */
    unsigned int ver, rel, req, ev, err;
    if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) {
        MP_ERR(vo, "Xv not supported by this X11 version/driver\n");
        goto error;
    }

    /* check for Xvideo support */
    if (Success !=
        XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display),
                        &ctx->adaptors, &ctx->ai)) {
        MP_ERR(vo, "XvQueryAdaptors failed.\n");
        goto error;
    }

    /* check adaptors */
    if (ctx->xv_port) {
        int port_found;

        for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) {
            if ((ctx->ai[i].type & XvInputMask)
                && (ctx->ai[i].type & XvImageMask)) {
                for (xv_p = ctx->ai[i].base_id;
                     xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports;
                     ++xv_p) {
                    if (xv_p == ctx->xv_port) {
                        port_found = 1;
                        break;
                    }
                }
            }
        }
        if (port_found) {
            if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime))
                ctx->xv_port = 0;
        } else {
            MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n");
            ctx->xv_port = 0;
        }
    }

    for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) {
        /* check if adaptor number has been specified */
        if (xv_adaptor != -1 && xv_adaptor != i)
            continue;

        if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) {
            for (xv_p = ctx->ai[i].base_id;
                 xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p)
                if (!XvGrabPort(x11->display, xv_p, CurrentTime)) {
                    ctx->xv_port = xv_p;
                    MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n",
                               i, ctx->ai[i].name);
                    break;
                } else {
                    MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p);
                    ++busy_ports;
                }
        }
    }
    if (!ctx->xv_port) {
        if (busy_ports)
            MP_ERR(vo,
                   "Could not find free Xvideo port - maybe another process is already\n"\
                   "using it. Close all video applications, and try again. If that does\n"\
                   "not help, see 'mpv -vo help' for other (non-xv) video out drivers.\n");
        else
            MP_ERR(vo,
                   "It seems there is no Xvideo support for your video card available.\n"\
                   "Run 'xvinfo' to verify its Xv support and read\n"\
                   "DOCS/HTML/en/video.html#xv!\n"\
                   "See 'mpv -vo help' for other (non-xv) video out drivers.\n"\
                   "Try -vo x11.\n");
        goto error;
    }

    if (!xv_init_colorkey(vo)) {
        goto error;             // bail out, colorkey setup failed
    }
    xv_enable_vsync(vo);
    xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height);

    ctx->fo = XvListImageFormats(x11->display, ctx->xv_port,
                                 (int *) &ctx->formats);

    return 0;

  error:
    uninit(vo);                 // free resources
    return -1;
}
コード例 #7
0
ファイル: vo_xv.c プロジェクト: DZW314/mpv
static int preinit(struct vo *vo)
{
    XvPortID xv_p;
    int busy_ports = 0;
    unsigned int i;
    struct xvctx *ctx = vo->priv;
    int xv_adaptor = ctx->cfg_xv_adaptor;

    if (!vo_x11_init(vo))
        return -1;

    if (!vo_x11_create_vo_window(vo, NULL, "xv"))
        goto error;

    struct vo_x11_state *x11 = vo->x11;

    /* check for Xvideo extension */
    unsigned int ver, rel, req, ev, err;
    if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) {
        MP_ERR(vo, "Xv not supported by this X11 version/driver\n");
        goto error;
    }

    /* check for Xvideo support */
    if (Success !=
        XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display),
                        &ctx->adaptors, &ctx->ai)) {
        MP_ERR(vo, "XvQueryAdaptors failed.\n");
        goto error;
    }

    /* check adaptors */
    if (ctx->xv_port) {
        int port_found;

        for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) {
            if ((ctx->ai[i].type & XvInputMask)
                && (ctx->ai[i].type & XvImageMask)) {
                for (xv_p = ctx->ai[i].base_id;
                     xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports;
                     ++xv_p) {
                    if (xv_p == ctx->xv_port) {
                        port_found = 1;
                        break;
                    }
                }
            }
        }
        if (port_found) {
            if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime))
                ctx->xv_port = 0;
        } else {
            MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n");
            ctx->xv_port = 0;
        }
    }

    for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) {
        /* check if adaptor number has been specified */
        if (xv_adaptor != -1 && xv_adaptor != i)
            continue;

        if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) {
            for (xv_p = ctx->ai[i].base_id;
                 xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p)
                if (!XvGrabPort(x11->display, xv_p, CurrentTime)) {
                    ctx->xv_port = xv_p;
                    MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n",
                               i, ctx->ai[i].name);
                    break;
                } else {
                    MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p);
                    ++busy_ports;
                }
        }
    }
    if (!ctx->xv_port) {
        if (busy_ports)
            MP_ERR(vo, "Xvideo ports busy.\n");
        else
            MP_ERR(vo, "No Xvideo support found.\n");
        goto error;
    }

    if (!xv_init_colorkey(vo)) {
        goto error;             // bail out, colorkey setup failed
    }
    xv_enable_vsync(vo);
    xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height);

    ctx->fo = XvListImageFormats(x11->display, ctx->xv_port,
                                 (int *) &ctx->formats);

    MP_WARN(vo, "Warning: this legacy VO has bad quality and performance, "
                "and will in particular result in blurry OSD and subtitles. "
                "You should fix your graphic drivers, or not force the xv VO.\n");
    return 0;

  error:
    uninit(vo);                 // free resources
    return -1;
}
コード例 #8
0
ファイル: renderxv.c プロジェクト: martinpiper/VICE
int find_yuv_port(Display* display, XvPortID* port, fourcc_t* format)
{
  int i, j, k;

  /* XvQueryExtension */
  unsigned int version, release, request_base, event_base, error_base;

  /* XvQueryAdaptors */
  unsigned int num_adaptors;
  XvAdaptorInfo* adaptor_info = NULL;
  XvPortID port_id;

  /* XvListImageFormats */
  int num_formats;
  XvImageFormatValues* format_list = NULL;

  switch (XvQueryExtension(display, &version, &release,
			   &request_base, &event_base, &error_base))
  {
  case Success:
    break;
  case XvBadExtension:
    printf("XvQueryExtension returned XvBadExtension.\n");
    return 0;
  case XvBadAlloc:
    printf("XvQueryExtension returned XvBadAlloc.\n");
    return 0;
  default:
    printf("XvQueryExtension returned unknown error.\n");
    return 0;
  }

  switch (XvQueryAdaptors(display, DefaultRootWindow(display),
			  &num_adaptors, &adaptor_info))
  {
  case Success:
    break;
  case XvBadExtension:
    printf("XvQueryAdaptors returned XvBadExtension.\n");
    return 0;
  case XvBadAlloc:
    printf("XvQueryAdaptors returned XvBadAlloc.\n");
    return 0;
  default:
    printf("XvQueryAdaptors returned unknown error.\n");
    return 0;
  }

  /* Find YUV capable adaptor. */
  for (i = 0; i < (int)num_adaptors; i++) {
    if (!(adaptor_info[i].type & XvInputMask
	  && adaptor_info[i].type & XvImageMask))
    {
      continue;
    }

    format_list = XvListImageFormats(display, adaptor_info[i].base_id,
				     &num_formats);

    for (j = 0; j < (int)(sizeof(fourcc_list) / sizeof(*fourcc_list)); j++) {
      if (format->id && fourcc_list[j].id != format->id) {
	continue;
      }
      for (k = 0; k < num_formats; k++) {
	if (format_list[k].id != fourcc_list[j].id) {
	  continue;
	}

	for (port_id = adaptor_info[i].base_id;
	     port_id < adaptor_info[i].base_id + adaptor_info[i].num_ports;
	     port_id++)
	  {
	    if (XvGrabPort(display, port_id, CurrentTime) != Success) {
	      continue;
	    }
	    *port = port_id;
	    *format = fourcc_list[j];
	    XFree(format_list);
	    XvFreeAdaptorInfo(adaptor_info);
	    return 1;
	  }
      }
    }

    XFree(format_list);
  }

  XvFreeAdaptorInfo(adaptor_info);
  printf("No suitable Xv YUV adaptor/port available.\n");
  return 0;
}
コード例 #9
0
ファイル: x11output.c プロジェクト: ChristianFrisson/gephex
static int find_best_xv_port(Display* dpy, Window win, XvPortID* xv_port,
                             char* error_text, int text_len)
{
  unsigned int num_adaptors;
  XvAdaptorInfo* adaptors;
  int ret;
  unsigned int i;

  DEBUG_PRINTF("Looking for port...\n");

  ret = XvQueryAdaptors(dpy, win, &num_adaptors, &adaptors);

  switch (ret)
    {
    case Success:
      break;
    case XvBadExtension: 
      snprintf(error_text, text_len,
               "Xv Extension not available for this display");
      return 0;
    case XvBadAlloc:
      snprintf(error_text, text_len,
               "XvQueryAdaptors could not allocate memory");
      return 0;
    default:
      snprintf(error_text, text_len,
               "XvQueryAdaptors: unknown error");
      return 0;
    }

  if (num_adaptors == 0)
    {
      snprintf(error_text, text_len, "No adaptors found");
      XvFreeAdaptorInfo(adaptors);
      return 0;
    }

  // grab first free port (TODO)
  for (i = 0; i < num_adaptors; ++i)
    {
      XvAdaptorInfo* ai = adaptors +i;

      DEBUG_PRINTF(" <><> Adaptor #%i (%s):\n", i, ai->name);
      if (ai->type & XvInputMask)
        DEBUG_PRINTF("    - input\n");
      if (ai->type & XvOutputMask)
        DEBUG_PRINTF("    - output\n");
      if (ai->type & XvImageMask)
        DEBUG_PRINTF("    - image\n");
      if (ai->type & XvStillMask)
        DEBUG_PRINTF("    - still\n");
      if (ai->type & XvVideoMask)
        DEBUG_PRINTF("    - video\n");

      if ((ai->type & XvInputMask) && (ai->type & XvImageMask))
        {
          XvPortID base_port = ai->base_id;
          XvPortID port;
          int num_ports = ai->num_ports;

          for (port = base_port; 
               port < base_port + num_ports; ++port)
            {
              int ret = XvGrabPort(dpy, port, CurrentTime);
              if (ret == Success)
                {
                  *xv_port = port;
                  DEBUG_PRINTF("Xv: got port %i\n", (int)port);
                  XvFreeAdaptorInfo(adaptors);
                  return 1;
                } 
              else
                {
                  DEBUG_PRINTF("Xv: could not grab port %i\n", (int)port);
                }
            }
        }
    }
  snprintf(error_text, text_len, "Could not find free port");

  XvFreeAdaptorInfo(adaptors);
  return 0;
}
コード例 #10
0
ファイル: xvoutput.c プロジェクト: Mikachu/tvtime
static int xv_check_extension( void )
{
    unsigned int version;
    unsigned int release;
    unsigned int dummy;
    unsigned int adaptors;
    unsigned int i;
    unsigned long j;
    int has_yuy2 = 0;
    XvAdaptorInfo *adaptorInfo;

    if( ( XvQueryExtension( display, &version, &release,
                            &dummy, &dummy, &dummy) != Success ) ||
         ( version < 2 ) || ( ( version == 2 ) && ( release < 2 ) ) ) {

        fprintf( stderr, "xvoutput: XVIDEO extension not found: X too old? didn't load extmod?\n" );
        return 0;
    }

    XvQueryAdaptors( display, output_window, &adaptors, &adaptorInfo );

    for( i = 0; i < adaptors; i++ ) {
        if( adaptorInfo[ i ].type & XvImageMask ) {
            for( j = 0; j < adaptorInfo[ i ].num_ports; j++ ) {
                if( xv_port_has_yuy2( adaptorInfo[ i ].base_id + j ) ) {
                    if( XvGrabPort( display, adaptorInfo[ i ].base_id + j, 0 ) == Success ) {
                        xv_port = adaptorInfo[ i ].base_id + j;
                        if( xvoutput_verbose ) {
                            fprintf( stderr, "xvoutput: Using XVIDEO adaptor %lu: %s.\n",
                                     adaptorInfo[ i ].base_id + j, adaptorInfo[ i ].name );
                        }
                        XvFreeAdaptorInfo( adaptorInfo );
                        return 1;
                    }
                    has_yuy2 = 1;
                }
            }
        }
    }

    XvFreeAdaptorInfo( adaptorInfo );

    if( has_yuy2 ) {
        fprintf( stderr, "xvoutput: No YUY2 XVIDEO port available.\n" );

        fprintf( stderr, "\n*** tvtime requires a hardware YUY2 overlay.  One is supported\n"
                           "*** by your driver, but we could not grab it.  It is likely\n"
                           "*** being used by another application, either another tvtime\n"
                           "*** instance or a media player.  Please shut down this other\n"
                           "*** application and try tvtime again.\n\n" );
    } else {
        fprintf( stderr, "xvoutput: No XVIDEO port found which supports YUY2 images.\n" );

        fprintf( stderr, "\n*** tvtime requires hardware YUY2 overlay support from your video card\n"
                           "*** driver.  If you are using an older NVIDIA card (TNT2), then\n"
                           "*** this capability is only available with their binary drivers.\n"
                           "*** For some ATI cards, this feature may be found in the experimental\n"
                           "*** GATOS drivers: http://gatos.sourceforge.net/\n"
                           "*** If unsure, please check with your distribution to see if your\n"
                           "*** X driver supports hardware overlay surfaces.\n\n" );
    }
    return 0;
}
コード例 #11
0
ファイル: xvwindow.cpp プロジェクト: NeoWing/ekiga-3.2.7
unsigned int 
XVWindow::FindXVPort () 
{
  XvAdaptorInfo *xvainfo = NULL;
  XvImageFormatValues *xviformats = NULL;

  unsigned int numXvainfo = 0;
  unsigned int i = 0;
  unsigned int candidateXVPort = 0;
  unsigned int busyPorts = 0;

  int numXviformats = 0;
  int j = 0;

  int result = 0;
  bool supportsYV12 = false;

  if (Success != XvQueryAdaptors (_display, _rootWindow, &numXvainfo, &xvainfo)) {
    PTRACE (1, "XVideo\tXQueryAdaptor failed");
    return 0;
  }

  for (i = 0; i < numXvainfo; i++) {

    char adaptorInfo [512];
    sprintf (adaptorInfo, "XVideo\t#%d, Adaptor: %s, type: %s%s%s%s%s, ports: %ld, first port:�%ld", i,
             xvainfo[i].name,
             (xvainfo[i].type & XvInputMask)?"input | ":"",
             (xvainfo[i].type & XvOutputMask)?"output | ":"",
             (xvainfo[i].type & XvVideoMask)?"video | ":"",
             (xvainfo[i].type & XvStillMask)?"still | ":"",
             (xvainfo[i].type & XvImageMask)?"image | ":"",
             xvainfo[i].num_ports,
             xvainfo[i].base_id);
    PTRACE (4, adaptorInfo);

    if ((xvainfo[i].type & XvInputMask) && (xvainfo[i].type & XvImageMask)) {

      for (candidateXVPort = xvainfo [i].base_id ; candidateXVPort < (xvainfo [i].base_id + xvainfo [i].num_ports) ; ++candidateXVPort) {

        if (grabbedPorts.find(candidateXVPort) != grabbedPorts.end()) {
          PTRACE(4, "XVideo\tPort " << candidateXVPort << " already grabbed by ourselves");
          ++busyPorts;
          continue;
        }

#if PTRACING
        DumpCapabilities (candidateXVPort);
#endif

        // Check if the Port supports YV12/YUV colorspace
        supportsYV12 = false;
        xviformats = XvListImageFormats (_display, candidateXVPort, &numXviformats);

        for (j = 0 ; j < numXviformats ; j++)
          if (xviformats [j].id == GUID_YV12_PLANAR)
            supportsYV12 = true;

        if (xviformats)
          XFree (xviformats);

        if (!supportsYV12) {

          PTRACE(4, "XVideo\tPort " << candidateXVPort << " does not support YV12 colorspace");
        }
        else {

          result = XvGrabPort (_display, candidateXVPort, CurrentTime);
          if ( result == Success) {

            PTRACE(4, "XVideo\tGrabbed Port: " << candidateXVPort);
            XvFreeAdaptorInfo (xvainfo);
            grabbedPorts.insert(candidateXVPort);

            return candidateXVPort;
          } 
          else {

            switch (result) 
              {
              case XvInvalidTime: 
                PTRACE (4, "XVideo\tCould not grab port " << candidateXVPort << ": requested time is older than the current port time"); 
                break;

              case XvAlreadyGrabbed: 
                PTRACE (4, "XVideo\tCould not grab port " << candidateXVPort << ": port is already grabbed by another client"); 
                break;

              case XvBadExtension: 
                PTRACE (4, "XVideo\tCould not grab port " << candidateXVPort << ": XV extension is unavailable"); 
                break;

              case XvBadAlloc: 
                PTRACE (4, "XVideo\tCould not grab port " << candidateXVPort << ": XvGrabPort failed to allocate memory to process the request"); 
                break;

              case XvBadPort: 
                PTRACE(4, "XVideo\tCould not grab port " << candidateXVPort << ": port does not exist"); 
                break;

              default: 
                PTRACE(4, "XVideo\tCould not grab port " << candidateXVPort);
              }

            ++busyPorts;
          }
        }
      }
    }
  }

  if (busyPorts) 
    PTRACE(1, "XVideo\tCould not find any free Xvideo port - maybe other processes are already using them");
  else 
    PTRACE(1, "XVideo\tIt seems there is no Xvideo support for your video card available");
  XvFreeAdaptorInfo (xvainfo);

  return 0;
}
コード例 #12
0
ファイル: vo_xv.c プロジェクト: kax4/mpv
static int preinit(struct vo *vo, const char *arg)
{
    XvPortID xv_p;
    int busy_ports = 0;
    unsigned int i;
    strarg_t ck_src_arg = { 0, NULL };
    strarg_t ck_method_arg = { 0, NULL };
    struct xvctx *ctx = talloc_zero(vo, struct xvctx);
    vo->priv = ctx;
    int xv_adaptor = -1;

    if (!vo_init(vo))
        return -1;

    struct vo_x11_state *x11 = vo->x11;

    const opt_t subopts[] =
    {
      /* name         arg type     arg var         test */
      {  "port",      OPT_ARG_INT, &x11->xv_port,  int_pos },
      {  "adaptor",   OPT_ARG_INT, &xv_adaptor,    int_non_neg },
      {  "ck",        OPT_ARG_STR, &ck_src_arg,    xv_test_ck },
      {  "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
      {  NULL }
    };

    x11->xv_port = 0;

    /* parse suboptions */
    if (subopt_parse(arg, subopts) != 0) {
        return -1;
    }

    /* modify colorkey settings according to the given options */
    xv_setup_colorkeyhandling(vo, ck_method_arg.str, ck_src_arg.str);

    /* check for Xvideo extension */
    unsigned int ver, rel, req, ev, err;
    if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) {
        mp_tmsg(MSGT_VO, MSGL_ERR, "[VO_XV] Sorry, Xv not supported by this X11 version/driver\n[VO_XV] ******** Try with  -vo x11 *********\n");
        goto error;
    }

    /* check for Xvideo support */
    if (Success !=
        XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display),
                        &ctx->adaptors, &ctx->ai)) {
        mp_tmsg(MSGT_VO, MSGL_ERR, "[VO_XV] XvQueryAdaptors failed.\n");
        goto error;
    }

    /* check adaptors */
    if (x11->xv_port) {
        int port_found;

        for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) {
            if ((ctx->ai[i].type & XvInputMask)
                && (ctx->ai[i].type & XvImageMask)) {
                for (xv_p = ctx->ai[i].base_id;
                     xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports;
                     ++xv_p) {
                    if (xv_p == x11->xv_port) {
                        port_found = 1;
                        break;
                    }
                }
            }
        }
        if (port_found) {
            if (XvGrabPort(x11->display, x11->xv_port, CurrentTime))
                x11->xv_port = 0;
        } else {
            mp_tmsg(MSGT_VO, MSGL_WARN, "[VO_XV] Invalid port parameter, overriding with port 0.\n");
            x11->xv_port = 0;
        }
    }

    for (i = 0; i < ctx->adaptors && x11->xv_port == 0; i++) {
        /* check if adaptor number has been specified */
        if (xv_adaptor != -1 && xv_adaptor != i)
            continue;

        if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) {
            for (xv_p = ctx->ai[i].base_id;
                 xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p)
                if (!XvGrabPort(x11->display, xv_p, CurrentTime)) {
                    x11->xv_port = xv_p;
                    mp_msg(MSGT_VO, MSGL_V,
                           "[VO_XV] Using Xv Adapter #%d (%s)\n",
                           i, ctx->ai[i].name);
                    break;
                } else {
                    mp_tmsg(MSGT_VO, MSGL_WARN, "[VO_XV] Could not grab port %i.\n",
                           (int) xv_p);
                    ++busy_ports;
                }
        }
    }
    if (!x11->xv_port) {
        if (busy_ports)
            mp_tmsg(MSGT_VO, MSGL_ERR,
                "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\
                "[VO_XV] using it. Close all video applications, and try again. If that does\n"\
                "[VO_XV] not help, see 'mpv -vo help' for other (non-xv) video out drivers.\n");
        else
            mp_tmsg(MSGT_VO, MSGL_ERR,
                "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\
                "[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\
                "[VO_XV] DOCS/HTML/en/video.html#xv!\n"\
                "[VO_XV] See 'mpv -vo help' for other (non-xv) video out drivers.\n"\
                "[VO_XV] Try -vo x11.\n");
        goto error;
    }

    if (!vo_xv_init_colorkey(vo)) {
        goto error;             // bail out, colorkey setup failed
    }
    vo_xv_enable_vsync(vo);
    vo_xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height);

    ctx->fo = XvListImageFormats(x11->display, x11->xv_port,
                                 (int *) &ctx->formats);

    ctx->osd_backup = talloc_steal(ctx, mp_draw_sub_backup_new());

    return 0;

  error:
    uninit(vo);                 // free resources
    return -1;
}
コード例 #13
0
ファイル: vo_xv.c プロジェクト: SibghatullahSheikh/mpv
static int preinit(struct vo *vo)
{
    XvPortID xv_p;
    int busy_ports = 0;
    unsigned int i;
    struct xvctx *ctx = vo->priv;
    int xv_adaptor = ctx->cfg_xv_adaptor;

    if (!vo_x11_init(vo))
        return -1;

    struct vo_x11_state *x11 = vo->x11;

    /* check for Xvideo extension */
    unsigned int ver, rel, req, ev, err;
    if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) {
        MP_ERR(vo, "Xv not supported by this X11 version/driver\n");
        goto error;
    }

    /* check for Xvideo support */
    if (Success !=
        XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display),
                        &ctx->adaptors, &ctx->ai)) {
        MP_ERR(vo, "XvQueryAdaptors failed.\n");
        goto error;
    }

    /* check adaptors */
    if (ctx->xv_port) {
        int port_found;

        for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) {
            if ((ctx->ai[i].type & XvInputMask)
                && (ctx->ai[i].type & XvImageMask)) {
                for (xv_p = ctx->ai[i].base_id;
                     xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports;
                     ++xv_p) {
                    if (xv_p == ctx->xv_port) {
                        port_found = 1;
                        break;
                    }
                }
            }
        }
        if (port_found) {
            if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime))
                ctx->xv_port = 0;
        } else {
            MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n");
            ctx->xv_port = 0;
        }
    }

    for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) {
        /* check if adaptor number has been specified */
        if (xv_adaptor != -1 && xv_adaptor != i)
            continue;

        if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) {
            for (xv_p = ctx->ai[i].base_id;
                 xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p)
                if (!XvGrabPort(x11->display, xv_p, CurrentTime)) {
                    ctx->xv_port = xv_p;
                    MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n",
                               i, ctx->ai[i].name);
                    break;
                } else {
                    MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p);
                    ++busy_ports;
                }
        }
    }
    if (!ctx->xv_port) {
        if (busy_ports)
            MP_ERR(vo,
                   "Could not find free Xvideo port - maybe another process is already\n"\
                   "using it. Close all video applications, and try again. If that does\n"\
                   "not help, see 'mpv -vo help' for other (non-xv) video out drivers.\n");
        else
            MP_ERR(vo,
                   "It seems there is no Xvideo support for your video card available.\n"\
                   "Run 'xvinfo' to verify its Xv support and read\n"\
                   "DOCS/HTML/en/video.html#xv!\n"\
                   "See 'mpv -vo help' for other (non-xv) video out drivers.\n"\
                   "Try -vo x11.\n");
        goto error;
    }

    if (!xv_init_colorkey(vo)) {
        goto error;             // bail out, colorkey setup failed
    }
    xv_enable_vsync(vo);
    xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height);

    ctx->fo = XvListImageFormats(x11->display, ctx->xv_port,
                                 (int *) &ctx->formats);

    return 0;

  error:
    uninit(vo);                 // free resources
    return -1;
}
コード例 #14
0
ファイル: xv.c プロジェクト: gabrielduque/unicap-1
int xv_init( xv_handle_t handle, Display *dpy, __u32 fourcc, int width, int height, int bpp )
{
	unsigned int version, release;
	unsigned int request_base, event_base, error_base;
	
	int i;

	if( XvQueryExtension( dpy, &version, &release, &request_base, &event_base, &error_base ) != Success )
	{
#ifdef DEBUG
		fprintf( stderr, "XvQueryExtension failed\n" );
#endif
		return -1;
	}
	
	if( XvQueryAdaptors( dpy, DefaultRootWindow( dpy ), &handle->num_adaptors, &handle->p_adaptor_info ) != Success )
	{
#ifdef DEBUG
		fprintf( stderr, "XvQueryAdaptors failed\n" );
#endif
		return -1;
	}

/* 	printf( "%d adaptors found\n", handle->num_adaptors ); */
	
	if( handle->num_adaptors == 0 )
	{
		return -2;
	}
	

	for( i = 0; i < handle->num_adaptors; i++ )
	{
/* 		int format; */
		unsigned int num_encodings;
		XvEncodingInfo *p_encoding_info;
		int encoding;

		XvAttribute *at;
		unsigned int num_attributes;
		int attribute;

		XvImageFormatValues *xvimage_formats;
		unsigned int num_xvimage_formats;
		int format;
		

#ifdef DEBUG
		printf( "Adaptor: %d\n", i );
		printf( "Name: %s\n", handle->p_adaptor_info[i].name );
		printf( "Ports: %lu\n", handle->p_adaptor_info[i].num_ports );
		printf( "Formats: %lu\n", handle->p_adaptor_info[i].num_formats );
		
		for( format = 0; format < handle->p_adaptor_info[i].num_formats; format++ )
		{
			printf( "+Format: %d\n", format );
			printf( " +Depth: %d\n", handle->p_adaptor_info[i].formats[format].depth );
			printf( " +VisualID: %lu\n", handle->p_adaptor_info[i].formats[format].visual_id );
		}

			
		if( XvQueryEncodings( dpy, handle->p_adaptor_info[i].base_id, &num_encodings, &p_encoding_info ) != Success )
		{
			fprintf( stderr, "XvQueryEncodings failed\n" );
		}
		printf( " +num_encodings: %d\n", num_encodings );
		
		for( encoding = 0; encoding < num_encodings; encoding++ )
		{
			printf( "  +Encoding: %d\n", encoding );
			printf( "  +Name: %s\n", p_encoding_info[encoding].name );
			printf( "  +Resolution: %lu x %lu\n", 
					p_encoding_info[encoding].width, 
					p_encoding_info[encoding].height );
		}
#endif //DEBUG

		at = XvQueryPortAttributes( dpy, handle->p_adaptor_info[i].base_id, &num_attributes );
#ifdef DEBUG
		printf( "num_attributes: %d\n", num_attributes );
#endif
		for( attribute = 0; attribute < num_attributes; attribute++ )
		{
			int val;
			Atom atom;
			
			if( !strcmp( at[attribute].name, "XV_COLORKEY" ) )
			{
#ifdef DEBUG
				printf( "attribute: %d\n", attribute );
				printf( "name: %s\n", at[attribute].name );
#endif
				atom = (Atom)XInternAtom( dpy, at[attribute].name, 0 );
#ifdef DEBUG
				printf( "atom: %p\n", atom );
#endif
				XvGetPortAttribute( dpy, 
									handle->p_adaptor_info[i].base_id, 
									atom, 
									&val );
#ifdef DEBUG
				printf( "Attribute: %d\n", attribute );
				printf( "Name: %s\n", at[attribute].name );
				printf( "min: %x\n", at[attribute].min_value );
				printf( "max: %x\n", at[attribute].max_value );
				printf( "value: %x\n", val );
#endif
				handle->atom_colorkey = XInternAtom( dpy, at[attribute].name, 0 );
			}
			if( !strcmp( at[attribute].name, "XV_BRIGHTNESS" ) )
			{
				handle->atom_brightness = XInternAtom( dpy, at[attribute].name, 0 );
				handle->brightness_min = at[attribute].min_value;
				handle->brightness_max = at[attribute].max_value;
			}
			if( !strcmp( at[attribute].name, "XV_HUE" ) )
			{
				handle->atom_hue = XInternAtom( dpy, at[attribute].name, 0 );
				handle->hue_min = at[attribute].min_value;
				handle->hue_max = at[attribute].max_value;
			}
			if( !strcmp( at[attribute].name, "XV_CONTRAST" ) )
			{
				handle->atom_contrast = XInternAtom( dpy, at[attribute].name, 0 );
				handle->contrast_min = at[attribute].min_value;
				handle->contrast_max = at[attribute].max_value;
			}
			if( !strcmp( at[attribute].name, "XV_DOUBLE_BUFFER" ) )
			{
				Atom _atom;
				_atom = XInternAtom( dpy, at[attribute].name, 0 );
				XvSetPortAttribute( dpy, handle->p_adaptor_info[i].base_id, _atom, 1 );
#ifdef DEBUG
				printf( "Xv: DOUBLE_BUFFER available\n" );
#endif
			}	
		}

		xvimage_formats = XvListImageFormats( dpy, handle->p_adaptor_info[i].base_id, &num_xvimage_formats );
/* 		printf( "num_xvimage_formats: %d\n", num_xvimage_formats ); */
		for( format = 0; format < num_xvimage_formats; format++ )
		{
			char imageName[5] = {0, 0, 0, 0, 0};
			memcpy(imageName, &(xvimage_formats[format].id), 4);
#ifdef DEBUG
			fprintf(stdout, "      id: 0x%x", xvimage_formats[format].id);
#endif
			if( isprint( imageName[0]) && isprint(imageName[1]) &&
			    isprint( imageName[2]) && isprint(imageName[3])) 
			{
#ifdef DEBUG
				fprintf(stdout, " (%s)\n", imageName);
#endif
				if( xvimage_formats[format].id == fourcc )
				{
					handle->xv_mode_id = fourcc;
					break;
				}
			} else {
#ifdef DEBUG
				fprintf(stdout, "\n");
#endif
			}
		}

		if( handle->xv_mode_id != fourcc )
		{
			return -3;
		}

		if( XvGrabPort( dpy, handle->p_adaptor_info[i].base_id, CurrentTime ) != Success )
		{
/* 			fprintf( stderr, "Failed to grab port!\n" ); */
			return -1;
		}
	}

	handle->use_shm = 1;

	if( handle->use_shm )
	{
		memset( &handle->shminfo, 0, sizeof( XShmSegmentInfo ) );
		handle->image = XvShmCreateImage( dpy, 
						  handle->p_adaptor_info[0].base_id, 
						  handle->xv_mode_id, 
						  (char*)NULL, 
						  width,
						  height, 
						  &handle->shminfo );

		if( handle->image )
		{
			handle->shminfo.shmid = shmget( IPC_PRIVATE, handle->image->data_size, IPC_CREAT | 0777 );
			if( handle->shminfo.shmid == -1 )
			{
/* 				fprintf( stderr, "shmget failed\n" ); */
				return -1;
			}
			handle->shminfo.shmaddr = handle->image->data = shmat( handle->shminfo.shmid, 0, 0 );
			shmctl(handle->shminfo.shmid, IPC_RMID, 0);
			/* destroy when we terminate, now if shmat failed */

			if( handle->shminfo.shmaddr == ( void * ) -1 )
			{
/* 				fprintf( stderr, "shmat failed\n" ); */
				return -1;
			}
			
			handle->shminfo.readOnly = False;
			if( !XShmAttach( dpy, &handle->shminfo ) )
			{
/* 				fprintf( stderr, "XShmAttach failed\n" ); */
				shmdt( handle->shminfo.shmaddr );
				XFree( handle->image );
				return -1;
			}
		}
		else
		{
/* 			fprintf( stderr, "XvShmCreateImage failed\n" ); */
			return -1;
		}
	}
	else
	{
		char * data = (char*) malloc( width*height*(bpp/8));
		handle->image = XvCreateImage( dpy, handle->p_adaptor_info[0].base_id, handle->xv_mode_id, data, width, height );
	}	

	handle->display = dpy;

	return 0;
}
コード例 #15
0
bool QX11VideoSurface::findPort()
{
    unsigned int count = 0;
    XvAdaptorInfo *adaptors = 0;
    bool portFound = false;

    if (XvQueryAdaptors(QX11Info::display(), m_winId, &count, &adaptors) == Success) {
#ifdef Q_WS_MAEMO_5
            //the overlay xvideo adapter fails to switch winId,
            //prefer the "SGX Textured Video" adapter instead
        for (int i = count-1; i >= 0 && !portFound; --i) {
#else
        for (unsigned int i = 0; i < count && !portFound; ++i) {
#endif
            if (adaptors[i].type & XvImageMask) {
                m_portId = adaptors[i].base_id;

                for (unsigned int j = 0; j < adaptors[i].num_ports && !portFound; ++j, ++m_portId)
                    portFound = XvGrabPort(QX11Info::display(), m_portId, 0) == Success;
            }
        }
        XvFreeAdaptorInfo(adaptors);
    }

    return portFound;
}

void QX11VideoSurface::querySupportedFormats()
{
    int count = 0;
    if (XvImageFormatValues *imageFormats = XvListImageFormats(
            QX11Info::display(), m_portId, &count)) {
        const int rgbCount = sizeof(qt_xvRgbLookup) / sizeof(XvFormatRgb);
        const int yuvCount = sizeof(qt_xvYuvLookup) / sizeof(XvFormatYuv);

        for (int i = 0; i < count; ++i) {
            switch (imageFormats[i].type) {
            case XvRGB:
                for (int j = 0; j < rgbCount; ++j) {
                    if (imageFormats[i] == qt_xvRgbLookup[j]) {
                        m_supportedPixelFormats.append(qt_xvRgbLookup[j].pixelFormat);
                        m_formatIds.append(imageFormats[i].id);
                        break;
                    }
                }
                break;
            case XvYUV:
                for (int j = 0; j < yuvCount; ++j) {
                    if (imageFormats[i] == qt_xvYuvLookup[j]) {
                        m_supportedPixelFormats.append(qt_xvYuvLookup[j].pixelFormat);
                        m_formatIds.append(imageFormats[i].id);
                        break;
                    }
                }
                break;
            }
        }
        XFree(imageFormats);
    }

    m_brightnessRange = qMakePair(0, 0);
    m_contrastRange = qMakePair(0, 0);
    m_hueRange = qMakePair(0, 0);
    m_saturationRange = qMakePair(0, 0);

    if (XvAttribute *attributes = XvQueryPortAttributes(QX11Info::display(), m_portId, &count)) {
        for (int i = 0; i < count; ++i) {
            if (qstrcmp(attributes[i].name, "XV_BRIGHTNESS") == 0)
                m_brightnessRange = qMakePair(attributes[i].min_value, attributes[i].max_value);
            else if (qstrcmp(attributes[i].name, "XV_CONTRAST") == 0)
                m_contrastRange = qMakePair(attributes[i].min_value, attributes[i].max_value);
            else if (qstrcmp(attributes[i].name, "XV_HUE") == 0)
                m_hueRange = qMakePair(attributes[i].min_value, attributes[i].max_value);
            else if (qstrcmp(attributes[i].name, "XV_SATURATION") == 0)
                m_saturationRange = qMakePair(attributes[i].min_value, attributes[i].max_value);
        }

        XFree(attributes);
    }
}
コード例 #16
0
//------------------------------------
//
//------------------------------------
uint8_t GUI_XvInit(GUI_WindowInfo * window, uint32_t w, uint32_t h)
{


    unsigned int ver, rel, req, ev, err;
    unsigned int port, adaptors;
    static XvAdaptorInfo *ai;
    static XvAdaptorInfo *curai;
    
#if 0
    win = gtk_widget_get_parent_window(window);
    xv_display = GDK_WINDOW_XDISPLAY(win);
//      xv_win= RootWindow(xv_display,0);
    xv_win = GDK_WINDOW_XWINDOW(GTK_WIDGET(window)->window);
#endif    

    xv_display=(Display *)window->display;
    xv_win=window->window;
    
    
#define WDN xv_display
    xv_port = 0;

    if (Success != XvQueryExtension(WDN, &ver, &rel, &req, &ev, &err))
      {
	  printf("\n Query Extension failed\n");
	  goto failed;
      }
    /* check for Xvideo support */
    if (Success != XvQueryAdaptors(WDN,
				   DefaultRootWindow(WDN), &adaptors, &ai))
      {
	  printf("\n Query Adaptor failed\n");
	  goto failed;
      }
    curai = ai;
    XvFormat *formats;
    // Dump infos
    port = 0;
    for (uint16_t i = 0; (!port) && (i < adaptors); i++)
      {
/*
XvPortID base_id;
unsigned long num_ports;
char type;
char *name;
unsigned long num_formats;
XvFormat *formats;
unsigned long num_adaptors;
*/
#ifdef VERBOSE_XV
	  printf("\n_______________________________\n");
	  printf("\n Adaptor 		: %d", i);
	  printf("\n Base ID		: %ld", curai->base_id);
	  printf("\n Nb Port	 	: %lu", curai->num_ports);
	  printf("\n Type			 	: %d,",
		 curai->type);
#define CHECK(x) if(curai->type & x) printf("|"#x);
	  CHECK(XvInputMask);
	  CHECK(XvOutputMask);
	  CHECK(XvVideoMask);
	  CHECK(XvStillMask);
	  CHECK(XvImageMask);

	  printf("\n Name			 	: %s",
		 curai->name);
	  printf("\n Num Adap	 	: %lu", curai->num_adaptors);
	  printf("\n Num fmt	 	: %lu", curai->num_formats);
#endif	  
	  formats = curai->formats;

	  //
	  uint16_t k;

	  for (k = 0; (k < curai->num_ports) && !port; k++)
	    {
		if (GUI_XvList(WDN, k + curai->base_id, &xv_format))
		    port = k + curai->base_id;
	    }


	  curai++;
      }
    //
    if (!port)
      {
	  printf("\n no port found");
	  goto failed;
      }
#ifdef 	COLORSPACE_YV12
    printf("\n Xv YV12 found at port :%d, format : %ld", port, xv_format);
#else
    printf("\n Xv YUY2 found at port :%d, format : %ld", port, xv_format);
#endif

    if (Success != XvGrabPort(WDN, port, 0))
	goto failed;
    {
	
	xv_port = port;
/*
   Display *display,
   XvPortID port,
   int id,
   char* data,
   int width,
   int height,
   XShmSegmentInfo *shminfo

*/
        
        XSetWindowAttributes xswa;
        XWindowAttributes attribs;
        static Atom xv_atom;
        unsigned long xswamask;
        int erCode;

        /* check if colorkeying is needed */
        xv_atom = getAtom( "XV_AUTOPAINT_COLORKEY" );
        if(xv_atom!=None)
        {
                XvSetPortAttribute( xv_display, xv_port, xv_atom, 1 );
        }
        else printf("No autopaint \n");

        /* if we have to deal with colorkeying ... */
        
	xvimage = XvShmCreateImage(WDN, xv_port,
				   xv_format, 0, w, h, &Shminfo);

	Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size,
			       IPC_CREAT | 0777);
        if(Shminfo.shmid<=0)
        {
                printf("shmget failed\n");
        }
	Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0);
	Shminfo.readOnly = False;
        if(Shminfo.shmaddr==(char *)-1)
        {
                printf("Shmat failed\n");
        }
	xvimage->data = Shminfo.shmaddr;
	XShmAttach(WDN, &Shminfo);
	XSync(WDN, False);
	erCode=shmctl(Shminfo.shmid, IPC_RMID, 0);
        if(erCode)
        {
                printf("Shmctl failed :%d\n",erCode);
        }
	memset(xvimage->data, 0, xvimage->data_size);

	xv_xgc.graphics_exposures = False;

	xv_gc = XCreateGC(xv_display, xv_win, 0L, &xv_xgc);
	
	//ADM_assert(BadWindow!=XSelectInput(xv_display, xv_win, ExposureMask | VisibilityChangeMask));

    }
    printf("\n Xv init succeedeed\n");

    return 1;
  failed:
    printf("\n Xv init failed..\n");
    return 0;
}
コード例 #17
0
ファイル: renderxv.c プロジェクト: AreaScout/vice
int find_yuv_port(Display* display, XvPortID* port, fourcc_t* format, int *overlay)
{
    int i, j, k, found_one = 0, is_overlay;

    /* XvQueryExtension */
    unsigned int version, release, request_base, event_base, error_base;

    /* XvQueryAdaptors */
    unsigned int num_adaptors;
    XvAdaptorInfo* adaptor_info = NULL;
    XvPortID port_id;

    /* XvListImageFormats */
    int num_formats;
    XvImageFormatValues* format_list = NULL;

    switch (XvQueryExtension(display, &version, &release, &request_base, &event_base, &error_base)) {
        case Success:
            break;
        case XvBadExtension:
            printf("XvQueryExtension returned XvBadExtension.\n");
            return 0;
        case XvBadAlloc:
            printf("XvQueryExtension returned XvBadAlloc.\n");
            return 0;
        default:
            printf("XvQueryExtension returned unknown error.\n");
            return 0;
    }

    switch (XvQueryAdaptors(display, DefaultRootWindow(display), &num_adaptors, &adaptor_info)) {
        case Success:
            break;
        case XvBadExtension:
            printf("XvQueryAdaptors returned XvBadExtension.\n");
            return 0;
        case XvBadAlloc:
            printf("XvQueryAdaptors returned XvBadAlloc.\n");
            return 0;
        default:
            printf("XvQueryAdaptors returned unknown error.\n");
            return 0;
    }

    /* Find YUV capable adaptor. */
    for (i = 0; i < (int)num_adaptors; i++) {
        if (!(adaptor_info[i].type & XvInputMask && adaptor_info[i].type & XvImageMask)) {
            continue;
        }
        /* Textured video is not an overlay */
        is_overlay = !strstr(adaptor_info[i].name, "Textured");

        format_list = XvListImageFormats(display, adaptor_info[i].base_id, &num_formats);

        for (j = 0; j < (int)(sizeof(fourcc_list) / sizeof(*fourcc_list)); j++) {
            if (format->id && fourcc_list[j].id != format->id) {
                continue;
            }
            for (k = 0; k < num_formats; k++) {
                if (format_list[k].id != fourcc_list[j].id) {
                    continue;
                }

                for (port_id = adaptor_info[i].base_id; port_id < adaptor_info[i].base_id + adaptor_info[i].num_ports; port_id++) {
                    if (XvGrabPort(display, port_id, CurrentTime) != Success) {
                        continue;
                    }
                    if (found_one) {
                        if (!*overlay && is_overlay) {
                            XvUngrabPort(display, port_id, CurrentTime);
                            continue; /* Prefer non-overlay as that one can handle more than one windows */
                        }
                        XvUngrabPort(display, *port, CurrentTime);
                    }
                    *port = port_id;
                    *format = fourcc_list[j];
                    *overlay = is_overlay;
                    found_one = 1;
                }
            }
        }
        XFree(format_list);
    }
    XvFreeAdaptorInfo(adaptor_info);
    if (!found_one) {
        printf("No suitable Xv YUV adaptor/port available.\n");
    }
    return found_one;
}
コード例 #18
0
ファイル: player-av.c プロジェクト: bmravec/GMediaMP
static void
player_av_load (Player *self, Entry *entry)
{
    gint i;
    PlayerAVPrivate *priv = PLAYER_AV (self)->priv;

    player_av_close (self);

    if (av_open_input_file (&priv->fctx, entry_get_location (entry), NULL, 0, NULL) != 0)
        return;

    if (av_find_stream_info (priv->fctx) < 0)
        return;

    priv->fctx->flags = AVFMT_FLAG_GENPTS;

    dump_format(priv->fctx, 0, entry_get_location (entry), 0);

    priv->astream = priv->vstream = -1;
    for (i = 0; i < priv->fctx->nb_streams; i++) {
        if (priv->fctx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
            priv->vstream = i;
        }

        if (priv->fctx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
            priv->astream = i;
        }

        if (priv->vstream != -1 && priv->astream != -1)
            break;
    }

    // Setup Audio Stream
    if (priv->astream != -1) {
        priv->actx = priv->fctx->streams[priv->astream]->codec;
        AVCodec *acodec = avcodec_find_decoder (priv->actx->codec_id);
        if (acodec && avcodec_open (priv->actx, acodec) < 0) {
            g_print ("Error opening audio stream\n");
            return;
        }
    } else {
        priv->actx = NULL;
    }

    // Setup Video Stream
    if (priv->vstream != -1) {
        priv->vctx = priv->fctx->streams[priv->vstream]->codec;
        AVCodec *vcodec = avcodec_find_decoder (priv->vctx->codec_id);
        if(vcodec && avcodec_open (priv->vctx, vcodec) < 0) {
            g_print ("Error opening video stream\n");
            return;
        }
    } else {
        priv->vctx = NULL;
    }

    if (priv->vctx) {
        priv->vctx->get_buffer = player_av_av_get_buffer;
        priv->vctx->release_buffer = player_av_av_release_buffer;

        priv->display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
        priv->root = DefaultRootWindow (priv->display);

        priv->win = GDK_WINDOW_XID (priv->em_da->window);
        XSetWindowBackgroundPixmap (priv->display, priv->win, None);

        int nb_adaptors;
        XvAdaptorInfo *adaptors;
        XvQueryAdaptors (priv->display, priv->root, &nb_adaptors, &adaptors);
        int adaptor_no = 0, j, res;

        priv->xv_port_id = 0;
        for (i = 0; i < nb_adaptors && !priv->xv_port_id; i++) {
            adaptor_no = i;
            for (j = 0; j < adaptors[adaptor_no].num_ports && !priv->xv_port_id; j++) {
                res = XvGrabPort (priv->display, adaptors[adaptor_no].base_id + j, 0);
                if (Success == res) {
                    priv->xv_port_id = adaptors[adaptor_no].base_id + j;
                }
            }
        }

        XvFreeAdaptorInfo (adaptors);

        int nb_formats;
        XvImageFormatValues *formats = XvListImageFormats (priv->display,
            priv->xv_port_id, &nb_formats);

        unsigned int vfmt = avcodec_pix_fmt_to_codec_tag (priv->vctx->pix_fmt);
        for (i = 0; i < nb_formats; i++) {
            if (vfmt == formats[i].id) {
                break;
            }
        }

        enum PixelFormat ofmt = PIX_FMT_NONE;

        priv->vframe = avcodec_alloc_frame ();
        priv->vframe_xv = avcodec_alloc_frame();

        if (i < nb_formats) {
            ofmt = priv->vctx->pix_fmt;
        } else {
            for (i = 0; i < nb_formats; i++) {
                ofmt = avcodec_codec_tag_to_pix_fmt (formats[i].id);
                if (ofmt != PIX_FMT_NONE) {
                    break;
                }
            }
        }

        int num_bytes = avpicture_get_size (ofmt,
            priv->vctx->width + priv->vctx->width % 4, priv->vctx->height);
        priv->vbuffer_xv = (uint8_t*) av_malloc (num_bytes * sizeof (uint8_t));

        avpicture_fill ((AVPicture*) priv->vframe_xv,
            priv->vbuffer_xv, ofmt,
            priv->vctx->width + priv->vctx->width % 4, priv->vctx->height);

        priv->sws_ctx = sws_getContext (
            priv->vctx->width, priv->vctx->height, priv->vctx->pix_fmt,
            priv->vctx->width, priv->vctx->height, ofmt,
            SWS_POINT, NULL, NULL, NULL);

        priv->xvimage = XvCreateImage (
            priv->display, priv->xv_port_id,
            formats[i].id, priv->vbuffer_xv,
            priv->vctx->width, priv->vctx->height);

        XFree (formats);

        priv->xv_gc = XCreateGC (priv->display, priv->win, 0, &priv->values);
    }

    priv->entry = entry;
    g_object_ref (entry);

    priv->vpos = 0;

    priv->start_time = -1;
    priv->stop_time = -1;
}
コード例 #19
0
static void x11video_prepare(MSFilter *f){
	X11Video *s=(X11Video*)f->data;
	unsigned int n;
	unsigned int nadaptors;
	int i;
	XvAdaptorInfo *xai=NULL;
	XvPortID port=-1;
	int imgfmt_id=0;
	XShmSegmentInfo *shminfo=&s->shminfo;
	XWindowAttributes wa = {0};

	if (s->display==NULL) return;
	if (s->window_id==0){
		if(s->auto_window) {
			s->window_id=createX11Window(s);
		}
		if (s->window_id==0) return;
		s->own_window=TRUE;
	}

	/* Make sure X11 window is ready to use*/
	XSync(s->display, False);

	if (s->own_window==FALSE){
		/*we need to register for resize events*/
		XSelectInput(s->display,s->window_id,StructureNotifyMask);
	}
	XGetWindowAttributes(s->display,s->window_id,&wa);
	XClearWindow(s->display,s->window_id);
	ms_message("x11video_prepare(): Window has size %ix%i, received video is %ix%i",wa.width,wa.height,s->vsize.width,s->vsize.height);

	if (wa.width<MS_LAYOUT_MIN_SIZE || wa.height<MS_LAYOUT_MIN_SIZE){
		return;
	}

	s->wsize.width=wa.width;
	s->wsize.height=wa.height;
	s->fbuf.w=s->vsize.width;
	s->fbuf.h=s->vsize.height;

	s->port=-1;
	if (XvQueryExtension(s->display, &n, &n, &n, &n, &n)!=0){
		ms_error("Fail to query xv extension");
		return;
	}

	if (XShmQueryExtension(s->display)==0){
		ms_error("Fail to query xshm extension");
		return;
	}

	if (XvQueryAdaptors(s->display,DefaultRootWindow(s->display),
	                                 &nadaptors, &xai)!=0){
		ms_error("XvQueryAdaptors failed.");
		return;
	}

	for (n=0;n<nadaptors && port==-1;++n){
		XvAdaptorInfo *ai=&xai[n];
		XvImageFormatValues *imgfmt;
		int nimgfmt=0;

		ms_message("Found output adaptor; name=%s num_ports=%i, with %i formats:",
		           ai->name,(int)ai->num_ports,(int)ai->num_formats);
		imgfmt=XvListImageFormats(s->display,ai->base_id,&nimgfmt);
		for(i=0;i<nimgfmt;++i){
			char fcc[5]={0};
			memcpy(fcc,&imgfmt[i].id,4);
			ms_message("type=%s/%s id=%s",
			           imgfmt[i].type == XvYUV ? "YUV" : "RGB",
			            imgfmt[i].format==XvPlanar ? "Planar" : "Packed",fcc);
			if (port==-1 && imgfmt[i].format==XvPlanar && strcasecmp(fcc,"YV12")==0){
				int k;
				/*we found a format interesting to us*/
				for(k=0;k<ai->num_ports;++k){
					if (XvGrabPort(s->display,ai->base_id+k,CurrentTime)==0){
						ms_message("Grabbed port %i",(int)ai->base_id+k);
						port=ai->base_id+k;
						imgfmt_id=imgfmt[i].id;
						break;
					}
				}
			}
		}
		if (imgfmt) XFree(imgfmt);
	}
	XvFreeAdaptorInfo(xai);
	if (port==-1){
		ms_error("Could not find suitable format or Xv port to work with.");
		return;
	}
	s->port=port;

	/*create the shared memory XvImage*/
	memset(shminfo,0,sizeof(*shminfo));
	s->xv_image=XvShmCreateImage(s->display,s->port,imgfmt_id,NULL,s->fbuf.w,s->fbuf.h,shminfo);
	if (s->xv_image==NULL){
		ms_error("XvShmCreateImage failed.");
		x11video_unprepare(f);
		return;
	}
	/*allocate some shared memory to receive the pixel data */
	shminfo->shmid=shmget(IPC_PRIVATE, s->xv_image->data_size,IPC_CREAT | 0777);
	if (shminfo->shmid==-1){
		ms_error("Could not allocate %i bytes of shared memory: %s",
		         s->xv_image->data_size,
		         strerror(errno));
		x11video_unprepare(f);
		return;
	}
	shminfo->shmaddr=shmat(shminfo->shmid,NULL,0);
	if (shminfo->shmaddr==(void*)-1){
		ms_error("shmat() failed: %s",strerror(errno));
		shminfo->shmaddr=NULL;
		x11video_unprepare(f);
		return;
	}
	/*ask the x-server to attach this shared memory segment*/
	x11_error=FALSE;
	if (!XShmAttach(s->display,shminfo)){
		ms_error("XShmAttach failed !");
		x11video_unprepare(f);
		return ;
	}
	s->xv_image->data=s->shminfo.shmaddr;
	s->fbuf.planes[0]=(void*)s->xv_image->data;
	s->fbuf.planes[2]=s->fbuf.planes[0]+(s->xv_image->height*s->xv_image->pitches[0]);
	s->fbuf.planes[1]=s->fbuf.planes[2]+((s->xv_image->height/2)*s->xv_image->pitches[1]);
	s->fbuf.strides[0]=s->xv_image->pitches[0];
	s->fbuf.strides[2]=s->xv_image->pitches[1];
	s->fbuf.strides[1]=s->xv_image->pitches[2];

	/* set picture black */
	x11video_fill_background(f);

	/*Create a GC*/
	s->gc=XCreateGC(s->display,s->window_id,0,NULL);
	if (s->gc==NULL){
		ms_error("XCreateGC() failed.");
		x11video_unprepare(f);
		return ;
	}

	s->ready=TRUE;
}
コード例 #20
0
ファイル: x11_out.c プロジェクト: gorinje/gpac-svn
static int X11_GetXVideoPort(GF_VideoOutput *vout, u32 pixel_format, Bool check_color)
{
	XWindow *xwin = (XWindow *)vout->opaque;
	Bool has_color_key = 0;
	XvAdaptorInfo *adaptors;
	unsigned int i;
	unsigned int nb_adaptors;
	int selected_port;

    if (XvQueryExtension(xwin->display, &i, &i, &i, &i, &i ) != Success) return -1;
    if (XvQueryAdaptors(xwin->display, DefaultRootWindow(xwin->display), &nb_adaptors, &adaptors) != Success) return -1;

    selected_port = -1;
    for (i=0; i < nb_adaptors; i++) {
        XvImageFormatValues *formats;
        int j, num_formats, port;

        if( !( adaptors[i].type & XvInputMask ) || !(adaptors[i].type & XvImageMask ) )
            continue;

        /* Check for our format... */
        formats = XvListImageFormats(xwin->display, adaptors[i].base_id, &num_formats);

        for (j=0; j<num_formats && (selected_port == -1 ); j++) {
		XvAttribute *attr;
		int k, nb_attributes;
		u32 pformat = X11_GetPixelFormat(formats[j].id);

		if( !is_same_yuv(pformat, pixel_format) ) continue;

		/* Grab first port  supporting this format */
		for (port=adaptors[i].base_id; (port < (int)(adaptors[i].base_id + adaptors[i].num_ports) ) && (selected_port == -1); port++) {
			if (port==xwin->xvport) continue;

			attr = XvQueryPortAttributes(xwin->display, port, &nb_attributes);
			for (k=0; k<nb_attributes; k++ ) {
			        if (!strcmp(attr[k].name, "XV_COLORKEY")) {
					const Atom ckey = XInternAtom(xwin->display, "XV_COLORKEY", False);
					XvGetPortAttribute(xwin->display, port, ckey, &vout->overlay_color_key);
					has_color_key = 1;
					vout->overlay_color_key |= 0xFF000000;
				}
/*			        else if (!strcmp(attr[k].name, "XV_AUTOPAINT_COLORKEY")) {
			            const Atom paint = XInternAtom(xwin->display, "XV_AUTOPAINT_COLORKEY", False);
			            XvSetPortAttribute(xwin->display, port, paint, 1);
				}
*/			}
			if (check_color && !has_color_key) continue;

			if (XvGrabPort(xwin->display, port, CurrentTime) == Success) {
				selected_port = port;
				xwin->xv_pf_format = formats[j].id;
			}
		}
		if (selected_port == -1 )
	                continue;
 
       }
        if (formats != NULL) XFree(formats);
    }
    if (nb_adaptors > 0) 
	XvFreeAdaptorInfo(adaptors);

   return selected_port;
}
コード例 #21
0
ファイル: display_gl.c プロジェクト: ymanton/mpeg2play_accel
static Bool 
GetPortId(Display *dpy, XvPortID *portID, int *surface_type)
{
   int i, j, k, numAdapt, numTypes, eventBase, errorBase;
   XvMCSurfaceInfo *surfaceInfo;
   XvAdaptorInfo *info;
   Bool result = 0;

   if(!XvMCQueryExtension(dpy, &eventBase, &errorBase))
	return 0;

   if(Success != XvQueryAdaptors(dpy,DefaultRootWindow(dpy),&numAdapt,&info))
        return 0;

   for(i = 0; i < numAdapt; i++) {
      if(info[i].type & XvImageMask) {  
         surfaceInfo = XvMCListSurfaceTypes(display, info[i].base_id,
                                               &numTypes);

         if(surfaceInfo) {
            for(j = 0; j < numTypes; j++) {
               if((surfaceInfo[j].chroma_format == XVMC_CHROMA_FORMAT_420) &&
                  (surfaceInfo[j].max_width >= coded_picture_width) &&
                  (surfaceInfo[j].max_height >= coded_picture_height) &&
                   ((surfaceInfo[j].mc_type == (XVMC_MOCOMP | XVMC_MPEG_2)) ||
                    (surfaceInfo[j].mc_type == (XVMC_IDCT | XVMC_MPEG_2))))
               {
                   if(use_idct != -1) {
                      if(use_idct == 1) {
                         if(surfaceInfo[j].mc_type == 
                                    (XVMC_MOCOMP | XVMC_MPEG_2))
                             continue;
                      } else {
                         if(surfaceInfo[j].mc_type == 
                                    (XVMC_IDCT | XVMC_MPEG_2))
                             continue;
                      }
                   }
                   for(k = 0; k < info[i].num_ports; k++) {
                        /* try to grab a port */
                        if(Success == XvGrabPort(dpy, info[i].base_id + k,
                                        CurrentTime))
                        {   
                            *portID = info[i].base_id + k;
                            *surface_type = surfaceInfo[j].surface_type_id;
                            result = 1;
                            break;
                        }
                    }
                    if(result) {
                       if(surfaceInfo[j].flags & XVMC_INTRA_UNSIGNED)
                           unsignedIntra = 1;
                       if(surfaceInfo[j].mc_type == (XVMC_IDCT | XVMC_MPEG_2))
                           useIDCT = 1;
                       break;
                    }
               }
            }
            XFree(surfaceInfo);
         }
      }
   }

   XvFreeAdaptorInfo(info);

   return result;
}
コード例 #22
0
// setup x or xvideo
void ffmpegWidget::xvSetup() {
    XvAdaptorInfo * ainfo;
    XvEncodingInfo *encodings;
    unsigned int adaptors, nencode;
    unsigned int ver, rel, extmaj, extev, exterr;
    // get display number
    this->dpy = x11Info().display();
    // Grab the window id and setup a graphics context
    this->w = this->winId();
    this->gc = XCreateGC(this->dpy, this->w, 0, 0);
    // Now try and setup xv
    // return version and release of extension
    if (XvQueryExtension(this->dpy, &ver, &rel, &extmaj, &extev, &exterr) != Success) {
        printf("XvQueryExtension failed, using QImage fallback mode\n");
        return;
    }
    //printf("Ver: %d, Rel: %d, ExtMajor: %d, ExtEvent: %d, ExtError: %d\n", ver, rel, extmaj, extev, exterr);
    //Ver: 2, Rel: 2, ExtMajor: 140, ExtEvent: 75, ExtError: 150
    // return adaptor information for the screen
    if (XvQueryAdaptors(this->dpy, QX11Info::appRootWindow(),
            &adaptors, &ainfo) != Success) {
        printf("XvQueryAdaptors failed, using QImage fallback mode\n");
        return;
    }
    // see if we have any adapters
    if (adaptors <= 0) {
        printf("No xv adaptors found, using QImage fallback mode\n");
        return;
    }
    // grab the port from the first adaptor
    int gotPort = 0;
    for(int p = 0; p < (int) ainfo[0].num_ports; p++) {
        if(XvGrabPort(this->dpy, ainfo[0].base_id + p, CurrentTime) == Success) {
            this->xv_port = ainfo[0].base_id + p;
            gotPort = 1;
            break;
        }
    }
    // if we didn't find a port
    if (!gotPort) {
        printf("No xv ports free, using QImage fallback mode\n");
        return;
    }
    // get max XV Image size
    int gotEncodings = 0;
    XvQueryEncodings(this->dpy, ainfo[0].base_id, &nencode, &encodings);
    if (encodings && nencode && (ainfo[0].type & XvImageMask)) {
        for(unsigned int n = 0; n < nencode; n++) {
            if(!strcmp(encodings[n].name, "XV_IMAGE")) {
                this->maxW = encodings[n].width;
                this->maxH = encodings[n].height;
                gotEncodings = 1;
                break;
            }
        }
    }
    // if we didn't find a list of encodings
    if (!gotEncodings) {
        printf("No encodings information, using QImage fallback mode\n");
        return;
    }
    // only support I420 mode for now
    int num_formats = 0;
    XvImageFormatValues * vals = XvListImageFormats(this->dpy,
        this->xv_port, &num_formats);
    for (int i=0; i<num_formats; i++) {
        if (strcmp(vals->guid, "I420") == 0) {
            this->xv_format = vals->id;
            this->ff_fmt = PIX_FMT_YUVJ420P;
            // Widget is responsible for painting all its pixels with an opaque color
            setAttribute(Qt::WA_OpaquePaintEvent);
            setAttribute(Qt::WA_PaintOnScreen);
            return;
        }
        vals++;
    }
    printf("Display doesn't support I420 mode, using QImage fallback mode\n");
    return;
}
コード例 #23
0
ファイル: x11_xv_display_sink.c プロジェクト: dluobo/ingex
static int XVideoGetPort( Display *p_display,
                          int32_t i_chroma,
                          int i_requested_adaptor)      // -1 for autoscan
{
    XvAdaptorInfo *p_adaptor;
    unsigned int i;
    unsigned int i_adaptor, i_num_adaptors;
    int i_selected_port;

    switch( XvQueryExtension( p_display, &i, &i, &i, &i, &i ) )
    {
        case Success:
            break;

        case XvBadExtension:
            ml_log_error("XvBadExtension\n" );
            return -1;

        case XvBadAlloc:
            ml_log_error("XvBadAlloc\n" );
            return -1;

        default:
            ml_log_error("XvQueryExtension failed\n" );
            return -1;
    }

    switch( XvQueryAdaptors( p_display,
                             DefaultRootWindow( p_display ),
                             &i_num_adaptors, &p_adaptor ) )
    {
        case Success:
            break;

        case XvBadExtension:
            ml_log_error("XvBadExtension for XvQueryAdaptors\n" );
            return -1;

        case XvBadAlloc:
            ml_log_error("XvBadAlloc for XvQueryAdaptors\n" );
            return -1;

        default:
            ml_log_error("XvQueryAdaptors failed\n" );
            return -1;
    }

    i_selected_port = -1;

    for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
    {
        XvImageFormatValues *p_formats;
        int i_format, i_num_formats;
        int i_port;

        /* If we requested an adaptor and it's not this one, we aren't
         * interested */
        if( i_requested_adaptor != -1 && i_adaptor != (unsigned int)i_requested_adaptor )
        {
            continue;
        }

        /* If the adaptor doesn't have the required properties, skip it */
        if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
            !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
        {
            continue;
        }

        /* Check that adaptor supports our requested format... */
        p_formats = XvListImageFormats( p_display,
                                        p_adaptor[i_adaptor].base_id,
                                        &i_num_formats );

        for( i_format = 0;
             i_format < i_num_formats && ( i_selected_port == -1 );
             i_format++ )
        {
            XvAttribute     *p_attr;
            int             i_attr, i_num_attributes;

            /* Matching chroma? */
            if( p_formats[ i_format ].id != i_chroma )
            {
                continue;
            }

            /* Look for the first available port supporting this format */
            for( i_port = p_adaptor[i_adaptor].base_id;
                 ( i_port < (int)(p_adaptor[i_adaptor].base_id
                                   + p_adaptor[i_adaptor].num_ports) )
                   && ( i_selected_port == -1 );
                 i_port++ )
            {
                if( XvGrabPort( p_display, i_port, CurrentTime )
                     == Success )
                {
                    i_selected_port = i_port;
                }
            }

            /* If no free port was found, forget it */
            if( i_selected_port == -1 )
            {
                continue;
            }

            /* If we found a port, print information about it */
            ml_log_info("X11 display adaptor %i, port %i, format 0x%x (%4.4s) %s\n",
                     i_adaptor, i_selected_port, p_formats[ i_format ].id,
                     (char *)&p_formats[ i_format ].id,
                     ( p_formats[ i_format ].format == XvPacked ) ?
                         "packed" : "planar" );

            /* Make sure XV_AUTOPAINT_COLORKEY is set */
            p_attr = XvQueryPortAttributes( p_display,
                                            i_selected_port,
                                            &i_num_attributes );

            for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
            {
                if( !strcmp( p_attr[i_attr].name, "XV_AUTOPAINT_COLORKEY" ) )
                {
                    const Atom autopaint =
                        XInternAtom( p_display,
                                     "XV_AUTOPAINT_COLORKEY", False );
                    XvSetPortAttribute( p_display,
                                        i_selected_port, autopaint, 1 );
                    break;
                }
            }

            if( p_attr != NULL )
            {
                XFree( p_attr );
            }
        }

        if( p_formats != NULL )
        {
            XFree( p_formats );
        }

    }

    if( i_num_adaptors > 0 )
    {
        XvFreeAdaptorInfo( p_adaptor );
    }

    if( i_selected_port == -1 )
    {
        int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
        if( i_requested_adaptor == -1 )
        {
            ml_log_error("no free XVideo port found for format: "
                      "0x%.8x (%4.4s)\n", i_chroma_tmp, (char*)&i_chroma_tmp );
        }
        else
        {
            ml_log_error("XVideo adaptor %i does not have a free: "
                      "XVideo port for format 0x%.8x (%4.4s)\n",
                      i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
        }
    }

    return i_selected_port;
}