ges.c 9.23 KB
Newer Older
Edward Hervey's avatar
Edward Hervey committed
1
/* GStreamer Editing Services
Edward Hervey's avatar
Edward Hervey committed
2
3
 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
 *               2009 Nokia Corporation
Edward Hervey's avatar
Edward Hervey committed
4
5
6
7
8
9
10
11
12
13
14
15
16
 *
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
17
18
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
Edward Hervey's avatar
Edward Hervey committed
19
20
 */

21
22
23
24
25
26
27
/* TODO
 * Add a deinit function
 *
 * Do not forget to
 *  + g_ptr_array_unref (new_paths);
 *  + g_hash_table_unref (tried_uris);
 */
28
29
30
31
32
33

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

#include <stdlib.h>
Edward Hervey's avatar
Edward Hervey committed
34
#include <ges/ges.h>
35
#include "ges/gstframepositioner.h"
36
#include "ges-internal.h"
Edward Hervey's avatar
Edward Hervey committed
37

Thibault Saunier's avatar
Thibault Saunier committed
38
39
#define GES_GNONLIN_VERSION_NEEDED_MAJOR 1
#define GES_GNONLIN_VERSION_NEEDED_MINOR 2
40
#define GES_GNONLIN_VERSION_NEEDED_MICRO 0
41

42
GST_DEBUG_CATEGORY (_ges_debug);
Edward Hervey's avatar
Edward Hervey committed
43

44
45
static gboolean ges_initialized = FALSE;

46

47
48
49
50

static gboolean
ges_init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
    GError ** error)
Edward Hervey's avatar
Edward Hervey committed
51
52
{
  /* initialize debugging category */
53
  GST_DEBUG_CATEGORY_INIT (_ges_debug, "ges", GST_DEBUG_FG_YELLOW,
Edward Hervey's avatar
Edward Hervey committed
54
      "GStreamer Editing Services");
55

56
57
58
59
60
61
62
  return TRUE;
}

static gboolean
ges_init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
    GError ** error)
{
63
  GESUriClipAssetClass *uriasset_klass = NULL;
64
  GstElementFactory *nlecomposition_factory = NULL;
65

66
67
68
69
70
  if (ges_initialized) {
    GST_DEBUG ("already initialized ges");
    return TRUE;
  }

71
  uriasset_klass = g_type_class_ref (GES_TYPE_URI_CLIP_ASSET);
72
  if (!uriasset_klass || !uriasset_klass->discoverer)
73
74
75
76
77
    goto failed;

  if (!uriasset_klass->sync_discoverer)
    goto failed;

78
79
80
81
82
83
84
85
86
87
88
89
90
  nlecomposition_factory = gst_element_factory_find ("nlecomposition");
  if (!nlecomposition_factory) {
    GST_ERROR ("The `nlecomposition` object was not found.");
    if (error)
      *error = g_error_new (GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN,
          "The `nle` plugin is missing.");

    goto failed;
  }
  gst_object_unref (nlecomposition_factory);



91
  /* register clip classes with the system */
92

93
94
95
96
97
98
  g_type_class_ref (GES_TYPE_TEST_CLIP);
  g_type_class_ref (GES_TYPE_URI_CLIP);
  g_type_class_ref (GES_TYPE_TITLE_CLIP);
  g_type_class_ref (GES_TYPE_TRANSITION_CLIP);
  g_type_class_ref (GES_TYPE_OVERLAY_CLIP);
  g_type_class_ref (GES_TYPE_OVERLAY_TEXT_CLIP);
99

100
  g_type_class_ref (GES_TYPE_GROUP);
101

102
  /* register formatter types with the system */
103
104
105
  g_type_class_ref (GES_TYPE_PITIVI_FORMATTER);
  g_type_class_ref (GES_TYPE_COMMAND_LINE_FORMATTER);
  g_type_class_ref (GES_TYPE_XML_FORMATTER);
106

107
  /* Register track elements */
108
  g_type_class_ref (GES_TYPE_EFFECT);
109

110
111
  ges_asset_cache_init ();

112
  gst_element_register (NULL, "framepositioner", 0, GST_TYPE_FRAME_POSITIONNER);
113
  gst_element_register (NULL, "gespipeline", 0, GES_TYPE_PIPELINE);
114

115
  /* TODO: user-defined types? */
116
  ges_initialized = TRUE;
117
  g_type_class_unref (uriasset_klass);
118

119
  GST_DEBUG ("GStreamer Editing Services initialized");
120
121

  return TRUE;
122
123
124
125
126
127
128
129

failed:
  if (uriasset_klass)
    g_type_class_unref (uriasset_klass);

  GST_ERROR ("Could not initialize GES.");

  return FALSE;
Edward Hervey's avatar
Edward Hervey committed
130
}
131

