Index: audacious-musepack/trunk/libmpc.cpp
===================================================================
--- audacious-musepack/trunk/libmpc.cpp	(revision 457)
+++ audacious-musepack/trunk/libmpc.cpp	(revision 468)
@@ -48,5 +48,5 @@
 static Widgets      widgets      = {0};
 static MpcDecoder   mpcDecoder   = {0};
-static TrackInfo    track        = {0};
+static mpc_streaminfo	streamInfo	= {0};
 
 static GThread            *threadHandle;
@@ -268,5 +268,5 @@
 }
 
-static gint mpcIsOurFD(gchar* p_Filename, VFSFile* file)
+static gint mpcIsOurFD(const gchar* p_Filename, VFSFile* file)
 {
     gchar magic[4];
@@ -283,5 +283,4 @@
     mpcDecoder.offset   = -1;
     mpcDecoder.isAlive  = true;
-    mpcDecoder.isOutput = false;
     mpcDecoder.isPause  = false;
     threadHandle = g_thread_self();
@@ -292,14 +291,4 @@
 {
     mpcDecoder.isAlive = false;
-    if (threadHandle)
-    {
-        g_thread_join(threadHandle);
-        if (mpcDecoder.isOutput)
-        {
-            data->output->buffer_free();
-            data->output->close_audio();
-            mpcDecoder.isOutput = false;
-        }
-    }
 }
 
@@ -424,5 +413,5 @@
 }
 
-static Tuple *mpcGetTuple(gchar* p_Filename, VFSFile *input)
+static Tuple *mpcGetTuple(const gchar* p_Filename, VFSFile *input)
 {
 	Tuple *tuple = 0;
@@ -451,11 +440,11 @@
 	aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, static_cast<int> (1000 * mpc_streaminfo_get_length(&info)));
 
-// 	gchar *scratch = g_strdup_printf("Musepack v%d (encoder %s)", info.stream_version, info.encoder);
-// 	aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, scratch);
-// 	g_free(scratch);
-
-// 	scratch = g_strdup_printf("lossy (%s)", info.profile_name);
-// 	aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, scratch);
-// 	g_free(scratch);
+ 	gchar *scratch = g_strdup_printf("Musepack v%d (encoder %s)", info.stream_version, info.encoder);
+ 	aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, scratch);
+ 	g_free(scratch);
+
+ 	scratch = g_strdup_printf("lossy (%s)", info.profile_name);
+ 	aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, scratch);
+ 	g_free(scratch);
 
 	aud_tuple_associate_int(tuple, FIELD_BITRATE, NULL, static_cast<int> (info.average_bitrate / 1000));
@@ -463,12 +452,12 @@
 	MpcInfo tags = getTags(p_Filename);
 
-// 	aud_tuple_associate_string(tuple, FIELD_DATE, NULL, tags.date);
-// 	aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, tags.title);
-// 	aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, tags.artist);
-// 	aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, tags.album);
-// 	aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, tags.track);
-// 	aud_tuple_associate_int(tuple, FIELD_YEAR, NULL, tags.year);
-// 	aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, tags.genre);
-// 	aud_tuple_associate_string(tuple, FIELD_COMMENT, NULL, tags.comment);
+ 	aud_tuple_associate_string(tuple, FIELD_DATE, NULL, tags.date);
+ 	aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, tags.title);
+ 	aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, tags.artist);
+ 	aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, tags.album);
+ 	aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, tags.track);
+ 	aud_tuple_associate_int(tuple, FIELD_YEAR, NULL, tags.year);
+ 	aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, tags.genre);
+ 	aud_tuple_associate_string(tuple, FIELD_COMMENT, NULL, tags.comment);
 
 	freeTags(tags);
@@ -480,22 +469,12 @@
 }
 
-static Tuple *mpcProbeForTuple(gchar* p_Filename, VFSFile *input)
+static Tuple *mpcProbeForTuple(const gchar* p_Filename, VFSFile *input)
 {
     return mpcGetTuple(p_Filename, input);
 }
 
