diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c index 7665b25ed..c1b7a97af 100644 --- a/hw/kdrive/ephyr/ephyrhostvideo.c +++ b/hw/kdrive/ephyr/ephyrhostvideo.c @@ -120,30 +120,6 @@ ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings) } free(a_encodings); } - -void -ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes) -{ - free(a_attributes); -} - -Bool -ephyrHostXVQueryPortAttributes(int a_port_id, - xcb_xv_query_port_attributes_reply_t **a_attributes) -{ - xcb_xv_query_port_attributes_cookie_t cookie; - xcb_xv_query_port_attributes_reply_t *reply; - xcb_connection_t *conn = hostx_get_xcbconn(); - - EPHYR_RETURN_VAL_IF_FAIL(a_attributes, FALSE); - - cookie = xcb_xv_query_port_attributes(conn, a_port_id); - reply = xcb_xv_query_port_attributes_reply(conn, cookie, NULL); - *a_attributes = reply; - - return (reply != NULL); -} - Bool ephyrHostXVQueryImageFormats(int a_port_id, EphyrHostImageFormat ** a_formats, @@ -199,51 +175,6 @@ ephyrHostXVQueryImageFormats(int a_port_id, return TRUE; } -Bool -ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value) -{ - EPHYR_LOG("atom,value: (%d,%d)\n", a_atom, a_attr_value); - - xcb_xv_set_port_attribute(hostx_get_xcbconn(), - a_port_id, - a_atom, - a_attr_value); - xcb_flush(hostx_get_xcbconn()); - EPHYR_LOG("leave\n"); - - return TRUE; -} - -Bool -ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value) -{ - Bool ret = FALSE; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_xv_get_port_attribute_cookie_t cookie; - xcb_xv_get_port_attribute_reply_t *reply; - xcb_generic_error_t *e; - - EPHYR_RETURN_VAL_IF_FAIL(a_attr_value, FALSE); - - EPHYR_LOG("enter, a_port_id: %d, a_atomid: %d\n", a_port_id, a_atom); - - cookie = xcb_xv_get_port_attribute(conn, a_port_id, a_atom); - reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e); - if (e) { - EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code); - free(e); - goto out; - } - *a_attr_value = reply->value; - EPHYR_LOG("atom,value: (%d, %d)\n", a_atom, *a_attr_value); - - ret = TRUE; - - out: - EPHYR_LOG("leave\n"); - return ret; -} - Bool ephyrHostXVQueryBestSize(int a_port_id, Bool a_motion, @@ -285,44 +216,6 @@ out: return is_ok; } -Bool -ephyrHostXVQueryImageAttributes(int a_port_id, - int a_image_id /*image fourcc code */ , - unsigned short *a_width, - unsigned short *a_height, - int *a_image_size, - int *a_pitches, int *a_offsets) -{ - xcb_connection_t *conn = hostx_get_xcbconn (); - xcb_xv_query_image_attributes_cookie_t cookie; - xcb_xv_query_image_attributes_reply_t *reply; - - EPHYR_RETURN_VAL_IF_FAIL(a_width, FALSE); - EPHYR_RETURN_VAL_IF_FAIL(a_height, FALSE); - EPHYR_RETURN_VAL_IF_FAIL(a_image_size, FALSE); - - cookie = xcb_xv_query_image_attributes(conn, - a_port_id, a_image_id, - *a_width, *a_height); - reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL); - if (!reply) - return FALSE; - if (a_pitches && a_offsets) { - memcpy(a_pitches, - xcb_xv_query_image_attributes_pitches(reply), - reply->num_planes << 2); - memcpy(a_offsets, - xcb_xv_query_image_attributes_offsets(reply), - reply->num_planes << 2); - } - *a_width = reply->width; - *a_height = reply->height; - *a_image_size = reply->data_size; - free(reply); - - return TRUE; -} - Bool ephyrHostGetAtom(const char *a_name, Bool a_create_if_not_exists, int *a_atom) { diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h index 7d2dbe2e8..6fa8f7af9 100644 --- a/hw/kdrive/ephyr/ephyrhostvideo.h +++ b/hw/kdrive/ephyr/ephyrhostvideo.h @@ -97,14 +97,6 @@ Bool ephyrHostXVQueryEncodings(int a_port_id, void ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings); -/* - * attribute - */ -Bool ephyrHostXVQueryPortAttributes(int a_port_id, - xcb_xv_query_port_attributes_reply_t **a_attributes); - -void ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes); - /* * image format */ @@ -112,11 +104,6 @@ void ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attribute Bool ephyrHostXVQueryImageFormats(int a_port_id, EphyrHostImageFormat ** a_formats, int *a_num_format); -/* - * Port Attribute Get/Set - */ -Bool ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value); -Bool ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value); /* *size query @@ -130,12 +117,6 @@ Bool ephyrHostXVQueryBestSize(int a_port_id, unsigned int *a_actual_w, unsigned int *a_actual_h); -Bool ephyrHostXVQueryImageAttributes(int a_port_id, - int a_image_id /*image fourcc code */ , - unsigned short *a_width, - unsigned short *a_height, - int *a_image_size, - int *a_pitches, int *a_offsets); /* * atom */ diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c index be5988645..590426546 100644 --- a/hw/kdrive/ephyr/ephyrvideo.c +++ b/hw/kdrive/ephyr/ephyrvideo.c @@ -352,32 +352,48 @@ videoEncodingDup(EphyrHostEncoding * a_encodings, int a_num_encodings) return result; } -static KdAttributePtr -portAttributesDup(const xcb_xv_query_port_attributes_reply_t *a_encodings) +static Bool +translate_xv_attributes(KdVideoAdaptorPtr adaptor, + xcb_xv_adaptor_info_t *host_adaptor) { + xcb_connection_t *conn = hostx_get_xcbconn(); int i = 0; - KdAttributePtr result = NULL; xcb_xv_attribute_info_iterator_t it; + xcb_xv_query_port_attributes_cookie_t cookie = + xcb_xv_query_port_attributes(conn, host_adaptor->base_id); + xcb_xv_query_port_attributes_reply_t *reply = + xcb_xv_query_port_attributes_reply(conn, cookie, NULL); - EPHYR_RETURN_VAL_IF_FAIL(a_encodings, NULL); + if (!reply) + return FALSE; - result = calloc(a_encodings->num_attributes, sizeof(KdAttributeRec)); - if (!result) { + adaptor->nAttributes = reply->num_attributes; + adaptor->pAttributes = calloc(reply->num_attributes, + sizeof(*adaptor->pAttributes)); + if (!adaptor->pAttributes) { EPHYR_LOG_ERROR("failed to allocate attributes\n"); - return NULL; + free(reply); + return FALSE; } - it = xcb_xv_query_port_attributes_attributes_iterator(a_encodings); - for (i = 0; - i < a_encodings->num_attributes; - xcb_xv_attribute_info_next(&it), i++) { - result[i].flags = it.data->flags; - result[i].min_value = it.data->min; - result[i].max_value = it.data->max; - result[i].name = malloc(it.data->size + 1); - memcpy (result[i].name, xcb_xv_attribute_info_name(it.data), it.data->size); - result[i].name[it.data->size] = '\0'; + + it = xcb_xv_query_port_attributes_attributes_iterator(reply); + for (i = 0; i < reply->num_attributes; i++) { + KdAttributePtr attribute = &adaptor->pAttributes[i]; + + attribute->flags = it.data->flags; + attribute->min_value = it.data->min; + attribute->max_value = it.data->max; + attribute->name = strndup(xcb_xv_attribute_info_name(it.data), + it.data->size); + + /* make sure atoms of attrs names are created in xephyr */ + MakeAtom(xcb_xv_attribute_info_name(it.data), it.data->size, TRUE); + + xcb_xv_attribute_info_next(&it); } - return result; + + free(reply); + return TRUE; } static Bool @@ -387,7 +403,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen()); EphyrHostVideoFormat *video_formats = NULL; EphyrHostEncoding *encodings = NULL; - xcb_xv_query_port_attributes_reply_t *attributes = NULL; EphyrHostImageFormat *image_formats = NULL; int num_video_formats = 0, base_port_id = 0, num_formats = 0, i = 0, port_priv_offset = 0; @@ -485,20 +500,15 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) port_priv->xv_priv = a_this; a_this->adaptors[i].pPortPrivates[j].ptr = port_priv; } - if (!ephyrHostXVQueryPortAttributes(base_port_id, &attributes)) { + + if (!translate_xv_attributes(&a_this->adaptors[i], cur_host_adaptor)) { + { EPHYR_LOG_ERROR("failed to get port attribute " "for adaptor %d\n", i); continue; } - a_this->adaptors[i].pAttributes = - portAttributesDup(attributes); - a_this->adaptors[i].nAttributes = attributes->num_attributes; - /*make sure atoms of attrs names are created in xephyr */ - for (j = 0; j < a_this->adaptors[i].nAttributes; j++) { - if (a_this->adaptors[i].pAttributes[j].name) - MakeAtom(a_this->adaptors[i].pAttributes[j].name, - strlen(a_this->adaptors[i].pAttributes[j].name), TRUE); } + if (!ephyrHostXVQueryImageFormats(base_port_id, &image_formats, &num_formats)) { EPHYR_LOG_ERROR("failed to get image formats " @@ -517,10 +527,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) ephyrHostEncodingsDelete(encodings, num_encodings); encodings = NULL; } - if (attributes) { - ephyrHostAttributesDelete(attributes); - attributes = NULL; - } EPHYR_LOG("leave\n"); return is_ok; } @@ -650,20 +656,27 @@ ephyrXVPrivGetImageBufSize(int a_port_id, unsigned short a_width, unsigned short a_height, int *a_size) { + xcb_connection_t *conn = hostx_get_xcbconn(); + xcb_xv_query_image_attributes_cookie_t cookie; + xcb_xv_query_image_attributes_reply_t *reply; Bool is_ok = FALSE; - unsigned short width = a_width, height = a_height; EPHYR_RETURN_VAL_IF_FAIL(a_size, FALSE); EPHYR_LOG("enter\n"); - if (!ephyrHostXVQueryImageAttributes(a_port_id, a_image_id, - &width, &height, a_size, NULL, NULL)) { - EPHYR_LOG_ERROR("failed to get image attributes\n"); + cookie = xcb_xv_query_image_attributes(conn, + a_port_id, a_image_id, + a_width, a_height); + reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL); + if (!reply) goto out; - } + + *a_size = reply->data_size; is_ok = TRUE; + free(reply); + out: EPHYR_LOG("leave\n"); return is_ok; @@ -715,6 +728,7 @@ static int ephyrSetPortAttribute(KdScreenInfo * a_info, Atom a_attr_name, int a_attr_value, pointer a_port_priv) { + xcb_connection_t *conn = hostx_get_xcbconn(); int res = Success, host_atom = 0; EphyrPortPriv *port_priv = a_port_priv; Bool is_attr_valid = FALSE; @@ -755,12 +769,9 @@ ephyrSetPortAttribute(KdScreenInfo * a_info, */ } - if (!ephyrHostXVSetPortAttribute(port_priv->port_number, - host_atom, a_attr_value)) { - EPHYR_LOG_ERROR("failed to set port attribute\n"); - res = BadMatch; - goto out; - } + xcb_xv_set_port_attribute(conn, port_priv->port_number, + host_atom, a_attr_value); + xcb_flush(conn); res = Success; out: @@ -772,8 +783,12 @@ static int ephyrGetPortAttribute(KdScreenInfo * a_screen_info, Atom a_attr_name, int *a_attr_value, pointer a_port_priv) { + xcb_connection_t *conn = hostx_get_xcbconn(); int res = Success, host_atom = 0; EphyrPortPriv *port_priv = a_port_priv; + xcb_generic_error_t *e; + xcb_xv_get_port_attribute_cookie_t cookie; + xcb_xv_get_port_attribute_reply_t *reply; EPHYR_RETURN_VAL_IF_FAIL(port_priv, BadMatch); EPHYR_RETURN_VAL_IF_FAIL(ValidAtom(a_attr_name), BadMatch); @@ -788,12 +803,17 @@ ephyrGetPortAttribute(KdScreenInfo * a_screen_info, goto out; } - if (!ephyrHostXVGetPortAttribute(port_priv->port_number, - host_atom, a_attr_value)) { - EPHYR_LOG_ERROR("failed to get port attribute\n"); + cookie = xcb_xv_get_port_attribute(conn, port_priv->port_number, host_atom); + reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e); + if (e) { + EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code); + free(e); res = BadMatch; goto out; } + *a_attr_value = reply->value; + + free(reply); res = Success; out: @@ -1130,6 +1150,9 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info, unsigned short *a_w, unsigned short *a_h, int *a_pitches, int *a_offsets) { + xcb_connection_t *conn = hostx_get_xcbconn(); + xcb_xv_query_image_attributes_cookie_t cookie; + xcb_xv_query_image_attributes_reply_t *reply; int image_size = 0; EPHYR_RETURN_VAL_IF_FAIL(a_w && a_h, FALSE); @@ -1137,13 +1160,25 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info, EPHYR_LOG("enter: dim (%dx%d), pitches: %p, offsets: %p\n", *a_w, *a_h, a_pitches, a_offsets); - if (!ephyrHostXVQueryImageAttributes(s_base_port_id, - a_id, - a_w, a_h, - &image_size, a_pitches, a_offsets)) { - EPHYR_LOG_ERROR("EphyrHostXVQueryImageAttributes() failed\n"); + cookie = xcb_xv_query_image_attributes(conn, + s_base_port_id, a_id, + *a_w, *a_h); + reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL); + if (!reply) goto out; + + *a_w = reply->width; + *a_h = reply->height; + if (a_pitches && a_offsets) { + memcpy(a_pitches, xcb_xv_query_image_attributes_pitches(reply), + reply->num_planes << 2); + memcpy(a_offsets, xcb_xv_query_image_attributes_offsets(reply), + reply->num_planes << 2); } + image_size = reply->data_size; + + free(reply); + EPHYR_LOG("image size: %d, dim (%dx%d)\n", image_size, *a_w, *a_h); out: