Author: nyadav Date: Tue Jul 12 10:50:31 2011 New Revision: 52653
URL: http://svn.reactos.org/svn/reactos?rev=52653&view=rev Log: [AUDSRV] server ready to accept actual buffer from client
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/rpc.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/idl/audsrvrpc.idl
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.h URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/service... ============================================================================== --- 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] Tue Jul 12 10:50:31 2011 @@ -44,7 +44,8 @@
/*Balance from -1.0 to 1.0*/ float balance; - BOOL ready; + /*state cycle 0->buffer write -> 1 -> filtering -> 2 ->playback -> 0*/ + char state; /*This buffer is filled by the client using RPC calls*/ PVOID genuinebuf; int length_genuine; @@ -56,6 +57,7 @@ PVOID maxsamplevalue;
HANDLE stream_played_event; + HANDLE buffer_write_event; HANDLE threadready; HANDLE thread; CRITICAL_SECTION CriticalSection; @@ -116,6 +118,9 @@ int mute, float balance);
+long WriteBuffer(LONG streamid, + LONG length, + LPVOID buffer); /*mixer.c*/ void * MixS8(MixerEngine * mixer, int buffer);
Modified: branches/nyadav-audio-branch/base/services/audsrv/mixer.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/service... ============================================================================== --- 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] Tue Jul 12 10:50:31 2011 @@ -4,7 +4,6 @@ * FILE: services/mixer.c * PURPOSE: Audio Server * COPYRIGHT: Copyright 2011 Neeraj Yadav - */
#include "audsrv.h" @@ -32,7 +31,7 @@ length = stream->length_filtered; while(stream->next != NULL) { - if(stream->length_filtered > length && stream->ready == TRUE ) + if(stream->length_filtered > length && stream->state == 2 ) length = stream->length_filtered; stream = stream->next; } @@ -47,11 +46,11 @@ minsamplevalue = 0; maxsamplevalue = 0;
- while( stream != NULL) + while(stream != NULL) { EnterCriticalSection(&(stream->CriticalSection));
- if(stream->ready == TRUE && *(short *) stream->minsamplevalue != 0 && *(short *) stream->minsamplevalue != 0) + if(stream->state == 2 && *(short *) stream->minsamplevalue != 0 && *(short *) stream->minsamplevalue != 0) { coefficient = 1.0;
@@ -78,12 +77,14 @@ localsinkbuf[i] = (short) (( (localsinkbuf[i] * streamcount) + ((short)((float) localsrcbuf[i] ) * coefficient) ) / (streamcount +1)); }
+ stream->state = 0; + HeapFree(GetProcessHeap(), + 0, + stream->filteredbuf); + + SetEvent(stream->stream_played_event); } - //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++;
Modified: branches/nyadav-audio-branch/base/services/audsrv/rpc.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/service... ============================================================================== --- branches/nyadav-audio-branch/base/services/audsrv/rpc.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/base/services/audsrv/rpc.c [iso-8859-1] Tue Jul 12 10:50:31 2011 @@ -79,6 +79,14 @@ return stream; }
+long AUDPlayBuffer( IN RPC_BINDING_HANDLE hBinding, + LONG streamid, + LONG length, + LPVOID buffer) +{ + WriteBuffer(streamid,length,NULL); + return 0; +} /*************************************************************************/ void __RPC_FAR *__RPC_USER midl_user_allocate(SIZE_T len) {
Modified: branches/nyadav-audio-branch/base/services/audsrv/stream.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/service... ============================================================================== --- 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] Tue Jul 12 10:50:31 2011 @@ -4,7 +4,6 @@ * FILE: services/stream.c * PURPOSE: Audio Server * COPYRIGHT: Copyright 2011 Neeraj Yadav - */
#include "audsrv.h" @@ -15,92 +14,53 @@ pengine->streamidpool += 1; return streamid; } +BOOL FilterAudio(LPVOID param) +{ + ServerStream * localstream = (ServerStream *) param; + + EnterCriticalSection(&(localstream->CriticalSection)); + + if(localstream->state == 1) + { + /*Fake Filter,Simply gives the genuine buffer as filtered buffer*/ + /*minsamplevalue and maxsamplevalue must be calculated during filtering*/ + /*Filter must ensure that all the samples are distributed evenly about 0 in case of signed samples*/ + localstream->length_filtered = localstream->length_genuine; + localstream->filteredbuf = HeapAlloc(GetProcessHeap(), + 0, + localstream->length_filtered); + + memcpy(localstream->filteredbuf,localstream->genuinebuf,localstream->length_filtered); + + HeapFree(GetProcessHeap(), + 0, + localstream->genuinebuf); + + *((int *)localstream->minsamplevalue) = -32766; + *((int *)localstream->maxsamplevalue) = 32766; + + localstream->state = 2; + + LeaveCriticalSection(&(localstream->CriticalSection)); + return TRUE; + } + else + { + LeaveCriticalSection(&(localstream->CriticalSection)); + return FALSE; + } +}
DWORD WINAPI RunStreamThread(LPVOID param) { - UINT i = 0; ServerStream * localstream = (ServerStream *) param;
-/*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; - PSHORT tempbuf; - - - localstream->length_filtered = localstream->freq * localstream->channels * localstream->bitspersample / 8; - tempbuf = (PSHORT) HeapAlloc(GetProcessHeap(), - 0, - localstream->length_filtered); - - while (i < localstream->length_filtered / 2) - { - 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) - { - if(tempbuf[i]<minimum) - minimum = tempbuf[i]; - }else - minimum = tempbuf[i]; - if(initmax) - { - if(tempbuf[i]>maximum) - maximum = tempbuf[i]; - }else - maximum = tempbuf[i]; - - if(initmin == FALSE || initmax == FALSE ) - { - initmin = TRUE; - initmax = TRUE; - } - i++; - - 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) - { - if(tempbuf[i]<minimum) - minimum = tempbuf[i]; - } - else - minimum = tempbuf[i]; - - if(initmax) - { - if(tempbuf[i]>maximum) - maximum = tempbuf[i]; - }else - maximum = tempbuf[i]; - i++; - } - - *((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 (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); + if(FilterAudio(param) == TRUE ) + WaitForSingleObject(localstream->stream_played_event,INFINITE); } /*Clean Stream's data*/ } @@ -157,7 +117,7 @@ newstream->channels = channels; /*TODO validation*/ newstream->channelmask = channelmask; /*TODO validation*/
- newstream->ready = FALSE; + newstream->state = 0; newstream->length_genuine = 0; newstream->genuinebuf = NULL; newstream->length_filtered = 0; @@ -177,6 +137,11 @@ FALSE, NULL);
+ newstream->buffer_write_event = CreateEvent(NULL, + FALSE, + FALSE, + NULL); + newstream->threadready = CreateEvent(NULL, FALSE, FALSE, @@ -231,5 +196,43 @@ return 0; }
+long WriteBuffer(LONG streamid, + LONG length, + LPVOID buffer) +{ + int i =0; + PSHORT tempbuf; + ServerStream * localstream = pengine->serverstreamlist; + while(localstream!=NULL) + { + if(localstream->streamid == streamid) break; + localstream = localstream->next; + } + + if(localstream == NULL) + return -1; + + EnterCriticalSection(&(localstream->CriticalSection)); + + if(localstream->state == 0) + { + localstream->length_genuine = localstream->freq * localstream->channels * localstream->bitspersample / 8; + localstream->genuinebuf = tempbuf = (PSHORT) HeapAlloc(GetProcessHeap(), + 0, + localstream->length_genuine); + + while (i < localstream->length_genuine / 2) + { + tempbuf[i+1] = tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 48000); + i+=2; + } + + localstream->state = 1; + } + + LeaveCriticalSection(&(localstream->CriticalSection)); + + return 0; +} /*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/au... ============================================================================== --- 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] Tue Jul 12 10:50:31 2011 @@ -92,7 +92,19 @@
/*Check Connection Status If not connected call Connect()*/ /*If connected Properly call the remote audsrv_play() function,This will be a blocking call, placing a dummy wait function here is a good idea.*/ - Sleep(1000); + RpcTryExcept + { + AUDPlayBuffer (audsrv_v0_0_c_ifspec, + clientstream->stream, + 0, + NULL); + } + RpcExcept(1) + { + status = RpcExceptionCode(); + } + RpcEndExcept + clientstream->callbacks.BufferCopied(0); } clientstream->callbacks.PlayComplete(0);
Modified: branches/nyadav-audio-branch/include/reactos/idl/audsrvrpc.idl URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/include/reac... ============================================================================== --- branches/nyadav-audio-branch/include/reactos/idl/audsrvrpc.idl [iso-8859-1] (original) +++ branches/nyadav-audio-branch/include/reactos/idl/audsrvrpc.idl [iso-8859-1] Tue Jul 12 10:50:31 2011 @@ -40,5 +40,5 @@ {
long AUDInitStream([in] handle_t h1,[in]LONG frequency,[in]int channels,[in]int bitspersample,[in]int datatype,[in] ULONG channelmask,[in]int volume,[in]int mute,[in]float balance); - + long AUDPlayBuffer([in] handle_t h1,[in]LONG streamid,[in]LONG length,[in]LPVOID buffer); }