Drop RECONFIGURE events from glimagesink

These are sent every time our GTK window is resized. The window is always
1024x768 on creation (hard coded in GStreamer). In windowed mode we then
resize it to match the input. In full screen mode further intermediate
sizes are set by the window manager until it's actually full screen.

Each resize sends a RECONFIGURE which forces reallocation of most
ION backed buffers. Since some are in flight we can run out of CMA
memory during the process for higher resolution frames.

This wasn't an issue in older GStreamer because the glmixer in
plugins-bad ate the events. glmixer in plugins-base is more clever and
can forward the events properly but this isn't needed in our use case.
We always use the same source resolution in the pipeline regardless of
sink size, and rely on the sink for scaling.

The RECONFIGURE can thus safely be dropped to avoid OOM.

Change-Id: I5dd8f8849d27e085e338e7219fc51963095e82f7
diff --git a/edgetpuvision/gstreamer.py b/edgetpuvision/gstreamer.py
index 96c0d56..efd37c1 100644
--- a/edgetpuvision/gstreamer.py
+++ b/edgetpuvision/gstreamer.py
@@ -315,6 +315,14 @@
                     allocation.width, allocation.height)
             return False
 
+        # Listens for and drops RECONFIGURE events from glimagesink to avoid costly memory
+        # reallocations when window size changes. These aren't needed in our use case.
+        def on_event_probe(pad, info, *data):
+            event = info.get_event()
+            if event.type == Gst.EventType.RECONFIGURE:
+                return Gst.PadProbeReturn.DROP
+            return Gst.PadProbeReturn.OK
+
         window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
         window.set_title(WINDOW_TITLE)
         window.set_default_size(layout.render_size.width, layout.render_size.height)
@@ -326,6 +334,7 @@
         drawing_area.realize()
 
         glsink = pipeline.get_by_name('glsink')
+        glsink.get_static_pad('sink').add_probe(Gst.PadProbeType.EVENT_UPSTREAM, on_event_probe)
         set_display_contexts(glsink, drawing_area)
         drawing_area.connect('draw', on_widget_draw)
         drawing_area.connect('configure-event', on_widget_configure, glsink)