コード例 #1
0
ファイル: filesrc.c プロジェクト: Grobik1/gstreamer
static void
check_uri_for_uri (GstElement * e, const gchar * in_uri, const gchar * uri)
{
  GstQuery *query;
  gchar *query_uri = NULL;

  gst_uri_handler_set_uri (GST_URI_HANDLER (e), in_uri, NULL);

  query = gst_query_new_uri ();
  fail_unless (gst_element_query (e, query));
  gst_query_parse_uri (query, &query_uri);
  gst_query_unref (query);

  if (uri != NULL) {
    fail_unless_equals_string (query_uri, uri);
  } else {
    gchar *fn;

    fail_unless (gst_uri_is_valid (query_uri));
    fn = g_filename_from_uri (query_uri, NULL, NULL);
    fail_unless (g_path_is_absolute (fn));
    fail_unless (fn != NULL);
    g_free (fn);
  }

  g_free (query_uri);
}
コード例 #2
0
static gboolean
gst_push_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
{
  GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler);

  if (src->filesrc == NULL || !g_str_has_prefix (uri, "pushfile://"))
    return FALSE;

  /* skip 'push' bit */
  return gst_uri_handler_set_uri (GST_URI_HANDLER (src->filesrc), uri + 4);
}
コード例 #3
0
static gboolean
gst_push_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
    GError ** error)
{
  GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler);

  if (src->filesrc == NULL) {
    g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE,
        "Could not create file source element");
    return FALSE;
  }

  /* skip 'push' bit */
  return gst_uri_handler_set_uri (GST_URI_HANDLER (src->filesrc), uri + 4,
      error);
}
コード例 #4
0
static void
test_uri_parse (const gchar * uri, const gchar * device, gint track)
{
  GstElement *foosrc;
  gchar *set_device = NULL;
  gint set_track = 0;

  foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc");
  fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), uri, NULL),
      "couldn't set uri %s", uri);
  g_object_get (foosrc, "device", &set_device, "track", &set_track, NULL);
  fail_unless (set_device != NULL);
  fail_unless (strcmp (set_device, device) == 0,
      "device set was %s, expected %s", set_device, device);
  fail_unless (set_track == track, "track set was %d, expected %d", set_track,
      track);
  g_free (set_device);
  gst_object_unref (foosrc);
}
コード例 #5
0
static gboolean
gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri)
{
  GstPad *pad;

  if (!gst_uri_is_valid (uri))
    return FALSE;

  if (downloader->urisrc) {
    GstURIHandler *uri_handler = GST_URI_HANDLER (downloader->urisrc);

    if (gst_uri_handler_set_uri (uri_handler, uri, NULL)) {
      GST_DEBUG_OBJECT (downloader, "reusing element %s to download URI %s",
          GST_ELEMENT_NAME (downloader->urisrc), uri);
      return TRUE;
    }

    gst_element_set_state (downloader->urisrc, GST_STATE_NULL);
    gst_object_unref (downloader->urisrc);
  }

  GST_DEBUG_OBJECT (downloader, "creating source element for URI %s", uri);
  downloader->urisrc =
      gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
  if (!downloader->urisrc) {
    GST_ERROR_OBJECT (downloader, "no element can handle URI %s", uri);
    return FALSE;
  }

  /* add a sync handler for the bus messages to detect errors */
  gst_element_set_bus (downloader->urisrc, downloader->bus);
  gst_bus_set_sync_handler (downloader->bus,
      gst_uri_downloader_bus_handler, downloader, NULL);

  pad = gst_element_get_static_pad (downloader->urisrc, "src");
  gst_pad_link_full (pad, downloader->pad, GST_PAD_LINK_CHECK_NOTHING);
  gst_object_unref (pad);

  return TRUE;
}
コード例 #6
0
static gboolean
gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri,
    const gchar * referer, gboolean compress, gboolean refresh,
    gboolean allow_cache)
{
  GstPad *pad;
  GObjectClass *gobject_class;

  if (!gst_uri_is_valid (uri))
    return FALSE;

  if (downloader->priv->urisrc) {
    gchar *old_protocol, *new_protocol;
    gchar *old_uri;

    old_uri =
        gst_uri_handler_get_uri (GST_URI_HANDLER (downloader->priv->urisrc));
    old_protocol = gst_uri_get_protocol (old_uri);
    new_protocol = gst_uri_get_protocol (uri);

    if (!g_str_equal (old_protocol, new_protocol)) {
      gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL);
      gst_object_unref (downloader->priv->urisrc);
      downloader->priv->urisrc = NULL;
      GST_DEBUG_OBJECT (downloader, "Can't re-use old source element");
    } else {
      GError *err = NULL;

      GST_DEBUG_OBJECT (downloader, "Re-using old source element");
      if (!gst_uri_handler_set_uri (GST_URI_HANDLER (downloader->priv->urisrc),
              uri, &err)) {
        GST_DEBUG_OBJECT (downloader, "Failed to re-use old source element: %s",
            err->message);
        g_clear_error (&err);
        gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL);
        gst_object_unref (downloader->priv->urisrc);
        downloader->priv->urisrc = NULL;
      }
    }
    g_free (old_uri);
    g_free (old_protocol);
    g_free (new_protocol);
  }

  if (!downloader->priv->urisrc) {
    GST_DEBUG_OBJECT (downloader, "Creating source element for the URI:%s",
        uri);
    downloader->priv->urisrc =
        gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
    if (!downloader->priv->urisrc)
      return FALSE;
  }

  gobject_class = G_OBJECT_GET_CLASS (downloader->priv->urisrc);
  if (g_object_class_find_property (gobject_class, "compress"))
    g_object_set (downloader->priv->urisrc, "compress", compress, NULL);
  if (g_object_class_find_property (gobject_class, "keep-alive"))
    g_object_set (downloader->priv->urisrc, "keep-alive", TRUE, NULL);
  if (g_object_class_find_property (gobject_class, "extra-headers")) {
    if (referer || refresh || !allow_cache) {
      GstStructure *extra_headers = gst_structure_new_empty ("headers");

      if (referer)
        gst_structure_set (extra_headers, "Referer", G_TYPE_STRING, referer,
            NULL);

      if (!allow_cache)
        gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING,
            "no-cache", NULL);
      else if (refresh)
        gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING,
            "max-age=0", NULL);

      g_object_set (downloader->priv->urisrc, "extra-headers", extra_headers,
          NULL);

      gst_structure_free (extra_headers);
    } else {
      g_object_set (downloader->priv->urisrc, "extra-headers", NULL, NULL);
    }
  }

  /* add a sync handler for the bus messages to detect errors in the download */
  gst_element_set_bus (GST_ELEMENT (downloader->priv->urisrc),
      downloader->priv->bus);
  gst_bus_set_sync_handler (downloader->priv->bus,
      gst_uri_downloader_bus_handler, downloader, NULL);

  pad = gst_element_get_static_pad (downloader->priv->urisrc, "src");
  if (!pad)
    return FALSE;
  gst_pad_link (pad, downloader->priv->pad);
  gst_object_unref (pad);
  return TRUE;
}
/* Test Callbacks  and vmethods*/
static GstPipeline *
create_pipeline (InsanityGstPipelineTest * ptest, gpointer unused_data)
{
  GstElementFactory *decofactory = NULL;

  GError *err = NULL;
  InsanityTest *test = INSANITY_TEST (ptest);
  gchar *decodername = NULL, *uri = NULL, *location = NULL;
  const gchar *klass;

  DECODER_TEST_LOCK ();
  glob_pipeline = GST_ELEMENT (gst_pipeline_new ("pipeline"));

  /* Create the source */
  insanity_test_get_boolean_argument (test, "push-mode",
      (gboolean *) & glob_push_mode);

  insanity_test_get_string_argument (test, "location", &location);
  if (location == NULL || g_strcmp0 (location, "") == 0) {
    ERROR (test, "Location name not set");
    goto failed;
  }

  uri = gst_filename_to_uri (location, &err);
  if (err != NULL) {
    ERROR (test, "Error creating uri %s", err->message);

    goto failed;
  } else if (glob_push_mode == FALSE) {
    glob_src = gst_element_factory_make ("filesrc", "src");
  } else {
    gchar *tmpuri;

    glob_src = gst_element_factory_make ("pushfilesrc", "src");
    tmpuri = g_strconcat ("push", uri, NULL);
    g_free (uri);

    uri = tmpuri;
  }

  gst_uri_handler_set_uri (GST_URI_HANDLER (glob_src), uri, &err);
  if (err != NULL) {
    ERROR (test, "Error setting uri %s", err->message);
    goto failed;
  }

  if (!insanity_test_get_string_argument (test, "decoder-name", &decodername) ||
      g_strcmp0 (decodername, "") == 0) {
    ERROR (test, "Decoder name not set");
    goto failed;
  }

  /* ... create the decoder, will not be used until we typefind and
   * plug the demuxer */
  glob_decoder = gst_element_factory_make (decodername, "decoder");
  if (glob_decoder == NULL)
    goto failed;

  /* We check wether the element is a parser or not */
  decofactory = gst_element_get_factory (glob_decoder);
  klass =
      gst_element_factory_get_metadata (decofactory,
      GST_ELEMENT_METADATA_KLASS);
  glob_testing_parser = g_strrstr (klass, "Parser") ? TRUE : FALSE;

  if (glob_testing_parser == FALSE && g_strrstr (klass, "Decoder") == NULL) {
    gchar *val_test = g_strdup_printf ("%s not a decoder nor a parser as"
        " neither of \"Decoder\" nor \"parser\" where present in the element"
        " factory klass: %s", decodername, klass);

    insanity_test_validate_checklist_item (test, "testing-decoder-or-parser",
        FALSE, val_test);

    g_free (val_test);
    goto failed;
  } else {
    insanity_test_validate_checklist_item (test, "testing-decoder-or-parser",
        TRUE, NULL);
  }

  if (glob_testing_parser == FALSE) {
    GstCaps *decode_sinkcaps = NULL;
    GList *tmp, *parsers;
    const GList *template;

    for (template = gst_element_factory_get_static_pad_templates (decofactory);