Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mediaplayerstate.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002  ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003  **
00004  ** This file is part of Qtopia Environment.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  **
00014  ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015  **
00016  ** Contact info@trolltech.com if any conditions of this licensing are
00017  ** not clear to you.
00018  **
00019  **********************************************************************/
00020 
00021 #ifdef QT_NO_COMPONENT
00022 // Plugins which are compiled in when no plugin architecture available
00023 #include "libmad/libmadpluginimpl.h"
00024 #include "libmpeg3/libmpeg3pluginimpl.h"
00025 #include "wavplugin/wavpluginimpl.h"
00026 #endif
00027 
00028 #include "mediaplayerstate.h"
00029 
00030 /* OPIE */
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 /* QT */
00038 #include <qdir.h>
00039 
00040 
00041 //#define MediaPlayerDebug(x) qDebug x
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 // Find the first decoder which supports this type of file
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 // ### hack to get true sample count
00122 MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() {
00123     return libmpeg3decoder;
00124 }
00125 
00126 // ### hack to get true sample count
00127 // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() {
00128 //     return libwavdecoder;
00129 // }
00130 
00131 void MediaPlayerState::loadPlugins() {
00132    //    odebug << "load plugins" << oendl;
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 //   odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl;
00150 
00151         if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) {
00152 
00153 //       odebug << "loading: " << QString( path + "/" + *it ) << "" << oendl;
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               // ### hack to get true sample count
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 

Generated on Sat Nov 5 16:15:38 2005 for OPIE by  doxygen 1.4.2