Diffstat (limited to 'core/multimedia/opieplayer/mediaplayerstate.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp index 5bfb87e..b700cd1 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.cpp +++ b/core/multimedia/opieplayer/mediaplayerstate.cpp | |||
@@ -1,193 +1,197 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | ||
21 | #include <qpe/qlibrary.h> | ||
22 | #include <qpe/config.h> | ||
23 | #include <qdir.h> | ||
24 | #include <qpe/mediaplayerplugininterface.h> | ||
25 | #include "mediaplayerstate.h" | ||
26 | |||
27 | |||
28 | 20 | ||
29 | #ifdef QT_NO_COMPONENT | 21 | #ifdef QT_NO_COMPONENT |
30 | // Plugins which are compiled in when no plugin architecture available | 22 | // Plugins which are compiled in when no plugin architecture available |
31 | #include "libmad/libmadpluginimpl.h" | 23 | #include "libmad/libmadpluginimpl.h" |
32 | #include "libmpeg3/libmpeg3pluginimpl.h" | 24 | #include "libmpeg3/libmpeg3pluginimpl.h" |
33 | #include "wavplugin/wavpluginimpl.h" | 25 | #include "wavplugin/wavpluginimpl.h" |
34 | #endif | 26 | #endif |
35 | 27 | ||
28 | #include "mediaplayerstate.h" | ||
29 | |||
30 | /* OPIE */ | ||
31 | #include <qpe/qpeapplication.h> | ||
32 | #include <qpe/qlibrary.h> | ||
33 | #include <qpe/config.h> | ||
34 | #include <qpe/mediaplayerplugininterface.h> | ||
35 | #include <opie2/odebug.h> | ||
36 | |||
37 | /* QT */ | ||
38 | #include <qdir.h> | ||
39 | |||
36 | 40 | ||
37 | //#define MediaPlayerDebug(x) qDebug x | 41 | //#define MediaPlayerDebug(x) qDebug x |
38 | #define MediaPlayerDebug(x) | 42 | #define MediaPlayerDebug(x) |
39 | 43 | ||
40 | 44 | ||
41 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) | 45 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) |
42 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { | 46 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { |
43 | Config cfg( "OpiePlayer" ); | 47 | Config cfg( "OpiePlayer" ); |
44 | readConfig( cfg ); | 48 | readConfig( cfg ); |
45 | loadPlugins(); | 49 | loadPlugins(); |
46 | } | 50 | } |
47 | 51 | ||
48 | 52 | ||
49 | MediaPlayerState::~MediaPlayerState() { | 53 | MediaPlayerState::~MediaPlayerState() { |
50 | Config cfg( "OpiePlayer" ); | 54 | Config cfg( "OpiePlayer" ); |
51 | writeConfig( cfg ); | 55 | writeConfig( cfg ); |
52 | } | 56 | } |
53 | 57 | ||
54 | 58 | ||
55 | void MediaPlayerState::readConfig( Config& cfg ) { | 59 | void MediaPlayerState::readConfig( Config& cfg ) { |
56 | cfg.setGroup("Options"); | 60 | cfg.setGroup("Options"); |
57 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); | 61 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); |
58 | isScaled = cfg.readBoolEntry( "Scaling" ); | 62 | isScaled = cfg.readBoolEntry( "Scaling" ); |
59 | isLooping = cfg.readBoolEntry( "Looping" ); | 63 | isLooping = cfg.readBoolEntry( "Looping" ); |
60 | isShuffled = cfg.readBoolEntry( "Shuffle" ); | 64 | isShuffled = cfg.readBoolEntry( "Shuffle" ); |
61 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); | 65 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); |
62 | usePlaylist = TRUE; | 66 | usePlaylist = TRUE; |
63 | isPlaying = FALSE; | 67 | isPlaying = FALSE; |
64 | isPaused = FALSE; | 68 | isPaused = FALSE; |
65 | curPosition = 0; | 69 | curPosition = 0; |
66 | curLength = 0; | 70 | curLength = 0; |
67 | curView = 'l'; | 71 | curView = 'l'; |
68 | } | 72 | } |
69 | 73 | ||
70 | 74 | ||
71 | void MediaPlayerState::writeConfig( Config& cfg ) const { | 75 | void MediaPlayerState::writeConfig( Config& cfg ) const { |
72 | cfg.setGroup("Options"); | 76 | cfg.setGroup("Options"); |
73 | cfg.writeEntry("FullScreen", isFullscreen ); | 77 | cfg.writeEntry("FullScreen", isFullscreen ); |
74 | cfg.writeEntry("Scaling", isScaled ); | 78 | cfg.writeEntry("Scaling", isScaled ); |
75 | cfg.writeEntry("Looping", isLooping ); | 79 | cfg.writeEntry("Looping", isLooping ); |
76 | cfg.writeEntry("Shuffle", isShuffled ); | 80 | cfg.writeEntry("Shuffle", isShuffled ); |
77 | cfg.writeEntry("UsePlayList", usePlaylist ); | 81 | cfg.writeEntry("UsePlayList", usePlaylist ); |
78 | } | 82 | } |
79 | 83 | ||
80 | 84 | ||
81 | struct MediaPlayerPlugin { | 85 | struct MediaPlayerPlugin { |
82 | #ifndef QT_NO_COMPONENT | 86 | #ifndef QT_NO_COMPONENT |
83 | QLibrary *library; | 87 | QLibrary *library; |
84 | #endif | 88 | #endif |
85 | MediaPlayerPluginInterface *iface; | 89 | MediaPlayerPluginInterface *iface; |
86 | MediaPlayerDecoder *decoder; | 90 | MediaPlayerDecoder *decoder; |
87 | MediaPlayerEncoder *encoder; | 91 | MediaPlayerEncoder *encoder; |
88 | }; | 92 | }; |
89 | 93 | ||
90 | 94 | ||
91 | static QValueList<MediaPlayerPlugin> pluginList; | 95 | static QValueList<MediaPlayerPlugin> pluginList; |
92 | 96 | ||
93 | 97 | ||
94 | // Find the first decoder which supports this type of file | 98 | // Find the first decoder which supports this type of file |
95 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { | 99 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { |
96 | MediaPlayerDecoder *tmpDecoder = NULL; | 100 | MediaPlayerDecoder *tmpDecoder = NULL; |
97 | QValueList<MediaPlayerPlugin>::Iterator it; | 101 | QValueList<MediaPlayerPlugin>::Iterator it; |
98 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { | 102 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { |
99 | if ( (*it).decoder->isFileSupported( file ) ) { | 103 | if ( (*it).decoder->isFileSupported( file ) ) { |
100 | tmpDecoder = (*it).decoder; | 104 | tmpDecoder = (*it).decoder; |
101 | break; | 105 | break; |
102 | } | 106 | } |
103 | } | 107 | } |
104 | if(file.left(4)=="http") | 108 | if(file.left(4)=="http") |
105 | isStreaming = TRUE; | 109 | isStreaming = TRUE; |
106 | else | 110 | else |
107 | isStreaming = FALSE; | 111 | isStreaming = FALSE; |
108 | return decoder = tmpDecoder; | 112 | return decoder = tmpDecoder; |
109 | } | 113 | } |
110 | 114 | ||
111 | 115 | ||
112 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { | 116 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { |
113 | return decoder; | 117 | return decoder; |
114 | } | 118 | } |
115 | 119 | ||
116 | 120 | ||
117 | // ### hack to get true sample count | 121 | // ### hack to get true sample count |
118 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { | 122 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { |
119 | return libmpeg3decoder; | 123 | return libmpeg3decoder; |
120 | } | 124 | } |
121 | 125 | ||
122 | // ### hack to get true sample count | 126 | // ### hack to get true sample count |
123 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { | 127 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { |
124 | // return libwavdecoder; | 128 | // return libwavdecoder; |
125 | // } | 129 | // } |
126 | 130 | ||
127 | void MediaPlayerState::loadPlugins() { | 131 | void MediaPlayerState::loadPlugins() { |
128 | // qDebug("load plugins"); | 132 | // odebug << "load plugins" << oendl; |
129 | #ifndef QT_NO_COMPONENT | 133 | #ifndef QT_NO_COMPONENT |
130 | QValueList<MediaPlayerPlugin>::Iterator mit; | 134 | QValueList<MediaPlayerPlugin>::Iterator mit; |
131 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { | 135 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { |
132 | (*mit).iface->release(); | 136 | (*mit).iface->release(); |
133 | (*mit).library->unload(); | 137 | (*mit).library->unload(); |
134 | delete (*mit).library; | 138 | delete (*mit).library; |
135 | } | 139 | } |
136 | pluginList.clear(); | 140 | pluginList.clear(); |
137 | 141 | ||
138 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; | 142 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; |
139 | QDir dir( path, "lib*.so" ); | 143 | QDir dir( path, "lib*.so" ); |
140 | QStringList list = dir.entryList(); | 144 | QStringList list = dir.entryList(); |
141 | QStringList::Iterator it; | 145 | QStringList::Iterator it; |
142 | for ( it = list.begin(); it != list.end(); ++it ) { | 146 | for ( it = list.begin(); it != list.end(); ++it ) { |
143 | MediaPlayerPluginInterface *iface = 0; | 147 | MediaPlayerPluginInterface *iface = 0; |
144 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 148 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
145 | // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); | 149 | // odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl; |
146 | 150 | ||
147 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { | 151 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { |
148 | 152 | ||
149 | // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); | 153 | // odebug << "loading: " << QString( path + "/" + *it ) << "" << oendl; |
150 | 154 | ||
151 | MediaPlayerPlugin plugin; | 155 | MediaPlayerPlugin plugin; |
152 | plugin.library = lib; | 156 | plugin.library = lib; |
153 | plugin.iface = iface; | 157 | plugin.iface = iface; |
154 | plugin.decoder = plugin.iface->decoder(); | 158 | plugin.decoder = plugin.iface->decoder(); |
155 | plugin.encoder = plugin.iface->encoder(); | 159 | plugin.encoder = plugin.iface->encoder(); |
156 | pluginList.append( plugin ); | 160 | pluginList.append( plugin ); |
157 | 161 | ||
158 | // ### hack to get true sample count | 162 | // ### hack to get true sample count |
159 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) | 163 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) |
160 | libmpeg3decoder = plugin.decoder; | 164 | libmpeg3decoder = plugin.decoder; |
161 | 165 | ||
162 | } else { | 166 | } else { |
163 | delete lib; | 167 | delete lib; |
164 | } | 168 | } |
165 | } | 169 | } |
166 | #else | 170 | #else |
167 | pluginList.clear(); | 171 | pluginList.clear(); |
168 | 172 | ||
169 | MediaPlayerPlugin plugin0; | 173 | MediaPlayerPlugin plugin0; |
170 | plugin0.iface = new LibMpeg3PluginImpl; | 174 | plugin0.iface = new LibMpeg3PluginImpl; |
171 | plugin0.decoder = plugin0.iface->decoder(); | 175 | plugin0.decoder = plugin0.iface->decoder(); |
172 | plugin0.encoder = plugin0.iface->encoder(); | 176 | plugin0.encoder = plugin0.iface->encoder(); |
173 | pluginList.append( plugin0 ); | 177 | pluginList.append( plugin0 ); |
174 | 178 | ||
175 | MediaPlayerPlugin plugin1; | 179 | MediaPlayerPlugin plugin1; |
176 | plugin1.iface = new LibMadPluginImpl; | 180 | plugin1.iface = new LibMadPluginImpl; |
177 | plugin1.decoder = plugin1.iface->decoder(); | 181 | plugin1.decoder = plugin1.iface->decoder(); |
178 | plugin1.encoder = plugin1.iface->encoder(); | 182 | plugin1.encoder = plugin1.iface->encoder(); |
179 | pluginList.append( plugin1 ); | 183 | pluginList.append( plugin1 ); |
180 | 184 | ||
181 | MediaPlayerPlugin plugin2; | 185 | MediaPlayerPlugin plugin2; |
182 | plugin2.iface = new WavPluginImpl; | 186 | plugin2.iface = new WavPluginImpl; |
183 | plugin2.decoder = plugin2.iface->decoder(); | 187 | plugin2.decoder = plugin2.iface->decoder(); |
184 | plugin2.encoder = plugin2.iface->encoder(); | 188 | plugin2.encoder = plugin2.iface->encoder(); |
185 | pluginList.append( plugin2 ); | 189 | pluginList.append( plugin2 ); |
186 | #endif | 190 | #endif |
187 | 191 | ||
188 | if ( pluginList.count() ) | 192 | if ( pluginList.count() ) |
189 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); | 193 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); |
190 | else | 194 | else |
191 | MediaPlayerDebug(( "No decoders found" )); | 195 | MediaPlayerDebug(( "No decoders found" )); |
192 | } | 196 | } |
193 | 197 | ||