author | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
commit | f180c1a5e8fc889ff1fb390d5cc94cdbc5085046 (patch) (unidiff) | |
tree | 5e9ea6f1313f4c33d57fb266523c1cfbe0826756 /core/multimedia/opieplayer/loopcontrol.cpp | |
parent | c0446b55fc32b7fdea9f58db06e40da703f5e8ff (diff) | |
download | opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.zip opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.gz opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.bz2 |
fucked up- no workie.. back out
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 352 |
1 files changed, 177 insertions, 175 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 1ae0059..dd466ed 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the 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 |
@@ -18,11 +18,10 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | ||
21 | |||
22 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
23 | |||
24 | #ifdef Q_WS_QWS | 21 | #ifdef Q_WS_QWS |
22 | |||
25 | #include <qpe/qcopenvelope_qws.h> | 23 | #include <qpe/qcopenvelope_qws.h> |
26 | #endif | 24 | #endif |
25 | #include <qpe/mediaplayerplugininterface.h> | ||
27 | #include <stdio.h> | 26 | #include <stdio.h> |
28 | #include <stdlib.h> | 27 | #include <stdlib.h> |
@@ -34,5 +33,4 @@ | |||
34 | #include "videowidget.h" | 33 | #include "videowidget.h" |
35 | #include "audiodevice.h" | 34 | #include "audiodevice.h" |
36 | #include "mediaplayerplugininterface.h" | ||
37 | #include "mediaplayerstate.h" | 35 | #include "mediaplayerstate.h" |
38 | 36 | ||
@@ -46,11 +44,11 @@ extern MediaPlayerState *mediaPlayerState; | |||
46 | 44 | ||
47 | 45 | ||
48 | static char *audioBuffer = NULL; | 46 | static char *audioBuffer = NULL; |
49 | static AudioDevice *audioDevice = NULL; | 47 | static AudioDevice *audioDevice = NULL; |
50 | static bool disabledSuspendScreenSaver = FALSE; | 48 | static bool disabledSuspendScreenSaver = FALSE; |
51 | static bool previousSuspendMode = FALSE; | 49 | static bool previousSuspendMode = FALSE; |
52 | 50 | ||
53 | 51 | ||
54 | pthread_t audio_tid; | 52 | pthread_taudio_tid; |
55 | pthread_attr_t audio_attr; | 53 | pthread_attr_t audio_attr; |
56 | bool threadOkToGo = FALSE; | 54 | bool threadOkToGo = FALSE; |
@@ -60,20 +58,20 @@ class Mutex { | |||
60 | public: | 58 | public: |
61 | Mutex() { | 59 | Mutex() { |
62 | pthread_mutexattr_t attr; | 60 | pthread_mutexattr_t attr; |
63 | pthread_mutexattr_init( &attr ); | 61 | pthread_mutexattr_init( &attr ); |
64 | pthread_mutex_init( &mutex, &attr ); | 62 | pthread_mutex_init( &mutex, &attr ); |
65 | pthread_mutexattr_destroy( &attr ); | 63 | pthread_mutexattr_destroy( &attr ); |
66 | } | 64 | } |
67 | 65 | ||
68 | ~Mutex() { | 66 | ~Mutex() { |
69 | pthread_mutex_destroy( &mutex ); | 67 | pthread_mutex_destroy( &mutex ); |
70 | } | 68 | } |
71 | 69 | ||
72 | void lock() { | 70 | void lock() { |
73 | pthread_mutex_lock( &mutex ); | 71 | pthread_mutex_lock( &mutex ); |
74 | } | 72 | } |
75 | 73 | ||
76 | void unlock() { | 74 | void unlock() { |
77 | pthread_mutex_unlock( &mutex ); | 75 | pthread_mutex_unlock( &mutex ); |
78 | } | 76 | } |
79 | private: | 77 | private: |
@@ -85,8 +83,8 @@ void *startAudioThread( void *ptr ) { | |||
85 | LoopControl *mpegView = (LoopControl *)ptr; | 83 | LoopControl *mpegView = (LoopControl *)ptr; |
86 | while ( TRUE ) { | 84 | while ( TRUE ) { |
87 | if ( threadOkToGo && mpegView->moreAudio ) | 85 | if ( threadOkToGo && mpegView->moreAudio ) |
88 | mpegView->startAudio(); | 86 | mpegView->startAudio(); |
89 | else | 87 | else |
90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 88 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
91 | } | 89 | } |
92 | return 0; | 90 | return 0; |
@@ -105,17 +103,22 @@ LoopControl::LoopControl( QObject *parent, const char *name ) | |||
105 | 103 | ||
106 | pthread_attr_init(&audio_attr); | 104 | pthread_attr_init(&audio_attr); |
107 | #define USE_REALTIME_AUDIO_THREAD | 105 | |
108 | #ifdef USE_REALTIME_AUDIO_THREAD | 106 | if ( getuid() == 0 ) { |
109 | // Attempt to set it to real-time round robin | 107 | printf("true, guid = %i\n", getuid()); |
110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 108 | |
111 | sched_param params; | 109 | // Attempt to set it to real-time round robin |
112 | params.sched_priority = 50; | 110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
113 | pthread_attr_setschedparam(&audio_attr,¶ms); | 111 | sched_param params; |
114 | } else { | 112 | params.sched_priority = 50; |
115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 113 | pthread_attr_setschedparam(&audio_attr,¶ms); |
116 | pthread_attr_destroy(&audio_attr); | 114 | } else { |
117 | pthread_attr_init(&audio_attr); | 115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
116 | pthread_attr_destroy(&audio_attr); | ||
117 | pthread_attr_init(&audio_attr); | ||
118 | } | ||
118 | } | 119 | } |
119 | #endif | 120 | // printf("false, guid = %i\n", getuid()); |
121 | usleep( 100 ); | ||
122 | |||
120 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 123 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
121 | } | 124 | } |
@@ -134,12 +137,12 @@ void LoopControl::timerEvent( QTimerEvent *te ) { | |||
134 | 137 | ||
135 | if ( te->timerId() == videoId ) | 138 | if ( te->timerId() == videoId ) |
136 | startVideo(); | 139 | startVideo(); |
137 | 140 | ||
138 | if ( te->timerId() == sliderId ) { | 141 | if ( te->timerId() == sliderId ) { |
139 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 142 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
140 | mediaPlayerState->updatePosition( audioSampleCounter ); | 143 | mediaPlayerState->updatePosition( audioSampleCounter ); |
141 | } else if ( hasVideoChannel && moreVideo ) { | 144 | } else if ( hasVideoChannel && moreVideo ) { |
142 | mediaPlayerState->updatePosition( current_frame ); | 145 | mediaPlayerState->updatePosition( current_frame ); |
143 | } | 146 | } |
144 | } | 147 | } |
145 | 148 | ||
@@ -155,24 +158,24 @@ void LoopControl::setPosition( long pos ) { | |||
155 | 158 | ||
156 | if ( hasVideoChannel && hasAudioChannel ) { | 159 | if ( hasVideoChannel && hasAudioChannel ) { |
157 | playtime.restart(); | 160 | playtime.restart(); |
158 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 161 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
159 | current_frame = pos + 1; | 162 | current_frame = pos + 1; |
160 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 163 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
161 | prev_frame = current_frame - 1; | 164 | prev_frame = current_frame - 1; |
162 | currentSample = (int)( (double)current_frame * freq / framerate ); | 165 | currentSample = (int)( (double)current_frame * freq / framerate ); |
163 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 166 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
164 | audioSampleCounter = currentSample - 1; | 167 | audioSampleCounter = currentSample - 1; |
165 | } else if ( hasVideoChannel ) { | 168 | } else if ( hasVideoChannel ) { |
166 | playtime.restart(); | 169 | playtime.restart(); |
167 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 170 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
168 | current_frame = pos + 1; | 171 | current_frame = pos + 1; |
169 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 172 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
170 | prev_frame = current_frame - 1; | 173 | prev_frame = current_frame - 1; |
171 | } else if ( hasAudioChannel ) { | 174 | } else if ( hasAudioChannel ) { |
172 | playtime.restart(); | 175 | playtime.restart(); |
173 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); | 176 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); |
174 | currentSample = pos + 1; | 177 | currentSample = pos + 1; |
175 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 178 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
176 | audioSampleCounter = currentSample - 1; | 179 | audioSampleCounter = currentSample - 1; |
177 | } | 180 | } |
178 | 181 | ||
@@ -187,30 +190,30 @@ void LoopControl::startVideo() { | |||
187 | if ( mediaPlayerState->curDecoder() ) { | 190 | if ( mediaPlayerState->curDecoder() ) { |
188 | 191 | ||
189 | if ( hasAudioChannel && !isMuted ) { | 192 | if ( hasAudioChannel && !isMuted ) { |
190 | 193 | ||
191 | current_frame = long( playtime.elapsed() * framerate / 1000 ); | 194 | current_frame = long( playtime.elapsed() * framerate / 1000 ); |
192 | 195 | ||
193 | if ( prev_frame != -1 && current_frame <= prev_frame ) | 196 | if ( prev_frame != -1 && current_frame <= prev_frame ) |
194 | return; | 197 | return; |
195 | 198 | ||
196 | } else { | 199 | } else { |
197 | // Don't skip | 200 | // Don't skip |
198 | current_frame++; | 201 | current_frame++; |
199 | } | 202 | } |
200 | 203 | ||
201 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 204 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
202 | if ( current_frame > prev_frame + 1 ) { | 205 | if ( current_frame > prev_frame + 1 ) { |
203 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 206 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
204 | } | 207 | } |
205 | moreVideo = videoUI->playVideo(); | 208 | moreVideo = videoUI->playVideo(); |
206 | prev_frame = current_frame; | 209 | prev_frame = current_frame; |
207 | } | 210 | } |
208 | 211 | ||
209 | } else { | 212 | } else { |
210 | 213 | ||
211 | moreVideo = FALSE; | 214 | moreVideo = FALSE; |
212 | killTimer( videoId ); | 215 | killTimer( videoId ); |
213 | 216 | ||
214 | } | 217 | } |
215 | 218 | ||
216 | } | 219 | } |
@@ -224,35 +227,34 @@ void LoopControl::startAudio() { | |||
224 | if ( moreAudio ) { | 227 | if ( moreAudio ) { |
225 | 228 | ||
226 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 229 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
227 | 230 | ||
228 | currentSample = audioSampleCounter + 1; | 231 | currentSample = audioSampleCounter + 1; |
229 | 232 | ||
230 | if ( currentSample != audioSampleCounter + 1 ) | 233 | if ( currentSample != audioSampleCounter + 1 ) |
231 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 234 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
232 | 235 | ||
233 | long samplesRead = 0; | 236 | long samplesRead = 0; |
234 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 237 | mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
235 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 238 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
236 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 239 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
237 | 240 | ||
238 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 241 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
239 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 242 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); |
240 | } | 243 | } else if ( sampleWaitTime <= -5000 ) { |
241 | else if ( sampleWaitTime <= -5000 ) { | 244 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); |
242 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | 245 | //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
243 | //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 246 | currentSample = sampleWeShouldBeAt; |
244 | currentSample = sampleWeShouldBeAt; | 247 | } |
245 | } | ||
246 | 248 | ||
247 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 249 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
248 | audioSampleCounter = currentSample + samplesRead - 1; | 250 | audioSampleCounter = currentSample + samplesRead - 1; |
249 | 251 | ||
250 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); | 252 | moreAudio = audioSampleCounter <= total_audio_samples; |
251 | 253 | ||
252 | } else { | 254 | } else { |
253 | 255 | ||
254 | moreAudio = FALSE; | 256 | moreAudio = FALSE; |
255 | 257 | ||
256 | } | 258 | } |
257 | 259 | ||
258 | } | 260 | } |
@@ -267,5 +269,5 @@ void LoopControl::killTimers() { | |||
267 | 269 | ||
268 | if ( hasVideoChannel ) | 270 | if ( hasVideoChannel ) |
269 | killTimer( videoId ); | 271 | killTimer( videoId ); |
270 | killTimer( sliderId ); | 272 | killTimer( sliderId ); |
271 | threadOkToGo = FALSE; | 273 | threadOkToGo = FALSE; |
@@ -283,12 +285,12 @@ void LoopControl::startTimers() { | |||
283 | 285 | ||
284 | if ( hasVideoChannel ) { | 286 | if ( hasVideoChannel ) { |
285 | moreVideo = TRUE; | 287 | moreVideo = TRUE; |
286 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value | 288 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value |
287 | videoId = startTimer( mSecsBetweenFrames ); | 289 | videoId = startTimer( mSecsBetweenFrames ); |
288 | } | 290 | } |
289 | 291 | ||
290 | if ( hasAudioChannel ) { | 292 | if ( hasAudioChannel ) { |
291 | moreAudio = TRUE; | 293 | moreAudio = TRUE; |
292 | threadOkToGo = TRUE; | 294 | threadOkToGo = TRUE; |
293 | } | 295 | } |
294 | 296 | ||
@@ -302,14 +304,14 @@ void LoopControl::setPaused( bool pause ) { | |||
302 | 304 | ||
303 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 305 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
304 | return; | 306 | return; |
305 | 307 | ||
306 | if ( pause ) { | 308 | if ( pause ) { |
307 | killTimers(); | 309 | killTimers(); |
308 | } else { | 310 | } else { |
309 | // Force an update of the position | 311 | // Force an update of the position |
310 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 312 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
311 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 313 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
312 | // Just like we never stopped | 314 | // Just like we never stopped |
313 | startTimers(); | 315 | startTimers(); |
314 | } | 316 | } |
315 | } | 317 | } |
@@ -320,7 +322,7 @@ void LoopControl::stop( bool willPlayAgainShortly ) { | |||
320 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 322 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
321 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 323 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
322 | disabledSuspendScreenSaver = FALSE; | 324 | disabledSuspendScreenSaver = FALSE; |
323 | // Re-enable the suspend mode | 325 | // Re-enable the suspend mode |
324 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 326 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
325 | } | 327 | } |
326 | #endif | 328 | #endif |
@@ -328,18 +330,18 @@ void LoopControl::stop( bool willPlayAgainShortly ) { | |||
328 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 330 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
329 | 331 | ||
330 | killTimers(); | 332 | killTimers(); |
331 | 333 | ||
332 | audioMutex->lock(); | 334 | audioMutex->lock(); |
333 | 335 | ||
334 | mediaPlayerState->curDecoder()->close(); | 336 | mediaPlayerState->curDecoder()->close(); |
335 | 337 | ||
336 | if ( audioDevice ) { | 338 | if ( audioDevice ) { |
337 | delete audioDevice; | 339 | delete audioDevice; |
338 | delete audioBuffer; | 340 | delete audioBuffer; |
339 | audioDevice = 0; | 341 | audioDevice = 0; |
340 | audioBuffer = 0; | 342 | audioBuffer = 0; |
341 | } | 343 | } |
342 | 344 | ||
343 | audioMutex->unlock(); | 345 | audioMutex->unlock(); |
344 | 346 | ||
345 | } | 347 | } |
@@ -360,13 +362,13 @@ bool LoopControl::init( const QString& filename ) { | |||
360 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 362 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
361 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 363 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
362 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 364 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
363 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 365 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
364 | mediaPlayerState->libMpeg3Decoder()->close(); | 366 | mediaPlayerState->libMpeg3Decoder()->close(); |
365 | } | 367 | } |
366 | } | 368 | } |
367 | 369 | ||
368 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 370 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
369 | audioMutex->unlock(); | 371 | audioMutex->unlock(); |
370 | return FALSE; | 372 | return FALSE; |
371 | } | 373 | } |
372 | 374 | ||
@@ -375,50 +377,50 @@ bool LoopControl::init( const QString& filename ) { | |||
375 | 377 | ||
376 | if ( hasAudioChannel ) { | 378 | if ( hasAudioChannel ) { |
377 | int astream = 0; | 379 | int astream = 0; |
378 | 380 | ||
379 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 381 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
380 | qDebug( "LC- channels = %d", channels ); | 382 | DecodeLoopDebug(( "channels = %d\n", channels )); |
381 | 383 | ||
382 | if ( !total_audio_samples ) | 384 | if ( !total_audio_samples ) |
383 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 385 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
384 | 386 | ||
385 | // total_audio_samples += 1000; | 387 | total_audio_samples += 1000; |
386 | 388 | ||
387 | mediaPlayerState->setLength( total_audio_samples ); | 389 | mediaPlayerState->setLength( total_audio_samples ); |
388 | 390 | ||
389 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 391 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
390 | qDebug( "LC- frequency = %d", freq ); | 392 | DecodeLoopDebug(( "frequency = %d\n", freq )); |
391 | 393 | ||
392 | audioSampleCounter = 0; | 394 | audioSampleCounter = 0; |
393 | 395 | ||
394 | int bits_per_sample = mediaPlayerState->curDecoder()->audioBitsPerSample( astream); | 396 | static const int bytes_per_sample = 2; //16 bit |
395 | 397 | ||
396 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 398 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); |
397 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 399 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
398 | channels = audioDevice->channels(); | 400 | channels = audioDevice->channels(); |
399 | 401 | ||
400 | //### must check which frequency is actually used. | 402 | //### must check which frequency is actually used. |
401 | static const int size = 1; | 403 | static const int size = 1; |
402 | short int buf[size]; | 404 | short int buf[size]; |
403 | long samplesRead = 0; | 405 | long samplesRead = 0; |
404 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 406 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
405 | } | 407 | } |
406 | 408 | ||
407 | if ( hasVideoChannel ) { | 409 | if ( hasVideoChannel ) { |
408 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 410 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
409 | 411 | ||
410 | mediaPlayerState->setLength( total_video_frames ); | 412 | mediaPlayerState->setLength( total_video_frames ); |
411 | 413 | ||
412 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 414 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
413 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 415 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
414 | 416 | ||
415 | if ( framerate <= 1.0 ) { | 417 | if ( framerate <= 1.0 ) { |
416 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 418 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
417 | framerate = 25; | 419 | framerate = 25; |
418 | } | 420 | } |
419 | 421 | ||
420 | if ( total_video_frames == 1 ) { | 422 | if ( total_video_frames == 1 ) { |
421 | DecodeLoopDebug(( "Cannot seek to frame" )); | 423 | DecodeLoopDebug(( "Cannot seek to frame" )); |
422 | } | 424 | } |
423 | 425 | ||
424 | } | 426 | } |
@@ -440,9 +442,9 @@ void LoopControl::play() { | |||
440 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 442 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
441 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 443 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
442 | disabledSuspendScreenSaver = TRUE; | 444 | disabledSuspendScreenSaver = TRUE; |
443 | previousSuspendMode = hasVideoChannel; | 445 | previousSuspendMode = hasVideoChannel; |
444 | // Stop the screen from blanking and power saving state | 446 | // Stop the screen from blanking and power saving state |
445 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 447 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
446 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 448 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
447 | } | 449 | } |
448 | #endif | 450 | #endif |
@@ -455,12 +457,12 @@ void LoopControl::play() { | |||
455 | void LoopControl::setMute( bool on ) { | 457 | void LoopControl::setMute( bool on ) { |
456 | if ( on != isMuted ) { | 458 | if ( on != isMuted ) { |
457 | isMuted = on; | 459 | isMuted = on; |
458 | if ( !on ) { | 460 | if ( !on ) { |
459 | // Force an update of the position | 461 | // Force an update of the position |
460 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 462 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
461 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 463 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
462 | // Resume playing audio | 464 | // Resume playing audio |
463 | moreAudio = TRUE; | 465 | moreAudio = TRUE; |
464 | } | 466 | } |
465 | } | 467 | } |
466 | } | 468 | } |