Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Streaming Http  (Read 2789 times)

0 Members and 2 Guests are viewing this topic.

underplank

  • Newbie
  • *
  • Posts: 4
    • View Profile
Streaming Http
« on: December 20, 2010, 06:05:04 am »
Hi All,

I've set up a streaming radio station using icecast. and I would like to use sfml to grab the stream and play it out. I know there is an intermediate problem here of the mp3 format but I think I can handle that with mpg123.

The thing that im having the problem with is how to connect to the URL and read the data from that url in chunks and append it to some kind of data structure so that I can read it in another thread.

At the moment when I use the Http class and do a Send.Request, if I try to get the body back then I get a massive string. I guess what I want to be able to do is read of a section of the string and push it onto another string, that can then be read by sf::SoundStream.OnGetData(). Im just having trouble working out how this all works.. its mentioned in the docs, but only in passing. and I havent been able to find some example code anywhere.

Could you help me out?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Streaming Http
« Reply #1 on: December 20, 2010, 07:51:38 am »
So what is your problem exactly? What have you already written?
Laurent Gomila - SFML developer

underplank

  • Newbie
  • *
  • Posts: 4
    • View Profile
Streaming Http
« Reply #2 on: December 20, 2010, 08:20:32 am »
Good point... I havent really asked a question have i? :(

What ive written:

Ive used the basic example in the sf::Http docs to connect to the streaming radio station url. This gets the data fine, but its blocking, which means I cant process the data to play.

So I think what I need to work out is how to use the sf:http class to connect to my streaming radio station and instead of just blocking and buffering the data, it needs to push it onto a vector or some such thing. This would mean in another thread I could pop the data of the other end of the vector and play the audio.

So My two questions are.

1. Does my theory about how to do this (I imagine im going to need locking as well) seem right?

2. How do I do this with the sf::Http class?

Cheers

Mark

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Streaming Http
« Reply #3 on: December 20, 2010, 08:28:26 am »
You're right, and you'll find a code that uses network and streaming together in the SFML examples ("voip"). I think it will help you.
Laurent Gomila - SFML developer

underplank

  • Newbie
  • *
  • Posts: 4
    • View Profile
Streaming Http
« Reply #4 on: December 20, 2010, 08:51:15 am »
cheers for that.

The voip one seems to work at the sockets level. Is there one that works with sf::http? Its just that my radio station has all the http stuff in there, and while I could build on top of sockets to get to http, you guys have done such a great job it seems a shame not to use it..

Cheers

Mark

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Streaming Http
« Reply #5 on: December 20, 2010, 08:58:14 am »
I have no idea about how HTTP streams work, so you'll have to figure out this part by yourself. However, it's just a matter of decoding the audio data from HTTP replies; the rest is the same as the voip example (threading, data queue, feeding the audio stream, ...).
Laurent Gomila - SFML developer

underplank

  • Newbie
  • *
  • Posts: 4
    • View Profile
Streaming Http
« Reply #6 on: December 20, 2010, 09:03:54 am »
The problem is not so much with how the audio streams work, its more to do with how sf::Http works. WHen you do a request ie

Page = Http.SendRequest(Request);

this blocks until it gets to the end of the Page, filling up the internal myBody string. I guess what I need to do is extend the http class to allow it to spit out a chunk of it at a time. Or just build on the sockets stuff..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Streaming Http
« Reply #7 on: December 20, 2010, 09:09:10 am »
I'm pretty sure there is a standard for HTTP streaming, probably using chunked data. You should search a little bit, maybe in the HTTP RFCs.

Like I said, I have no idea how this works so I can't help you more. I don't even know if SFML wil be able to handle that (it currently doesn't support chunked data).
Laurent Gomila - SFML developer

 

anything