summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index cb8de8a..4b2827e 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -176,120 +176,119 @@ void LoopControl::setPosition( long pos ) {
176 currentSample = pos + 1; 176 currentSample = pos + 1;
177 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 177 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
178 audioSampleCounter = currentSample - 1; 178 audioSampleCounter = currentSample - 1;
179 } 179 }
180 180
181 audioMutex->unlock(); 181 audioMutex->unlock();
182} 182}
183 183
184 184
185void LoopControl::startVideo() { 185void LoopControl::startVideo() {
186 186
187 if ( moreVideo ) { 187 if ( moreVideo ) {
188 188
189 if ( mediaPlayerState->curDecoder() ) { 189 if ( mediaPlayerState->curDecoder() ) {
190 190
191 if ( hasAudioChannel && !isMuted ) { 191 if ( hasAudioChannel && !isMuted ) {
192 192
193 current_frame = long( playtime.elapsed() * framerate / 1000 ); 193 current_frame = long( playtime.elapsed() * framerate / 1000 );
194 194
195 if ( prev_frame != -1 && current_frame <= prev_frame ) 195 if ( prev_frame != -1 && current_frame <= prev_frame )
196 return; 196 return;
197 197
198 } else { 198 } else {
199 // Don't skip 199 // Don't skip
200 current_frame++; 200 current_frame++;
201 } 201 }
202 202
203 if ( prev_frame == -1 || current_frame > prev_frame ) { 203 if ( prev_frame == -1 || current_frame > prev_frame ) {
204 if ( current_frame > prev_frame + 1 ) { 204 if ( current_frame > prev_frame + 1 ) {
205 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 205 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
206 } 206 }
207 moreVideo = videoUI->playVideo(); 207 moreVideo = videoUI->playVideo();
208 prev_frame = current_frame; 208 prev_frame = current_frame;
209 } 209 }
210 210
211 } else { 211 } else {
212 212
213 moreVideo = FALSE; 213 moreVideo = FALSE;
214 killTimer( videoId ); 214 killTimer( videoId );
215 215
216 } 216 }
217 217
218 } 218 }
219} 219}
220 220
221 221
222void LoopControl::startAudio() { 222void LoopControl::startAudio() {
223 223
224//qDebug("start audio");
225 audioMutex->lock(); 224 audioMutex->lock();
226 if ( moreAudio ) { 225 if ( moreAudio ) {
227 226
228 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
229 228
230 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
231 230
232 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
233 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
234 233
235 long samplesRead = 0; 234 long samplesRead = 0;
236 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
237 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
238 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
239 238
240// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
241// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
242// } 241// }
243// else if ( sampleWaitTime <= -5000 ) { 242// else if ( sampleWaitTime <= -5000 ) {
244// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 243// // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
245// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
246// currentSample = sampleWeShouldBeAt; 245// currentSample = sampleWeShouldBeAt;
247// } 246// }
248 247
249 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 248 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
250 audioSampleCounter = currentSample + samplesRead - 1; 249 audioSampleCounter = currentSample + samplesRead - 1;
251 250
252 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
253 252
254 } else { 253 } else {
255 254
256 moreAudio = FALSE; 255 moreAudio = FALSE;
257 256
258 } 257 }
259 258
260 } 259 }
261 260
262 audioMutex->unlock(); 261 audioMutex->unlock();
263} 262}
264 263
265 264
266void LoopControl::killTimers() { 265void LoopControl::killTimers() {
267 266
268 audioMutex->lock(); 267 audioMutex->lock();
269 268
270 if ( hasVideoChannel ) 269 if ( hasVideoChannel )
271 killTimer( videoId ); 270 killTimer( videoId );
272 killTimer( sliderId ); 271 killTimer( sliderId );
273 threadOkToGo = FALSE; 272 threadOkToGo = FALSE;
274 273
275 audioMutex->unlock(); 274 audioMutex->unlock();
276} 275}
277 276
278 277
279void LoopControl::startTimers() { 278void LoopControl::startTimers() {
280 279
281 audioMutex->lock(); 280 audioMutex->lock();
282 281
283 moreVideo = FALSE; 282 moreVideo = FALSE;
284 moreAudio = FALSE; 283 moreAudio = FALSE;
285 284
286 if ( hasVideoChannel ) { 285 if ( hasVideoChannel ) {
287 moreVideo = TRUE; 286 moreVideo = TRUE;
288 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value 287 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value
289 videoId = startTimer( mSecsBetweenFrames ); 288 videoId = startTimer( mSecsBetweenFrames );
290 } 289 }
291 290
292 if ( hasAudioChannel ) { 291 if ( hasAudioChannel ) {
293 moreAudio = TRUE; 292 moreAudio = TRUE;
294 threadOkToGo = TRUE; 293 threadOkToGo = TRUE;
295 } 294 }
@@ -334,115 +333,117 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
334 audioMutex->lock(); 333 audioMutex->lock();
335 334
336 mediaPlayerState->curDecoder()->close(); 335 mediaPlayerState->curDecoder()->close();
337 336
338 if ( audioDevice ) { 337 if ( audioDevice ) {
339 delete audioDevice; 338 delete audioDevice;
340 delete audioBuffer; 339 delete audioBuffer;
341 audioDevice = 0; 340 audioDevice = 0;
342 audioBuffer = 0; 341 audioBuffer = 0;
343 } 342 }
344 343
345 audioMutex->unlock(); 344 audioMutex->unlock();
346 345
347 } 346 }
348} 347}
349 348
350 349
351bool LoopControl::init( const QString& filename ) { 350bool LoopControl::init( const QString& filename ) {
352 stop(); 351 stop();
353 352
354 audioMutex->lock(); 353 audioMutex->lock();
355 354
356 fileName = filename; 355 fileName = filename;
357 stream = 0; // only play stream 0 for now 356 stream = 0; // only play stream 0 for now
358 current_frame = total_video_frames = total_audio_samples = 0; 357 current_frame = total_video_frames = total_audio_samples = 0;
359 358
360 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 359 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
361 360
362 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 361 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
363 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 362 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
364 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 363 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
365 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 364 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
366 mediaPlayerState->libMpeg3Decoder()->close(); 365 mediaPlayerState->libMpeg3Decoder()->close();
367 } 366 }
368 } 367 }
369 368
370 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
371 audioMutex->unlock(); 370 audioMutex->unlock();
372 return FALSE; 371 return FALSE;
373 } 372 }
374 373
375 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
376 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
377 376
378 if ( hasAudioChannel ) { 377 if ( hasAudioChannel ) {
379 int astream = 0; 378 int astream = 0;
380 379
381 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 380 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
382 qDebug( "LC- channels = %d", channels ); 381// qDebug( "LC- channels = %d", channels );
383 382
384 if ( !total_audio_samples ) 383 if ( !total_audio_samples )
385 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
386 385
387// total_audio_samples += 1000; 386// total_audio_samples += 1000;
388 387
389 mediaPlayerState->setLength( total_audio_samples ); 388 mediaPlayerState->setLength( total_audio_samples );
390 389
391 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
392 qDebug( "LC- frequency = %d", freq ); 391// qDebug( "LC- frequency = %d", freq );
393 392
394 audioSampleCounter = 0; 393 audioSampleCounter = 0;
395 int bits_per_sample; 394 int bits_per_sample;
396 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { 395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) {
397 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
398 qDebug("using stupid hack"); 397// qDebug("using stupid hack");
399 } else { 398 } else {
400 bits_per_sample=0; 399 bits_per_sample=0;
400// freq=44100;
401 channels=2;
401 } 402 }
402 403
403 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 404 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
404 audioBuffer = new char[ audioDevice->bufferSize() ]; 405 audioBuffer = new char[ audioDevice->bufferSize() ];
405 channels = audioDevice->channels(); 406 channels = audioDevice->channels();
406 407
407 //### must check which frequency is actually used. 408 //### must check which frequency is actually used.
408 static const int size = 1; 409 static const int size = 1;
409 short int buf[size]; 410 short int buf[size];
410 long samplesRead = 0; 411 long samplesRead = 0;
411 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 412 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
412 } 413 }
413 414
414 if ( hasVideoChannel ) { 415 if ( hasVideoChannel ) {
415 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); 416 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
416 417
417 mediaPlayerState->setLength( total_video_frames ); 418 mediaPlayerState->setLength( total_video_frames );
418 419
419 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); 420 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
420 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); 421 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
421 422
422 if ( framerate <= 1.0 ) { 423 if ( framerate <= 1.0 ) {
423 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); 424 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
424 framerate = 25; 425 framerate = 25;
425 } 426 }
426 427
427 if ( total_video_frames == 1 ) { 428 if ( total_video_frames == 1 ) {
428 DecodeLoopDebug(( "Cannot seek to frame" )); 429 DecodeLoopDebug(( "Cannot seek to frame" ));
429 } 430 }
430 431
431 } 432 }
432 433
433 current_frame = 0; 434 current_frame = 0;
434 prev_frame = -1; 435 prev_frame = -1;
435 436
436 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 437 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
437 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 438 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
438 439
439 audioMutex->unlock(); 440 audioMutex->unlock();
440 441
441 return TRUE; 442 return TRUE;
442} 443}
443 444
444 445
445void LoopControl::play() { 446void LoopControl::play() {
446 qDebug("LC- play"); 447 qDebug("LC- play");
447#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 448#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
448 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 449 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {