[Bug 646566] Protect against Pad-Parent disappearing

GStreamer (bugzilla.gnome.org) bugzilla at gnome.org
Fri Apr 8 12:57:13 PDT 2011


https://bugzilla.gnome.org/show_bug.cgi?id=646566
  GStreamer | gstreamer (core) | git

--- Comment #23 from Håvard Graff (hgr) <havard.graff at tandberg.com> 2011-04-08 19:57:06 UTC ---
(In reply to comment #20)
> Not really in favour of this approach at all, there must be a better way to do
> this that doesn't involve adding such checks to every single element.
> 
> Also, they're not really correct either, e.g.
> 
>   queue = GST_QUEUE (gst_pad_get_parent (pad));
> 
> might still throw a warning and possibly abort if get_parent() returns NULL,
> which is arguably better than crashing, but still broken.

I thought queue = GST_QUEUE (NULL); was legal?

Anyway, I made these stress-tests you might want? Posting them inline here,
since this bug is now closed... :)


static gboolean keep_going;

static gpointer
query_func (gpointer data)
{
  GstElement * element = GST_ELEMENT (data);
  GstPad * src_pad = gst_element_get_static_pad (element, "src");
  GstQuery * query = gst_query_new_latency ();
  while (keep_going)
    gst_pad_query (src_pad, query);

  gst_query_unref (query);
  gst_object_unref (src_pad);
  return NULL;
}

static gpointer
event_func (gpointer data)
{
  GstElement * element = GST_ELEMENT (data);
  GstPad * src_pad = gst_element_get_static_pad (element, "src");
  GstStructure * event_structure = gst_structure_new ("test-event", NULL);
  GstEvent * event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
event_structure);
  GstPadEventFunction eventfunc = GST_PAD_EVENTFUNC (src_pad);
  g_assert (eventfunc);

  while (keep_going)
    eventfunc (src_pad, gst_event_ref (event));

  gst_event_unref (event);
  gst_object_unref (src_pad);
  return NULL;
}

static gpointer
state_change_and_unparent_func (gpointer data)
{
  GstElement * element = GST_ELEMENT (data);
  GstPad * src_pad = gst_element_get_static_pad (element, "src");
  while (keep_going)
  {
    gst_element_set_state (element, GST_STATE_PLAYING);
    g_usleep (G_USEC_PER_SEC / 10000);
    gst_element_set_state (element, GST_STATE_NULL);
    g_usleep (G_USEC_PER_SEC / 10000);

    gst_object_unparent (GST_OBJECT (src_pad));
    g_usleep (G_USEC_PER_SEC / 10000);
    gst_object_set_parent (GST_OBJECT (src_pad), GST_OBJECT (element));
    g_usleep (G_USEC_PER_SEC / 10000);
  }

  gst_object_unref (src_pad);

  return NULL;
}

static void
test_element_against_racy_upstream_querys (GstElement * element)
{
  GThread * query_thread;
  GThread * state_change_and_unparent_thread;

  keep_going = TRUE;

  query_thread =
    g_thread_create_full (query_func, element, 0, TRUE, TRUE,
      G_THREAD_PRIORITY_NORMAL, NULL);

  state_change_and_unparent_thread =
    g_thread_create_full (state_change_and_unparent_func, element, 0, TRUE,
TRUE,
      G_THREAD_PRIORITY_NORMAL, NULL);

  g_usleep (G_USEC_PER_SEC / 4);

  keep_going = FALSE;
  g_thread_join (query_thread);
  g_thread_join (state_change_and_unparent_thread);
}

static void
test_element_against_racy_upstream_events (GstElement * element)
{
  GThread * event_thread;
  GThread * state_change_and_unparent_thread;

  keep_going = TRUE;

  event_thread =
    g_thread_create_full (event_func, element, 0, TRUE, TRUE,
      G_THREAD_PRIORITY_NORMAL, NULL);

  state_change_and_unparent_thread =
    g_thread_create_full (state_change_and_unparent_func, element, 0, TRUE,
TRUE,
      G_THREAD_PRIORITY_NORMAL, NULL);

  g_usleep (G_USEC_PER_SEC / 4);

  keep_going = FALSE;
  g_thread_join (event_thread);
  g_thread_join (state_change_and_unparent_thread);
}

-- 
Configure bugmail: https://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the gstreamer-bugs mailing list