author | simon <simon> | 2002-12-11 14:25:49 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 14:25:49 (UTC) |
commit | 7a17954c26add31f28b69989f54e0f28a17c8949 (patch) (unidiff) | |
tree | 8603026771be07c996f49a29375fda64c8cd0e67 /noncore/multimedia/opieplayer2/lib.cpp | |
parent | 16138f0cdf46994d20ade71b5621b82fb9386933 (diff) | |
download | opie-7a17954c26add31f28b69989f54e0f28a17c8949.zip opie-7a17954c26add31f28b69989f54e0f28a17c8949.tar.gz opie-7a17954c26add31f28b69989f54e0f28a17c8949.tar.bz2 |
- roll back the threaded xine initialization, the mediaplayer initialization
state and the PlayButton change set
- instead load the audio-/video widget and the xine control on-demand. much
faster and much simpler for startup
Diffstat (limited to 'noncore/multimedia/opieplayer2/lib.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 92 |
1 files changed, 2 insertions, 90 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index 20fd1e2..1e0dc21 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -69,14 +69,12 @@ extern "C" { | |||
69 | } | 69 | } |
70 | 70 | ||
71 | using namespace XINE; | 71 | using namespace XINE; |
72 | 72 | ||
73 | Lib::Lib( XineVideoWidget* widget ) | 73 | Lib::Lib( XineVideoWidget* widget ) |
74 | { | 74 | { |
75 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
76 | m_initialized = false; | ||
77 | m_video = false; | 75 | m_video = false; |
78 | m_wid = widget; | 76 | m_wid = widget; |
79 | printf("Lib"); | 77 | printf("Lib"); |
80 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | 78 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; |
81 | // get the configuration | 79 | // get the configuration |
82 | 80 | ||
@@ -86,25 +84,14 @@ Lib::Lib( XineVideoWidget* widget ) | |||
86 | f.open(IO_WriteOnly); | 84 | f.open(IO_WriteOnly); |
87 | QTextStream ts( &f ); | 85 | QTextStream ts( &f ); |
88 | ts << "misc.memcpy_method:glibc\n"; | 86 | ts << "misc.memcpy_method:glibc\n"; |
89 | f.close(); | 87 | f.close(); |
90 | } | 88 | } |
91 | 89 | ||
92 | start(); | ||
93 | } | ||
94 | |||
95 | void Lib::run() | ||
96 | { | ||
97 | initialize(); | ||
98 | } | ||
99 | |||
100 | void Lib::initialize() | ||
101 | { | ||
102 | m_xine = xine_new( ); | 90 | m_xine = xine_new( ); |
103 | 91 | ||
104 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | ||
105 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); | 92 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); |
106 | 93 | ||
107 | xine_init( m_xine ); | 94 | xine_init( m_xine ); |
108 | 95 | ||
109 | // allocate oss for sound | 96 | // allocate oss for sound |
110 | // and fb for framebuffer | 97 | // and fb for framebuffer |
@@ -127,24 +114,15 @@ void Lib::initialize() | |||
127 | // m_wid->repaint(); | 114 | // m_wid->repaint(); |
128 | } | 115 | } |
129 | 116 | ||
130 | m_queue = xine_event_new_queue (m_stream); | 117 | m_queue = xine_event_new_queue (m_stream); |
131 | 118 | ||
132 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); | 119 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); |
133 | |||
134 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
135 | m_initialized = true; | ||
136 | |||
137 | send( new ThreadUtil::ChannelMessage( InitializationMessageType ), OneWay ); | ||
138 | } | 120 | } |
139 | 121 | ||
140 | Lib::~Lib() { | 122 | Lib::~Lib() { |
141 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
142 | |||
143 | assert( m_initialized ); | ||
144 | |||
145 | // free( m_config ); | 123 | // free( m_config ); |
146 | 124 | ||
147 | xine_close( m_stream ); | 125 | xine_close( m_stream ); |
148 | 126 | ||
149 | xine_event_dispose_queue( m_queue ); | 127 | xine_event_dispose_queue( m_queue ); |
150 | 128 | ||
@@ -153,23 +131,12 @@ Lib::~Lib() { | |||
153 | xine_exit( m_xine ); | 131 | xine_exit( m_xine ); |
154 | /* FIXME either free or delete but valgrind bitches against both */ | 132 | /* FIXME either free or delete but valgrind bitches against both */ |
155 | //free( m_videoOutput ); | 133 | //free( m_videoOutput ); |
156 | //delete m_audioOutput; | 134 | //delete m_audioOutput; |
157 | } | 135 | } |
158 | 136 | ||
159 | void Lib::assertInitialized() const | ||
160 | { | ||
161 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
162 | |||
163 | if ( m_initialized ) | ||
164 | return; | ||
165 | |||
166 | qDebug( "LibXine: xine function called while not being initialized, yet! Fix the caller!" ); | ||
167 | assert( m_initialized ); | ||
168 | } | ||
169 | |||
170 | void Lib::resize ( const QSize &s ) { | 137 | void Lib::resize ( const QSize &s ) { |
171 | if ( s. width ( ) && s. height ( ) ) { | 138 | if ( s. width ( ) && s. height ( ) ) { |
172 | ::null_set_gui_width( m_videoOutput, s. width() ); | 139 | ::null_set_gui_width( m_videoOutput, s. width() ); |
173 | ::null_set_gui_height( m_videoOutput, s. height() ); | 140 | ::null_set_gui_height( m_videoOutput, s. height() ); |
174 | } | 141 | } |
175 | } | 142 | } |
@@ -190,185 +157,132 @@ int Lib::subVersion() { | |||
190 | int major, minor, sub; | 157 | int major, minor, sub; |
191 | xine_get_version ( &major, &minor, &sub ); | 158 | xine_get_version ( &major, &minor, &sub ); |
192 | return sub; | 159 | return sub; |
193 | } | 160 | } |
194 | 161 | ||
195 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 162 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
196 | assertInitialized(); | ||
197 | |||
198 | QString str = fileName.stripWhiteSpace(); | 163 | QString str = fileName.stripWhiteSpace(); |
199 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { | 164 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { |
200 | return 0; | 165 | return 0; |
201 | } | 166 | } |
202 | return xine_play( m_stream, startPos, start_time); | 167 | return xine_play( m_stream, startPos, start_time); |
203 | } | 168 | } |
204 | 169 | ||
205 | void Lib::stop() { | 170 | void Lib::stop() { |
206 | assertInitialized(); | ||
207 | |||
208 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); | 171 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); |
209 | xine_stop( m_stream ); | 172 | xine_stop( m_stream ); |
210 | } | 173 | } |
211 | 174 | ||
212 | void Lib::pause( bool toggle ) { | 175 | void Lib::pause( bool toggle ) { |
213 | assertInitialized(); | ||
214 | |||
215 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); | 176 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); |
216 | } | 177 | } |
217 | 178 | ||
218 | int Lib::speed() const { | 179 | int Lib::speed() const { |
219 | assertInitialized(); | ||
220 | |||
221 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); | 180 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); |
222 | } | 181 | } |
223 | 182 | ||
224 | void Lib::setSpeed( int speed ) { | 183 | void Lib::setSpeed( int speed ) { |
225 | assertInitialized(); | ||
226 | |||
227 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); | 184 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); |
228 | } | 185 | } |
229 | 186 | ||
230 | int Lib::status() const { | 187 | int Lib::status() const { |
231 | assertInitialized(); | ||
232 | |||
233 | return xine_get_status( m_stream ); | 188 | return xine_get_status( m_stream ); |
234 | } | 189 | } |
235 | 190 | ||
236 | int Lib::currentPosition() const { | 191 | int Lib::currentPosition() const { |
237 | assertInitialized(); | ||
238 | |||
239 | int pos, time, length; | 192 | int pos, time, length; |
240 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 193 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
241 | return pos; | 194 | return pos; |
242 | } | 195 | } |
243 | 196 | ||
244 | int Lib::currentTime() const { | 197 | int Lib::currentTime() const { |
245 | assertInitialized(); | ||
246 | |||
247 | int pos, time, length; | 198 | int pos, time, length; |
248 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 199 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
249 | return time/1000; | 200 | return time/1000; |
250 | } | 201 | } |
251 | 202 | ||
252 | int Lib::length() const { | 203 | int Lib::length() const { |
253 | assertInitialized(); | ||
254 | |||
255 | int pos, time, length; | 204 | int pos, time, length; |
256 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 205 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
257 | return length/1000; | 206 | return length/1000; |
258 | } | 207 | } |
259 | 208 | ||
260 | bool Lib::isSeekable() const { | 209 | bool Lib::isSeekable() const { |
261 | assertInitialized(); | ||
262 | |||
263 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 210 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
264 | } | 211 | } |
265 | 212 | ||
266 | void Lib::seekTo( int time ) { | 213 | void Lib::seekTo( int time ) { |
267 | assertInitialized(); | ||
268 | |||
269 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( | 214 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( |
270 | // since its now milliseconds we need *1000 | 215 | // since its now milliseconds we need *1000 |
271 | xine_play( m_stream, 0, time*1000 ); | 216 | xine_play( m_stream, 0, time*1000 ); |
272 | } | 217 | } |
273 | 218 | ||
274 | 219 | ||
275 | Frame Lib::currentFrame() const { | 220 | Frame Lib::currentFrame() const { |
276 | assertInitialized(); | ||
277 | |||
278 | Frame frame; | 221 | Frame frame; |
279 | return frame; | 222 | return frame; |
280 | }; | 223 | }; |
281 | 224 | ||
282 | QString Lib::metaInfo( int number) const { | 225 | QString Lib::metaInfo( int number) const { |
283 | assertInitialized(); | ||
284 | |||
285 | return xine_get_meta_info( m_stream, number ); | 226 | return xine_get_meta_info( m_stream, number ); |
286 | } | 227 | } |
287 | 228 | ||
288 | int Lib::error() const { | 229 | int Lib::error() const { |
289 | assertInitialized(); | ||
290 | |||
291 | return xine_get_error( m_stream ); | 230 | return xine_get_error( m_stream ); |
292 | }; | 231 | }; |
293 | 232 | ||
294 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) | 233 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) |
295 | { | 234 | { |
296 | assert( sendType == ThreadUtil::Channel::OneWay ); | 235 | assert( sendType == ThreadUtil::Channel::OneWay ); |
297 | switch ( msg->type() ) { | 236 | handleXineEvent( msg->type() ); |
298 | case XineMessageType: | ||
299 | handleXineEvent( static_cast<XineMessage *>( msg )->xineEvent ); | ||
300 | break; | ||
301 | case InitializationMessageType: | ||
302 | emit initialized(); | ||
303 | break; | ||
304 | } | ||
305 | delete msg; | 237 | delete msg; |
306 | } | 238 | } |
307 | 239 | ||
308 | void Lib::handleXineEvent( const xine_event_t* t ) { | 240 | void Lib::handleXineEvent( const xine_event_t* t ) { |
309 | send( new XineMessage( t->type ), OneWay ); | 241 | send( new ThreadUtil::ChannelMessage( t->type ), OneWay ); |
310 | } | 242 | } |
311 | 243 | ||
312 | void Lib::handleXineEvent( int type ) { | 244 | void Lib::handleXineEvent( int type ) { |
313 | assertInitialized(); | ||
314 | |||
315 | if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { | 245 | if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { |
316 | emit stopped(); | 246 | emit stopped(); |
317 | } | 247 | } |
318 | } | 248 | } |
319 | 249 | ||
320 | 250 | ||
321 | void Lib::setShowVideo( bool video ) { | 251 | void Lib::setShowVideo( bool video ) { |
322 | assertInitialized(); | ||
323 | |||
324 | m_video = video; | 252 | m_video = video; |
325 | ::null_set_show_video( m_videoOutput, video ); | 253 | ::null_set_show_video( m_videoOutput, video ); |
326 | } | 254 | } |
327 | 255 | ||
328 | bool Lib::isShowingVideo() const { | 256 | bool Lib::isShowingVideo() const { |
329 | assertInitialized(); | ||
330 | |||
331 | return ::null_is_showing_video( m_videoOutput ); | 257 | return ::null_is_showing_video( m_videoOutput ); |
332 | } | 258 | } |
333 | 259 | ||
334 | bool Lib::hasVideo() const { | 260 | bool Lib::hasVideo() const { |
335 | assertInitialized(); | ||
336 | |||
337 | return xine_get_stream_info( m_stream, 18 ); | 261 | return xine_get_stream_info( m_stream, 18 ); |
338 | } | 262 | } |
339 | 263 | ||
340 | void Lib::showVideoFullScreen( bool fullScreen ) { | 264 | void Lib::showVideoFullScreen( bool fullScreen ) { |
341 | assertInitialized(); | ||
342 | |||
343 | ::null_set_fullscreen( m_videoOutput, fullScreen ); | 265 | ::null_set_fullscreen( m_videoOutput, fullScreen ); |
344 | } | 266 | } |
345 | 267 | ||
346 | bool Lib::isVideoFullScreen() const { | 268 | bool Lib::isVideoFullScreen() const { |
347 | assertInitialized(); | ||
348 | |||
349 | return ::null_is_fullscreen( m_videoOutput ); | 269 | return ::null_is_fullscreen( m_videoOutput ); |
350 | } | 270 | } |
351 | 271 | ||
352 | void Lib::setScaling( bool scale ) { | 272 | void Lib::setScaling( bool scale ) { |
353 | assertInitialized(); | ||
354 | |||
355 | ::null_set_scaling( m_videoOutput, scale ); | 273 | ::null_set_scaling( m_videoOutput, scale ); |
356 | } | 274 | } |
357 | 275 | ||
358 | void Lib::setGamma( int value ) { | 276 | void Lib::setGamma( int value ) { |
359 | assertInitialized(); | ||
360 | |||
361 | //qDebug( QString( "%1").arg(value) ); | 277 | //qDebug( QString( "%1").arg(value) ); |
362 | /* int gammaValue = ( 100 + value ); */ | 278 | /* int gammaValue = ( 100 + value ); */ |
363 | ::null_set_videoGamma( m_videoOutput, value ); | 279 | ::null_set_videoGamma( m_videoOutput, value ); |
364 | } | 280 | } |
365 | 281 | ||
366 | bool Lib::isScaling() const { | 282 | bool Lib::isScaling() const { |
367 | assertInitialized(); | ||
368 | |||
369 | return ::null_is_scaling( m_videoOutput ); | 283 | return ::null_is_scaling( m_videoOutput ); |
370 | } | 284 | } |
371 | 285 | ||
372 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | 286 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { |
373 | ( (Lib*)user_data)->handleXineEvent( t ); | 287 | ( (Lib*)user_data)->handleXineEvent( t ); |
374 | } | 288 | } |
@@ -376,14 +290,12 @@ void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | |||
376 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 290 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
377 | int width, int height, int bytes ) { | 291 | int width, int height, int bytes ) { |
378 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 292 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
379 | } | 293 | } |
380 | 294 | ||
381 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { | 295 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { |
382 | assertInitialized(); | ||
383 | |||
384 | if ( !m_video ) { | 296 | if ( !m_video ) { |
385 | qWarning("not showing video now"); | 297 | qWarning("not showing video now"); |
386 | return; | 298 | return; |
387 | } | 299 | } |
388 | m_wid-> setVideoFrame ( frame, width, height, bytes ); | 300 | m_wid-> setVideoFrame ( frame, width, height, bytes ); |
389 | } | 301 | } |