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  return std::accumulate(factories->cbegin(), factories->cend(),
81  QStringList(),
82  [](QStringList l, const auto & factory)
83  { return l += factory->description(); } );
84 }
85 
86 bool Decoder::supports(const QString &source)
87 {
89 
90  return std::any_of(factories->cbegin(), factories->cend(),
91  [source](const auto & factory)
92  {return factory->supports(source); } );
93 }
94 
96 {
97  factories->push_back(fact);
98 }
99 
100 Decoder *Decoder::create(const QString &source, AudioOutput *output, bool deletable)
101 {
102  checkFactories();
103 
104  auto supported = [source](const auto & factory)
105  { return factory->supports(source); };
106  auto f = std::find_if(factories->cbegin(), factories->cend(), supported);
107  return (f != factories->cend())
108  ? (*f)->create(source, output, deletable)
109  : nullptr;
110 }
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:1420
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:112
MythObservable::dispatch
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
Definition: mythobservable.cpp:73
CdDecoderFactory
Definition: decoder.h:122
AudioOutput
Definition: audiooutput.h:26
Decoder
Definition: decoder.h:65
Decoder::create
static Decoder * create(const QString &source, AudioOutput *output, bool deletable=false)
Definition: decoder.cpp:100
Decoder::unlock
virtual void unlock(void)
Definition: decoder.h:81
DecoderEvent
Definition: decoder.h:29
avfDecoderFactory
Definition: decoder.h:133
f
QTextStream t & f
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:603
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:86
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:95
Decoder::output
AudioOutput * output()
Definition: decoder.h:76
output
#define output
Definition: synaesthesia.cpp:220
musicmetadata.h
output.h
decoder.h
musicplayer.h
Decoder::m_fctry
DecoderFactory * m_fctry
Definition: decoder.h:103
visual.h