VideoInfo, AudioInfo: fix usage with python bindings
authorMathieu Duponchelle <mathieu@centricular.com>
Tue, 25 Jan 2022 23:02:49 +0000 (00:02 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 27 Jan 2022 08:36:46 +0000 (08:36 +0000)
* Expose an actual constructor from caps

* Error out in overrides for code that was using the "manual
  allocation" pattern which only worked by chance. Direct
  the script writer to the new_from_caps constructor instead.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-python/-/issues/47

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1571>

subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.c
subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h
subprojects/gst-plugins-base/gst-libs/gst/video/video-info.c
subprojects/gst-plugins-base/gst-libs/gst/video/video-info.h
subprojects/gst-python/gi/overrides/GstAudio.py [new file with mode: 0644]
subprojects/gst-python/gi/overrides/GstVideo.py [new file with mode: 0644]
subprojects/gst-python/gi/overrides/meson.build

index 2fcc6711fbacb641ff596a18af001502ea822a39..f55246d901ff753c584a23737b6bc0bbd7957d60 100644 (file)
@@ -320,6 +320,28 @@ invalid_channel_mask:
   }
 }
 
+/**
+ * gst_audio_info_new_from_caps:
+ * @caps: a #GstCaps
+ *
+ * Parse @caps to generate a #GstAudioInfo.
+ *
+ * Returns: A #GstAudioInfo, or %NULL if @caps couldn't be parsed
+ * Since: 1.20
+ */
+GstAudioInfo *
+gst_audio_info_new_from_caps (const GstCaps * caps)
+{
+  GstAudioInfo *ret = gst_audio_info_new ();
+
+  if (gst_audio_info_from_caps (ret, caps)) {
+    return ret;
+  } else {
+    gst_audio_info_free (ret);
+    return NULL;
+  }
+}
+
 /**
  * gst_audio_info_to_caps:
  * @info: a #GstAudioInfo
index 8cc6d36f16d1c39aa191cd0597d1eb5b2c98a012..51264b9304737c08608464f94d38ce35372d3a26 100644 (file)
@@ -104,6 +104,9 @@ GType gst_audio_info_get_type                (void);
 GST_AUDIO_API
 GstAudioInfo * gst_audio_info_new         (void);
 
+GST_AUDIO_API
+GstAudioInfo * gst_audio_info_new_from_caps (const GstCaps * caps);
+
 GST_AUDIO_API
 void           gst_audio_info_init        (GstAudioInfo *info);
 
index 0269b970fd6544b27e3bc11ba8f4f882302e1ffb..9cf7821f9f439bfc12aebabde5eb516908617398 100644 (file)
@@ -568,6 +568,28 @@ alternate_no_feature:
   }
 }
 
+/**
+ * gst_video_info_new_from_caps:
+ * @caps: a #GstCaps
+ *
+ * Parse @caps to generate a #GstVideoInfo.
+ *
+ * Returns: A #GstVideoInfo, or %NULL if @caps couldn't be parsed
+ * Since: 1.20
+ */
+GstVideoInfo *
+gst_video_info_new_from_caps (const GstCaps * caps)
+{
+  GstVideoInfo *ret = gst_video_info_new ();
+
+  if (gst_video_info_from_caps (ret, caps)) {
+    return ret;
+  } else {
+    gst_video_info_free (ret);
+    return NULL;
+  }
+}
+
 /**
  * gst_video_info_is_equal:
  * @info: a #GstVideoInfo
index d3ff1ba965a66866c7bb0a56032fe34018de25d8..3de617d954b38ccde6d59e0762d39d35fa69bf21 100644 (file)
@@ -436,6 +436,9 @@ GstVideoInfo * gst_video_info_copy        (const GstVideoInfo *info);
 GST_VIDEO_API
 void           gst_video_info_free        (GstVideoInfo *info);
 
+GST_VIDEO_API
+GstVideoInfo * gst_video_info_new_from_caps (const GstCaps * caps);
+
 GST_VIDEO_API
 gboolean       gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat format,
                                            guint width, guint height);
diff --git a/subprojects/gst-python/gi/overrides/GstAudio.py b/subprojects/gst-python/gi/overrides/GstAudio.py
new file mode 100644 (file)
index 0000000..c186371
--- /dev/null
@@ -0,0 +1,16 @@
+from ..module import get_introspection_module
+
+import gi
+gi.require_version('Gst', '1.0')
+
+from gi.repository import Gst  # noqa
+
+GstAudio = get_introspection_module('GstAudio')
+__all__ = []
+
+
+def __audio_info_from_caps(*args):
+    raise NotImplementedError('AudioInfo.from_caps was removed, use AudioInfo.new_from_caps instead')
+
+
+GstAudio.AudioInfo.from_caps = __audio_info_from_caps
diff --git a/subprojects/gst-python/gi/overrides/GstVideo.py b/subprojects/gst-python/gi/overrides/GstVideo.py
new file mode 100644 (file)
index 0000000..2650c11
--- /dev/null
@@ -0,0 +1,16 @@
+from ..module import get_introspection_module
+
+import gi
+gi.require_version('Gst', '1.0')
+
+from gi.repository import Gst  # noqa
+
+GstVideo = get_introspection_module('GstVideo')
+__all__ = []
+
+
+def __video_info_from_caps(*args):
+    raise NotImplementedError('VideoInfo.from_caps was removed, use VideoInfo.new_from_caps instead')
+
+
+GstVideo.VideoInfo.from_caps = __video_info_from_caps
index b2aa334dec46d4b9446a14113ddd49aa89a07a9a..5b87a72a90a8246576f40ccbdc24a507515cbb24 100644 (file)
@@ -1,4 +1,4 @@
-pysources = ['Gst.py', 'GstPbutils.py']
+pysources = ['Gst.py', 'GstPbutils.py', 'GstVideo.py', 'GstAudio.py']
 install_data(pysources,
     install_dir: pygi_override_dir)