public void SendTexture2D(Texture2D tex) { // If we are connected to a session, broadcast our head info if (this.serverConnection != null && this.serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)HoloPaintMessageID.Texture2D); // Store width and height msg.Write(tex.width); msg.Write(tex.height); // Encode to PNG byte[] png = tex.EncodeToPNG(); msg.Write(png.Length); msg.WriteArray(png, (uint)png.Length); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Avatar); } }
void AppendString(NetworkOutMessage msg, String str) { byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str); uint length = (uint)byteArray.Length; msg.WriteArray(byteArray, length); }
// string void AddVal(NetworkOutMessage msg, string value) { byte[] strBytes = System.Text.Encoding.ASCII.GetBytes(value); long byteSize = (long)strBytes.Length; msg.Write(byteSize); msg.WriteArray(strBytes, (uint)byteSize); }
// Append a network message with IP Byte Size and Byte array for IP. void AppendIP(NetworkOutMessage msg, string IP) { byte[] ipBytes = System.Text.Encoding.ASCII.GetBytes(IP); long byteSize = (long)ipBytes.Length; msg.Write(byteSize); msg.WriteArray(ipBytes, (uint)byteSize); }
public void SendIRImageByArray(byte[] imageBytes) { if (serverConnection != null && serverConnection.IsConnected()) { NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage); msg.Write(imageBytes.Length); msg.WriteArray(imageBytes, Convert.ToUInt32(imageBytes.Length)); serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default); } }
public void SendIRImageByLinescan(byte[] imageBytes, Int32 scanIndex) { if (serverConnection != null && serverConnection.IsConnected()) { NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage); //send the current scan index msg.Write(scanIndex); //send length data msg.Write(imageBytes.Length); Debug.Log("sent bytes: " + imageBytes.Length); //send image msg.WriteArray(imageBytes, Convert.ToUInt32(imageBytes.Length)); serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default); } }
public void SendUnityUserID(long localUserID) { // If we are connected to a session, broadcast our head info if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.EditorUser); uint byteSize = (uint)HolographicCameraManager.Instance.localIPBytes.Length; msg.Write(byteSize); msg.WriteArray(HolographicCameraManager.Instance.localIPBytes, byteSize); msg.Write(localUserID); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.Reliable, MessageChannel.Avatar); } }
public void SendVoiceLine(Vector3 position, Quaternion rotation, byte[] bytesData) { // If we are connected to a session, broadcast our head info if (serverConnection != null && serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.VoiceLine); AppendVector3(msg, position); AppendQuaternion(msg, rotation); msg.WriteArray(bytesData, 1024); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } }
public void SendHeadTransform(Vector3 position, Quaternion rotation) { // If we are connected to a session, broadcast our head info if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HeadTransform); uint byteSize = (uint)HolographicCameraManager.Instance.localIPBytes.Length; msg.Write(byteSize); msg.WriteArray(HolographicCameraManager.Instance.localIPBytes, byteSize); AppendTransform(msg, position, rotation); if (HolographicCameraManager.Instance == null || HolographicCameraManager.Instance.editorUser == null || !HolographicCameraManager.Instance.editorUser.IsValid()) { // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } else { // We have a known editor user, only send the message to the editor. serverConnection.SendTo( HolographicCameraManager.Instance.editorUser, ClientRole.Primary, msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } } }
private void SendFixedSizedChunk(NetworkConnection connection, byte[] data, int dataSize) { DateTime currentTime = DateTime.Now; float seconds = (float)(currentTime - timeOfLastPacketSend).TotalSeconds; timeOfLastPacketSend = currentTime; if (seconds < 10.0) { if (worstTimeBetweenPackets < seconds) { worstTimeBetweenPackets = seconds; } if (ShowInterPacketTime) { Debug.LogFormat("Microphone: Milliseconds since last sent: {0}, Worst: {1}", (seconds * 1000.0).ToString(CultureInfo.InvariantCulture), (worstTimeBetweenPackets * 1000.0).ToString(CultureInfo.InvariantCulture)); } } 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(pack); // the packed bits // This is where stream data starts. Write all data for one stream msg.Write(0.0f); // average amplitude. Not needed in direction from client to server. msg.Write(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, CameraCache.Main.transform.position); cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo( null, GlobalAnchorTransform, CameraCache.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); }
private void SendFixedSizedChunk(float[] dataFloats, int dataCountFloats) { System.DateTime currentTime = System.DateTime.Now; float seconds = (float)(currentTime - this.timeOfLastPacketSend).TotalSeconds; this.timeOfLastPacketSend = currentTime; if (seconds < 10.0) { if (this.worstTimeBetweenPackets < seconds) { this.worstTimeBetweenPackets = seconds; } if (ShowInterPacketTime) { UnityEngine.Debug.Log("Microphone: Millisecs since last sent: " + seconds * 1000.0 + " Worst: " + this.worstTimeBetweenPackets * 1000.0); } } // pack the header NetworkOutMessage msg = this.connection.CreateMessage((byte)MessageID.AudioSamples); 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, this.muteMicrophone ? 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)this.clientId); // non-zero client ID for this client. // HRTF position bits Vector3 cameraPosRelativeToGlobalAnchor = Vector3.zero; Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero; if (this.GlobalAnchorTransform != null) { cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo( null, this.GlobalAnchorTransform, Camera.main.transform.position); cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo( null, this.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); if (this.dataStreamSendBytes == null || this.dataStreamSendBytes.Length != dataCountFloats * 4) { this.dataStreamSendBytes = new byte[dataCountFloats * 4]; } dataFloats.ToByteArray4(this.dataStreamSendBytes, dataCountFloats); msg.WriteArray(this.dataStreamSendBytes, 4 * (uint)dataCountFloats); this.connection.Send(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Audio, true); }
void AppendByteArray(NetworkOutMessage msg, byte[] byteArray) { uint length = (uint)byteArray.Length; msg.WriteArray(byteArray, length); }