From: Andre Noll <maan@systemlinux.org>
Date: Wed, 7 Oct 2009 18:53:47 +0000 (+0200)
Subject: Various wma fixes.
X-Git-Tag: v0.4.1~110
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=620c2a3eb4c3395c5be73f663435740ecd878775;p=paraslash.git

Various wma fixes.
---

diff --git a/configure.ac b/configure.ac
index 4583b1eb..aadaee34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,7 +123,7 @@ audiod_errlist_objs="audiod signal string daemon stat net
 	client_common ggo udp_recv color fec prebuffer_filter sha1 audiod_command_list
 	bitstream mdct wma_common wmadec_filter"
 audiod_ldflags=""
-audiod_audio_formats=""
+audiod_audio_formats="wma"
 
 afh_cmdline_objs="add_cmdline(afh)"
 afh_errlist_objs="afh string fd mp3_afh afh_common time wma_afh wma_common"
@@ -390,7 +390,7 @@ if test "$have_ogg" = "yes"; then
 	audiod_errlist_objs="$audiod_errlist_objs oggdec_filter"
 	afh_errlist_objs="$afh_errlist_objs ogg_afh"
 
-	audiod_audio_formats="ogg"
+	audiod_audio_formats="$audiod_audio_formats ogg"
 	server_audio_formats="$server_audio_formats ogg"
 	AC_SUBST(oggvorbis_cppflags)
 	AC_SUBST(oggvorbis_libs)
diff --git a/error.h b/error.h
index 7553699c..0d2566d7 100644
--- a/error.h
+++ b/error.h
@@ -35,10 +35,14 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define AFS_COMMAND_LIST_ERRORS
 #define AUDIOD_COMMAND_LIST_ERRORS
 #define WMA_AFH_ERRORS
-#define WMA_COMMON_ERRORS
 
 extern const char **para_errlist[];
 
+#define WMA_COMMON_ERRORS \
+	PARA_ERROR(WMA_NO_GUID, "audio stream guid not found"), \
+	PARA_ERROR(WMA_BAD_ASF_HEADER, "invalid asf header"), \
+
+
 #define WMADEC_FILTER_ERRORS \
 	PARA_ERROR(WMA_BAD_PARAMS, "invalid WMA parameters"), \
 	PARA_ERROR(WMA_OUTPUT_SPACE, "insufficient output space"), \
diff --git a/wma_afh.c b/wma_afh.c
index 335ab890..2d463900 100644
--- a/wma_afh.c
+++ b/wma_afh.c
@@ -191,16 +191,15 @@ static int wma_make_chunk_table(char *buf, size_t buf_size, int block_align,
 	const uint8_t *f, *start = (uint8_t *)buf;
 	int i, j, frames_per_chunk, chunk_time;
 	size_t ct_size = 250;
+	int count = 0, num_frames;
+
 	afhi->chunk_table = para_malloc(ct_size * sizeof(uint32_t));
 	afhi->chunk_table[0] = 0;
 	afhi->chunk_table[1] = afhi->header_len;
 
-
-	int count = 0, num_frames;
-
 	num_frames = count_frames(buf, buf_size, block_align,
 		&afhi->chunks_total);
-	PARA_ERROR_LOG("%d frames\n", num_frames);
+	PARA_INFO_LOG("%d frames\n", num_frames);
 	afhi->seconds_total = num_frames * 2048 /* FIXME */
 		/ afhi->frequency;
 	frames_per_chunk = num_frames / afhi->chunks_total;
@@ -208,7 +207,7 @@ static int wma_make_chunk_table(char *buf, size_t buf_size, int block_align,
 	j = 1;
 	FOR_EACH_FRAME(f, start, buf_size, block_align) {
 		count += f[WMA_FRAME_SKIP] & 0x0f;
-		while (count > j * frames_per_chunk) {
+		while (count > j * frames_per_chunk && f > start) {
 			j++;
 			if (j >= ct_size) {
 				ct_size *= 2;
@@ -223,7 +222,7 @@ static int wma_make_chunk_table(char *buf, size_t buf_size, int block_align,
 	afhi->chunks_total = j;
 	chunk_time = num_frames * 1000 / afhi->frequency * 2048
 		/ afhi->chunks_total;
-	PARA_ERROR_LOG("ct: %d\n", chunk_time);
+	PARA_INFO_LOG("ct: %d\n", chunk_time);
 	afhi->chunk_tv.tv_sec = chunk_time / 1000;
 	afhi->chunk_tv.tv_usec = (chunk_time % 1000) * 1000;
 	//set_chunk_tv(num_frames, j, afhi->frequency, &afhi->chunk_tv);
diff --git a/wma_common.c b/wma_common.c
index 9a7a22ac..c4d96ad0 100644
--- a/wma_common.c
+++ b/wma_common.c
@@ -46,10 +46,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;
 }
@@ -58,11 +56,9 @@ static int read_header_len(char *buf, int len)
 {
 	uint16_t header_len;
 
-	if (len < 18)
-		return -1;
 	header_len = read_u16(buf + 16) + 46;
 	if (header_len > len)
-		return -2;
+		return -E_WMA_BAD_ASF_HEADER;
 	PARA_DEBUG_LOG("header_len: %d\n", header_len);
 	return header_len;
 }