Author: nyadav
Date: Sun Jul 10 12:55:38 2011
New Revision: 52602
URL:
http://svn.reactos.org/svn/reactos?rev=52602&view=rev
Log:
[AUDSRV] Fix some Thread Synchronization bugs and some style fixes
Modified:
branches/nyadav-audio-branch/base/services/audsrv/audsrv.h
branches/nyadav-audio-branch/base/services/audsrv/mixer.c
branches/nyadav-audio-branch/base/services/audsrv/stream.c
branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c
branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] Sun Jul 10
12:55:38 2011
@@ -55,9 +55,10 @@
PVOID minsamplevalue;
PVOID maxsamplevalue;
- HANDLE played;
+ HANDLE stream_played_event;
HANDLE threadready;
HANDLE thread;
+ CRITICAL_SECTION CriticalSection;
struct ServerStream * next;
} ServerStream;
Modified: branches/nyadav-audio-branch/base/services/audsrv/mixer.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] Sun Jul 10
12:55:38 2011
@@ -13,6 +13,9 @@
{
return NULL;
}
+
+/*Filter Should ensure that sample data is divided equally on both side of Analog-Zero
Sample value[0 for signed data,maxattainablevalue/2 for unsigned]*/
+
void * MixS16(MixerEngine * mixer,
int buffer)
{
@@ -41,15 +44,24 @@
/*Perform Actual Mixing*/
stream = mixer->serverstreamlist;
- minsamplevalue = *(short *) stream->minsamplevalue;
- maxsamplevalue = *(short *) stream->maxsamplevalue;
+ minsamplevalue = 0;
+ maxsamplevalue = 0;
while( stream != NULL)
{
- localsrcbuf = stream->filteredbuf;
- if(stream->ready == TRUE )
+ EnterCriticalSection(&(stream->CriticalSection));
+
+ if(stream->ready == TRUE && *(short *) stream->minsamplevalue != 0
&& *(short *) stream->minsamplevalue != 0)
{
coefficient = 1.0;
+
+ localsrcbuf = stream->filteredbuf;
+
+ if(minsamplevalue == 0)
+ minsamplevalue = *(short *) stream->minsamplevalue;
+
+ if(maxsamplevalue == 0)
+ maxsamplevalue = *(short *) stream->maxsamplevalue;
if( *(short *)stream->maxsamplevalue != maxsamplevalue ||
*(short *)stream->minsamplevalue != minsamplevalue )
@@ -60,12 +72,20 @@
else
coefficient = (float) minsamplevalue / (float)*(short
*)stream->minsamplevalue;
}
+
for(i=0;i<stream->length_filtered/sizeof(short);i++)
{
localsinkbuf[i] = (short) (( (localsinkbuf[i] * streamcount) +
((short)((float) localsrcbuf[i] ) * coefficient) ) / (streamcount +1));
}
+
}
//stream->ready = 0; /*TODO Enable it when actual filter thread starts
working*/
+ //HeapFree(GetProcessHeap(),
+ // 0,
+ // stream->filteredbuf);
+ SetEvent(stream->stream_played_event);
+ LeaveCriticalSection(&(stream->CriticalSection));
+
streamcount++;
stream = stream->next;
}
Modified: branches/nyadav-audio-branch/base/services/audsrv/stream.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] Sun Jul 10
12:55:38 2011
@@ -12,7 +12,7 @@
long GetNewStreamID()
{
long streamid= pengine->streamidpool;
- pengine->streamidpool+=1;
+ pengine->streamidpool += 1;
return streamid;
}
@@ -23,11 +23,11 @@
/*UGLY HACK--WILL be removed soon-- fill filtered buffer (1 second duration in the master
stream format) directly until we are in a condition to get buffer directly from the
client*/
/******************************************************/
- BOOL initmin=FALSE,initmax =FALSE;
- short minimum=0,maximum=0;
+ BOOL initmin=FALSE,initmax = FALSE;
+ short minimum=0,maximum = 0;
PSHORT tempbuf;
- localstream->ready =TRUE;
+
localstream->length_filtered = localstream->freq * localstream->channels *
localstream->bitspersample / 8;
tempbuf = (PSHORT) HeapAlloc(GetProcessHeap(),
0,
@@ -35,12 +35,12 @@
while (i < localstream->length_filtered / 2)
{
- tempbuf[i] = 0x7FFF * sin(0.5 * (i - 1) * 500 * 6.28 / 48000);
+ tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 48000);
if((localstream->streamid %2) == 0)
- tempbuf[i] = 0;
-
- if(initmin)
+ tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 24000);
+
+ if(initmin)
{
if(tempbuf[i]<minimum)
minimum = tempbuf[i];
@@ -60,10 +60,10 @@
}
i++;
- tempbuf[i] = 0x7FFF * sin(0.5 * (i - 2) * 500 * 6.28 / 48000);
-
- if((localstream->streamid %2) != 0)
- tempbuf[i] = 0;
+ tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 48000);
+
+ if((localstream->streamid %2) == 0)
+ tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 24000);
if(initmin)
@@ -86,13 +86,21 @@
*((int *)localstream->minsamplevalue) = minimum;
*((int *)localstream->maxsamplevalue) = maximum;
localstream->filteredbuf = tempbuf;
+ localstream->ready =TRUE;
+
/******************************************************/
+/*Do Some Initialization If needed.Only After these Initialization remaining system will
be told that stream is ready*/
SetEvent(localstream->threadready);
- while (1)
- {
- OutputDebugStringA("Stream Thread Running.");
- Sleep(100);
+ while (TRUE)
+ {
+ /*Wait For Data Write Event,currently NO Wait considering Data has always been
written*/
+
+ EnterCriticalSection(&(localstream->CriticalSection));
+
+ LeaveCriticalSection(&(localstream->CriticalSection));
+ /*Wait For Stream Played Event*/
+ WaitForSingleObject(localstream->stream_played_event,INFINITE);
}
/*Clean Stream's data*/
}
@@ -164,7 +172,7 @@
newstream->next = NULL;
- newstream->played = CreateEvent(NULL,
+ newstream->stream_played_event = CreateEvent(NULL,
FALSE,
FALSE,
NULL);
@@ -174,7 +182,13 @@
FALSE,
NULL);
- if(newstream->played == NULL || newstream->threadready == NULL)
+ if(newstream->stream_played_event == NULL || newstream->threadready == NULL)
+ goto error;
+
+ newstream->streamid=GetNewStreamID();
+
+ if (!InitializeCriticalSectionAndSpinCount(&(newstream->CriticalSection),
+ 0x00000400) )
goto error;
newstream->thread=CreateThread(NULL,
@@ -187,11 +201,10 @@
if(newstream->thread == NULL)
goto error;
-
WaitForSingleObject(newstream->threadready,
INFINITE);
- newstream->streamid=GetNewStreamID();
+
if(localstream == NULL)
{
@@ -212,8 +225,11 @@
return newstream->streamid;
error:
- HeapFree(GetProcessHeap(), 0, newstream);
+ HeapFree(GetProcessHeap(),
+ 0,
+ newstream);
return 0;
}
-/*Dont forget to clean ServerStream's minsamplevalue and maxsamplevalue while
removing the stream*/
+/*Dont forget to clean ServerStream's minsamplevalue and maxsamplevalue while
removing the stream*/
+/*Delete Critical Section while cleaning Stream*/
Modified: branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/dll/win32/a…
==============================================================================
--- branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c [iso-8859-1] Sun Jul 10
12:55:38 2011
@@ -14,7 +14,9 @@
/*Initialize an audio stream
*Return -1 if callbacks are NULL pointers
*/
-WINAPI int InitStream (ClientStream * clientstream,
+int
+WINAPI
+InitStream (ClientStream * clientstream,
LONG frequency,
int channels,
int bitspersample,
@@ -69,7 +71,9 @@
return 0;
}
-WINAPI int PlayAudio ( ClientStream * clientstream )
+int
+WINAPI
+PlayAudio ( ClientStream * clientstream )
{
/*This is an ActiveScheduler*/
clientstream->callbacks.OpenComplete(0);
@@ -97,7 +101,9 @@
return 0;
}
-WINAPI int StopAudio (ClientStream * clientstream )
+int
+WINAPI
+StopAudio (ClientStream * clientstream )
{
/*Server Side termination is remaining*/
/*If connected Properly call the remote audsrv_stop() function*/
@@ -106,19 +112,25 @@
return 0;
}
-WINAPI int Volume(ClientStream * clientstream,
+int
+WINAPI
+Volume(ClientStream * clientstream,
int * volume )
{
return 0;
}
-WINAPI int SetVolume(ClientStream * clientstream ,
+int
+WINAPI
+SetVolume(ClientStream * clientstream ,
const int newvolume)
{
return 0;
}
-WINAPI int Write(ClientStream * clientstream ,
+int
+WINAPI
+Write(ClientStream * clientstream ,
const char * aData)
{
if(clientstream->dead)
@@ -129,13 +141,17 @@
return 0;
}
-WINAPI int SetBalance(ClientStream * clientstream ,
+int
+WINAPI
+SetBalance(ClientStream * clientstream ,
float balance)
{
return 0;
}
-WINAPI int GetBalance(ClientStream * clientstream ,
+int
+WINAPI
+GetBalance(ClientStream * clientstream ,
float * balance)
{
return 0;
Modified: branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/include/rea…
==============================================================================
--- branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1]
(original)
+++ branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1] Sun
Jul 10 12:55:38 2011
@@ -24,7 +24,9 @@
} ClientStream;
/********************API Functions******************/
-WINAPI int InitStream (ClientStream * clientstream,
+int
+WINAPI
+InitStream (ClientStream * clientstream,
LONG frequency,
int channels,
int bitspersample,
@@ -34,18 +36,34 @@
int mute,
float balance);
-WINAPI int PlayAudio ( ClientStream * clientstream);
-WINAPI int StopAudio (ClientStream * clientstream );
+int
+WINAPI
+PlayAudio ( ClientStream * clientstream);
-WINAPI int Volume(ClientStream * clientstream,
+int
+WINAPI
+StopAudio (ClientStream * clientstream );
+
+int
+WINAPI
+Volume(ClientStream * clientstream,
int * volume );
-WINAPI int SetVolume(ClientStream * clientstream ,
+int
+WINAPI
+SetVolume(ClientStream * clientstream ,
const int newvolume);
-WINAPI int Write(ClientStream * clientstream ,
+int
+WINAPI
+Write(ClientStream * clientstream ,
const char * aData);
-WINAPI int SetBalance(ClientStream * clientstream ,
+
+int
+WINAPI
+SetBalance(ClientStream * clientstream ,
float balance);
-WINAPI int GetBalance(ClientStream * clientstream ,
+int
+WINAPI
+GetBalance(ClientStream * clientstream ,
float * balance);
#endif