LInet::SendSound

#include "ltwrappr.h"

L_INT LInet::SendSound(plRemoteComp, pWaveFormatData, pWaveData, pdwDataSize)

LInet plRemoteComp;

/* instance 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

plRemoteComp

Instance 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.

A call to LInet::OnSoundReceived will be generated on the remote computer.

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

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 LInet::StartUp 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:

LInet::SendBitmap, LInet::SendData, LInet::Connect, LInet::Close, LInet::ReadData, LInet::EnableAutoProcess, LInet::ServerInit, LInet::ClearQueue, LInet::GetQueueSize, LInet::OnSoundReceived, LInet::StartUp, LInet::ShutDown¸ Class Members

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.

// a user defined class derived from LInet should be used to support OnConnectRequest and 
// OnSounrReceived callback function
// suppose it was named as LUserInet
// a user defined class derived from LMMCapture should be used to support RecordCallBack function
// suppose it was named as LUserMMcap;

// code on the server side
LUserInet UserServerInet;
LUserMMCapture UserServerMMcap;

UserServerInet.StartUp();

if (UserServerInet.ServerInit(1000) != SUCCESS)
   LBase::DisplayError(NULL, TEXT("Error attempting to start the server"));


L_INT LUserInet::OnConnectRequest(LInet L_FAR *plConnection, L_INT nError)
{
   L_INT nRet = SUCCESS;

   if ( nError != SUCCESS)
       return FAILURE;

   nRet = AcceptConnect(plConnection);
   if (nRet != SUCCESS)
   {
       LBase::DisplayError(NULL, TEXT("Error in accepting remote computer."));
       return nRet;
   }

   nRet = UserServerMMcap.StopFeedSound ();
   return nRet;
}

L_INT LUserInet::OnSoundReceived(LInet L_FAR *plConnection, L_INT nError,  LPWAVEFORMATDATA pWaveFormatData, L_UINT32 ulWaveFormatSize,  LPWAVEDATA pWaveData)
{
   L_INT nRet = SUCCESS;

   if ( nError != SUCCESS)
       return FAILURE;

   nRet = UserServerMMcap.StartFeedSound (NULL, CAP_DEVICE_MAPPER, pWaveFormatData, 0, CAP_FEED_PLAYDATA);
   if (nRet != SUCCESS)
   {
       LBase::DisplayError(NULL, TEXT("Error starting sound."));
       return nRet;
   }

   nRet = UserServerMMcap.FeedSound (pWaveData);
   return nRet;
}

// code on the client side
LUserInet UserClientInet;
LUserMMCapture UserClientMMcap;

// connect to LEAD.
if (UserClientInet.Connect("207.238.49.190", 1000) != SUCCESS)
    LBase::DisplayError(NULL, TEXT("Error attempting to connect"));

L_INT LUserMMCapture::RecordCallback (LPWAVEDATA pWaveData)
{
   L_UINT32 dwTotalSize;
   LPWAVEFORMATDATA  pWaveFormatData;
   L_INT nRet = SUCCESS;
   LInet L_FAR *plRemote = NULL;

   // Suppose that remote computer was the last one in my list
   plRemote = UserClientInet.GetLastItem();
   nRet = UserClientInet.SendSound(plRemote, pWaveFormatData, pWaveData, &dwTotalSize);

   return nRet;
}

L_INT LUserInet::OnConnect(LInet L_FAR *plConnection, L_INT nError)
{
   L_UINT   uWaveFormatSize;
   LPWAVEFORMATDATA  pWaveFormatData;

   if (nError != SUCCESS)
      return nError;
 
   // start recording in the current default Windows format
   // get the format size
   UserClientMMcap.GetDefaultAudFormat (NULL, &uWaveFormatSize, NULL, NULL);

   // allocate memory and get the format
   pWaveFormatData = (LPWAVEFORMATDATA)GlobalAllocPtr(GMEM_MOVEABLE, uWaveFormatSize);
   UserClientMMcap.GetDefaultAudFormat (pWaveFormatData, &uWaveFormatSize, NULL, NULL);

   if (UserClientMMcap.OpenRecord (CAP_DEVICE_MAPPER, pWaveFormatData, 0,
      pWaveFormatData->nAvgBytesPerSec) != SUCCESS)
   {
       LBase::DisplayError(NULL, TEXT("Error starting recording!"));
       return FAILURE;
   }
    UserClientMMcap.StartRecord ();

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