summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/mediaplayerstate.cpp
blob: b700cd1cd1efef02aba927cbe94fb2fc5d730a2d (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**********************************************************************
 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
 **
 ** This file is part of Qtopia Environment.
 **
 ** This file may be distributed and/or modified under the terms of the
 ** GNU General Public License version 2 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.GPL included in the
 ** packaging of this file.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
 **
 ** Contact info@trolltech.com if any conditions of this licensing are
 ** not clear to you.
 **
 **********************************************************************/

#ifdef QT_NO_COMPONENT
// Plugins which are compiled in when no plugin architecture available
#include "libmad/libmadpluginimpl.h"
#include "libmpeg3/libmpeg3pluginimpl.h"
#include "wavplugin/wavpluginimpl.h"
#endif

#include "mediaplayerstate.h"

/* OPIE */
#include <qpe/qpeapplication.h>
#include <qpe/qlibrary.h>
#include <qpe/config.h>
#include <qpe/mediaplayerplugininterface.h>
#include <opie2/odebug.h>

/* QT */
#include <qdir.h>


//#define MediaPlayerDebug(x) qDebug x
#define MediaPlayerDebug(x)


MediaPlayerState::MediaPlayerState( QObject *parent, const char *name )
        : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) {
    Config cfg( "OpiePlayer" );
    readConfig( cfg );
    loadPlugins();
}


MediaPlayerState::~MediaPlayerState() {
    Config cfg( "OpiePlayer" );
    writeConfig( cfg );
}


void MediaPlayerState::readConfig( Config& cfg ) {
    cfg.setGroup("Options");
    isFullscreen = cfg.readBoolEntry( "FullScreen" );
    isScaled = cfg.readBoolEntry( "Scaling" );
    isLooping = cfg.readBoolEntry( "Looping" );
    isShuffled = cfg.readBoolEntry( "Shuffle" );
    usePlaylist = cfg.readBoolEntry( "UsePlayList" );
    usePlaylist = TRUE;
    isPlaying = FALSE;
    isPaused = FALSE;
    curPosition = 0;
    curLength = 0;
    curView = 'l';
}


void MediaPlayerState::writeConfig( Config& cfg ) const {
    cfg.setGroup("Options");
    cfg.writeEntry("FullScreen", isFullscreen );
    cfg.writeEntry("Scaling", isScaled );
    cfg.writeEntry("Looping", isLooping );
    cfg.writeEntry("Shuffle", isShuffled );
    cfg.writeEntry("UsePlayList", usePlaylist );
}


struct MediaPlayerPlugin {
#ifndef QT_NO_COMPONENT
    QLibrary *library;
#endif
    MediaPlayerPluginInterface *iface;
    MediaPlayerDecoder *decoder;
    MediaPlayerEncoder *encoder;
};


static QValueList<MediaPlayerPlugin> pluginList;


// Find the first decoder which supports this type of file
MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) {
    MediaPlayerDecoder *tmpDecoder = NULL;
    QValueList<MediaPlayerPlugin>::Iterator it;
    for ( it = pluginList.begin(); it != pluginList.end(); ++it ) {
        if ( (*it).decoder->isFileSupported( file ) ) {
            tmpDecoder = (*it).decoder;
            break;
        }
    }
    if(file.left(4)=="http")
        isStreaming = TRUE;
    else
        isStreaming = FALSE;
    return decoder = tmpDecoder;
}


MediaPlayerDecoder *MediaPlayerState::curDecoder() {
    return decoder;
}


// ### hack to get true sample count
MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() {
    return libmpeg3decoder;
}

// ### hack to get true sample count
// MediaPlayerDecoder *MediaPlayerState::libWavDecoder() {
//     return libwavdecoder;
// }

void MediaPlayerState::loadPlugins() {
   //    odebug << "load plugins" << oendl;
#ifndef QT_NO_COMPONENT
    QValueList<MediaPlayerPlugin>::Iterator mit;
    for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) {
        (*mit).iface->release();
        (*mit).library->unload();
        delete (*mit).library;
    }
    pluginList.clear();

    QString path = QPEApplication::qpeDir() + "/plugins/codecs";
    QDir dir( path, "lib*.so" );
    QStringList list = dir.entryList();
    QStringList::Iterator it;
    for ( it = list.begin(); it != list.end(); ++it ) {
        MediaPlayerPluginInterface *iface = 0;
        QLibrary *lib = new QLibrary( path + "/" + *it );
//   odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl;

        if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) {

//       odebug << "loading: " << QString( path + "/" + *it ) << "" << oendl;

            MediaPlayerPlugin plugin;
            plugin.library = lib;
            plugin.iface = iface;
            plugin.decoder = plugin.iface->decoder();
            plugin.encoder = plugin.iface->encoder();
            pluginList.append( plugin );

              // ### hack to get true sample count
            if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") )
                libmpeg3decoder = plugin.decoder;

        } else {
            delete lib;
        }
    }
#else
    pluginList.clear();

    MediaPlayerPlugin plugin0;
    plugin0.iface = new LibMpeg3PluginImpl;
    plugin0.decoder = plugin0.iface->decoder();
    plugin0.encoder = plugin0.iface->encoder();
    pluginList.append( plugin0 );

    MediaPlayerPlugin plugin1;
    plugin1.iface = new LibMadPluginImpl;
    plugin1.decoder = plugin1.iface->decoder();
    plugin1.encoder = plugin1.iface->encoder();
    pluginList.append( plugin1 );

    MediaPlayerPlugin plugin2;
    plugin2.iface = new WavPluginImpl;
    plugin2.decoder = plugin2.iface->decoder();
    plugin2.encoder = plugin2.iface->encoder();
    pluginList.append( plugin2 );
#endif

    if ( pluginList.count() )
        MediaPlayerDebug(( "%i decoders found", pluginList.count() ));
    else
        MediaPlayerDebug(( "No decoders found" ));
}