tag: Generate GLib enums/flags with glib-mkenums

This commit is contained in:
Sebastian Dröge 2017-04-09 12:51:52 +03:00
parent b56dcb3e20
commit e74e1e80fa
8 changed files with 91 additions and 140 deletions

View file

@ -1,8 +1,23 @@
libgsttagincludedir = \
$(includedir)/gstreamer-@GST_API_VERSION@/gst/tag
glib_enum_define = GST_TAG
glib_gen_prefix = gst_tag
glib_gen_basename = tag
glib_enum_headers = tag.h gsttagdemux.h
built_sources = tag-enumtypes.c
built_headers = tag-enumtypes.h
BUILT_SOURCES = $(built_sources) $(built_headers)
include $(top_srcdir)/common/gst-glib-gen.mak
libgsttaginclude_HEADERS = \
tag.h gsttagdemux.h gsttagmux.h xmpwriter.h
nodist_libgsttaginclude_HEADERS = tag-enumtypes.h
CLEANFILES = $(BUILT_SOURCES)
lib_LTLIBRARIES = libgsttag-@GST_API_VERSION@.la
@ -10,6 +25,7 @@ libgsttag_@GST_API_VERSION@_la_SOURCES = \
gstvorbistag.c gstid3tag.c gstxmptag.c gstexiftag.c \
lang.c licenses.c tags.c gsttagdemux.c gsttagmux.c \
gsttageditingprivate.c id3v2.c id3v2frames.c xmpwriter.c
nodist_libgsttag_@GST_API_VERSION@_la_SOURCES = $(BUILT_SOURCES)
libgsttag_@GST_API_VERSION@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(ZLIB_CFLAGS) \
@ -73,7 +89,7 @@ typelibs_DATA = $(BUILT_GIRSOURCES:.gir=.typelib)
--includedir=`PKG_CONFIG_PATH="$(GST_PKG_CONFIG_PATH)" $(PKG_CONFIG) --variable=girdir gstreamer-base-@GST_API_VERSION@` \
$(INTROSPECTION_COMPILER_OPTS) $< -o $(@F)
CLEANFILES = $(BUILT_GIRSOURCES) $(typelibs_DATA)
CLEANFILES += $(BUILT_GIRSOURCES) $(typelibs_DATA)
endif
# little program that reads iso_639.xml and outputs tables for us as fallback

View file

@ -168,23 +168,6 @@ static void gst_tag_demux_init (GstTagDemux * obj, GstTagDemuxClass * klass);
static gpointer parent_class; /* NULL */
GType
gst_tag_demux_result_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{GST_TAG_DEMUX_RESULT_BROKEN_TAG, "GST_TAG_DEMUX_RESULT_BROKEN_TAG",
"broken-tag"},
{GST_TAG_DEMUX_RESULT_AGAIN, "GST_TAG_DEMUX_RESULT_AGAIN", "again"},
{GST_TAG_DEMUX_RESULT_OK, "GST_TAG_DEMUX_RESULT_OK", "ok"},
{0, NULL, NULL}
};
etype = g_enum_register_static ("GstTagDemuxResult", values);
}
return etype;
}
/* Cannot use boilerplate macros here because we want the abstract flag */
GType
gst_tag_demux_get_type (void)

View file

