2010-09-13 23:21:15 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
|
|
|
|
* 2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:gesformatter
|
2017-03-08 21:13:48 +00:00
|
|
|
* @title: GESFormatter
|
2010-11-26 17:39:26 +00:00
|
|
|
* @short_description: Timeline saving and loading.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
|
|
|
**/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2010-09-13 23:21:15 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2012-04-03 23:25:18 +00:00
|
|
|
#include <gio/gio.h>
|
2010-09-13 23:21:15 +00:00
|
|
|
#include <stdlib.h>
|
2012-12-28 22:06:30 +00:00
|
|
|
#include <string.h>
|
2012-01-04 17:59:21 +00:00
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
#include "ges-formatter.h"
|
|
|
|
#include "ges-internal.h"
|
2012-01-04 17:59:21 +00:00
|
|
|
#include "ges.h"
|
2019-07-04 19:58:44 +00:00
|
|
|
#ifndef DISABLE_XPTV
|
|
|
|
#include "ges-pitivi-formatter.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-05 18:46:49 +00:00
|
|
|
#ifdef HAS_PYTHON
|
|
|
|
#include <Python.h>
|
|
|
|
#include "ges-resources.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (ges_formatter_debug);
|
|
|
|
#undef GST_CAT_DEFAULT
|
|
|
|
#define GST_CAT_DEFAULT ges_formatter_debug
|
2019-07-04 19:58:44 +00:00
|
|
|
static gboolean initialized = FALSE;
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
/* TODO Add a GCancellable somewhere in the API */
|
2012-09-24 20:24:42 +00:00
|
|
|
static void ges_extractable_interface_init (GESExtractableInterface * iface);
|
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
struct _GESFormatterPrivate
|
|
|
|
{
|
2012-11-24 02:52:32 +00:00
|
|
|
gpointer nothing;
|
2011-01-08 15:01:31 +00:00
|
|
|
};
|
|
|
|
|
2018-09-06 01:55:02 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GESFormatter, ges_formatter,
|
|
|
|
G_TYPE_INITIALLY_UNOWNED, G_ADD_PRIVATE (GESFormatter)
|
|
|
|
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
|
|
|
|
ges_extractable_interface_init));
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
static void ges_formatter_dispose (GObject * object);
|
2013-04-22 20:34:09 +00:00
|
|
|
static gboolean default_can_load_uri (GESFormatter * dummy_instance,
|
2012-12-17 22:26:23 +00:00
|
|
|
const gchar * uri, GError ** error);
|
2012-09-24 20:24:42 +00:00
|
|
|
|
|
|
|
/* GESExtractable implementation */
|
|
|
|
static gchar *
|
|
|
|
extractable_check_id (GType type, const gchar * id)
|
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
GESFormatterClass *class;
|
|
|
|
|
|
|
|
if (id)
|
2012-09-24 20:24:42 +00:00
|
|
|
return g_strdup (id);
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
class = g_type_class_peek (type);
|
|
|
|
return g_strdup (class->name);
|
2012-09-24 20:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
extractable_get_id (GESExtractable * self)
|
|
|
|
{
|
|
|
|
GESAsset *asset;
|
|
|
|
|
|
|
|
if (!(asset = ges_extractable_get_asset (self)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_strdup (ges_asset_get_id (asset));
|
|
|
|
}
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
static gboolean
|
|
|
|
_register_metas (GESExtractableInterface * iface, GObjectClass * class,
|
|
|
|
GESAsset * asset)
|
2012-09-24 20:24:42 +00:00
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
GESFormatterClass *fclass = GES_FORMATTER_CLASS (class);
|
|
|
|
GESMetaContainer *container = GES_META_CONTAINER (asset);
|
|
|
|
|
|
|
|
ges_meta_container_register_meta_string (container, GES_META_READABLE,
|
|
|
|
GES_META_FORMATTER_NAME, fclass->name);
|
|
|
|
ges_meta_container_register_meta_string (container, GES_META_READABLE,
|
|
|
|
GES_META_DESCRIPTION, fclass->description);
|
|
|
|
ges_meta_container_register_meta_string (container, GES_META_READABLE,
|
|
|
|
GES_META_FORMATTER_MIMETYPE, fclass->mimetype);
|
|
|
|
ges_meta_container_register_meta_string (container, GES_META_READABLE,
|
|
|
|
GES_META_FORMATTER_EXTENSION, fclass->extension);
|
|
|
|
ges_meta_container_register_meta_double (container, GES_META_READABLE,
|
|
|
|
GES_META_FORMATTER_VERSION, fclass->version);
|
|
|
|
ges_meta_container_register_meta_uint (container, GES_META_READABLE,
|
|
|
|
GES_META_FORMATTER_RANK, fclass->rank);
|
2015-05-18 19:24:25 +00:00
|
|
|
ges_meta_container_register_meta_string (container, GES_META_READ_WRITE,
|
|
|
|
GES_META_FORMAT_VERSION, NULL);
|
2012-09-24 20:24:42 +00:00
|
|
|
|
2019-02-05 18:46:49 +00:00
|
|
|
/* We are leaking the metadata but we don't really have choice here
|
|
|
|
* as calling ges_init() after deinit() is allowed.
|
|
|
|
*/
|
2019-03-11 22:25:23 +00:00
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
return TRUE;
|
2012-09-24 20:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_extractable_interface_init (GESExtractableInterface * iface)
|
|
|
|
{
|
|
|
|
iface->check_id = (GESExtractableCheckId) extractable_check_id;
|
|
|
|
iface->get_id = extractable_get_id;
|
2012-12-17 22:26:23 +00:00
|
|
|
iface->asset_type = GES_TYPE_ASSET;
|
|
|
|
iface->register_metas = _register_metas;
|
2012-09-24 20:24:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
static void
|
|
|
|
ges_formatter_class_init (GESFormatterClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = ges_formatter_dispose;
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
klass->can_load_uri = default_can_load_uri;
|
2012-12-17 22:26:23 +00:00
|
|
|
klass->load_from_uri = NULL;
|
|
|
|
klass->save_to_uri = NULL;
|
|
|
|
|
|
|
|
/* We set dummy metas */
|
2019-03-11 22:25:23 +00:00
|
|
|
klass->name = g_strdup ("base-formatter");
|
|
|
|
klass->extension = g_strdup ("noextension");
|
|
|
|
klass->description = g_strdup ("Formatter base class, you should give"
|
|
|
|
" a name to your formatter");
|
|
|
|
klass->mimetype = g_strdup ("No mimetype");
|
2012-12-17 22:26:23 +00:00
|
|
|
klass->version = 0.0;
|
|
|
|
klass->rank = GST_RANK_NONE;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_init (GESFormatter * object)
|
|
|
|
{
|
2018-09-06 01:55:02 +00:00
|
|
|
object->priv = ges_formatter_get_instance_private (object);
|
2012-12-17 22:26:23 +00:00
|
|
|
object->project = NULL;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_dispose (GObject * object)
|
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
ges_formatter_set_project (GES_FORMATTER (object), NULL);
|
2014-03-07 20:48:06 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (ges_formatter_parent_class)->dispose (object);
|
2012-09-23 00:06:44 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
static gboolean
|
2013-04-22 20:34:09 +00:00
|
|
|
default_can_load_uri (GESFormatter * dummy_instance, const gchar * uri,
|
2012-12-17 22:26:23 +00:00
|
|
|
GError ** error)
|
2010-11-26 17:39:26 +00:00
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
GST_DEBUG ("%s: no 'can_load_uri' vmethod implementation",
|
2013-04-22 20:34:09 +00:00
|
|
|
G_OBJECT_TYPE_NAME (dummy_instance));
|
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-28 22:06:30 +00:00
|
|
|
static gchar *
|
|
|
|
_get_extension (const gchar * uri)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
gsize len;
|
|
|
|
gint find;
|
|
|
|
|
|
|
|
GST_DEBUG ("finding extension of %s", uri);
|
|
|
|
|
|
|
|
if (uri == NULL)
|
|
|
|
goto no_uri;
|
|
|
|
|
|
|
|
/* find the extension on the uri, this is everything after a '.' */
|
|
|
|
len = strlen (uri);
|
|
|
|
find = len - 1;
|
|
|
|
|
|
|
|
while (find >= 0) {
|
|
|
|
if (uri[find] == '.')
|
|
|
|
break;
|
|
|
|
find--;
|
|
|
|
}
|
|
|
|
if (find < 0)
|
|
|
|
goto no_extension;
|
|
|
|
|
|
|
|
result = g_strdup (&uri[find + 1]);
|
|
|
|
|
|
|
|
GST_DEBUG ("found extension %s", result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_WARNING ("could not parse the peer uri");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_extension:
|
|
|
|
{
|
|
|
|
GST_WARNING ("could not find uri extension in %s", uri);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_can_load_uri:
|
|
|
|
* @uri: a #gchar * pointing to the URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Checks if there is a #GESFormatter available which can load a #GESTimeline
|
|
|
|
* from the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if there is a #GESFormatter that can support the given uri
|
|
|
|
* or FALSE if not.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
ges_formatter_can_load_uri (const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-12-28 22:06:30 +00:00
|
|
|
gchar *extension;
|
2012-12-17 22:26:23 +00:00
|
|
|
GList *formatter_assets, *tmp;
|
|
|
|
GESFormatterClass *class = NULL;
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
if (!(gst_uri_is_valid (uri))) {
|
|
|
|
GST_ERROR ("Invalid uri!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-28 22:06:30 +00:00
|
|
|
extension = _get_extension (uri);
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
formatter_assets = ges_list_assets (GES_TYPE_FORMATTER);
|
|
|
|
for (tmp = formatter_assets; tmp; tmp = tmp->next) {
|
|
|
|
GESAsset *asset = GES_ASSET (tmp->data);
|
2013-04-22 20:34:09 +00:00
|
|
|
GESFormatter *dummy_instance;
|
2019-04-19 13:07:44 +00:00
|
|
|
gchar **valid_exts =
|
|
|
|
g_strsplit (ges_meta_container_get_string (GES_META_CONTAINER (asset),
|
|
|
|
GES_META_FORMATTER_EXTENSION), ",", -1);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (extension) {
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; valid_exts[i]; i++) {
|
|
|
|
if (!g_strcmp0 (extension, valid_exts[i])) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
goto next;
|
|
|
|
}
|
2012-12-28 22:06:30 +00:00
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
class = g_type_class_ref (ges_asset_get_extractable_type (asset));
|
2013-04-22 20:34:09 +00:00
|
|
|
dummy_instance =
|
2019-01-14 21:28:52 +00:00
|
|
|
g_object_ref_sink (g_object_new (ges_asset_get_extractable_type (asset),
|
|
|
|
NULL));
|
2013-04-22 20:34:09 +00:00
|
|
|
if (class->can_load_uri (dummy_instance, uri, error)) {
|
2012-12-17 22:26:23 +00:00
|
|
|
g_type_class_unref (class);
|
2013-04-22 20:34:09 +00:00
|
|
|
gst_object_unref (dummy_instance);
|
2012-12-17 22:26:23 +00:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_type_class_unref (class);
|
2013-04-22 20:34:09 +00:00
|
|
|
gst_object_unref (dummy_instance);
|
2019-04-19 13:07:44 +00:00
|
|
|
next:
|
|
|
|
g_strfreev (valid_exts);
|
2012-12-17 22:26:23 +00:00
|
|
|
}
|
2019-04-19 13:07:44 +00:00
|
|
|
g_free (extension);
|
2012-12-17 22:26:23 +00:00
|
|
|
|
|
|
|
g_list_free (formatter_assets);
|
|
|
|
return ret;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-26 17:39:26 +00:00
|
|
|
* ges_formatter_can_save_uri:
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns TRUE if there is a #GESFormatter available which can save a
|
|
|
|
* #GESTimeline to the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the given @uri is supported, else FALSE.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
ges_formatter_can_save_uri (const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
2012-07-20 12:19:01 +00:00
|
|
|
GFile *file = NULL;
|
|
|
|
GFile *dir = NULL;
|
2013-08-20 12:22:24 +00:00
|
|
|
gboolean ret = TRUE;
|
2012-07-20 12:19:01 +00:00
|
|
|
GFileInfo *info = NULL;
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
if (!(gst_uri_is_valid (uri))) {
|
2012-01-05 16:21:40 +00:00
|
|
|
GST_ERROR ("%s invalid uri!", uri);
|
2010-09-13 23:21:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(gst_uri_has_protocol (uri, "file"))) {
|
|
|
|
gchar *proto = gst_uri_get_protocol (uri);
|
2019-08-20 21:46:09 +00:00
|
|
|
GST_ERROR ("Unsupported protocol '%s'", proto);
|
2010-09-13 23:21:15 +00:00
|
|
|
g_free (proto);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-20 12:19:01 +00:00
|
|
|
/* Check if URI or parent directory is writeable */
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL)
|
|
|
|
== G_FILE_TYPE_DIRECTORY) {
|
2013-08-20 12:22:24 +00:00
|
|
|
dir = g_object_ref (file);
|
2012-07-20 12:19:01 +00:00
|
|
|
} else {
|
|
|
|
dir = g_file_get_parent (file);
|
|
|
|
|
|
|
|
if (dir == NULL)
|
2013-08-20 12:22:24 +00:00
|
|
|
goto error;
|
2012-07-20 12:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
|
|
|
|
G_FILE_QUERY_INFO_NONE, NULL, error);
|
|
|
|
|
|
|
|
if (error && *error != NULL) {
|
|
|
|
GST_ERROR ("Unable to write to directory: %s", (*error)->message);
|
|
|
|
|
2013-08-20 12:22:24 +00:00
|
|
|
goto error;
|
2012-07-20 12:19:01 +00:00
|
|
|
} else {
|
|
|
|
gboolean writeable = g_file_info_get_attribute_boolean (info,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
|
|
|
|
if (!writeable) {
|
|
|
|
GST_ERROR ("Unable to write to directory");
|
2013-08-20 12:22:24 +00:00
|
|
|
goto error;
|
2012-07-20 12:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 12:22:24 +00:00
|
|
|
done:
|
|
|
|
if (file)
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
if (dir)
|
|
|
|
g_object_unref (dir);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
2012-07-20 12:19:01 +00:00
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
/* TODO: implement file format registry */
|
|
|
|
/* TODO: search through the registry and chose a GESFormatter class that can
|
|
|
|
* handle the URI.*/
|
|
|
|
|
2013-08-20 12:22:24 +00:00
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_load_from_uri:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Load data from the given URI into timeline.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the timeline data was successfully loaded from the URI,
|
|
|
|
* else FALSE.
|
2019-08-20 21:46:09 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.18: Use @ges_timeline_load_from_uri
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2013-04-22 20:34:09 +00:00
|
|
|
ges_formatter_load_from_uri (GESFormatter * formatter,
|
|
|
|
GESTimeline * timeline, const gchar * uri, GError ** error)
|
2010-10-07 13:25:22 +00:00
|
|
|
{
|
2012-05-21 22:10:29 +00:00
|
|
|
gboolean ret = FALSE;
|
2010-10-07 13:25:22 +00:00
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
|
|
|
|
2012-01-04 17:59:21 +00:00
|
|
|
g_return_val_if_fail (GES_IS_FORMATTER (formatter), FALSE);
|
|
|
|
g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
|
|
|
|
|
2012-05-21 22:10:29 +00:00
|
|
|
if (klass->load_from_uri) {
|
2012-07-01 23:34:53 +00:00
|
|
|
formatter->timeline = timeline;
|
2012-09-23 00:05:42 +00:00
|
|
|
ret = klass->load_from_uri (formatter, timeline, uri, error);
|
2012-05-21 22:10:29 +00:00
|
|
|
}
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2012-05-21 22:10:29 +00:00
|
|
|
return ret;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_save_to_uri:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-12-17 22:26:23 +00:00
|
|
|
* @overwrite: %TRUE to overwrite file if it exists
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Save data from timeline to the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the timeline data was successfully saved to the URI
|
|
|
|
* else FALSE.
|
2019-08-20 21:46:09 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.18: Use @ges_timeline_save_to_uri
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2010-10-07 13:25:22 +00:00
|
|
|
ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline *
|
2012-12-17 22:26:23 +00:00
|
|
|
timeline, const gchar * uri, gboolean overwrite, GError ** error)
|
2010-10-07 13:25:22 +00:00
|
|
|
{
|
2012-12-05 11:51:48 +00:00
|
|
|
GError *lerr = NULL;
|
|
|
|
gboolean ret = FALSE;
|
2010-10-07 13:25:22 +00:00
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2012-12-05 11:51:48 +00:00
|
|
|
GST_DEBUG_OBJECT (formatter, "Saving %" GST_PTR_FORMAT " to %s",
|
|
|
|
timeline, uri);
|
2010-10-07 13:25:22 +00:00
|
|
|
if (klass->save_to_uri)
|
2012-12-05 11:51:48 +00:00
|
|
|
ret = klass->save_to_uri (formatter, timeline, uri, overwrite, &lerr);
|
|
|
|
else
|
|
|
|
GST_ERROR_OBJECT (formatter, "save_to_uri not implemented!");
|
|
|
|
|
|
|
|
if (lerr) {
|
|
|
|
GST_WARNING_OBJECT (formatter, "%" GST_PTR_FORMAT
|
|
|
|
" not saved to %s error: %s", timeline, uri, lerr->message);
|
|
|
|
g_propagate_error (error, lerr);
|
|
|
|
} else
|
|
|
|
GST_INFO_OBJECT (formatter, "%" GST_PTR_FORMAT
|
|
|
|
" saved to %s", timeline, uri);
|
2011-05-26 16:15:29 +00:00
|
|
|
|
2012-12-05 11:51:48 +00:00
|
|
|
return ret;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_get_default:
|
|
|
|
*
|
|
|
|
* Get the default #GESAsset to use as formatter. It will return
|
|
|
|
* the asset for the #GESFormatter that has the highest @rank
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The #GESAsset for the formatter with highest @rank
|
|
|
|
*/
|
|
|
|
GESAsset *
|
|
|
|
ges_formatter_get_default (void)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
2012-12-17 22:26:23 +00:00
|
|
|
GList *assets, *tmp;
|
|
|
|
GESAsset *ret = NULL;
|
2016-11-17 18:39:01 +00:00
|
|
|
guint tmprank, rank = GST_RANK_NONE;
|
2012-12-17 22:26:23 +00:00
|
|
|
|
|
|
|
assets = ges_list_assets (GES_TYPE_FORMATTER);
|
|
|
|
for (tmp = assets; tmp; tmp = tmp->next) {
|
|
|
|
tmprank = GST_RANK_NONE;
|
|
|
|
ges_meta_container_get_uint (GES_META_CONTAINER (tmp->data),
|
|
|
|
GES_META_FORMATTER_RANK, &tmprank);
|
|
|
|
|
|
|
|
if (tmprank > rank) {
|
|
|
|
rank = tmprank;
|
|
|
|
ret = GES_ASSET (tmp->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (assets);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-05 13:40:57 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_class_register_metas:
|
|
|
|
* @klass: The class to register metas on
|
|
|
|
* @name: The name of the formatter
|
|
|
|
* @description: The formatter description
|
|
|
|
* @extensions: A list of coma separated file extensions handled
|
|
|
|
* by the formatter. The order of the extensions should match the
|
|
|
|
* list of the structures inside @caps
|
|
|
|
* @caps: The caps the formatter handled, they should match what
|
|
|
|
* gstreamer typefind mechanism will report for the files the formatter
|
|
|
|
* handles.
|
|
|
|
* @version: The version of the formatter
|
|
|
|
* @rank: The rank of the formatter
|
|
|
|
*/
|
2012-12-17 22:26:23 +00:00
|
|
|
void
|
2019-07-05 13:40:57 +00:00
|
|
|
ges_formatter_class_register_metas (GESFormatterClass * klass,
|
2019-03-11 22:25:23 +00:00
|
|
|
const gchar * name, const gchar * description, const gchar * extensions,
|
2019-07-05 13:40:57 +00:00
|
|
|
const gchar * caps, gdouble version, GstRank rank)
|
2012-12-17 22:26:23 +00:00
|
|
|
{
|
2019-07-05 13:40:57 +00:00
|
|
|
g_return_if_fail (klass->name);
|
|
|
|
klass->name = g_strdup (name);
|
|
|
|
klass->description = g_strdup (description);
|
|
|
|
klass->extension = g_strdup (extensions);
|
|
|
|
klass->mimetype = g_strdup (caps);
|
|
|
|
klass->version = version;
|
|
|
|
klass->rank = rank;
|
2019-01-14 21:32:23 +00:00
|
|
|
|
2019-07-04 19:58:44 +00:00
|
|
|
if (g_atomic_int_get (&initialized)
|
2019-07-05 13:40:57 +00:00
|
|
|
&& g_type_class_peek (G_OBJECT_CLASS_TYPE (klass)))
|
|
|
|
gst_object_unref (ges_asset_request (G_OBJECT_CLASS_TYPE (klass), NULL,
|
|
|
|
NULL));
|
2012-12-17 22:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Main Formatter methods */
|
|
|
|
|
|
|
|
/*< protected >*/
|
|
|
|
void
|
|
|
|
ges_formatter_set_project (GESFormatter * formatter, GESProject * project)
|
|
|
|
{
|
|
|
|
formatter->project = project;
|
|
|
|
}
|
|
|
|
|
|
|
|
GESProject *
|
|
|
|
ges_formatter_get_project (GESFormatter * formatter)
|
|
|
|
{
|
|
|
|
return formatter->project;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_list_formatters (GType * formatters, guint n_formatters)
|
|
|
|
{
|
|
|
|
GType *tmptypes, type;
|
|
|
|
guint tmp_n_types, i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_formatters; i++) {
|
|
|
|
type = formatters[i];
|
|
|
|
tmptypes = g_type_children (type, &tmp_n_types);
|
|
|
|
if (tmp_n_types) {
|
|
|
|
/* Recurse as g_type_children does not */
|
|
|
|
_list_formatters (tmptypes, tmp_n_types);
|
|
|
|
}
|
2012-12-31 01:37:22 +00:00
|
|
|
g_free (tmptypes);
|
2012-12-17 22:26:23 +00:00
|
|
|
|
|
|
|
if (G_TYPE_IS_ABSTRACT (type)) {
|
|
|
|
GST_DEBUG ("%s is abstract, not using", g_type_name (type));
|
|
|
|
} else {
|
|
|
|
gst_object_unref (ges_asset_request (type, NULL, NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 18:46:49 +00:00
|
|
|
static void
|
|
|
|
load_python_formatters (void)
|
|
|
|
{
|
|
|
|
#ifdef HAS_PYTHON
|
|
|
|
PyGILState_STATE state = 0;
|
|
|
|
PyObject *main_module, *main_locals;
|
|
|
|
GError *err = NULL;
|
|
|
|
GResource *resource = ges_get_resource ();
|
|
|
|
GBytes *bytes =
|
|
|
|
g_resource_lookup_data (resource, "/ges/python/gesotioformatter.py",
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
|
|
|
|
PyObject *code = NULL, *res = NULL;
|
|
|
|
gboolean we_initialized = FALSE;
|
|
|
|
GModule *libpython;
|
|
|
|
gpointer has_python = NULL;
|
|
|
|
|
|
|
|
GST_LOG ("Checking to see if libpython is already loaded");
|
|
|
|
if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LOCAL),
|
|
|
|
"_Py_NoneStruct", &has_python) && has_python) {
|
|
|
|
GST_LOG ("libpython is already loaded");
|
|
|
|
} else {
|
|
|
|
const gchar *libpython_path =
|
|
|
|
PY_LIB_LOC "/libpython" PYTHON_VERSION PY_ABI_FLAGS "." PY_LIB_SUFFIX;
|
|
|
|
GST_LOG ("loading libpython from '%s'", libpython_path);
|
|
|
|
libpython = g_module_open (libpython_path, 0);
|
|
|
|
if (!libpython) {
|
|
|
|
GST_ERROR ("Couldn't g_module_open libpython. Reason: %s",
|
|
|
|
g_module_error ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Py_IsInitialized ()) {
|
|
|
|
GST_LOG ("python wasn't initialized");
|
|
|
|
/* set the correct plugin for registering stuff */
|
|
|
|
Py_Initialize ();
|
|
|
|
we_initialized = TRUE;
|
|
|
|
} else {
|
|
|
|
GST_LOG ("python was already initialized");
|
|
|
|
state = PyGILState_Ensure ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bytes) {
|
|
|
|
GST_DEBUG ("Could not load gesotioformatter: %s\n", err->message);
|
|
|
|
|
|
|
|
g_clear_error (&err);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
main_module = PyImport_AddModule ("__main__");
|
|
|
|
if (main_module == NULL) {
|
|
|
|
GST_WARNING ("Could not add main module");
|
|
|
|
PyErr_Print ();
|
|
|
|
PyErr_Clear ();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
main_locals = PyModule_GetDict (main_module);
|
|
|
|
/* Compiling the code ourself so it has a proper filename */
|
|
|
|
code =
|
|
|
|
Py_CompileString (g_bytes_get_data (bytes, NULL), "gesotioformatter.py",
|
|
|
|
Py_file_input);
|
|
|
|
if (PyErr_Occurred ()) {
|
|
|
|
PyErr_Print ();
|
|
|
|
PyErr_Clear ();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
res = PyEval_EvalCode ((gpointer) code, main_locals, main_locals);
|
|
|
|
Py_XDECREF (code);
|
|
|
|
Py_XDECREF (res);
|
|
|
|
if (PyErr_Occurred ()) {
|
2020-05-04 14:35:25 +00:00
|
|
|
PyObject *exception_backtrace;
|
|
|
|
PyObject *exception_type;
|
|
|
|
PyObject *exception_value, *exception_value_repr, *exception_value_str;
|
|
|
|
|
|
|
|
PyErr_Fetch (&exception_type, &exception_value, &exception_backtrace);
|
|
|
|
PyErr_NormalizeException (&exception_type, &exception_value,
|
|
|
|
&exception_backtrace);
|
|
|
|
|
|
|
|
exception_value_repr = PyObject_Repr (exception_value);
|
|
|
|
exception_value_str =
|
|
|
|
PyUnicode_AsEncodedString (exception_value_repr, "utf-8", "Error ~");
|
|
|
|
GST_INFO ("Could not load OpenTimelineIO formatter: %s",
|
|
|
|
PyBytes_AS_STRING (exception_value_str));
|
|
|
|
|
|
|
|
Py_XDECREF (exception_type);
|
|
|
|
Py_XDECREF (exception_value);
|
|
|
|
Py_XDECREF (exception_backtrace);
|
|
|
|
|
|
|
|
Py_XDECREF (exception_value_repr);
|
|
|
|
Py_XDECREF (exception_value_str);
|
2019-02-05 18:46:49 +00:00
|
|
|
PyErr_Clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (bytes)
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
|
|
|
if (we_initialized) {
|
|
|
|
PyEval_SaveThread ();
|
|
|
|
} else {
|
|
|
|
PyGILState_Release (state);
|
|
|
|
}
|
|
|
|
#endif /* HAS_PYTHON */
|
|
|
|
}
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
void
|
|
|
|
_init_formatter_assets (void)
|
|
|
|
{
|
|
|
|
GType *formatters;
|
|
|
|
guint n_formatters;
|
2019-02-05 18:46:49 +00:00
|
|
|
static gsize init_debug = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&init_debug)) {
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (ges_formatter_debug, "gesformatter",
|
|
|
|
GST_DEBUG_FG_YELLOW, "ges formatter");
|
|
|
|
g_once_init_leave (&init_debug, TRUE);
|
|
|
|
}
|
|
|
|
|
2019-07-04 19:58:44 +00:00
|
|
|
if (g_atomic_int_compare_and_exchange (&initialized, FALSE, TRUE)) {
|
|
|
|
/* register formatter types with the system */
|
|
|
|
#ifndef DISABLE_XPTV
|
|
|
|
g_type_class_ref (GES_TYPE_PITIVI_FORMATTER);
|
|
|
|
#endif
|
|
|
|
g_type_class_ref (GES_TYPE_COMMAND_LINE_FORMATTER);
|
|
|
|
g_type_class_ref (GES_TYPE_XML_FORMATTER);
|
2019-02-05 18:46:49 +00:00
|
|
|
|
2019-07-04 19:58:44 +00:00
|
|
|
load_python_formatters ();
|
|
|
|
|
|
|
|
formatters = g_type_children (GES_TYPE_FORMATTER, &n_formatters);
|
|
|
|
_list_formatters (formatters, n_formatters);
|
|
|
|
g_free (formatters);
|
|
|
|
}
|
|
|
|
}
|
2012-12-17 22:26:23 +00:00
|
|
|
|
2019-07-04 19:58:44 +00:00
|
|
|
void
|
|
|
|
_deinit_formatter_assets (void)
|
|
|
|
{
|
|
|
|
if (g_atomic_int_compare_and_exchange (&initialized, TRUE, FALSE)) {
|
|
|
|
|
|
|
|
#ifndef DISABLE_XPTV
|
|
|
|
g_type_class_unref (g_type_class_peek (GES_TYPE_PITIVI_FORMATTER));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2012-12-17 22:26:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:45:55 +00:00
|
|
|
static gint
|
|
|
|
_sort_formatters (GESAsset * asset, GESAsset * asset1)
|
|
|
|
{
|
|
|
|
GESFormatterClass *class =
|
|
|
|
g_type_class_peek (ges_asset_get_extractable_type (asset));
|
|
|
|
GESFormatterClass *class1 =
|
|
|
|
g_type_class_peek (ges_asset_get_extractable_type (asset1));
|
|
|
|
|
|
|
|
/* We want the highest ranks to be first! */
|
|
|
|
if (class->rank > class1->rank)
|
|
|
|
return -1;
|
|
|
|
else if (class->rank < class1->rank)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
GESAsset *
|
2015-02-23 13:48:18 +00:00
|
|
|
_find_formatter_asset_for_id (const gchar * id)
|
2012-12-17 22:26:23 +00:00
|
|
|
{
|
|
|
|
GESFormatterClass *class = NULL;
|
|
|
|
GList *formatter_assets, *tmp;
|
|
|
|
GESAsset *asset = NULL;
|
|
|
|
|
2013-10-08 16:45:55 +00:00
|
|
|
formatter_assets = g_list_sort (ges_list_assets (GES_TYPE_FORMATTER),
|
|
|
|
(GCompareFunc) _sort_formatters);
|
2012-12-17 22:26:23 +00:00
|
|
|
for (tmp = formatter_assets; tmp; tmp = tmp->next) {
|
2013-04-22 20:34:09 +00:00
|
|
|
GESFormatter *dummy_instance;
|
|
|
|
|
2012-12-17 22:26:23 +00:00
|
|
|
asset = GES_ASSET (tmp->data);
|
|
|
|
class = g_type_class_ref (ges_asset_get_extractable_type (asset));
|
2013-04-22 20:34:09 +00:00
|
|
|
dummy_instance =
|
2019-01-14 21:28:52 +00:00
|
|
|
g_object_ref_sink (g_object_new (ges_asset_get_extractable_type (asset),
|
|
|
|
NULL));
|
2015-02-23 13:48:18 +00:00
|
|
|
if (class->can_load_uri (dummy_instance, id, NULL)) {
|
2012-12-17 22:26:23 +00:00
|
|
|
g_type_class_unref (class);
|
|
|
|
asset = gst_object_ref (asset);
|
2013-04-22 20:34:09 +00:00
|
|
|
gst_object_unref (dummy_instance);
|
2012-12-17 22:26:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
asset = NULL;
|
|
|
|
g_type_class_unref (class);
|
2013-04-22 20:34:09 +00:00
|
|
|
gst_object_unref (dummy_instance);
|
2012-12-17 22:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (formatter_assets);
|
|
|
|
|
|
|
|
return asset;
|
2012-01-04 17:59:21 +00:00
|
|
|
}
|
2019-07-04 00:15:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_find_formatter_for_uri:
|
|
|
|
*
|
|
|
|
* Get the best formatter for @uri. It tries to find a formatter
|
|
|
|
* compatible with @uri extension, if none is found, it returns the default
|
|
|
|
* formatter asset.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The #GESAsset for the best formatter to save to @uri
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
GESAsset *
|
|
|
|
ges_find_formatter_for_uri (const gchar * uri)
|
|
|
|
{
|
|
|
|
GList *formatter_assets, *tmp;
|
|
|
|
GESAsset *asset = NULL;
|
|
|
|
|
|
|
|
gchar *extension = _get_extension (uri);
|
|
|
|
if (!extension)
|
|
|
|
return ges_formatter_get_default ();
|
|
|
|
|
|
|
|
formatter_assets = g_list_sort (ges_list_assets (GES_TYPE_FORMATTER),
|
|
|
|
(GCompareFunc) _sort_formatters);
|
|
|
|
|
|
|
|
for (tmp = formatter_assets; tmp; tmp = tmp->next) {
|
|
|
|
gint i;
|
|
|
|
gchar **valid_exts =
|
|
|
|
g_strsplit (ges_meta_container_get_string (GES_META_CONTAINER
|
|
|
|
(tmp->data),
|
|
|
|
GES_META_FORMATTER_EXTENSION), ",", -1);
|
|
|
|
|
|
|
|
for (i = 0; valid_exts[i]; i++) {
|
|
|
|
if (!g_strcmp0 (extension, valid_exts[i])) {
|
|
|
|
asset = GES_ASSET (tmp->data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (valid_exts);
|
|
|
|
if (asset)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (extension);
|
|
|
|
g_list_free (formatter_assets);
|
|
|
|
|
|
|
|
if (asset) {
|
|
|
|
GST_INFO_OBJECT (asset, "Using for URI %s", uri);
|
|
|
|
return asset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ges_formatter_get_default ();
|
|
|
|
}
|