00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef QT_NO_COMPONENT
00022
00023 #include "libmad/libmadpluginimpl.h"
00024 #include "libmpeg3/libmpeg3pluginimpl.h"
00025 #include "wavplugin/wavpluginimpl.h"
00026 #endif
00027
00028 #include "mediaplayerstate.h"
00029
00030
00031 #include <qpe/qpeapplication.h>
00032 #include <qpe/qlibrary.h>
00033 #include <qpe/config.h>
00034 #include <qpe/mediaplayerplugininterface.h>
00035 #include <opie2/odebug.h>
00036
00037
00038 #include <qdir.h>
00039
00040
00041
00042 #define MediaPlayerDebug(x)
00043
00044
00045 MediaPlayerState::MediaPlayerState( QObject *parent, const char *name )
00046 : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) {
00047 Config cfg( "OpiePlayer" );
00048 readConfig( cfg );
00049 loadPlugins();
00050 }
00051
00052
00053 MediaPlayerState::~MediaPlayerState() {
00054 Config cfg( "OpiePlayer" );
00055 writeConfig( cfg );
00056 }
00057
00058
00059 void MediaPlayerState::readConfig( Config& cfg ) {
00060 cfg.setGroup("Options");
00061 isFullscreen = cfg.readBoolEntry( "FullScreen" );
00062 isScaled = cfg.readBoolEntry( "Scaling" );
00063 isLooping = cfg.readBoolEntry( "Looping" );
00064 isShuffled = cfg.readBoolEntry( "Shuffle" );
00065 usePlaylist = cfg.readBoolEntry( "UsePlayList" );
00066 usePlaylist = TRUE;
00067 isPlaying = FALSE;
00068 isPaused = FALSE;
00069 curPosition = 0;
00070 curLength = 0;
00071 curView = 'l';
00072 }
00073
00074
00075 void MediaPlayerState::writeConfig( Config& cfg ) const {
00076 cfg.setGroup("Options");
00077 cfg.writeEntry("FullScreen", isFullscreen );
00078 cfg.writeEntry("Scaling", isScaled );
00079 cfg.writeEntry("Looping", isLooping );
00080 cfg.writeEntry("Shuffle", isShuffled );
00081 cfg.writeEntry("UsePlayList", usePlaylist );
00082 }
00083
00084
00085 struct MediaPlayerPlugin {
00086 #ifndef QT_NO_COMPONENT
00087 QLibrary *library;
00088 #endif
00089 MediaPlayerPluginInterface *iface;
00090 MediaPlayerDecoder *decoder;
00091 MediaPlayerEncoder *encoder;
00092 };
00093
00094
00095 static QValueList<MediaPlayerPlugin> pluginList;
00096
00097
00098
00099 MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) {
00100 MediaPlayerDecoder *tmpDecoder = NULL;
00101 QValueList<MediaPlayerPlugin>::Iterator it;
00102 for ( it = pluginList.begin(); it != pluginList.end(); ++it ) {
00103 if ( (*it).decoder->isFileSupported( file ) ) {
00104 tmpDecoder = (*it).decoder;
00105 break;
00106 }
00107 }
00108 if(file.left(4)=="http")
00109 isStreaming = TRUE;
00110 else
00111 isStreaming = FALSE;
00112 return decoder = tmpDecoder;
00113 }
00114
00115
00116 MediaPlayerDecoder *MediaPlayerState::curDecoder() {
00117 return decoder;
00118 }
00119
00120
00121
00122 MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() {
00123 return libmpeg3decoder;
00124 }
00125
00126
00127
00128
00129
00130
00131 void MediaPlayerState::loadPlugins() {
00132
00133 #ifndef QT_NO_COMPONENT
00134 QValueList<MediaPlayerPlugin>::Iterator mit;
00135 for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) {
00136 (*mit).iface->release();
00137 (*mit).library->unload();
00138 delete (*mit).library;
00139 }
00140 pluginList.clear();
00141
00142 QString path = QPEApplication::qpeDir() + "plugins/codecs";
00143 QDir dir( path, "lib*.so" );
00144 QStringList list = dir.entryList();
00145 QStringList::Iterator it;
00146 for ( it = list.begin(); it != list.end(); ++it ) {
00147 MediaPlayerPluginInterface *iface = 0;
00148 QLibrary *lib = new QLibrary( path + "/" + *it );
00149
00150
00151 if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) {
00152
00153
00154
00155 MediaPlayerPlugin plugin;
00156 plugin.library = lib;
00157 plugin.iface = iface;
00158 plugin.decoder = plugin.iface->decoder();
00159 plugin.encoder = plugin.iface->encoder();
00160 pluginList.append( plugin );
00161
00162
00163 if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") )
00164 libmpeg3decoder = plugin.decoder;
00165
00166 } else {
00167 delete lib;
00168 }
00169 }
00170 #else
00171 pluginList.clear();
00172
00173 MediaPlayerPlugin plugin0;
00174 plugin0.iface = new LibMpeg3PluginImpl;
00175 plugin0.decoder = plugin0.iface->decoder();
00176 plugin0.encoder = plugin0.iface->encoder();
00177 pluginList.append( plugin0 );
00178
00179 MediaPlayerPlugin plugin1;
00180 plugin1.iface = new LibMadPluginImpl;
00181 plugin1.decoder = plugin1.iface->decoder();
00182 plugin1.encoder = plugin1.iface->encoder();
00183 pluginList.append( plugin1 );
00184
00185 MediaPlayerPlugin plugin2;
00186 plugin2.iface = new WavPluginImpl;
00187 plugin2.decoder = plugin2.iface->decoder();
00188 plugin2.encoder = plugin2.iface->encoder();
00189 pluginList.append( plugin2 );
00190 #endif
00191
00192 if ( pluginList.count() )
00193 MediaPlayerDebug(( "%i decoders found", pluginList.count() ));
00194 else
00195 MediaPlayerDebug(( "No decoders found" ));
00196 }
00197