]> git.tue.mpg.de Git - paraslash.git/commitdiff
The ogg/speex tagger.
authorAndre Noll <maan@systemlinux.org>
Fri, 27 Dec 2013 00:22:01 +0000 (00:22 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Apr 2015 12:13:34 +0000 (14:13 +0200)
This commit adds support for editing meta information of ogg/speex
files. As for ogg/opus and ogg/vorbis we make use of the generic
ogg_rewrite_tags() to write out an ogg file with modified tags. Hence
this patch only adds the speex-specific part, spx_make_meta_packet(),
which creates a meta data packet for the altered tags.

spx_afh.c

index e83536795d4c9b57b97b285e4dfa15f7d3869c4b..108cfaa49c1acf2168858f1120357569379f9c71 100644 (file)
--- a/spx_afh.c
+++ b/spx_afh.c
@@ -163,6 +163,94 @@ static int spx_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        return ogg_get_file_info(map, numbytes, afhi, &spx_callback_info);
 }
 
+static size_t spx_make_meta_packet(struct taginfo *tags, char **result)
+{
+       size_t sz;
+       char *buf, *p;
+       size_t comment_len = strlen(tags->comment),
+               artist_len = strlen(tags->artist),
+               title_len = strlen(tags->title),
+               album_len = strlen(tags->album),
+               year_len = strlen(tags->year);
+       uint32_t comment_sz = comment_len,
+               artist_sz = artist_len + strlen("artist="),
+               title_sz = title_len + strlen("title="),
+               album_sz = album_len + strlen("album="),
+               year_sz = year_len + strlen("year=");
+       uint32_t num_tags;
+
+       sz = 4 /* comment length (always present) */
+               + comment_sz
+               + 4; /* number of tags */
+       num_tags = 0;
+       if (artist_len) {
+               num_tags++;
+               sz += 4 + artist_sz;
+       }
+       if (title_len) {
+               num_tags++;
+               sz += 4 + title_sz;
+       }
+       if (album_len) {
+               num_tags++;
+               sz += 4 + album_sz;
+       }
+       if (year_len) {
+               num_tags++;
+               sz += 4 + year_sz;
+       }
+       PARA_DEBUG_LOG("meta packet size: %zu bytes\n", sz);
+       /* terminating zero byte for the last sprintf() */
+       buf = p = para_malloc(sz + 1);
+       write_u32(p, comment_sz);
+       p += 4;
+       strcpy(p, tags->comment);
+       p += comment_sz;
+       write_u32(p, num_tags);
+       p += 4;
+       if (artist_len) {
+               write_u32(p, artist_sz);
+               p += 4;
+               sprintf(p, "artist=%s", tags->artist);
+               p += artist_sz;
+       }
+       if (title_len) {
+               write_u32(p, title_sz);
+               p += 4;
+               sprintf(p, "title=%s", tags->title);
+               p += title_sz;
+       }
+       if (album_len) {
+               write_u32(p, album_sz);
+               p += 4;
+               sprintf(p, "album=%s", tags->album);
+               p += album_sz;
+       }
+       if (year_len) {
+               write_u32(p, year_sz);
+               p += 4;
+               sprintf(p, "year=%s", tags->year);
+               p += year_sz;
+       }
+       assert(p == buf + sz);
+       *result = buf;
+       return sz;
+}
+
+static int spx_rewrite_tags(const char *map, size_t mapsize,
+               struct taginfo *tags, int output_fd,
+               __a_unused const char *filename)
+{
+       char *meta_packet;
+       size_t meta_sz;
+       int ret;
+
+       meta_sz = spx_make_meta_packet(tags, &meta_packet);
+       ret = ogg_rewrite_tags(map, mapsize, output_fd, meta_packet, meta_sz);
+       free(meta_packet);
+       return ret;
+}
+
 /**
  * The init function of the ogg/speex audio format handler.
  *
@@ -172,4 +260,5 @@ void spx_afh_init(struct audio_format_handler *afh)
 {
        afh->get_file_info = spx_get_file_info,
        afh->suffixes = speex_suffixes;
+       afh->rewrite_tags = spx_rewrite_tags;
 }