Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Reply
Thread Tools Search this Thread Display Modes
Old 30th October 2002, 04:04   #1
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
Shoutcast Protocol : source -> SHOUTcast

Hello ALL

I'm interested in building my own source for a SHOUTcast server. I'm hoping to find detailed information how you use the SHOUTcast protocol to establish a stream from a source to the SHOUTcast server.

I found this article:
http://forums.radiotoolbox.com/viewtopic.php?t=74

After reading it I understand how to prepare a server for an mp3 stream and how to update basic things like song titles. I may have missed something, but it doesn't seem to explain how you actually stream MP3 data to the SHOUTcast server.

The article says you send information ABOUT the stream by doign this:

icy-name:Unnamed Server\r\nicy-genre:Unknown Genre\r\nicy-pub:1\r\nicy-br:56\r\nicy-url:http://www.shoutcast.com\r\nicy-irc:...:N%2FA\r\n\r\n

I imagine that is some sort of header? Do you tack on the MP3 data to the end of the header?

Does anyone out there have this isnformation? I'd love to see an example of how you build your own source..regardless of the language. Psuedocode would be good enough.

Thanks for reading.
Dredd is offline   Reply With Quote
Old 30th October 2002, 04:13   #2
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
the first thing you do as the source is send the password of the server, then the server responds with OK2, that is your cue to send the stream's header which is the code you posted (note that \r\n is a linefeed not meant to be used literally), after the header has been sent then send mpeg data.
Jay is offline   Reply With Quote
Old 30th October 2002, 04:32   #3
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
Ahhh....thats what I thought. Thanks for the confirmation.


Just a couple more questions:

1. When I stream the data to the Shoutcast server I probably have to send in a steady stream of X bytes. Where X bytes is in proportion to the rate I am broadcasting at. So..if all my MP3's are encoded at 32Kbs I'd send chunks of 4096KB....right?

2. Maybe this question is one in the same as the first one...... How to I make sure I am not sending the data too fast, or too slow to shoutcast? Do i need to pause a bit before each chunk I'm streaming? Know what I mean? I don't want to send the stream faster than SHOUTcast will send it to the client otherwise I'll overrun SHOUTcasts buffer and...well...it will suck.

Thanks
Dredd is offline   Reply With Quote
Old 30th October 2002, 04:48   #4
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
Quote:
Originally posted by Dredd
Ahhh....thats what I thought. Thanks for the confirmation.


Just a couple more questions:

1. When I stream the data to the Shoutcast server I probably have to send in a steady stream of X bytes. Where X bytes is in proportion to the rate I am broadcasting at. So..if all my MP3's are encoded at 32Kbs I'd send chunks of 4096KB....right?

2. Maybe this question is one in the same as the first one...... How to I make sure I am not sending the data too fast, or too slow to shoutcast? Do i need to pause a bit before each chunk I'm streaming? Know what I mean? I don't want to send the stream faster than SHOUTcast will send it to the client otherwise I'll overrun SHOUTcasts buffer and...well...it will suck.

Thanks
well I am currently takling this one in my php source program. It's difficult because you don't have a player doing this for you like in a dsp environment. If you are encoding the data and sending it then all you need to do is regulate the rate to the birate set in the file per second. If the shoutcast buffer runs too low then your listener will experience a stop in the stream to wait for the source to fill the winamp buffer back up. If you transfer the data too fast then the buffer in shoutcast overwrites itself before the client has a chance to get the stream, which makes for a very strange experience. If you find that the regulation scheme I have talked about doesn't meet the needs of shoutcast let me know but in my php environment it seems to be working more or less. Also just FYI the data you send per sec is in kilo bits not bytes a the chunck you have listed would make for a confusing experience on the shoutcast server.
Jay is offline   Reply With Quote
Old 30th October 2002, 05:06   #5
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
yep...more questions

This is more or less going to be my first attempt to make my ouwn SHOUTcast source. I took a really weak stab at it a year ago using Python wrapper for libshout and then dropped the ball.

