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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1571>
This commit is contained in:
Mathieu Duponchelle 2022-01-26 00:02:49 +01:00 committed by GStreamer Marge Bot
parent 6838742801
commit 830d1595b9
7 changed files with 83 additions and 1 deletions

View 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

View 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);

View 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

View 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);

View file

@ -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

View file

@ -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

View 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)