CreateMessage() public method

public CreateMessage ( byte messageType ) : NetworkOutMessage
messageType byte
return NetworkOutMessage
コード例 #1
0
        private NetworkOutMessage CreateMessage(byte MessageType)
        {
            NetworkOutMessage msg = serverConnection.CreateMessage(MessageType);

            msg.Write(MessageType);
            // Add the local userID so that the remote clients know whose message they are receiving
            //msg.Write(localUserID); // TODO Is this necessary if using one hololens?
            return(msg);
        }
コード例 #2
0
        private NetworkOutMessage CreateMessage(byte messageType)
        {
            NetworkOutMessage msg = serverConnection.CreateMessage(messageType);

            msg.Write(messageType);
            // Add the local userID so that the remote clients know whose message they are receiving
            msg.Write(localUserID);
            return(msg);
        }
コード例 #3
0
        private void SendFixedSizedChunk(NetworkConnection connection, byte[] data, int dataSize)
        {
            System.DateTime currentTime = System.DateTime.Now;
            float           seconds     = (float)(currentTime - timeOfLastPacketSend).TotalSeconds;

            timeOfLastPacketSend = currentTime;
            if (seconds < 10.0)
            {
                if (worstTimeBetweenPackets < seconds)
                {
                    worstTimeBetweenPackets = seconds;
                }

                if (ShowInterPacketTime)
                {
                    UnityEngine.Debug.Log("Microphone: Millisecs since last sent: " + seconds * 1000.0 + "  Worst: " + worstTimeBetweenPackets * 1000.0);
                }
            }

            int clientId = SharingStage.Instance.Manager.GetLocalUser().GetID();

            // pack the header
            NetworkOutMessage msg = connection.CreateMessage((byte)MessageID.AudioSamples);

            int dataCountFloats = dataSize / 4;

            msg.Write((byte)5);             // 8 byte header size

            Int32 pack = 0;

            versionPacker.SetBits(ref pack, 1);                         // version
            audioStreamCountPacker.SetBits(ref pack, 1);                // AudioStreamCount
            channelCountPacker.SetBits(ref pack, 1);                    // ChannelCount
            sampleRatePacker.SetBits(ref pack, sampleRateType);         // SampleRate: 1 = 16000, 3 = 48000
            sampleTypePacker.SetBits(ref pack, 0);                      // SampleType
            sampleCountPacker.SetBits(ref pack, dataCountFloats);       // SampleCount (data count is in bytes and the actual data is in floats, so div by 4)
            codecTypePacker.SetBits(ref pack, 0);                       // CodecType
            mutePacker.SetBits(ref pack, Mute ? 1 : 0);
            sequenceNumberPacker.SetBits(ref pack, sequenceNumber++);
            sequenceNumber %= 32;

            msg.Write((int)pack);                       // the packed bits

            // This is where stream data starts. Write all data for one stream

            msg.Write((float)0.0f);                // average amplitude.  Not needed in direction from client to server.
            msg.Write((int)clientId);              // non-zero client ID for this client.

            // HRTF position bits

            Vector3 cameraPosRelativeToGlobalAnchor       = Vector3.zero;
            Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero;

            if (GlobalAnchorTransform != null)
            {
                cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo(
                    null,
                    GlobalAnchorTransform,
                    Camera.main.transform.position);

                cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo(
                    null,
                    GlobalAnchorTransform,
                    Camera.main.transform.position);
            }

            cameraPosRelativeToGlobalAnchor.Normalize();
            cameraDirectionRelativeToGlobalAnchor.Normalize();

            // Camera position
            msg.Write(cameraPosRelativeToGlobalAnchor.x);
            msg.Write(cameraPosRelativeToGlobalAnchor.y);
            msg.Write(cameraPosRelativeToGlobalAnchor.z);

            // HRTF direction bits
            msg.Write(cameraDirectionRelativeToGlobalAnchor.x);
            msg.Write(cameraDirectionRelativeToGlobalAnchor.y);
            msg.Write(cameraDirectionRelativeToGlobalAnchor.z);

            msg.WriteArray(data, (uint)dataCountFloats * 4);

            connection.Send(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Audio, true);
        }