After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 779058 - caps: simplify creates invalid caps with sets or ranges, intersect fails even more on them
caps: simplify creates invalid caps with sets or ranges, intersect fails even...
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal minor
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-02-22 10:37 UTC by Sebastian Dröge (slomo)
Modified: 2018-11-03 12:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix union of int range and int when extending range (2.66 KB, patch)
2017-03-13 13:17 UTC, Vincent Penquerc'h
committed Details | Review
implement fraction range union (2.95 KB, patch)
2017-03-13 15:24 UTC, Vincent Penquerc'h
none Details | Review
implement fraction range union (4.12 KB, patch)
2017-03-14 14:59 UTC, Vincent Penquerc'h
none Details | Review
implement fraction range union (9.19 KB, patch)
2017-03-15 14:56 UTC, Vincent Penquerc'h
none Details | Review

Description Sebastian Dröge (slomo) 2017-02-22 10:37:01 UTC
intersect() of sets of ranges is broken:

"video/x-h264, framerate=(fraction){ [ 5/1, 240/1 ], [ 3/1, 5/1 ] }"

intersected with itself gives

"video/x-h264, framerate=(fraction){ [ 5/1, 240/1 ], 5/1, { 5/1, [ 3/1, 5/1 ] } }"


There should not be ranges inside sets to begin with, but the intersection result is even worse than that. It's of a different type than the input, and the set contains elements of different types.


And these sets of ranges are caused by simplify():

"video/x-raw, framerate=(fraction) [3/1, 30/1]; video/x-raw, framerate=(fraction) [3/1, 120/1]"

gives simplified

"video/x-raw, framerate=(fraction){ [ 30/1, 60/1 ], [ 3/1, 30/1 ], [ 60/1, 120/1 ] }"
Comment 1 Vincent Penquerc'h 2017-03-13 13:15:21 UTC
I don't quite see that here (on top of 586b34436e889c57f3108e6160f20beb55e61cd7):

#include <gst/gst.h>

#define CAPS "video/x-raw, framerate=(fraction) [3/1, 30/1]; video/x-raw, framerate=(fraction) [3/1, 120/1]"
int
main (int argc, char **argv)
{
  GstCaps *caps;
  char *s;

  gst_init(&argc, &argv);

  caps = gst_caps_from_string(CAPS);
  s = gst_caps_to_string (caps);
  g_print("caps: %s\n", s);
  g_free (s);
  caps = gst_caps_simplify(caps);
  s = gst_caps_to_string (caps);
  g_print ("simplified: %s\n", s);
  g_free (s);
  gst_caps_unref (caps);

  return 0;
}
$ gcc -Wall -W simplify.c `pkg-config --cflags --libs gstreamer-1.0 glib-2.0` && ./a.out 
caps: video/x-raw, framerate=(fraction)[ 3/1, 30/1 ]; video/x-raw, framerate=(fraction)[ 3/1, 120/1 ]
simplified: video/x-raw, framerate=(fraction){ [ 30/1, 120/1 ], [ 3/1, 30/1 ] }

The non-simplified part above is due to:

#if 0
  /* Implement these if needed */
  gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
      gst_value_union_fraction_fraction_range);
  gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
      GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
#endif

I still found a bug in the area though.
Comment 2 Vincent Penquerc'h 2017-03-13 13:17:06 UTC
Created attachment 347834 [details] [review]
fix union of int range and int when extending range

This doesn't fix the bug, just something I found while looking for it.
Comment 3 Vincent Penquerc'h 2017-03-13 15:24:47 UTC
Created attachment 347842 [details] [review]
implement fraction range union
Comment 4 Vincent Penquerc'h 2017-03-13 15:25:38 UTC
$ gcc -Wall -W simplify.c `pkg-config --cflags --libs gstreamer-1.0 glib-2.0` && GST_DEBUG=1 ./a.out 
caps: video/x-raw, framerate=(fraction)[ 3/1, 30/1 ]; video/x-raw, framerate=(fraction)[ 3/1, 120/1 ]
simplified: video/x-raw, framerate=(fraction)[ 3/1, 120/1 ]


Now, since I did not have your original full problem, this might not fix it all.
Comment 5 Vincent Penquerc'h 2017-03-13 15:32:18 UTC
When intersecting the original caps, I get:

$ gcc -Wall -W intersect.c `pkg-config --cflags --libs gstreamer-1.0 glib-2.0` && GST_DEBUG=1 ./a.out 
caps: video/x-h264, framerate=(fraction){ [ 5/1, 240/1 ], [ 3/1, 5/1 ] }
intersected: video/x-h264, framerate=(fraction){ [ 5/1, 240/1 ], [ 3/1, 5/1 ] }

(could be simplified, but _simplify is probably not called there)
Comment 6 Sebastian Dröge (slomo) 2017-03-14 13:15:53 UTC
Comment on attachment 347842 [details] [review]
implement fraction range union

Please add some tests for this while you're at it :)
Comment 7 Sebastian Dröge (slomo) 2017-03-14 13:16:58 UTC
(In reply to Vincent Penquerc'h from comment #1)
> I don't quite see that here (on top of
> 586b34436e889c57f3108e6160f20beb55e61cd7):

Let's keep it open after merging your patches then, I'll double check and write test-case if it's still a problem after your patches. But good bugs you found there :)
Comment 8 Vincent Penquerc'h 2017-03-14 14:59:08 UTC
Created attachment 347923 [details] [review]
implement fraction range union
Comment 9 Sebastian Dröge (slomo) 2017-03-14 16:10:54 UTC
Comment on attachment 347923 [details] [review]
implement fraction range union

maybe some more tests than this single one, similar to what is there for other types already. Also if you have that now already, seems trivial to also add gst_value_union_fraction_fraction_range() or not? :)
Comment 10 Vincent Penquerc'h 2017-03-15 13:10:03 UTC
One thing that's not clear to me is whether fractions set operations should operate like mathematical fractions. I'm guessing yes, but when used as framerate, it kinda makes a difference if the denominators are not the same, and I've previously treated them as being "numerator between bounds, but same denominator". The unit tests for fraction values treats them as mathematical. My union code doesn't (which is fine, as it's conservative, just not optimal).
Comment 11 Sebastian Dröge (slomo) 2017-03-15 13:25:39 UTC
Fractions are everywhere considered like mathematical fractions. 300/10 is the same as 30/1.
Comment 12 Vincent Penquerc'h 2017-03-15 13:58:33 UTC
Hrm. Then this means that my "extending the range" is wrong in the patches above. ie, I consider [10/20 - 30/20] union [31/20 - 60/20] to be [10/20 - 60/20], which isn't right for mathematical fractions...
I will fix.
Comment 13 Vincent Penquerc'h 2017-03-15 14:56:35 UTC
Created attachment 348011 [details] [review]
implement fraction range union
Comment 14 GStreamer system administrator 2018-11-03 12:39:35 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/221.