summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp37
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.cpp33
2 files changed, 35 insertions, 35 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 6a38fc9..d296d27 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -21,38 +21,39 @@
21 21
22 22
23#include <stdlib.h> 23#include <stdlib.h>
24#include <stdio.h> 24#include <stdio.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/custom.h>
27#include <qmessagebox.h> 28#include <qmessagebox.h>
28 29
29#include "audiodevice.h" 30#include "audiodevice.h"
30 31
31 32
32#include <errno.h> 33#include <errno.h>
33 34
34#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 35#if !defined(QT_NO_COP)
35#include "qpe/qcopenvelope_qws.h" 36#include <qpe/qcopenvelope_qws.h>
36#endif 37#endif
37 38
38#if defined(Q_WS_X11) || defined(Q_WS_QWS) 39#if defined(Q_WS_X11) || defined(Q_WS_QWS)
39#include <fcntl.h> 40#include <fcntl.h>
40#include <sys/ioctl.h> 41#include <sys/ioctl.h>
41#include <sys/soundcard.h> 42#include <sys/soundcard.h>
42#include <sys/stat.h> 43#include <sys/stat.h>
43#include <sys/time.h> 44#include <sys/time.h>
44#include <sys/types.h> 45#include <sys/types.h>
45#include <unistd.h> 46#include <unistd.h>
46#endif 47#endif
47 48
48# if defined(QT_QWS_IPAQ) 49#ifdef OPIE_SOUND_FRAGMENT_SHIFT
49static const int sound_fragment_shift = 14; 50static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT;
50# else 51#else
51static const int sound_fragment_shift = 16; 52static const int sound_fragment_shift = 16;
52# endif 53#endif
53static const int sound_fragment_bytes = (1<<sound_fragment_shift); 54static const int sound_fragment_bytes = (1<<sound_fragment_shift);
54//#endif 55//#endif
55 56
56 57
57class AudioDevicePrivate { 58class AudioDevicePrivate {
58public: 59public:
@@ -142,24 +143,24 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
142 Config cfg("qpe"); // qtopia is "Sound" 143 Config cfg("qpe"); // qtopia is "Sound"
143 cfg.setGroup("Volume"); // qtopia is "Settings" 144 cfg.setGroup("Volume"); // qtopia is "Settings"
144 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume 145 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
145# endif 146# endif
146 147
147//#endif 148//#endif
148// qDebug( "setting volume to: 0x%x", volume ); 149// qDebug( "setting volume to: 0x%x", volume );
149#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 150#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
150 // Send notification that the volume has changed 151 // Send notification that the volume has changed
151 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 152 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
152#endif 153#endif
153} 154}
154 155
155 156
156 157
157AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 158AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
158 // qDebug("creating new audio device"); 159 // qDebug("creating new audio device");
159// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 160// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
160 d = new AudioDevicePrivate; 161 d = new AudioDevicePrivate;
161 d->frequency = f; 162 d->frequency = f;
162 d->channels = chs; 163 d->channels = chs;
163 d->bytesPerSample = bps; 164 d->bytesPerSample = bps;
164 // qDebug("%d",bps); 165 // qDebug("%d",bps);
165 int format=0; 166 int format=0;
@@ -169,13 +170,13 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
169 // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 170 // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
170 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 171 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
171 172
172 int fragments = 0x10000 * 8 + sound_fragment_shift; 173 int fragments = 0x10000 * 8 + sound_fragment_shift;
173 int capabilities = 0; 174 int capabilities = 0;
174 175
175 176
176#ifdef KEEP_DEVICE_OPEN 177#ifdef KEEP_DEVICE_OPEN
177 if ( AudioDevicePrivate::dspFd == 0 ) { 178 if ( AudioDevicePrivate::dspFd == 0 ) {
178#endif 179#endif
179#ifdef QT_QWS_DEVFS 180#ifdef QT_QWS_DEVFS
180 if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) { 181 if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) {
181#else 182#else
@@ -184,13 +185,13 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
184 185
185 perror("open(\"/dev/dsp\")"); 186 perror("open(\"/dev/dsp\")");
186 QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); 187 QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now.");
187 QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); 188 QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort"));
188 exit(-1); //harsh? 189 exit(-1); //harsh?
189 } 190 }
190#ifdef KEEP_DEVICE_OPEN 191#ifdef KEEP_DEVICE_OPEN
191 AudioDevicePrivate::dspFd = d->handle; 192 AudioDevicePrivate::dspFd = d->handle;
192 } else { 193 } else {
193 d->handle = AudioDevicePrivate::dspFd; 194 d->handle = AudioDevicePrivate::dspFd;
194 } 195 }
195#endif 196#endif
196 197
@@ -206,40 +207,40 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
206 // qDebug("channels %d",d->channels); 207 // qDebug("channels %d",d->channels);
207 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 208 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
208 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 209 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
209 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 210 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
210 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 211 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
211 } 212 }
212// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 213// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
213 214
214 d->bufferSize = sound_fragment_bytes; 215 d->bufferSize = sound_fragment_bytes;
215 d->unwrittenBuffer = new char[d->bufferSize]; 216 d->unwrittenBuffer = new char[d->bufferSize];
216 d->unwritten = 0; 217 d->unwritten = 0;
217 d->can_GETOSPACE = TRUE; // until we find otherwise 218 d->can_GETOSPACE = TRUE; // until we find otherwise
218 219
219 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 220 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
220 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 221 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
221 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 222 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
222 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 223 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
223 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 224 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
224 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 225 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
225 226
226} 227}
227 228
228 229
229AudioDevice::~AudioDevice() { 230AudioDevice::~AudioDevice() {
230 // qDebug("destryo audiodevice"); 231 // qDebug("destryo audiodevice");
231// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 232// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
232 233
233# ifndef KEEP_DEVICE_OPEN 234# ifndef KEEP_DEVICE_OPEN
234 close( d->handle ); // Now it should be safe to shut the handle 235 close( d->handle ); // Now it should be safe to shut the handle
235# endif 236# endif
236 delete d->unwrittenBuffer; 237 delete d->unwrittenBuffer;
237 delete d; 238 delete d;
238// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 239// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
239 240
240} 241}
241 242
242 243
243void AudioDevice::volumeChanged( bool muted ) 244void AudioDevice::volumeChanged( bool muted )
244{ 245{
245 AudioDevicePrivate::muted = muted; 246 AudioDevicePrivate::muted = muted;
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
index 364e77b..3796549 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
@@ -17,15 +17,16 @@
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _REENTRANT 20#define _REENTRANT
21 21
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#include <qpe/custom.h>
23#include <qimage.h> 24#include <qimage.h>
24#include <qpainter.h> 25#include <qpainter.h>
25#ifdef Q_WS_QWS 26#if !defined(QT_NO_COP)
26#include <qpe/qcopenvelope_qws.h> 27#include <qpe/qcopenvelope_qws.h>
27#endif 28#endif
28#include "mediaplayerplugininterface.h" 29#include "mediaplayerplugininterface.h"
29#include <stdio.h> 30#include <stdio.h>
30#include <stdlib.h> 31#include <stdlib.h>
31#include <string.h> 32#include <string.h>
@@ -36,15 +37,13 @@
36#include "audiodevice.h" 37#include "audiodevice.h"
37#include "videowidget.h" 38#include "videowidget.h"
38#include "audiowidget.h" 39#include "audiowidget.h"
39#include "mediaplayerstate.h" 40#include "mediaplayerstate.h"
40 41
41 42
42#if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) 43
43#define USE_REALTIME_AUDIO_THREAD
44#endif
45 44
46 45
47extern VideoWidget *videoUI; // now only needed to tell it to play a frame 46extern VideoWidget *videoUI; // now only needed to tell it to play a frame
48extern MediaPlayerState *mediaPlayerState; 47extern MediaPlayerState *mediaPlayerState;
49 48
50 49
@@ -253,13 +252,13 @@ void LoopControl::startVideo() {
253 252
254 253
255/* 254/*
256 videoMutex->lock(); 255 videoMutex->lock();
257 current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); 256 current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
258 //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; 257 //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
259 258
260 // Sync to Audio 259 // Sync to Audio
261// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); 260// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq);
262 261
263 long mSecsToNextFrame = 0; 262 long mSecsToNextFrame = 0;
264 263
265 if ( current_frame == prev_frame ) { 264 if ( current_frame == prev_frame ) {
@@ -309,31 +308,31 @@ void LoopControl::startVideo() {
309 videoMutex->lock(); 308 videoMutex->lock();
310 if ( current_frame > prev_frame + 1 ) { 309 if ( current_frame > prev_frame + 1 ) {
311 // qDebug("skipped a frame"); 310 // qDebug("skipped a frame");
312 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 311 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
313 } 312 }
314 prev_frame = current_frame; 313 prev_frame = current_frame;
315 if ( moreVideo = videoUI->playVideo() ) 314 if ( moreVideo = videoUI->playVideo() )
316 emitChangePos = TRUE; 315 emitChangePos = TRUE;
317 videoMutex->unlock(); 316 videoMutex->unlock();
318 } 317 }
319 318
320 } else 319 } else
321 moreVideo = FALSE; 320 moreVideo = FALSE;
322 321
323 } 322 }
324 323
325 if ( !moreVideo && !moreAudio ) 324 if ( !moreVideo && !moreAudio )
326 emitPlayFinished = TRUE; 325 emitPlayFinished = TRUE;
327 326
328 pthread_exit(NULL); 327 pthread_exit(NULL);
329} 328}
330 329
331void LoopControl::startAudio() { 330void LoopControl::startAudio() {
332 moreAudio = TRUE; 331 moreAudio = TRUE;
333 332
334 while ( moreAudio ) { 333 while ( moreAudio ) {
335 334
336 if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { 335 if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) {
337 336
338 audioMutex->lock(); 337 audioMutex->lock();
339 currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); 338 currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream );
@@ -401,13 +400,13 @@ void LoopControl::startAudio() {
401 400
402 } 401 }
403 } 402 }
404 403
405 // qDebug( "End of file" ); 404 // qDebug( "End of file" );
406 405
407 if ( !moreVideo && !moreAudio ) 406 if ( !moreVideo && !moreAudio )
408 emitPlayFinished = TRUE; 407 emitPlayFinished = TRUE;
409 408
410 pthread_exit(NULL); 409 pthread_exit(NULL);
411} 410}
412 411
413void LoopControl::killTimers() { 412void LoopControl::killTimers() {
@@ -481,13 +480,13 @@ void LoopControl::setPaused( bool pause ) {
481 480
482 481
483void LoopControl::stop( bool willPlayAgainShortly ) { 482void LoopControl::stop( bool willPlayAgainShortly ) {
484 483
485#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 484#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
486 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 485 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
487 disabledSuspendScreenSaver = FALSE; 486 disabledSuspendScreenSaver = FALSE;
488 // Re-enable the suspend mode 487 // Re-enable the suspend mode
489 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 488 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
490 } 489 }
491#endif 490#endif
492 491
493 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { 492 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
@@ -509,15 +508,15 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
509 508
510bool LoopControl::init( const QString& filename ) { 509bool LoopControl::init( const QString& filename ) {
511 stop(); 510 stop();
512 fileName = filename; 511 fileName = filename;
513 stream = 0; // only play stream 0 for now 512 stream = 0; // only play stream 0 for now
514 current_frame = total_video_frames = total_audio_samples = 0; 513 current_frame = total_video_frames = total_audio_samples = 0;
515 514
516 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 515 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
517 516
518 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 517 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
519 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 518 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
520 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 519 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
521 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 520 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
522 mediaPlayerState->libMpeg3Decoder()->close(); 521 mediaPlayerState->libMpeg3Decoder()->close();
523 } 522 }
@@ -531,18 +530,18 @@ bool LoopControl::init( const QString& filename ) {
531 530
532 if ( hasAudioChannel ) { 531 if ( hasAudioChannel ) {
533 int astream = 0; 532 int astream = 0;
534 533
535 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 534 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
536 DecodeLoopDebug(( "channels = %d\n", channels )); 535 DecodeLoopDebug(( "channels = %d\n", channels ));
537 536
538 if ( !total_audio_samples ) 537 if ( !total_audio_samples )
539 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 538 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
540 539
541 mediaPlayerState->setLength( total_audio_samples ); 540 mediaPlayerState->setLength( total_audio_samples );
542 541
543 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 542 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
544 DecodeLoopDebug(( "frequency = %d\n", freq )); 543 DecodeLoopDebug(( "frequency = %d\n", freq ));
545 544
546 audioSampleCounter = 0; 545 audioSampleCounter = 0;
547 546
548 static const int bytes_per_sample = 2; //16 bit 547 static const int bytes_per_sample = 2; //16 bit
@@ -591,15 +590,15 @@ bool LoopControl::init( const QString& filename ) {
591 590
592 591
593void LoopControl::play() { 592void LoopControl::play() {
594 593
595#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 594#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
596 if ( !disabledSuspendScreenSaver ) { 595 if ( !disabledSuspendScreenSaver ) {
597 disabledSuspendScreenSaver = TRUE; 596 disabledSuspendScreenSaver = TRUE;
598 // Stop the screen from blanking and power saving state 597 // Stop the screen from blanking and power saving state
599 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 598 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
600 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 599 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
601 } 600 }
602#endif 601#endif
603 602
604 //begin = clock(); 603 //begin = clock();
605 playtime.start(); 604 playtime.start();