openjpegenc: fail negotation in handle_frame if alignment mismatch
authorAaron Boxer <aaron.boxer@collabora.com>
Mon, 13 Jan 2020 19:00:38 +0000 (14:00 -0500)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 12 Nov 2020 13:53:47 +0000 (13:53 +0000)
If encoder is in stripe mode, then downstream must also support stripe

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1800>

ext/openjpeg/gstopenjpegenc.c

index 307d753..6186222 100644 (file)
@@ -618,7 +618,6 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
   GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (encoder);
   GstCaps *allowed_caps, *caps;
   GstStructure *s;
-  const gchar *str = NULL;
   const gchar *colorspace = NULL;
   GstJPEG2000Sampling sampling = GST_JPEG2000_SAMPLING_NONE;
   gint ncomps;
@@ -747,16 +746,6 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
   } else
     g_return_val_if_reached (FALSE);
 
-  if (stripe_mode) {
-    str = gst_structure_get_string (s, "alignment");
-    if (!str || strcmp (str, "stripe") != 0) {
-      GST_ERROR_OBJECT (self,
-          "Number of stripes set to %d, but alignment=stripe not supported downstream",
-          self->num_stripes);
-      return FALSE;
-    }
-  }
-
   if (sampling != GST_JPEG2000_SAMPLING_NONE) {
     caps = gst_caps_new_simple (gst_structure_get_name (s),
         "colorspace", G_TYPE_STRING, colorspace,
@@ -941,9 +930,29 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder,
   opj_image_t *image;
   GstVideoFrame vframe;
   guint i;
+  GstCaps *current_caps;
+  GstStructure *s;
+  gboolean stripe_mode =
+      self->num_stripes != GST_OPENJPEG_ENC_DEFAULT_NUM_STRIPES;
 
   GST_DEBUG_OBJECT (self, "Handling frame");
 
+  current_caps = gst_pad_get_current_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
+  s = gst_caps_get_structure (current_caps, 0);
+
+  if (stripe_mode) {
+    const gchar *str = gst_structure_get_string (s, "alignment");
+    if (g_strcmp0 (str, "stripe") != 0) {
+      GST_ERROR_OBJECT (self,
+          "Number of stripes set to %d, but alignment=stripe not supported downstream",
+          self->num_stripes);
+      gst_video_codec_frame_unref (frame);
+      ret = GST_FLOW_NOT_NEGOTIATED;
+      goto done;
+    }
+  }
+
+
   for (i = 0; i < self->num_stripes; ++i) {
     enc = opj_create_compress (self->codec_format);
     if (!enc)
@@ -1029,6 +1038,9 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder,
 
   }
 
+done:
+  if (current_caps)
+    gst_caps_unref (current_caps);
   return ret;
 
 initialization_error: