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  QString *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  QList<DecoderFactory*>::iterator it = factories->begin();
83  for (; it != factories->end(); ++it)
84  l += (*it)->description();
85 
86  return l;
87 }
88 
89 bool Decoder::supports(const QString &source)
90 {
92 
93  QList<DecoderFactory*>::iterator it = factories->begin();
94  for (; it != factories->end(); ++it)
95  {
96  if ((*it)->supports(source))
97  return true;
98  }
99 
100  return false;
101 }
102 
104 {
105  factories->push_back(fact);
106 }
107 
108 Decoder *Decoder::create(const QString &source, AudioOutput *output, bool deletable)
109 {
110  checkFactories();
111 
112  QList<DecoderFactory*>::iterator it = factories->begin();
113  for (; it != factories->end(); ++it)
114  {
115  if ((*it)->supports(source))
116  return (*it)->create(source, output, deletable);
117  }
118 
119  return nullptr;
120 }
static void registerFactory(DecoderFactory *)
Definition: decoder.cpp:103
static void checkFactories()
Definition: decoder.cpp:63
static Type Finished
Definition: decoder.h:49
static Type Decoding
Definition: decoder.h:47
virtual ~Decoder()
Definition: decoder.cpp:33
virtual void unlock(void)
Definition: decoder.h:82
virtual void lock(void)
Definition: decoder.h:81
static Type Error
Definition: decoder.h:50
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
static Decoder * create(const QString &, AudioOutput *, bool=false)
Definition: decoder.cpp:108
DecoderFactory * m_fctry
Definition: decoder.h:104
static Type Stopped
Definition: decoder.h:48
void error(const QString &)
Definition: decoder.cpp:53
void setOutput(AudioOutput *)
Definition: decoder.cpp:46
static QStringList all()
Definition: decoder.cpp:76
AudioOutput * output()
Definition: decoder.h:77
static bool supports(const QString &)
Definition: decoder.cpp:89
static QList< DecoderFactory * > * factories
Definition: decoder.cpp:61
AudioOutput * m_out
Definition: decoder.h:106
#define output