File indexing completed on 2024-05-12 08:50:26
0001 /* 0002 Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 0017 USA. 0018 */ 0019 0020 #ifndef AUDIOCD_ENCODER_H 0021 #define AUDIOCD_ENCODER_H 0022 0023 #include "audiocdplugins_export.h" 0024 0025 #include <KIO/WorkerBase> 0026 #include <QList> 0027 #include <QLoggingCategory> 0028 #include <sys/types.h> 0029 0030 #include <KCDDB/CDInfo> 0031 0032 Q_DECLARE_LOGGING_CATEGORY(AUDIOCD_KIO_LOG) 0033 0034 class KConfigSkeleton; 0035 using namespace KCDDB; 0036 0037 class AUDIOCDPLUGINS_EXPORT AudioCDEncoder { 0038 0039 public: 0040 /** 0041 * Constructor. 0042 * @param worker parent that this classes can use to call data() with 0043 * when finished encoding bits. 0044 */ 0045 explicit AudioCDEncoder(KIO::WorkerBase *worker) 0046 : ioWorker(worker) 0047 { 0048 } 0049 0050 /** 0051 * Destructor. 0052 */ 0053 virtual ~AudioCDEncoder() 0054 { 0055 } 0056 0057 /** 0058 * Initializes the decoder, loading libraries, etc. Encoders 0059 * that don't return true will will deleted and not used. 0060 * @returns false if unable to initialize the encoder. 0061 */ 0062 virtual bool init() = 0; 0063 0064 /** 0065 * The encoder should read in its config data here. 0066 */ 0067 virtual void loadSettings() = 0; 0068 0069 /** 0070 * Helper function to determine the end size of a 0071 * encoded file. 0072 * @param time_secs the length of the audio track in seconds. 0073 * @returns the size of a file if it is time_secs in length. 0074 */ 0075 virtual unsigned long size(long time_secs) const = 0; 0076 0077 /** 0078 * @returns the generic user string type/name of this encoder 0079 * Examples: "MP3", "Ogg Vorbis", "Wav", "FID Level 2", etc 0080 */ 0081 virtual QString type() const = 0; 0082 0083 /** 0084 * @returns the mime type for the files this encoder produces. 0085 * Example: "audio/x-wav" 0086 */ 0087 virtual const char *mimeType() const = 0; 0088 0089 /** 0090 * @returns the file type for the files this encoder produces. 0091 * Used in naming of the file for example foo.mp3 0092 * Examples: "mp3", "ogg", "wav" 0093 */ 0094 virtual const char *fileType() const = 0; 0095 0096 /** 0097 * Before the read functions are called this is 0098 * called to allow the encoders to store the cddb 0099 * information if they want to so it can be inserted 0100 * where necessary (start, middle, end, or combos etc). 0101 */ 0102 virtual void fillSongInfo(KCDDB::CDInfo info, int track, const QString &comment) = 0; 0103 0104 /** 0105 * Perform any initial file creation necessary for a new song (that 0106 * has just been sent via fillSongInfo()) 0107 * @param size - the total binary size of the end file (via size()). 0108 * @return size of the data that was created by this function. 0109 */ 0110 virtual long readInit(long size) = 0; 0111 0112 /** 0113 * Passes a little bit of cd data to be encoded 0114 * This function is most likely called many many times. 0115 * @param buf pointer to the audio that has been read in so far 0116 * @param frames the number of frames of audio that are in @p buf 0117 * @return size of the data that was created by this function, -1 on error. 0118 */ 0119 virtual long read(qint16 *buf, int frames) = 0; 0120 0121 /** 0122 * Perform any final file creation/padding that is necessary 0123 * @return size of the data that was created by this function. 0124 */ 0125 virtual long readCleanup() = 0; 0126 0127 /** 0128 * Returns a configure widget for the encoder 0129 */ 0130 virtual QWidget *getConfigureWidget(KConfigSkeleton **manager) const 0131 { 0132 Q_UNUSED(manager); 0133 return nullptr; 0134 } 0135 0136 /** 0137 * Returns the last error message; called when e.g. read() returns -1. 0138 */ 0139 virtual QString lastErrorMessage() const { return QString(); } 0140 0141 /** 0142 * Helper function to load all of the AudioCD Encoders from libraries. 0143 * Uses QLibraryInfo to find where libraries could be, opens all of the ones 0144 * that we might own audiocd_encoder_* and then uses the symbol 0145 * create_audiocd_encoders to obtain the encoders from that library. 0146 * @param worker Worker needed if the plugin is going to be used to encode 0147 * something. 0148 * @param encoders container for new encoders. 0149 */ 0150 static void findAllPlugins(KIO::WorkerBase *worker, QList<AudioCDEncoder *> &encoders); 0151 0152 protected: 0153 /** 0154 * Pointer to the ioWorker that is running this encoder. 0155 * Used (only?) for the data() function to pass back encoded data. 0156 */ 0157 KIO::WorkerBase *ioWorker; 0158 }; 0159 0160 #endif // AUDIOCD_ENCODER_H