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  delete m_error_msg;
39  }
40 
41  const QString *errorMessage() const { return m_error_msg; }
42 
43  MythEvent *clone(void) const override // MythEvent
44  { return new DecoderEvent(*this); }
45 
46  static Type Decoding;
47  static Type Stopped;
48  static Type Finished;
49  static Type Error;
50 
51  private:
53  {
54  if (o.m_error_msg)
55  {
56  m_error_msg = new QString(*o.m_error_msg);
57  }
58  }
60 
61  private:
62  QString *m_error_msg {nullptr};
63 };
64 
65 class Decoder : public MThread, public MythObservable
66 {
67  public:
68  virtual ~Decoder();
69 
70  virtual bool initialize() = 0;
71  virtual void seek(double) = 0;
72  virtual void stop() = 0;
73 
74  DecoderFactory *factory() const { return m_fctry; }
75 
76  AudioOutput *output() { return m_out; }
77  void setOutput(AudioOutput *);
78  void setURL(const QString &url) { m_url = url; }
79 
80  virtual void lock(void) { return m_mtx.lock(); }
81  virtual void unlock(void) { return m_mtx.unlock(); }
82  virtual bool tryLock(void) { return m_mtx.tryLock(); }
83 
84  QWaitCondition *cond() { return &m_cnd; }
85 
86  QString getURL(void) const { return m_url; }
87 
88  // static methods
89  static QStringList all();
90  static bool supports(const QString &);
91  static void registerFactory(DecoderFactory *);
92  static Decoder *create(const QString &, AudioOutput *, bool = false);
93 
94  protected:
96  : MThread("MythMusicDecoder"), m_fctry(d), m_out(o) {}
97  QMutex* getMutex(void) { return &m_mtx; }
98  void error(const QString &);
99 
100  QString m_url;
101 
102  private:
104 
105  AudioOutput *m_out {nullptr};
106 
107  QMutex m_mtx;
108  QWaitCondition m_cnd;
109 
110 };
111 
113 {
114 public:
115  virtual bool supports(const QString &source) const = 0;
116  virtual const QString &extension() const = 0; // file extension, ie. ".mp3" or ".ogg"
117  virtual const QString &description() const = 0; // file type, ie. "MPEG Audio Files"
118  virtual Decoder *create(const QString &, AudioOutput *, bool) = 0;
119  virtual ~DecoderFactory() = default;
120 };
121 
123 {
125 
126 public:
127  bool supports(const QString &) const override; // DecoderFactory
128  const QString &extension() const override; // DecoderFactory
129  const QString &description() const override; // DecoderFactory
130  Decoder *create(const QString &, AudioOutput *, bool) override; // DecoderFactory
131 };
132 
134 {
136 
137 public:
138  bool supports(const QString &) const override; // DecoderFactory
139  const QString &extension() const override; // DecoderFactory
140  const QString &description() const override; // DecoderFactory
141  Decoder *create(const QString &, AudioOutput *, bool) override; // DecoderFactory
142 };
143 
144 #endif
~DecoderEvent()
Definition: decoder.h:36
QString * m_error_msg
Definition: decoder.h:62
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:48
Q_DECLARE_TR_FUNCTIONS(avfDecoderFactory)
DecoderFactory * factory() const
Definition: decoder.h:74
static Type Decoding
Definition: decoder.h:46
virtual ~Decoder()
Definition: decoder.cpp:33
virtual void unlock(void)
Definition: decoder.h:81
const QString * errorMessage() const
Definition: decoder.h:41
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:95
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:80
static Type Error
Definition: decoder.h:49
This class is used as a container for messages.
Definition: mythevent.h:16
virtual bool tryLock(void)
Definition: decoder.h:82
virtual bool initialize()=0
QWaitCondition m_cnd
Definition: decoder.h:108
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:103
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:47
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:52
QWaitCondition * cond()
Definition: decoder.h:84
virtual void seek(double)=0
DecoderEvent(Type type)
Definition: decoder.h:32
virtual void stop()=0
QMutex m_mtx
Definition: decoder.h:107
DecoderEvent(QString *e)
Definition: decoder.h:34
static QStringList all()
Definition: decoder.cpp:76
AudioOutput * output()
Definition: decoder.h:76
static bool supports(const QString &)
Definition: decoder.cpp:89
virtual const QString & description() const =0
QString getURL(void) const
Definition: decoder.h:86
QString m_url
Definition: decoder.h:100
const QString & extension() const override
Definition: cddecoder.cpp:767
AudioOutput * m_out
Definition: decoder.h:105
bool supports(const QString &) const override
Definition: avfdecoder.cpp:590
MythEvent * clone(void) const override
Definition: decoder.h:43
virtual Decoder * create(const QString &, AudioOutput *, bool)=0
QMutex * getMutex(void)
Definition: decoder.h:97
void setURL(const QString &url)
Definition: decoder.h:78
virtual const QString & extension() const =0