Index: mythplugins/mythmusic/mythmusic/mythmusic.pro
===================================================================
--- mythplugins/mythmusic/mythmusic/mythmusic.pro	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/mythmusic.pro	(working copy)
@@ -6,7 +6,7 @@
 !exists( config.pro ) {
    error(Missing config.pro: please run the configure script)
 }
- 
+
 INCLUDEPATH *= /usr/include/cdda
 TEMPLATE = lib
 CONFIG += plugin thread
@@ -23,7 +23,7 @@
 # Input
 HEADERS += cddecoder.h cdrip.h constants.h databasebox.h
 HEADERS += decoder.h flacdecoder.h flacencoder.h maddecoder.h mainvisual.h
-HEADERS += metadata.h playbackbox.h playlist.h polygon.h 
+HEADERS += metadata.h playbackbox.h playlist.h polygon.h
 HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h avfdecoder.h
 HEADERS += treecheckitem.h vorbisdecoder.h vorbisencoder.h polygon.h
 HEADERS += bumpscope.h globalsettings.h lameencoder.h dbcheck.h
@@ -37,17 +37,17 @@
 HEADERS += filescanner.h libvisualplugin.h musicplayer.h miniplayer.h
 HEADERS += mythlistview-qt3.h mythlistbox-qt3.h
 
-SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp 
-SOURCES += flacdecoder.cpp flacencoder.cpp maddecoder.cpp main.cpp
-SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp 
+SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp
+SOURCES += flacencoder.cpp main.cpp
+SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp
 SOURCES += streaminput.cpp encoder.cpp dbcheck.cpp
-SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpp lameencoder.cpp
+SOURCES += synaesthesia.cpp treecheckitem.cpp lameencoder.cpp
 SOURCES += vorbisencoder.cpp visualize.cpp bumpscope.cpp globalsettings.cpp
 SOURCES += databasebox.cpp genres.cpp
-SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp 
+SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp
 SOURCES += metaioflacvorbiscomment.cpp metaioavfcomment.cpp
 SOURCES += goom/filters.c goom/goom_core.c goom/graphic.c goom/tentacle3d.c
-SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c 
+SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c
 SOURCES += goom/zoom_filter_mmx.c goom/zoom_filter_xmmx.c goom/mythgoom.cpp
 SOURCES += avfdecoder.cpp editmetadata.cpp smartplaylist.cpp search.cpp
 SOURCES += treebuilders.cpp importmusic.cpp directoryfinder.cpp
@@ -71,6 +71,6 @@
 
 
 #The following line was inserted by qt3to4
-QT += xml  sql opengl qt3support 
+QT += xml  sql opengl qt3support
 
 include ( ../../libs-targetfix.pro )
Index: mythplugins/mythmusic/mythmusic/aacdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/aacdecoder.cpp	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/aacdecoder.cpp	(working copy)
@@ -3,9 +3,9 @@
 
 	(c) 2003, 2004 Thor Sigvaldason and Isaac Richards
 	Part of the mythTV project
-	
+
 	aac decoder methods
-	
+
 */
 
 #include <faad.h>
@@ -50,12 +50,12 @@
     {
         return the_decoder_object->aacRead((char *)buffer, length);
     }
-    VERBOSE(VB_IMPORTANT, 
+    VERBOSE(VB_IMPORTANT,
             "read_callback called with no aacDecoder object assigned");
     return 0;
-    
+
 }
-    
+
 uint32_t seek_callback(void *user_data, uint64_t position)
 {
     aacDecoder *the_decoder_object = (aacDecoder*) user_data;
@@ -66,7 +66,7 @@
     VERBOSE(VB_IMPORTANT,
             "seek_callback called with no aacDecoder object assigned");
     return 0;
-}        
+}
 
 
 
@@ -76,8 +76,8 @@
 
 
 
-aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 
-                       AudioOutput *o) 
+aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
+                       AudioOutput *o)
           : Decoder(d, i, o)
 {
     filename = file;
@@ -96,7 +96,7 @@
     output_buf = 0;
     output_bytes = 0;
     output_at = 0;
-    
+
     mp4_file_flag = false;
     mp4_callback = NULL;
     timescale = 0;
@@ -124,14 +124,14 @@
 {
     ulong min = final ? 0 : bks;
 
-    while ((!done && !finish && seekTime <= 0) && output_bytes > min) 
+    while ((!done && !finish && seekTime <= 0) && output_bytes > min)
     {
-        if (user_stop || finish) 
+        if (user_stop || finish)
         {
             inited = FALSE;
             done = TRUE;
-        } 
-        else 
+        }
+        else
         {
             ulong sz = output_bytes < bks ? output_bytes : bks;
 
@@ -147,7 +147,7 @@
 		lock();
 		done = user_stop;
 	      }
-	    
+
         }
     }
 }
@@ -163,7 +163,7 @@
     framesize = 0;
     seekTime = -1.0;
     totalTime = 0.0;
-    
+
     mp4_file_flag = false;
 
     if (! input())
@@ -172,7 +172,7 @@
         return false;
     }
 
-   
+
     if (!output_buf) {
         output_buf = new char[globalBufferSize];
     }
@@ -198,32 +198,32 @@
       error("couldn't seek in input");
         return false;
     }
-    
 
+
     //
     //  figure out if it's an mp4 file (aac in a mp4 wrapper a la Apple) or
     //  just a pure aac file.
     //
-    
+
     mp4_file_flag = false;
     char header_buffer[8];
     input()->readBlock(header_buffer, 8);
-    
+
     //
     //  Seek back to the begining, otherwise the decoder gets totally confused.
     //
-    
+
     input()->at(0);
-    
+
     if (
-            header_buffer[4] == 'f' && 
-            header_buffer[5] == 't' && 
-            header_buffer[6] == 'y' && 
+            header_buffer[4] == 'f' &&
+            header_buffer[5] == 't' &&
+            header_buffer[6] == 'y' &&
             header_buffer[7] == 'p'
       )
     {
         //
-        //  It's an mp4/m4a (iTunes file) ... 
+        //  It's an mp4/m4a (iTunes file) ...
         //
         mp4_file_flag = true;
         return initializeMP4();
@@ -236,7 +236,7 @@
         inited = false;
         return false;
     }
-    
+
     input()->close();
     inited = false;
     return false;
@@ -253,26 +253,26 @@
     mp4_callback->read = read_callback;
     mp4_callback->seek = seek_callback;
     mp4_callback->user_data = this;
-    
+
     //
     //  Open decoder library (?)
     //
-    
+
     decoder_handle = faacDecOpen();
 
     //
     //  Set configuration
     //
-    
+
     faacDecConfigurationPtr config = faacDecGetCurrentConfiguration(decoder_handle);
     config->outputFormat = FAAD_FMT_16BIT;
     config->downMatrix = 0; // if 1, we could downmix 5.1 to 2 ... apparently
     config->dontUpSampleImplicitSBR = 1;
     faacDecSetConfiguration(decoder_handle, config);
-                   
+
     //
-    //  Open the mp4 input file  
-    //                   
+    //  Open the mp4 input file
+    //
 
     mp4_input_file = mp4ff_open_read(mp4_callback);
     if (!mp4_input_file)
@@ -305,9 +305,9 @@
     uint buffer_size;
 
     mp4ff_get_decoder_config(
-                                mp4_input_file, 
-                                aac_track_number, 
-                                &buffer, 
+                                mp4_input_file,
+                                aac_track_number,
+                                &buffer,
                                 &buffer_size
                             );
 // some linux distros (gentoo, debian) modify the faad2 api with stdint.h types
@@ -335,10 +335,10 @@
 
     timescale = mp4ff_time_scale(mp4_input_file, aac_track_number);
     framesize = 1024;
-            
+
     //
     //  Fiddle with the default frame size if the data appears to need it
-    // 
+    //
 
     mp4AudioSpecificConfig mp4ASC;
     if (buffer)
@@ -354,16 +354,16 @@
     //
     //  Extract some information about the content
     //
-    
+
     long samples = mp4ff_num_samples(mp4_input_file, aac_track_number);
     float f = 1024.0;
     float seconds;
