00001
00002
00003
00004
00005
00006
00007 #include "decoder.h"
00008 #include "constants.h"
00009 #include "metadata.h"
00010 #include "metaio.h"
00011 #include <mythtv/output.h>
00012 #include <mythtv/visual.h>
00013
00014 #include <qapplication.h>
00015 #include <qobject.h>
00016 #include <qptrlist.h>
00017 #include <qdir.h>
00018 #include <qstringlist.h>
00019 #include <qregexp.h>
00020
00021 #include <mythtv/mythcontext.h>
00022
00023 DecoderEvent* DecoderEvent::clone()
00024 {
00025 DecoderEvent *result = new DecoderEvent(*this);
00026
00027 if (error_msg)
00028 result->error_msg = new QString(*error_msg);
00029
00030 return result;
00031 }
00032
00033 Decoder::Decoder(DecoderFactory *d, QIODevice *i, AudioOutput *o)
00034 : fctry(d), in(i), out(o), blksize(0)
00035 {
00036 }
00037
00038 Decoder::~Decoder()
00039 {
00040 fctry = 0;
00041 in = 0;
00042 out = 0;
00043 blksize = 0;
00044 }
00045
00046 void Decoder::setInput(QIODevice *i)
00047 {
00048 lock();
00049 in = i;
00050 unlock();
00051 }
00052
00053 void Decoder::setOutput(AudioOutput *o)
00054 {
00055 lock();
00056 out = o;
00057 unlock();
00058 }
00059
00060 void Decoder::error(const QString &e)
00061 {
00062 QString *str = new QString(e.utf8());
00063 DecoderEvent ev(str);
00064 dispatch(ev);
00065 }
00066
00074 Metadata *Decoder::readMetadata(void)
00075 {
00076 Metadata *mdata = NULL;
00077 MetaIO* p_tagger = doCreateTagger();
00078
00079 if (p_tagger)
00080 {
00081 if (!ignore_id3)
00082 mdata = p_tagger->read(filename);
00083
00084 if (ignore_id3 || !mdata)
00085 mdata = p_tagger->readFromFilename(filename);
00086
00087 delete p_tagger;
00088 }
00089
00090 if (!mdata)
00091 {
00092 VERBOSE(VB_IMPORTANT, "Decoder::readMetadata(): " +
00093 QString("Could not read '%1'").arg(filename));
00094 }
00095
00096 return mdata;
00097 }
00098
00099
00108 Metadata* Decoder::getMetadata(void)
00109 {
00110
00111 Metadata *mdata = new Metadata(filename);
00112 if (mdata->isInDatabase())
00113 {
00114 return mdata;
00115 }
00116
00117 delete mdata;
00118
00119 return readMetadata();
00120 }
00121
00122
00142 MetaIO *Decoder::doCreateTagger(void)
00143 {
00144 return NULL;
00145 }
00146
00156 void Decoder::commitMetadata(Metadata *mdata)
00157 {
00158 MetaIO* p_tagger = doCreateTagger();
00159 if (p_tagger)
00160 {
00161 p_tagger->write(mdata);
00162 delete p_tagger;
00163 }
00164 }
00165
00166
00167
00168 int Decoder::ignore_id3 = 0;
00169 QString Decoder::musiclocation = "";
00170
00171 void Decoder::SetLocationFormatUseTags(void)
00172 {
00173 QString startdir = gContext->GetSetting("MusicLocation");
00174 startdir = QDir::cleanDirPath(startdir);
00175 if (!startdir.endsWith("/"))
00176 startdir += "/";
00177
00178 musiclocation = startdir;
00179
00180 ignore_id3 = gContext->GetNumSetting("Ignore_ID3", 0);
00181 }
00182
00183 static QPtrList<DecoderFactory> *factories = 0;
00184
00185 static void checkFactories()
00186 {
00187 if (!factories)
00188 {
00189 factories = new QPtrList<DecoderFactory>;
00190
00191 Decoder::registerFactory(new VorbisDecoderFactory);
00192 Decoder::registerFactory(new MadDecoderFactory);
00193 Decoder::registerFactory(new FlacDecoderFactory);
00194 #ifndef USING_MINGW
00195 Decoder::registerFactory(new CdDecoderFactory);
00196 #endif // USING_MINGW
00197 Decoder::registerFactory(new avfDecoderFactory);
00198 #ifdef AAC_SUPPORT
00199 Decoder::registerFactory(new aacDecoderFactory);
00200 #endif
00201 }
00202 }
00203
00204 QStringList Decoder::all()
00205 {
00206 checkFactories();
00207
00208 QStringList l;
00209 DecoderFactory *fact = factories->first();
00210 while (fact)
00211 {
00212 l << fact->description();
00213 fact = factories->next();
00214 }
00215
00216 return l;
00217 }
00218
00219 bool Decoder::supports(const QString &source)
00220 {
00221 checkFactories();
00222
00223 DecoderFactory *fact = factories->first();
00224 while (fact)
00225 {
00226 if (fact->supports(source))
00227 return TRUE;
00228
00229 fact = factories->next();
00230 }
00231
00232 return FALSE;
00233 }
00234
00235 void Decoder::registerFactory(DecoderFactory *fact)
00236 {
00237 factories->append(fact);
00238 }
00239
00240 Decoder *Decoder::create(const QString &source, QIODevice *input,
00241 AudioOutput *output, bool deletable)
00242 {
00243 checkFactories();
00244
00245 Decoder *decoder = 0;
00246
00247 DecoderFactory *fact = factories->first();
00248 while (fact)
00249 {
00250 if (fact->supports(source))
00251 {
00252 decoder = fact->create(source, input, output, deletable);
00253 break;
00254 }
00255
00256 fact = factories->next();
00257 }
00258
00259 return decoder;
00260 }
00261
00262