Index: libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 150)
+++ libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 151)
@@ -33,4 +33,5 @@
 */
 
+#include <string.h>
 #include <mpcdec/streaminfo.h>
 #include <mpcdec/mpcdec.h>
@@ -114,7 +115,7 @@
  */
 static void
-mpc_demux_seek(mpc_demux * d, mpc_uint32_t fpos, mpc_uint32_t min_bytes) {
+mpc_demux_seek(mpc_demux * d, mpc_size_t fpos, mpc_uint32_t min_bytes) {
 // 	mpc_uint32_t cur_pos = d->r->tell(d->r);
-	mpc_uint32_t next_pos;
+	mpc_size_t next_pos;
 	mpc_int_t bit_offset;
 
@@ -123,9 +124,9 @@
 	next_pos = fpos >> 3;
 	if (d->si.stream_version == 7)
-		next_pos &= (-1u << 2);
-	bit_offset = fpos - (next_pos << 3);
+		next_pos &= (-1 << 2);
+	bit_offset = (int) (fpos - (next_pos << 3));
 	next_pos += d->si.header_position; // add id3 offset
 
-	d->r->seek(d->r, next_pos);
+	d->r->seek(d->r, (mpc_int32_t) next_pos);
 	mpc_demux_clear_buff(d);
 	if (d->si.stream_version == 7)
@@ -155,8 +156,8 @@
 	if (d->si.block_pwr > d->seek_pwr)
 		d->seek_pwr = d->si.block_pwr;
-	d->seek_table = malloc((1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t));
+	d->seek_table = malloc((size_t)(1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t));
 	if (d->seek_table == 0)
 		return MPC_STATUS_FILE;
-	d->seek_table[0] = mpc_demux_pos(d);
+	d->seek_table[0] = (mpc_uint32_t)mpc_demux_pos(d);
 	d->seek_table_size = 1;
 
@@ -175,11 +176,11 @@
 
 	mpc_bits_get_size(&r, &tmp);
-	d->seek_table_size = tmp;
+	d->seek_table_size = (mpc_uint32_t) tmp;
 	d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4);
-	d->seek_table = malloc((1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t));
+	d->seek_table = malloc((size_t)(1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t));
 
 	table = d->seek_table;
 	mpc_bits_get_size(&r, &tmp);
-	table[0] = (tmp + d->si.header_position) * 8;
+	table[0] = (mpc_uint32_t) (tmp + d->si.header_position) * 8;
 
 	if (d->seek_table_size == 1)
@@ -187,10 +188,10 @@
 
 	mpc_bits_get_size(&r, &tmp);
-	table[1] = (tmp + d->si.header_position) * 8;
+	table[1] = (mpc_uint32_t) (tmp + d->si.header_position) * 8;
 
 	for (i = 2; i < d->seek_table_size; i++) {
 		int code = mpc_bits_golomb_dec(&r, 12);
 		if (code & 1)
-			code = -(code & (-1u << 1));
+			code = -(code & (-1 << 1));
 		code <<= 2;
 		table[i] = code + 2 * table[i-1] - table[i-2];
@@ -209,5 +210,5 @@
 	mpc_bits_get_block(&d->bits_reader, &b);
 	if (memcmp(b.key, "ST", 2) == 0) {
-		mpc_demux_fill(d, b.size, 0);
+		mpc_demux_fill(d, (mpc_uint32_t) b.size, 0);
 		mpc_demux_ST(d);
 	}
@@ -253,12 +254,12 @@
 		size = mpc_bits_get_block(&d->bits_reader, &b);
 		while( memcmp(b.key, "AD", 2) != 0 ){ // scan all blocks until audio
-			mpc_demux_fill(d, 11 + b.size, 0);
+			mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
 			if (memcmp(b.key, "SI", 2) == 0){
-				int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, b.size);
+				int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size);
 				if (ret != MPC_STATUS_OK) return ret;
 			} else if (memcmp(b.key, "EI", 2) == 0)
 				streaminfo_encoder_info(&d->si, &d->bits_reader);
 			else if (memcmp(b.key, "SP", 2) == 0)
-				mpc_demux_SP(d, size, b.size);
+				mpc_demux_SP(d, size, (mpc_uint32_t) b.size);
 			else if (memcmp(b.key, "ST", 2) == 0)
 				mpc_demux_ST(d);
@@ -315,5 +316,5 @@
 			d->bits_reader.count &= -8;
 			if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) {
-				d->seek_table[d->seek_table_size] = mpc_demux_pos(d);
+				d->seek_table[d->seek_table_size] = (mpc_uint32_t) mpc_demux_pos(d);
 				d->seek_table_size ++;
 			}
@@ -325,9 +326,9 @@
 					break;
 				}
-				mpc_demux_fill(d, 11 + b.size, 0);
+				mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
 				d->bits_reader.buff += b.size;
 				mpc_bits_get_block(&d->bits_reader, &b);
 			}
-			d->block_bits = b.size * 8;
+			d->block_bits = (mpc_uint32_t) b.size * 8;
 		}
 		// FIXME : this is not good if block size > buffer size
@@ -337,9 +338,9 @@
 		d->block_bits -= ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count;
 	} else {
+		mpc_bits_reader r;
 		if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) {
-			d->seek_table[d->seek_table_size] = mpc_demux_pos(d);
+			d->seek_table[d->seek_table_size] = (mpc_uint32_t) mpc_demux_pos(d);
 			d->seek_table_size ++;
 		}
-		mpc_bits_reader r;
 		mpc_demux_fill(d, MAX_FRAME_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP);
 		mpc_bits_read(&d->bits_reader, 20); // read frame size
@@ -354,5 +355,5 @@
 }
 
-mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_int64_t destsample)
+mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample)
 {
 	mpc_uint32_t fwd, samples_to_skip, fpos, i;
@@ -388,5 +389,5 @@
 			if (memcmp(b.key, "AD", 2) == 0) {
 				if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) {
-					d->seek_table[d->seek_table_size] = mpc_demux_pos(d) - 8 * size;
+					d->seek_table[d->seek_table_size] = (mpc_uint32_t) mpc_demux_pos(d) - 8 * size;
 					d->seek_table_size ++;
 				}
@@ -394,5 +395,5 @@
 				i++;
 			}
-			fpos += (b.size + size) * 8;
+			fpos += ((mpc_uint32_t)b.size + size) * 8;
 			mpc_demux_seek(d, fpos, 11);
 			size = mpc_bits_get_block(&d->bits_reader, &b);
@@ -404,5 +405,5 @@
 		for( ; i < fwd; i++){
 			if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) {
-				d->seek_table[d->seek_table_size] = mpc_demux_pos(d);
+				d->seek_table[d->seek_table_size] = (mpc_uint32_t) mpc_demux_pos(d);
 				d->seek_table_size ++;
 			}
