]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - wma_common.c
remove unused field tmp_buf of struct fft_context.
[paraslash.git] / wma_common.c
index 9a7a22acf30bd310f2dd14f8494f93cff5adc070..be195e665cfb5eef751d678a8d41a00ce1701aed 100644 (file)
 #include "error.h"
 #include "afh.h"
 #include "portable_io.h"
-#include "mdct.h"
+#include "imdct.h"
 #include "wma.h"
 
 const char *search_pattern(const char *pattern, int pattern_len, const char *buf, int buf_size)
 {
        const char *p, *end = buf + buf_size;
 
-       if (pattern_len > buf_size)
-               return NULL;
        for (p = buf; p + pattern_len < end; p++) {
                if (memcmp(p, pattern, pattern_len))
                        continue;
@@ -46,10 +44,8 @@ static int find_audio_stream_info(const char *buf, int len)
        const char pattern[] = {0x40, 0x9e, 0x69, 0xf8};
        const char *p = search_pattern(pattern, sizeof(pattern), buf, len);
 
-       if (!p) {
-               PARA_NOTICE_LOG("audio stream guid not found");
-               return -1;
-       }
+       if (!p)
+               return -E_WMA_NO_GUID;
        PARA_DEBUG_LOG("found audio stream guid@%0zx\n", p - buf);
        return p - buf;
 }
@@ -59,27 +55,30 @@ static int read_header_len(char *buf, int len)
        uint16_t header_len;
 
        if (len < 18)
-               return -1;
+               return 0;
        header_len = read_u16(buf + 16) + 46;
-       if (header_len > len)
-               return -2;
        PARA_DEBUG_LOG("header_len: %d\n", header_len);
        return header_len;
 }
 
+/**
+ * \return Negative on errors, zero if more data is needed in order to read the
+ * full header. Positive header length on success.
+ */
 int read_asf_header(char *buf, int loaded, struct asf_header_info *ahi)
 {
        int ret;
        char *start;
 
-       ret = read_header_len(buf, loaded);
-       if (ret < 0)
-               return ret;
-       ahi->header_len = ret;
-
+       ahi->header_len = read_header_len(buf, loaded);
+       if (ahi->header_len == 0) /* too short to read header len */
+               return 0;
+       if (ahi->header_len > loaded) /* too short to read header */
+               return 0;
        ret = find_audio_stream_info(buf, ahi->header_len);
        if (ret < 0)
                return ret;
+       /* FIXME: Check ranges */
        ahi->audio_stream_info_start = ret + 16;
        start = buf + ahi->audio_stream_info_start;
 
@@ -98,7 +97,7 @@ int read_asf_header(char *buf, int loaded, struct asf_header_info *ahi)
        ahi->flags2 = read_u16(start + 60);
        PARA_INFO_LOG("read_asf_header: flags1: %d, flag2: %d\n",
                ahi->flags1, ahi->flags2);
-       return 42;
+       return 1;
 }
 
 const uint8_t log2_tab[256] = {