VoiceConnect

DirectPlay

 
Microsoft DirectX 9.0 SDK Update (Summer 2003)

VoiceConnect


The VoiceConnect sample shows how to network with other players to start a Microsoft® DirectPlay® Voice chat session. After joining or creating a session, the players can use a microphone to talk to one other. Other players can join the session at any time.

Path

Source: (SDK root)\Samples\C++\DirectPlay\VoiceConnect

Executable: (SDK root)\Samples\C++\DirectPlay\Bin

User's Guide

For information about how to connect, refer to the User's Guide section of the SimplePeer sample. After connecting, the host is presented with a dialog box asking which voice codec to use. Typical voice applications automatically select a voice codec, or present this to the user in some other fashion. When the chat session begins, any client can alter the playback or capture settings by clicking Setup.

Note  If you choose the Internetwork Packet Exchange (IPX) service provider and want to have DirectPlay perform a search for the address, select the use DPNSVR check box.

Programming Notes

The VoiceConnect sample is very similar in form to the SimplePeer sample. The VoiceConnect differs by letting clients use DirectPlay Voice to talk to each other using a computer microphone. For detailed programming notes, see the Programming Notes section of the SimplePeer sample.

To create the voice functionality, the application must first initialize DirectPlay voice. This sample does this by calling CNetVoice::Init when the main dialog is initialized. CNetVoice::Init performs the following tasks.

  • Calls the VoiceSessionTestAudioSetup function to test the audio setup with DirectPlay Voice. VoiceSessionTestAudioSetup does the following:

    1. Creates an IDirectPlayVoiceTest object with CoCreateInstance.
    2. Calls IDirectPlayVoiceTest::CheckAudioSetup with the DVFLAGS_QUERYONLY flag set. This will return DVERR_RUNSETUP if the setup wizard needs to be run. To run the setup wizard, call IDirectPlayVoiceTest::CheckAudioSetup again without the DVFLAGS_QUERYONLY flag. If it returns successfully, then the VoiceConnect sample continues, otherwise the sample ends.
    3. Releases the IDirectPlayVoiceTest object.

  • Calls the VoiceSessionCreate function to create the audio setup with DirectPlay Voice if the player is hosting. VoiceSessionCreate does the following:
    1. Creates an IDirectPlayVoiceServer with CoCreateInstance.
    2. Calls IDirectPlayVoiceServer::Initialize to register the voice server message handler. The DirectPlay interface is also passed here.
    3. Fills out a DVSESSIONDESC structure with the session type and the desired voice codec.
    4. Calls IDirectPlayVoiceServer::StartSession passing in the DVSESSIONDESC structure.
  • If the player is either hosting or joining, the application calls the VoiceSessionConnect function, which uses the following steps to connect to the session.
    1. Create an IDirectPlayVoiceClient with CoCreateInstance.
    2. Call IDirectPlayVoiceClient::Initialize to register the voice client message handler. The DirectPlay interface is also passed here.
    3. Fill out a DVSOUNDDEVICECONFIG structure with the globally unique identifiers (GUIDs) for the Microsoft DirectShow® playback and capture devices.
    4. Fill out a DVCLIENTCONFIG structure. In this sample, this structure is filled out when with a dialog box. More complex applications might want to do this a different way. See the VoiceConfigDlgProc function in VoiceConnect.cpp.
    5. Call IDirectPlayVoiceClient::Connect passing the DVSOUNDDEVICECONFIG and DVCLIENTCONFIG structures.
    6. Call IDirectPlayVoiceClient::SetTransmitTargets to the desired default target. This sample sets the target value to DVID_ALLPLAYERS, which targets all players.
    7. Call IDirectPlayVoiceClient::GetSoundDeviceConfig. Check for the DVSOUNDCONFIG_HALFDUPLEX flag in the dwflags member of the DVSOUNDDEVICECONFIG structure returned to figure out if this client is in half-duplex mode. In half-duplex mode, the client cannot talk but can listen.

DirectPlayVoiceClientMessageHandler handles different DirectPlay messages such as:

  • DVMSGID_CREATEVOICEPLAYER
  • DVMSGID_DELETEVOICEPLAYER
  • DVMSGID_HOSTMIGRATED
  • DVMSGID_GAINFOCUS and DVMSGID_LOSTFOCUS
  • DVMSGID_RECORDSTART
  • DVMSGID_RECORDSTOP
  • DVMSGID_PLAYERVOICESTART
  • DVMSGID_PLAYERVOICESTOP

When Exit is clicked, the application needs to clean up DirectPlay Voice by calling CNetVoice::Free, which does the following:

  1. Disconnects the player from the voice session. The VoiceSessionDisconnect function calls IDirectPlayVoiceClient::Disconnect and releases the IDirectPlayVoiceClient object.
  2. Destroys the voice session if this player is the host. The VoiceSessionDestroy function calls IDirectPlayVoiceServer::StopSession and releases the IDirectPlayVoiceServer object

© 2003 Microsoft Corporation. All rights reserved.