diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-01-17 08:51:39 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-01-17 08:51:39 +0000 |
| commit | acb3d9b6c3df6dd3eaedefde0f6d82f51681158a (patch) | |
| tree | 28e76c1e8db5baddeb75ae97075ecf76977455e7 /src/plugins/Output/waveout/outputwaveout.cpp | |
| parent | 49cdf460a519565b113892095c874c15ef755bc5 (diff) | |
| download | qmmp-acb3d9b6c3df6dd3eaedefde0f6d82f51681158a.tar.gz qmmp-acb3d9b6c3df6dd3eaedefde0f6d82f51681158a.tar.bz2 qmmp-acb3d9b6c3df6dd3eaedefde0f6d82f51681158a.zip | |
added win32 patches
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2537 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Output/waveout/outputwaveout.cpp')
| -rw-r--r-- | src/plugins/Output/waveout/outputwaveout.cpp | 107 |
1 files changed, 62 insertions, 45 deletions
diff --git a/src/plugins/Output/waveout/outputwaveout.cpp b/src/plugins/Output/waveout/outputwaveout.cpp index f95100aac..57b70b7e3 100644 --- a/src/plugins/Output/waveout/outputwaveout.cpp +++ b/src/plugins/Output/waveout/outputwaveout.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009 by Ilya Kotov *
+ * Copyright (C) 2009-2012 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -31,19 +31,19 @@ #include <qmmp/visual.h>
#include "outputwaveout.h"
-#define MAX_WAVEBLOCKS 32
+#define MAX_WAVEBLOCKS 256
static CRITICAL_SECTION cs;
static HWAVEOUT dev = NULL;
-static int ScheduledBlocks = 0;
+static unsigned int ScheduledBlocks = 0;
static int PlayedWaveHeadersCount = 0; // free index
static WAVEHDR* PlayedWaveHeaders [MAX_WAVEBLOCKS];
-static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 )
+static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
- if ( uMsg == WOM_DONE )
+ if (uMsg == WOM_DONE)
{
EnterCriticalSection (&cs);
PlayedWaveHeaders [PlayedWaveHeadersCount++] = (WAVEHDR*) dwParam1;
@@ -52,38 +52,28 @@ static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DW }
static void
-free_memory ( void )
+free_memory (void)
{
WAVEHDR* wh;
HGLOBAL hg;
- EnterCriticalSection ( &cs );
+ EnterCriticalSection (&cs);
wh = PlayedWaveHeaders [--PlayedWaveHeadersCount];
ScheduledBlocks--; // decrease the number of USED blocks
- LeaveCriticalSection ( &cs );
+ LeaveCriticalSection (&cs);
- waveOutUnprepareHeader ( dev, wh, sizeof (WAVEHDR) );
+ waveOutUnprepareHeader (dev, wh, sizeof (WAVEHDR));
- hg = GlobalHandle ( wh -> lpData ); // Deallocate the buffer memory
+ hg = GlobalHandle (wh -> lpData); // Deallocate the buffer memory
GlobalUnlock (hg);
GlobalFree (hg);
- hg = GlobalHandle ( wh ); // Deallocate the header memory
+ hg = GlobalHandle (wh); // Deallocate the header memory
GlobalUnlock (hg);
GlobalFree (hg);
}
-static int
-Box ( const char* msg )
-{
- //MessageBox ( NULL, ms"Error Message . . .", MB_OK | MB_ICONEXCLAMATION );
- return -1;
-}
-
-
-
-OutputWaveOut::OutputWaveOut(QObject * parent)
- : Output(parent)
+OutputWaveOut::OutputWaveOut(QObject * parent) : Output(parent)
{
//m_connection = 0;
//m_dev = 0;
@@ -139,7 +129,7 @@ bool OutputWaveOut::initialize(quint32 freq, int chan, Qmmp::AudioFormat format) }
waveOutReset (dev);
- InitializeCriticalSection ( &cs );
+ InitializeCriticalSection (&cs);
configure(freq, chan, format);
return true;
@@ -159,60 +149,88 @@ qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len) void* allocptr;
len = qMin(len, (qint64)1024);
- do
- {
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
- free_memory ();
-
- if ( ScheduledBlocks < sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders) ) // wait for a free block ...
- break;
- usleep (500);
+
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory ();
+ if (ScheduledBlocks >= sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders)) // wait for a free block ...
+ {
+ usleep(500);
+ return 0;
+ }
+
+ if ((hg2 = GlobalAlloc (GMEM_MOVEABLE, len)) == NULL) // allocate some memory for a copy of the buffer
+ {
+ qWarning("OutputWaveOut: GlobalAlloc failed");
+ return 0;
}
- while (1);
-
- if ( (hg2 = GlobalAlloc ( GMEM_MOVEABLE, len )) == NULL ) // allocate some memory for a copy of the buffer
- return Box ( "GlobalAlloc failed." );
allocptr = GlobalLock (hg2);
- CopyMemory ( allocptr, data, len ); // Here we can call any modification output functions we want....
+ CopyMemory (allocptr, data, len); // Here we can call any modification output functions we want....
- if ( (hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL ) // now make a header and WRITE IT!
+ if ((hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL) // now make a header and WRITE IT!
return -1;
wh = (wavehdr_tag*)GlobalLock (hg);
wh->dwBufferLength = len;
wh->lpData = (CHAR *)allocptr;
- if ( waveOutPrepareHeader ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR )
+ if (waveOutPrepareHeader (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
{
GlobalUnlock (hg);
GlobalFree (hg);
return -1;
}
- if ( waveOutWrite ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR )
+ if (waveOutWrite (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
{
GlobalUnlock (hg);
GlobalFree (hg);
return -1;
}
- EnterCriticalSection ( &cs );
+ EnterCriticalSection (&cs);
ScheduledBlocks++;
- LeaveCriticalSection ( &cs );
+ LeaveCriticalSection (&cs);
return len;
}
+void OutputWaveOut::drain()
+{
+ while (ScheduledBlocks > 0)
+ {
+ Sleep(ScheduledBlocks);
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory();
+ }
+}
+
+void OutputWaveOut::suspend()
+{
+ waveOutPause(dev);
+}
+
+void OutputWaveOut::resume()
+{
+ waveOutRestart(dev);
+}
+
+void OutputWaveOut::reset()
+{
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory ();
+ waveOutReset (dev);
+}
+
void OutputWaveOut::uninitialize()
{
if (dev)
{
- while ( ScheduledBlocks > 0 )
+ while (ScheduledBlocks > 0)
{
Sleep (ScheduledBlocks);
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
free_memory ();
}
@@ -221,8 +239,7 @@ void OutputWaveOut::uninitialize() dev = 0;
}
- DeleteCriticalSection ( &cs );
+ DeleteCriticalSection (&cs);
ScheduledBlocks = 0;
return;
}
-
|