-static Tuple *mpcGetSongTuple(gchar* p_Filename)
+static Tuple *mpcGetSongTuple(const gchar* p_Filename)
 {
 	return mpcGetTuple(p_Filename, 0);
-}
-
-static char* mpcGenerateTitle(const MpcInfo& p_Tags, gchar* p_Filename)
-{
-    Tuple* tuple = mpcGetSongTuple(p_Filename);
-
-    gchar* title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
-
-    aud_tuple_free((void *) tuple);
-    return title;
 }
 
@@ -550,5 +529,5 @@
 }
 
-static void mpcFileInfoBox(char* p_Filename)
+static void mpcFileInfoBox(const gchar* p_Filename)
 {
     GtkWidget* infoBox = widgets.infoBox;
@@ -737,7 +716,7 @@
 static void* endThread(gchar* p_FileName, VFSFile * p_FileHandle, bool release)
 {
-    if(release)
+    if (release)
         lockRelease();
-    if(mpcDecoder.isError)
+    if (mpcDecoder.isError)
     {
         perror(mpcDecoder.isError);
@@ -748,9 +727,4 @@
     if(p_FileHandle)
         aud_vfs_fclose(p_FileHandle);
-    if(track.display)
-    {
-        g_free(track.display);
-        track.display = NULL;
-    }
     return 0;
 }
@@ -766,12 +740,12 @@
 	if (info.bits == -1) return -1; // end of stream
 
-	copyBuffer(sampleBuffer, xmmsBuffer, info.samples * track.channels);
+	copyBuffer(sampleBuffer, xmmsBuffer, info.samples * streamInfo.channels);
 
     if (pluginConfig.dynamicBitrate)
     {
-		track.bitrate = static_cast<int> (info.bits * track.sampleFreq / 1152);
+		mpcDecoder.dynbitrate = info.bits * streamInfo.sample_freq / 1152;
     }
 
-	playback->pass_audio(playback, FMT_S16_LE, track.channels, info.samples * 2 * track.channels, xmmsBuffer, NULL);
+	playback->output->write_audio(xmmsBuffer, info.samples * 2 * streamInfo.channels);
 	return info.samples;
 }
@@ -798,16 +772,9 @@
 	}
 
