[Pkg-gstreamer-commits] [gstreamer-vaapi] 162/176: context: introduce concept of usage.

Vincent Cheng vcheng at moszumanska.debian.org
Tue Jun 3 08:09:37 UTC 2014


This is an automated email from the git hooks/post-receive script.

vcheng pushed a commit to branch upstream
in repository gstreamer-vaapi.

commit 0eb40709779b4f0df27d2799eae83cff116248a9
Author: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
Date:   Thu Jan 23 13:30:41 2014 +0100

    context: introduce concept of usage.
    
    Introduce GstVaapiContextUsage so that to explicitly determine the
    usage of a VA context. This is useful in view to simplifying the
    creation of VA context for VPP too.
---
 gst-libs/gst/vaapi/gstvaapicontext.c | 73 +++++++++++++++++++-----------------
 gst-libs/gst/vaapi/gstvaapicontext.h | 15 ++++++++
 gst-libs/gst/vaapi/gstvaapidecoder.c |  1 +
 gst-libs/gst/vaapi/gstvaapiencoder.c |  1 +
 4 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c
index 7524b51..f09e289 100644
--- a/gst-libs/gst/vaapi/gstvaapicontext.c
+++ b/gst-libs/gst/vaapi/gstvaapicontext.c
@@ -144,18 +144,18 @@ context_create (GstVaapiContext * context)
   const GstVaapiContextInfo *const cip = &context->info;
   GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
   guint va_rate_control;
-  VAConfigAttrib attribs[2];
-  guint num_attribs;
+  VAConfigAttrib attribs[2], *attrib = attribs;
   VAContextID context_id;
   VASurfaceID surface_id;
   VAStatus status;
   GArray *surfaces = NULL;
   gboolean success = FALSE;
-  guint i;
+  guint i, value;
 
   if (!context->surfaces && !context_create_surfaces (context))
     goto cleanup;
 
+  /* Create VA surfaces list for vaCreateContext() */
   surfaces = g_array_sized_new (FALSE,
       FALSE, sizeof (VASurfaceID), context->surfaces->len);
   if (!surfaces)
@@ -170,41 +170,47 @@ context_create (GstVaapiContext * context)
   }
   g_assert (surfaces->len == context->surfaces->len);
 
+  /* Reset profile and entrypoint */
   if (!cip->profile || !cip->entrypoint)
     goto cleanup;
   context->va_profile = gst_vaapi_profile_get_va_profile (cip->profile);
   context->va_entrypoint =
       gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint);
 
-  num_attribs = 0;
-  attribs[num_attribs++].type = VAConfigAttribRTFormat;
-  if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE)
-    attribs[num_attribs++].type = VAConfigAttribRateControl;
-
-  GST_VAAPI_DISPLAY_LOCK (display);
-  status = vaGetConfigAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
-      context->va_profile, context->va_entrypoint, attribs, num_attribs);
-  GST_VAAPI_DISPLAY_UNLOCK (display);
-  if (!vaapi_check_status (status, "vaGetConfigAttributes()"))
+  /* Validate VA surface format */
+  attrib->type = VAConfigAttribRTFormat;
+  if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
     goto cleanup;
-  if (!(attribs[0].value & VA_RT_FORMAT_YUV420))
+  if (!(value & VA_RT_FORMAT_YUV420))
     goto cleanup;
