|
|
#1 |
|
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. |
|
|
|
|
|
#2 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#3 |
|
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 |
|
|
|
|
|
#4 | |
|
Moderator Alumni
Join Date: May 2000
Location: Next Door
Posts: 8,888
|
Quote:
-Jay | Radio Toolbox.com |
|
|
|
|
|
|
#5 |
|
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. |
|
|
|
|
|
#6 | |||
|
Moderator Alumni
Join Date: May 2000
Location: Next Door
Posts: 8,888
|
Re: yep...more questions
Quote:
But a quick example would be something like code: Its rough I know but should give you a better idea. Quote:
Quote:
-Jay | Radio Toolbox.com |
|||
|
|
|
|
|
#7 |
|
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. |
|
|
|
|
|
#8 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#9 |
|
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. |
|
|
|
|
|
#10 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#11 |
|
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 |
|
|
|
|
|
#12 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#13 |
|
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? |
|
|
|
|
|
#14 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#15 |
|
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? |
|
|
|
|
|
#16 |
|
Moderator Alumni
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 | Radio Toolbox.com |
|
|
|
|
|
#17 |
|
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. |
|
|
|
|
|
#18 |
|
Junior Member
|
is it hard to get a list of all the shoutcast servers with a vb.net program? like winamp does?
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|