Index: /libmpc/branches/r2d/libmpcdec/internal.h
===================================================================
--- /libmpc/branches/r2d/libmpcdec/internal.h	(revision 138)
+++ /libmpc/branches/r2d/libmpcdec/internal.h	(revision 139)
@@ -72,5 +72,6 @@
 	mpc_uint32_t bytes_total;
 	mpc_bits_reader bits_reader;
-	mpc_uint32_t block_bits;	// bits remaining in current audio block
+	mpc_uint32_t block_bits; /// bits remaining in current audio block
+	mpc_bool_t end; /// end of stream flag
 };
 
Index: /libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 138)
+++ /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 139)
@@ -138,6 +138,5 @@
 			if (memcmp(b.key, "SI", 2) == 0){
 				int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, b.size);
-				if (ret != MPC_STATUS_OK)
-					return ret;
+				if (ret != MPC_STATUS_OK) return ret;
 			} else if (memcmp(b.key, "EI", 2) == 0)
 				streaminfo_encoder_info(&d->si, &d->bits_reader);
@@ -164,4 +163,5 @@
 		p_tmp->bits_reader.count = 8;
 		p_tmp->block_bits = 0;
+		p_tmp->end = MPC_FALSE;
 		// lire entÃªte
 		if (mpc_demux_header(p_tmp) == MPC_STATUS_OK) {
@@ -192,5 +192,5 @@
 	if (d->si.stream_version == 8) {
 		mpc_bits_reader r;
-		if (d->block_bits < 8 && (d->d->decoded_samples < d->d->samples || d->d->samples == 0)){
+		if (d->block_bits < 8 && d->end == MPC_FALSE){
 			mpc_block b;
 			d->bits_reader.count &= -8;
@@ -198,4 +198,6 @@
 			mpc_bits_get_block(&d->bits_reader, &b);
 			while( memcmp(b.key, "AD", 2) != 0 ){ // scan all blocks until audio
+				if (memcmp(b.key, "SE", 2) == 0) // end block
+					d->end = MPC_TRUE;
 				mpc_demux_fill(d, 11 + b.size, 0);
 				d->bits_reader.buff += b.size;
@@ -218,99 +220,2 @@
 }
 
-// static mpc_uint32_t
-// mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
-// {
-// 	mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH;
-// 	mpc_uint32_t FwdJumpInfo = 0;
-// 	mpc_uint32_t  FrameBitCnt = 0;
-//
-// 	if (d->decoded_frames >= d->OverallFrames) {
-// 		return (mpc_uint32_t)(-1);                           // end of file -> abort decoding
-// 	}
-//
-//     // add seeking info
-// 	if (d->seeking_table_frames < d->decoded_frames &&
-// 		   (d->decoded_frames & ((1 << d->seeking_pwr) - 1)) == 0) {
-// 		d->seeking_table[d->decoded_frames >> d->seeking_pwr] = mpc_decoder_bits_read(d);
-// 		d->seeking_table_frames = d->decoded_frames;
-// 		   }
-//
-// 		   switch (d->StreamVersion) {
-// 			   case 0x07:
-// 			   case 0x17:
-// 		// read jump-info for validity check of frame
-// 				   FwdJumpInfo  = mpc_decoder_bitstream_read(d, 20);
-//     	// decode data and check for validity of frame
-// 				   FrameBitCnt = mpc_decoder_bits_read(d);
-//
-// 				   d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
-// 				   break;
-// 			   case 0x08:
-// 				   if (d->BlockBits < 8){
-// 					   mpc_block block;
-// 			// trouver le block
-// 					   mpc_decoder_bitstream_read(d, d->BlockBits);
-// 					   while (1) {
-// 						   mpc_decoder_get_block(d, &block);
-// 						   if (memcmp(block.key, "AD", 2) != 0)
-// 							   mpc_decoder_seek(d, mpc_decoder_bits_read(d) + block.size * 8);
-// 						   else
-// 							   break;
-// 					   }
-// 					   d->BlockBits = block.size * 8;
-// 				   }
-// 				   FrameBitCnt = mpc_decoder_bits_read(d);
-// 				   mpc_decoder_read_bitstream_sv7(d, FALSE);
-// 				   d->BlockBits -= mpc_decoder_bits_read(d) - FrameBitCnt;
-// 				   d->FrameWasValid = 1;
-// 				   break;
-// 			   default:
-// 				   return (mpc_uint32_t)(-1);
-// 		   }
-//
-// 		   return output_frame_length;
-// }
-//
-// mpc_uint32_t mpc_decoder_decode(
-// 		mpc_decoder *d,
-//     MPC_SAMPLE_FORMAT *buffer,
-// 	mpc_uint32_t *vbr_update_acc,
-// 	mpc_uint32_t *vbr_update_bits)
-// {
-// 	for(;;)
-// 	{
-//         //const mpc_int32_t MaxBrokenFrames = 0; // PluginSettings.MaxBrokenFrames
-//
-// 		mpc_uint32_t RING = d->Zaehler;
-// 		mpc_int32_t vbr_ring = (RING << 5) + d->pos;
-//
-// 		mpc_uint32_t valid_samples = mpc_decoder_decode_internal(d, buffer);
-//
-// 		if (valid_samples == (mpc_uint32_t)(-1) ) {
-// 			return 0;
-// 		}
-//
-// 		/**************** ERROR CONCEALMENT *****************/
-// 		if (d->FrameWasValid == 0 ) {
-//             // error occurred in bitstream
-// 			return (mpc_uint32_t)(-1);
-// 		}
-// 		else {
-// 			if (vbr_update_acc && vbr_update_bits) {
-// 				(*vbr_update_acc) ++;
-// 				vbr_ring = (d->Zaehler << 5) + d->pos - vbr_ring;
-// 				if (vbr_ring < 0) {
-// 					vbr_ring += 524288;
-// 				}
-// 				(*vbr_update_bits) += vbr_ring;
-// 			}
-//
-// 		}
-// 		mpc_decoder_update_buffer(d, RING);
-//
-// 		if (valid_samples > 0) {
-// 			return valid_samples;
-// 		}
-// 	}
-// }
-
