MythTV  master
decoder.cpp
Go to the documentation of this file.
1 // Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com>
2 //
3 // Use, modification and distribution is allowed without limitation,
4 // warranty, or liability of any kind.
5 //
6 
7 // mythmusic
8 #include "decoder.h"
9 #include "constants.h"
10 #include "musicplayer.h"
11 
12 // qt
13 #include <QDir>
14 
15 // libmyth
16 #include <mythcontext.h>
17 #include <output.h>
18 #include <visual.h>
19 
20 // libmythmetadata
21 #include "musicmetadata.h"
22 #include "metaio.h"
23 
24 QEvent::Type DecoderEvent::Decoding =
25  (QEvent::Type) QEvent::registerEventType();
26 QEvent::Type DecoderEvent::Stopped =
27  (QEvent::Type) QEvent::registerEventType();
28 QEvent::Type DecoderEvent::Finished =
29  (QEvent::Type) QEvent::registerEventType();
30 QEvent::Type DecoderEvent::Error =
31  (QEvent::Type) QEvent::registerEventType();
32 
34 {
35  m_fctry = nullptr;
36  m_out = nullptr;
37 }
38 
39 /*
40 QString Decoder::getURL(void)
41 {
42  return gPlayer->getDecoderHandler()->getUrl();
43 }
44 */
45 
47 {
48  lock();
49  m_out = o;
50  unlock();
51 }
52 
53 void Decoder::error(const QString &e)
54 {
55  auto *str = new QString(e.toUtf8());
56  DecoderEvent ev(str);
57  dispatch(ev);
58 }
59 
60 // static methods
61 static QList<DecoderFactory*> *factories = nullptr;
62 
63 static void checkFactories()
64 {
65  if (!factories)
66  {
67  factories = new QList<DecoderFactory*>;
68 
69 #ifdef HAVE_CDIO
71 #endif
73  }
74 }
75 
76 QStringList Decoder::all()
77 {
79 
80  QStringList l;
81 
82  for (const auto & factory : qAsConst(*factories))
83  l += factory->description();
84 
85  return l;
86 }
87 
88 bool Decoder::supports(const QString &source)
89 {
91 
92  for (const auto & factory : qAsConst(*factories))
93  {
94  if (factory->supports(source))
95  return true;
96  }
97 
98  return false;
99 }
100 
102 {
103  factories->push_back(fact);
104 }
105 
106 Decoder *Decoder::create(const QString &source, AudioOutput *output, bool deletable)
107 {
108  checkFactories();
109 
110  for (const auto & factory : qAsConst(*factories))
111  {
112  if (factory->supports(source))
113  return factory->create(source, output, deletable);
114  }
115 
116  return nullptr;
117 }
Decoder::~Decoder
~Decoder() override
Definition: decoder.cpp:33
Decoder::m_out
AudioOutput * m_out
Definition: decoder.h:105
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1417
DecoderFactory::supports
virtual bool supports(const QString &source) const =0
Decoder::factory
DecoderFactory * factory() const
Definition: decoder.h:74
factories
static QList< DecoderFactory * > * factories
Definition: decoder.cpp:61
DecoderFactory::description
virtual const QString & description() const =0
DecoderEvent::Error
static Type Error
Definition: decoder.h:50
DecoderFactory
Definition: decoder.h:113
MythObservable::dispatch
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
Definition: mythobservable.cpp:73
CdDecoderFactory
Definition: decoder.h:123
AudioOutput
Definition: audiooutput.h:26
Decoder
Definition: decoder.h:66
Decoder::create
static Decoder * create(const QString &source, AudioOutput *output, bool deletable=false)
Definition: decoder.cpp:106
Decoder::unlock
virtual void unlock(void)
Definition: decoder.h:81
DecoderEvent
Definition: decoder.h:30
avfDecoderFactory
Definition: decoder.h:134
DecoderFactory::create
virtual Decoder * create(const QString &source, AudioOutput *output, bool deletable)=0
DecoderEvent::Decoding
static Type Decoding
Definition: decoder.h:47
DecoderEvent::Finished
static Type Finished
Definition: decoder.h:49
Decoder::all
static QStringList all()
Definition: decoder.cpp:76
Decoder::error
void error(const QString &e)
Definition: decoder.cpp:53
DecoderEvent::Stopped
static Type Stopped
Definition: decoder.h:48
metaio.h
constants.h
Decoder::setOutput
void setOutput(AudioOutput *o)
Definition: decoder.cpp:46
mythcontext.h
Decoder::supports
static bool supports(const QString &source)
Definition: decoder.cpp:88
Decoder::lock
virtual void lock(void)
Definition: decoder.h:80
checkFactories
static void checkFactories()
Definition: decoder.cpp:63
Decoder::registerFactory
static void registerFactory(DecoderFactory *fact)
Definition: decoder.cpp:101
Decoder::output
AudioOutput * output()
Definition: decoder.h:76
output
#define output
Definition: synaesthesia.cpp:221
musicmetadata.h
output.h
decoder.h
musicplayer.h
Decoder::m_fctry
DecoderFactory * m_fctry
Definition: decoder.h:103
visual.h