~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty

« back to all changes in this revision

Viewing changes to gst/gsturi.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-08-08 18:12:33 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120808181233-riejwxprfsxh1njl
Tags: 0.11.93-1
* New upstream release:
  + debian/libgstreamer.symbols:
    - Update symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#endif
43
43
 
44
44
#include "gst_private.h"
 
45
#include "gst.h"
45
46
#include "gsturi.h"
46
47
#include "gstinfo.h"
47
48
#include "gstregistry.h"
313
314
 
314
315
  gst_uri_protocol_check_internal (protocol, &endptr);
315
316
 
316
 
  return *endptr == '\0' && ((gsize) (endptr - protocol)) >= 3;
 
317
  return *endptr == '\0' && ((gsize) (endptr - protocol)) >= 2;
317
318
}
318
319
 
319
320
/**
334
335
 
335
336
  gst_uri_protocol_check_internal (uri, &endptr);
336
337
 
337
 
  return *endptr == ':' && ((gsize) (endptr - uri)) >= 3;
 
338
  return *endptr == ':' && ((gsize) (endptr - uri)) >= 2;
338
339
}
339
340
 
340
341
/**
367
368
 * Checks if the protocol of a given valid URI matches @protocol.
368
369
 *
369
370
 * Returns: %TRUE if the protocol matches.
370
 
 *
371
 
 * Since: 0.10.4
372
371
 */
373
372
gboolean
374
373
gst_uri_has_protocol (const gchar * uri, const gchar * protocol)
398
397
 *
399
398
 * Free-function: g_free
400
399
 *
401
 
 * Returns: (transfer full) (array zero-terminated=1): the location for this
402
 
 *     URI. Returns NULL if the URI isn't valid. If the URI does not contain
403
 
 *     a location, an empty string is returned.
 
400
 * Returns: (transfer full): the location for this URI. Returns NULL if the
 
401
 *     URI isn't valid. If the URI does not contain a location, an empty
 
402
 *     string is returned.
404
403
 */
405
404
gchar *
406
405
gst_uri_get_location (const gchar * uri)
439
438
/**
440
439
 * gst_uri_construct:
441
440
 * @protocol: Protocol for URI
442
 
 * @location: (array zero-terminated=1) (transfer none): Location for URI
 
441
 * @location: (transfer none): Location for URI
443
442
 *
444
443
 * Constructs a URI for a given valid protocol and location.
445
444
 *
446
445
 * Free-function: g_free
447
446
 *
448
 
 * Returns: (transfer full) (array zero-terminated=1): a new string for this
449
 
 *     URI. Returns NULL if the given URI protocol is not valid, or the given
450
 
 *     location is NULL.
 
447
 * Returns: (transfer full): a new string for this URI. Returns NULL if the
 
448
 *     given URI protocol is not valid, or the given location is NULL.
451
449
 */
452
450
gchar *
453
451
gst_uri_construct (const gchar * protocol, const gchar * location)
538
536
 * gst_element_make_from_uri() is guaranteed to work.
539
537
 *
540
538
 * Returns: TRUE
541
 
 *
542
 
 * Since: 0.10.13
543
539
*/
544
540
gboolean
545
541
gst_uri_protocol_is_supported (const GstURIType type, const gchar * protocol)
562
558
 * @type: Whether to create a source or a sink
563
559
 * @uri: URI to create an element for
564
560
 * @elementname: (allow-none): Name of created element, can be NULL.
 
561
 * @error: (allow-none): address where to store error information, or NULL.
565
562
 *
566
563
 * Creates an element for handling the given URI.
567
564
 *
569
566
 */
570
567
GstElement *
571
568
gst_element_make_from_uri (const GstURIType type, const gchar * uri,
572
 
    const gchar * elementname)
 
569
    const gchar * elementname, GError ** error)
