summaryrefslogtreecommitdiff
path: root/gnl/gnlurisource.c
blob: b02a8797b7b402ef6c10a37ee7e11ee1186d037e (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
165
166
/* 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., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */


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

#include "gnl.h"
#include "gnlurisource.h"

/**
 * SECTION:element-gnlurisource
 *
 * GnlURISource is a #GnlSource 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_urisource_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_SOMETIMES,
    GST_STATIC_CAPS_ANY);

GST_DEBUG_CATEGORY_STATIC (gnlurisource);
#define GST_CAT_DEFAULT gnlurisource

#define _do_init \
  GST_DEBUG_CATEGORY_INIT (gnlurisource, "gnlurisource", GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "GNonLin URI Source Element");
#define  gnl_urisource_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GnlURISource, gnl_urisource, GNL_TYPE_SOURCE,
    _do_init);

enum
{
  ARG_0,
  ARG_URI,
};

static gboolean gnl_urisource_prepare (GnlObject * object);

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

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

static void
gnl_urisource_class_init (GnlURISourceClass * klass)
{
  GObjectClass *gobject_class;
  GnlObjectClass *gnlobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;
  gnlobject_class = (GnlObjectClass *) klass;
  parent_class = g_type_class_ref (GNL_TYPE_SOURCE);

  gst_element_class_set_static_metadata (gstelement_class, "GNonLin URI Source",
      "Filter/Editor",
      "High-level URI Source element", "Edward Hervey <bilboed@bilboed.com>");

  gobject_class->set_property = GST_DEBUG_FUNCPTR (gnl_urisource_set_property);
  gobject_class->get_property = GST_DEBUG_FUNCPTR (gnl_urisource_get_property);

  g_object_class_install_property (gobject_class, ARG_URI,
      g_param_spec_string ("uri", "Uri",
          "Uri of the file to use", NULL, G_PARAM_READWRITE));

  gst_element_class_add_pad_template (gstelement_class,
      gst_static_pad_template_get (&gnl_urisource_src_template));

  gnlobject_class->prepare = gnl_urisource_prepare;
}

static void
gnl_urisource_init (GnlURISource * urisource)
{
  GstElement *decodebin = NULL;

  GST_OBJECT_FLAG_SET (urisource, GNL_OBJECT_SOURCE);

  /* We create a bin with source and decodebin within */
  decodebin =
      gst_element_factory_make ("uridecodebin", "internal-uridecodebin");
  g_object_set (decodebin, "expose-all-streams", FALSE, NULL);

  gst_bin_add (GST_BIN (urisource), decodebin);
}

static inline void
gnl_urisource_set_uri (GnlURISource * fs, const gchar * uri)
{
  g_object_set (GNL_SOURCE (fs)->element, "uri", uri, NULL);
}

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

  switch (prop_id) {
    case ARG_URI:
      gnl_urisource_set_uri (fs, g_value_get_string (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

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

  switch (prop_id) {
    case ARG_URI:
      g_object_get_property ((GObject *) GNL_SOURCE (fs)->element, "uri",
          value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }

}

static gboolean
gnl_urisource_prepare (GnlObject * object)
{
  GnlSource *fs = (GnlSource *) object;

  GST_DEBUG ("prepare");

  /* Set the caps on uridecodebin */
  if (!gst_caps_is_any (object->caps)) {
    GST_DEBUG_OBJECT (object, "Setting uridecodebin caps to %" GST_PTR_FORMAT,
        object->caps);
    g_object_set (fs->element, "caps", object->caps, NULL);
  }

  return GNL_OBJECT_CLASS (parent_class)->prepare (object);
}