Skip to content

Commit

Permalink
v.1.3.7.2, 2014-03-09, 12:46:40
Browse files Browse the repository at this point in the history
+ Crash reporter
+ Option to kick other DJs off the icecast mount if in use
~ OSD popups are extra resilient
~ Skinning framework...?
  • Loading branch information
9001 committed Oct 12, 2015
1 parent fbc34fd commit 1976212
Show file tree
Hide file tree
Showing 26 changed files with 1,263 additions and 23 deletions.
400 changes: 400 additions & 0 deletions Loopstream/Exceptional.cs

Large diffs are not rendered by default.

48 changes: 38 additions & 10 deletions Loopstream/LSDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,54 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Loopstream
{
public class LSDevice
{
bool tested;
public string id, name;
public bool isRec, isPlay;
public string capt1, capt2;
public string serializationData;

[XmlIgnore]
public NAudio.CoreAudioApi.MMDevice mm;

[XmlIgnore]
public NAudio.Wave.WaveFormat wf;
bool tested;

public LSDevice()
{
id = name = null;
isRec = isPlay = false;
serializationData = "undef";
capt1 = "undef";
capt2 = "undef";
mm = null;
wf = null;
}

void makeSerializationData()
{
serializationData = LSDevice.stringer(wf);
}

public override string ToString()
{
return string.Format("{0} - {1}", !tested ? "?" : tested && wf == null ? "FUCKED" : "OK", name);
}

public static string stringer(NAudio.Wave.IWaveIn wp)
{
if (wp == null) return "FUCKED";
return stringer(wp.WaveFormat);
}

public static string stringer(NAudio.Wave.WaveFormat wf)
{
if (wf == null) return "FUCKED";
return "ABPS:" + wf.AverageBytesPerSecond +
" BPS:" + wf.BitsPerSample +
" BA:" + wf.BlockAlign +
Expand All @@ -49,23 +66,34 @@ public bool test()
try
{
if (mm == null) return false;
if (mm.DataFlow == NAudio.CoreAudioApi.DataFlow.All ||
mm.DataFlow == NAudio.CoreAudioApi.DataFlow.Render)
NAudio.Wave.IWaveIn dev = null;

capt1 = mm.FriendlyName; // windows name
capt2 = mm.DeviceFriendlyName; // just device
if (capt1.EndsWith(capt2 + ")"))
{
NAudio.Wave.WasapiLoopbackCapture dev = new NAudio.Wave.WasapiLoopbackCapture(mm);
wf = dev.WaveFormat;
dev.Dispose();
return true;
capt1 = capt1.Substring(0, capt1.Length - (capt2.Length + 3));
}
else
isRec = mm.DataFlow == NAudio.CoreAudioApi.DataFlow.All || mm.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture;
isPlay = mm.DataFlow == NAudio.CoreAudioApi.DataFlow.All || mm.DataFlow == NAudio.CoreAudioApi.DataFlow.Render;

dev = isPlay
? dev = new NAudio.Wave.WasapiLoopbackCapture(mm)
: dev = new NAudio.CoreAudioApi.WasapiCapture(mm);

if (dev != null)
{
NAudio.CoreAudioApi.WasapiCapture dev = new NAudio.CoreAudioApi.WasapiCapture(mm);
wf = dev.WaveFormat;
makeSerializationData();
dev.Dispose();
return true;
}
}
catch { return false; }
catch
{
mm = null;
}
return false;
}
}
}
46 changes: 46 additions & 0 deletions Loopstream/LSEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class LSEncoder
protected LSPcmFeed pimp;
protected LSSettings settings;
public LSSettings.LSParams enc;
public int rekick;

public Stream stdin { get; set; }
public Stream stdout { get; set; }
protected Stream pstdin { get; set; }
protected Stream pstdout { get; set; }
public bool crashed { get; private set; }
public bool aborted { get; private set; }

