[vlc-commits] input/demux: make helper type more generic
Filip Roséen
git at videolan.org
Tue Aug 2 15:47:21 CEST 2016
vlc | branch: master | Filip Roséen <filip at atch.se> | Sat Jul 30 05:47:08 2016 +0200| [cf8aa14fcded795f67dde659323d93c05dae5cd9] | committer: Jean-Baptiste Kempf
input/demux: make helper type more generic
The affected helper-type can be used elsewhere in this translation-unit though
for lookup of other strings not directly related to a certain mime-type.
This commit changes both the name of the type, but also its data-members, so
that it is more generic. As the lookup maps will always be initialized with
string-literals, there is no need to specify an explicit size for the
data-members; instead we can simply rely on a pointer-to-char.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cf8aa14fcded795f67dde659323d93c05dae5cd9
---
src/input/demux.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/input/demux.c b/src/input/demux.c
index 2d854a3..c8a6ca5 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -38,23 +38,24 @@
static bool SkipID3Tag( demux_t * );
static bool SkipAPETag( demux_t *p_demux );
-struct demux_type
+typedef const struct
{
- char type[20];
- char demux[8];
-};
+ const char* key;
+ const char* name;
+
+} demux_mapping;
static int typecmp( const void *k, const void *t )
{
const char *key = k;
- const struct demux_type *type = t;
+ demux_mapping *type = t;
- return vlc_ascii_strcasecmp( key, type->type );
+ return vlc_ascii_strcasecmp( key, type->key );
}
static const char *demux_NameFromContentType(const char *mime)
{
- static const struct demux_type types[] =
+ static demux_mapping types[] =
{ /* Must be sorted in ascending ASCII order */
{ "audio/aac", "m4a" },
{ "audio/aacp", "m4a" },
@@ -67,11 +68,9 @@ static const char *demux_NameFromContentType(const char *mime)
{ "video/nsa", "nsv" },
{ "video/nsv", "nsv" },
};
- const struct demux_type *type;
-
- type = bsearch( mime, types, sizeof (types) / sizeof (types[0]),
- sizeof (types[0]), typecmp );
- return (type != NULL) ? type->demux : "any";
+ demux_mapping* type = bsearch( mime, types, ARRAY_SIZE( types ),
+ sizeof( types[0] ), typecmp );
+ return (type != NULL) ? type->name : "any";
}
/*****************************************************************************
More information about the vlc-commits
mailing list