Exemplo n.º 1
0
static GstIterator *
gst_proxy_pad_do_iterate_internal_links (GstPad * pad)
{
  GstIterator *res = NULL;
  GstPad *target = gst_proxy_pad_get_target (pad);

  if (target) {
    res = gst_pad_iterate_internal_links (target);
    gst_object_unref (target);
  }

  return res;
}
static gboolean
pad_added_cb (GstElement * element, GstPad * new_pad, InsanityTest * test)
{
  GstElement *fakesink;
  GstPadTemplate *mqsinktmpl;
  GstPadLinkReturn linkret;

  GstIterator *it = NULL;
  GstCaps *caps = NULL;
  gboolean ret = TRUE;

  gulong probe_id;
  GstPad *mqsinkpad = NULL, *mqsrcpad = NULL, *ssinkpad = NULL, *decodesinkpad =
      NULL, *decodesrcpad = NULL, *tmppad;

  DECODER_TEST_LOCK ();

  /* First check if the pad caps are compatible with the decoder or the parser */
  caps = gst_pad_get_current_caps (new_pad);
  if (glob_parser)
    decodesinkpad = gst_element_get_compatible_pad (glob_parser, new_pad, caps);
  else
    decodesinkpad =
        gst_element_get_compatible_pad (glob_decoder, new_pad, caps);

  if (decodesinkpad == NULL)
    goto error;

  mqsinktmpl =
      gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
      (glob_multiqueue), "sink%d");

  if (mqsinktmpl == NULL)
    goto error;

  mqsinkpad = gst_element_request_pad (glob_multiqueue, mqsinktmpl, NULL, NULL);

  it = gst_pad_iterate_internal_links (mqsinkpad);
  if (!it || (gst_iterator_next (it, (gpointer) & mqsrcpad)) != GST_ITERATOR_OK
      || mqsrcpad == NULL) {
    ERROR (test, "Couldn't get srcpad from multiqueue for sinkpad %"
        GST_PTR_FORMAT, mqsinkpad);

    goto error;
  }

  /* Finnish creating and add to bin */
  fakesink = gst_element_factory_make ("fakesink", NULL);
  gst_bin_add (GST_BIN (glob_pipeline), fakesink);
  gst_element_sync_state_with_parent (fakesink);
  gst_element_sync_state_with_parent (glob_decoder);

  linkret = gst_pad_link (new_pad, mqsinkpad);
  if (linkret != GST_PAD_LINK_OK) {
    ERROR (test, "Getting linking %" GST_PTR_FORMAT " with %" GST_PTR_FORMAT,
        new_pad, mqsinkpad);
    goto error;
  }

  /* Link to the decoder */
  linkret = gst_pad_link (mqsrcpad, decodesinkpad);
  if (linkret != GST_PAD_LINK_OK) {
    ERROR (test, "Getting linking %" GST_PTR_FORMAT " with %" GST_PTR_FORMAT,
        mqsrcpad, decodesinkpad);
    goto error;
  }

  if (glob_parser) {
    if (!gst_element_link (glob_parser, glob_decoder)) {
      ERROR (test, "Linking parser with decoder");
      goto error;
    }
  }

  /* Now link to the faksink */
  decodesrcpad = gst_element_get_static_pad (glob_decoder, "src");
  if (decodesrcpad == NULL) {
    ERROR (test, "Getting decoder srcpad");
    goto error;
  }

  ssinkpad = gst_element_get_static_pad (fakesink, "sink");
  if (ssinkpad == NULL) {
    ERROR (test, "Getting fakesink sinkpad");
    goto error;
  }

  linkret = gst_pad_link (decodesrcpad, ssinkpad);
  if (linkret != GST_PAD_LINK_OK) {
    ERROR (test, "Getting linking %" GST_PTR_FORMAT " with %" GST_PTR_FORMAT,
        decodesrcpad, ssinkpad);
    goto error;
  }

  /* And install a probe to the decoder src pad */
  if (insanity_gst_test_add_data_probe (INSANITY_GST_TEST (test),
          GST_BIN (glob_pipeline), GST_OBJECT_NAME (glob_decoder),
          GST_ELEMENT_NAME (decodesrcpad), &tmppad, &probe_id,
          &probe_cb, NULL, NULL) == TRUE) {

    glob_prob_ctx = g_slice_new0 (ProbeContext);
    glob_prob_ctx->probe_id = probe_id;
    glob_prob_ctx->pad = tmppad;
    glob_prob_ctx->decoder = glob_decoder;
    glob_prob_ctx->fakesink = fakesink;
    glob_prob_ctx->test = test;

    insanity_test_validate_checklist_item (test, "install-probes", TRUE, NULL);
  } else {
    insanity_test_validate_checklist_item (test,
        "install-probes", FALSE, "Failed to attach probe to fakesink");

    /* No reason to keep the test alive if there is a probe we can't add */
    insanity_test_done (test);
    goto error;
  }

  if (glob_media_desc_parser)
    media_descriptor_parser_add_stream (glob_media_desc_parser, new_pad);

done:
  DECODER_TEST_UNLOCK ();

  if (it)
    gst_iterator_free (it);

  if (decodesinkpad)
    gst_object_unref (decodesinkpad);

  if (caps)
    gst_caps_unref (caps);

  if (mqsinkpad)
    gst_object_unref (mqsinkpad);

  if (ssinkpad)
    gst_object_unref (ssinkpad);

  return ret;

error:
  ret = FALSE;
  goto done;
}