LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2010, 04:43 AM   #1
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Rep: Reputation: 0
Implementation of RTP/RTCP


Hi all,
I have a SIP/UDP client running on a OS independent platform. To extend my project I am planning to implement RTP/RTCP protocol for Unicast communication. Is there a simple example of implementing this protocol by myself with C as programming language. The fact is I am not supposed to use any of the libraries or RTP stacks. It should be implemented from scratch.
So any good reference or good example would be appreciated.
If you have any questions regarding this post then please let me know!

Regards,
Greek.
 
Old 11-08-2010, 04:54 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by tecknicalgreek View Post
The fact is I am not supposed to use any of the libraries or RTP stacks. It should be implemented from scratch.
The best reference is often a working implementation. Have a look at a few and see how they do it, then you should be ready to implement your own. From what I remember, the RTP stuff included in pjsip is fairly easy to understand.
 
Old 11-08-2010, 06:35 AM   #3
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
thanks for your reply! What about the example RTP Sender and Receiver algorithms which is furnished in RFC 3550/3551. How far that can help me in implementing the same. can i follow that or as you said PJSIP is much easier to follow.
Regards,
Greek
 
Old 11-08-2010, 08:26 AM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by tecknicalgreek View Post
What about the example RTP Sender and Receiver algorithms which is furnished in RFC 3550/3551. How far that can help me in implementing the same. can i follow that or as you said PJSIP is much easier to follow.
I don't know, to be honest - after a quick look over rtp.h in the pjsip sources and a read of this Wikipedia page, I was able to implement basic sending/receiving of RTP packets. The RTP packet structure is actually fairly simple, especially if you refuse to look at packets with any non-zero CSRC count or an extension header (since you said you're doing unicast, this shouldn't be a problem).

If you've not thought to do so already, get familiar with Wireshark and have a look at some RTP going back & forth between some existing implementations (SIP phones like linphone and ekiga are good for this) to make sure you're familiar with how timestamps and sequence numbers are used, and you can get it to check your packets are okay when you start generating them. Also in Wireshark, the "Stream Analysis" in the Telephony -> RTP menu is useful, both to study what a good RTP stream is like and to check your own.

Oh, and I found sending was easier than receiving, so you're probably best to start with that.

Last edited by JohnGraham; 11-08-2010 at 08:27 AM.
 
1 members found this post helpful.
Old 11-08-2010, 09:14 AM   #5
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
thank you very much for the valuable information you gave. I do follow your instructions, and I may come up with some more questions for you from time to time.
Any way a big thanks for your support and time.
Kind Regards,
Greek.
 
Old 11-08-2010, 03:04 PM   #6
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by tecknicalgreek View Post
Hi John,
thank you very much for the valuable information you gave. I do follow your instructions, and I may come up with some more questions for you from time to time.
Any way a big thanks for your support and time.
Kind Regards,
Greek.
No problem. Was awkward for me when I had to DIY some RTP for an embedded project, but mostly because I thought it would be harder than it actually is. Feel free to ask if you run into trouble.
 
1 members found this post helpful.
Old 11-11-2010, 10:18 AM   #7
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
I have got one more open end question for you. What about RTCP, did you try to implement that protocol as well. If so did you follow the PJSIP i.e RTCP.h and RTCP.c files.
Regards,
Greek
 
Old 11-12-2010, 10:26 AM   #8
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi,
I am getting an error after compiling my project, I know it is a simple piece of code in C, but I don't know where the error lies.

This is the piece of code
struct rtp_hdr{
uint16_t v:2;
uint16_t p:1;
uint16_t x:1;
uint16_t cc:5;
uint16_t m:1;
uint16_t pt:7;
uint16_t seq;
uint16_t ts;
uint16_t ssrc;
};
typedef struct rtp_hdr rtp_hdr;

the error it throws me is like this "E268: tag "rtp_hdr" already declared", this happens with my other declarations as well and I have ported it from PJMEDIA.

I am sure that I have not declared it any where else.

Please let me know what is the mistake I am making.

Regards,
Greek.
 
Old 11-13-2010, 06:35 AM   #9
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
I haven't been able to get around to RTCP yet as it happens. If you're intent on making a fully compliant RTP/RTCP implementation, it might be worth looking at the RFC for RTP.

As for your second issue, do you have the rtp_hdr structure defined in a header file? If so, do you have an include-guard?
 
Old 11-15-2010, 05:09 AM   #10
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
need one more clarification from you, in my project I plan to design a Intercom for a House, which will be having not more than 2-3 receivers lets say each in one room. My question is only RTP Send and Receive will be sufficient or do I need to have RTCP as well. Since I am not dealing with lot of users I think it does not matter to deal with RTCP. I wanted to know your opinion on this.
Regards,
Greek.
 
