encoder: h264: only submit packed headers when required.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 21 Jan 2014 17:35:17 +0000 (18:35 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 22 Jan 2014 17:30:26 +0000 (18:30 +0100)
Make sure to submit the packed headers only if the underlying VA driver
requires those. Currently, only handle packed sequence and picture
headers.

https://bugzilla.gnome.org/show_bug.cgi?id=722737

gst-libs/gst/vaapi/gstvaapicontext.c
gst-libs/gst/vaapi/gstvaapicontext.h
gst-libs/gst/vaapi/gstvaapiencoder.c
gst-libs/gst/vaapi/gstvaapiencoder_h264.c
gst-libs/gst/vaapi/gstvaapiencoder_priv.h

index 06282245398b33a3058c78c5ff35340c62c65bc8..52e9317da1213af718d65aa765a8947a12ab2d48 100644 (file)
@@ -1005,3 +1005,43 @@ error:
     gst_vaapi_context_clear_overlay(context);
     return FALSE;
 }
+
+
+/**
+ * gst_vaapi_context_get_attribute:
+ * @context: a #GstVaapiContext
+ * @type: a VA config attribute type
+ * @out_value_ptr: return location for the config attribute value
+ *
+ * Determines the value for the VA config attribute @type.
+ *
+ * Note: this function only returns success if the VA driver does
+ * actually know about this config attribute type and that it returned
+ * a valid value for it.
+ *
+ * Return value: %TRUE if the VA driver knows about the requested
+ *   config attribute and returned a valid value, %FALSE otherwise
+ */
+gboolean
+gst_vaapi_context_get_attribute(GstVaapiContext *context,
+    VAConfigAttribType type, guint *out_value_ptr)
+{
+    VAConfigAttrib attrib;
+    VAStatus status;
+
+    g_return_val_if_fail(context != NULL, FALSE);
+
+    GST_VAAPI_OBJECT_LOCK_DISPLAY(context);
+    attrib.type = type;
+    status = vaGetConfigAttributes(GST_VAAPI_OBJECT_VADISPLAY(context),
+        gst_vaapi_profile_get_va_profile(context->info.profile),
+        gst_vaapi_entrypoint_get_va_entrypoint(context->info.entrypoint),
+        &attrib, 1);
+    GST_VAAPI_OBJECT_UNLOCK_DISPLAY(context);
+    if (!vaapi_check_status(status, "vaGetConfiAttributes()"))
+        return FALSE;
+
+    if (out_value_ptr)
+        *out_value_ptr = attrib.value;
+    return TRUE;
+}
index 771f505469fcaf9042da5652a830a3057587651e..22ce7527865209af6fdefc1de1bb58d453fda653 100644 (file)
@@ -127,6 +127,11 @@ gst_vaapi_context_apply_composition(
     GstVideoOverlayComposition *composition
 );
 
+G_GNUC_INTERNAL
+gboolean
+gst_vaapi_context_get_attribute(GstVaapiContext *context,
+    VAConfigAttribType type, guint *out_value_ptr);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_CONTEXT_H */
index b9767f154394b5622c460e95b49f8b5b315b9994..7b3d00965bf9e16f5e654e37e010b4bd822e2e0a 100644 (file)
@@ -466,6 +466,16 @@ error_invalid_framerate:
   }
 }
 
+/* Determines the set of required packed headers */
+static void
+ensure_packed_headers (GstVaapiEncoder * encoder)
+{
+  if (!gst_vaapi_context_get_attribute (encoder->context,
+          VAConfigAttribEncPackedHeaders, &encoder->packed_headers))
+    encoder->packed_headers = 0;
+  GST_INFO ("packed headers mask: 0x%08x", encoder->packed_headers);
+}
+
 /* Updates video context */
 static void
 set_context_info (GstVaapiEncoder * encoder)
@@ -520,6 +530,7 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
 
   if (!gst_vaapi_encoder_ensure_context (encoder))
     goto error_reset_context;
+  ensure_packed_headers (encoder);
 
   codedbuf_size = encoder->codedbuf_pool ?
       gst_vaapi_coded_buffer_pool_get_buffer_size (GST_VAAPI_CODED_BUFFER_POOL
index 1fc440e7240ec977463075b454ec724ee62563d0..8b7f2834f1033fddd46140a408409b36a132bd54 100644 (file)
@@ -1366,7 +1366,8 @@ ensure_sequence (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
     goto error;
 
   if (picture->type == GST_VAAPI_PICTURE_TYPE_I &&
-      !add_packed_sequence_header (encoder, picture, sequence))
+      (GST_VAAPI_ENCODER_PACKED_HEADERS (encoder) & VAEncPackedHeaderH264_SPS)
+      && !add_packed_sequence_header (encoder, picture, sequence))
     goto error;
   gst_vaapi_enc_picture_set_sequence (picture, sequence);
   gst_vaapi_codec_object_replace (&sequence, NULL);
@@ -1430,7 +1431,8 @@ ensure_picture (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture,
     return FALSE;
 
   if (picture->type == GST_VAAPI_PICTURE_TYPE_I &&
-      !add_packed_picture_header (encoder, picture)) {
+      (GST_VAAPI_ENCODER_PACKED_HEADERS (encoder) & VAEncPackedHeaderH264_PPS)
+      && !add_packed_picture_header (encoder, picture)) {
     GST_ERROR ("set picture packed header failed");
     return FALSE;
   }
index abe3309a4dd0154ddab04ca39752b16e044e1bce..43e5ad2c7de50073d423f7fde2b5cd0ae0b7d5ff 100644 (file)
@@ -40,6 +40,18 @@ G_BEGIN_DECLS
 #define GST_VAAPI_ENCODER_GET_CLASS(obj) \
     GST_VAAPI_ENCODER_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(obj))
 
+/**
+ * GST_VAAPI_ENCODER_PACKED_HEADERS:
+ * @encoder: a #GstVaapiEncoder
+ *
+ * Macro that evaluates to the required set of VA packed headers that
+ * need to be submitted along with the corresponding param buffers.
+ * This is an internal macro that does not do any run-time type check.
+ */
+#undef  GST_VAAPI_ENCODER_PACKED_HEADERS
+#define GST_VAAPI_ENCODER_PACKED_HEADERS(encoder) \
+    GST_VAAPI_ENCODER_CAST(encoder)->packed_headers
+
 /**
  * GST_VAAPI_ENCODER_DISPLAY:
  * @encoder: a #GstVaapiEncoder
@@ -191,6 +203,7 @@ struct _GstVaapiEncoder
   GstVaapiContext *context;
   GstVaapiContextInfo context_info;
   GstVaapiEncoderTune tune;
+  guint packed_headers;
 
   VADisplay va_display;
   VAContextID va_context;