-    mpc_streaminfo info;
-	mpc_demux_get_info(demux, &info);
-
-    MpcInfo tags     = getTags(filename);
-    track.display    = mpcGenerateTitle(tags, filename);
-    track.length     = static_cast<int> (1000 * mpc_streaminfo_get_length(&info));
-    track.bitrate    = static_cast<int> (info.average_bitrate);
-    track.sampleFreq = info.sample_freq;
-    track.channels   = info.channels;
-    freeTags(tags);
-
-    data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
+	mpc_demux_get_info(demux, &streamInfo);
+
+	data->set_tuple(data, mpcGetTuple(data->filename, input));
+	data->set_params(data, 0, 0, static_cast<int> (streamInfo.average_bitrate),
+					 streamInfo.sample_freq, streamInfo.channels);
 
 	mpc_set_replay_level(demux, MPC_OLD_GAIN_REF, pluginConfig.replaygain,
@@ -817,5 +784,5 @@
     char xmmsBuffer[MPC_DECODER_BUFFER_LENGTH * 4];
 
-    if (!data->output->open_audio(FMT_S16_LE, track.sampleFreq, track.channels))
+    if (!data->output->open_audio(FMT_S16_LE, streamInfo.sample_freq, streamInfo.channels))
     {
         mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open an audio output");
@@ -823,5 +790,4 @@
     }
 
-	mpcDecoder.isOutput = true;
     lockRelease();
 
@@ -829,5 +795,5 @@
 	data->playing = TRUE;
 
-    gint counter = 2 * track.sampleFreq / 3;
+    gint counter = 2 * streamInfo.sample_freq / 3;
 	int status = 0;
     while (mpcDecoder.isAlive)
@@ -837,15 +803,13 @@
 		if (mpcDecoder.offset != -1)
         {
-			mpc_demux_seek_sample(demux, mpcDecoder.offset * track.sampleFreq / 1000);
+			mpc_demux_seek_sample(demux, mpcDecoder.offset * streamInfo.sample_freq / 1000);
 			data->output->flush(mpcDecoder.offset);
             mpcDecoder.offset = -1;
         }
-
-        short iPlaying = data->output->buffer_playing()? 1 : 0;
-        gint iFree = data->output->buffer_free();
-        if (!mpcDecoder.isPause && iFree >= ((1152 * 4) << iPlaying) && status != -1)
+		lockRelease();
+
+        if (mpcDecoder.isPause == FALSE && status != -1)
         {
             status = processBuffer(data, sampleBuffer, xmmsBuffer, demux);
-            lockRelease();
 
             if(pluginConfig.dynamicBitrate)
@@ -854,6 +818,6 @@
                 if(counter < 0)
                 {
-                    data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
-                    counter = 2 * track.sampleFreq / 3;
+					data->set_params(data, 0, 0, mpcDecoder.dynbitrate, streamInfo.sample_freq, streamInfo.channels);
+                    counter = 2 * streamInfo.sample_freq / 3;
                 }
             }
@@ -861,5 +825,4 @@
         else
         {
-            lockRelease();
 			if (mpcDecoder.isPause == FALSE && status == -1 &&
 						 data->output->buffer_playing() == FALSE)
@@ -868,4 +831,5 @@
         }
     }
+	data->output->close_audio();
 	mpc_demux_exit(demux);
     return endThread(filename, input, false);
@@ -882,33 +846,24 @@
     mpcAboutBox, // about : Show About box
     mpcConfigBox, // configure : Show Configure box
-    TRUE, // enabled
+    0, // PluginPreferences *settings
+
+    0, // gboolean have_subtune : Plugin supports/uses subtunes.
+    (gchar **)mpc_fmts, // vfs_extensions
+    0, // GList *(*scan_dir) (gchar * dirname);
 	0, // is_our_file
-	0, // scan_dir
+    mpcIsOurFD, // is_our_file_from_vfs
+	mpcProbeForTuple, // Tuple *(*probe_for_tuple)(gchar *uri, VFSFile *fd);
     mpcPlay, // play_file
     mpcStop, // stop
     mpcPause, // pause
     mpcSeek, // seek
+	mpcSeekm, // void (*mseek) (InputPlayback * playback, gulong millisecond);
 	0, // get_time
 	0, // get_volume
 	0, // set_volume
-	0, // get_vis_type
-	0, // add_vis_pcm
-	0, // set_info
-	0, // set_info_text
-	0, // get_song_info : Get Title String callback
-    mpcFileInfoBox, // file_info_box : Show File Info Box
+	mpcFileInfoBox, // file_info_box : Show File Info Box
     mpcGetSongTuple, // get_song_tuple : Acquire tuple for song
-    mpcIsOurFD, // is_our_file_from_vfs
-    (gchar **)mpc_fmts, // vfs_extensions
-
-    /* Added in Audacious 1.4.0 */
-	mpcSeekm, // void (*mseek) (InputPlayback * playback, gulong millisecond);
-	mpcProbeForTuple, // Tuple *(*probe_for_tuple)(gchar *uri, VFSFile *fd);
-
-    /* Added in Audacious 1.4.1 */
-//     gboolean have_subtune;
-
-    /* Added in Audacious 1.5.0 */
-//     gboolean (*update_song_tuple)(Tuple *tuple, VFSFile *fd);
+    0, //     gboolean (*update_song_tuple)(Tuple *tuple, VFSFile *fd);
+    0 //gint priority; /* 0 = first, 10 = last */
 };
 
