]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Replace the five tag value functions by a single one.
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 26 Aug 2021 17:57:45 +0000 (19:57 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 6 Jun 2022 14:30:15 +0000 (16:30 +0200)
It's easier to let the caller pass the tag item string than to
have one caller for each of the five tags of interest. This commit
renames meta_find_by_name() to mp4_get_tag_value(), makes it public
and removes its five callers from mp4.c.

The only user is _aac_afh_get_taginfo() of aac_afh.c, which needs to
be adjusted accordingly. Kill the pointless underscore while at it.

aac_afh.c
mp4.c
mp4.h

index b6c90d59009a3315f9249e5e3b200429132d6296..ae1e99dc9662095af7cc887173c85b9598dd7796 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -107,13 +107,13 @@ static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context,
        return 1;
 }
 
-static void _aac_afh_get_taginfo(const struct mp4 *mp4, struct taginfo *tags)
+static void aac_afh_get_taginfo(const struct mp4 *mp4, struct taginfo *tags)
 {
-       tags->artist = mp4_meta_get_artist(mp4);
-       tags->title = mp4_meta_get_title(mp4);
-       tags->year = mp4_meta_get_date(mp4);
-       tags->album = mp4_meta_get_album(mp4);
-       tags->comment = mp4_meta_get_comment(mp4);
+       tags->artist = mp4_get_tag_value(mp4, "artist");
+       tags->title = mp4_get_tag_value(mp4, "title");
+       tags->year = mp4_get_tag_value(mp4, "date");
+       tags->album = mp4_get_tag_value(mp4, "album");
+       tags->comment = mp4_get_tag_value(mp4, "comment");
 }
 
 /*
@@ -162,7 +162,7 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        if (aac_afh_get_chunk(0, c, &buf, &len) >= 0)
                numbytes -= buf - map;
        afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000;
-       _aac_afh_get_taginfo(c->mp4, &afhi->tags);
+       aac_afh_get_taginfo(c->mp4, &afhi->tags);
        ret = 1;
 close:
        aac_afh_close(c);
diff --git a/mp4.c b/mp4.c
index 757c42958da37c7eeac1c70dc379752da2076fae..e4082549113c5bb89a6c765b9ff50f76d765a60f 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -896,70 +896,23 @@ free_moov:
        return ret;
 }
 
-static char *meta_find_by_name(const struct mp4 *f, const char *item)
-{
-       uint32_t i;
-
-       for (i = 0; i < f->meta.count; i++)
-               if (!strcasecmp(f->meta.tags[i].item, item))
-                       return para_strdup(f->meta.tags[i].value);
-       return NULL;
-}
-
 /**
- * Return the value of the artist meta tag of an mp4 file.
+ * Return the value of the given tag item.
  *
  * \param f Must not be NULL.
+ * \param item "artist", "title", "album", "comment", or "date".
  *
- * \return If the file does not contain this metadata tag, the function returns
- * NULL. Otherwise, a copy of the tag value is returned. The caller should free
- * this memory when it is no longer needed.
+ * \return The function always returns NULL if the given item is not in the
+ * above list. Otherwise, if the file does not contain a tag for the given
+ * item, the function also returns NULL. Otherwise a copy of the tag value is
+ * returned and the caller should free this memory when it is no longer needed.
  */
-char *mp4_meta_get_artist(const struct mp4 *f)
+char *mp4_get_tag_value(const struct mp4 *f, const char *item)
 {
-       return meta_find_by_name(f, "artist");
-}
-
-/**
- * Return the value of the title meta tag of an mp4 file.
- *
- * \param f See \ref mp4_meta_get_artist().
- * \return See \ref mp4_meta_get_artist().
- */
-char *mp4_meta_get_title(const struct mp4 *f)
-{
-       return meta_find_by_name(f, "title");
-}
-
-/**
- * Return the value of the date meta tag of an mp4 file.
- *
- * \param f See \ref mp4_meta_get_artist().
- * \return See \ref mp4_meta_get_artist().
- */
-char *mp4_meta_get_date(const struct mp4 *f)
-{
-       return meta_find_by_name(f, "date");
-}
-
-/**
- * Return the value of the album meta tag of an mp4 file.
- *
- * \param f See \ref mp4_meta_get_artist().
- * \return See \ref mp4_meta_get_artist().
- */
-char *mp4_meta_get_album(const struct mp4 *f)
-{
-       return meta_find_by_name(f, "album");
-}
+       uint32_t i;
 
-/**
- * Return the value of the comment meta tag of an mp4 file.
- *
- * \param f See \ref mp4_meta_get_artist().
- * \return See \ref mp4_meta_get_artist().
- */
-char *mp4_meta_get_comment(const struct mp4 *f)
-{
-       return meta_find_by_name(f, "comment");
+       for (i = 0; i < f->meta.count; i++)
+               if (!strcasecmp(f->meta.tags[i].item, item))
+                       return para_strdup(f->meta.tags[i].value);
+       return NULL;
 }
diff --git a/mp4.h b/mp4.h
index 243b75ca369e988b84083853829ef2c24bb4d424..0775956bdff2fae0c2cbd8e432bdf94cbf6a9dcd 100644 (file)
--- a/mp4.h
+++ b/mp4.h
@@ -30,8 +30,4 @@ uint64_t mp4_get_duration(const struct mp4 *f);
 int mp4_open_meta(const struct mp4_callback *cb, struct mp4 **result);
 struct mp4_metadata *mp4_get_meta(struct mp4 *f);
 int mp4_meta_update(struct mp4 *f);
-char *mp4_meta_get_artist(const struct mp4 *f);
-char *mp4_meta_get_title(const struct mp4 *f);
-char *mp4_meta_get_date(const struct mp4 *f);
-char *mp4_meta_get_album(const struct mp4 *f);
-char *mp4_meta_get_comment(const struct mp4 *f);
+char *mp4_get_tag_value(const struct mp4 *f, const char *item);