would it be ok if I saw your "anti-bufferflow" alogorithm that you are using? I'm not sure I understood what you were telling me.

Also, when I look at the messages you are supposed to send to SHOUTcast via its port, I see lots of \r\n. Does that mean CRLF ...Carriage Return Line Feed? Ascii 10 & ascii 13? Or something like that?

Also..when I open the socket, what protocol do I use? TCP, UDP? I assume TCP.

Thanks again. I should go to sleep before I stay up much later thinking of more questions.

PS
I'm attempting to write this with either MS VB.NET or MS C# to make this either very interesting or very painful.
Dredd is offline   Reply With Quote
Old 30th October 2002, 05:16   #6
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
Re: yep...more questions

Quote:
Originally posted by Dredd
This is more or less going to be my first attempt to make my ouwn SHOUTcast source. I took a really weak stab at it a year ago using Python wrapper for libshout and then dropped the ball.

would it be ok if I saw your "anti-bufferflow" alogorithm that you are using? I'm not sure I understood what you were telling me.
well you are free to download mp3 toolbox at www.radiotoolbox.com/mp3toolbox/ but I don't think it will help because I do not have much control of sockets in PHP default install environment.

But a quick example would be something like
code:

while (*we are connected*)
{
*send bitrate of mp3 multiplied by 1024 divided by 8 (so you get it in bytes)*

sleep(1000); // Sleep for 1 second
}


Its rough I know but should give you a better idea.
Quote:
Originally posted by Dredd

Also, when I look at the messages you are supposed to send to SHOUTcast via its port, I see lots of \r\n. Does that mean CRLF ...Carriage Return Line Feed? Ascii 10 & ascii 13? Or something like that?
Exactly, \r\n = CRLF
Quote:
Originally posted by Dredd

Also..when I open the socket, what protocol do I use? TCP, UDP? I assume TCP.
TCP
Jay is offline   Reply With Quote
Old 30th October 2002, 19:42   #7
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
More Questions :)

Jay,

Thanks for all your help so far. I have managed to create my own source for SHOUTcast and it works...mostly

Do you have any advice for getting the MP3 stream to the client to play smoothly?

When I use my new source to send the stream to SHOUTcast, the WINAMP clients stutter, click, pop and chirp a little.

I tried pausing at different intervals (.5 secds - 2 seconds) between buffer writes to SHOUTcast, but that didn't make a difference. So I guess timing is not the problem.

I'm reading the file from the file system, in chunks of X, then I send the chunk of X Bytes over to shoutcast....repeat the process until I've reached the end of the file.

Maybe I should read the while file into memory then chunk it over to the server?

Any advice would be great.
Dredd is offline   Reply With Quote
Old 30th October 2002, 19:47   #8
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
is the chirping constant and regular or does it happen every few seconds or so?
Jay is offline   Reply With Quote
Old 30th October 2002, 19:58   #9
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
chirps n burps

well the static like noises and chirps don't seem to happen too often.

But there is a steady stutter every second or so. It happens so fast its hard to tell what is going on, but it sounds like a fade out then fade it...but its hard to tell....its liek a fraction of a second.

Also, once in a while a little red light appears to the left of the green arrow...right near the time. Its the red light/dot that lights up when winamp isn't playing anything.So..does that mean I have a timing issue?

Also, my source, shoutcast and winamp are located on the same machine. I checked the CPU usage for each process and its very low. I have plenty of resources available..so I don't think I'm getting bogged down anywhere.
Dredd is offline   Reply With Quote
Old 30th October 2002, 20:11   #10
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
sounds like a sync problem in the mp3 stream, i.e. garbage is getting into the stream, i'd check your network code. You can also try sending more data, say 2% more and see if it resolves the stuttering, there may be overhead we are not considering here.
Jay is offline   Reply With Quote
Old 30th October 2002, 20:25   #11
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
hmmmm

Sending more data didn't seem to help

Also, The MP3 by it self is clean. It plays great in winamp when opened from disk..and it also plays well through the Shoutcast DSP plugin.


