]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - wma_common.c
wmadec: Set data size to 0 if nothing was decoded.
[paraslash.git] / wma_common.c
index ee7f451eebbadd65bac712baf1cc042879452281..27cb51d0434367e168fa49554e05bf1f13d9f473 100644 (file)
@@ -1,18 +1,12 @@
 /*
- * Copyright (C) 2009-2012 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2009 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file wma_common.c Functions used by both the WMA afh and decoder. */
 
-#include <inttypes.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
 
 #include "para.h"
 #include "error.h"
@@ -48,6 +42,17 @@ const char *search_pattern(const char *pattern, int pattern_len,
        return NULL;
 }
 
+static int find_file_properties(const char *buf, int len)
+{
+       const char pattern[] = {0xa1, 0xdc, 0xab, 0x8c};
+       const char *p = search_pattern(pattern, sizeof(pattern), buf, len);
+
+       if (!p)
+               return -E_WMA_NO_GUID;
+       PARA_DEBUG_LOG("found file property guid@%0x\n", (int)(p - buf));
+       return p - buf + 16;
+}
+
 /*
    40 9e 69 f8 4d 5b cf 11  a8 fd 00 80 5f 5c 44 2b
  */
@@ -113,8 +118,26 @@ int read_asf_header(const char *buf, int loaded, struct asf_header_info *ahi)
 
        ahi->flags1 = read_u32(start + 56);
        ahi->flags2 = read_u16(start + 60);
-       PARA_INFO_LOG("read_asf_header: flags1: %d, flag2: %d\n",
+       PARA_INFO_LOG("read_asf_header: flags1: %d, flags2: %d\n",
                ahi->flags1, ahi->flags2);
+       ahi->use_exp_vlc = ahi->flags2 & 0x0001;
+       ahi->use_bit_reservoir = ahi->flags2 & 0x0002;
+       ahi->use_variable_block_len = ahi->flags2 & 0x0004;
+
+       ret = find_file_properties(buf, ahi->header_len);
+       if (ret < 0)
+               return ret;
+       /* file property header is always 88 bytes (sans GUID) */
+       if (ret + 88 > loaded)
+               return 0;
+       start = buf + ret;
+       ahi->packet_size = read_u32(start + 76); /* min packet size */
+       /* we only support fixed packet sizes */
+       if (ahi->packet_size != read_u32(start + 80)) /* min != max */
+               return -E_BAD_ASF_FILE_PROPS;
+       if (ahi->packet_size <= ahi->block_align)
+               return -E_BAD_ASF_FILE_PROPS;
+       PARA_INFO_LOG("packet size: %u\n", ahi->packet_size);
        return 1;
 }