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  DecoderEvent &operator=(const DecoderEvent&) = delete;
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_errorMsg)
56  {
57  m_errorMsg = new QString(*o.m_errorMsg);
58  }
59  }
60 
61  private:
62  QString *m_errorMsg {nullptr};
63 };
64 
65 class Decoder : public MThread, public MythObservable
66 {
67  public:
68  ~Decoder() override;
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 *o);
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 &source);
91  static void registerFactory(DecoderFactory *fact);
92  static Decoder *create(const QString &source, AudioOutput *output, bool deletable = 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 &e);
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 &source, AudioOutput *output, bool deletable) = 0;
119  virtual ~DecoderFactory() = default;
120 };
121 
123 {
125 
126 public:
127  bool supports(const QString &source) const override; // DecoderFactory
128  const QString &extension() const override; // DecoderFactory
129  const QString &description() const override; // DecoderFactory
130  Decoder *create(const QString &file, AudioOutput *output, bool deletable) override; // DecoderFactory
131 };
132 
134 {
136 
137 public:
138  bool supports(const QString &source) const override; // DecoderFactory
139  const QString &extension() const override; // DecoderFactory
140  const QString &description() const override; // DecoderFactory
141  Decoder *create(const QString &file, AudioOutput *output, bool deletable) override; // DecoderFactory
142 };
143 
144 #endif
DecoderEvent::DecoderEvent
DecoderEvent(const DecoderEvent &o)
Definition: decoder.h:53
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:1417
DecoderFactory::supports
virtual bool supports(const QString &source) const =0
Decoder::m_mtx
QMutex m_mtx
Definition: decoder.h:107
DecoderEvent::clone
MythEvent * clone(void) const override
Definition: decoder.h:44
Decoder::factory
DecoderFactory * factory() const
Definition: decoder.h:74
OutputEvent
Definition: output.h:30
CdDecoderFactory::description
const QString & description() const override
Definition: cddecoder.cpp:777
MythObservable
Superclass for making an object have a set of listeners.
Definition: mythobservable.h:12
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:17
CdDecoderFactory::create
Decoder * create(const QString &file, AudioOutput *output, bool deletable) override
Definition: cddecoder.cpp:784
DecoderFactory::description
virtual const QString & description() const =0
MetaIO
Definition: metaio.h:18
DecoderEvent::Error
static Type Error
Definition: decoder.h:50
CdDecoderFactory::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(CdDecoderFactory)
MusicMetadata
Definition: musicmetadata.h:81
avfDecoderFactory::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(avfDecoderFactory)
DecoderFactory
Definition: decoder.h:113
build_compdb.file
file
Definition: build_compdb.py:55
Decoder::m_url
QString m_url
Definition: decoder.h:100
DecoderEvent::DecoderEvent
DecoderEvent(QString *e)
Definition: decoder.h:33
CdDecoderFactory
Definition: decoder.h:123
Decoder::tryLock
virtual bool tryLock(void)
Definition: decoder.h:82
Decoder::cond
QWaitCondition * cond()
Definition: decoder.h:84
AudioOutput
Definition: audiooutput.h:26
Decoder
Definition: decoder.h:66
Decoder::create
static Decoder * create(const QString &source, AudioOutput *output, bool deletable=false)
Definition: decoder.cpp:106
Decoder::unlock
virtual void unlock(void)
Definition: decoder.h:81
avfDecoderFactory::supports
bool supports(const QString &source) const override
Definition: avfdecoder.cpp:582
DecoderEvent
Definition: decoder.h:30
Decoder::getMutex
QMutex * getMutex(void)
Definition: decoder.h:97
avfDecoderFactory::description
const QString & description() const override
Definition: avfdecoder.cpp:603
Decoder::m_cnd
QWaitCondition m_cnd
Definition: decoder.h:108
avfDecoderFactory
Definition: decoder.h:134
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:598
Decoder::getURL
QString getURL(void) const
Definition: decoder.h:86
DecoderEvent::Decoding
static Type Decoding
Definition: decoder.h:47
DecoderEvent::~DecoderEvent
~DecoderEvent() override
Definition: decoder.h:35
Decoder::setURL
void setURL(const QString &url)
Definition: decoder.h:78
DecoderEvent::Finished
static Type Finished
Definition: decoder.h:49
avfDecoderFactory::create
Decoder * create(const QString &file, AudioOutput *output, bool deletable) override
Definition: avfdecoder.cpp:609
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:764
Decoder::initialize
virtual bool initialize()=0
DecoderEvent::Stopped
static Type Stopped
Definition: decoder.h:48
Buffer
Definition: MythExternControl.h:37
DecoderFactory::~DecoderFactory
virtual ~DecoderFactory()=default
Decoder::setOutput
void setOutput(AudioOutput *o)
Definition: decoder.cpp:46
DecoderEvent::operator=
DecoderEvent & operator=(const DecoderEvent &)=delete
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
mthread.h
DecoderFactory::extension
virtual const QString & extension() const =0
Decoder::supports
static bool supports(const QString &source)
Definition: decoder.cpp:88
Decoder::lock
virtual void lock(void)
Definition: decoder.h:80
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:101
Decoder::output
AudioOutput * output()
Definition: decoder.h:76
Decoder::seek
virtual void seek(double)=0
CdDecoderFactory::extension
const QString & extension() const override
Definition: cddecoder.cpp:770
output
#define output
Definition: synaesthesia.cpp:221
Decoder::Decoder
Decoder(DecoderFactory *d, AudioOutput *o)
Definition: decoder.h:95
DecoderEvent::m_errorMsg
QString * m_errorMsg
Definition: decoder.h:62
mythobservable.h
Decoder::m_fctry
DecoderFactory * m_fctry
Definition: decoder.h:103
DecoderEvent::errorMessage
const QString * errorMessage() const
Definition: decoder.h:40