Old 11-15-2010, 06:46 AM   #11
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by tecknicalgreek View Post
Hi John,
need one more clarification from you, in my project I plan to design a Intercom for a House, which will be having not more than 2-3 receivers lets say each in one room. My question is only RTP Send and Receive will be sufficient or do I need to have RTCP as well. Since I am not dealing with lot of users I think it does not matter to deal with RTCP. I wanted to know your opinion on this.
Regards,
Greek.
Yeah, RTCP would be over-the-top for that type of system. RTCP reports packet delay/jitter, but that's only really useful if the lines aren't being used by humans (e.g. telephony signalling, etc.). No computer on earth will be as good as a human at telling you if the audio quality isn't up to scratch.
 
1 members found this post helpful.
Old 11-15-2010, 09:29 AM   #12
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
thank you very much for your valuable time and support.
Regards,
Greek.
 
Old 11-23-2010, 05:41 AM   #13
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
I have again run into trouble, let me say it in brief.......
I have got a SIP client running good and after that I have integrated the Audio part to my project such that I convert the audio from Analog to Digital using PCM. This part of the audio which is sampled and stored in the buffer is sent to the G.711 Codec Routine.

In my implementation of G.711 codec I am returning the compressed data in this variable like "return (unsigned char)(alaw^0xD5);".

Now once this is done, I should initiate the RTP and pass this to the payload.

How and where should I initiate RTP, i mean at the end of my Audio Codec routine, if so which values should I pass in to the routine for-ex my routine has parameters like "rtp_session_init(rtp_session *ses, int default_pt, uint32_t sender_ssrc)", in this what should be passed for *ses and sender_ssrc.

I am totally perplexed here, please dont mind if my question was too straight forward. Let me know if you have any more doubts regarding my post.

Thank You and Regards,
Greek
 
Old 11-23-2010, 10:56 AM   #14
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by tecknicalgreek View Post
How and where should I initiate RTP, i mean at the end of my Audio Codec routine, if so which values should I pass in to the routine for-ex my routine has parameters like "rtp_session_init(rtp_session *ses, int default_pt, uint32_t sender_ssrc)", in this what should be passed for *ses and sender_ssrc.
I'm not sure I get it - it seems like you're wanting to "rtp_session_init" for every block of audio data you get, but that can't be right. In my implementation, the initialisation needs to know about the remote host to send RTP packets to (i.e. hostname/IP address and port number) and the local port to send from. Then each time the RTP is sent, I tell the session about the data to send (i.e. pass in a pointer to the buffer and the length of the buffer) that constitutes the payload of the packet, and the amount by which to increment the timestamp (since this is dependant on the codec you're using).

The RTP session object itself maintains data about the SSRC (since it has to randomly generate one, and then handle SSRC collisions) the last timestamp, the sequence number and the payload type (set separately).
 
Old 11-24-2010, 10:17 AM   #15
tecknicalgreek
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Hi John,
first of all thank you for your reply.
But still I'm not getting a clear picture, let me put it in another way.
I have implemented a lwIP TCP/IP Stack. On top of it I have implemented a UDP/SIP Client.
My SIP client sends a INVITE to Asterisk Server, gets a 200 OK response and once I get this 200 OK Response from Server I immediately send an ACK to the Server.

Until this everything works smoothly, now i have extended my project by adding the Audio part, so that I compress the data and this compressed data is finally stored in (unsigned char)(alaw^0xD5).
And as per your advice I have ported the PJSIP rtp.h and rtp.c on to my board, which I have included in my main().

According to the pjsip it has been mentioned in this way
"First application must call #pjmedia_rtp_session_init() to initialize the RTP session.
* When application wants to send RTP packet, it needs to call #pjmedia_rtp_encode_rtp() to build the RTP header. Note that this WILL NOT build the complete RTP packet, but instead only the header. Application can then either concatenate the header with the payload, or send the two fragments (the header and the payload) using scatter-gather transport API

* (e.g. \a sendv())
."

So in order to initialize this rtp_session_init(), i should pass some parameters, but I am not sure what and after that the rtp_encode() and so on.

Is it possible to get a look at your implementation, only if that is completely OK for you. If you don't want to post your implementation you can send it to my mail: tecknicalgreek@hotmail.com

Thanks and Regards,
Greek
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
secure RTP implementation for asterisks bhrugu Linux - Security 2 04-01-2014 06:25 AM
Rtp/Rtcp puneeth bhat Programming 9 07-19-2010 11:32 AM
rtp packet implementation sibtay Programming 1 08-08-2004 05:12 PM
RTP/RTCP stack max_linuxquesti Linux - Networking 0 12-18-2002 12:57 AM
HTB QOS. udp rtp rtcp. GT-GEO Linux - General 0 03-02-2002 09:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration