Skip to content

Commit

Permalink
v.1.1.0.0, 2013-07-30, 12:08:47
Browse files Browse the repository at this point in the history
+ TAGS! (foobar,winamp,vlc,itunes,custom)
+ 32bit cloning for eavesdropping on 32bit apps
+ Settings GUI looks dope
+ Basic network monitor
+ Soundcard detection progressbar
  • Loading branch information
9001 committed Oct 12, 2015
1 parent 745c7b2 commit c2a0d1c
Show file tree
Hide file tree
Showing 18 changed files with 2,057 additions and 536 deletions.
40 changes: 38 additions & 2 deletions Loopstream/LSEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Loopstream
{
public class LSEncoder
{
object locker;
protected bool dump;
protected Process proc;
protected LSPcmFeed pimp;
Expand All @@ -36,6 +37,7 @@ public LSEncoder()
dump = false;
settings = null;
crashed = false;
locker = new object();
}

protected void makeShouter()
Expand Down Expand Up @@ -119,11 +121,16 @@ protected void makeShouter()
else if (str.StartsWith("HTTP/1.0 200 OK"))
{
s = prepS;
stampee = 0;
stdin = pstdin;
stdout = pstdout;
stamps = new List<long>();
stamps = new long[32];
chunks = new long[32];
long v = DateTime.UtcNow.Ticks / 10000;
for (int a = 0; a < stamps.Length; a++) stamps[a] = v;
Program.ni.ShowBalloonTip(1000, "Loopstream Connected", "Streaming to " + settings.mount + "." + enc.ext, ToolTipIcon.Info);
new System.Threading.Thread(new System.Threading.ThreadStart(reader)).Start();
new System.Threading.Thread(new System.Threading.ThreadStart(counter)).Start();
}
else
{
Expand All @@ -132,7 +139,9 @@ protected void makeShouter()
}
}

public List<long> stamps;
int stampee;
public long[] chunks;
public long[] stamps;
protected void reader()
{
System.IO.FileStream m = null;
Expand All @@ -159,18 +168,45 @@ protected void reader()
}
catch
{
enc.FIXME_kbps = -1;
crashed = true;
break;
}

// speed measuring
lock (locker)
{
chunks[stampee] = i;
stamps[stampee] = DateTime.UtcNow.Ticks / 10000;
stampee = ++stampee < stamps.Length ? stampee : 0;
}
}
string fn = proc.StartInfo.FileName;
fn = fn.Substring(fn.Replace('\\', '/').LastIndexOf('/') + 1).Split('.')[0];
Console.WriteLine("shutting down " + fn);
if (m != null) m.Close();
}

void counter()
{
while (!crashed)
{
lock (locker)
{
long time = DateTime.UtcNow.Ticks / 10000;
int i = stampee + 1;
i = i >= stamps.Length ? 0 : i;
time -= stamps[i];
enc.FIXME_kbps = Math.Max(1, ((8000.0 * (chunks.Sum() - 4096)) / time) / 1024);
}
System.Threading.Thread.Sleep(10);
}
enc.FIXME_kbps = -1;
}

public void Dispose()
{
enc.FIXME_kbps = -1;
stdin = stdout = null;
crashed = true;
proc.Kill();
Expand Down
108 changes: 92 additions & 16 deletions Loopstream/LSSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ public void apply(LSPreset preset)
}
}

public class LSMeta
{
public enum Reader { WindowCaption, File, Website, ProcessMemory };
public string src, ptn, tit;
[XmlIgnore]
public Encoding enc;
public string encoding { get { return enc.WebName; } set { enc = Encoding.GetEncoding(value); } }
public Reader reader;
public int freq, grp;

public LSMeta()
{
src = ptn = tit = "";
encoding = "UTF-8";
reader = Reader.WindowCaption;
freq = 500;
grp = 1;
}
public LSMeta(Reader r, string ti, string sr, int fr, string pt, int grp)
{
reader = r;
tit = ti;
src = sr;
ptn = pt;
freq = fr;
encoding = "UTF-8";
this.grp = grp;
}
public override string ToString()
{
return tit;
}
public void apply(LSMeta meta)
{
src = meta.src;
ptn = meta.ptn;
tit = meta.tit;
encoding = meta.encoding;
reader = meta.reader;
freq = meta.freq;
grp = meta.grp;
}
}
public List<LSMeta> metas;
public LSMeta meta;
public bool latin;

public enum LSCompression { cbr, q };
public enum LSChannels { mono, stereo }
public class LSParams
Expand All @@ -49,6 +96,7 @@ public class LSParams
public long quality;
public LSChannels channels;
public string ext;
public double FIXME_kbps;
}

LSDevice _devRec, _devMic, _devOut;
Expand Down Expand Up @@ -76,6 +124,9 @@ public class LSParams
public enum LSRelay { ice, shout, siren }
public LSRelay relay;

