mediafile: Turn into an extension point
This way, we can support external libraries providing implementations of GtkMediaFile. We also add a media backend called 'nomedia' that can be enabled to not compile any support for GtkMediaFile. This is useful when people want to statically compile GTK into an application that does not use media. For now, this option is the default. We also support a new environment variable GTK_MEDIA that allows selecting the implementation to use. GTK_MEDIA=help can be used to get info about the available implementations.
This commit is contained in:
committed by
Benjamin Otte
parent
427bce6c54
commit
bd25c4110c
@@ -119,6 +119,7 @@
|
||||
#include "gtkdebugupdatesprivate.h"
|
||||
#include "gtkdndprivate.h"
|
||||
#include "gtkmain.h"
|
||||
#include "gtkmediafileprivate.h"
|
||||
#include "gtkmenu.h"
|
||||
#include "gtkmodulesprivate.h"
|
||||
#include "gtkprivate.h"
|
||||
@@ -632,6 +633,7 @@ default_display_notify_cb (GdkDisplayManager *dm)
|
||||
debug_flags[0].display = gdk_display_get_default ();
|
||||
gtk_print_backends_init ();
|
||||
gtk_im_modules_init ();
|
||||
gtk_media_file_extension_init ();
|
||||
_gtk_accessibility_init ();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkmediafile.h"
|
||||
#include "gtkmediafileprivate.h"
|
||||
|
||||
#include "gtkdebug.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkmodulesprivate.h"
|
||||
#include "gtknomediafileprivate.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkmediafile
|
||||
@@ -179,8 +182,64 @@ gtk_media_file_init (GtkMediaFile *self)
|
||||
static GType
|
||||
gtk_media_file_get_impl_type (void)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return G_TYPE_INVALID;
|
||||
static GType impl_type = G_TYPE_NONE;
|
||||
const char *extension_name;
|
||||
GIOExtension *e;
|
||||
GIOExtensionPoint *ep;
|
||||
|
||||
if (G_LIKELY (impl_type != G_TYPE_NONE))
|
||||
return impl_type;
|
||||
|
||||
GTK_NOTE (MODULES, g_print ("Looking up MediaFile extension\n"));
|
||||
|
||||
ep = g_io_extension_point_lookup (GTK_MEDIA_FILE_EXTENSION_POINT_NAME);
|
||||
e = NULL;
|
||||
|
||||
extension_name = g_getenv ("GTK_MEDIA");
|
||||
if (extension_name)
|
||||
{
|
||||
if (g_str_equal (extension_name, "help"))
|
||||
{
|
||||
GList *l;
|
||||
|
||||
g_print ("Supported arguments for GTK_MEDIA environment variable:\n");
|
||||
|
||||
for (l = g_io_extension_point_get_extensions (ep); l; l = l->next)
|
||||
{
|
||||
e = l->data;
|
||||
|
||||
g_print ("%10s - %d\n", g_io_extension_get_name (e), g_io_extension_get_priority (e));
|
||||
}
|
||||
|
||||
e = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
e = g_io_extension_point_get_extension_by_name (ep, extension_name);
|
||||
if (e == NULL)
|
||||
{
|
||||
g_warning ("Media extension \"%s\" from GTK_MEDIA environment variable not found.", extension_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (e == NULL)
|
||||
{
|
||||
GList *l = g_io_extension_point_get_extensions (ep);
|
||||
|
||||
if (l == NULL)
|
||||
{
|
||||
g_error ("GTK was run without any GtkMediaFile extension being present. This must not happen.");
|
||||
}
|
||||
|
||||
e = l->data;
|
||||
}
|
||||
|
||||
impl_type = g_io_extension_get_type (e);
|
||||
|
||||
GTK_NOTE (MODULES, g_print ("Using %s from \"%s\" extension\n", g_type_name (impl_type), g_io_extension_get_name (e)));
|
||||
|
||||
return impl_type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,3 +583,47 @@ gtk_media_file_get_input_stream (GtkMediaFile *self)
|
||||
|
||||
return priv->input_stream;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_media_file_extension_init (void)
|
||||
{
|
||||
GIOExtensionPoint *ep;
|
||||
GIOModuleScope *scope;
|
||||
char **paths;
|
||||
int i;
|
||||
|
||||
GTK_NOTE (MODULES,
|
||||
g_print ("Registering extension point %s\n", GTK_MEDIA_FILE_EXTENSION_POINT_NAME));
|
||||
|
||||
ep = g_io_extension_point_register (GTK_MEDIA_FILE_EXTENSION_POINT_NAME);
|
||||
g_io_extension_point_set_required_type (ep, GTK_TYPE_MEDIA_FILE);
|
||||
|
||||
g_type_ensure (GTK_TYPE_NO_MEDIA_FILE);
|
||||
|
||||
scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
|
||||
|
||||
paths = _gtk_get_module_path ("media");
|
||||
for (i = 0; paths[i]; i++)
|
||||
{
|
||||
GTK_NOTE (MODULES,
|
||||
g_print ("Scanning io modules in %s\n", paths[i]));
|
||||
g_io_modules_scan_all_in_directory_with_scope (paths[i], scope);
|
||||
}
|
||||
g_strfreev (paths);
|
||||
|
||||
g_io_module_scope_free (scope);
|
||||
|
||||
if (GTK_DEBUG_CHECK (MODULES))
|
||||
{
|
||||
GList *list, *l;
|
||||
|
||||
list = g_io_extension_point_get_extensions (ep);
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
GIOExtension *ext = l->data;
|
||||
g_print ("extension: %s: type %s\n",
|
||||
g_io_extension_get_name (ext),
|
||||
g_type_name (g_io_extension_get_type (ext)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_MEDIA_FILE_EXTENSION_POINT_NAME "gtk-media-file"
|
||||
|
||||
#define GTK_TYPE_MEDIA_FILE (gtk_media_file_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
||||
29
gtk/gtkmediafileprivate.h
Normal file
29
gtk/gtkmediafileprivate.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright © 2018 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_MEDIA_FILE_PRIVATE_H__
|
||||
#define __GTK_MEDIA_FILE_PRIVATE_H__
|
||||
|
||||
#include "gtkmediafile.h"
|
||||
|
||||
|
||||
void gtk_media_file_extension_init (void);
|
||||
|
||||
|
||||
#endif /* __GTK_MEDIA_FILE_PRIVATE_H__ */
|
||||
63
gtk/gtknomediafile.c
Normal file
63
gtk/gtknomediafile.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright © 2018 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtknomediafileprivate.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
|
||||
struct _GtkNoMediaFile
|
||||
{
|
||||
GtkMediaFile parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkNoMediaFileClass
|
||||
{
|
||||
GtkMediaFileClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkNoMediaFile, gtk_no_media_file, GTK_TYPE_MEDIA_FILE,
|
||||
g_io_extension_point_implement (GTK_MEDIA_FILE_EXTENSION_POINT_NAME,
|
||||
g_define_type_id,
|
||||
"none",
|
||||
G_MININT);)
|
||||
|
||||
static void
|
||||
gtk_no_media_file_open (GtkMediaFile *file)
|
||||
{
|
||||
gtk_media_stream_error (GTK_MEDIA_STREAM (file),
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
_("GTK has been compiled without media support."));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_no_media_file_class_init (GtkNoMediaFileClass *klass)
|
||||
{
|
||||
GtkMediaFileClass *file_class = GTK_MEDIA_FILE_CLASS (klass);
|
||||
|
||||
file_class->open = gtk_no_media_file_open;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_no_media_file_init (GtkNoMediaFile *video)
|
||||
{
|
||||
}
|
||||
|
||||
33
gtk/gtknomediafileprivate.h
Normal file
33
gtk/gtknomediafileprivate.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright © 2018 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_NO_MEDIA_FILE_H__
|
||||
#define __GTK_NO_MEDIA_FILE_H__
|
||||
|
||||
#include <gtk/gtkmediafile.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_NO_MEDIA_FILE (gtk_no_media_file_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GtkNoMediaFile, gtk_no_media_file, GTK, NO_MEDIA_FILE, GtkMediaFile)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_NO_MEDIA_FILE_H__ */
|
||||
@@ -265,6 +265,7 @@ gtk_public_sources = files([
|
||||
'gtkmodules.c',
|
||||
'gtkmountoperation.c',
|
||||
'gtknativedialog.c',
|
||||
'gtknomediafile.c',
|
||||
'gtknotebook.c',
|
||||
'gtkorientable.c',
|
||||
'gtkoverlay.c',
|
||||
|
||||
16
meson.build
16
meson.build
@@ -589,6 +589,21 @@ if cloudproviders_enabled
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
media_backends = []
|
||||
|
||||
# We require manually disabling support for media backends.
|
||||
# People should only do that when they know exactly what they're doing
|
||||
# (either not using media or providing their own implementation.)
|
||||
if get_option('nomedia')
|
||||
media_backends += ['none']
|
||||
endif
|
||||
|
||||
if media_backends.length() == 0
|
||||
error('No media backends enabled. If you are sure about that, enable the "nomedia" option.')
|
||||
endif
|
||||
|
||||
|
||||
subdir('gdk')
|
||||
subdir('gsk')
|
||||
subdir('gtk')
|
||||
@@ -705,6 +720,7 @@ summary = [
|
||||
' Enabled backends: @0@'.format(pkg_targets.strip()),
|
||||
' Vulkan support: @0@'.format(have_vulkan),
|
||||
' Print backends: @0@'.format(' '.join(print_backends)),
|
||||
' Media backends: @0@'.format(' '.join(media_backends)),
|
||||
' Tests: @0@'.format(get_option('build-tests')),
|
||||
' Documentation: @0@'.format(get_option('documentation')),
|
||||
' Demos: @0@'.format(get_option('demos')),
|
||||
|
||||
@@ -10,6 +10,10 @@ option('win32-backend', type: 'boolean', value: true,
|
||||
option('quartz-backend', type: 'boolean', value: true,
|
||||
description : 'Enable the macOS gdk backend (only when building on macOS)')
|
||||
|
||||
# Media backends
|
||||
option('nomedia', type: 'boolean', value: true,
|
||||
description : 'Set to confirm that no media backend should be enabled')
|
||||
|
||||
# Optional dependencies
|
||||
option('vulkan', type: 'combo', choices : ['yes', 'no', 'auto'], value : 'auto',
|
||||
description : 'Enable support for the Vulkan graphics API')
|
||||
|
||||
3
modules/media/meson.build
Normal file
3
modules/media/meson.build
Normal file
@@ -0,0 +1,3 @@
|
||||
media_subdir = 'gtk-4.0/@0@/media'.format(gtk_binary_version)
|
||||
media_install_dir = join_paths(get_option('libdir'), media_subdir)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
if os_unix
|
||||
subdir('printbackends')
|
||||
endif
|
||||
|
||||
subdir('media')
|
||||
|
||||
Reference in New Issue
Block a user