mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 00:11:59 +02:00
clapper-app: Create pipeline preview file async
This commit is contained in:
@@ -548,42 +548,42 @@ _get_tmp_dir (const gchar *subdir)
|
||||
|
||||
#ifdef HAVE_GRAPHVIZ
|
||||
static GFile *
|
||||
_create_tmp_subdir (const gchar *subdir)
|
||||
_create_tmp_subdir (const gchar *subdir, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
GFile *tmp_dir;
|
||||
GError *error = NULL;
|
||||
GError *my_error = NULL;
|
||||
|
||||
tmp_dir = _get_tmp_dir (subdir);
|
||||
|
||||
if (!g_file_make_directory_with_parents (tmp_dir, NULL, &error)) {
|
||||
if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_EXISTS) {
|
||||
GST_ERROR ("Could not create temp dir, reason: %s",
|
||||
GST_STR_NULL (error->message));
|
||||
if (!g_file_make_directory_with_parents (tmp_dir, cancellable, &my_error)) {
|
||||
if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_EXISTS) {
|
||||
*error = g_error_copy (my_error);
|
||||
g_clear_object (&tmp_dir); // return NULL
|
||||
}
|
||||
g_error_free (error);
|
||||
g_error_free (my_error);
|
||||
}
|
||||
|
||||
return tmp_dir;
|
||||
}
|
||||
#endif
|
||||
|
||||
GFile *
|
||||
clapper_app_utils_create_pipeline_svg_file (ClapperPlayer *player, GError **error)
|
||||
static void
|
||||
_create_pipeline_svg_file_in_thread (GTask *task, GObject *source G_GNUC_UNUSED,
|
||||
ClapperPlayer *player, GCancellable *cancellable)
|
||||
{
|
||||
GFile *tmp_file = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
#ifdef HAVE_GRAPHVIZ
|
||||
GFile *tmp_subdir;
|
||||
Agraph_t *graph;
|
||||
GVC_t *gvc;
|
||||
gchar *path, *template, *dot_data, *img_data = NULL;
|
||||
gchar *path, *template = NULL, *dot_data = NULL, *img_data = NULL;
|
||||
gint fd;
|
||||
guint size = 0;
|
||||
|
||||
tmp_subdir = _create_tmp_subdir ("pipelines");
|
||||
if (G_UNLIKELY (tmp_subdir == NULL))
|
||||
return NULL;
|
||||
if (!(tmp_subdir = _create_tmp_subdir ("pipelines", cancellable, &error)))
|
||||
goto finish;
|
||||
|
||||
path = g_file_get_path (tmp_subdir);
|
||||
g_object_unref (tmp_subdir);
|
||||
@@ -594,14 +594,16 @@ clapper_app_utils_create_pipeline_svg_file (ClapperPlayer *player, GError **erro
|
||||
fd = g_mkstemp (template); // Modifies template to actual filename
|
||||
|
||||
if (G_UNLIKELY (fd == -1)) {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"Could not open temp file for writing");
|
||||
g_free (template);
|
||||
|
||||
return NULL;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
dot_data = clapper_player_make_pipeline_graph (player, GST_DEBUG_GRAPH_SHOW_ALL);
|
||||
|
||||
if (g_cancellable_is_cancelled (cancellable))
|
||||
goto close_and_finish;
|
||||
|
||||
graph = agmemread (dot_data);
|
||||
|
||||
gvc = gvContext ();
|
||||
@@ -610,27 +612,48 @@ clapper_app_utils_create_pipeline_svg_file (ClapperPlayer *player, GError **erro
|
||||
|
||||
agclose (graph);
|
||||
gvFreeContext (gvc);
|
||||
g_free (dot_data);
|
||||
|
||||
if (g_cancellable_is_cancelled (cancellable))
|
||||
goto close_and_finish;
|
||||
|
||||
if (write (fd, img_data, size) != -1) {
|
||||
tmp_file = g_file_new_for_path (template);
|
||||
} else {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"Could not write data to temp file");
|
||||
}
|
||||
|
||||
close_and_finish:
|
||||
/* Always close the file IO */
|
||||
if (G_UNLIKELY (close (fd) == -1))
|
||||
GST_ERROR ("Could not close temp file!");
|
||||
|
||||
g_free (img_data);
|
||||
finish:
|
||||
g_free (template);
|
||||
g_free (dot_data);
|
||||
g_free (img_data);
|
||||
#else
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"Cannot create graph file when compiled without Graphviz");
|
||||
#endif
|
||||
|
||||
return tmp_file;
|
||||
if (tmp_file)
|
||||
g_task_return_pointer (task, tmp_file, (GDestroyNotify) g_object_unref);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
void
|
||||
clapper_app_utils_create_pipeline_svg_file_async (ClapperPlayer *player,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
GTask *task;
|
||||
|
||||
task = g_task_new (NULL, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, gst_object_ref (player), (GDestroyNotify) gst_object_unref);
|
||||
g_task_run_in_thread (task, (GTaskThreadFunc) _create_pipeline_svg_file_in_thread);
|
||||
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
Reference in New Issue
Block a user