public string title, description, genre, url;
public bool pubstream;

public bool testDevs;
public bool splash;
public bool recPCM;
Expand Down Expand Up @@ -105,11 +156,22 @@ public LSSettings()
ogg.channels = LSChannels.stereo;
ogg.ext = "ogg";
samplerate = 44100;

host = "stream0.r-a-d.io";
port = 1337;
pass = "user|assword";
mount = "main";
relay = LSRelay.ice;
title = "Loopstream";
description = "Cave Explorer Committee";
genre = "Post-Avant Jazzcore";
url = "https://github.com/9001/loopstream";
pubstream = false;

latin = false;
meta = new LSMeta();
metas = new List<LSMeta>();

presets = new LSPreset[] {
new LSPreset(1.00, 1, 0.6, 1, true, false, false),
new LSPreset(0.25, 1, 0.6, 1, true, true, false),
Expand Down Expand Up @@ -153,12 +215,33 @@ in mde.EnumerateAudioEndPoints(
if (!string.IsNullOrEmpty(s_devRec)) devRec = getDevByID(s_devRec);
if (!string.IsNullOrEmpty(s_devMic)) devMic = getDevByID(s_devMic);
if (!string.IsNullOrEmpty(s_devOut)) devOut = getDevByID(s_devOut);

}
public void initWhenDeserializationFails()
{
if (metas.Count == 0)
{
metas.AddRange(new LSMeta[] {
new LSMeta(LSMeta.Reader.WindowCaption, "Foobar 2000", "foobar2000", 500,
@" *(.*[^ ]) *( - foobar2000$|\[foobar2000 v([0-9\.]*)\]$)", 1),
new LSMeta(LSMeta.Reader.WindowCaption, "Winamp", "winamp", 500,
@"([0-9]*\. )? *(.*[^ ]) * - Winamp$", 2),
new LSMeta(LSMeta.Reader.WindowCaption, "VLC", "vlc", 500,
@" *(.*[^ ]) * - VLC media player", 1),
new LSMeta(LSMeta.Reader.ProcessMemory, "iTunes 64bit 11.0.4.4", "itunes", 500,
"iTunes.dll+15C4D52, iTunes.dll+15C4952", 1),
new LSMeta(LSMeta.Reader.Website, "other icecast mount", "http://stream0.r-a-d.io:8000/", 2000,
"<tr>\\n<td><h3>Mount Point /main.mp3</h3></td>.*?<td>Current Song:</td>\\n<td class=\"streamdata\">(.*?)</td>", 1),
});
}
}
public void runTests(Splesh splesh)
{
if (testDevs)
{
foreach (LSDevice dev in devs)
for (int a = 0; a < devs.Length; a++)
{
dev.test();
splesh.prog(a + 1, devs.Length);
devs[a].test();
}
/*using (System.IO.StreamWriter sw = new System.IO.StreamWriter("Loopstream.devs", false, Encoding.UTF8))
{
Expand Down Expand Up @@ -215,7 +298,7 @@ static int version()
public void save()
{
XmlSerializer x = new XmlSerializer(this.GetType());
using (var s = System.IO.File.OpenWrite("Loopstream.ini"))
using (var s = new System.IO.FileStream("Loopstream.ini", System.IO.FileMode.Create))
{
byte[] ver = System.Text.Encoding.UTF8.GetBytes(version().ToString("x") + "\n");
s.Write(ver, 0, ver.Length);
Expand All @@ -233,16 +316,8 @@ public static LSSettings load()
string str = System.IO.File.ReadAllText("Loopstream.ini", Encoding.UTF8);
string ver = str.Substring(0, str.IndexOf('\n'));
str = str.Substring(ver.Length + 1);
if (str.EndsWith(">>"))
{
str = str.Substring(0, str.Length - 1);
}
System.IO.MemoryStream s = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(str));

// FIXED LOL



int myVer = version();
int iniVer = Convert.ToInt32(ver, 16);
if (myVer != iniVer && false)
Expand Down Expand Up @@ -271,6 +346,9 @@ public static LSSettings load()
try
{
ret.init();
ret.mp3.FIXME_kbps =
ret.ogg.FIXME_kbps = -1;
return ret;
}
catch (Exception e)
{
Expand All @@ -279,10 +357,8 @@ public static LSSettings load()
e.Message + "\r\n\r\n" + e.Source + "\r\n\r\n" + e.InnerException + "\r\n\r\n" + e.StackTrace);
}
}
else
{
ret = new LSSettings();
}
ret = new LSSettings();
ret.initWhenDeserializationFails(); // it is 06:20 am, what are you looking at
return ret;
}
}
Expand Down
Loading

0 comments on commit c2a0d1c

Please sign in to comment.