Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

Tutorial: Creating Plugin For Cruxus Engine

The Cruxus engine is a media engine created specifically for Qt Extended. Many plugins for this media engine already exist in the src/plugins/codecs and src/3rdparty/plugins/codecs directories including libmad (mp3), libtimidity (mid), tremor (ogg), wavplay (wav). To build using the cruxus engine use -mediaengines cruxus on the configure line to enable. Cruxus plugins are enabled and disabled by modifying src/general.pri and commenting or uncommenting before configuration.

NOTE: plugin codecs not provided in the source code can be obtained from qtextended.org.

It is also possible to build with multiple engines and the priority of use is determined by the order they appear in the configure line.

-mediaengines cruxus,helix,gstreamer

The following is the wav plugin used by cruxus for wav playback.

The basic process is as follows:

connectToInput(input) will be called to connect to the input stream.

The start() function of the QMediaDecoder is called this should start reading from the input stream and work out the playback parameter like frequency, channels and emit the signals lengthChanged(d->length), readyRead() and playerStateChanged(QtopiaMedia::Playing)

readData() function will be called to read and decode the input stream data emitting positionChanged(d->position) when needed.

Other functions required to be implemented are disconnectFromInput(), stop(), pause(), length(), seek(), setVolume(), volume(), setMuted(), isMuted().

plugins/codecs/wavplay/wavplugin.h

QMediaCodecPlugin Class Definition for wavplay

    class WavPluginPrivate;

    class WavPlugin :
        public QObject,
        public QMediaCodecPlugin
    {
        Q_OBJECT
        Q_INTERFACES(QMediaCodecPlugin)

    public:
        WavPlugin();
        ~WavPlugin();

        QString name() const;
        QString comment() const;
        QStringList mimeTypes() const;
        QStringList fileExtensions() const;

        double version() const;

        bool canEncode() const;
        bool canDecode() const;

        QMediaEncoder* encoder(QString const& mimeType);
        QMediaDecoder* decoder(QString const& mimeType);

    private:
        WavPluginPrivate*  d;
    };

plugins/codecs/wavplay/wavplugin.cpp

QMediaCodecPlugin Class Code for wavplay

see also QMediaCodecPlugin plugins/codecs/wavplay/wavplugin.cpp is an implementation of this class.

plugins/codecs/wavplay/wavdecoder.h

QMediaDecoder Class Definition for wavplay

    class WavDecoderPrivate;

    class WavDecoder : public QMediaDecoder
    {
        Q_OBJECT

    public:
        WavDecoder();
        ~WavDecoder();

        QMediaDevice::Info const& dataType() const;

        bool connectToInput(QMediaDevice* input);
        void disconnectFromInput(QMediaDevice* input);

        void start();
        void stop();
        void pause();

        quint64 length();
        bool seek(qint64 ms);

        void setVolume(int volume);
        int volume();

        void setMuted(bool mute);
        bool isMuted();

    private:
        qint64 readData(char *data, qint64 maxlen);
        qint64 writeData(const char *data, qint64 len);

        WavDecoderPrivate* d;
    };

plugins/codecs/wavplay/wavdecoder.cpp

QMediaDecoder Class Code for wavplay

see also QMediaDecoder plugins/codecs/wavplay/wavdecoder.cpp is an implementation of this class.

Creating a new Cruxus plugin

Copy an existing plugin to use as a template.

  1. Create a new directory (eg. $HOME/src/libblah) and copy all the wavplay files to that directory.
        mkdir $HOME/src/libblah
        cd $HOME/src/libblah
        cp -r <qt-extended-source-directory>/src/plugins/codecs/wavplay/* .
        chmod +w *

    Edit and change name accordingly, replace functionality of each function accordingly (look at the many examples available already).

  2. Build the new application.
        export QPEDIR=<qt-extended-build-directory>
        $QPEDIR/bin/qbuild
        $QPEDIR/bin/qbuild image
  3. Run Qt Extended.
        $QPEDIR/bin/runqtopia
  4. Try playing media file that your codec decodes.


Copyright © 2009 Nokia Trademarks
Qt Extended 4.4.3