X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=wma_common.c;h=dab96257d09876916240817811508c31c45b29d6;hp=3326cfff6148128f08ebc3b388ee82711a3c9ed5;hb=05527588bd503e4748d801b641a9e3a6556525ad;hpb=56d97fc7556b3d0c383eb62c08f70fd8d5be0285 diff --git a/wma_common.c b/wma_common.c index 3326cfff..dab96257 100644 --- a/wma_common.c +++ b/wma_common.c @@ -21,14 +21,24 @@ #include "imdct.h" #include "wma.h" -const char *search_pattern(const char *pattern, int pattern_len, const char *buf, int buf_size) +/** + * Find the first occurrence of the given pattern. + * + * \param pattern The pattern to search for. + * \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. + */ +const char *search_pattern(const char *pattern, int pattern_len, + const char *buf, int buf_size) { const char *p, *end = buf + buf_size; + /* TODO: Use suffix arrays to speed up the search. */ for (p = buf; p + pattern_len < end; p++) { if (memcmp(p, pattern, pattern_len)) continue; - PARA_DEBUG_LOG("found %d byte pattern@%d\n", + PARA_DEBUG_LOG("found %d byte pattern@%zd\n", pattern_len, p - buf); return p; } @@ -50,7 +60,7 @@ static int find_audio_stream_info(const char *buf, int len) return p - buf + 16; } -static int read_header_len(char *buf, int len) +static int read_header_len(const char *buf, int len) { uint16_t header_len; @@ -71,10 +81,10 @@ static int read_header_len(char *buf, int len) * \return Negative on errors, zero if more data is needed in order to read the * full header, 1 on success. */ -int read_asf_header(char *buf, int loaded, struct asf_header_info *ahi) +int read_asf_header(const char *buf, int loaded, struct asf_header_info *ahi) { int ret; - char *start; + const char *start; ahi->header_len = read_header_len(buf, loaded); if (ahi->header_len == 0) /* too short to read header len */ @@ -125,6 +135,13 @@ const uint8_t log2_tab[256] = { 7, 7, 7, 7, 7, 7, 7, 7 }; +/** + * Compute the base-2 logarithm. + * + * \param v The value to compute the logarithm of. + * + * \return An integer approximation of log2(v). + */ int wma_log2(unsigned int v) { int n = 0;