diff --git a/PiStrom/HttpServer.cs b/PiStrom/HttpServer.cs index bd98962..9bb5eab 100644 --- a/PiStrom/HttpServer.cs +++ b/PiStrom/HttpServer.cs @@ -129,46 +129,11 @@ private void OnConnection(Socket socket, CancellationToken cancellationToken) streams.Add(requestSplit[1], musicStream); } + else + { + socket.Close(); + } } - - //socket.Send(Encoding.UTF8.GetBytes(responseHeader)); - - //string[] files = new string[] { @"C:\Users\Banane\Music\Binärpilot\Nordland\10 - Nordland.mp3", @"C:\Users\Banane\Music\Binärpilot\Nordland\01 - aXXo.mp3" }; - //string[] names = new string[] { "Nordland", "aXXo" }; - - //buffer = new byte[32768]; - - //try - //{ - // for (int i = 0; i < 2; i++) - // { - // FileStream fileStream = File.OpenRead(files[i]); - - // while (fileStream.Position < fileStream.Length) - // { - // fileStream.Read(buffer, 0, buffer.Length); - // socket.Send(buffer); - - // if (sendIcyMeta) - // { - // List metaByteBuffer = new List(); - - // string meta = "StreamTitle='" + names[i] + "';"; - // meta = meta.PadRight(meta.Length + (16 - (meta.Length % 16))); - // byte[] metaBytes = Encoding.UTF8.GetBytes(meta); - - // metaByteBuffer.Add((byte)(metaBytes.Length / 16)); - // metaByteBuffer.AddRange(metaBytes); - - // socket.Send(metaByteBuffer.ToArray()); - // } - // } - // } - //} - //catch - //{ - // Console.WriteLine("Connection dropped."); - //} } public void Start() diff --git a/PiStrom/MusicStream.cs b/PiStrom/MusicStream.cs index 951562a..4429ce9 100644 --- a/PiStrom/MusicStream.cs +++ b/PiStrom/MusicStream.cs @@ -52,7 +52,7 @@ public MusicStream(string configPath) public void AddClient(Socket client, bool metaInfo) { - string responseHeader = "HTTP/1.1 200 OK\r\nContent-Type: audio/mpeg\r\nServer: PiStrøm\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nConnection: close\r\n" + (metaInfo ? "icy-metaint:" + StreamInfo.MetaInt + "\r\nicy-name:" + StreamInfo.Name + "\r\nicy-genre:" + StreamInfo.Genre + "\r\n" : "") + "\r\n"; //icy-url:http://localhost:1337\r\n type: audio/mpeg + string responseHeader = "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nServer: PiStrøm\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nConnection: close\r\n" + (metaInfo ? "icy-metaint:" + StreamInfo.MetaInt + "\r\nicy-name:" + StreamInfo.Name + "\r\nicy-genre:" + StreamInfo.Genre + "\r\n" : "") + "\r\n"; //icy-url:http://localhost:1337\r\n type: audio/mpeg client.Send(Encoding.UTF8.GetBytes(responseHeader)); clients.Add(client, metaInfo); } @@ -84,6 +84,7 @@ public void Run(CancellationToken cancellationToken) { Thread.Sleep(delay - sinceLastSend); } + lastSend = DateTime.Now; Parallel.ForEach(clients, client => diff --git a/PiStrom/Streams/Electro.xml b/PiStrom/Streams/Electro.xml index a7417bf..125d4e4 100644 --- a/PiStrom/Streams/Electro.xml +++ b/PiStrom/Streams/Electro.xml @@ -2,8 +2,8 @@ Electro Stream Electro - 32768 - 24000 + 65536 + 25000 C:\Users\Banane\Music\Binärpilot diff --git a/README.md b/README.md index b01afd5..b75bf95 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ This folder contains the informations for the individual streams that will be av Electro Stream Electro - 32768 - 24000 + 65536 + 25000 C:\Users\Banane\Music\Binärpilot @@ -87,7 +87,9 @@ While it is a bit more complex than `PiStrom.xml`, it's easy to understand as we * `` is the interval (in bytes) at which MetaInfo will be embedded into the Stream. Also defines the size of the buffer into which is read from the file and from which is written into the Stream. -* `` is the maximum rate at which data is sent. In bytes per second. To get the value from the kbit/s of the music, multiply by 8000. For example 192kbit/s would require 24000 byte/s. +* `` is the maximum rate at which data is sent. In bytes per second. To get the value from the kbit/s of the music, divide by eight and then multiply by a thousand. For example 192kbit/s would require 24000 byte/s. + +**Note that, if the connection isn't at top speed and the file requires the limit it might get a bit laggy and the player stops, to buffer some data. To prevent this, simply set the value higher than the maximum required value.** Now, the values for Name and Genre only matter if the Client requests `Ice-MetaInt: 1` as a HTTP header in the request. The MetaInfo will also only be sent if that was requested, but it still defines the buffer size.