]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - aac_afh.c
Revert "Makefile: Fix compilation after header removal."
[paraslash.git] / aac_afh.c
index f70b811c4e2fedd39c1bb53d9d77e98dbbdd23aa..5c1225b62b2e179026dadf7638d4f44f041345cb 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 /*
  * based in parts on libfaad, Copyright (C) 2003-2005 M. Bakker,
  * Ahead Software AG
@@ -11,6 +7,7 @@
 /** \file aac_afh.c para_server's aac audio format handler. */
 
 #include <regex.h>
+#include <neaacdec.h>
 
 #include "para.h"
 
@@ -22,7 +19,6 @@
 #include "portable_io.h"
 #include "afh.h"
 #include "string.h"
-#include "aac.h"
 #include "fd.h"
 
 
@@ -39,17 +35,13 @@ struct aac_afh_context {
 static uint32_t aac_afh_read_cb(void *user_data, void *dest, uint32_t want)
 {
        struct aac_afh_context *c = user_data;
-       uint32_t have, rv;
+       size_t have, rv;
 
-       if (want == 0 || c->fpos >= c->mapsize) {
-               PARA_INFO_LOG("failed attempt to read %u bytes @%zu\n", want,
-                       c->fpos);
-               errno = EAGAIN;
-               return -1;
-       }
+       if (want == 0 || c->fpos >= c->mapsize)
+               return 0;
        have = c->mapsize - c->fpos;
-       rv = PARA_MIN(have, want);
-       PARA_DEBUG_LOG("reading %u bytes @%zu\n", rv, c->fpos);
+       rv = PARA_MIN(have, (size_t)want);
+       PARA_DEBUG_LOG("reading %zu bytes @%zu\n", rv, c->fpos);
        memcpy(dest, c->map + c->fpos, rv);
        c->fpos += rv;
        return rv;
@@ -134,8 +126,8 @@ static void aac_afh_close(void *afh_context)
  */
 int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample);
 
-static int aac_afh_get_chunk(long unsigned chunk_num, void *afh_context,
-               const char **buf, size_t *len)
+static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context,
+               const char **buf, uint32_t *len)
 {
        struct aac_afh_context *c = afh_context;
        int32_t ss;
@@ -174,8 +166,7 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        struct aac_afh_context *c;
        int64_t tmp;
        const char *buf;
-       size_t sz;
-       uint32_t n;
+       uint32_t n, len;
 
        ret = aac_afh_open(map, numbytes, (void **)&c);
        if (ret < 0)
@@ -200,16 +191,16 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        afhi->chunks_total = rv;
        afhi->max_chunk_size = 0;
        for (n = 0; n < afhi->chunks_total; n++) {
-               if (aac_afh_get_chunk(n, c, &buf, &sz) < 0)
+               if (aac_afh_get_chunk(n, c, &buf, &len) < 0)
                        break;
-               afhi->max_chunk_size = PARA_MAX((size_t)afhi->max_chunk_size, sz);
+               afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, len);
        }
 
        tmp = c->masc.sbr_present_flag == 1? 2048 : 1024;
        afhi->seconds_total = tmp * afhi->chunks_total / afhi->frequency;
        ms2tv(1000 * tmp / afhi->frequency, &afhi->chunk_tv);
 
-       if (aac_afh_get_chunk(0, c, &buf, &sz) >= 0)
+       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->mp4ff, &afhi->tags);
@@ -296,8 +287,7 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
                mp4ff_tag_t *tag = metadata.tags + i;
 
                ret = -E_MP4FF_META_READ;
-               if (mp4ff_meta_get_by_index(mp4ff, i,
-                               &tag->item, &tag->value) < 0)
+               if (!mp4ff_meta_get_by_index(mp4ff, i, &tag->item, &tag->value))
                        goto free_tags;
                PARA_INFO_LOG("found: %s: %s\n", tag->item, tag->value);
                if (!strcmp(tag->item, "artist"))
@@ -322,7 +312,7 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
        if (!found_comment)
                add_tag(&metadata, "comment", tags->comment);
        ret = -E_MP4FF_META_WRITE;
-       if (mp4ff_meta_update(&cb, &metadata) < 0)
+       if (!mp4ff_meta_update(&cb, &metadata))
                goto free_tags;
        ret = 1;
 free_tags:
@@ -337,17 +327,17 @@ close:
 }
 
 static const char * const aac_suffixes[] = {"m4a", "mp4", NULL};
+
 /**
- * the init function of the aac audio format handler
+ * The audio format handler for the Advanced Audio Codec.
  *
- * \param afh pointer to the struct to initialize
+ * This is only compiled in if the faad library is installed.
  */
-void aac_afh_init(struct audio_format_handler *afh)
-{
-       afh->get_file_info = aac_get_file_info,
-       afh->suffixes = aac_suffixes;
-       afh->rewrite_tags = aac_afh_rewrite_tags;
-       afh->open = aac_afh_open;
-       afh->get_chunk = aac_afh_get_chunk;
-       afh->close = aac_afh_close;
-}
+const struct audio_format_handler aac_afh = {
+       .get_file_info = aac_get_file_info,
+       .suffixes = aac_suffixes,
+       .rewrite_tags = aac_afh_rewrite_tags,
+       .open = aac_afh_open,
+       .get_chunk = aac_afh_get_chunk,
+       .close = aac_afh_close,
+};