Beispiel #1
0
XvMCOSD::XvMCOSD(Display *disp, int port, int surface_type_id,
                 int xvmc_surf_flags)
    : XJ_disp(disp), XJ_width(0), XJ_height(0),
      xv_port(port), osd_palette(NULL), osd_xv_image(NULL),
      osd_subpict_mode(NO_SUBPICTURE), osd_subpict_clear_color(0),
      osd_subpict_alloc(false)
{
    bzero(&osd_subpict, sizeof(osd_subpict));
    // subpicture init
    int num = 0;
    XvImageFormatValues *xvfmv = NULL;
    X11S(xvfmv = XvMCListSubpictureTypes(XJ_disp, xv_port,
                                         surface_type_id, &num));

    for (int i = (xvfmv) ? 0 : num; i < num; i++)
    {
        if (GUID_IA44_PACKED == xvfmv[i].id || GUID_AI44_PACKED == xvfmv[i].id)
        {
            osd_subpict_info  = xvfmv[i];
            bool be = (XVMC_BACKEND_SUBPICTURE & xvmc_surf_flags);
            osd_subpict_mode = (be) ? BACKEND_SUBPICTURE : BLEND_SUBPICTURE;
            break;
        }
    }

    if (xvfmv)
        X11S(XFree(xvfmv));
}
Beispiel #2
0
static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvimage_id)
{
    XvImageFormatValues *subpictures;
    int num_subpics;
    unsigned int i;

    subpictures = XvMCListSubpictureTypes(dpy, port, surface_type_id, &num_subpics);
    if (num_subpics < 1) {
        if (subpictures)
            XFree(subpictures);
        return BadMatch;
    }
    if (!subpictures)
        return BadAlloc;

    for (i = 0; i < num_subpics; ++i) {
        if (subpictures[i].id == xvimage_id) {
            XVMC_MSG(XVMC_TRACE, "[XvMC] Found requested subpicture format.\n" \
                     "[XvMC]   port=%u\n" \
                     "[XvMC]   surface id=0x%08X\n" \
                     "[XvMC]   image id=0x%08X\n" \
                     "[XvMC]   type=%08X\n" \
                     "[XvMC]   byte order=%08X\n" \
                     "[XvMC]   bits per pixel=%u\n" \
                     "[XvMC]   format=%08X\n" \
                     "[XvMC]   num planes=%d\n",
                     port, surface_type_id, xvimage_id, subpictures[i].type, subpictures[i].byte_order,
                     subpictures[i].bits_per_pixel, subpictures[i].format, subpictures[i].num_planes);
            if (subpictures[i].type == XvRGB) {
                XVMC_MSG(XVMC_TRACE, "[XvMC]   depth=%d\n" \
                         "[XvMC]   red mask=0x%08X\n" \
                         "[XvMC]   green mask=0x%08X\n" \
                         "[XvMC]   blue mask=0x%08X\n",
                         subpictures[i].depth, subpictures[i].red_mask,
                         subpictures[i].green_mask, subpictures[i].blue_mask);
            }
            else if (subpictures[i].type == XvYUV) {
                XVMC_MSG(XVMC_TRACE, "[XvMC]   y sample bits=0x%08X\n" \
                         "[XvMC]   u sample bits=0x%08X\n" \
                         "[XvMC]   v sample bits=0x%08X\n" \
                         "[XvMC]   horz y period=%u\n" \
                         "[XvMC]   horz u period=%u\n" \
                         "[XvMC]   horz v period=%u\n" \
                         "[XvMC]   vert y period=%u\n" \
                         "[XvMC]   vert u period=%u\n" \
                         "[XvMC]   vert v period=%u\n",
                         subpictures[i].y_sample_bits, subpictures[i].u_sample_bits, subpictures[i].v_sample_bits,
                         subpictures[i].horz_y_period, subpictures[i].horz_u_period, subpictures[i].horz_v_period,
                         subpictures[i].vert_y_period, subpictures[i].vert_u_period, subpictures[i].vert_v_period);
            }
            break;
        }
    }

    XFree(subpictures);

    return i < num_subpics ? Success : BadMatch;
}
int main(int argc, char **argv)
{
	const unsigned int	width = 16, height = 16;
	const unsigned int	mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
	const unsigned int	subpic_width = 16, subpic_height = 16;

	Display			*display;
	XvPortID		port_num;
	int			surface_type_id;
	unsigned int		is_overlay, intra_unsigned;
	int			colorkey;
	XvMCContext		context;
	XvImageFormatValues	*subpics;
	int			num_subpics;
	XvMCSubpicture		subpicture = {0};
	int			i;

	display = XOpenDisplay(NULL);

	if (!GetPort
	(
		display,
		width,
		height,
		XVMC_CHROMA_FORMAT_420,
		mc_types,
		2,
		&port_num,
		&surface_type_id,
		&is_overlay,
		&intra_unsigned
	))
	{
		XCloseDisplay(display);
		fprintf(stderr, "Error, unable to find a good port.\n");
		exit(1);
	}

	if (is_overlay)
	{
		Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
		XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
	}

	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);

	subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
	assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));

	for (i = 0; i < num_subpics; ++i)
	{
		printf("Subpicture %d:\n", i);
		printf("\tid: 0x%08x\n", subpics[i].id);
		printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
		printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
		PrintGUID(subpics[i].guid);
		printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
		printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
		printf("\tnum_planes: %u\n", subpics[i].num_planes);

		if (subpics[i].type == XvRGB)
		{
			printf("\tdepth: %u\n", subpics[i].depth);
			printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
			printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
			printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
		}
		else if (subpics[i].type == XvYUV)
		{
			printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
			printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
			printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
			printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
			printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
			printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
			printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
			printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
			printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
		}
		PrintComponentOrder(subpics[i].component_order);
		printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
	}

	if (num_subpics == 0)
	{
		printf("Subpictures not supported, nothing to test.\n");
		return 0;
	}

	/* Test NULL context */
	assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
	/* Test NULL subpicture */
	assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
	/* Test invalid subpicture */
	assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
	/* Test huge width */
	assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
	/* Test huge height */
	assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
	/* Test huge width & height */
	assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
	for (i = 0; i < num_subpics; ++i)
	{
		/* Test valid params */
		assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
		/* Test subpicture id assigned */
		assert(subpicture.subpicture_id != 0);
		/* Test context id assigned and correct */
		assert(subpicture.context_id == context.context_id);
		/* Test subpicture type id assigned and correct */
		assert(subpicture.xvimage_id == subpics[i].id);
		/* Test width & height assigned and correct */
		assert(subpicture.width == width && subpicture.height == height);
		if (subpics[i].type == XvRGB)
			/* Test no palette support */
			assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
		else
			/* Test palette support */
			assert(subpicture.num_palette_entries == 16 && subpicture.entry_bytes == 4);
		/* Test valid params */
		assert(XvMCDestroySubpicture(display, &subpicture) == Success);
	}
	/* Test NULL surface */
	assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);

	assert(XvMCDestroyContext(display, &context) == Success);

	free(subpics);
	XvUngrabPort(display, port_num, CurrentTime);
	XCloseDisplay(display);

	return 0;
}