MythTV  master
decoder.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef DECODER_H_
4 #define DECODER_H_
5 
6 #include <QWaitCondition>
7 #include <QStringList>
8 #include <QEvent>
9 #include <QMutex>
10 #include <QCoreApplication>
11 
12 #include "config.h"
13 
14 #include <mythobservable.h>
15 #include <mthread.h>
16 
17 class MusicMetadata;
18 class MetaIO;
19 class Decoder;
20 class DecoderFactory;
21 
22 class QObject;
23 class QIODevice;
24 class OutputEvent;
25 
26 class Buffer;
27 class AudioOutput;
28 
29 class DecoderEvent : public MythEvent
30 {
31  public:
32  explicit DecoderEvent(Type type) : MythEvent(type) { ; }
33 
34  explicit DecoderEvent(QString *e) : MythEvent(Error), m_error_msg(e) { ; }
35 
37  {
38  if (m_error_msg)
39  delete m_error_msg;
40  }
41 
42  const QString *errorMessage() const { return m_error_msg; }
43 
44  MythEvent *clone(void) const override // MythEvent
45  { return new DecoderEvent(*this); }
46 
47  static Type Decoding;
48  static Type Stopped;
49  static Type Finished;
50  static Type Error;
51 
52  private:
54  {
55  if (o.m_error_msg)
56  {
57  m_error_msg = new QString(*o.m_error_msg);
58  }
59  }
61 
62  private:
63  QString *m_error_msg {nullptr};
64 };
65 
66 class Decoder : public MThread, public MythObservable
67 {
68  public:
69  virtual ~Decoder();
70 
71  virtual bool initialize() = 0;
72  virtual void seek(double) = 0;
73  virtual void stop() = 0;
74 
75  DecoderFactory *factory() const { return m_fctry; }
76 
77  AudioOutput *output() { return m_out; }
78  void setOutput(AudioOutput *);
79  void setURL(const QString &url) { m_url = url; }
80 
81  virtual void lock(void) { return m_mtx.lock(); }
82  virtual void unlock(void) { return m_mtx.unlock(); }
83  virtual bool tryLock(void) { return m_mtx.tryLock(); }
84 
85  QWaitCondition *cond() { return &m_cnd; }
86 
87  QString getURL(void) const { return m_url; }
88 
89  // static methods
90  static QStringList all();
91  static bool supports(const QString &);
92  static void registerFactory(DecoderFactory *);
93  static Decoder *create(const QString &, AudioOutput *, bool = false);
94 
95  protected:
97  : MThread("MythMusicDecoder"), m_fctry(d), m_out(o) {}
98  QMutex* getMutex(void) { return &m_mtx; }
99  void error(const QString &);
100 
101  QString m_url;
102 
103  private:
105 
106  AudioOutput *m_out {nullptr};
107 
108  QMutex m_mtx;
109  QWaitCondition m_cnd;
110 
111 };
112 
114 {
115 public:
116  virtual bool supports(const QString &source) const = 0;
117  virtual const QString &extension() const = 0; // file extension, ie. ".mp3" or ".ogg"
118  virtual const QString &description() const = 0; // file type, ie. "MPEG Audio Files"
119  virtual Decoder *create(const QString &, AudioOutput *, bool) = 0;
120  virtual ~DecoderFactory() = default;
121 };
122 
124 {
126 
127 public:
128  bool supports(const QString &) const override; // DecoderFactory
129  const QString &extension() const override; // DecoderFactory
130  const QString &description() const override; // DecoderFactory
131  Decoder *create(const QString &, AudioOutput *, bool) override; // DecoderFactory
132 };
133 
135 {
137 
138 public:
139  bool supports(const QString &) const override; // DecoderFactory
140  const QString &extension() const override; // DecoderFactory
141  const QString &description() const override; // DecoderFactory
142  Decoder *create(const QString &, AudioOutput *, bool) override; // DecoderFactory
143 };
144 
145 #endif
~DecoderEvent()
Definition: decoder.h:36
QString * m_error_msg
Definition: decoder.h:63
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
static void registerFactory(DecoderFactory *)
Definition: decoder.cpp:103
static Type Finished
Definition: decoder.h:49
Q_DECLARE_TR_FUNCTIONS(avfDecoderFactory)
DecoderFactory * factory() const
Definition: decoder.h:75
static Type Decoding
Definition: decoder.h:47
virtual ~Decoder()
Definition: decoder.cpp:33
virtual void unlock(void)
Definition: decoder.h:82
const QString * errorMessage() const
Definition: decoder.h:42
Decoder * create(const QString &, AudioOutput *, bool) override
Definition: cddecoder.cpp:781
const QString & description() const override
Definition: cddecoder.cpp:774
Decoder(DecoderFactory *d, AudioOutput *o)
Definition: decoder.h:96
const QString & description() const override
Definition: avfdecoder.cpp:607
Superclass for making an object have a set of listeners.
Definition: metaio.h:17
virtual void lock(void)
Definition: decoder.h:81
static Type Error
Definition: decoder.h:50
This class is used as a container for messages.
Definition: mythevent.h:16
virtual bool tryLock(void)
Definition: decoder.h:83
virtual bool initialize()=0
QWaitCondition m_cnd
Definition: decoder.h:109
Decoder * create(const QString &, AudioOutput *, bool) override
Definition: avfdecoder.cpp:613
static Decoder * create(const QString &, AudioOutput *, bool=false)
Definition: decoder.cpp:108
static const uint16_t * d
virtual bool supports(const QString &source) const =0
DecoderFactory * m_fctry
Definition: decoder.h:104
const QString & extension() const override
Definition: avfdecoder.cpp:602
bool supports(const QString &) const override
Definition: cddecoder.cpp:761
DecoderEvent & operator=(const DecoderEvent &)
static Type Stopped
Definition: decoder.h:48
void error(const QString &)
Definition: decoder.cpp:53
void setOutput(AudioOutput *)
Definition: decoder.cpp:46
Q_DECLARE_TR_FUNCTIONS(CdDecoderFactory)
virtual ~DecoderFactory()=default
DecoderEvent(const DecoderEvent &o)
Definition: decoder.h:53
QWaitCondition * cond()
Definition: decoder.h:85
virtual void seek(double)=0
DecoderEvent(Type type)
Definition: decoder.h:32
virtual void stop()=0
QMutex m_mtx
Definition: decoder.h:108
DecoderEvent(QString *e)
Definition: decoder.h:34
static QStringList all()
Definition: decoder.cpp:76
AudioOutput * output()
Definition: decoder.h:77
static bool supports(const QString &)
Definition: decoder.cpp:89
virtual const QString & description() const =0
QString getURL(void) const
Definition: decoder.h:87
QString m_url
Definition: decoder.h:101
const QString & extension() const override
Definition: cddecoder.cpp:767
AudioOutput * m_out
Definition: decoder.h:106
bool supports(const QString &) const override
Definition: avfdecoder.cpp:590
MythEvent * clone(void) const override
Definition: decoder.h:44
virtual Decoder * create(const QString &, AudioOutput *, bool)=0
QMutex * getMutex(void)
Definition: decoder.h:98
void setURL(const QString &url)
Definition: decoder.h:79
virtual const QString & extension() const =0