vaapipostproc: handle size and direction together in src events

Mapping a pointer event needs to consider both size and
video-direction operations together, not just one or the other.

This fixes an issue where x,y were not being mapped correctly
for 90r, 90l, ur-ll and ul-lr video-direction. In these directions,
the WxH are swapped and GST_VAAPI_POSTPROC_FLAG_SIZE is set.  Thus,
the first condition in the pointer event handling was entered and
x,y scale factor were incorrectly computed due to srcpad WxH
swap.

This also fixes all cases where both video-direction and scaling
are enabled at the same time.

Test that all pointer events map appropriately:

for i in `seq 0 7`
do
 GST_DEBUG=vaapipostproc:5 gst-launch-1.0 -vf videotestsrc \
  ! vaapipostproc video-direction=${i} width=300 \
  ! vaapisink
 GST_DEBUG=vaapipostproc:5 gst-launch-1.0 -vf videotestsrc \
  ! vaapipostproc video-direction=${i} width=300 height=200 \
  ! vaapisink
 GST_DEBUG=vaapipostproc:5 gst-launch-1.0 -vf videotestsrc \
  ! vaapipostproc video-direction=${i} height=200 \
  ! vaapisink
 GST_DEBUG=vaapipostproc:5 gst-launch-1.0 -vf videotestsrc \
  ! vaapipostproc video-direction=${i} \
  ! vaapisink
done
This commit is contained in:
U. Artie Eoff 2019-09-04 10:52:51 -07:00
parent 6700f642fc
commit 9fd020a117

View file

@ -1639,11 +1639,33 @@ gst_vaapipostproc_decide_allocation (GstBaseTransform * trans, GstQuery * query)
query);
}
static void
get_scale_factor (GstVaapiPostproc * const postproc, gdouble * w_factor,
gdouble * h_factor)
{
gdouble wd = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info);
gdouble hd = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info);
switch (gst_vaapi_filter_get_video_direction (postproc->filter)) {
case GST_VIDEO_ORIENTATION_90R:
case GST_VIDEO_ORIENTATION_90L:
case GST_VIDEO_ORIENTATION_UR_LL:
case GST_VIDEO_ORIENTATION_UL_LR:
G_PRIMITIVE_SWAP (gdouble, wd, hd);
break;
default:
break;
}
*w_factor = GST_VIDEO_INFO_WIDTH (&postproc->sinkpad_info) / wd;
*h_factor = GST_VIDEO_INFO_HEIGHT (&postproc->sinkpad_info) / hd;
}
static gboolean
gst_vaapipostproc_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVaapiPostproc *const postproc = GST_VAAPIPOSTPROC (trans);
gdouble new_x = 0, new_y = 0, x = 0, y = 0;
gdouble new_x = 0, new_y = 0, x = 0, y = 0, w_factor = 1, h_factor = 1;
GstStructure *structure;
gboolean ret;
@ -1659,55 +1681,45 @@ gst_vaapipostproc_src_event (GstBaseTransform * trans, GstEvent * event)
gst_structure_get_double (structure, "pointer_y", &y)) {
GST_DEBUG_OBJECT (postproc, "converting %fx%f", x, y);
if (postproc->flags & GST_VAAPI_POSTPROC_FLAG_SIZE) {
if ((GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info)
!= GST_VIDEO_INFO_WIDTH (&postproc->sinkpad_info))
&& (GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info)
!= GST_VIDEO_INFO_HEIGHT (&postproc->sinkpad_info))) {
new_x =
x * GST_VIDEO_INFO_WIDTH (&postproc->sinkpad_info) /
GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info);
new_y =
y * GST_VIDEO_INFO_HEIGHT (&postproc->sinkpad_info) /
GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info);
}
} else if (postproc->flags & GST_VAAPI_POSTPROC_FLAG_VIDEO_DIRECTION) {
switch (gst_vaapi_filter_get_video_direction (postproc->filter)) {
case GST_VIDEO_ORIENTATION_90R:
new_x = y;
new_y = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
break;
case GST_VIDEO_ORIENTATION_90L:
new_x = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
new_y = x;
break;
case GST_VIDEO_ORIENTATION_UR_LL:
new_x = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
new_y = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
break;
case GST_VIDEO_ORIENTATION_UL_LR:
new_x = y;
new_y = x;
break;
case GST_VIDEO_ORIENTATION_180:
new_x = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
new_y = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
break;
case GST_VIDEO_ORIENTATION_HORIZ:
new_x = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
new_y = y;
break;
case GST_VIDEO_ORIENTATION_VERT:
new_x = x;
new_y = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
break;
default:
new_x = x;
new_y = y;
break;
}
switch (gst_vaapi_filter_get_video_direction (postproc->filter)) {
case GST_VIDEO_ORIENTATION_90R:
new_x = y;
new_y = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
break;
case GST_VIDEO_ORIENTATION_90L:
new_x = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
new_y = x;
break;
case GST_VIDEO_ORIENTATION_UR_LL:
new_x = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
new_y = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
break;
case GST_VIDEO_ORIENTATION_UL_LR:
new_x = y;
new_y = x;
break;
case GST_VIDEO_ORIENTATION_180:
new_x = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
new_y = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
break;
case GST_VIDEO_ORIENTATION_HORIZ:
new_x = GST_VIDEO_INFO_WIDTH (&postproc->srcpad_info) - x;
new_y = y;
break;
case GST_VIDEO_ORIENTATION_VERT:
new_x = x;
new_y = GST_VIDEO_INFO_HEIGHT (&postproc->srcpad_info) - y;
break;
default:
new_x = x;
new_y = y;
break;
}
get_scale_factor (postproc, &w_factor, &h_factor);
new_x *= w_factor;
new_y *= h_factor;
GST_DEBUG_OBJECT (postproc, "to %fx%f", new_x, new_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);