-    
+
     if (mp4ASC.sbr_present_flag == 1)
     {
         f = f * 2.0;
     }
-    
+
     seconds = (float)samples*(float)(f-1.0)/(float)mp4ASC.samplingFrequency;
 
     totalTime = seconds;
@@ -374,7 +374,7 @@
     {
 	bitrate = mp4ff_get_avg_bitrate(mp4_input_file, aac_track_number) / 1000;
     }
-    
+
     //
     //  Check we got same answers from mp4ASC
     //
@@ -437,7 +437,7 @@
 
     //
     //  No AAC tracks
-    // 
+    //
     return -1;
 }
 
@@ -470,7 +470,7 @@
 
     lock();
 
-    if (!inited) 
+    if (!inited)
     {
       error("aacDecoder: run() called without being init'd");
         unlock();
@@ -496,27 +496,27 @@
     uchar *buffer;
     uint  buffer_size;
 
-    while (!done && !finish && !user_stop) 
+    while (!done && !finish && !user_stop)
     {
         lock();
 
         ++current_sample;
-        if (seekTime >= 0.0) 
+        if (seekTime >= 0.0)
         {
             //
             //  Crap ... seek ... well, this is approximately correct
-            //        
+            //
 
             current_sample = (long int) (((double)(seekTime / totalTime)) * total_numb_samples);
             seekTime = -1.0;
         }
-        
+
         if (current_sample >= total_numb_samples)
         {
             //
             //  We're done ... make sure we play all the remaining output
             //
-            
+
             flush(TRUE);
 
             if (output())
@@ -539,10 +539,10 @@
             buffer_size = 0;
 
             int rc = mp4ff_read_sample(
-                                        mp4_input_file, 
-                                        aac_track_number, 
-                                        current_sample, 
-                                        &buffer,  
+                                        mp4_input_file,
+                                        aac_track_number,
+                                        current_sample,
+                                        &buffer,
                                         &buffer_size
                                       );
             if (rc == 0)
@@ -552,15 +552,15 @@
             }
             else
             {
-            
+
                 faacDecFrameInfo frame_info;
                 void *sample_buffer = faacDecDecode(
-                                                    decoder_handle, 
-                                                    &frame_info, 
-                                                    buffer, 
+                                                    decoder_handle,
+                                                    &frame_info,
+                                                    buffer,
                                                     buffer_size
                                                    );
-            
+
                 sample_count = frame_info.samples;
 
                 //
@@ -568,7 +568,7 @@
                 //  to the output (after checking we're not going to exceed
                 //  the output buffer size)
                 //
-                
+
                 if (((sample_count * 2) + output_at ) >= globalBufferSize)
                 {
                     error("aacDecoder: gloablBufferSize too small, "
@@ -576,7 +576,7 @@
                           "sound like crap)");
                     sample_count = ((globalBufferSize - output_at) / 2) - 100;
                 }
-            
+
                 char *char_buffer = (char *)sample_buffer;
                 short *sample_buffer16 = (short*)char_buffer;
                 for(uint i = 0; i < sample_count; i++)
@@ -584,7 +584,7 @@
                     output_buf[output_at + (i*2)]     = (char)(sample_buffer16[i] & 0xFF);
                     output_buf[output_at + (i*2) + 1] = (char)((sample_buffer16[i] >> 8) & 0xFF);
                 }
-            
+
                 if (sample_count > 0)
                 {
                     output_at += sample_count * 2;
@@ -595,20 +595,20 @@
 			if (bitrate)
 			{
 			    output()->SetSourceBitrate(bitrate);
-			} 
-                        else 
+			}
+                        else
                         {
 			    output()->SetSourceBitrate(
 				(int) ((float) (frame_info.bytesconsumed * 8) /
-				       (frame_info.samples / 
-				        frame_info.num_front_channels) 
+				       (frame_info.samples /
+				        frame_info.num_front_channels)
 				* frame_info.samplerate) / 1000);
 			}
 
                         flush();
                     }
                 }
-            
+
                 if (buffer)
                 {
                     free(buffer);
@@ -656,7 +656,7 @@
         {
             return 0;
         }
-        return read_result; 
+        return read_result;
     }
     error("aacDecoder: aacRead() was called, but there is no input");
     return 0;
