-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimfroghelper.h
76 lines (58 loc) · 2.76 KB
/
optimfroghelper.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
/***************************************************************************
* This file is part of the TTK qmmp plugin project
* Copyright (C) 2015 - 2025 Greedysky Studio
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#ifndef OPTIMFROGHELPER_H
#define OPTIMFROGHELPER_H
#include <QMap>
#include <QFile>
#include <QLibrary>
#include <OptimFROG/OptimFROG.h>
/*!
* @author Greedysky <[email protected]>
*/
class OptimFROGHelper
{
public:
explicit OptimFROGHelper(QIODevice *input);
~OptimFROGHelper();
void deinit();
bool initialize();
void seek(qint64 time);
qint64 totalTime() const;
inline int bitrate() const { return m_info.bitrate; }
inline int sampleRate() const { return m_info.samplerate; }
inline int channels() const { return m_info.channels; }
inline int depth() const { return m_info.bitspersample; }
inline int version() const { return m_info.version; }
qint64 read(unsigned char *data, qint64 maxSize);
inline double compression() const { return 1000.0 * bitrate() / sampleRate() / channels() / depth(); }
inline bool hasTags() const { return !m_tags.isEmpty(); }
inline QString tag(const char *key) const { return m_tags[key]; }
private:
void *m_input = nullptr;
void *m_decoder = nullptr;
QLibrary *m_instance = nullptr;
OptimFROG_Info m_info;
bool m_signed = false;
QMap<QString, QString> m_tags;
static QIODevice *VFS(void *instance) { return reinterpret_cast<QIODevice *>(instance); }
static condition_t ofr_close(void *) { return true; }
static sInt32_t ofr_read(void *instance, void *buf, uInt32_t n) { return VFS(instance)->read(reinterpret_cast<char *>(buf), n); }
static condition_t ofr_eof(void *instance) { return VFS(instance)->atEnd(); }
static condition_t ofr_seekable(void *instance) { return !VFS(instance)->isSequential(); }
static sInt64_t ofr_length(void *instance) { return VFS(instance)->size(); }
static sInt64_t ofr_get_pos(void *instance) { return VFS(instance)->pos(); }
static condition_t ofr_seek(void *instance, sInt64_t offset) { return VFS(instance)->seek(offset); }
};
#endif