mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-27 01:28:34 +00:00
gstvideo: Add gst_video_get_size_from_caps function
gst_video_get_size_from_caps () allows easy calculation of the raw video buffer size from some fixed video caps. API: gst_video_get_size_from_caps()
This commit is contained in:
parent
c475464600
commit
ad2010d379
3 changed files with 57 additions and 3 deletions
|
@ -325,7 +325,7 @@ gst_video_parse_caps_chroma_site (GstCaps * caps)
|
|||
* Returns: TRUE if @caps was parsed correctly.
|
||||
*/
|
||||
gboolean
|
||||
gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
|
||||
gst_video_format_parse_caps (const GstCaps * caps, GstVideoFormat * format,
|
||||
int *width, int *height)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
@ -2066,6 +2066,36 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_get_size_from_caps:
|
||||
* @caps: a pointer to #GstCaps
|
||||
* @size: a pointer to a gint that will be assigned the size (in bytes) of a video frame with the given caps
|
||||
*
|
||||
* Calculates the total number of bytes in the raw video format for the given
|
||||
* caps. This number should be used when allocating a buffer for raw video.
|
||||
*
|
||||
* Since: 0.10.34
|
||||
*
|
||||
* Returns: %TRUE if the size could be calculated from the caps
|
||||
*/
|
||||
gboolean
|
||||
gst_video_get_size_from_caps (const GstCaps * caps, gint * size)
|
||||
{
|
||||
GstVideoFormat format = 0;
|
||||
gint width = 0, height = 0;
|
||||
|
||||
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
|
||||
g_return_val_if_fail (size != NULL, FALSE);
|
||||
|
||||
if (gst_video_format_parse_caps (caps, &format, &width, &height) == FALSE) {
|
||||
GST_WARNING ("Could not parse caps: %" GST_PTR_FORMAT, caps);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*size = gst_video_format_get_size (format, width, height);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_format_convert:
|
||||
* @format: a #GstVideoFormat
|
||||
|
|
|
@ -446,8 +446,8 @@ gboolean gst_video_calculate_display_ratio (guint *dar_n, guint *dar_d,
|
|||
guint video_par_n, guint video_par_d,
|
||||
guint display_par_n, guint display_par_d);
|
||||
|
||||
gboolean gst_video_format_parse_caps (GstCaps *caps, GstVideoFormat *format,
|
||||
int *width, int *height);
|
||||
gboolean gst_video_format_parse_caps (const GstCaps *caps,
|
||||
GstVideoFormat *format, int *width, int *height);
|
||||
gboolean gst_video_format_parse_caps_interlaced (GstCaps *caps, gboolean *interlaced);
|
||||
gboolean gst_video_parse_caps_framerate (GstCaps *caps,
|
||||
int *fps_n, int *fps_d);
|
||||
|
@ -480,6 +480,7 @@ int gst_video_format_get_component_height (GstVideoFormat format, int component,
|
|||
int gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
||||
int width, int height);
|
||||
int gst_video_format_get_size (GstVideoFormat format, int width, int height);
|
||||
gboolean gst_video_get_size_from_caps (const GstCaps * caps, gint * size);
|
||||
gboolean gst_video_format_convert (GstVideoFormat format, int width, int height,
|
||||
int fps_n, int fps_d,
|
||||
GstFormat src_format, gint64 src_value,
|
||||
|
|
|
@ -748,6 +748,28 @@ GST_START_TEST (test_convert_frame_async)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_video_size_from_caps)
|
||||
{
|
||||
gint size;
|
||||
guint32 fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
|
||||
GstCaps *caps = gst_caps_new_simple ("video/x-raw-yuv",
|
||||
"format", GST_TYPE_FOURCC, fourcc,
|
||||
"width", G_TYPE_INT, 640,
|
||||
"height", G_TYPE_INT, 480,
|
||||
"framerate", GST_TYPE_FRACTION, 25, 1,
|
||||
NULL);
|
||||
|
||||
fail_unless (gst_video_get_size_from_caps (caps, &size));
|
||||
fail_unless (size ==
|
||||
gst_video_format_get_size (gst_video_format_from_fourcc (fourcc), 640,
|
||||
480));
|
||||
fail_unless (size == (640 * 480 * 12 / 8));
|
||||
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static Suite *
|
||||
video_suite (void)
|
||||
{
|
||||
|
@ -763,6 +785,7 @@ video_suite (void)
|
|||
tcase_add_test (tc_chain, test_events);
|
||||
tcase_add_test (tc_chain, test_convert_frame);
|
||||
tcase_add_test (tc_chain, test_convert_frame_async);
|
||||
tcase_add_test (tc_chain, test_video_size_from_caps);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue