Skip to content

Commit

Permalink
Changed the readme a bit, fixed a bug in the HttpServer and fixed the…
Browse files Browse the repository at this point in the history
… mime-type of the stream
  • Loading branch information
Banane9 committed Jan 19, 2014
1 parent e82e021 commit ca6cd1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
43 changes: 4 additions & 39 deletions PiStrom/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> metaByteBuffer = new List<byte>();

// 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()
Expand Down
3 changes: 2 additions & 1 deletion PiStrom/MusicStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -84,6 +84,7 @@ public void Run(CancellationToken cancellationToken)
{
Thread.Sleep(delay - sinceLastSend);
}

lastSend = DateTime.Now;

Parallel.ForEach(clients, client =>
Expand Down
4 changes: 2 additions & 2 deletions PiStrom/Streams/Electro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<StreamInfo>
<Name>Electro Stream</Name>
<Genre>Electro</Genre>
<MetaInt>32768</MetaInt>
<TargetByteRate>24000</TargetByteRate>
<MetaInt>65536</MetaInt>
<TargetByteRate>25000</TargetByteRate>
<Music FileType="mp3">
<TimeSpan From="02:00" Till="21:40">
<Folder>C:\Users\Banane\Music\Binärpilot</Folder>
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ This folder contains the informations for the individual streams that will be av
<StreamInfo>
<Name>Electro Stream</Name>
<Genre>Electro</Genre>
<MetaInt>32768</MetaInt>
<TargetByteRate>24000</TargetByteRate>
<MetaInt>65536</MetaInt>
<TargetByteRate>25000</TargetByteRate>
<Music FileType="mp3">
<TimeSpan From="02:00" Till="21:40">
<Folder>C:\Users\Banane\Music\Binärpilot</Folder>
Expand All @@ -87,7 +87,9 @@ While it is a bit more complex than `PiStrom.xml`, it's easy to understand as we

* `<MetaInt>` 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.

* `<TargetByteRate>` 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.
* `<TargetByteRate>` 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.

Expand Down

0 comments on commit ca6cd1f

Please sign in to comment.