mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 17:50:36 +00:00
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:
parent
f0738f6fd3
commit
96a3780816
3 changed files with 48 additions and 4 deletions
14
ChangeLog
14
ChangeLog
|
@ -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>
|
2008-04-11 Wim Taymans <wim.taymans@collabora.co.uk>
|
||||||
|
|
||||||
* docs/design/draft-keyframe-force.txt:
|
* docs/design/draft-keyframe-force.txt:
|
||||||
|
|
|
@ -373,6 +373,9 @@ GstCaps *
|
||||||
gst_video_format_new_caps (GstVideoFormat format, int width, int height,
|
gst_video_format_new_caps (GstVideoFormat format, int width, int height,
|
||||||
int framerate_n, int framerate_d, int par_n, int par_d)
|
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)) {
|
if (gst_video_format_is_yuv (format)) {
|
||||||
return gst_caps_new_simple ("video/x-raw-yuv",
|
return gst_caps_new_simple ("video/x-raw-yuv",
|
||||||
"format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
|
"format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
|
||||||
|
@ -505,6 +508,8 @@ gst_video_format_from_fourcc (guint32 fourcc)
|
||||||
guint32
|
guint32
|
||||||
gst_video_format_to_fourcc (GstVideoFormat format)
|
gst_video_format_to_fourcc (GstVideoFormat format)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
return GST_MAKE_FOURCC ('I', '4', '2', '0');
|
return GST_MAKE_FOURCC ('I', '4', '2', '0');
|
||||||
|
@ -729,6 +734,10 @@ int
|
||||||
gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
||||||
int width)
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
@ -787,6 +796,9 @@ gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
||||||
int
|
int
|
||||||
gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
@ -836,6 +848,10 @@ int
|
||||||
gst_video_format_get_component_width (GstVideoFormat format, int component,
|
gst_video_format_get_component_width (GstVideoFormat format, int component,
|
||||||
int width)
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
@ -893,6 +909,10 @@ int
|
||||||
gst_video_format_get_component_height (GstVideoFormat format, int component,
|
gst_video_format_get_component_height (GstVideoFormat format, int component,
|
||||||
int height)
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
@ -944,6 +964,10 @@ int
|
||||||
gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
||||||
int width, int height)
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
if (component == 0)
|
if (component == 0)
|
||||||
|
@ -1092,6 +1116,9 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height)
|
||||||
{
|
{
|
||||||
int size;
|
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) {
|
switch (format) {
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
@ -1156,6 +1183,9 @@ gst_video_format_convert (GstVideoFormat format, int width, int height,
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
int size;
|
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);
|
size = gst_video_format_get_size (format, width, height);
|
||||||
|
|
||||||
GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
|
GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
|
||||||
|
|
|
@ -480,8 +480,8 @@ GST_START_TEST (test_parse_caps_rgb)
|
||||||
int w = -1, h = -1;
|
int w = -1, h = -1;
|
||||||
|
|
||||||
caps = gst_caps_from_string (formats[i].tmpl_caps_string);
|
caps = gst_caps_from_string (formats[i].tmpl_caps_string);
|
||||||
gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * i, "height",
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * (i + 1), "height",
|
||||||
G_TYPE_INT, i, "framerate", GST_TYPE_FRACTION, 15, 1,
|
G_TYPE_INT, i + 1, "framerate", GST_TYPE_FRACTION, 15, 1,
|
||||||
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
|
||||||
g_assert (gst_caps_is_fixed (caps));
|
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 (gst_video_format_parse_caps (caps, &fmt, &w, &h));
|
||||||
fail_unless_equals_int (fmt, formats[i].fmt);
|
fail_unless_equals_int (fmt, formats[i].fmt);
|
||||||
fail_unless_equals_int (w, 2 * i);
|
fail_unless_equals_int (w, 2 * (i + 1));
|
||||||
fail_unless_equals_int (h, i);
|
fail_unless_equals_int (h, i + 1);
|
||||||
|
|
||||||
/* make sure they're serialised back correctly */
|
/* make sure they're serialised back correctly */
|
||||||
caps2 = gst_video_format_new_caps (fmt, w, h, 15, 1, 1, 1);
|
caps2 = gst_video_format_new_caps (fmt, w, h, 15, 1, 1, 1);
|
||||||
|
|
Loading…
Reference in a new issue