Can I play rtp stream at HTML5 player

Topics: Question
Feb 12, 2016 at 1:35 PM
There way to play a mp3 audio file and stremming it via rtp to play at a HTML5 web player?
Coordinator
Feb 12, 2016 at 8:15 PM
Sure, create a small duration of sound and send it to the client.

When the client is done start another request to retrieve more data, start playing the data you just received.

You can do that with Javascript and the Audio element even without HTML5.

You can do something similar with the HTML5 video element and H.264 / AAC and a mp4 / webm container. (Even works in IE 9) and you wouldn't need any Javascript although you could use the Media Source Extensions if you wanted.
Marked as answer by juliusfriedman on 2/12/2016 at 12:15 PM
Feb 17, 2016 at 6:26 PM
Good news, I don't know yet how can I set the mp3 file to start play the stream, I tryed creating a Console project and instancing the RtspServer class and then call server.TryAddMedia, but I don't know how add a mp3 file.

Any tip or tutorial to create a simple Rtp Server?

Thanks!
Coordinator
Feb 17, 2016 at 6:38 PM
There's an example of using the RtspServer in the Unit Tests project.

I don't have any support for reading from container files right now, it wouldn't be very hard to implement especially if your only considering a single file type.

I plan on adding this functionality at some point but I have quite a few other things to work on also so I have to get done what I can when time permits.

Essentially you need a way to read the container of the format the media is in, then you need to be able to take the samples of the media and convert them into RtpPackets, based on the codec of the media there are several ways the media can be packetized and thus is the reason for the delay.

All of the tools are there to accomplish this but the logic is missing to bring it all together.

There needs to be a way to create a SDP from the information within the container, and there needs to be a way to create the proper format Rtp Packets based on the codec.

If you know the SDP format for the codec in your media file and you only want to deal with a single type then this shouldn't be very hard, you would just need to implement the GetSample for the Container format of the media.

Then Packetize the byte[] returned from GetSample using the correct MediaType class from the RtspServer.

I have this in my Issues as a todo along with quite a few other things, maybe you can get started on the process and I can help you along.

Then I can integrate those efforts with what I already have and hopefully get this out for others to use also.

Let me know if you have any questions!
Marked as answer by juliusfriedman on 2/17/2016 at 10:38 AM
Feb 18, 2016 at 12:25 PM
Edited Feb 18, 2016 at 12:29 PM
Ok, in fact I would like to implement something much more.
I would like to implement a concept project of a real time radio automation with multiple collaborate client remote administration via web UI.

With HTML5 features, today it is easy to render or print audio wave like soundcloud web site do today.

By the way, the RTSP protocol is my guarantee that even web client interface can hear what is playing at moment synchronously by the server.

So the web GUI control will control the RTP stream at channel. I don't know yet how can I mix some mp3 after each audio transition like playing more than one mp3 file. But, let resolve one problem each time.

Now my next step is synchronize what is playing at server to all GUI web client.

I will consider what you told about create a SDP, containers, Rtp Packets, I will study this project better late.

Quickly, changing the subject, why you dont move this project to Github? It is more collaborative.


Thanks!
Coordinator
Feb 18, 2016 at 3:31 PM
Edited Feb 18, 2016 at 6:56 PM
The project sounds interesting but quite easy then.

MP3 is quite a simple format, I will see about including a basic elementary stream parser in the Mpeg container eventually which should cover MP3 and more.

Since you don't have to decode the format you can just worry about taking the frames which contain the mpeg audio and building a rtp packet from them.

There is a rfc which describes loss tolerant mp3 transfer over rtp, rfc 5219. It explains how to build and decode the rtp packet from the mpeg audio frames.

I would probably work on that first since it's what you really need if your going to use rtp. If I get some time I will see about integrating some additional code which helps with this.

Finally in reference to Github, I don't really gain anything besides people being able to easily fork the project which is not desirable for me, if theres another reason I should consider please let me know and I will take a look.

In the meantime let me know how else I can help.
Marked as answer by juliusfriedman on 2/18/2016 at 7:31 AM
Coordinator
Feb 19, 2016 at 10:00 PM
Edited Feb 19, 2016 at 10:10 PM
I updated the code again, while it's not very much more it should allow you to use the ProgramStreamReader to begin to parse the .mp3 file, you can check out Nlayer.CodePlex.com to get some info on how to parse the format further but remember that an MP3 is a type of Elementary Stream which has MPEG Audio headers, some of which carry ID3 and other structures which must be skipped. See MP3

There are also some other examples if you search C# MPEG Headers on google or check in the Codecs.Mp3 project which should be more than enough to get you started, combine that with the logic in the RFC and you will be able to read the encoded data to RtpPacket's and decode the RtpPacket's received to be played on the other side.

Maybe we can work together on this and I can help you so everyone can benefit from the implementation, I don't know that I will need the decoder yet but being able to read the mp3 for playback over Rtsp or save to a file / memory stream from Rtp would probably be useful for others also for various purposes and would be a good start. I am also pretty sure that I would eventually implement the same thing when I had more time anyway so it's better sooner than later.

Let me know when you are done with your research and how much time you can allocate to the project, I would estimate it definitely shouldn't take more than a month to get completed based on the requirements and what the overall goals are to achieve the general end result which you could then use in your project which is more specific and would also probably use the Nlayer decoder or some other encoder / decoder.

I can give you some additional pointers or you can just dive in and I can help you when you get stuck on something.

Have a great weekend!
Marked as answer by juliusfriedman on 2/19/2016 at 2:00 PM
Coordinator
Mar 11, 2016 at 6:14 PM
I am also planning on more audio support for PCM and Raw PCM as well as a few others defined in RFC3550 where possible.

Let me know if those might also help you, I think it might as you would be able to work things out using raw audio to more easily integrate with HTML5 and elsewhere than MP3 or Aac or otherwise as well as more platforms.
Marked as answer by juliusfriedman on 3/11/2016 at 10:14 AM
Apr 12 at 11:14 PM
Hi @juliusfriedman I will return this issue this year, we will talk more about all that.

The codeplex will down, where you migrate all this project and discussions?