X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=wma_common.c;h=b123b5d2104a24500b8123f94bc7e2c6b8622fbc;hp=781db5f4a36678f14db97a165b02e8f41df3e8b8;hb=9d232e636d79a2321e280fe3eee6839c8f45c36f;hpb=9417eae5ca2b9f10d25f769221e8fd91048bc68a diff --git a/wma_common.c b/wma_common.c index 781db5f4..b123b5d2 100644 --- a/wma_common.c +++ b/wma_common.c @@ -1,18 +1,8 @@ -/* - * Copyright (C) 2009-2011 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2009 Andre Noll , see file COPYING. */ /** \file wma_common.c Functions used by both the WMA afh and decoder. */ -#include #include -#include -#include -#include -#include -#include #include "para.h" #include "error.h" @@ -28,6 +18,8 @@ * \param pattern_len The length of the pattern in bytes. * \param buf The buffer to search for the pattern. * \param buf_size The number of bytes in \a buf. + * + * \return A pointer into \a buf or \p NULL if the pattern was not found. */ const char *search_pattern(const char *pattern, int pattern_len, const char *buf, int buf_size) @@ -46,6 +38,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", (unsigned)(p - buf)); + return p - buf + 16; +} + /* 40 9e 69 f8 4d 5b cf 11 a8 fd 00 80 5f 5c 44 2b */ @@ -56,7 +59,7 @@ static int find_audio_stream_info(const char *buf, int len) if (!p) return -E_WMA_NO_GUID; - PARA_DEBUG_LOG("found audio stream guid@%0x\n", (int)(p - buf)); + PARA_DEBUG_LOG("found audio stream guid@%0x\n", (unsigned)(p - buf)); return p - buf + 16; } @@ -104,19 +107,37 @@ int read_asf_header(const char *buf, int loaded, struct asf_header_info *ahi) ahi->sample_rate); ahi->bit_rate = 8 * read_u16(start + 46); - PARA_INFO_LOG("bit rate: %d\n", ahi->bit_rate); + PARA_INFO_LOG("bit rate: %u\n", ahi->bit_rate); ahi->block_align = read_u16(start + 50); PARA_INFO_LOG("block_align: %d\n", ahi->block_align); 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: %u, flags2: %u\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; } -const uint8_t log2_tab[256] = { +static const uint8_t log2_tab[256] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, @@ -142,7 +163,7 @@ const uint8_t log2_tab[256] = { * * \return An integer approximation of log2(v). */ -int wma_log2(unsigned int v) +__a_const int wma_log2(unsigned int v) { int n = 0; if (v & 0xffff0000) { @@ -153,7 +174,5 @@ int wma_log2(unsigned int v) v >>= 8; n += 8; } - n += log2_tab[v]; - - return n; + return n + log2_tab[v]; }