Index: libmpcdec/branches/zorg/src/streaminfo.c
===================================================================
--- libmpcdec/branches/zorg/src/streaminfo.c	(revision 70)
+++ libmpcdec/branches/zorg/src/streaminfo.c	(revision 81)
@@ -41,5 +41,5 @@
 static const char na[] = "n.a.";
 static const char *versionNames[] = {
-    na, "'Unstable/Experimental'", na, na, na, "'quality 0'", "'quality 1'", 
+    na, "'Unstable/Experimental'", na, na, na, "'quality 0'", "'quality 1'",
     "'Telephone'", "'Thumb'", "'Radio'", "'Standard'", "'Extreme'", "'Insane'",
     "'BrainDead'", "'quality 9'", "'quality 10'"
@@ -53,5 +53,5 @@
 }
 
-/// Reads streaminfo from SV7 header. 
+/// Reads streaminfo from SV7 header.
 static mpc_status
 streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_uint32_t HeaderData[8])
@@ -107,4 +107,56 @@
 }
 
+/// Reads streaminfo from SV8 header.
+static mpc_status
+streaminfo_read_header_sv8(mpc_streaminfo* si, mpc_reader * p_reader)
+{
+	int ret;
+	mpc_block_t block;
+	mpc_bits_reader bits_reader = {0, 0};
+	mpc_uint32_t CRC;
+	mpc_int32_t header_pos;
+	unsigned char tmp;
+	mpc_uint64_t sampleCount = 0;
+
+	ret = mpc_find_block(p_reader, &block, "SI", "AD");
+	if (ret != MPC_STATUS_OK)
+		return ret;
+
+	header_pos = p_reader->tell(p_reader);
+
+	// FIXME : add CRC check
+	CRC = mpc_read_bits(p_reader, &bits_reader, 32);
+	si->stream_version = mpc_read_bits(p_reader, &bits_reader, 8);
+
+	do {
+		p_reader->read(p_reader, &tmp, 1);
+		sampleCount = (sampleCount << 7) | (tmp & 0x7F);
+	} while((tmp & 0x80));
+
+	si->frames = (sampleCount + MPC_FRAME_LENGTH - 1) / MPC_FRAME_LENGTH;
+	si->is_true_gapless = 1;
+	si->last_frame_samples = sampleCount - (si->frames - 1) * MPC_FRAME_LENGTH;
+	si->sample_freq = samplefreqs[mpc_read_bits(p_reader, &bits_reader, 4)];
+	si->channels = mpc_read_bits(p_reader, &bits_reader, 4) + 1;
+	si->max_band = mpc_read_bits(p_reader, &bits_reader, 5) + 1;
+	// FIXME : this flag will be removed, must be 0
+	si->is = mpc_read_bits(p_reader, &bits_reader, 1);
+	si->ms = mpc_read_bits(p_reader, &bits_reader, 1);
+
+	si->bitrate            = 0;
+	si->block_size         = 1;
+
+	si->pcm_samples     = sampleCount;
+	si->average_bitrate = 0;
+	if (si->pcm_samples > 0)
+		si->average_bitrate = (si->tag_offset - si->header_position) * 8.0
+				*  si->sample_freq / si->pcm_samples;
+
+	// seek to the end of the block
+	p_reader->seek(p_reader, header_pos + block.size);
+
+	return MPC_STATUS_OK;
+}
+
 // reads file header and tags
 mpc_status
@@ -121,41 +173,50 @@
     err = p_reader->seek(p_reader, si->header_position);
     if(!err) return MPC_STATUS_FILE;
-    err = p_reader->read(p_reader, headerData, 8 * 4);
-    if(err != 8 * 4) return MPC_STATUS_FILE;
-    err = p_reader->seek(p_reader, si->header_position + 6 * 4);
-    if(!err) return MPC_STATUS_FILE;
-
-    err = p_reader->get_size(p_reader);
-    if(err < 0) return MPC_STATUS_FILE;
-    si->tag_offset = si->total_file_length = err;
-
-    err = memcmp(headerData, "MP+", 3);
-    if(err) return MPC_STATUS_INVALIDSV;
+
+	// read magic
+	err = p_reader->read(p_reader, headerData, 4);
+	if(err != 4) return MPC_STATUS_FILE;
+
+	if (memcmp(headerData, "MP+", 3) == 0) {
+		// SV 4-7
+		err = p_reader->read(p_reader, headerData + 1, 7 * 4);
+		if(err != 7 * 4) return MPC_STATUS_FILE;
+		err = p_reader->seek(p_reader, si->header_position + 6 * 4);
+		if(!err) return MPC_STATUS_FILE;
+
+		err = p_reader->get_size(p_reader);
+		if(err < 0) return MPC_STATUS_FILE;
+		si->tag_offset = si->total_file_length = err;
 
 #ifndef MPC_LITTLE_ENDIAN
-    {
-        mpc_uint32_t ptr;
-        for (ptr = 0; ptr < 8; ptr++)
-            headerData[ptr] = mpc_swap32(headerData[ptr]);
-    }
+		{
+			mpc_uint32_t ptr;
+			for (ptr = 0; ptr < 8; ptr++)
+				headerData[ptr] = mpc_swap32(headerData[ptr]);
+		}
 #endif
-     si->stream_version = headerData[0] >> 24;
-
-     if ((si->stream_version & 15) >= 8)
-        return MPC_STATUS_INVALIDSV;
-     else if ((si->stream_version & 15) == 7)
-     {
-        err = streaminfo_read_header_sv7(si, headerData);
-        if(err < 0) return err;
-     }
-
-    // estimation, exact value needs too much time
-    si->pcm_samples     = 1152 * si->frames - 576;
-    si->average_bitrate = 0;
-    if (si->pcm_samples > 0)
-        si->average_bitrate = (si->tag_offset  - si->header_position) * 8.0 
-                            *  si->sample_freq / si->pcm_samples;
-
-    return MPC_STATUS_OK;
+		si->stream_version = headerData[0] >> 24;
+
+		if ((si->stream_version & 15) >= 8)
+			return MPC_STATUS_INVALIDSV;
+		else if ((si->stream_version & 15) == 7) {
+			err = streaminfo_read_header_sv7(si, headerData);
+			if(err < 0) return err;
+		}
+
+		// estimation, exact value needs too much time
+		si->pcm_samples     = 1152 * si->frames - 576;
+		si->average_bitrate = 0;
+		if (si->pcm_samples > 0)
+			si->average_bitrate = (si->tag_offset  - si->header_position) * 8.0
+					*  si->sample_freq / si->pcm_samples;
+	} else if (memcmp(headerData, "MPCK", 4) == 0) {
+		// SV 8
+		printf("sv8\n");
+		streaminfo_read_header_sv8(si, p_reader);
+	} else
+		return MPC_STATUS_INVALIDSV;
+
+	return MPC_STATUS_OK;
 }
 