132
133
134
135
136
137
138
139
140
141
142
143
144
/**
 * ges_init:
 *
 * Initialize the GStreamer Editing Service. Call this before any usage of
 * GES. You should take care of initilizing GStreamer before calling this
 * function.
 */

gboolean
ges_init (void)
{
  ges_init_pre (NULL, NULL, NULL, NULL);

145
  return ges_init_post (NULL, NULL, NULL, NULL);
146
147
}

Guillaume Desmottes's avatar
Guillaume Desmottes committed
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * ges_deinit:
 *
 * Clean up any resources created by GES in ges_init().
 *
 * It is normally not needed to call this function in a normal application as the
 * resources will automatically be freed when the program terminates.
 * This function is therefore mostly used by testsuites and other memory profiling tools.
 *
 * After this call GES (including this method) should not be used anymore.
 */
void
ges_deinit (void)
{
  _ges_uri_asset_cleanup ();
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

  g_type_class_unref (g_type_class_peek (GES_TYPE_TEST_CLIP));
  g_type_class_unref (g_type_class_peek (GES_TYPE_URI_CLIP));
  g_type_class_unref (g_type_class_peek (GES_TYPE_TITLE_CLIP));
  g_type_class_unref (g_type_class_peek (GES_TYPE_TRANSITION_CLIP));
  g_type_class_unref (g_type_class_peek (GES_TYPE_OVERLAY_CLIP));
  g_type_class_unref (g_type_class_peek (GES_TYPE_OVERLAY_TEXT_CLIP));

  g_type_class_unref (g_type_class_peek (GES_TYPE_GROUP));

  /* register formatter types with the system */
  g_type_class_unref (g_type_class_peek (GES_TYPE_PITIVI_FORMATTER));
  g_type_class_unref (g_type_class_peek (GES_TYPE_COMMAND_LINE_FORMATTER));
  g_type_class_unref (g_type_class_peek (GES_TYPE_XML_FORMATTER));

  /* Register track elements */
  g_type_class_unref (g_type_class_peek (GES_TYPE_EFFECT));
Guillaume Desmottes's avatar
Guillaume Desmottes committed
180
181
}

182
183
184
185
186
187
188
189
#ifndef GST_DISABLE_OPTION_PARSING
static gboolean
parse_goption_arg (const gchar * s_opt,
    const gchar * arg, gpointer data, GError ** err)
{
  if (g_strcmp0 (s_opt, "--ges-version") == 0) {
    g_print ("GStreamer Editing Services version %s\n", PACKAGE_VERSION);
    exit (0);
190
191
192
193
  } else if (g_strcmp0 (s_opt, "--ges-sample-paths") == 0) {
    ges_add_missing_uri_relocation_uri (arg, FALSE);
  } else if (g_strcmp0 (s_opt, "--ges-sample-path-recurse") == 0) {
    ges_add_missing_uri_relocation_uri (arg, TRUE);
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
  }

  return TRUE;
}
#endif

