Example #1
0
static GstElement *
gst_switch_request_new_case (GstSwitch * swit, GstPadTemplate * templ,
    const GstCaps * caps)
{
  GstElement *swcase = NULL;
  gchar *name;

  name = g_strdup_printf ("case_%d", GST_BIN_NUMCHILDREN (GST_BIN (swit)));
  swcase = gst_element_factory_make (CASE_ELEMENT_NAME, name);
  g_free (name);

  if (!gst_bin_add (GST_BIN (swit), swcase))
    goto error_bin_add_case;

  INFO ("new %s for %s.%s (%d cases)", GST_ELEMENT_NAME (swcase),
      GST_ELEMENT_NAME (swit), GST_PAD_TEMPLATE_NAME_TEMPLATE (templ),
      GST_BIN_NUMCHILDREN (GST_BIN (swit)));

  return swcase;

error_bin_add_case:
  {
    GST_ERROR_OBJECT (swit, "Bin add failed for %s.%s",
        GST_ELEMENT_NAME (swit), GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
    if (swcase)
      gst_object_unref (GST_OBJECT (swcase));
    return NULL;
  }
}
Example #2
0
static GstPad *
dvb_base_bin_request_new_pad (GstElement * element,
    GstPadTemplate * templ, const gchar * name)
{
  GstPad *pad;
  GstPad *ghost;
  gchar *pad_name;

  if (name == NULL)
    name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);

  pad =
      gst_element_get_request_pad (GST_DVB_BASE_BIN (element)->mpegtsparse,
      name);
  if (pad == NULL)
    return NULL;

  pad_name = gst_pad_get_name (pad);
  ghost = gst_ghost_pad_new (pad_name, pad);
  g_free (pad_name);
  gst_element_add_pad (element, ghost);
  gst_element_no_more_pads (element);

  return ghost;
}
Example #3
0
static GstPad *
dvb_base_bin_request_new_pad (GstElement * element,
    GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
{
  DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (element);
  GstPad *pad;
  GstPad *ghost;
  gchar *pad_name;

  GST_DEBUG_OBJECT (dvbbasebin, "New pad requested %s", GST_STR_NULL (name));

  if (dvbbasebin->tsparse == NULL)
    return NULL;

  if (name == NULL)
    name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);

  pad = gst_element_get_request_pad (dvbbasebin->tsparse, name);
  if (pad == NULL)
    return NULL;

  pad_name = gst_pad_get_name (pad);
  ghost = gst_ghost_pad_new (pad_name, pad);
  g_free (pad_name);
  gst_element_add_pad (element, ghost);

  return ghost;
}
Example #4
0
static GstGhostPad *
gst_switch_request_new_sink_pad (GstSwitch * swit,
    GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
{
  GstElement *swcase = gst_switch_select (swit, templ, name, caps);
  GstGhostPad *pad = NULL;
  GstPad *basepad = NULL;

  if (!swcase)
    goto error_no_case;

  basepad = gst_switch_get_case_sink_pad (swcase, caps);

  if (!basepad)
    goto error_no_basepad;

  if (gst_pad_is_linked (basepad))
    goto error_basepad_already_linked;

  if (name) {
    pad = GST_GHOST_PAD (gst_ghost_pad_new (name, basepad));
  } else {
    name = g_strdup_printf ("sink_%u", GST_ELEMENT (swit)->numsinkpads);
    pad = GST_GHOST_PAD (gst_ghost_pad_new (name, basepad));
    g_free ((gchar *) name);
  }

  gst_object_unref (basepad);
  return pad;

error_no_case:
  {
    GST_ERROR_OBJECT (swit, "Failed to request new case for %s.%s",
        GST_ELEMENT_NAME (swit), GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
    return NULL;
  }

error_no_basepad:
  {
    GST_ERROR_OBJECT (swit, "Failed to request new pad on %s",
        GST_ELEMENT_NAME (swcase));
    return NULL;
  }

error_basepad_already_linked:
  {
    GstPad *pp = GST_PAD_PEER (basepad);
    GstElement *ppp = GST_PAD_PARENT (pp);
    GST_ERROR_OBJECT (swit, "Pad %s.%s already linked with %s.%s",
        GST_ELEMENT_NAME (swcase), GST_PAD_NAME (basepad),
        GST_ELEMENT_NAME (ppp), GST_PAD_NAME (pp));

    gst_object_unref (basepad);
    return NULL;
  }
}
Example #5
0
static char *
gst_mxf_mux_create_pad_name (GstPadTemplate * templ, guint id)
{
  GString *string;

  string = g_string_new (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
  g_string_truncate (string, string->len - 2);
  g_string_append_printf (string, "%u", id);

  return g_string_free (string, FALSE);
}
static void
gst_pad_template_dispose (GObject * object)
{
  GstPadTemplate *templ = GST_PAD_TEMPLATE (object);

  g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
  if (GST_PAD_TEMPLATE_CAPS (templ)) {
    gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
  }

  G_OBJECT_CLASS (parent_class)->dispose (object);
}
Example #7
0
static GstPad *
gst_tcp_mix_src_request_new_pad (GstElement * element, GstPadTemplate * templ,
    const gchar * unused, const GstCaps * caps)
{
  GstTCPMixSrc *src = GST_TCP_MIX_SRC (element);
  GstPad *srcpad;
  gchar *name;
  gboolean res;
  int num;

  //g_print ("%s:%d: %s\n", __FILE__, __LINE__, __FUNCTION__);

  GST_INFO_OBJECT (src, "Requesting new pad %s.%s (caps: %s)",
      GST_ELEMENT_NAME (src), GST_PAD_TEMPLATE_NAME_TEMPLATE (templ),
      gst_caps_to_string (caps));

  GST_OBJECT_LOCK (src);
  num = g_list_length (GST_ELEMENT_PADS (src));
  name = g_strdup_printf ("src_%u", num);
  srcpad = GST_PAD_CAST (g_object_new (GST_TYPE_TCP_MIX_SRC_PAD,
          "name", name, "direction", templ->direction, "template", templ,
          NULL));
  g_free (name);
  GST_OBJECT_UNLOCK (src);


  // see: gst_tcp_mix_src_activate_push
  gst_pad_set_active (srcpad, TRUE);
  gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE);

  gst_pad_set_activatemode_function (srcpad,
      (GstPadActivateModeFunction) gst_tcp_mix_src_activate_mode);
  gst_pad_set_query_function (srcpad, gst_tcp_mix_src_query);
  gst_pad_set_event_function (srcpad, gst_tcp_mix_src_event);
  gst_pad_set_getrange_function (srcpad, gst_tcp_mix_src_getrange);

  //GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PROXY_CAPS);

  //INFO ("add-pad: %s.%s", GST_ELEMENT_NAME (src), GST_PAD_NAME (srcpad));
  res = gst_element_add_pad (GST_ELEMENT_CAST (src), srcpad);

  gst_tcp_mix_src_start (src, GST_TCP_MIX_SRC_PAD (srcpad));

  if (G_UNLIKELY (!res)) {
    GST_ERROR_OBJECT (src, "Failed to add new pad");
  }

  return srcpad;
}
Example #8
0
static GstPad *
gst_switch_request_new_pad (GstElement * element,
    GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
{
  GstSwitch *swit = GST_SWITCH (element);
  GstGhostPad *pad;

  INFO ("requesting: %s.%s (%d=%d+%d)", GST_ELEMENT_NAME (swit),
      name ? name : GST_PAD_TEMPLATE_NAME_TEMPLATE (templ),
      element->numpads, element->numsrcpads, element->numsinkpads);

  GST_SWITCH_LOCK (swit);

  switch (GST_PAD_TEMPLATE_DIRECTION (templ)) {
    case GST_PAD_SRC:
      pad = gst_switch_request_new_src_pad (swit, templ, name, caps);
      break;
    case GST_PAD_SINK:
      pad = gst_switch_request_new_sink_pad (swit, templ, name, caps);
      break;
    default:
      pad = NULL;
      break;
  }

  if (pad) {
    gst_pad_set_active (GST_PAD (pad), TRUE);

    if (gst_element_add_pad (GST_ELEMENT (swit), GST_PAD (pad))) {
      GstPad *basepad = gst_ghost_pad_get_target (pad);
      GstElement *swcase = GST_ELEMENT (GST_PAD_PARENT (basepad));

      GST_OBJECT_FLAG_SET (basepad, GST_SWITCH_PAD_FLAG_GHOSTED);

      GST_DEBUG_OBJECT (swit, "New %s:%s on %s:%s",
          GST_ELEMENT_NAME (swit), GST_PAD_NAME (pad),
          GST_ELEMENT_NAME (swcase), GST_PAD_NAME (basepad));

      INFO ("requested %s.%s on %s.%s",
          GST_ELEMENT_NAME (swit), GST_PAD_NAME (pad),
          GST_ELEMENT_NAME (swcase), GST_PAD_NAME (basepad));
    }
  }

  GST_SWITCH_UNLOCK (swit);

  return GST_PAD (pad);
}
static gboolean
connect_element (InsanityTest * test, GstElement * demux)
{
  GList *pads;
  gboolean res = TRUE;
  gboolean dynamic = FALSE;
  GList *to_connect = NULL;

  /* 1. Loop over pad templates, grabbing existing pads along the way */
  for (pads = GST_ELEMENT_GET_CLASS (demux)->padtemplates; pads;
      pads = g_list_next (pads)) {
    GstPadTemplate *templ = GST_PAD_TEMPLATE (pads->data);
    const gchar *templ_name;

    /* we are only interested in source pads */
    if (GST_PAD_TEMPLATE_DIRECTION (templ) != GST_PAD_SRC)
      continue;

    templ_name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);

    /* figure out what kind of pad this is */
    switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
      case GST_PAD_ALWAYS:
      {
        GstPad *pad = gst_element_get_static_pad (demux, templ_name);

        /* We concider the demuxer is not broken, and thus always
         * pads are always here */
        to_connect = g_list_prepend (to_connect, pad);
        break;
      }
      case GST_PAD_SOMETIMES:
      {
        /* try to get the pad to see if it is already created or
         * not */
        GstPad *pad = gst_element_get_static_pad (demux, templ_name);

        if (pad) {
          /* the pad is created, we need to try to link to it */
          to_connect = g_list_prepend (to_connect, pad);
        } else {
          /* we have an element that will create dynamic pads */
          dynamic = TRUE;
        }
        break;
      }
      case GST_PAD_REQUEST:
        /* ignore request pads */
        break;
    }
  }

  /* 2. if there are more potential pads, connect to signal */
  if (dynamic) {
    g_signal_connect (glob_demuxer, "pad-added", G_CALLBACK (pad_added_cb),
        test);
  }

  /* 3. for every available pad, check if we can connect it */
  for (pads = to_connect; pads; pads = g_list_next (pads)) {
    GstPad *pad = GST_PAD_CAST (pads->data);

    pad_added_cb (demux, pad, test);
    gst_object_unref (pad);
  }
  g_list_free (to_connect);

  return res;
}