System.Net.Sockets.TcpClient tc;
System.Net.Sockets.NetworkStream s;
Expand All @@ -39,6 +41,7 @@ public LSEncoder()
settings = null;
crashed = false;
locker = new object();
rekick = 0;
}

string esc(string raw)
Expand Down Expand Up @@ -149,10 +152,51 @@ protected void makeShouter()
MessageBox.Show("Radio server error: Wrong password",
"Stream abort", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (str.StartsWith("HTTP/1.0 403 Mountpoint in use"))
{
if (--rekick > 0)
{
crashed = true;
}
else if (DialogResult.Yes == MessageBox.Show(
"Someone are already connected to the server.\n\nTry to kick them?",
"Mountpoint in use", MessageBoxButtons.YesNo))
{
byte[] kickrequest = System.Text.Encoding.UTF8.GetBytes(string.Format(
"GET /admin/killsource?mount=/{1}.{2} HTTP/1.0{0}" +
"Authorization: Basic {3}{0}" +
"User-Agent: loopstream/{4}{0}" +
"Content-Type: audio/mpeg{0}{0}",

"\r\n",
settings.mount,
enc.ext,
auth,
ver
));
logger.a("kicker socket");
var kc = new System.Net.Sockets.TcpClient();
kc.Connect(settings.host, settings.port);
logger.a("kicker connected");
var ks = kc.GetStream();
ks.Write(kickrequest, 0, kickrequest.Length);
logger.a("kicker sent");
int i = ks.Read(kickrequest, 0, kickrequest.Length);
string kickresult = System.Text.Encoding.UTF8.GetString(kickrequest, 0, i);
logger.a("kicker done");
rekick = 5;
crashed = true;
}
else
{
aborted = true;
}
}
else if (str.StartsWith("HTTP/1.0 200 OK"))
{
logger.a("bootstrap");
s = prepS;
rekick = 0;
stampee = 0;
stdin = pstdin;
stdout = pstdout;
Expand All @@ -178,6 +222,8 @@ protected void makeShouter()

public void eat(byte[] buffer, int c)
{
if (crashed || aborted) return;

try
{
stdin.Write(buffer, 0, c);
Expand Down
10 changes: 9 additions & 1 deletion Loopstream/LSPcmFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void dicks()

// Finally, reposition PCM pointer to minimize latency
// (and chance of lost packets because icecast a bitch)
//outlet.setReadPtr(0.2);
outlet.setReadPtr(0.2);

// PCM reader loop, passing on to encoders/shouters
//List<string> toclip = new List<string>();
Expand Down Expand Up @@ -195,6 +195,14 @@ void medic()
Program.ni.ShowBalloonTip(1000, "Connection error", "Failed to restart " + enc.enc.ext, System.Windows.Forms.ToolTipIcon.Error);
}
}
else if (enc.aborted)
{
string msg = "Removing " + enc.enc.ext + " encoder";

Logger.pcm.a(msg);
encoders.RemoveAt(a--);
Program.ni.ShowBalloonTip(1000, "Connection error", msg, System.Windows.Forms.ToolTipIcon.Error);
}
}
System.Threading.Thread.Sleep(10);
}
Expand Down
11 changes: 10 additions & 1 deletion Loopstream/LSSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Loopstream
{
public class LSSettings
{
[XmlIgnore]
public static LSSettings singleton;

public class LSServerPreset
{
public int port;
Expand Down Expand Up @@ -322,6 +325,7 @@ public class LSParams
public long quality;
public LSChannels channels;
public string ext;
[XmlIgnore]
public double FIXME_kbps;
}

Expand Down Expand Up @@ -681,7 +685,10 @@ public void runTests(Splesh splesh, bool forceTest)
StringBuilder sw = new StringBuilder();
for (int a = 0; a < devs.Length; a++)
{
splesh.prog(a + 1, devs.Length);
if (splesh != null)
{
splesh.prog(a + 1, devs.Length);
}
//devs[a].test();
try
{
Expand Down Expand Up @@ -819,6 +826,7 @@ public static LSSettings load()
ret.metaDec();
}
catch { }
LSSettings.singleton = ret;
return ret;
}
catch (Exception e)
Expand All @@ -830,6 +838,7 @@ public static LSSettings load()
}
ret = new LSSettings();
ret.initWhenDeserializationFails(); // it is 06:20 am, what are you looking at
LSSettings.singleton = ret; // for exception handler
return ret;
}
}
Expand Down
10 changes: 10 additions & 0 deletions Loopstream/Loopstream.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DFC.cs" />
<Compile Include="Exceptional.cs" />
<Compile Include="LSDevice.cs" />
<Compile Include="LSEncoder.cs" />
<Compile Include="LSLame.cs" />
Expand Down Expand Up @@ -147,6 +148,12 @@
<Compile Include="UI_ConfigSC.Designer.cs">
<DependentUpon>UI_ConfigSC.cs</DependentUpon>
</Compile>
<Compile Include="UI_Exception.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI_Exception.Designer.cs">
<DependentUpon>UI_Exception.cs</DependentUpon>
</Compile>
<Compile Include="UI_Graph.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -223,6 +230,9 @@
<EmbeddedResource Include="UI_ConfigSC.resx">
<DependentUpon>UI_ConfigSC.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI_Exception.resx">
<DependentUpon>UI_Exception.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI_Graph.resx">
<DependentUpon>UI_Graph.cs</DependentUpon>
</EmbeddedResource>
Expand Down
28 changes: 28 additions & 0 deletions Loopstream/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static class Program
/// The main entry point for the application.
/// </summary>
[STAThread]
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
static void Main(string[] args)
{
//new UI_Msg("poor", "").ShowDialog();
Expand All @@ -39,6 +40,14 @@ static void Main(string[] args)
}
}

AppDomain.CurrentDomain.UnhandledException += (ueSender, ueArgs) =>
new UI_Exception(ueArgs.ExceptionObject as Exception, 1).ShowDialog();

Application.ThreadException += (ueSender, ueArgs) =>
new UI_Exception(ueArgs.Exception, 2).ShowDialog();

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
if (!debug)
{
Expand Down Expand Up @@ -76,9 +85,11 @@ static void Main(string[] args)
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.High;

Logger.init();
Skinner.init();
rnd = new Random();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//throw new Exception("asdf");
//Application.Run(new UI_Winlist());
Application.Run(new Home());
}
Expand Down Expand Up @@ -133,5 +144,22 @@ public static void fixWorkingDirectory()
System.Threading.Thread.Sleep(1000);
kill();
}

public static void popception(int lv = 1)
{
bool cu = false;
try
{
if (lv == 6)
{
throw new Exception("hit lv");
}
popception(lv + 1);
}
finally
{
cu = true;
}
}
}
}
4 changes: 2 additions & 2 deletions Loopstream/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.7.0")]
[assembly: AssemblyFileVersion("1.3.7.0")]
[assembly: AssemblyVersion("1.3.7.2")]
[assembly: AssemblyFileVersion("1.3.7.2")]
7 changes: 7 additions & 0 deletions Loopstream/UC_Graden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public Graden()
renderedOpacity = 1;
ca = _ca = colorA;
cb = _cb = colorB;

Skinner.add(this);
}

~Graden()
{
Skinner.rem(this);
}

Color ca, cb;
Expand Down
7 changes: 7 additions & 0 deletions Loopstream/UC_LLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public LLabel()
0, y, sha.Width, y);
}
}

Skinner.add(this);
}
~LLabel()
{
Skinner.rem(this);
}

double olevel;
Color agrad1, agrad2;
NPatch.VolumeSlider vs;
Expand Down
Loading

0 comments on commit 1976212

Please sign in to comment.