@@ -691,7 +691,7 @@
 
 const QString &aacDecoderFactory::extension() const
 {
-    static QString ext(".m4a");
+    static QString ext(".aac|.m4a");
     return ext;
 }
 
@@ -702,7 +702,7 @@
     return desc;
 }
 
-Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input, 
+Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input,
                                   AudioOutput *output, bool deletable)
 {
 
@@ -710,11 +710,11 @@
         return new aacDecoder(file, this, input, output);
 
     static aacDecoder *decoder = 0;
-    if (!decoder) 
+    if (!decoder)
     {
         decoder = new aacDecoder(file, this, input, output);
-    } 
-    else 
+    }
+    else
     {
         decoder->setInput(input);
         decoder->setOutput(output);
Index: mythplugins/mythmusic/mythmusic/decoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.h	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/decoder.h	(working copy)
@@ -89,7 +89,7 @@
     static QStringList all();
     static bool supports(const QString &);
     static void registerFactory(DecoderFactory *);
-    static Decoder *create(const QString &, QIODevice *, AudioOutput *, 
+    static Decoder *create(const QString &, QIODevice *, AudioOutput *,
                            bool = FALSE);
     static void SetLocationFormatUseTags(void);
 
@@ -126,24 +126,6 @@
     virtual ~DecoderFactory() {}
 };
 
-class VorbisDecoderFactory : public DecoderFactory
-{
-public:
-    bool supports(const QString &) const;
-    const QString &extension() const;
-    const QString &description() const;
-    Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
-};
-
-class MadDecoderFactory : public DecoderFactory
-{
-public:
-    bool supports(const QString &) const;
-    const QString &extension() const;
-    const QString &description() const;
-    Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
-};
-
 class CdDecoderFactory : public DecoderFactory
 {
 public:
@@ -153,15 +135,6 @@
     Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
 };
 
-class FlacDecoderFactory : public DecoderFactory
-{
-public:
-    bool supports(const QString &) const;
-    const QString &extension() const;
-    const QString &description() const;
-    Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
-};
-
 class avfDecoderFactory : public DecoderFactory
 {
 public:
Index: mythplugins/mythmusic/mythmusic/decoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/decoder.cpp	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/decoder.cpp	(working copy)
@@ -20,8 +20,8 @@
 
 #include <mythtv/mythcontext.h>
 
-DecoderEvent* DecoderEvent::clone() 
-{ 
+DecoderEvent* DecoderEvent::clone()
+{
     DecoderEvent *result = new DecoderEvent(*this);
 
     if (error_msg)
@@ -57,7 +57,7 @@
     unlock();
 }
 
-void Decoder::error(const QString &e) 
+void Decoder::error(const QString &e)
 {
     QString *str = new QString(e.toUtf8());
     DecoderEvent ev(str);
@@ -98,7 +98,7 @@
 
 
 /** \fn Decoder::getMetadata(void)
- *  \brief Get the metadata  for \p filename 
+ *  \brief Get the metadata  for \p filename
  *
  *  First tries to read the metadata from the database. If there
  *  is no database entry, it'll call \p Decoder::readMetadata.
@@ -127,7 +127,7 @@
  *  instance of the appropriate MetaIO subtype. It is used by \p
  *  Decoder::getMetadata, \p Decoder::readMetadata and \p
  *  Decoder::commitMetadata.
- *       
+ *
  *  The default implementation returns a NULL pointer, which
  *  essentially means, that if the decoder does not overrider this
  *  method or all of the users (see previous paragraph), files
@@ -182,15 +182,12 @@
 
 static Q3PtrList<DecoderFactory> *factories = 0;
 
-static void checkFactories() 
+static void checkFactories()
 {
-    if (!factories) 
+    if (!factories)
     {
         factories = new Q3PtrList<DecoderFactory>;
 
-        Decoder::registerFactory(new VorbisDecoderFactory);
-        Decoder::registerFactory(new MadDecoderFactory);
-        Decoder::registerFactory(new FlacDecoderFactory);
 #ifndef USING_MINGW
         Decoder::registerFactory(new CdDecoderFactory);
 #endif // USING_MINGW
@@ -207,7 +204,7 @@
 
     QStringList l;
     DecoderFactory *fact = factories->first();
-    while (fact) 
+    while (fact)
     {
         l << fact->description();
         fact = factories->next();
@@ -221,7 +218,7 @@
     checkFactories();
 
     DecoderFactory *fact = factories->first();
-    while (fact) 
+    while (fact)
     {
         if (fact->supports(source))
             return TRUE;
@@ -245,9 +242,9 @@
     Decoder *decoder = 0;
 
     DecoderFactory *fact = factories->first();
-    while (fact) 
+    while (fact)
     {
-        if (fact->supports(source)) 
+        if (fact->supports(source))
         {
             decoder = fact->create(source, input, output, deletable);
             break;
Index: mythplugins/mythmusic/mythmusic/avfdecoder.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.cpp	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.cpp	(working copy)
@@ -2,37 +2,44 @@
     MythTV WMA Decoder
     Written by Kevin Kuphal
 
-    Special thanks to 
+    Special thanks to
        ffmpeg team for libavcodec and libavformat
        qemacs team for their av support which I used to understand the libraries
        getid3.sourceforget.net project for the ASF information used here
-        
-    This library decodes Windows Media (WMA/ASF) files into PCM data 
-    returned to the MythMusic output buffer.  
 
+    This library decodes Windows Media (WMA/ASF) files into PCM data
+    returned to the MythMusic output buffer.
+
     Revision History
         - Initial release
         - 1/9/2004 - Improved seek support
 */
 
+// C++ headers
 #include <iostream>
 #include <string>
-#include <qobject.h>
-#include <qiodevice.h>
-#include <qfile.h>
 
+// QT headers
+#include <QObject>
+#include <QIODevice>
+#include <QFile>
+
+// Myth headers
+#include <mythtv/mythcontext.h>
+#include <mythtv/audiooutput.h>
+#include <mythtv/mythverbose.h>
+
 using namespace std;
 
+// Mythmusic Headers
 #include "avfdecoder.h"
 #include "constants.h"
-#include <mythtv/audiooutput.h>
 #include "metadata.h"
 #include "metaioavfcomment.h"
 
-#include <mythtv/mythcontext.h>
 
-avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 
-                       AudioOutput *o) 
+avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
+                       AudioOutput *o)
           : Decoder(d, i, o)
 {
     filename = file;
@@ -47,16 +54,18 @@
     bitrate = 0;
     seekTime = -1.0;
     totalTime = 0.0;
-    chan = 0;
+    m_channels = 0;
     output_buf = 0;
     output_bytes = 0;
     output_at = 0;
 
-    ic = NULL;
-    oc = NULL;
-    ifmt = NULL;
-    ap = &params;
-    pkt = &pkt1;
+    m_inputContext = NULL;
+    m_outputContext = NULL;
+    m_inputFormat = NULL;
+    m_outputFormat = NULL;
+    m_ap = &m_params;
+    m_pkt = &m_pkt1;
+    m_decStream = NULL;
 }
 
 avfDecoder::~avfDecoder(void)
@@ -80,18 +89,18 @@
 {
     ulong min = final ? 0 : bks;
 
-    while ((!done && !finish && seekTime <= 0) && output_bytes > min) 
+    while ((!done && !finish && seekTime <= 0) && output_bytes > min)
     {
-        if (user_stop || finish) 
+        if (user_stop || finish)
         {
             inited = FALSE;
             done = TRUE;
-        } 
-        else 
+        }
+        else
         {
             ulong sz = output_bytes < bks ? output_bytes : bks;
 
-            int samples = (sz*8)/(chan*16);
+            int samples = (sz*8)/(m_channels*16);
             if (output()->AddSamples(output_buf, samples, -1))
             {
                 output_bytes -= sz;
@@ -109,16 +118,17 @@
 
 bool avfDecoder::initialize()
 {
+    VERBOSE(VB_GENERAL, "Initialising");
     bks = blockSize();
 
     inited = user_stop = done = finish = FALSE;
     len = freq = bitrate = 0;
-    stat = chan = 0;
+    stat = m_channels = 0;
     seekTime = -1.0;
     totalTime = 0.0;
 
     filename = ((QFile *)input())->name();
-   
+
     if (!output_buf)
         output_buf = new char[globalBufferSize];
     output_at = 0;
@@ -130,69 +140,94 @@
 
     // open the media file
     // this should populate the input context
-    if (av_open_input_file(&ic, filename, ifmt, 0, ap) < 0)
-        return FALSE;    
+    if (av_open_input_file(&m_inputContext, filename, m_inputFormat, 0, m_ap) < 0)
+    {
+        deinit();
+        return FALSE;
+    }
 
     // determine the stream format
     // this also populates information needed for metadata
-    if (av_find_stream_info(ic) < 0) 
+    if (av_find_stream_info(m_inputContext) < 0)
+    {
+        deinit();
         return FALSE;
+    }
 
     // Store the audio codec of the stream
-    audio_dec = ic->streams[0]->codec;
+    m_audioDec = m_inputContext->streams[0]->codec;
 
     // Store the input format of the context
-    ifmt = ic->iformat;
+    m_inputFormat = m_inputContext->iformat;
 
     // Determine the output format
     // Given we are outputing to a sound card, this will always
     // be a PCM format
+
 #ifdef WORDS_BIGENDIAN
-    fmt = guess_format("s16be", NULL, NULL);
+    m_outputFormat = guess_format("s16be", NULL, NULL);
 #else
-    fmt = guess_format("s16le", NULL, NULL);
+    m_outputFormat = guess_format("s16le", NULL, NULL);
 #endif
-    if (!fmt)
+
+    if (!m_outputFormat)
     {
         VERBOSE(VB_IMPORTANT, "avfDecoder.o - failed to get output format");
+        deinit();
         return FALSE;
     }
 
     // Populate the output context
     // Create the output stream and attach to output context
     // Set various parameters to match the input format
-    oc = (AVFormatContext *)av_mallocz(sizeof(AVFormatContext));
-    oc->oformat = fmt;
+    m_outputContext = (AVFormatContext *)av_mallocz(sizeof(AVFormatContext));
+    m_outputContext->oformat = m_outputFormat;
 
-    dec_st = av_new_stream(oc,0);
-    dec_st->codec->codec_type = CODEC_TYPE_AUDIO;
-    dec_st->codec->codec_id = oc->oformat->audio_codec;
-    dec_st->codec->sample_rate = audio_dec->sample_rate;
-    dec_st->codec->channels = audio_dec->channels;
-    dec_st->codec->bit_rate = audio_dec->bit_rate;
-    av_set_parameters(oc, NULL);
+    m_decStream = av_new_stream(m_outputContext,0);
+    m_decStream->codec->codec_type = CODEC_TYPE_AUDIO;
+    m_decStream->codec->codec_id = m_outputContext->oformat->audio_codec;
+    m_decStream->codec->sample_rate = m_audioDec->sample_rate;
+    m_decStream->codec->channels = m_audioDec->channels;
+    m_decStream->codec->bit_rate = m_audioDec->bit_rate;
+    av_set_parameters(m_outputContext, NULL);
 
     // Prepare the decoding codec
     // The format is different than the codec
     // While we could get fed a WAV file, it could contain a number
     // of different codecs
-    codec = avcodec_find_decoder(audio_dec->codec_id);
-    if (!codec)
+    m_codec = avcodec_find_decoder(m_audioDec->codec_id);
+    if (!m_codec)
+    {
+        deinit();
         return FALSE;
-    if (avcodec_open(audio_dec,codec) < 0)
+    }
+    if (avcodec_open(m_audioDec,m_codec) < 0)
+    {
+        deinit();
         return FALSE;
-    totalTime = (ic->duration / AV_TIME_BASE) * 1000;
+    }
+    if (AV_TIME_BASE > 0)
+        totalTime = (m_inputContext->duration / AV_TIME_BASE) * 1000;
 
-    freq = audio_dec->sample_rate;
-    chan = audio_dec->channels;
+    freq = m_audioDec->sample_rate;
+    m_channels = m_audioDec->channels;
 
+    if (m_channels <= 0)
+    {
+        VERBOSE(VB_IMPORTANT, QString("AVCodecContext tells us %1 channel are "
+                                      "available, this is bad, bailing.")
+                                      .arg(m_channels));
+        deinit();
+        return false;
+    }
+
     if (output())
     {
         const AudioSettings settings(
-            16 /*bits*/, audio_dec->channels, audio_dec->sample_rate,
+            16 /*bits*/, m_audioDec->channels, m_audioDec->sample_rate,
             false /* AC3/DTS pass through */);
         output()->Reconfigure(settings);
-        output()->SetSourceBitrate(audio_dec->bit_rate);
+        output()->SetSourceBitrate(m_audioDec->bit_rate);
     }
 
     inited = TRUE;
@@ -206,23 +241,30 @@
 
 void avfDecoder::deinit()
 {
+    VERBOSE(VB_GENERAL, "De-initialising");
     inited = user_stop = done = finish = FALSE;
     len = freq = bitrate = 0;
-    stat = chan = 0;
+    stat = m_channels = 0;
     setInput(0);
     setOutput(0);
 
     // Cleanup here
-    if(ic)
+    if(m_inputContext)
     {
-        av_close_input_file(ic);
-        ic = NULL;
+        av_close_input_file(m_inputContext);
+        m_inputContext = NULL;
     }
-    if(oc)
+    if(m_outputContext)
     {
-        av_free(oc);
-        oc = NULL;
+        av_free(m_outputContext);
+        m_outputContext = NULL;
     }
+
+    m_decStream = NULL;
+    m_codec = NULL;
+    m_audioEnc = m_audioDec = NULL;
+    m_inputFormat = NULL;
+    m_outputFormat = NULL;
 }
 
 void avfDecoder::run()
@@ -232,7 +274,7 @@
 
     lock();
 
-    if (!inited) 
+    if (!inited)
     {
         unlock();
         return;
@@ -247,17 +289,17 @@
         dispatch(e);
     }
 
-    av_read_play(ic);
-    while (!done && !finish && !user_stop) 
+    av_read_play(m_inputContext);
+    while (!done && !finish && !user_stop)
     {
         lock();
 
         // Look to see if user has requested a seek
-        if (seekTime >= 0.0) 
+        if (seekTime >= 0.0)
         {
             VERBOSE(VB_GENERAL, QString("avfdecoder.o: seek time %1")
                 .arg(seekTime));
-            if (av_seek_frame(ic, -1, (int64_t)(seekTime * AV_TIME_BASE), 0)
+            if (av_seek_frame(m_inputContext, -1, (int64_t)(seekTime * AV_TIME_BASE), 0)
                               < 0)
             {
                 VERBOSE(VB_IMPORTANT, "Error seeking");
@@ -267,8 +309,8 @@
         }
 
         // Read a packet from the input context
-        // if (av_read_packet(ic, pkt) < 0)
-        if (av_read_frame(ic, pkt) < 0)
+        // if (av_read_packet(m_inputContext, m_pkt) < 0)
+        if (av_read_frame(m_inputContext, m_pkt) < 0)
         {
             VERBOSE(VB_IMPORTANT, "Read frame failed");
             unlock();
@@ -277,11 +319,11 @@
         }
 
         // Get the pointer to the data and its length
-        ptr = pkt->data;
-        len = pkt->size;
+        ptr = m_pkt->data;
+        len = m_pkt->size;
         unlock();
 
-        while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0)  
+        while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0)
         {
             lock();
             // Decode the stream to the output codec
@@ -289,9 +331,9 @@
             // data_size is the size in bytes of the frame
             // ptr is the input buffer
             // len is the size of the input buffer
-            dec_len = avcodec_decode_audio(audio_dec, samples, &data_size, 
-                                           ptr, len);    
-            if (dec_len < 0) 
+            dec_len = avcodec_decode_audio(m_audioDec, samples, &data_size,
+                                           ptr, len);
+            if (dec_len < 0)
             {
                 unlock();
                 break;
@@ -300,8 +342,8 @@
             s = (char *)samples;
             unlock();
 
-            while (data_size > 0 && !done && !finish && !user_stop && 
-                   seekTime <= 0.0) 
+            while (data_size > 0 && !done && !finish && !user_stop &&
+                   seekTime <= 0.0)
              {
                 lock();
                 // Store and check the size
@@ -339,11 +381,12 @@
             len -= dec_len;
             unlock();
         }
-        av_free_packet(pkt);
+        av_free_packet(m_pkt);
     }
 
     flush(TRUE);
-    if (output())
+
+    if (output() && !user_stop)
         output()->Drain();
 
     if (finish)
@@ -364,7 +407,7 @@
 MetaIO* avfDecoder::doCreateTagger(void)
 {
     return new MetaIOAVFComment();
-}    
+}
 
 bool avfDecoderFactory::supports(const QString &source) const
 {
@@ -380,7 +423,8 @@
 
 const QString &avfDecoderFactory::extension() const
 {
-    static QString ext(".wma|.wav");
+    static QString ext(".mp3|.mp2|.ogg|.flac|.wma|.wav|.ac3|.oma|.omg|.atp|"
+                       ".ra|.dts");
     return ext;
 }
 
@@ -390,18 +434,18 @@
     return desc;
 }
 
-Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input, 
+Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input,
                                   AudioOutput *output, bool deletable)
 {
     if (deletable)
         return new avfDecoder(file, this, input, output);
 
     static avfDecoder *decoder = 0;
-    if (!decoder) 
+    if (!decoder)
     {
         decoder = new avfDecoder(file, this, input, output);
-    } 
-    else 
+    }
+    else
     {
         decoder->setInput(input);
         decoder->setOutput(output);
Index: mythplugins/mythmusic/mythmusic/main.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/main.cpp	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/main.cpp	(working copy)
@@ -23,8 +23,6 @@
 // MythMusic headers
 #include "decoder.h"
 #include "metadata.h"
-#include "maddecoder.h"
-#include "vorbisdecoder.h"
 #include "databasebox.h"
 #include "playbackbox.h"
 #include "playlist.h"
Index: mythplugins/mythmusic/mythmusic/avfdecoder.h
===================================================================
--- mythplugins/mythmusic/mythmusic/avfdecoder.h	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/avfdecoder.h	(working copy)
@@ -37,7 +37,7 @@
     unsigned int bks;
     bool done, finish;
     long len, freq, bitrate;
-    int chan;
+    int m_channels;
     unsigned long output_size;
     double totalTime, seekTime;
 
@@ -46,16 +46,16 @@
     long int start;
     long int end;
 
-    AVOutputFormat *fmt;	// Encoding format (PCM)
-    AVInputFormat *ifmt;	// Decoding format
-    AVFormatParameters params;
-    AVFormatParameters *ap;
-    AVFormatContext *oc, *ic;
-    AVStream *enc_st, *dec_st;
-    AVCodec *codec, *enc_codec;		// Codec
-    AVCodecContext *audio_enc, *audio_dec;
-    AVPacket pkt1;
-    AVPacket *pkt;
+    AVOutputFormat *m_outputFormat; // Encoding format (PCM)
+    AVInputFormat *m_inputFormat; // Decoding format
+    AVFormatParameters m_params;
+    AVFormatParameters *m_ap;
+    AVFormatContext *m_outputContext, *m_inputContext;
+    AVStream *m_decStream;
+    AVCodec *m_codec; // Codec
+    AVCodecContext *m_audioEnc, *m_audioDec;
+    AVPacket m_pkt1;
+    AVPacket *m_pkt;
 
     int errcode;
 
Index: mythplugins/mythmusic/mythmusic/filescanner.cpp
===================================================================
--- mythplugins/mythmusic/mythmusic/filescanner.cpp	(revision 18943)
+++ mythplugins/mythmusic/mythmusic/filescanner.cpp	(working copy)
@@ -16,8 +16,6 @@
 
 // MythMusic headers
 #include "decoder.h"
-#include "maddecoder.h"
-#include "vorbisdecoder.h"
 #include "filescanner.h"
 #include "metadata.h"
 