Just so you have an idea what I'm doing here is my loop for streaming the file. Its nothing fancy..I've seen other streamers written in Python and Perl..and they pretty much do what you see below:


Dim BR As New IO.BinaryReader(IO.File.OpenRead(sFile))

Do Until BR.Read = -1
BR.Read(buffer, 0, bufferlen)
networkStream.Write(buffer, 0, bufferlen) 'write to SHOUTcast
meThread.Sleep(1000) ' Sleeps for 1 second
Loop


I don't get it..I'm going to have to keep plugging along and trying things out. I've come pretty far though
Dredd is offline   Reply With Quote
Old 30th October 2002, 20:37   #12
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
yea I have no doubt that the file is clean. I wrote a tiny shoutcast source -> server -> client solution a few months ago and found that mistakes in my network code caused the problems you are having. like an unclean buffer and stuff. This problem is more highly specialized to the environment you are working in, which I know very little about unfortunately. As a debug you could take the buffer and while the mp3 is being fed into the server write using the exact same buffer to a file and play the created file in winamp to see if it has the artifacts. This might help determine if its a problem in your code, or something else.
Jay is offline   Reply With Quote
Old 30th October 2002, 20:44   #13
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
Good idea

That is a good idea. I'm going to give thata try.


Although..the network code is all built in. I didn't have to write the socket plumbing. Those few lines are all I have to do. I'm developing this with .Net and it has a very rich networking libary, very similar to Java.

I've used both the Java and .Net networkign libaries for communicating via sockets before, with no hitch. But never with binary data.


Anyway....before I go and write that buffer to the file, is there anything I am not doing? I do I have to send any sort of header before each track? I send the standard ICY header right after I authenticate, but is there anything else I need to send with each track I stream?
Dredd is offline   Reply With Quote
Old 30th October 2002, 20:51   #14
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
Well when working with binary files on windows be careful to open them in binary mode.

and nope the first header is all you have to send the rest is just pure mpeg data..
Jay is offline   Reply With Quote
Old 31st October 2002, 01:47   #15
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
bah!

frustration
anger
pain
despair
determination
Refuse to be DENIED!!!


It looks like I solved the problem..by reading the whole MP3 into memory and then streaming it..its not choppy anymore.

It may not be the best answer but it works...and RAM is cheap.....

Kind of lame that I have to do that huh?
Dredd is offline   Reply With Quote
Old 31st October 2002, 02:24   #16
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
wow that's pretty messed up. Maybe instead of reading all of it you create a small buffer
Jay is offline   Reply With Quote
Old 31st October 2002, 02:33   #17
Dredd
Member
 
Join Date: Oct 2002
Posts: 61
Buffers....

Ya...I messed around with the buffer sizes, but it wasn't getting me anywhere. I'm sure I could find the correct buffer size/bitrate ratio but I shoudln't have to. It should just work they way I had it..the way everyone else does it.

I posted some comments on the MS VB.Net newsgroup about this. It looks like file access in .Net maybe a tad slow, or I wasn't using the best method to access a file. Either way, I'm sure one of the people that monitor that group will get back to me with some info. They do a pretty good job of monitoring thier news groups.

Now...this probably belongs in anoher thread..but It just an quick question. Can you point me in the direction of anyting that can help me downsample mp3's on the fly? I saw LAME and I may have trouble getting that to integrate with my .Net application on windows..so I probably can't use that. Any other options? Worst case I'll just create duplicate tracks with different sample rates.

Thanks for all the help so far. Now that I have the streaming fundamentals out of the way, I can start concentration on my radio stations features.
Dredd is offline   Reply With Quote
Old 10th February 2006, 20:35   #18
teknology
Junior Member
 
Join Date: Feb 2006
Posts: 4
Send a message via AIM to teknology Send a message via Yahoo to teknology
is it hard to get a list of all the shoutcast servers with a vb.net program? like winamp does?
teknology is offline   Reply With Quote
Reply
Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump