Author: nyadav Date: Mon Jun 6 12:20:41 2011 New Revision: 52115
URL: http://svn.reactos.org/svn/reactos?rev=52115&view=rev Log: [AUDSRV] Style Fixes,Warning Fixes,Documentation etc
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.c 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/dll/win32/audsrvapi/dllmain.c branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/service... ============================================================================== --- branches/nyadav-audio-branch/base/services/audsrv/audsrv.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/base/services/audsrv/audsrv.c [iso-8859-1] Mon Jun 6 12:20:41 2011 @@ -3,20 +3,21 @@ * LICENSE: GPL - See COPYING in the top level directory * FILE: services/audsrv.c * PURPOSE: Audio Server - * COPYRIGHT: Copyright 2011 Pankaj Yadav + * COPYRIGHT: Copyright 2011 Neeraj Yadav
*/
-/* INCLUDES *****************************************************************/ - #include "audsrv.h"
-/* GLOBALS ******************************************************************/ - -static VOID CALLBACK ServiceMain(DWORD, LPWSTR *); +static VOID CALLBACK ServiceMain(DWORD, + LPWSTR *); + static DWORD ServiceInit(VOID); -static BOOL WINAPI close ( DWORD dwCtrlType ); + +static BOOL WINAPI close (DWORD dwCtrlType); + static WCHAR ServiceName[] = L"AudSrv"; + static SERVICE_TABLE_ENTRYW ServiceTable[2] = { { ServiceName, ServiceMain }, @@ -25,9 +26,6 @@
SERVICE_STATUS ServiceStatus; SERVICE_STATUS_HANDLE ServiceStatusHandle; - - -HANDLE MyHeap = NULL;
#define _2pi 6.283185307179586476925286766559
@@ -44,10 +42,11 @@ const GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {0x00000003L, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; const GUID KSDATAFORMAT_SPECIFIER_WAVEFORMATEX = {0x05589f81L, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
+/*Global Pointer to MixerEngine Structure*/ MixerEngine engine,*pengine; -/* FUNCTIONS ****************************************************************/ - -static VOID + +static +VOID UpdateServiceStatus(DWORD dwState) { ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; @@ -81,7 +80,7 @@ { case SERVICE_CONTROL_STOP: DPRINT(" SERVICE_CONTROL_STOP received\n"); - close(CTRL_CLOSE_EVENT); + close(CTRL_CLOSE_EVENT); UpdateServiceStatus(SERVICE_STOPPED); return ERROR_SUCCESS;
@@ -103,7 +102,7 @@
case SERVICE_CONTROL_SHUTDOWN: DPRINT(" SERVICE_CONTROL_SHUTDOWN received\n"); - close(CTRL_CLOSE_EVENT); + close(CTRL_CLOSE_EVENT); UpdateServiceStatus(SERVICE_STOPPED); return ERROR_SUCCESS;
@@ -113,7 +112,9 @@ } }
-static VOID CALLBACK +static +VOID +CALLBACK ServiceMain(DWORD argc, LPWSTR *argv) { @@ -151,36 +152,85 @@ DPRINT("ServiceMain() done\n"); }
- - -void mixandfill(MixerEngine * mixer,int buffer) -{ - while(WaitForSingleObject(mixer->streampresent,100)!=0){if(mixer->dead) return;} /*Check if there is at least one stream present.*/ - if(mixer->masterdatatype == 0)/*signed int*/ - { - if(mixer->masterbitspersample == 8)mixs8(mixer,buffer);else if(mixer->masterbitspersample == 16) mixs16(mixer,buffer);else if(mixer->masterbitspersample == 32) mixs32(mixer,buffer);else if(mixer->masterbitspersample == 64) mixs64(mixer,buffer); - } - else if (mixer->masterdatatype == 1)/*unsigned int*/ - { - if(mixer->masterbitspersample == 8)mixu8(mixer,buffer);else if(mixer->masterbitspersample == 16) mixu16(mixer,buffer);else if(mixer->masterbitspersample == 32) mixu32(mixer,buffer);else if(mixer->masterbitspersample == 64) mixu64(mixer,buffer); - } - else if(mixer->masterdatatype == 2)/*Float*/ - { - if(mixer->masterbitspersample == 32)mixfl32(mixer,buffer);else if(mixer->masterbitspersample == 64) mixfl64(mixer,buffer); - } - - mixer->masterbuf[buffer] = HeapAlloc(GetProcessHeap(), 0, mixer->serverstreamlist->length_filtered); - CopyMemory(mixer->masterbuf[buffer],mixer->serverstreamlist->filteredbuf,mixer->serverstreamlist->length_filtered); - mixer->bytes_to_play = mixer->serverstreamlist->length_filtered; -} +/*This Function is called repeatedly by mixer thread. + *This functions fetches FilteredBuffer from Every ClientStream Stucture + *and mixes them in oder to feed player thread*/ +void +mixandfill(MixerEngine * mixer, + int buffer) +{ + while(WaitForSingleObject(mixer->streampresent, + 100) != 0) + { + if(mixer->dead) + return; + } + + /*Master Stream's Datatype is signed int,unsigned int or float when masterdatatype =0,1 and 2 respectively*/ + if(mixer->masterdatatype == 0) + { + switch(mixer->masterbitspersample) + { + case 8: + mixs8(mixer,buffer); + break; + case 16: + mixs16(mixer,buffer); + break; + case 32: + mixs32(mixer,buffer); + break; + case 64: + mixs64(mixer,buffer); + break; + } + } + else if (mixer->masterdatatype == 1) + { + switch(mixer->masterbitspersample) + { + case 8: + mixu8(mixer,buffer); + break; + case 16: + mixu16(mixer,buffer); + break; + case 32: + mixu32(mixer,buffer); + break; + case 64: + mixu64(mixer,buffer); + break; + } + } + else if(mixer->masterdatatype == 2) + { + switch(mixer->masterbitspersample) + { + case 32: + mixfl32(mixer,buffer); + break; + case 64: + mixfl64(mixer,buffer); + break; + } + } +} + +/*Frees the Buffer Created in mixer thread*/ void freebuffer() { - HeapFree(GetProcessHeap(), 0, pengine->masterbuf[pengine->playcurrent]); - pengine->masterbuf[pengine->playcurrent] = NULL; -} + HeapFree(GetProcessHeap(), + 0, + pengine->masterbuf[pengine->playcurrent]); + + pengine->masterbuf[pengine->playcurrent] = NULL; +} + +/*Plays Master buffer pengine->masterbuf[pengine->playcurrent]*/ void playbuffer(MixerEngine * mixer,int buffer) { - SP_DEVICE_INTERFACE_DATA InterfaceData; + SP_DEVICE_INTERFACE_DATA InterfaceData; SP_DEVINFO_DATA DeviceData; PSP_DEVICE_INTERFACE_DETAIL_DATA DetailData; HDEVINFO DeviceHandle; @@ -191,8 +241,9 @@ DWORD Length; BOOL Result; NTSTATUS Status; -if(mixer->masterbuf[buffer]) -{ + + if(mixer->masterbuf[buffer]) + { // // Get a handle to KS Audio Interfaces // @@ -201,7 +252,6 @@ NULL, DIGCF_DEVICEINTERFACE |DIGCF_PRESENT);
- //printf("DeviceHandle %p\n", DeviceHandle);
// // Enumerate the first interface @@ -214,7 +264,6 @@ 1, &InterfaceData);
- //printf("SetupDiEnumDeviceInterfaces %u Error %ld\n", Result, GetLastError());
// // Get the interface details (namely the device path) @@ -233,7 +282,6 @@ NULL, &DeviceData);
- //wprintf(L"SetupDiGetDeviceInterfaceDetail %u Path DetailData %s\n", Result, (LPWSTR)&DetailData->DevicePath[0]);
// // Open a handle to the device @@ -246,7 +294,6 @@ FILE_ATTRIBUTE_NORMAL, NULL);
- //printf("Handle %p\n", mixer->FilterHandle);
// // Close the interface handle and clean up @@ -279,41 +326,37 @@ // // Setup the KS Data Format Information // - //printf("DataFormat %p %p\n", DataFormat,(PVOID)((((ULONG_PTR)DataFormat + 7)) & ~7));
DataFormat->Flags = 0; DataFormat->Reserved = 0; DataFormat->MajorFormat = KSDATAFORMAT_TYPE_AUDIO; - if(mixer->masterdatatype == 0 || mixer->masterdatatype == 1) - DataFormat->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - else - DataFormat->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; + if(mixer->masterdatatype == 0 || mixer->masterdatatype == 1) + DataFormat->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + else + DataFormat->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; DataFormat->Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX; DataFormat->SampleSize = mixer->masterchannels * mixer->masterbitspersample / 8; DataFormat->FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEXTENSIBLE);
WaveFormat->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; - WaveFormat->Format.nChannels = mixer->masterchannels; + WaveFormat->Format.nChannels = mixer->masterchannels; WaveFormat->Format.nSamplesPerSec = mixer->masterfreq; WaveFormat->Format.nBlockAlign = (mixer->masterchannels * mixer->masterbitspersample)/8;; WaveFormat->Format.nAvgBytesPerSec = WaveFormat->Format.nSamplesPerSec * WaveFormat->Format.nBlockAlign; WaveFormat->Format.wBitsPerSample = mixer->masterbitspersample; WaveFormat->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); - WaveFormat->dwChannelMask = mixer->masterchannelmask; + WaveFormat->dwChannelMask = mixer->masterchannelmask; WaveFormat->Samples.wValidBitsPerSample = mixer->masterbitspersample; - if(mixer->masterdatatype == 0 || mixer->masterdatatype == 1) - WaveFormat->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - else - WaveFormat->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; - - - // + if(mixer->masterdatatype == 0 || mixer->masterdatatype == 1) + WaveFormat->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + else + WaveFormat->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; + + + // // Create the pin // Status = KsCreatePin(mixer->FilterHandle, PinConnect, GENERIC_READ|GENERIC_WRITE, &(mixer->PinHandle)); - - //printf("PinHandle %p Status %lx\n", mixer->PinHandle, Status); -
Length = mixer->masterfreq * mixer->masterchannels * mixer->masterbitspersample / 8; // @@ -322,7 +365,7 @@ mixer->Packet = (PKSSTREAM_HEADER)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(KSSTREAM_HEADER)); - mixer->Packet->Data = mixer->masterbuf[buffer]; + mixer->Packet->Data = mixer->masterbuf[buffer]; mixer->Packet->FrameExtent = mixer->bytes_to_play; mixer->Packet->DataUsed = mixer->bytes_to_play; mixer->Packet->Size = sizeof(KSSTREAM_HEADER); @@ -373,52 +416,96 @@ CloseHandle(mixer->FilterHandle); } } + +/*Thread Routine For Mixer Thread*/ DWORD WINAPI RunMixerThread(LPVOID param) { - MixerEngine * mixer = (MixerEngine *) param; - - SetEvent(mixer->played); - while(1) - { - while(WaitForSingleObject(mixer->played,100)!=0){if(mixer->dead)goto DEAD;} - mixandfill(mixer,1-mixer->playcurrent); - SetEvent(mixer->filled); - } + MixerEngine * mixer = (MixerEngine *) param; + + SetEvent(mixer->played); + + while(1) + { + while(WaitForSingleObject(mixer->played, + 100)!=0) + { + if(mixer->dead) + goto DEAD; + } + + mixandfill(mixer, + 1-mixer->playcurrent); + + SetEvent(mixer->filled); + } + DEAD: - printf("\nMixer Thread Ended\n"); - return 0; -} + return 0; +} + +/*Thread Routine For Player Thread*/ DWORD WINAPI RunPlayerThread(LPVOID param) { - MixerEngine * mixer = (MixerEngine *) param; - while(1) - { - while(WaitForSingleObject(mixer->filled,100)!=0){if(mixer->dead)goto DEAD;} - SetEvent(mixer->played); - playbuffer(mixer,mixer->playcurrent); - freebuffer(); - mixer->playcurrent=1-mixer->playcurrent; - } + MixerEngine * mixer = (MixerEngine *) param; + + while(1) + { + while(WaitForSingleObject(mixer->filled, + 100)!=0) + { + if(mixer->dead) + goto DEAD; + } + + SetEvent(mixer->played); + playbuffer(mixer, + mixer->playcurrent); + + freebuffer(); + + mixer->playcurrent=1-mixer->playcurrent; + }
DEAD: - printf("\nPlayer Thread Ended\n"); - return 0; -} + return 0; +} + +/*Create Mixer Thread*/ void SpawnMixerThread(MixerEngine * mixer) { - DWORD dwID; - mixer->mixerthread=CreateThread(NULL,0,RunMixerThread,pengine,0,&dwID); -} + DWORD dwID; + mixer->mixerthread=CreateThread(NULL, + 0, + RunMixerThread, + pengine, + 0, + &dwID); +} + +/*Create Player Thread*/ void SpawnPlayerThread(MixerEngine * mixer) { - DWORD dwID; - mixer->playerthread=CreateThread(NULL,0,RunPlayerThread,pengine,0,&dwID); -} + DWORD dwID; + mixer->playerthread=CreateThread(NULL, + 0, + RunPlayerThread, + pengine, + 0, + &dwID); +} + +/*Create RPC Thread*/ void SpawnRPCThread(MixerEngine * mixer) { - DWORD dwID; - mixer->rpcthread=CreateThread(NULL,0,RunRPCThread,pengine,0,&dwID); -} + DWORD dwID; + mixer->rpcthread=CreateThread(NULL, + 0, + RunRPCThread, + pengine, + 0, + &dwID); +} + void ShutdownRPC(void) { RPC_STATUS status; @@ -437,92 +524,107 @@ exit(status); } } + +/*This Functions Kills the application, in any condition*/ static BOOL WINAPI close ( DWORD dwCtrlType ) { - pengine->dead=1; - WaitForSingleObject(pengine->mixerthread,INFINITE); - WaitForSingleObject(pengine->playerthread,INFINITE); - ShutdownRPC(); - WaitForSingleObject(pengine->rpcthread,INFINITE); - - CloseHandle(pengine->mixerthread); - CloseHandle(pengine->playerthread); - CloseHandle(pengine->rpcthread); - return TRUE; + pengine->dead=1; + + WaitForSingleObject(pengine->mixerthread, + INFINITE); + WaitForSingleObject(pengine->playerthread, + INFINITE); + + ShutdownRPC(); + + WaitForSingleObject(pengine->rpcthread,INFINITE); + + CloseHandle(pengine->mixerthread); + CloseHandle(pengine->playerthread); + CloseHandle(pengine->rpcthread); + + return TRUE; }
INT wmain(int argc, char *argv[]) { INT RetCode = 0; -/*For Temporary Debug purpose, If there is any argument it acts as simple command line app,otherwise it is a NTSERVICE*/ -if(argc==1) -{ -printf("Under Construction.Please Use audsrv.exe -n to start as normal command line application.\n"); - MyHeap = HeapCreate(0, 1024 * 256, 0); - - if (!MyHeap) - { - DPRINT1("FATAL ERROR, can't create heap.\n"); - RetCode = 1; - goto err; - } - - StartServiceCtrlDispatcher(ServiceTable); -} -else -{ - pengine=&engine; - - /*Later these will be loaded from a Conf file*/ - pengine->mastervolume=1000; - pengine->mute=FALSE; - - pengine->dead=0; - pengine->streamidpool=0; - pengine->playcurrent=1; - pengine->masterbuf[0] = NULL; - pengine->masterbuf[1] = NULL; - pengine->played=CreateEvent(NULL,FALSE,FALSE,NULL); - pengine->filled=CreateEvent(NULL,FALSE,FALSE,NULL); - pengine->streampresent=CreateEvent(NULL,TRUE,FALSE,NULL); - SetConsoleCtrlHandler(close,TRUE); - SpawnMixerThread(pengine); - SpawnPlayerThread(pengine); - SpawnRPCThread(pengine); - WaitForSingleObject(pengine->mixerthread,INFINITE); - WaitForSingleObject(pengine->playerthread,INFINITE); - WaitForSingleObject(pengine->rpcthread,INFINITE); -} - err: -CloseHandle(pengine->mixerthread); -CloseHandle(pengine->playerthread); -CloseHandle(pengine->rpcthread); - if (MyHeap) - HeapDestroy(MyHeap); + + /*For Temporary Debugging purpose, If there is any argument it acts as simple command line app,otherwise it is a NTSERVICE*/ + if(argc==1) + { + StartServiceCtrlDispatcher(ServiceTable); + } + else + { + pengine=&engine; + + /*Later these will be loaded from a Conf file*/ + pengine->mastervolume=1000; + pengine->mute=FALSE; + + pengine->dead=0; + pengine->streamidpool=0; + pengine->playcurrent=1; + pengine->masterbuf[0] = NULL; + pengine->masterbuf[1] = NULL; + pengine->played=CreateEvent(NULL, + FALSE, + FALSE, + NULL); + + pengine->filled=CreateEvent(NULL, + FALSE, + FALSE, + NULL); + + pengine->streampresent=CreateEvent(NULL, + TRUE, + FALSE, + NULL); + + SetConsoleCtrlHandler(close, + TRUE); + + SpawnMixerThread(pengine); + SpawnPlayerThread(pengine); + SpawnRPCThread(pengine); + + WaitForSingleObject(pengine->mixerthread, + INFINITE); + WaitForSingleObject(pengine->playerthread, + INFINITE); + WaitForSingleObject(pengine->rpcthread,INFINITE); + } + + CloseHandle(pengine->mixerthread); + CloseHandle(pengine->playerthread); + CloseHandle(pengine->rpcthread);
return RetCode; } + static DWORD ServiceInit(VOID) { - pengine=&engine; - - /*Later these will be loaded from a Conf file*/ - pengine->mastervolume=1000; - pengine->mute=FALSE; - - pengine->dead=0; - pengine->streamidpool=0; - pengine->playcurrent=1; - pengine->masterbuf[0] = NULL; - pengine->masterbuf[1] = NULL; - pengine->played=CreateEvent(NULL,FALSE,FALSE,NULL); - pengine->filled=CreateEvent(NULL,FALSE,FALSE,NULL); - pengine->streampresent=CreateEvent(NULL,TRUE,FALSE,NULL); - SetConsoleCtrlHandler(close,TRUE); - SpawnMixerThread(pengine); - SpawnPlayerThread(pengine); - SpawnRPCThread(pengine); + pengine=&engine; + + /*Later these will be loaded from a Conf file*/ + pengine->mastervolume=1000; + pengine->mute=FALSE; + + pengine->dead=0; + pengine->streamidpool=0; + pengine->playcurrent=1; + pengine->masterbuf[0] = NULL; + pengine->masterbuf[1] = NULL; + pengine->played=CreateEvent(NULL,FALSE,FALSE,NULL); + pengine->filled=CreateEvent(NULL,FALSE,FALSE,NULL); + pengine->streampresent=CreateEvent(NULL,TRUE,FALSE,NULL); + SetConsoleCtrlHandler(close,TRUE); + SpawnMixerThread(pengine); + SpawnPlayerThread(pengine); + SpawnRPCThread(pengine);
return ERROR_SUCCESS; }
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] Mon Jun 6 12:20:41 2011 @@ -2,8 +2,8 @@ * PROJECT: ReactOS kernel * LICENSE: GPL - See COPYING in the top level directory * FILE: services/audsrv/audsrv.h - * PURPOSE: Event logging service - * COPYRIGHT: Copyright 2011 Pankaj Yadav + * PURPOSE: Audio Service + * COPYRIGHT: Copyright 2011 Neeraj Yadav */
#ifndef __AUDSRV_H__ @@ -29,79 +29,121 @@
typedef struct ServerStream { - long streamid; - int volume; - LONG freq; - int bitspersample; - int datatype; /*0=signed int,1=unsigned int,2=float*/ - int channels; - ULONG channelmask; - HANDLE played; - HANDLE threadready; - HANDLE thread; - float balance; - BOOL ready; - PVOID genuinebuf; - int length_genuine; - PVOID filteredbuf; - int length_filtered; - PVOID minsamplevalue; - PVOID maxsamplevalue; - struct ServerStream * next; + long streamid; + int volume; + LONG freq; + int bitspersample; + + /*0=signed int,1=unsigned int,2=float*/ + int datatype; + + int channels; + + /*Standard channelmasks from WINAPI/ksmeida.h*/ + ULONG channelmask; + + /*Balance from -1.0 to 1.0*/ + float balance; + BOOL ready; + /*This buffer is filled by the client using RPC calls*/ + PVOID genuinebuf; + int length_genuine; + /*This Buffer is filled by Stream-Specific Server Thread, This Buffer's matches masterbuffer specifications*/ + PVOID filteredbuf; + int length_filtered; + /*These values must be filled by Stream-Specific Server Thread,these are helful for Mixer Thread*/ + PVOID minsamplevalue; + PVOID maxsamplevalue; + + HANDLE played; + HANDLE threadready; + HANDLE thread; + + struct ServerStream * next; } ServerStream;
typedef struct MixerEngine { -/*Should be Initialized at Server Start*/ - char dead; - long streamidpool; - HANDLE played; - HANDLE filled; - HANDLE streampresent; - HANDLE mixerthread; - HANDLE playerthread; - HANDLE rpcthread; - int playcurrent; -/*Should be Initialized at Server Start from configuration file,Currently there is no configuration file so initialized to a fixed value at start*/ - int mastervolume; - BOOL mute; -/*Should be Initialized before playing First Stream*/ - long masterfreq; - int masterchannels; - unsigned long masterchannelmask; - int masterbitspersample; - int masterdatatype; - PVOID masterbuf[2]; -/*Currently don't know the future of following variables*/ - long bytes_to_play; - HANDLE FilterHandle; + /*Should be Initialized at Server Start*/ + char dead; + long streamidpool; + HANDLE played; + HANDLE filled; + HANDLE streampresent; + HANDLE mixerthread; + HANDLE playerthread; + HANDLE rpcthread; + int playcurrent; + /*Should be Initialized at Server Start from configuration file,Currently there is no configuration file so initialized to a fixed value at start*/ + int mastervolume; + BOOL mute; + /*Should be Initialized before playing First Stream*/ + long masterfreq; + int masterchannels; + unsigned long masterchannelmask; + int masterbitspersample; + int masterdatatype; + PVOID masterbuf[2]; + /*Currently don't know the future of following variables*/ + long bytes_to_play; + HANDLE FilterHandle; HANDLE PinHandle; - PKSPROPERTY Property; - PKSSTREAM_HEADER Packet; - ServerStream * serverstreamlist; + PKSPROPERTY Property; + PKSSTREAM_HEADER Packet; + ServerStream * serverstreamlist; } MixerEngine;
extern MixerEngine engine,*pengine;
/* rpc.c */ DWORD WINAPI RunRPCThread(LPVOID lpParameter); + /* audsrv.c*/ -void mixandfill(MixerEngine * mixer,int buffer); -void playbuffer(MixerEngine * mixer,int buffer); +void mixandfill(MixerEngine * mixer, + int buffer); +void playbuffer(MixerEngine * mixer, + int buffer); + /*stream.c*/ long getnewstreamid(); -long addstream(LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance); +long addstream(LONG frequency, + int channels, + int bitspersample, + int datatype, + ULONG channelmask, + int volume, + int mute, + float balance); + /*mixer.c*/ -void * mixs8(MixerEngine * mixer,int buffer); -void * mixs16(MixerEngine * mixer,int buffer); -void * mixs32(MixerEngine * mixer,int buffer); -void * mixs64(MixerEngine * mixer,int buffer); -void * mixu8(MixerEngine * mixer,int buffer); -void * mixu16(MixerEngine * mixer,int buffer); -void * mixu32(MixerEngine * mixer,int buffer); -void * mixu64(MixerEngine * mixer,int buffer); -void * mixfl32(MixerEngine * mixer,int buffer); -void * mixfl64(MixerEngine * mixer,int buffer); -/********************************/ +void * mixs8(MixerEngine * mixer, + int buffer); + +void * mixs16(MixerEngine * mixer, + int buffer); + +void * mixs32(MixerEngine * mixer, + int buffer); + +void * mixs64(MixerEngine * mixer, + int buffer); + +void * mixu8(MixerEngine * mixer, + int buffer); + +void * mixu16(MixerEngine * mixer, + int buffer); + +void * mixu32(MixerEngine * mixer, + int buffer); + +void * mixu64(MixerEngine * mixer, + int buffer); + +void * mixfl32(MixerEngine * mixer, + int buffer); + +void * mixfl64(MixerEngine * mixer, + int buffer);
#endif /* __AUDSRV_H__ */
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] Mon Jun 6 12:20:41 2011 @@ -2,34 +2,45 @@ #include "audsrv.h" void * mixs8(MixerEngine * mixer,int buffer) { + return NULL; } void * mixs16(MixerEngine * mixer,int buffer) { - mixer->masterbuf[buffer] = HeapAlloc(GetProcessHeap(), 0, mixer->serverstreamlist->length_filtered); - CopyMemory(mixer->masterbuf[buffer],mixer->serverstreamlist->filteredbuf,mixer->serverstreamlist->length_filtered); - mixer->bytes_to_play = mixer->serverstreamlist->length_filtered; + mixer->masterbuf[buffer] = HeapAlloc(GetProcessHeap(), 0, mixer->serverstreamlist->length_filtered); + CopyMemory(mixer->masterbuf[buffer],mixer->serverstreamlist->filteredbuf,mixer->serverstreamlist->length_filtered); + mixer->bytes_to_play = mixer->serverstreamlist->length_filtered; + + return NULL; } void * mixs32(MixerEngine * mixer,int buffer) { + return NULL; } void * mixs64(MixerEngine * mixer,int buffer) { + return NULL; } void * mixu8(MixerEngine * mixer,int buffer) { + return NULL; } void * mixu16(MixerEngine * mixer,int buffer) { + return NULL; } void * mixu32(MixerEngine * mixer,int buffer) { + return NULL; } void * mixu64(MixerEngine * mixer,int buffer) { + return NULL; } void * mixfl32(MixerEngine * mixer,int buffer) { + return NULL; } void * mixfl64(MixerEngine * mixer,int buffer) { + return NULL; }
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] Mon Jun 6 12:20:41 2011 @@ -3,56 +3,74 @@ * LICENSE: GPL - See COPYING in the top level directory * FILE: services/audsrv/rpc.c * PURPOSE: Audio Server - * COPYRIGHT: Copyright 2011 Pankaj Yadav + * COPYRIGHT: Copyright 2011 Neeraj Yadav */ - -/* INCLUDES *****************************************************************/
#include "audsrv.h"
LIST_ENTRY LogHandleListHead;
-/* FUNCTIONS ****************************************************************/ - +/*RPC Listener Thread,Returns values less than 0 in failures*/ DWORD WINAPI RunRPCThread(LPVOID lpParameter) { RPC_STATUS Status;
InitializeListHead(&LogHandleListHead); - Status = RpcServerUseProtseqEp(L"ncacn_np", 20, L"\pipe\audsrv", NULL); + + Status = RpcServerUseProtseqEp(L"ncacn_np", + 20, + L"\pipe\audsrv", + NULL); if (Status != RPC_S_OK) { - printf("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status); - return 0; + return -1; }
- Status = RpcServerRegisterIfEx(audsrv_v0_0_s_ifspec, NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); + Status = RpcServerRegisterIfEx(audsrv_v0_0_s_ifspec, + NULL, + NULL, + 0, + RPC_C_LISTEN_MAX_CALLS_DEFAULT, + NULL ); if (Status != RPC_S_OK) { - printf("RpcServerRegisterIf() failed (Status %lx)\n", Status); - return 0; + return -2; }
- Status = RpcServerListen(1, 20, FALSE); + Status = RpcServerListen(1, + 20, + FALSE); + if (Status != RPC_S_OK) { - printf("RpcServerListen() failed (Status %lx)\n", Status); + return -3; }
return 0; }
- /*************************RPC Functions**********************************/
-long AUDInitStream( IN RPC_BINDING_HANDLE hBinding,LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance) +long AUDInitStream( IN RPC_BINDING_HANDLE hBinding,LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance) { - long stream; - printf("Client Connected and Initiated Stream Freq: %ld,Channle: %d,Bitspersample: %d,Datatype: %d,Mask: %ld,Volume: %d,Mute: %d,Balance: %f\n",frequency,channels,bitspersample,datatype,channelmask,volume,mute,balance); - stream = addstream(frequency,channels,bitspersample,datatype,channelmask,volume,mute,balance); - if( stream != 0 ){printf("Stream added\n");} + long stream; + + stream = addstream(frequency, + channels, + bitspersample, + datatype, + channelmask, + volume, + mute, + balance); + + if( stream != 0 ) + { + /*ERROR*/ + } return stream; } + /*************************************************************************/ 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] Mon Jun 6 12:20:41 2011 @@ -2,100 +2,193 @@
long getnewstreamid() { - long streamid= pengine->streamidpool; - pengine->streamidpool+=1; - return streamid; + long streamid= pengine->streamidpool; + pengine->streamidpool+=1; + return streamid; } + DWORD WINAPI RunStreamThread(LPVOID param) { - UINT i = 0; - ServerStream * localstream = (ServerStream *) 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;
- printf("Signaling Mixer Thread For First Stream\n"); -/*HACK 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*/ -/******************************************************/ -PSHORT tempbuf; -localstream->ready =TRUE; -localstream->length_filtered = localstream->freq * localstream->channels * localstream->bitspersample / 8; -tempbuf = (PSHORT)HeapAlloc(GetProcessHeap(), 0, localstream->length_filtered); + localstream->ready =TRUE; + 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 - 1) * 500 * 6.28 / 48000); + 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 - 2) * 500 * 6.28 / 48000); + 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++; } -localstream->filteredbuf = tempbuf; + + *((int *)localstream->minsamplevalue) = minimum; + *((int *)localstream->maxsamplevalue) = maximum; + localstream->filteredbuf = tempbuf; /******************************************************/ - SetEvent(localstream->threadready); + SetEvent(localstream->threadready);
- while (1){OutputDebugStringA("Stream Thread Running.");Sleep(100);}; - /*Clean Stream's data*/ + while (1) + { + OutputDebugStringA("Stream Thread Running."); + Sleep(100); + } + /*Clean Stream's data*/ }
long addstream(LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance) { - ServerStream * newstream,*localstream; - DWORD dwID; + ServerStream * newstream,*localstream; + DWORD dwID;
- /*Add Data to Linked list*/ - localstream = pengine->serverstreamlist; - newstream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ServerStream)); - if(newstream == NULL) {goto error;} - if(volume < 0) {newstream->volume = 0;}else if (volume > 1000) {newstream->volume = 1000;}else {newstream->volume = volume;} - if(volume < -1.0) {newstream->volume = -1.0;}else if (volume > 1.0) {newstream->volume = 1.0;}else {newstream->volume = volume;} - newstream->freq = frequency; /*TODO frequency validation required*/ - if(datatype==0 || datatype==1 || datatype==2){newstream->datatype=datatype;}else goto error; - if ((datatype==0 && (bitspersample == 8 || bitspersample == 16 || bitspersample == 32 || bitspersample == 64 )) || - (datatype==1 && (bitspersample == 8 || bitspersample == 16 || bitspersample == 32 || bitspersample == 64)) || - (datatype==2 && (bitspersample == 32 || bitspersample == 64)) ) - newstream->bitspersample = bitspersample; /*TODO bitspersample validation*/ - else goto error; + /*Add Data to Linked list*/ + localstream = pengine->serverstreamlist; + newstream = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(ServerStream));
- newstream->channels = channels; /*TODO validation*/ - newstream->channelmask = channelmask; /*TODO validation*/ + if(newstream == NULL) + goto error;
- newstream->ready = FALSE; - newstream->length_genuine = 0; - newstream->genuinebuf = NULL; - newstream->length_filtered = 0; - newstream->filteredbuf = NULL; - newstream->minsamplevalue = NULL; - newstream->maxsamplevalue = NULL; - - newstream->next = NULL; - newstream->played = CreateEvent(NULL,FALSE,FALSE,NULL); - newstream->threadready = CreateEvent(NULL,FALSE,FALSE,NULL); + if(volume < 0) + newstream->volume = 0; + else if (volume > 1000) + newstream->volume = 1000; + else + newstream->volume = volume;
- if(newstream->played == NULL || newstream->threadready == NULL) {goto error;} - newstream->thread=CreateThread(NULL,0,RunStreamThread,newstream,0,&dwID); - if(newstream->thread == NULL) {goto error;} + if(volume < -1.0) + newstream->volume = -1.0; + else if (volume > 1.0) + newstream->volume = 1.0; + else + newstream->volume = volume; + + newstream->freq = frequency; /*TODO frequency validation required*/ + + if(datatype==0 || datatype==1 || datatype==2) + newstream->datatype=datatype; + else + goto error; + + if ((datatype==0 && (bitspersample == 8 || bitspersample == 16 || bitspersample == 32 || bitspersample == 64 )) || + (datatype==1 && (bitspersample == 8 || bitspersample == 16 || bitspersample == 32 || bitspersample == 64)) || + (datatype==2 && (bitspersample == 32 || bitspersample == 64)) ) + newstream->bitspersample = bitspersample; /*TODO bitspersample validation*/ + else + goto error; + + newstream->channels = channels; /*TODO validation*/ + newstream->channelmask = channelmask; /*TODO validation*/ + + newstream->ready = FALSE; + newstream->length_genuine = 0; + newstream->genuinebuf = NULL; + newstream->length_filtered = 0; + newstream->filteredbuf = NULL; + newstream->minsamplevalue = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + bitspersample/8); + + newstream->maxsamplevalue = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + bitspersample/8); + + newstream->next = NULL; + + newstream->played = CreateEvent(NULL, + FALSE, + FALSE, + NULL); + + newstream->threadready = CreateEvent(NULL, + FALSE, + FALSE, + NULL); + + if(newstream->played == NULL || newstream->threadready == NULL) + goto error; + + newstream->thread=CreateThread(NULL, + 0, + RunStreamThread, + newstream, + 0, + &dwID); + + if(newstream->thread == NULL) + goto error;
- WaitForSingleObject(newstream->threadready,INFINITE); + WaitForSingleObject(newstream->threadready, + INFINITE);
- newstream->streamid=getnewstreamid(); - if(localstream == NULL) - { - pengine->serverstreamlist = newstream; + newstream->streamid=getnewstreamid();
- pengine->masterfreq=frequency; - pengine->masterchannels=channels; - pengine->masterchannelmask=channelmask; - pengine->masterbitspersample=bitspersample; - pengine->masterdatatype = datatype; - } - else - { - while(localstream->next != NULL){localstream = localstream->next;} - localstream->next = newstream; - } - SetEvent(pengine->streampresent); - return newstream->streamid; + if(localstream == NULL) + { + pengine->serverstreamlist = newstream; + pengine->masterfreq=frequency; + pengine->masterchannels=channels; + pengine->masterchannelmask=channelmask; + pengine->masterbitspersample=bitspersample; + pengine->masterdatatype = datatype; + } + else + { + while(localstream->next != NULL) + localstream = localstream->next; + localstream->next = newstream; + } + SetEvent(pengine->streampresent); + return newstream->streamid;
error: - printf("Stream Rejected \n"); - HeapFree(GetProcessHeap(), 0, newstream); - return 0; + HeapFree(GetProcessHeap(), 0, newstream); + return 0; } + +/*Dont forget to clean ServerStream's minsamplevalue and maxsamplevalue while removing the 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] Mon Jun 6 12:20:41 2011 @@ -7,76 +7,114 @@ */ WINAPI int initstream (ClientStream * clientstream,LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance) { - long streamid; - if (clientstream == NULL ) return -1; - if (clientstream->callbacks.OpenComplete == NULL || clientstream->callbacks.BufferCopied == NULL || clientstream->callbacks.PlayComplete == NULL) return -2; - /*Validity of all other data will be checked at server*/ - /*Check Connection Status If not connected call Connect()*/ - /*If connected Properly call the remote audsrv_initstream() function*/ + long streamid;
- RpcTryExcept + if (clientstream == NULL ) + return -1; + + if (clientstream->callbacks.OpenComplete == NULL || clientstream->callbacks.BufferCopied == NULL || clientstream->callbacks.PlayComplete == NULL) + return -2; + + /*Validity of all other data will be checked at server*/ + /*Check Connection Status If not connected call Connect()*/ + /*If connected Properly call the remote audsrv_initstream() function*/ + + RpcTryExcept { - streamid = AUDInitStream (audsrv_v0_0_c_ifspec,frequency,channels,bitspersample,datatype,channelmask,volume,mute,balance); - printf("AUDInitStream Returned %ld",streamid); - if(streamid != 0) {clientstream->stream = streamid;} + streamid = AUDInitStream (audsrv_v0_0_c_ifspec, + frequency, + channels, + bitspersample, + datatype, + channelmask, + volume, + mute, + balance); + + if(streamid != 0) + clientstream->stream = streamid; } RpcExcept(1) { status = RpcExceptionCode(); - printf("Runtime reported exception 0x%lx = %ld\n", status, status); } RpcEndExcept
- /*Analyse the return by the function*/ - /*Currently Suppose the return is 0 and a valid streamid is returned*/ - clientstream->ClientEventPool[0]=CreateEvent(NULL,FALSE,FALSE,NULL); - clientstream->dead = 0; + /*Analyse the return by the function*/ + /*Currently Suppose the return is 0 and a valid streamid is returned*/ + clientstream->ClientEventPool[0]=CreateEvent(NULL, + FALSE, + FALSE, + NULL);
- return 0; + clientstream->dead = 0; + + return 0; }
WINAPI int playaudio ( ClientStream * clientstream ) { - /*This is an ActiveScheduler*/ - clientstream->callbacks.OpenComplete(0); - while(1) - { - while(WaitForSingleObject(clientstream->ClientEventPool[0],100)!=0){if(clientstream->dead)goto DEAD;} - /*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); - printf("Played a virtual buffer on Virtual Audio Server :) %d\n",clientstream->dead); - clientstream->callbacks.BufferCopied(0); - } - clientstream->callbacks.PlayComplete(0); + /*This is an ActiveScheduler*/ + clientstream->callbacks.OpenComplete(0); + + while(1) + { + while(WaitForSingleObject(clientstream->ClientEventPool[0], + 100)!=0) + { + if(clientstream->dead) + goto DEAD; + } + /*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); + clientstream->callbacks.BufferCopied(0); + } + clientstream->callbacks.PlayComplete(0);
DEAD: -printf("\nAudio Thread Ended\n"); +/*Audio Thread Ended*/
- return 0; + return 0; } + WINAPI int stopaudio (ClientStream * clientstream ) { - /*Server Side termination is remaining*/ - /*If connected Properly call the remote audsrv_stop() function*/ - clientstream->dead = 1; /*Client Side termination*/ + /*Server Side termination is remaining*/ + /*If connected Properly call the remote audsrv_stop() function*/ + clientstream->dead = 1; /*Client Side termination*/ + + return 0; } + WINAPI int Volume(ClientStream * clientstream, int * volume ) { + return 0; } + WINAPI int SetVolume(ClientStream * clientstream ,const int newvolume) { + return 0; } + WINAPI int Write(ClientStream * clientstream ,const char * aData) { - if(clientstream->dead) return -1; - SetEvent(clientstream->ClientEventPool[0]); + if(clientstream->dead) + return -1; + + SetEvent(clientstream->ClientEventPool[0]); + + return 0; } + WINAPI int SetBalance(ClientStream * clientstream ,float balance) { + return 0; } + WINAPI int GetBalance(ClientStream * clientstream ,float * balance) { + return 0; }
Modified: branches/nyadav-audio-branch/dll/win32/audsrvapi/dllmain.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/dll/win32/au... ============================================================================== --- branches/nyadav-audio-branch/dll/win32/audsrvapi/dllmain.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/dll/win32/audsrvapi/dllmain.c [iso-8859-1] Mon Jun 6 12:20:41 2011 @@ -5,30 +5,42 @@ BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved - ) + ) { - RPC_STATUS status; + RPC_STATUS status; unsigned short * pszStringBinding = NULL; - - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - status = RpcStringBindingComposeW(NULL,L"ncacn_np",NULL,L"\pipe\audsrv", NULL,&pszStringBinding); + + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + status = RpcStringBindingComposeW(NULL, + L"ncacn_np", + NULL, + L"\pipe\audsrv", + NULL, + &pszStringBinding);
- status = RpcBindingFromStringBindingW(pszStringBinding, &audsrv_v0_0_c_ifspec); + status = RpcBindingFromStringBindingW(pszStringBinding, + &audsrv_v0_0_c_ifspec);
- if (status) printf("Connection Problem p %d \n",status); + if (status) + { + /*Connection Problem*/ + }
- status = RpcStringFree(&pszStringBinding); + status = RpcStringFree(&pszStringBinding);
- if (status) printf("Problem Freeing String : %d \n",status); - break; - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - status = RpcBindingFree(audsrv_v0_0_c_ifspec); - if (status == RPC_S_INVALID_BINDING) printf("Error : %d Invalid RPC S HANDLE\n",status); - break; - } - return TRUE; + if (status) + { + /*problem*/ + } + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + status = RpcBindingFree(audsrv_v0_0_c_ifspec); + if (status == RPC_S_INVALID_BINDING) printf("Error : %d Invalid RPC S HANDLE\n",(int)status); + break; + } + return TRUE; }
Modified: branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/drivers/wdm/... ============================================================================== --- branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c [iso-8859-1] Mon Jun 6 12:20:41 2011 @@ -8,49 +8,79 @@ void buffercopied (int error ); void playcomplete (int error );
-ClientStream clientstream = {0,0,{NULL},{opencomplete,buffercopied,playcomplete}};/*This initialization should not be necessary for a typical client*/ +ClientStream clientstream = {0, + 0, + {NULL}, + {opencomplete, + buffercopied, + playcomplete} + };
DWORD WINAPI RunAudioThread(LPVOID param) { - ClientStream * localstream = (ClientStream *) param; - printf("Starting Audio Thread \n"); - playaudio(localstream); + ClientStream * localstream = (ClientStream *) param; + playaudio(localstream); + + return 0; } void opencomplete (int error ) { - /*Copy First Buffer and write*/ - Write(&clientstream,"HELLO_RANDOM_STRING"); + /*Copy First Buffer and write*/ + Write(&clientstream, + "HELLO_RANDOM_STRING"); } void buffercopied (int error ) { - Write(&clientstream,"HELLO_RANDOM_STRING"); + Write(&clientstream, + "HELLO_RANDOM_STRING"); } void playcomplete (int error ) { - printf("Play Complete Code %d\n",error); + printf("Play Complete Code %d\n", + error); } int __cdecl wmain(int argc, char* argv[]) { - int error; - DWORD dwID; - HANDLE audiothread; - char input='\0'; - printf("ReactOS Audio Mixer Sample Client.Enter 'a' to Stop.\n"); - //if (clientstream->callbacks.OpenComplete == NULL || clientstream->callbacks.BufferCopied == NULL || clientstream->callbacks.PlayComplete == NULL) printf(""); - error = initstream ( &clientstream , 44100 , 2 , 16 ,0, KSAUDIO_SPEAKER_STEREO , 1000 , 0, 0.0 ); /*[out]HANDLE * streamhandle,[in] long frequency,[in] int number of channels,[in] int bitspersample,[in]ULONG channelmask,[in] int volume,[in] int mute,[in] float balance*/ - if ( error ) - printf("Failed to Initialize Stream.Error %d\n", error); - else - { - printf("StreamID : %ld\n",clientstream.stream); - audiothread = CreateThread(NULL,0,RunAudioThread,&clientstream,0,&dwID); - } - while ( input != 'a' ) - scanf("%c",&input); - printf("Stoping Audio Stream.\n"); - stopaudio(&clientstream); - WaitForSingleObject(audiothread,INFINITE); + int error; + DWORD dwID; + HANDLE audiothread = NULL; + char input='\0'; + printf("ReactOS Audio Mixer Sample Client.Enter 'a' to Stop.\n"); + //if (clientstream->callbacks.OpenComplete == NULL || clientstream->callbacks.BufferCopied == NULL || clientstream->callbacks.PlayComplete == NULL) printf(""); + + /*[out]HANDLE * streamhandle,[in] long frequency,[in] int number of channels,[in] int bitspersample,[in]ULONG channelmask,[in] int volume,[in] int mute,[in] float balance*/ + error = initstream ( &clientstream , + 44100 , + 2 , + 16 , + 0, + KSAUDIO_SPEAKER_STEREO , + 1000 , + 0, + 0.0 ); + + if ( error ) + { + printf("Failed to Initialize Stream.Error %d\n", error); + goto error; + } + else + { + printf("StreamID : %ld\n",clientstream.stream); + audiothread = CreateThread(NULL,0,RunAudioThread,&clientstream,0,&dwID); + } + + while ( input != 'a' ) + scanf("%c",&input); + + printf("Stoping Audio Stream.\n"); + stopaudio(&clientstream); + WaitForSingleObject(audiothread,INFINITE); + return 0; + +error: + return -1; }
Modified: branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h URL: http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/include/reac... ============================================================================== --- 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] Mon Jun 6 12:20:41 2011 @@ -10,26 +10,42 @@
typedef struct CallBacks { - void (*OpenComplete) (int error ); - void (*BufferCopied) (int error ); - void (*PlayComplete) (int error ); + void (*OpenComplete) (int error ); + void (*BufferCopied) (int error ); + void (*PlayComplete) (int error ); } CallBacks;
typedef struct ClientStream { -long stream; -int dead; -HANDLE ClientEventPool[1]; //0]th event is for Activescheduler -struct CallBacks callbacks; + long stream; + int dead; + HANDLE ClientEventPool[1]; + struct CallBacks callbacks; } ClientStream;
/********************API Functions******************/ -WINAPI int initstream (ClientStream * clientstream,LONG frequency,int channels,int bitspersample,int datatype, ULONG channelmask,int volume,int mute,float balance); +WINAPI int initstream (ClientStream * clientstream, + LONG frequency, + int channels, + int bitspersample, + int datatype, /*0=signed int,1=unsigned int,2=float*/ + ULONG channelmask, + int volume, + int mute, + float balance); + WINAPI int playaudio ( ClientStream * clientstream); WINAPI int stopaudio (ClientStream * clientstream ); -WINAPI int Volume(ClientStream * clientstream, int * volume ); -WINAPI int SetVolume(ClientStream * clientstream ,const int newvolume); -WINAPI int Write(ClientStream * clientstream ,const char * aData); -WINAPI int SetBalance(ClientStream * clientstream ,float balance); -WINAPI int GetBalance(ClientStream * clientstream ,float * balance); + +WINAPI int Volume(ClientStream * clientstream, + int * volume ); + +WINAPI int SetVolume(ClientStream * clientstream , + const int newvolume); +WINAPI int Write(ClientStream * clientstream , + const char * aData); +WINAPI int SetBalance(ClientStream * clientstream , + float balance); +WINAPI int GetBalance(ClientStream * clientstream , + float * balance); #endif