Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 4b2827e..b9f96de 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -1,46 +1,45 @@ | |||
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 | // L.J.Potter added changes Fri 02-15-2002 | 20 | // L.J.Potter added changes Fri 02-15-2002 |
21 | 21 | ||
22 | |||
23 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
24 | 23 | ||
25 | #ifdef Q_WS_QWS | 24 | #ifdef Q_WS_QWS |
26 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
27 | #endif | 26 | #endif |
28 | #include <stdio.h> | 27 | #include <stdio.h> |
29 | #include <stdlib.h> | 28 | #include <stdlib.h> |
30 | #include <string.h> | 29 | #include <string.h> |
31 | #include <pthread.h> | 30 | #include <pthread.h> |
32 | #include <errno.h> | 31 | #include <errno.h> |
33 | #include <unistd.h> | 32 | #include <unistd.h> |
34 | #include "loopcontrol.h" | 33 | #include "loopcontrol.h" |
35 | #include "videowidget.h" | 34 | #include "videowidget.h" |
36 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
37 | #include <qpe/mediaplayerplugininterface.h> | 36 | #include <qpe/mediaplayerplugininterface.h> |
38 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
39 | 38 | ||
40 | 39 | ||
41 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
42 | extern MediaPlayerState *mediaPlayerState; | 41 | extern MediaPlayerState *mediaPlayerState; |
43 | 42 | ||
44 | 43 | ||
45 | //#define DecodeLoopDebug(x) qDebug x | 44 | //#define DecodeLoopDebug(x) qDebug x |
46 | #define DecodeLoopDebug(x) | 45 | #define DecodeLoopDebug(x) |
@@ -200,71 +199,72 @@ void LoopControl::startVideo() { | |||
200 | current_frame++; | 199 | current_frame++; |
201 | } | 200 | } |
202 | 201 | ||
203 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 202 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
204 | if ( current_frame > prev_frame + 1 ) { | 203 | if ( current_frame > prev_frame + 1 ) { |
205 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
206 | } | 205 | } |
207 | moreVideo = videoUI->playVideo(); | 206 | moreVideo = videoUI->playVideo(); |
208 | prev_frame = current_frame; | 207 | prev_frame = current_frame; |
209 | } | 208 | } |
210 | 209 | ||
211 | } else { | 210 | } else { |
212 | 211 | ||
213 | moreVideo = FALSE; | 212 | moreVideo = FALSE; |
214 | killTimer( videoId ); | 213 | killTimer( videoId ); |
215 | 214 | ||
216 | } | 215 | } |
217 | 216 | ||
218 | } | 217 | } |
219 | } | 218 | } |
220 | 219 | ||
221 | 220 | ||
222 | void LoopControl::startAudio() { | 221 | void LoopControl::startAudio() { |
223 | 222 | ||
223 | //qDebug("start audio"); | ||
224 | audioMutex->lock(); | 224 | audioMutex->lock(); |
225 | if ( moreAudio ) { | 225 | if ( moreAudio ) { |
226 | 226 | ||
227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
228 | 228 | ||
229 | currentSample = audioSampleCounter + 1; | 229 | currentSample = audioSampleCounter + 1; |
230 | 230 | ||
231 | if ( currentSample != audioSampleCounter + 1 ) | 231 | if ( currentSample != audioSampleCounter + 1 ) |
232 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 232 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
233 | 233 | ||
234 | long samplesRead = 0; | 234 | long samplesRead = 0; |
235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
238 | 238 | ||
239 | // if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 239 | // if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
240 | // usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 240 | // usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); |
241 | // } | 241 | // } |
242 | // else if ( sampleWaitTime <= -5000 ) { | 242 | // else if ( sampleWaitTime <= -5000 ) { |
243 | // // 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 ); |
244 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 244 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
245 | // currentSample = sampleWeShouldBeAt; | 245 | // currentSample = sampleWeShouldBeAt; |
246 | // } | 246 | // } |
247 | 247 | ||
248 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 248 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
249 | audioSampleCounter = currentSample + samplesRead - 1; | 249 | audioSampleCounter = currentSample + samplesRead - 1; |
250 | 250 | ||
251 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); | 251 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); |
252 | 252 | ||
253 | } else { | 253 | } else { |
254 | 254 | ||
255 | moreAudio = FALSE; | 255 | moreAudio = FALSE; |
256 | 256 | ||
257 | } | 257 | } |
258 | 258 | ||
259 | } | 259 | } |
260 | 260 | ||
261 | audioMutex->unlock(); | 261 | audioMutex->unlock(); |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | void LoopControl::killTimers() { | 265 | void LoopControl::killTimers() { |
266 | 266 | ||
267 | audioMutex->lock(); | 267 | audioMutex->lock(); |
268 | 268 | ||
269 | if ( hasVideoChannel ) | 269 | if ( hasVideoChannel ) |
270 | killTimer( videoId ); | 270 | killTimer( videoId ); |
@@ -357,69 +357,67 @@ bool LoopControl::init( const QString& filename ) { | |||
357 | current_frame = total_video_frames = total_audio_samples = 0; | 357 | current_frame = total_video_frames = total_audio_samples = 0; |
358 | 358 | ||
359 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 359 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
360 | 360 | ||
361 | // ### 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 |
362 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 362 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
363 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 363 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
364 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 364 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
365 | mediaPlayerState->libMpeg3Decoder()->close(); | 365 | mediaPlayerState->libMpeg3Decoder()->close(); |
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 369 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
370 | audioMutex->unlock(); | 370 | audioMutex->unlock(); |
371 | return FALSE; | 371 | return FALSE; |
372 | } | 372 | } |
373 | 373 | ||
374 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 374 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
375 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 375 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
376 | 376 | ||
377 | if ( hasAudioChannel ) { | 377 | if ( hasAudioChannel ) { |
378 | int astream = 0; | 378 | int astream = 0; |
379 | 379 | ||
380 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 380 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
381 | // qDebug( "LC- channels = %d", channels ); | 381 | qDebug( "LC- channels = %d", channels ); |
382 | 382 | ||
383 | if ( !total_audio_samples ) | 383 | if ( !total_audio_samples ) |
384 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 384 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
385 | 385 | ||
386 | // total_audio_samples += 1000; | 386 | // total_audio_samples += 1000; |
387 | 387 | ||
388 | mediaPlayerState->setLength( total_audio_samples ); | 388 | mediaPlayerState->setLength( total_audio_samples ); |
389 | 389 | ||
390 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 390 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
391 | // qDebug( "LC- frequency = %d", freq ); | 391 | qDebug( "LC- frequency = %d", freq ); |
392 | 392 | ||
393 | audioSampleCounter = 0; | 393 | audioSampleCounter = 0; |
394 | int bits_per_sample; | 394 | int bits_per_sample; |
395 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) { | 395 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
396 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | 396 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); |
397 | // qDebug("using stupid hack"); | 397 | qDebug("using stupid hack"); |
398 | } else { | 398 | } else { |
399 | bits_per_sample=0; | 399 | bits_per_sample=0; |
400 | // freq=44100; | ||
401 | channels=2; | ||
402 | } | 400 | } |
403 | 401 | ||
404 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 402 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
405 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 403 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
406 | channels = audioDevice->channels(); | 404 | channels = audioDevice->channels(); |
407 | 405 | ||
408 | //### must check which frequency is actually used. | 406 | //### must check which frequency is actually used. |
409 | static const int size = 1; | 407 | static const int size = 1; |
410 | short int buf[size]; | 408 | short int buf[size]; |
411 | long samplesRead = 0; | 409 | long samplesRead = 0; |
412 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 410 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
413 | } | 411 | } |
414 | 412 | ||
415 | if ( hasVideoChannel ) { | 413 | if ( hasVideoChannel ) { |
416 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 414 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
417 | 415 | ||
418 | mediaPlayerState->setLength( total_video_frames ); | 416 | mediaPlayerState->setLength( total_video_frames ); |
419 | 417 | ||
420 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 418 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
421 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 419 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
422 | 420 | ||
423 | if ( framerate <= 1.0 ) { | 421 | if ( framerate <= 1.0 ) { |
424 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 422 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
425 | framerate = 25; | 423 | framerate = 25; |