summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -15,50 +15,51 @@
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// L.J.Potter added better error code Fri 02-15-2002 14:37:47
#include <stdlib.h>
#include <stdio.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
+#include <qpe/custom.h>
#include <qmessagebox.h>
#include "audiodevice.h"
#include <errno.h>
-#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
-#include "qpe/qcopenvelope_qws.h"
+#if !defined(QT_NO_COP)
+#include <qpe/qcopenvelope_qws.h>
#endif
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#endif
-# if defined(QT_QWS_IPAQ)
-static const int sound_fragment_shift = 14;
-# else
+#ifdef OPIE_SOUND_FRAGMENT_SHIFT
+static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT;
+#else
static const int sound_fragment_shift = 16;
-# endif
+#endif
static const int sound_fragment_bytes = (1<<sound_fragment_shift);
//#endif
class AudioDevicePrivate {
public:
int handle;
unsigned int frequency;
unsigned int channels;
unsigned int bytesPerSample;
unsigned int bufferSize;
//#ifndef Q_OS_WIN32
@@ -136,116 +137,116 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
} else
perror("open(\"/dev/mixer\")");
# else
// This is the way this has to be done now I guess, doesn't allow for
// independant right and left channel setting, or setting for different outputs
Config cfg("qpe"); // qtopia is "Sound"
cfg.setGroup("Volume"); // qtopia is "Settings"
cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
# endif
//#endif
-// qDebug( "setting volume to: 0x%x", volume );
+// qDebug( "setting volume to: 0x%x", volume );
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
// Send notification that the volume has changed
- QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
+ QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
#endif
}
AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
// qDebug("creating new audio device");
-// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
+// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
d = new AudioDevicePrivate;
d->frequency = f;
d->channels = chs;
d->bytesPerSample = bps;
// qDebug("%d",bps);
int format=0;
if( bps == 8) format = AFMT_U8;
else if( bps <= 0) format = AFMT_S16_LE;
else format = AFMT_S16_LE;
// qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
int fragments = 0x10000 * 8 + sound_fragment_shift;
int capabilities = 0;
-
+
#ifdef KEEP_DEVICE_OPEN
if ( AudioDevicePrivate::dspFd == 0 ) {
#endif
#ifdef QT_QWS_DEVFS
if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) {
#else
if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
#endif
perror("open(\"/dev/dsp\")");
QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now.");
QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort"));
exit(-1); //harsh?
}
-#ifdef KEEP_DEVICE_OPEN
+#ifdef KEEP_DEVICE_OPEN
AudioDevicePrivate::dspFd = d->handle;
} else {
d->handle = AudioDevicePrivate::dspFd;
}
#endif
if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
// qDebug("freq %d", d->frequency);
if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
perror("ioctl(\"SNDCTL_DSP_SPEED\")");
// qDebug("channels %d",d->channels);
if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
d->channels = ( d->channels == 1 ) ? 2 : d->channels;
if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
}
-// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
+// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
d->bufferSize = sound_fragment_bytes;
d->unwrittenBuffer = new char[d->bufferSize];
d->unwritten = 0;
d->can_GETOSPACE = TRUE; // until we find otherwise
-
+
//if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
//if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
//if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
//if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
//if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
//if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
-
+
}
-
+
AudioDevice::~AudioDevice() {
// qDebug("destryo audiodevice");
// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
-
-# ifndef KEEP_DEVICE_OPEN
+
+# ifndef KEEP_DEVICE_OPEN
close( d->handle ); // Now it should be safe to shut the handle
# endif
delete d->unwrittenBuffer;
delete d;
// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
-
+
}
void AudioDevice::volumeChanged( bool muted )
{
AudioDevicePrivate::muted = muted;
}
void AudioDevice::write( char *buffer, unsigned int length )
{
int t = ::write( d->handle, buffer, length );
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
@@ -11,46 +11,45 @@
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#define _REENTRANT
#include <qpe/qpeapplication.h>
+#include <qpe/custom.h>
#include <qimage.h>
#include <qpainter.h>
-#ifdef Q_WS_QWS
+#if !defined(QT_NO_COP)
#include <qpe/qcopenvelope_qws.h>
#endif
#include "mediaplayerplugininterface.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include "loopcontrol.h"
#include "audiodevice.h"
#include "videowidget.h"
#include "audiowidget.h"
#include "mediaplayerstate.h"
-#if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES)
-#define USE_REALTIME_AUDIO_THREAD
-#endif
+
extern VideoWidget *videoUI; // now only needed to tell it to play a frame
extern MediaPlayerState *mediaPlayerState;
#define DecodeLoopDebug(x) qDebug x
//#define DecodeLoopDebug(x)
static char *audioBuffer = NULL;
static AudioDevice *audioDevice = NULL;
@@ -247,25 +246,25 @@ void LoopControl::startVideo() {
if ( hasAudioChannel && !isMuted ) {
bool done = FALSE;
do {
/*
videoMutex->lock();
current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
//current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
-
+
// Sync to Audio
// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq);
long mSecsToNextFrame = 0;
if ( current_frame == prev_frame ) {
int nf = current_frame + 1;
if ( nf > 0 && nf != total_video_frames )
// mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin );
mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() );
}
videoMutex->unlock();
@@ -303,43 +302,43 @@ void LoopControl::startVideo() {
videoMutex->lock();
bool check = current_frame && current_frame > prev_frame;
videoMutex->unlock();
if ( check ) {
videoMutex->lock();
if ( current_frame > prev_frame + 1 ) {
// qDebug("skipped a frame");
mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
}
prev_frame = current_frame;
- if ( moreVideo = videoUI->playVideo() )
+ if ( moreVideo = videoUI->playVideo() )
emitChangePos = TRUE;
videoMutex->unlock();
}
- } else
+ } else
moreVideo = FALSE;
}
- if ( !moreVideo && !moreAudio )
+ if ( !moreVideo && !moreAudio )
emitPlayFinished = TRUE;
pthread_exit(NULL);
}
void LoopControl::startAudio() {
moreAudio = TRUE;
-
+
while ( moreAudio ) {
if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) {
audioMutex->lock();
currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream );
if ( currentSample == 0 )
currentSample = audioSampleCounter + 1;
// if ( currentSample != audioSampleCounter + 1 )
// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
@@ -395,25 +394,25 @@ void LoopControl::startAudio() {
} else {
if ( mediaPlayerState->curDecoder() && hasAudioChannel )
usleep( 100000 ); // Check every 1/10 sec to see if mute is off
else
moreAudio = FALSE;
}
}
// qDebug( "End of file" );
- if ( !moreVideo && !moreAudio )
+ if ( !moreVideo && !moreAudio )
emitPlayFinished = TRUE;
pthread_exit(NULL);
}
void LoopControl::killTimers() {
if ( hasVideoChannel ) {
if ( pthread_self() != video_tid ) {
if ( pthread_cancel(video_tid) == 0 ) {
void *thread_result = 0;
if ( pthread_join(video_tid,&thread_result) != 0 )
// qDebug("thread join error 1");
@@ -475,25 +474,25 @@ void LoopControl::setPaused( bool pause ) {
playtime.restart();
playtime = playtime.addMSecs( -whenPaused );
whenPaused = 0;
startTimers();
}
}
void LoopControl::stop( bool willPlayAgainShortly ) {
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
- disabledSuspendScreenSaver = FALSE;
+ disabledSuspendScreenSaver = FALSE;
// Re-enable the suspend mode
QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
}
#endif
if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
killTimers();
mediaPlayerState->curDecoder()->close();
if ( audioDevice ) {
@@ -503,52 +502,52 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
audioBuffer = 0;
}
}
}
bool LoopControl::init( const QString& filename ) {
stop();
fileName = filename;
stream = 0; // only play stream 0 for now
current_frame = total_video_frames = total_audio_samples = 0;
-
+
// qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
-
+
// ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
mediaPlayerState->libMpeg3Decoder()->close();
}
}
if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) )
return FALSE;
hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
if ( hasAudioChannel ) {
int astream = 0;
channels = mediaPlayerState->curDecoder()->audioChannels( astream );
DecodeLoopDebug(( "channels = %d\n", channels ));
-
+
if ( !total_audio_samples )
total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
mediaPlayerState->setLength( total_audio_samples );
-
+
freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
DecodeLoopDebug(( "frequency = %d\n", freq ));
audioSampleCounter = 0;
static const int bytes_per_sample = 2; //16 bit
audioDevice = new AudioDevice( freq, channels, bytes_per_sample );
audioBuffer = new char[ audioDevice->bufferSize() ];
channels = audioDevice->channels();
//### must check which frequency is actually used.
@@ -585,27 +584,27 @@ bool LoopControl::init( const QString& filename ) {
connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
//setBackgroundColor( black );
return TRUE;
}
void LoopControl::play() {
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
if ( !disabledSuspendScreenSaver ) {
- disabledSuspendScreenSaver = TRUE;
+ disabledSuspendScreenSaver = TRUE;
// Stop the screen from blanking and power saving state
- QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
+ QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
<< ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
}
#endif
//begin = clock();
playtime.start();
startTimers();
//updateGeometry();
}
void LoopControl::setMute( bool on ) {