gst-libs/gst/video/video.c: Add guards to these functions to ensure sane input values.

Original commit message from CVS:
* gst-libs/gst/video/video.c: (gst_video_format_new_caps),
(gst_video_format_to_fourcc), (gst_video_format_get_row_stride),
(gst_video_format_get_pixel_stride),
(gst_video_format_get_component_width),
(gst_video_format_get_component_height),
(gst_video_format_get_component_offset), (gst_video_format_get_size),
(gst_video_format_convert):
Add guards to these functions to ensure sane input values.
* tests/check/libs/video.c:
Fix unit test not to create caps with width=0 and height=0.
This commit is contained in:
Tim-Philipp Müller 2008-04-11 17:13:52 +00:00
parent f0738f6fd3
commit 96a3780816
3 changed files with 48 additions and 4 deletions

View file

@ -1,3 +1,17 @@
2008-04-11 Tim-Philipp Müller <tim at centricular dot net>
* gst-libs/gst/video/video.c: (gst_video_format_new_caps),
(gst_video_format_to_fourcc), (gst_video_format_get_row_stride),
(gst_video_format_get_pixel_stride),
(gst_video_format_get_component_width),
(gst_video_format_get_component_height),
(gst_video_format_get_component_offset), (gst_video_format_get_size),
(gst_video_format_convert):
Add guards to these functions to ensure sane input values.
* tests/check/libs/video.c:
Fix unit test not to create caps with width=0 and height=0.
2008-04-11 Wim Taymans <wim.taymans@collabora.co.uk>
* docs/design/draft-keyframe-force.txt:

View file

@ -373,6 +373,9 @@ GstCaps *
gst_video_format_new_caps (GstVideoFormat format, int width, int height,
int framerate_n, int framerate_d, int par_n, int par_d)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
if (gst_video_format_is_yuv (format)) {
return gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
@ -505,6 +508,8 @@ gst_video_format_from_fourcc (guint32 fourcc)
guint32
gst_video_format_to_fourcc (GstVideoFormat format)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
return GST_MAKE_FOURCC ('I', '4', '2', '0');
@ -729,6 +734,10 @@ int
gst_video_format_get_row_stride (GstVideoFormat format, int component,
int width)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (component >= 0 && component <= 3, 0);
g_return_val_if_fail (width > 0, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
@ -787,6 +796,9 @@ gst_video_format_get_row_stride (GstVideoFormat format, int component,
int
gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (component >= 0 && component <= 3, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
@ -836,6 +848,10 @@ int
gst_video_format_get_component_width (GstVideoFormat format, int component,
int width)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (component >= 0 && component <= 3, 0);
g_return_val_if_fail (width > 0, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
@ -893,6 +909,10 @@ int
gst_video_format_get_component_height (GstVideoFormat format, int component,
int height)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (component >= 0 && component <= 3, 0);
g_return_val_if_fail (height > 0, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
@ -944,6 +964,10 @@ int
gst_video_format_get_component_offset (GstVideoFormat format, int component,
int width, int height)
{
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (component >= 0 && component <= 3, 0);
g_return_val_if_fail (width > 0 && height > 0, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
if (component == 0)
@ -1092,6 +1116,9 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height)
{
int size;
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (width > 0 && height > 0, 0);
switch (format) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
@ -1156,6 +1183,9 @@ gst_video_format_convert (GstVideoFormat format, int width, int height,
gboolean ret = FALSE;
int size;
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
g_return_val_if_fail (width > 0 && height > 0, 0);
size = gst_video_format_get_size (format, width, height);
GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",

View file

@ -480,8 +480,8 @@ GST_START_TEST (test_parse_caps_rgb)
int w = -1, h = -1;
caps = gst_caps_from_string (formats[i].tmpl_caps_string);
gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * i, "height",
G_TYPE_INT, i, "framerate", GST_TYPE_FRACTION, 15, 1,
gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * (i + 1), "height",
G_TYPE_INT, i + 1, "framerate", GST_TYPE_FRACTION, 15, 1,
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
g_assert (gst_caps_is_fixed (caps));
@ -489,8 +489,8 @@ GST_START_TEST (test_parse_caps_rgb)
fail_unless (gst_video_format_parse_caps (caps, &fmt, &w, &h));
fail_unless_equals_int (fmt, formats[i].fmt);
fail_unless_equals_int (w, 2 * i);
fail_unless_equals_int (h, i);
fail_unless_equals_int (w, 2 * (i + 1));
fail_unless_equals_int (h, i + 1);
/* make sure they're serialised back correctly */
caps2 = gst_video_format_new_caps (fmt, w, h, 15, 1, 1, 1);