Example #1
0
    protected void CreateVoiceSession(Peer dpp, Voice.SessionType type, Guid compressionType)
    {
        try
        {
            //set up session description for the voice server
            Voice.SessionDescription sessionDesc = new Voice.SessionDescription();
            sessionDesc.BufferAggressiveness = Voice.BufferAggressiveness.Default;
            sessionDesc.BufferQuality        = Voice.BufferQuality.Default;
            sessionDesc.Flags               = 0;
            sessionDesc.SessionType         = type;
            sessionDesc.GuidCompressionType = compressionType;

            //start the session
            try
            {
                server.StartSession(sessionDesc);
                mIsHost    = true;
                mInSession = true;
            }
            catch (DirectXException dxe)
            {
                throw dxe;
            }
        }
        catch (Exception e)
        {
            throw e;
        }
    }
Example #2
0
        /// <summary>
        /// Initializes the DirectPlayVoice Client and Server objects
        /// </summary>
        private void InitDirectPlayVoice()
        {
            // Release any existing resources
            if (m_VoiceClient != null)
            {
                m_VoiceClient.Dispose();
                m_VoiceClient = null;
            }

            if (m_VoiceServer != null)
            {
                m_VoiceServer.Dispose();
                m_VoiceServer = null;
            }

            // Initialize UI variables
            this.m_NumPlayersTalking = 0;

            // Based on the current connection, create DirectPlay voice objects.
            #region About DirectPlay Voice
            // Since the DirectPlay Voice API defines server and client interfaces,
            // but not a peer interface, one of the peers must act as the server
            // for voice communication; the logical choice is the session host, so
            // for this sample, the session host creates a server object in addition
            // to a client object. Note that in order to send and receive voice
            // messages you must have a connected voice client object, even if you
            // are acting as the voice server.
            #endregion
            switch (Connection)
            {
            case ConnectionType.Hosting:
            {
                // Create a new Voice Server
                m_VoiceServer = new Voice.Server(m_Peer);

                // Create a Session Description for the voice session
                Voice.SessionDescription desc = new Voice.SessionDescription();
                desc.SessionType          = Voice.SessionType.Peer;
                desc.BufferQuality        = Voice.BufferQuality.Default;
                desc.GuidCompressionType  = Voice.CompressionGuid.Default;
                desc.BufferAggressiveness = Voice.BufferAggressiveness.Default;

                // Launch a new voice session
                m_VoiceServer.StartSession(desc);

                // Fall-through to create client object
                goto case ConnectionType.Connected;
            }

            case ConnectionType.Connected:
            {
                // Test Direct Voice
                if (TestDirectVoice() == false)
                {
                    return;
                }

                // Create a new Voice Client
                m_VoiceClient = new Voice.Client(m_Peer);

                // Add event handlers
                m_VoiceClient.PlayerStarted += new Voice.PlayerStartedEventHandler(PlayerStartedHandler);
                m_VoiceClient.PlayerStopped += new Voice.PlayerStoppedEventHandler(PlayerStoppedHandler);
                m_VoiceClient.RecordStarted += new Voice.RecordStartedEventHandler(RecordStartedHandler);
                m_VoiceClient.RecordStopped += new Voice.RecordStoppedEventHandler(RecordStoppedHandler);


                // Fill in description object for device configuration
                Voice.SoundDeviceConfig soundConfig = new Voice.SoundDeviceConfig();
                soundConfig.Flags = Voice.SoundConfigFlags.AutoSelect;
                soundConfig.GuidPlaybackDevice = DSoundHelper.DefaultPlaybackDevice;
                soundConfig.GuidCaptureDevice  = DSoundHelper.DefaultCaptureDevice;
                soundConfig.Window             = m_Form;
                soundConfig.MainBufferPriority = 0;

                // Fill in description object for client configuration
                Voice.ClientConfig clientConfig = new Voice.ClientConfig();
                clientConfig.Flags = Voice.ClientConfigFlags.AutoVoiceActivated |
                                     Voice.ClientConfigFlags.AutoRecordVolume;
                clientConfig.RecordVolume         = (int)Voice.RecordVolume.Last;
                clientConfig.PlaybackVolume       = (int)Voice.PlaybackVolume.Default;
                clientConfig.Threshold            = Voice.Threshold.Unused;
                clientConfig.BufferQuality        = Voice.BufferQuality.Default;
                clientConfig.BufferAggressiveness = Voice.BufferAggressiveness.Default;
                clientConfig.NotifyPeriod         = 0;

                try
                {
                    // Connect to the voice session
                    m_VoiceClient.Connect(soundConfig, clientConfig, Voice.VoiceFlags.Sync);
                }
                catch (Exception ex)
                {
                    m_Form.ShowException(ex, "Connect", true);
                    m_Form.Dispose();
                    return;
                }

                // Set DirectPlay to send voice messages to all players
                int[] targets = { (int)Voice.PlayerId.AllPlayers };
                m_VoiceClient.TransmitTargets = targets;

                break;
            }

            case ConnectionType.Disconnected:
            {
                return;
            }
            }
        }