]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - aac_afh.c
mp4: Make sample number be an unsigned parameter.
[paraslash.git] / aac_afh.c
index 42cba27a3670ddac4bde28f9d683c9c31a86e924..b45db477e0e80ddbe1f170446c92e2df99cdc9e1 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -41,11 +41,19 @@ static ssize_t aac_afh_read_cb(void *user_data, void *dest, size_t want)
        return rv;
 }
 
-static uint32_t aac_afh_seek_cb(void *user_data, uint64_t pos)
+static off_t aac_afh_seek_cb(void *user_data, off_t offset, int whence)
 {
        struct aac_afh_context *c = user_data;
-       c->fpos = pos;
-       return 0;
+
+       if (whence == SEEK_SET)
+               c->fpos = offset;
+       else if (whence == SEEK_CUR)
+               c->fpos += offset;
+       else if (whence == SEEK_END)
+               c->fpos = c->mapsize + offset;
+       else
+               assert(false);
+       return c->fpos;
 }
 
 static int aac_afh_open(const void *map, size_t mapsize, void **afh_context)
@@ -60,9 +68,8 @@ static int aac_afh_open(const void *map, size_t mapsize, void **afh_context)
        c->cb.seek = aac_afh_seek_cb;
        c->cb.user_data = c;
 
-       ret = -E_MP4_OPEN;
-       c->mp4 = mp4_open_read(&c->cb);
-       if (!c->mp4)
+       ret = mp4_open_read(&c->cb, &c->mp4);
+       if (ret < 0)
                goto free_ctx;
        *afh_context = c;
        return 0;
@@ -100,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");
 }
 
 /*
@@ -155,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);
@@ -168,19 +175,22 @@ static ssize_t aac_afh_meta_read_cb(void *user_data, void *dest, size_t want)
        return read(fd, dest, want);
 }
 
-static uint32_t aac_afh_meta_seek_cb(void *user_data, uint64_t pos)
+static off_t aac_afh_meta_seek_cb(void *user_data, off_t offset, int whence)
 {
        int fd = *(int *)user_data;
-       return lseek(fd, pos, SEEK_SET);
+       off_t ret = lseek(fd, offset, whence);
+
+       assert(ret != (off_t)-1);
+       return ret;
 }
 
-static uint32_t aac_afh_meta_write_cb(void *user_data, void *dest, uint32_t want)
+static ssize_t aac_afh_meta_write_cb(void *user_data, void *dest, size_t count)
 {
        int fd = *(int *)user_data;
-       return write(fd, dest, want);
+       return write(fd, dest, count);
 }
 
-static uint32_t aac_afh_meta_truncate_cb(void *user_data)
+static int aac_afh_meta_truncate_cb(void *user_data)
 {
        int fd = *(int *)user_data;
        off_t offset = lseek(fd, 0, SEEK_CUR);
@@ -229,9 +239,9 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
                return ret;
        lseek(fd, 0, SEEK_SET);
 
-       mp4 = mp4_open_meta(&cb);
-       if (!mp4)
-               return -E_MP4_OPEN;
+       ret = mp4_open_meta(&cb, &mp4);
+       if (ret < 0)
+               return ret;
        metadata = mp4_get_meta(mp4);
        PARA_NOTICE_LOG("%u metadata item(s) found\n", metadata->count);
        replace_or_add_tag("artist", tags->artist, metadata);
@@ -239,11 +249,7 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
        replace_or_add_tag("album", tags->album, metadata);
        replace_or_add_tag("date", tags->year, metadata);
        replace_or_add_tag("comment", tags->comment, metadata);
-       ret = -E_MP4_META_WRITE;
-       if (!mp4_meta_update(mp4))
-               goto close;
-       ret = 1;
-close:
+       ret = mp4_meta_update(mp4);
        mp4_close(mp4);
        return ret;
 }