summaryrefslogtreecommitdiff
path: root/gnl/gnlfilesource.c
blob: f7e008ec04e7552aea9b17c5985dc284604c9029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Gnonlin
 * Copyright (C) <2005-2008> Edward Hervey <bilboed@bilboed.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gnl.h"

/**
 * SECTION:element-gnlfilesource
 * @short_description: GNonLin File Source
 *
 * GnlFileSource is a #GnlURISource which reads and decodes the contents
 * of a given file. The data in the file is decoded using any available
 * GStreamer plugins.
 */

static GstStaticPadTemplate gnl_filesource_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_SOMETIMES,
    GST_STATIC_CAPS_ANY);

GST_DEBUG_CATEGORY_STATIC (gnlfilesource);
#define GST_CAT_DEFAULT gnlfilesource


GST_BOILERPLATE (GnlFileSource, gnl_filesource, GnlURISource,
    GNL_TYPE_URI_SOURCE);

static GstElementDetails gnl_filesource_details = GST_ELEMENT_DETAILS
    ("GNonLin File Source",
    "Filter/Editor",
    "High-level File Source element",
    "Edward Hervey <bilboed@bilboed.com>");

enum
{
  ARG_0,
  ARG_LOCATION,
};

static void
gnl_filesource_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);

static void
gnl_filesource_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);

static void
gnl_filesource_base_init (gpointer g_class)
{
  GstElementClass *gstclass = GST_ELEMENT_CLASS (g_class);

  gst_element_class_set_details (gstclass, &gnl_filesource_details);
}

static void
gnl_filesource_class_init (GnlFileSourceClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;

  parent_class = g_type_class_ref (GNL_TYPE_URI_SOURCE);

  GST_DEBUG_CATEGORY_INIT (gnlfilesource, "gnlfilesource",
      GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "GNonLin File Source Element");

  gobject_class->set_property = GST_DEBUG_FUNCPTR (gnl_filesource_set_property);
  gobject_class->get_property = GST_DEBUG_FUNCPTR (gnl_filesource_get_property);

  g_object_class_install_property (gobject_class, ARG_LOCATION,
      g_param_spec_string ("location", "Location",
          "Location of the file to use", NULL, G_PARAM_READWRITE));

  gst_element_class_add_pad_template (gstelement_class,
      gst_static_pad_template_get (&gnl_filesource_src_template));
}

static void
gnl_filesource_init (GnlFileSource * filesource,
    GnlFileSourceClass * klass G_GNUC_UNUSED)
{
}

static void
gnl_filesource_set_location (GnlFileSource * fs, const gchar * location)
{
  gchar *tmp;

  GST_DEBUG_OBJECT (fs, "location: '%s'", location);

  if (g_ascii_strncasecmp (location, "file://", 7))
    tmp = g_strdup_printf ("file://%s", location);
  else
    tmp = g_strdup (location);
  GST_DEBUG ("%s", tmp);
  g_object_set (fs, "uri", tmp, NULL);
  g_free (tmp);
}

static void
gnl_filesource_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GnlFileSource *fs = (GnlFileSource *) object;

  switch (prop_id) {
    case ARG_LOCATION:
      /* proxy to gnomevfssrc */
      gnl_filesource_set_location (fs, g_value_get_string (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gnl_filesource_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GnlFileSource *fs = (GnlFileSource *) object;

  switch (prop_id) {
    case ARG_LOCATION:
    {
      const gchar *uri = NULL;;

      g_object_get (fs, "uri", &uri, NULL);
      if (uri != NULL && g_str_has_prefix (uri, "file://"))
        g_value_set_string (value, uri + 7);
      else
        g_value_set_string (value, NULL);
    }
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }

}