author | llornkcor <llornkcor> | 2002-03-18 01:50:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-18 01:50:17 (UTC) |
commit | c09cb25eb6bbf31bed0d4a415802469cfd1efedf (patch) (unidiff) | |
tree | 86ced0fa482bd5fb244629f2baa1b1a4f25c9189 /core/multimedia/opieplayer/loopcontrol.cpp | |
parent | 848182342d81b4e6ab4ce6b75bdaa0b109828af3 (diff) | |
download | opie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.zip opie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.tar.gz opie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.tar.bz2 |
added stuff and fixed stuff that I dont remember- plays w/o going to playlist among other things
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 29 |
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 | |||
@@ -200,72 +200,71 @@ void LoopControl::startVideo() { | |||
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 | ||
222 | void LoopControl::startAudio() { | 222 | void 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 | ||
266 | void LoopControl::killTimers() { | 265 | void LoopControl::killTimers() { |
267 | 266 | ||
268 | audioMutex->lock(); | 267 | audioMutex->lock(); |
269 | 268 | ||
270 | if ( hasVideoChannel ) | 269 | if ( hasVideoChannel ) |
271 | killTimer( videoId ); | 270 | killTimer( videoId ); |
@@ -358,67 +357,69 @@ bool LoopControl::init( const QString& filename ) { | |||
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; |