Skip to content

Commit

Permalink
Merge pull request #47 from Meetsch/master
Browse files Browse the repository at this point in the history
Feature: Channel Administration & speaking in multiple channels + minor fixes
  • Loading branch information
martindevans authored Feb 23, 2020
2 parents 7dc67a3 + 6b61b63 commit 99fae54
Show file tree
Hide file tree
Showing 18 changed files with 891 additions and 174 deletions.
4 changes: 2 additions & 2 deletions MumbleClient/MumbleClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
<Reference Include="NAudio, Version=1.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.10.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=2.4.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.2.4.0\lib\net40\protobuf-net.dll</HintPath>
Expand Down
28 changes: 23 additions & 5 deletions MumbleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace MumbleClient
{
internal class Program
{
private static Exception _updateLoopThreadException = null;

private static void Main(string[] args)
{
string addr, name, pass;
Expand Down Expand Up @@ -59,8 +61,14 @@ private static void Main(string[] args)
MumbleConnection connection = new MumbleConnection(new IPEndPoint(Dns.GetHostAddresses(addr).First(a => a.AddressFamily == AddressFamily.InterNetwork), port), protocol);
connection.Connect(name, pass, new string[0], addr);

Thread t = new Thread(a => UpdateLoop(connection)) {IsBackground = true};
t.Start();
//Start the UpdateLoop thread, and collect a possible exception at termination
ThreadStart updateLoopThreadStart = new ThreadStart(() => UpdateLoop(connection, out _updateLoopThreadException));
updateLoopThreadStart += () => {
if(_updateLoopThreadException != null)
throw new Exception($"{nameof(UpdateLoop)} was terminated unexpectedly because of a {_updateLoopThreadException.GetType().ToString()}", _updateLoopThreadException);
};
Thread updateLoopThread = new Thread(updateLoopThreadStart) {IsBackground = true};
updateLoopThread.Start();

var r = new MicrophoneRecorder(protocol);

Expand Down Expand Up @@ -92,11 +100,21 @@ private static void DrawChannel(string indent, IEnumerable<Channel> channels, IE
DrawChannel(indent + "\t", channels, users, channel);
}

private static void UpdateLoop(MumbleConnection connection)
private static void UpdateLoop(MumbleConnection connection, out Exception exception)
{
while (connection.State != ConnectionStates.Disconnected)
exception = null;
try
{
while (connection.State != ConnectionStates.Disconnected)
{
if (connection.Process())
Thread.Yield();
else
Thread.Sleep(1);
}
} catch (Exception ex)
{
connection.Process();
exception = ex;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion MumbleClient/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NAudio" version="1.9.0" targetFramework="net45" />
<package id="NAudio" version="1.10.0" targetFramework="net45" />
<package id="protobuf-net" version="2.4.0" targetFramework="net45" />
</packages>
7 changes: 6 additions & 1 deletion MumbleGuiClient/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MumbleSharp;
Expand Down Expand Up @@ -251,7 +252,10 @@ private void btnSend_Click(object sender, EventArgs e)
private void mumbleUpdater_Tick(object sender, EventArgs e)
{
if (connection != null)
connection.Process();
if (connection.Process())
Thread.Yield();
else
Thread.Sleep(1);
}

private void tvUsers_MouseDoubleClick(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -457,6 +461,7 @@ private void btnConnect_Click(object sender, EventArgs e)
while (connection.Protocol.LocalUser == null)
{
connection.Process();
Thread.Sleep(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions MumbleGuiClient/MumbleGuiClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
<Reference Include="NAudio, Version=1.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.10.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
2 changes: 1 addition & 1 deletion MumbleGuiClient/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NAudio" version="1.9.0" targetFramework="net45" />
<package id="NAudio" version="1.10.0" targetFramework="net45" />
</packages>
3 changes: 3 additions & 0 deletions MumbleSharp/Audio/AudioDecodingBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public int Read(byte[] buffer, int offset, int count)
/// <param name="codec">The codec to use to decode this packet</param>
public void AddEncodedPacket(long sequence, byte[] data, IVoiceCodec codec)
{
if(sequence == 0)
_nextSequenceToDecode = 0;

if (_codec == null)
_codec = codec;
else if (_codec != null && _codec != codec)
Expand Down
26 changes: 23 additions & 3 deletions MumbleSharp/Audio/AudioEncodingBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Stop()
_unencodedBuffer.Add(new TargettedSpeech(stop: true));
}

public byte[] Encode(SpeechCodecs codec)
public EncodedTargettedSpeech? Encode(SpeechCodecs codec)
{
//Get the codec
var codecInstance = _codecs.GetCodec(codec);
Expand Down Expand Up @@ -95,7 +95,10 @@ public byte[] Encode(SpeechCodecs codec)
byte[] b = new byte[frameBytes];
int read = _pcmBuffer.Read(new ArraySegment<byte>(b));

return codecInstance.Encode(new ArraySegment<byte>(b, 0, read));
return new EncodedTargettedSpeech(
codecInstance.Encode(new ArraySegment<byte>(b, 0, read)),
_target,
_targetId);
}
else
{
Expand All @@ -107,7 +110,10 @@ public byte[] Encode(SpeechCodecs codec)
byte[] b = new byte[frameBytes];
int read = _pcmBuffer.Read(new ArraySegment<byte>(b));

return codecInstance.Encode(new ArraySegment<byte>(b, 0, read));
return new EncodedTargettedSpeech(
codecInstance.Encode(new ArraySegment<byte>(b, 0, read)),
_target,
_targetId);
}
else return null;
}
Expand All @@ -133,6 +139,20 @@ private bool TryAddToEncodingBuffer(TargettedSpeech t, out bool stopped)
return true;
}

public struct EncodedTargettedSpeech
{
public readonly byte[] EncodedPcm;
public readonly SpeechTarget Target;
public readonly uint TargetId;

public EncodedTargettedSpeech(byte[] encodedPcm, SpeechTarget target, uint targetId)
{
TargetId = targetId;
Target = target;
EncodedPcm = encodedPcm;
}
}

/// <summary>
/// PCM data targetted at a specific person
/// </summary>
Expand Down
Loading

0 comments on commit 99fae54

Please sign in to comment.