L_InetSendSound

#include "l_bitmap.h"
#include "ltnet.h"

L_INT EXT_FUNCTION L_InetSendSound(hComputer, pWaveFormatData, pWaveData, pdwDataSize)

L_COMP hComputer;

/* handle of a remote computer */

LPWAVEFORMATDATA pWaveFormatData;

/* pointer to a structure describing the sound format */

LPWAVEDATA pWaveData;

/* pointer to a structure containing the sound data */

L_UINT32 L_FAR * pdwDataSize;

/* address of a variable to be updated with the size of the data being sent */

Sends sound data to a remote computer.

Parameter

Description

hComputer

Handle of a remote computer to which sound data will be sent.

pWaveFormatData

Pointer to a structure that describes the sound format.

pWaveData

Pointer to a structure containing the sound data.

pdwDataSize

Pointer to a variable which will be updated with the size of the data that was sent. This parameter is optional. You can pass NULL if you don't need this information.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function sends the pWaveFormatData structure first, including all the extra bytes needed by the format. It then sends the pWaveData structure, followed by the actual sound data.

The remote computer will receive an INET_SOUND_RECEIVED notification and pBuffer will point to pWaveFormatData. The remote computer will have to obtain the pointer to pWaveData. Since this structure follows the pWaveFormatData structure, use the SIZEOF_WAVEFORMATDATA macro to determine the size of the pWaveFormatData structure and thus the start of the pWaveData structure. On the remote computer, LEADTOOLS automatically adjusts pWaveData->lpData to point to the sound data.

The remote end can use pWaveFormatData and pWaveData to save the sound to a file, or to play it (using L_CapStartFeedSound).

The sound format is sent every time so that it will facilitate handling multiple connections to different computers that are recording sound in different formats.

You must initialize the LEADTOOLS Internet DLL using L_InetStartUp before calling this function.

Required DLLs and Libraries

LTNET

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

L_InetSendBitmap, L_InetSendData, L_InetConnect, L_InetClose, L_InetReadData, L_InetAutoProcess, L_InetServerInit, L_InetClearQueue, L_InetGetQueueSize, INETCALLBACK, L_InetStartUp, L_InetShutDown

Topics:

Internet Functions

Example

For a more complex example, you can look at the source for the NETCAP example.

This example contains code for both the server and the client program and shows
how sound can be captured by the client and sent to the server.

// ------------ code on the server side -------------
L_COMP hServer;
HGLOBAL hSoundServer;
L_COMP hClient;

...
if(L_InetServerInit(1000,&hServer,InetCallbackServer,NULL) != SUCCESS)
   MessageBox(NULL, TEXT("Error attempting to start the server"), TEXT("ERROR"), MB_OK);
...

// at some point, before the end of the server program you should do
// L_InetClose(hServer, FALSE); or L_InetClose(hServer, TRUE);
// L_CapStopFeedSound(hSoundServer, FALSE); or L_CapStopFeedSound(hSoundServer, TRUE);

L_INT L_EXPORT EXT_CALLBACK InetCallbackServer(L_COMP hComp,L_INT nMessage, L_INT nError,
L_CHAR L_FAR *pBuffer,L_INT32 lSize, L_VOID L_FAR*pUserData)
{
   switch(nMessage)
   {
      case INET_CONNECT_REQUEST: // somebody wants to connect with us
         if(nError == SUCCESS)
         {
            L_InetAcceptConnect (hServer,&hClient, InetCallbackServer, NULL);
            if(hSoundServer)
               L_CapStopFeedSound (hSoundServer, TRUE);
            hSoundServer = NULL;
         }
      break;

      case INET_SOUND_RECEIVED:
         // note: we will do less error checking to make the code simpler
         // still check for nError being SUCCESS to make sure we won't get memory violations
         if(nError == SUCCESS)
         {
            LPWAVEFORMATDATA pFormatData = (LPWAVEFORMATDATA)pBuffer;
            LPWAVEDATA pWaveData = (LPWAVEDATA)(pBuffer + SIZEOF_WAVEFORMATDATA(pFormatData));

            if(!hSoundServer)
               // first time we received sound data. start playing the sound
               L_CapStartFeedSound (&hSoundServer, NULL, CAP_DEVICE_MAPPER, pFormatData, 0, CAP_FEED_PLAYDATA, NULL, NULL);

            L_CapFeedSound (hSoundServer, pWaveData);
         }
      break;
   }
   return TRUE;
}

// ----------- code on the client side -------------

L_COMP hClient;
HGLOBAL hSoundClient;

/* note: instead of server_address you need to put the IP address
of the computer running the server. You can also put in
the computer name, if the server is running on a local network */

...
if(L_InetConnect ("server_address", 1000, &hClient, InetCallbackClient, NULL) != SUCCESS)
   MessageBox(NULL, TEXT("Error attempting to connect"), TEXT("ERROR"), MB_OK);
...

// somewhere before the end of the program you should do
// L_InetClose(hRemoteServer, FALSE); or L_InetClose(hRemoteServer, TRUE);
// L_CapCloseRecord(hSoundClient);


L_INT L_EXPORT EXT_CALLBACK RecordCallback(LPWAVEDATA pWaveData, L_VOID L_FAR*pUserData)
{
   L_UINT32 dwTotalSize;
   L_InetSendSound
(hClient, pWaveFormatData, pWaveData, &dwTotalSize);
   // dwTotalSize has now the size of the data being sent
   return SUCCESS;
}

L_INT L_EXPORT EXT_CALLBACK InetCallbackClient(L_COMP hComp,
L_INT nMessage, L_INT nError, L_CHAR L_FAR *pBuffer,
L_UINT32 lSize,L_VOID L_FAR*pUserData)
{
   L_UINT uWaveFormatSize;
   LPWAVEFORMATDATA pWaveFormatData;

   switch(nMessage)
   {
      case INET_CONNECT:
         /* check the status and send some data */
         if(nError == SUCCESS)
         {
            // note: hComp will be the same as hClient. but you can reassign it anyway
            hClient = hComp;

            // start recording in the current default Windows format
            // get the format size
            L_CapGetDefaultAudFormat (NULL, &uWaveFormatSize, NULL, NULL);
            // allocate memory and get the format
            pWaveFormatData = GlobalAllocPtr(GMEM_MOVEABLE, uWaveFormatSize);
            L_CapGetDefaultAudFormat(pWaveFormatData, &uWaveFormatSize, NULL, NULL);

            if(L_CapOpenRecord(&hSoundClient, CAP_DEVICE_MAPPER, pWaveFormatData, 0, pWaveFormatData->nAvgBytesPerSec, RecordCallback, NULL) != SUCCESS)
            {
               MessageBox(NULL, TEXT("Error starting recording!"), TEXT("Error"), MB_OK);
               break;
            }
            else
               L_CapStartRecord (hSoundClient);

            // i don't need this anymore
            GlobalFreePtr(pWaveFormatData);
         }
      break;
   }
   return SUCCESS;
}