plugins: use GstVideoInfo in video uploader helper.

This commit is contained in:
Gwenole Beauchesne 2013-07-10 15:03:43 +02:00
parent 1cfe03ee52
commit 419af50009

View file

@ -50,13 +50,10 @@ struct _GstVaapiUploaderPrivate {
GstVaapiDisplay *display; GstVaapiDisplay *display;
GstCaps *allowed_caps; GstCaps *allowed_caps;
GstVaapiVideoPool *images; GstVaapiVideoPool *images;
GstVideoInfo image_info;
GstCaps *image_caps; GstCaps *image_caps;
GstVideoFormat image_format;
guint image_width;
guint image_height;
GstVaapiVideoPool *surfaces; GstVaapiVideoPool *surfaces;
guint surface_width; GstVideoInfo surface_info;
guint surface_height;
guint direct_rendering; guint direct_rendering;
}; };
@ -168,9 +165,11 @@ end:
} }
static gboolean static gboolean
ensure_image_pool(GstVaapiUploader *uploader, GstCaps *caps) ensure_image_pool(GstVaapiUploader *uploader, GstCaps *caps,
gboolean *caps_changed_ptr)
{ {
GstVaapiUploaderPrivate * const priv = uploader->priv; GstVaapiUploaderPrivate * const priv = uploader->priv;
GstVaapiVideoPool *pool;
GstVideoInfo vi; GstVideoInfo vi;
GstVideoFormat format; GstVideoFormat format;
guint width, height; guint width, height;
@ -182,42 +181,55 @@ ensure_image_pool(GstVaapiUploader *uploader, GstCaps *caps)
width = GST_VIDEO_INFO_WIDTH(&vi); width = GST_VIDEO_INFO_WIDTH(&vi);
height = GST_VIDEO_INFO_HEIGHT(&vi); height = GST_VIDEO_INFO_HEIGHT(&vi);
if (format != priv->image_format || *caps_changed_ptr =
width != priv->image_width || format != GST_VIDEO_INFO_FORMAT(&priv->image_info) ||
height != priv->image_height) { width != GST_VIDEO_INFO_WIDTH(&priv->image_info) ||
priv->image_format = format; height != GST_VIDEO_INFO_HEIGHT(&priv->image_info);
priv->image_width = width; if (!*caps_changed_ptr)
priv->image_height = height; return TRUE;
gst_vaapi_video_pool_replace(&priv->images, NULL);
priv->images = gst_vaapi_image_pool_new(priv->display, &vi); pool = gst_vaapi_image_pool_new(priv->display, &vi);
if (!priv->images) if (!pool)
return FALSE; return FALSE;
gst_caps_replace(&priv->image_caps, caps);
} gst_video_info_set_format(&priv->image_info, format, width, height);
gst_caps_replace(&priv->image_caps, caps);
gst_vaapi_video_pool_replace(&priv->images, pool);
gst_vaapi_video_pool_unref(pool);
return TRUE; return TRUE;
} }
static gboolean static gboolean
ensure_surface_pool(GstVaapiUploader *uploader, GstCaps *caps) ensure_surface_pool(GstVaapiUploader *uploader, GstCaps *caps,
gboolean *caps_changed_ptr)
{ {
GstVaapiUploaderPrivate * const priv = uploader->priv; GstVaapiUploaderPrivate * const priv = uploader->priv;
GstVaapiVideoPool *pool;
GstVideoInfo vi; GstVideoInfo vi;
GstVideoFormat format;
guint width, height; guint width, height;
if (!gst_video_info_from_caps(&vi, caps)) if (!gst_video_info_from_caps(&vi, caps))
return FALSE; return FALSE;
format = GST_VIDEO_INFO_FORMAT(&vi);
width = GST_VIDEO_INFO_WIDTH(&vi); width = GST_VIDEO_INFO_WIDTH(&vi);
height = GST_VIDEO_INFO_HEIGHT(&vi); height = GST_VIDEO_INFO_HEIGHT(&vi);
if (width != priv->surface_width || height != priv->surface_height) { *caps_changed_ptr =
priv->surface_width = width; format != GST_VIDEO_INFO_FORMAT(&priv->surface_info) ||
priv->surface_height = height; width != GST_VIDEO_INFO_WIDTH(&priv->surface_info) ||
gst_vaapi_video_pool_replace(&priv->surfaces, NULL); height != GST_VIDEO_INFO_HEIGHT(&priv->surface_info);
priv->surfaces = gst_vaapi_surface_pool_new(priv->display, &vi); if (!*caps_changed_ptr)
if (!priv->surfaces) return TRUE;
return FALSE;
} pool = gst_vaapi_surface_pool_new(priv->display, &vi);
if (!pool)
return FALSE;
gst_video_info_set_format(&priv->surface_info, format, width, height);
gst_vaapi_video_pool_replace(&priv->surfaces, pool);
gst_vaapi_video_pool_unref(pool);
return TRUE; return TRUE;
} }
@ -292,6 +304,9 @@ gst_vaapi_uploader_init(GstVaapiUploader *uploader)
priv = GST_VAAPI_UPLOADER_GET_PRIVATE(uploader); priv = GST_VAAPI_UPLOADER_GET_PRIVATE(uploader);
uploader->priv = priv; uploader->priv = priv;
gst_video_info_init(&priv->image_info);
gst_video_info_init(&priv->surface_info);
} }
GstVaapiUploader * GstVaapiUploader *
@ -323,14 +338,20 @@ gst_vaapi_uploader_ensure_caps(
GstVaapiImage *image; GstVaapiImage *image;
GstVideoFormat format; GstVideoFormat format;
GstVideoInfo vi; GstVideoInfo vi;
gboolean image_caps_changed, surface_caps_changed;
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE); g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE);
g_return_val_if_fail(src_caps != NULL, FALSE); g_return_val_if_fail(src_caps != NULL, FALSE);
if (!ensure_image_pool(uploader, src_caps)) if (!out_caps)
out_caps = src_caps;
if (!ensure_image_pool(uploader, src_caps, &image_caps_changed))
return FALSE; return FALSE;
if (!ensure_surface_pool(uploader, out_caps ? out_caps : src_caps)) if (!ensure_surface_pool(uploader, out_caps, &surface_caps_changed))
return FALSE; return FALSE;
if (!image_caps_changed && !surface_caps_changed)
return TRUE;
priv = uploader->priv; priv = uploader->priv;
priv->direct_rendering = 0; priv->direct_rendering = 0;