-
-  if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) {
-    va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
-    if (va_rate_control == VA_RC_NONE)
-      attribs[1].value = VA_RC_NONE;
-    if ((attribs[1].value & va_rate_control) != va_rate_control) {
-      GST_ERROR ("unsupported %s rate control",
-          string_of_VARateControl (va_rate_control));
-      goto cleanup;
+  attrib->value = VA_RT_FORMAT_YUV420;
+  attrib++;
+
+  switch (cip->usage) {
+    case GST_VAAPI_CONTEXT_USAGE_ENCODE:
+    {
+      /* Rate control */
+      attrib->type = VAConfigAttribRateControl;
+      if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
+        goto cleanup;
+
+      va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
+      if ((value & va_rate_control) != va_rate_control) {
+        GST_ERROR ("unsupported %s rate control",
+            string_of_VARateControl (va_rate_control));
+        goto cleanup;
+      }
+      attrib->value = va_rate_control;
+      attrib++;
+      break;
     }
-    attribs[1].value = va_rate_control;
+    default:
+      break;
   }
 
   GST_VAAPI_DISPLAY_LOCK (display);
   status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
-      context->va_profile, context->va_entrypoint, attribs, num_attribs,
+      context->va_profile, context->va_entrypoint, attribs, attrib - attribs,
       &context->va_config);
   GST_VAAPI_DISPLAY_UNLOCK (display);
   if (!vaapi_check_status (status, "vaCreateConfig()"))
@@ -314,15 +320,14 @@ gst_vaapi_context_reset (GstVaapiContext * context,
     cip->entrypoint = new_cip->entrypoint;
   }
 
-  switch (new_cip->entrypoint) {
-    case GST_VAAPI_ENTRYPOINT_SLICE_ENCODE:
-      if (cip->rc_mode != new_cip->rc_mode) {
-        cip->rc_mode = new_cip->rc_mode;
-        config_changed = TRUE;
-      }
-      break;
-    default:
-      break;
+  if (cip->usage != new_cip->usage) {
+    cip->usage = new_cip->usage;
+    config_changed = TRUE;
+  } else if (new_cip->usage == GST_VAAPI_CONTEXT_USAGE_ENCODE) {
+    if (cip->rc_mode != new_cip->rc_mode) {
+      cip->rc_mode = new_cip->rc_mode;
+      config_changed = TRUE;
+    }
   }
 
   if (size_changed)
diff --git a/gst-libs/gst/vaapi/gstvaapicontext.h b/gst-libs/gst/vaapi/gstvaapicontext.h
index 8112fd4..f19dca5 100644
--- a/gst-libs/gst/vaapi/gstvaapicontext.h
+++ b/gst-libs/gst/vaapi/gstvaapicontext.h
@@ -42,6 +42,20 @@ typedef struct _GstVaapiContext GstVaapiContext;
 typedef struct _GstVaapiContextClass GstVaapiContextClass;
 
 /**
+ * GstVaapiContextUsage:
+ * @GST_VAAPI_CONTEXT_MODE_DECODE: context used for decoding.
+ * @GST_VAAPI_CONTEXT_MODE_ENCODE: context used for encoding.
+ * @GST_VAAPI_CONTEXT_MODE_VPP: context used for video processing.
+ *
+ * The set of supported VA context usages.
+ */
+typedef enum {
+  GST_VAAPI_CONTEXT_USAGE_DECODE = 1,
+  GST_VAAPI_CONTEXT_USAGE_ENCODE,
+  GST_VAAPI_CONTEXT_USAGE_VPP,
+} GstVaapiContextUsage;
+
+/**
  * GstVaapiContextInfo:
  *
  * Structure holding VA context info like encoded size, decoder
@@ -53,6 +67,7 @@ typedef struct _GstVaapiContextClass GstVaapiContextClass;
  */
 struct _GstVaapiContextInfo
 {
+  GstVaapiContextUsage usage;
   GstVaapiProfile profile;
   GstVaapiEntrypoint entrypoint;
   GstVaapiRateControl rc_mode;
diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c
index c724017..9224b1a 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder.c
@@ -952,6 +952,7 @@ gst_vaapi_decoder_ensure_context(
 {
     gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
 
+    cip->usage = GST_VAAPI_CONTEXT_USAGE_DECODE;
     if (decoder->context) {
         if (!gst_vaapi_context_reset(decoder->context, cip))
             return FALSE;
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c
index a0729dd..23f60d2 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder.c
@@ -484,6 +484,7 @@ set_context_info (GstVaapiEncoder * encoder)
 {
   GstVaapiContextInfo *const cip = &encoder->context_info;
 
+  cip->usage = GST_VAAPI_CONTEXT_USAGE_ENCODE;
   cip->profile = encoder->profile;
   cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
   cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gstreamer/gstreamer-vaapi.git



More information about the Pkg-gstreamer-commits mailing list