Debian Codegraph @

plugins/audiocdencoder.h

raw
1 /*
2 Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA.
18 */
19
20 #ifndef AUDIOCD_ENCODER_H
21 #define AUDIOCD_ENCODER_H
22
23 #include "audiocdplugins_export.h"
24
25 #include <KIO/WorkerBase>
26 #include <QList>
27 #include <QLoggingCategory>
28 #include <sys/types.h>
29
30 #include <KCDDB/CDInfo>
31
32 Q_DECLARE_LOGGING_CATEGORY(AUDIOCD_KIO_LOG)
33
34 class KConfigSkeleton;
35 using namespace KCDDB;
36
37 class AUDIOCDPLUGINS_EXPORT AudioCDEncoder
38 {
39 public:
40 /**
41 * Constructor.
42 * @param worker parent that this classes can use to call data() with
43 * when finished encoding bits.
44 */
45 explicit AudioCDEncoder(KIO::WorkerBase *worker)
46 : ioWorker(worker)
47 {
48 }
49
50 /**
51 * Destructor.
52 */
53 virtual ~AudioCDEncoder()
54 {
55 }
56
57 /**
58 * Initializes the decoder, loading libraries, etc. Encoders
59 * that don't return true will will deleted and not used.
60 * @returns false if unable to initialize the encoder.
61 */
62 virtual bool init() = 0;
63
64 /**
65 * The encoder should read in its config data here.
66 */
67 virtual void loadSettings() = 0;
68
69 /**
70 * Helper function to determine the end size of a
71 * encoded file.
72 * @param time_secs the length of the audio track in seconds.
73 * @returns the size of a file if it is time_secs in length.
74 */
75 virtual unsigned long size(long time_secs) const = 0;
76
77 /**
78 * @returns the generic user string type/name of this encoder
79 * Examples: "MP3", "Ogg Vorbis", "Wav", "FID Level 2", etc
80 */
81 virtual QString type() const = 0;
82
83 /**
84 * @returns the mime type for the files this encoder produces.
85 * Example: "audio/x-wav"
86 */
87 virtual const char *mimeType() const = 0;
88
89 /**
90 * @returns the file type for the files this encoder produces.
91 * Used in naming of the file for example foo.mp3
92 * Examples: "mp3", "ogg", "wav"
93 */
94 virtual const char *fileType() const = 0;
95
96 /**
97 * Before the read functions are called this is
98 * called to allow the encoders to store the cddb
99 * information if they want to so it can be inserted
100 * where necessary (start, middle, end, or combos etc).
101 */
102 virtual void fillSongInfo(KCDDB::CDInfo info, int track, const QString &comment) = 0;
103
104 /**
105 * Perform any initial file creation necessary for a new song (that
106 * has just been sent via fillSongInfo())
107 * @param size - the total binary size of the end file (via size()).
108 * @return size of the data that was created by this function.
109 */
110 virtual long readInit(long size) = 0;
111
112 /**
113 * Passes a little bit of cd data to be encoded
114 * This function is most likely called many many times.
115 * @param buf pointer to the audio that has been read in so far
116 * @param frames the number of frames of audio that are in @p buf
117 * @return size of the data that was created by this function, -1 on error.
118 */
119 virtual long read(qint16 *buf, int frames) = 0;
120
121 /**
122 * Perform any final file creation/padding that is necessary
123 * @return size of the data that was created by this function.
124 */
125 virtual long readCleanup() = 0;
126
127 /**
128 * Returns a configure widget for the encoder
129 */
130 virtual QWidget *getConfigureWidget(KConfigSkeleton **manager) const
131 {
132 Q_UNUSED(manager);
133 return nullptr;
134 }
135
136 /**
137 * Returns the last error message; called when e.g. read() returns -1.
138 */
139 virtual QString lastErrorMessage() const
140 {
141 return QString();
142 }
143
144 /**
145 * Helper function to load all of the AudioCD Encoders from libraries.
146 * Uses QLibraryInfo to find where libraries could be, opens all of the ones
147 * that we might own audiocd_encoder_* and then uses the symbol
148 * create_audiocd_encoders to obtain the encoders from that library.
149 * @param worker Worker needed if the plugin is going to be used to encode
150 * something.
151 * @param encoders container for new encoders.
152 */
153 static void findAllPlugins(KIO::WorkerBase *worker, QList<AudioCDEncoder *> &encoders);
154
155 protected:
156 /**
157 * Pointer to the ioWorker that is running this encoder.
158 * Used (only?) for the data() function to pass back encoded data.
159 */
160 KIO::WorkerBase *ioWorker;
161 };
162
163 #endif // AUDIOCD_ENCODER_H