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
|
/*************************************************************************
CodecPlugin.h - base class for codec plugins
-------------------
begin : Fri Dec 28 2012
copyright : (C) 2012 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CODEC_PLUGIN_H
#define CODEC_PLUGIN_H
#include "config.h"
#include "libkwave_export.h"
#include <QtGlobal>
#include <QList>
#include "libkwave/Plugin.h"
namespace Kwave
{
class Decoder;
class Encoder;
class LIBKWAVE_EXPORT CodecPlugin: public Kwave::Plugin
{
public:
/** container for codecs */
typedef struct {
int m_use_count; /**< use count */
QList<Kwave::Encoder *> m_encoder; /**< list of encoders */
QList<Kwave::Decoder *> m_decoder; /**< list of decoders */
} Codec;
/**
* Constructor
* @param parent pointer to the corresponding plugin manager
* @param args argument list, containts internal meta data
* @param codec reference to a static container for the codec
*/
CodecPlugin(QObject *parent, const QVariantList &args, Codec &codec);
/** Destructor */
~CodecPlugin() override;
/**
* Gets called when the plugin is first loaded. Registers new encoder
* and decoder on first call, all subsequenct calls only increment
* the reference count of the existing encoder/decoder instances.
*/
void load(QStringList &/* params */) override;
/**
* Gets called before the plugin is unloaded. Decrements the use count
* of existing encoder/decoder instances and removes them if zero
* gets reached.
*/
void unload() override;
/**
* Create a new set of decoders
* @return list of decoders, may be empty
*/
virtual QList<Kwave::Decoder *> createDecoder() = 0;
/**
* Create a new set of encoders
* @return list of encoders, may be empty
*/
virtual QList<Kwave::Encoder *> createEncoder() = 0;
protected:
/**
* helper template to return a list with a single decoder,
* for use within createDecoder()
*/
template<class T> QList<Kwave::Decoder *> singleDecoder()
{
QList<Kwave::Decoder *> list;
list.append(new(std::nothrow) T);
return list;
}
/**
* helper template to return a list with a single encoder,
* for use within createEncoder()
*/
template<class T> QList<Kwave::Encoder *> singleEncoder()
{
QList<Kwave::Encoder *> list;
list.append(new(std::nothrow) T);
return list;
}
private:
/** reference to the static container with encoder/decoder/usecount */
Codec &m_codec;
};
}
/** initializer for an empty Kwave::CodecPlugin::Codec */
#define EMPTY_CODEC {0, QList<Kwave::Encoder *>(), QList<Kwave::Decoder *>() }
#endif /* CODEC_PLUGIN_H */
//***************************************************************************
//***************************************************************************
|