@ -22,6 +22,7 @@
#define __GST_TAG_DEMUX_H__
#include <gst/gst.h>
#include <gst/tag/tag-enumtypes.h>
G_BEGIN_DECLS
@ -49,9 +50,6 @@ typedef enum {
GST_TAG_DEMUX_RESULT_OK
} GstTagDemuxResult;
GType gst_tag_demux_result_get_type (void);
#define GST_TYPE_TAG_DEMUX_RESULT (gst_tag_demux_result_get_type())
/**
* GstTagDemux:
* @element: parent element

View file

@ -507,55 +507,3 @@ gst_tag_get_license_version (const gchar * license_ref)
GST_ERROR ("Could not determine version for ref '%s'", license_ref);
return NULL;
}
GType
gst_tag_license_flags_get_type (void)
{
/* FIXME: we should really be using glib-mkenums for this.. */
#define C_FLAGS(v) ((guint) v)
static gsize id = 0;
static const GFlagsValue values[] = {
{C_FLAGS (GST_TAG_LICENSE_PERMITS_REPRODUCTION),
"GST_TAG_LICENSE_PERMITS_REPRODUCTION", "permits-reproduction"},
{C_FLAGS (GST_TAG_LICENSE_PERMITS_DISTRIBUTION),
"GST_TAG_LICENSE_PERMITS_DISTRIBUTION", "permits-distribution"},
{C_FLAGS (GST_TAG_LICENSE_PERMITS_DERIVATIVE_WORKS),
"GST_TAG_LICENSE_PERMITS_DERIVATIVE_WORKS",
"permits-derivative-works"},
{C_FLAGS (GST_TAG_LICENSE_PERMITS_SHARING),
"GST_TAG_LICENSE_PERMITS_SHARING", "permits-sharing"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_NOTICE),
"GST_TAG_LICENSE_REQUIRES_NOTICE", "requires-notice"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_ATTRIBUTION),
"GST_TAG_LICENSE_REQUIRES_ATTRIBUTION", "requires-attributions"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_SHARE_ALIKE),
"GST_TAG_LICENSE_REQUIRES_SHARE_ALIKE", "requires-share-alike"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_SOURCE_CODE),
"GST_TAG_LICENSE_REQUIRES_SOURCE_CODE", "requires-source-code"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_COPYLEFT),
"GST_TAG_LICENSE_REQUIRES_COPYLEFT", "requires-copyleft"},
{C_FLAGS (GST_TAG_LICENSE_REQUIRES_LESSER_COPYLEFT),
"GST_TAG_LICENSE_REQUIRES_LESSER_COPYLEFT",
"requires-lesser-copyleft"},
{C_FLAGS (GST_TAG_LICENSE_PROHIBITS_COMMERCIAL_USE),
"GST_TAG_LICENSE_PROHIBITS_COMMERCIAL_USE",
"prohibits-commercial-use"},
{C_FLAGS (GST_TAG_LICENSE_PROHIBITS_HIGH_INCOME_NATION_USE),
"GST_TAG_LICENSE_PROHIBITS_HIGH_INCOME_NATION_USE",
"prohibits-high-income-nation-use"},
{C_FLAGS (GST_TAG_LICENSE_CREATIVE_COMMONS_LICENSE),
"GST_TAG_LICENSE_CREATIVE_COMMONS_LICENSE",
"creative-commons-license"},
{C_FLAGS (GST_TAG_LICENSE_FREE_SOFTWARE_FOUNDATION_LICENSE),
"GST_TAG_LICENSE_FREE_SOFTWARE_FOUNDATION_LICENSE",
"free-software-foundation-license"},
{0, NULL, NULL}
};
if (g_once_init_enter (&id)) {
GType tmp = g_flags_register_static ("GstTagLicenseFlags", values);
g_once_init_leave (&id, tmp);
}
return (GType) id;
}

View file

