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  explicit DecoderEvent(QString *e) : MythEvent(Error), m_errorMsg(e) { ; }
34 
35  ~DecoderEvent() override
36  {
37  delete m_errorMsg;
38  }
39 
40  const QString *errorMessage() const { return m_errorMsg; }
41 
42  MythEvent *clone(void) const override // MythEvent
43  { return new DecoderEvent(*this); }
44 
45  static Type Decoding;
46  static Type Stopped;
47  static Type Finished;
48  static Type Error;
49 
50  private:
52  {
53  if (o.m_errorMsg)
54  {
55  m_errorMsg = new QString(*o.m_errorMsg);
56  }
57  }
58 
59  // No implicit copying.
60  protected:
61  DecoderEvent &operator=(const DecoderEvent &other) = default;
62  public:
63  DecoderEvent(DecoderEvent &&) = delete;
64  DecoderEvent &operator=(DecoderEvent &&) = delete;
65 
66  private:
67  QString *m_errorMsg {nullptr};
68 };
69 
70 class Decoder : public MThread, public MythObservable
71 {
72  public:
73  ~Decoder() override;
74 
75  virtual bool initialize() = 0;
76  virtual void seek(double) = 0;
77  virtual void stop() = 0;
78 
79  DecoderFactory *factory() const { return m_fctry; }
80 
81  AudioOutput *output() { return m_out; }
82  void setOutput(AudioOutput *o);
83  void setURL(const QString &url) { m_url = url; }
84 
85  virtual void lock(void) { m_mtx.lock(); }
86  virtual void unlock(void) { m_mtx.unlock(); }
87  virtual bool tryLock(void) { return m_mtx.tryLock(); }
88 
89  QWaitCondition *cond() { return &m_cnd; }
90 
91  QString getURL(void) const { return m_url; }
92 
93  // static methods
94  static QStringList all();
95  static bool supports(const QString &source);
96  static void registerFactory(DecoderFactory *fact);
97  static Decoder *create(const QString &source, AudioOutput *output, bool deletable = false);
98 
99  protected:
101  : MThread("MythMusicDecoder"), m_fctry(d), m_out(o) {}
102  QMutex* getMutex(void) { return &m_mtx; }
103  void error(const QString &e);
104 
105  QString m_url;
106 
107  private:
109 
110  AudioOutput *m_out {nullptr};
111 
112  QMutex m_mtx;
113  QWaitCondition m_cnd;
114 
115 };
116 
118 {
119 public:
120  virtual bool supports(const QString &source) const = 0;
121  virtual const QString &extension() const = 0; // file extension, ie. ".mp3" or ".ogg"
122  virtual const QString &description() const = 0; // file type, ie. "MPEG Audio Files"
123  virtual Decoder *create(const QString &source, AudioOutput *output, bool deletable) = 0;
124  virtual ~DecoderFactory() = default;
125 };
126 
128 {
130 
131 public:
132  bool supports(const QString &source) const override; // DecoderFactory
133  const QString &extension() const override; // DecoderFactory
134  const QString &description() const override; // DecoderFactory
135  Decoder *create(const QString &file, AudioOutput *output, bool deletable) override; // DecoderFactory
136 };
137 
139 {
141 
142 public:
143  bool supports(const QString &source) const override; // DecoderFactory
144  const QString &extension() const override; // DecoderFactory
145  const QString &description() const override; // DecoderFactory
146  Decoder *create(const QString &file, AudioOutput *output, bool deletable) override; // DecoderFactory
147 };
148 
149 #endif
DecoderEvent::DecoderEvent
DecoderEvent(const DecoderEvent &o)
Definition: decoder.h:51
Decoder::~Decoder
~Decoder() override
Definition: decoder.cpp:33
Decoder::m_out
AudioOutput * m_out
Definition: decoder.h:110
DecoderFactory::supports
virtual bool supports(const QString &source) const =0
Decoder::m_mtx
QMutex m_mtx
Definition: decoder.h:112
DecoderEvent::clone
MythEvent * clone(void) const override
Definition: decoder.h:42
Decoder::factory
DecoderFactory * factory() const
Definition: decoder.h:79
OutputEvent
Definition: output.h:31
CdDecoderFactory::description
const QString & description() const override
Definition: cddecoder.cpp:701
MythObservable
Superclass for making an object have a set of listeners.
Definition: mythobservable.h:11
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
CdDecoderFactory::create
Decoder * create(const QString &file, AudioOutput *output, bool deletable) override
Definition: cddecoder.cpp:708
DecoderFactory::description
virtual const QString & description() const =0
MetaIO
Definition: metaio.h:17
DecoderEvent::Error
static Type Error
Definition: decoder.h:48
CdDecoderFactory::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(CdDecoderFactory)
MusicMetadata
Definition: musicmetadata.h:80
avfDecoderFactory::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(avfDecoderFactory)
DecoderFactory
Definition: decoder.h:117
build_compdb.file
file
Definition: build_compdb.py:55
Decoder::m_url
QString m_url
Definition: decoder.h:105
DecoderEvent::DecoderEvent
DecoderEvent(QString *e)
Definition: decoder.h:33
CdDecoderFactory
Definition: decoder.h:127
Decoder::tryLock
virtual bool tryLock(void)
Definition: decoder.h:87
Decoder::cond
QWaitCondition * cond()
Definition: decoder.h:89
AudioOutput
Definition: audiooutput.h:26
Decoder
Definition: decoder.h:70
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:86
avfDecoderFactory::supports
bool supports(const QString &source) const override
Definition: avfdecoder.cpp:585
DecoderEvent
Definition: decoder.h:29
Decoder::getMutex
QMutex * getMutex(void)
Definition: decoder.h:102
avfDecoderFactory::description
const QString & description() const override
Definition: avfdecoder.cpp:602
Decoder::m_cnd
QWaitCondition m_cnd
Definition: decoder.h:113
avfDecoderFactory
Definition: decoder.h:138
Decoder::stop
virtual void stop()=0
DecoderFactory::create
virtual Decoder * create(const QString &source, AudioOutput *output, bool deletable)=0
avfDecoderFactory::extension
const QString & extension() const override
Definition: avfdecoder.cpp:597
Decoder::getURL
QString getURL(void) const
Definition: decoder.h:91
DecoderEvent::Decoding
static Type Decoding
Definition: decoder.h:45
DecoderEvent::~DecoderEvent
~DecoderEvent() override
Definition: decoder.h:35
Decoder::setURL
void setURL(const QString &url)
Definition: decoder.h:83
DecoderEvent::Finished
static Type Finished
Definition: decoder.h:47
avfDecoderFactory::create
Decoder * create(const QString &file, AudioOutput *output, bool deletable) override
Definition: avfdecoder.cpp:608
Decoder::all
static QStringList all()
Definition: decoder.cpp:76
Decoder::error
void error(const QString &e)
Definition: decoder.cpp:53
CdDecoderFactory::supports
bool supports(const QString &source) const override
Definition: cddecoder.cpp:688
Decoder::initialize
virtual bool initialize()=0
DecoderEvent::operator=
DecoderEvent & operator=(const DecoderEvent &other)=default
DecoderEvent::Stopped
static Type Stopped
Definition: decoder.h:46
Buffer
Definition: MythExternControl.h:36
DecoderFactory::~DecoderFactory
virtual ~DecoderFactory()=default
Decoder::setOutput
void setOutput(AudioOutput *o)
Definition: decoder.cpp:46
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
DecoderFactory::extension
virtual const QString & extension() const =0
Decoder::supports
static bool supports(const QString &source)
Definition: decoder.cpp:86
Decoder::lock
virtual void lock(void)
Definition: decoder.h:85
DecoderEvent::DecoderEvent
DecoderEvent(Type type)
Definition: decoder.h:32
d
static const iso6937table * d
Definition: iso6937tables.cpp:1025
Decoder::registerFactory
static void registerFactory(DecoderFactory *fact)
Definition: decoder.cpp:95
Decoder::output
AudioOutput * output()
Definition: decoder.h:81
Decoder::seek
virtual void seek(double)=0
CdDecoderFactory::extension
const QString & extension() const override
Definition: cddecoder.cpp:694
output
#define output
Definition: synaesthesia.cpp:220
Decoder::Decoder
Decoder(DecoderFactory *d, AudioOutput *o)
Definition: decoder.h:100
DecoderEvent::m_errorMsg
QString * m_errorMsg
Definition: decoder.h:67
mythobservable.h
Decoder::m_fctry
DecoderFactory * m_fctry
Definition: decoder.h:108
DecoderEvent::errorMessage
const QString * errorMessage() const
Definition: decoder.h:40