573
570
{
574
571
  GList *possibilities, *walk;
575
572
  gchar *protocol;
576
573
  GstElement *ret = NULL;
577
574
 
 
575
  g_return_val_if_fail (gst_is_initialized (), NULL);
578
576
  g_return_val_if_fail (GST_URI_TYPE_IS_VALID (type), NULL);
579
577
  g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
 
578
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
580
579
 
581
580
  GST_DEBUG ("type:%d, uri:%s, elementname:%s", type, uri, elementname);
582
581
 
583
582
  protocol = gst_uri_get_protocol (uri);
584
583
  possibilities = get_element_factories_from_uri_protocol (type, protocol);
585
 
  g_free (protocol);
586
584
 
587
585
  if (!possibilities) {
588
586
    GST_DEBUG ("No %s for URI '%s'", type == GST_URI_SINK ? "sink" : "source",
589
587
        uri);
 
588
    /* The error message isn't great, but we don't expect applications to
 
589
     * show that error to users, but call the missing plugins functions */
 
590
    g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
 
591
        _("No URI handler for the %s protocol found"), protocol);
 
592
    g_free (protocol);
590
593
    return NULL;
591
594
  }
 
595
  g_free (protocol);
592
596
 
593
597
  possibilities = g_list_sort (possibilities, (GCompareFunc) sort_by_rank);
594
598
  walk = possibilities;
595
599
  while (walk) {
596
 
    if ((ret =
597
 
            gst_element_factory_create (GST_ELEMENT_FACTORY_CAST (walk->data),
598
 
                elementname)) != NULL) {
 
600
    GstElementFactory *factory = walk->data;
 
601
    GError *uri_err = NULL;
 
602
 
 
603
    ret = gst_element_factory_create (factory, elementname);
 
604
    if (ret != NULL) {
599
605
      GstURIHandler *handler = GST_URI_HANDLER (ret);
600
606
 
601
 
      if (gst_uri_handler_set_uri (handler, uri, NULL))
 
607
      if (gst_uri_handler_set_uri (handler, uri, &uri_err))
602
608
        break;
603
 
      GST_WARNING ("element %s didn't accept the URI", GST_ELEMENT_NAME (ret));
 
609
 
 
610
      GST_WARNING ("%s didn't accept URI '%s': %s", GST_OBJECT_NAME (ret), uri,
 
611
          uri_err->message);
 
612
 
 
613
      if (error != NULL && *error == NULL)
 
614
        g_propagate_error (error, uri_err);
 
615
      else
 
616
        g_error_free (uri_err);
 
617
 
604
618
      gst_object_unref (ret);
605
619
      ret = NULL;
606
620
    }
610
624
 
611
625
  GST_LOG_OBJECT (ret, "created %s for URL '%s'",
612
626
      type == GST_URI_SINK ? "sink" : "source", uri);
 
627
 
 
628
  /* if the first handler didn't work, but we found another one that works */
 
629
  if (ret != NULL)
 
630
    g_clear_error (error);
 
631
 
613
632
  return ret;
614
633
}
615
634
 
647
666
 * Gets the list of protocols supported by @handler. This list may not be
648
667
 * modified.
649
668
 *
650
 
 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): the
651
 
 *     supported protocols. Returns NULL if the @handler isn't implemented
652
 
 *     properly, or the @handler doesn't support any protocols.
 
669
 * Returns: (transfer none) (element-type utf8): the supported protocols.
 
670
 *     Returns NULL if the @handler isn't implemented properly, or the @handler
 
671
 *     doesn't support any protocols.
653
672
 */
654
673
const gchar *const *
655
674
gst_uri_handler_get_protocols (GstURIHandler * handler)
741
760
      }
742
761
 
743
762
      if (!found_protocol) {
744
 
        g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_PROTOCOL,
 
763
        g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
745
764
            _("URI scheme '%s' not supported"), protocol);
746
765
        g_free (protocol);
747
766
        return FALSE;
830
849
 * will be canonicalised so that it doesn't contain any './' or '../' segments.
831
850
 *
832
851
 * On Windows #filename should be in UTF-8 encoding.
833
 
 *
834
 
 * Since: 0.10.33
835
852
 */
836
853
gchar *
837
854
gst_filename_to_uri (const gchar * filename, GError ** error)