@ -22,9 +22,24 @@ tag_headers = [
]
install_headers(tag_headers, subdir : 'gstreamer-1.0/gst/tag/')
mkenums = find_program('tag_mkenum.py')
gsttag_h = custom_target('gsttagenum_h',
output : 'tag-enumtypes.h',
input : tag_mkenum_headers,
install : true,
install_dir : 'include/gstreamer-1.0/gst/tag/',
command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
gsttag_c = custom_target('gsttagenum_c',
output : 'tag-enumtypes.c',
input : tag_mkenum_headers,
depends : [gsttag_h],
command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
tag_gen_sources = [gsttag_h]
tag_deps = [gst_base_dep, libm]
gsttag = library('gsttag-@0@'.format(api_version),
tag_sources,
tag_sources, gsttag_h, gsttag_c,
c_args : gst_plugins_base_args,
include_directories: [configinc, libsinc],
version : libversion,
@ -34,10 +49,9 @@ gsttag = library('gsttag-@0@'.format(api_version),
vs_module_defs: vs_module_defs_dir + 'libgsttag.def',
)
tag_gen_sources = []
if build_gir
tag_gen_sources += [gnome.generate_gir(gsttag,
sources : tag_sources + tag_headers,
sources : tag_sources + tag_headers + [gsttag_h] + [gsttag_c],
namespace : 'GstTag',
nsversion : api_version,
identifier_prefix : 'Gst',

View file

@ -26,6 +26,7 @@
#include <gst/tag/gsttagdemux.h>
#include <gst/tag/gsttagmux.h>
#include <gst/tag/xmpwriter.h>
#include <gst/tag/tag-enumtypes.h>
G_BEGIN_DECLS
@ -412,9 +413,6 @@ typedef enum {
GST_TAG_IMAGE_TYPE_PUBLISHER_STUDIO_LOGO
} GstTagImageType;
#define GST_TYPE_TAG_IMAGE_TYPE (gst_tag_image_type_get_type ())
GType gst_tag_image_type_get_type (void);
/**
* GST_TAG_ID3V2_HEADER_SIZE:
*
@ -611,8 +609,6 @@ const gchar * gst_tag_get_license_description (const gchar * license_ref)
const gchar * gst_tag_get_license_jurisdiction (const gchar * license_ref);
GType gst_tag_license_flags_get_type (void);
G_END_DECLS
#endif /* __GST_TAG_TAG_H__ */

55
gst-libs/gst/tag/tag_mkenum.py Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env python3
# This is in its own file rather than inside meson.build
# because a) mixing the two is ugly and b) trying to
# make special characters such as \n go through all
# backends is a fool's errand.
import sys, os, shutil, subprocess
h_array = ['--fhead',
"#ifndef __GST_TAG_ENUM_TYPES_H__\n#define __GST_TAG_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n",
'--fprod',
"\n/* enumerations from \"@filename@\" */\n",
'--vhead',
'GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n',
'--ftail',
'G_END_DECLS\n\n#endif /* __GST_TAG_ENUM_TYPES_H__ */',
]
c_array = ['--fhead',
"#include \"tag-enumtypes.h\"\n\n#include \"tag.h\" \n#include \"gsttagdemux.h\"",
'--fprod',
"\n/* enumerations from \"@filename@\" */",
'--vhead',
"GType\n@enum_name@_get_type (void)\n{\n static volatile gsize g_define_type_id__volatile = 0;\n if (g_once_init_enter (&g_define_type_id__volatile)) {\n static const G@Type@Value values[] = {",
'--vprod',
" { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" },",
'--vtail',
" { 0, NULL, NULL }\n };\n GType g_define_type_id = g_@type@_register_static (\"@EnumName@\", values);\n g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);\n }\n return g_define_type_id__volatile;\n}\n",
]
cmd = []
argn = 1
# Find the full command needed to run glib-mkenums
# On UNIX-like, this is just the full path to glib-mkenums
# On Windows, this is the full path to interpreter + full path to glib-mkenums
for arg in sys.argv[1:]:
cmd.append(arg)
argn += 1
if arg.endswith('glib-mkenums'):
break
ofilename = sys.argv[argn]
headers = sys.argv[argn + 1:]
if ofilename.endswith('.h'):
arg_array = h_array
else:
arg_array = c_array
cmd_array = cmd + arg_array + headers
pc = subprocess.Popen(cmd_array, stdout=subprocess.PIPE)
(stdo, _) = pc.communicate()
if pc.returncode != 0:
sys.exit(pc.returncode)
open(ofilename, 'wb').write(stdo)

View file

@ -225,65 +225,6 @@ gst_tag_register_musicbrainz_tags (void)
g_once (&mb_once, gst_tag_register_tags_internal, NULL);
}
static void
register_tag_image_type_enum (GType * id)
{
static const GEnumValue image_types[] = {
{GST_TAG_IMAGE_TYPE_NONE, "GST_TAG_IMAGE_TYPE_NONE", "none"},
{GST_TAG_IMAGE_TYPE_UNDEFINED, "GST_TAG_IMAGE_TYPE_UNDEFINED", "undefined"},
{GST_TAG_IMAGE_TYPE_FRONT_COVER, "GST_TAG_IMAGE_TYPE_FRONT_COVER",
"front-cover"},
{GST_TAG_IMAGE_TYPE_BACK_COVER, "GST_TAG_IMAGE_TYPE_BACK_COVER",
"back-cover"},
{GST_TAG_IMAGE_TYPE_LEAFLET_PAGE, "GST_TAG_IMAGE_TYPE_LEAFLET_PAGE",
"leaflet-page"},
{GST_TAG_IMAGE_TYPE_MEDIUM, "GST_TAG_IMAGE_TYPE_MEDIUM", "medium"},
{GST_TAG_IMAGE_TYPE_LEAD_ARTIST, "GST_TAG_IMAGE_TYPE_LEAD_ARTIST",
"lead-artist"},
{GST_TAG_IMAGE_TYPE_ARTIST, "GST_TAG_IMAGE_TYPE_ARTIST", "artist"},
{GST_TAG_IMAGE_TYPE_CONDUCTOR, "GST_TAG_IMAGE_TYPE_CONDUCTOR", "conductor"},
{GST_TAG_IMAGE_TYPE_BAND_ORCHESTRA, "GST_TAG_IMAGE_TYPE_BAND_ORCHESTRA",
"band-orchestra"},
{GST_TAG_IMAGE_TYPE_COMPOSER, "GST_TAG_IMAGE_TYPE_COMPOSER", "composer"},
{GST_TAG_IMAGE_TYPE_LYRICIST, "GST_TAG_IMAGE_TYPE_LYRICIST", "lyricist"},
{GST_TAG_IMAGE_TYPE_RECORDING_LOCATION,
"GST_TAG_IMAGE_TYPE_RECORDING_LOCATION",
"recording-location"},
{GST_TAG_IMAGE_TYPE_DURING_RECORDING, "GST_TAG_IMAGE_TYPE_DURING_RECORDING",
"during-recording"},
{GST_TAG_IMAGE_TYPE_DURING_PERFORMANCE,
"GST_TAG_IMAGE_TYPE_DURING_PERFORMANCE",
"during-performance"},
{GST_TAG_IMAGE_TYPE_VIDEO_CAPTURE, "GST_TAG_IMAGE_TYPE_VIDEO_CAPTURE",
"video-capture"},
{GST_TAG_IMAGE_TYPE_FISH, "GST_TAG_IMAGE_TYPE_FISH", "fish"},
{GST_TAG_IMAGE_TYPE_ILLUSTRATION, "GST_TAG_IMAGE_TYPE_ILLUSTRATION",
"illustration"},
{GST_TAG_IMAGE_TYPE_BAND_ARTIST_LOGO, "GST_TAG_IMAGE_TYPE_BAND_ARTIST_LOGO",
"artist-logo"},
{GST_TAG_IMAGE_TYPE_PUBLISHER_STUDIO_LOGO,
"GST_TAG_IMAGE_TYPE_PUBLISHER_STUDIO_LOGO",
"publisher-studio-logo"},
{0, NULL, NULL}
};
*id = g_enum_register_static ("GstTagImageType", image_types);
/* work around thread-safety issue with class creation in GLib */
g_type_class_ref (*id);
}
GType
gst_tag_image_type_get_type (void)
{
static GType id;
static GOnce once = G_ONCE_INIT;
g_once (&once, (GThreadFunc) register_tag_image_type_enum, &id);
return id;
}
static inline gboolean
gst_tag_image_type_is_valid (GstTagImageType type)
{