/**
 * ges_init_get_option_group: (skip)
 *
 * Returns a #GOptionGroup with GES's argument specifications. The
 * group is set up to use standard GOption callbacks, so when using this
 * group in combination with GOption parsing methods, all argument parsing
 * and initialization is automated.
 *
 * This function is useful if you want to integrate GES with other
 * libraries that use GOption (see g_option_context_add_group() ).
 *
 * If you use this function, you should make sure you initialise the GStreamer
212
213
214
 * as one of the very first things in your program. That means you need to
 * use gst_init_get_option_group() and add it to the option context before
 * using the ges_init_get_option_group() result.
215
216
217
218
219
220
221
222
223
224
225
226
227
228
 *
 * Returns: (transfer full): a pointer to GES's option group.
 */
GOptionGroup *
ges_init_get_option_group (void)
{
#ifndef GST_DISABLE_OPTION_PARSING

  GOptionGroup *group;
  static const GOptionEntry ges_args[] = {
    {"ges-version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
          (gpointer) parse_goption_arg,
          "Print the GStreamer Editing Services version",
        NULL},
229
230
    {"ges-sample-paths", 0, 0, G_OPTION_ARG_CALLBACK,
          (gpointer) parse_goption_arg,
231
        "List of pathes to look assets in if they were moved"},
232
233
    {"ges-sample-path-recurse", 0, 0, G_OPTION_ARG_CALLBACK,
          (gpointer) parse_goption_arg,
234
        "Same as above, but recursing into the folder"},
235
236
237
238
    {NULL}
  };

  group = g_option_group_new ("GES", "GStreamer Editing Services Options",
239
      "Show GES Options", NULL, NULL);
240
241
  g_option_group_set_parse_hooks (group, (GOptionParseFunc) ges_init_pre,
      (GOptionParseFunc) ges_init_post);
242
243
244
245
246
247
248
249
  g_option_group_add_entries (group, ges_args);

  return group;

#else
  return NULL;
#endif
}
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

/**
 * ges_version:
 * @major: (out): pointer to a guint to store the major version number
 * @minor: (out): pointer to a guint to store the minor version number
 * @micro: (out): pointer to a guint to store the micro version number
 * @nano:  (out): pointer to a guint to store the nano version number
 *
 * Gets the version number of the GStreamer Editing Services library.
 */
void
ges_version (guint * major, guint * minor, guint * micro, guint * nano)
{
  g_return_if_fail (major);
  g_return_if_fail (minor);
  g_return_if_fail (micro);
  g_return_if_fail (nano);

  *major = GES_VERSION_MAJOR;
  *minor = GES_VERSION_MINOR;
  *micro = GES_VERSION_MICRO;
  *nano = GES_VERSION_NANO;
}
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

/**
 * ges_init_check:
 * @argc: (inout) (allow-none): pointer to application's argc
 * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
 * @err: pointer to a #GError to which a message will be posted on error
 *
 * Initializes the GStreamer Editing Services library, setting up internal path lists,
 * and loading evrything needed.
 *
 * This function will return %FALSE if GES could not be initialized
 * for some reason.
 *
 * Returns: %TRUE if GES could be initialized.
 */
gboolean
ges_init_check (int *argc, char **argv[], GError ** err)
{
#ifndef GST_DISABLE_OPTION_PARSING
  GOptionGroup *group;
  GOptionContext *ctx;
#endif
  gboolean res;

  if (ges_initialized) {
    GST_DEBUG ("already initialized ges");
    return TRUE;
  }
#ifndef GST_DISABLE_OPTION_PARSING
  ctx = g_option_context_new ("- GStreamer Editing Services initialization");
  g_option_context_set_ignore_unknown_options (ctx, TRUE);
  g_option_context_set_help_enabled (ctx, FALSE);
  group = ges_init_get_option_group ();
  g_option_context_add_group (ctx, group);
  res = g_option_context_parse (ctx, argc, argv, err);
  g_option_context_free (ctx);
#endif
  if (!res)
    return res;

  return ges_init ();
}