示例#1
0
static void
gst_negotiation_update_caps (GstNegotiation * negotiation)
{
  GstCaps *srccaps;
  GstCaps *sinkcaps;
  GstCaps *icaps;

  srccaps = gst_pad_get_allowed_caps (negotiation->srcpad);
  sinkcaps = gst_pad_get_allowed_caps (negotiation->sinkpad);

  icaps = gst_caps_intersect (srccaps, sinkcaps);
  gst_caps_free (srccaps);
  gst_caps_free (sinkcaps);

  gst_caps_replace (&negotiation->caps, icaps);
  g_object_notify (G_OBJECT (negotiation), "allowed-caps");
  GST_DEBUG ("notify %" GST_PTR_FORMAT, icaps);
}
static void
gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore)
{
    guint8 *data;
    GdkPixbufLoader *pixbuf_loader;
    GdkPixbufFormat *format;

    data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE);
    if (data == NULL)
        return;

    GST_DEBUG ("creating new loader");

    pixbuf_loader = gdk_pixbuf_loader_new ();

    gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE,
                             NULL);

    format = gdk_pixbuf_loader_get_format (pixbuf_loader);

    if (format != NULL) {
        GstCaps *caps;
        gchar **p;
        gchar **mlist = gdk_pixbuf_format_get_mime_types (format);

        for (p = mlist; *p; ++p) {
            GST_DEBUG ("suggesting mime type %s", *p);
            caps = gst_caps_new_simple (*p, NULL);
            gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps);
            gst_caps_free (caps);
        }
        g_strfreev (mlist);
    }

    GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ...");
    /* librsvg 2.4.x has a bug where it triggers an endless loop in trying
       to close a gzip that's not an svg; fixed upstream but no good way
       to work around it */
    gdk_pixbuf_loader_close (pixbuf_loader, NULL);
    GST_DEBUG ("closed pixbuf loader");
    g_object_unref (G_OBJECT (pixbuf_loader));
}
static GstCaps *
gst_hermes_colorspace_getcaps (GstPad * pad)
{
  GstHermesColorspace *space;
  GstPad *otherpad;
  GstCaps *othercaps;
  GstCaps *caps;

  space = GST_HERMES_COLORSPACE (gst_pad_get_parent (pad));

  otherpad = (pad == space->srcpad) ? space->sinkpad : space->srcpad;

  othercaps = gst_pad_get_allowed_caps (otherpad);

  othercaps = gst_hermes_colorspace_caps_remove_format_info (othercaps);

  caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad));
  gst_caps_free (othercaps);

  return caps;
}
示例#4
0
static GstCaps *
gst_mikmod_srcfixate (GstPad * pad, const GstCaps * caps)
{
  GstCaps *ret;
  GstStructure *structure;

  /* FIXME: select est caps here */
  if (gst_caps_get_size (caps) > 1)
    return NULL;

  ret = gst_caps_copy (caps);
  structure = gst_caps_get_structure (ret, 0);

  if (gst_structure_fixate_field_nearest_int (structure, "channels", 2))
    return ret;
  if (gst_structure_fixate_field_nearest_int (structure, "rate", 44100))
    return ret;

  gst_caps_free (ret);
  return NULL;
}
static GstPadLinkReturn
gst_hermes_colorspace_link (GstPad * pad, const GstCaps * caps)
{
  GstHermesColorspace *space;
  GstPad *otherpad;
  GstStructure *structure;
  GstPadLinkReturn link_ret;
  int width, height;
  double fps;
  int i;

  space = GST_HERMES_COLORSPACE (gst_pad_get_parent (pad));
  otherpad = (pad == space->sinkpad) ? space->srcpad : space->sinkpad;

  link_ret = gst_pad_try_set_caps (otherpad, caps);
  if (link_ret == GST_PAD_LINK_OK) {
    space->passthru = TRUE;
    return link_ret;
  }

  structure = gst_caps_get_structure (caps, 0);

  for (i = 0; i < G_N_ELEMENTS (gst_hermes_colorspace_formats); i++) {
    GstCaps *icaps;
    GstCaps *fcaps;

    fcaps =
        gst_caps_copy (gst_static_caps_get (&gst_hermes_colorspace_formats
            [i].caps));

    icaps = gst_caps_intersect (caps, fcaps);
    if (!gst_caps_is_empty (icaps)) {
      break;
    }
    gst_caps_free (icaps);
  }
  if (i == G_N_ELEMENTS (gst_hermes_colorspace_formats)) {
    g_assert_not_reached ();
    return GST_PAD_LINK_REFUSED;
  }

  gst_structure_get_int (structure, "width", &width);
  gst_structure_get_int (structure, "height", &height);
  gst_structure_get_double (structure, "framerate", &fps);

  GST_INFO ("size: %dx%d", space->width, space->height);

  if (gst_pad_is_negotiated (otherpad)) {
    GstCaps *othercaps;

    othercaps = gst_caps_copy (gst_pad_get_negotiated_caps (otherpad));

    gst_caps_set_simple (othercaps,
        "width", G_TYPE_INT, width,
        "height", G_TYPE_INT, height, "framerate", G_TYPE_DOUBLE, fps, NULL);

    link_ret = gst_pad_try_set_caps (otherpad, othercaps);
    if (link_ret != GST_PAD_LINK_OK) {
      return link_ret;
    }
  }

  if (pad == space->srcpad) {
    space->src_format_index = i;
    gst_hermes_colorspace_structure_to_hermes_format (&space->src_format,
        structure);
  } else {
    space->sink_format_index = i;
    gst_hermes_colorspace_structure_to_hermes_format (&space->sink_format,
        structure);
  }

  space->sink_stride = width * (space->sink_format.bits / 8);
  space->src_stride = width * (space->src_format.bits / 8);
  space->sink_size = space->sink_stride * height;
  space->src_size = space->src_stride * height;
  space->width = width;
  space->height = height;
  space->fps = fps;

  if (gst_pad_is_negotiated (otherpad)) {
    if (!Hermes_ConverterRequest (space->h_handle, &space->sink_format,
            &space->src_format)) {
      g_warning ("Hermes: could not get converter\n");
      return GST_PAD_LINK_REFUSED;
    }
    g_print ("inited\n");
  }

  return GST_PAD_LINK_OK;
}
示例#6
0
void gap_metadata_load (GAPMetaData *md, const char *uri)
{
        GstElement *pipeline = NULL;
        GstElement *gnomevfssrc = NULL;
        GstElement *typefind = NULL;
        GstElement *spider = NULL;
	GstElement *fakesink = NULL;
        GstCaps *filtercaps = NULL;
        const char *plugin_name = NULL;

	g_return_if_fail (uri != NULL);

	g_print ("Loading metadata for: %s\n", uri);
	md->uri = g_strdup (uri);
	md->duration = -1;

        /* The main tagfinding pipeline looks like this:
         * gnomevfssrc ! typefind ! spider ! application/x-gst-tags ! fakesink
         */
        pipeline = gst_pipeline_new ("pipeline");
	g_signal_connect (pipeline, "error", G_CALLBACK (cb_gst_error), md);
	g_signal_connect (pipeline, "found-tag", G_CALLBACK (cb_gst_found_tag), md);

	gnomevfssrc = gst_element_factory_make ("gnomevfssrc", "gnomevfssrc");
	/* TODO: check error */
	gst_bin_add (GST_BIN (pipeline), gnomevfssrc);
	g_object_set (G_OBJECT (gnomevfssrc), "location", uri, NULL);
	
	typefind  = gst_element_factory_make ("typefind", "typefind");
	/* TODO: check error */
	g_signal_connect (typefind, "have_type", G_CALLBACK (cb_gst_have_type), md);
	gst_bin_add (GST_BIN (pipeline), typefind);

	spider = gst_element_factory_make ("spider", "spider");
	/* TODO: check error */
	gst_bin_add (GST_BIN (pipeline), spider);

	fakesink = gst_element_factory_make ("fakesink", "fakesink");
	/* TODO: check error */
	gst_bin_add (GST_BIN (pipeline), fakesink);
	g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
	g_signal_connect (fakesink, "handoff", G_CALLBACK (cb_gst_handoff), md);
	g_signal_connect (fakesink, "eos", G_CALLBACK (cb_gst_eos), md);

	gst_element_link_many (gnomevfssrc, typefind, spider, NULL);

	filtercaps = gst_caps_new_simple ("audio/x-raw-int", NULL);
	gst_element_link_filtered (spider, fakesink, filtercaps);
	gst_caps_free (filtercaps);

	gst_element_set_state (pipeline, GST_STATE_PLAYING);
	while ((gst_bin_iterate (GST_BIN (pipeline)))
		&& (md->error == NULL)
		&& (!md->handoff)
		&& (!md->eos))
		;

	if (md->handoff)
	{
		if (md->duration == -1)
		{
			GstFormat format = GST_FORMAT_TIME;
			gint64 length;
	
			if (gst_element_query (fakesink, GST_QUERY_TOTAL, &format, &length))
			{
				GValue *newval = g_new0 (GValue, 1);
				g_print ("Duration query succeeded\n");
				g_value_init (newval, G_TYPE_LONG);
				g_value_set_long (newval, (long) (length / (1 * 1000 * 1000 * 1000)));
				md->duration = g_value_get_long (newval);
				g_printf ("Duration: %d\n", md->duration);
			}
			else
				g_print ("Duration query failed\n");
		}
	}
	else if (md->eos)
		g_print ("Received eos without handoff\n");

	gst_element_set_state (pipeline, GST_STATE_NULL);

	if (pipeline != NULL)
		gst_object_unref (GST_OBJECT (pipeline));
}