From 830d1595b94ee855b664b2101f0832fbd0181b9c Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 26 Jan 2022 00:02:49 +0100 Subject: [PATCH] VideoInfo, AudioInfo: fix usage with python bindings * 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: --- .../gst-libs/gst/audio/audio-info.c | 22 ++++++++++++++++++++++ .../gst-libs/gst/audio/audio-info.h | 3 +++ .../gst-libs/gst/video/video-info.c | 22 ++++++++++++++++++++++ .../gst-libs/gst/video/video-info.h | 3 +++ subprojects/gst-python/gi/overrides/GstAudio.py | 16 ++++++++++++++++ subprojects/gst-python/gi/overrides/GstVideo.py | 16 ++++++++++++++++ subprojects/gst-python/gi/overrides/meson.build | 2 +- 7 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 subprojects/gst-python/gi/overrides/GstAudio.py create mode 100644 subprojects/gst-python/gi/overrides/GstVideo.py diff --git a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.c b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.c index 2fcc671..f55246d 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.c @@ -321,6 +321,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 * diff --git a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h index 8cc6d36..51264b9 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h @@ -105,6 +105,9 @@ 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); GST_AUDIO_API diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.c b/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.c index 0269b97..9cf7821 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.c @@ -569,6 +569,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 * @other: a #GstVideoInfo diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.h b/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.h index d3ff1ba..3de617d 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-info.h @@ -437,6 +437,9 @@ 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 index 0000000..c186371 --- /dev/null +++ b/subprojects/gst-python/gi/overrides/GstAudio.py @@ -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 index 0000000..2650c11 --- /dev/null +++ b/subprojects/gst-python/gi/overrides/GstVideo.py @@ -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 diff --git a/subprojects/gst-python/gi/overrides/meson.build b/subprojects/gst-python/gi/overrides/meson.build index b2aa334..5b87a72 100644 --- a/subprojects/gst-python/gi/overrides/meson.build +++ b/subprojects/gst-python/gi/overrides/meson.build @@ -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) -- 2.7.4