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