encoder: notify the encoder of the submitted packed headers.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 23 Jan 2014 14:13:06 +0000 (15:13 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 23 Jan 2014 14:48:58 +0000 (15:48 +0100)
Make sure to configure the encoder with the set of packed headers we
intend to generate and submit. i.e. make selection of packed headers
to submit more robust.

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_mpeg2.c
gst-libs/gst/vaapi/gstvaapiencoder_priv.h

index 92a591e..96f1499 100644 (file)
@@ -144,7 +144,7 @@ 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], *attrib = attribs;
+  VAConfigAttrib attribs[3], *attrib = attribs;
   VAContextID context_id;
   VASurfaceID surface_id;
   VAStatus status;
@@ -204,6 +204,21 @@ context_create (GstVaapiContext * context)
       }
       attrib->value = va_rate_control;
       attrib++;
+
+      /* Packed headers */
+      if (config->packed_headers) {
+        attrib->type = VAConfigAttribEncPackedHeaders;
+        if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
+          goto cleanup;
+
+        if ((value & config->packed_headers) != config->packed_headers) {
+          GST_ERROR ("unsupported packed headers 0x%08x",
+              config->packed_headers & ~(value & config->packed_headers));
+          goto cleanup;
+        }
+        attrib->value = config->packed_headers;
+        attrib++;
+      }
       break;
     }
     default:
@@ -250,6 +265,11 @@ context_update_config_encoder (GstVaapiContext * context,
     config->rc_mode = new_config->rc_mode;
     config_changed = TRUE;
   }
+
+  if (config->packed_headers != new_config->packed_headers) {
+    config->packed_headers = new_config->packed_headers;
+    config_changed = TRUE;
+  }
   return config_changed;
 }
 
index 680dc3e..24ba697 100644 (file)
@@ -59,12 +59,14 @@ typedef enum {
 /**
  * GstVaapiConfigInfoEncoder:
  * @rc_mode: rate-control mode (#GstVaapiRateControl).
+ * @packed_headers: notify encoder that packed headers are submitted (mask).
  *
  * Extra configuration for encoding.
  */
 struct _GstVaapiConfigInfoEncoder
 {
   GstVaapiRateControl rc_mode;
+  guint packed_headers;
 };
 
 /**
index 550e3fa..89eb579 100644 (file)
@@ -534,14 +534,24 @@ get_config_attribute (GstVaapiEncoder * encoder, VAConfigAttribType type,
   return TRUE;
 }
 
-/* Determines the set of required packed headers */
-static void
-ensure_packed_headers (GstVaapiEncoder * encoder)
+/* Determines the set of supported packed headers */
+static guint
+get_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);
+  const GstVaapiEncoderClassData *const cdata =
+      GST_VAAPI_ENCODER_GET_CLASS (encoder)->class_data;
+  guint value;
+
+  if (encoder->got_packed_headers)
+    return encoder->packed_headers;
+
+  if (!get_config_attribute (encoder, VAConfigAttribEncPackedHeaders, &value))
+    value = 0;
+  GST_INFO ("supported packed headers: 0x%08x", value);
+
+  encoder->got_packed_headers = TRUE;
+  encoder->packed_headers = cdata->packed_headers & value;
+  return encoder->packed_headers;
 }
 
 /* Updates video context */
@@ -560,6 +570,7 @@ set_context_info (GstVaapiEncoder * encoder)
 
   memset (config, 0, sizeof (*config));
   config->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
+  config->packed_headers = get_packed_headers (encoder);
 }
 
 /* Ensures the underlying VA context for encoding is created */
@@ -602,7 +613,6 @@ 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 22845e6..9f90ea2 100644 (file)
   (GST_VAAPI_ENCODER_TUNE_MASK (NONE) |                 \
    GST_VAAPI_ENCODER_TUNE_MASK (HIGH_COMPRESSION))
 
+/* Supported set of VA packed headers, within this implementation */
+#define SUPPORTED_PACKED_HEADERS                \
+  (VA_ENC_PACKED_HEADER_SEQUENCE |              \
+   VA_ENC_PACKED_HEADER_PICTURE)
+
 #define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_NONE        0
 #define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_LOW         1
 #define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_MEDIUM      2
index d9938cb..4536365 100644 (file)
 #define SUPPORTED_TUNE_OPTIONS \
   (GST_VAAPI_ENCODER_TUNE_MASK (NONE))
 
+/* Supported set of VA packed headers, within this implementation */
+#define SUPPORTED_PACKED_HEADERS                \
+  (VA_ENC_PACKED_HEADER_SEQUENCE |              \
+   VA_ENC_PACKED_HEADER_PICTURE)
+
 static gboolean
 gst_bit_writer_write_sps (GstBitWriter * bitwriter,
     const VAEncSequenceParameterBufferMPEG2 * seq_param);
index 96b0d1e..5cf748a 100644 (file)
@@ -225,6 +225,7 @@ struct _GstVaapiEncoder
   GAsyncQueue *codedbuf_queue;
   guint32 num_codedbuf_queued;
 
+  guint got_packed_headers:1;
   guint got_rate_control_mask:1;
 };
 
@@ -232,6 +233,7 @@ struct _GstVaapiEncoderClassData
 {
   /*< private >*/
   GstVaapiCodec codec;
+  guint32 packed_headers;
 
   GType (*rate_control_get_type)(void);
   GstVaapiRateControl default_rate_control;
@@ -255,6 +257,7 @@ struct _GstVaapiEncoderClassData
                                                                         \
   static const GstVaapiEncoderClassData g_class_data = {                \
     .codec = G_PASTE (GST_VAAPI_CODEC_, CODEC),                         \
+    .packed_headers = SUPPORTED_PACKED_HEADERS,                         \
     .rate_control_get_type =                                            \
         G_PASTE (G_PASTE (gst_vaapi_rate_control_, CODEC), _get_type),  \
     .default_rate_control = DEFAULT_RATECONTROL,                        \