Basically, I am working in the VOIP application and trying to build an app using the WebRTC. I already know complete implementation and details about the RTP header which contains things like
1. version
2. padding
3. extension
4. CSRC count
5. marker
6. payload type
7. sequence number
8. Time Stamp
9. SSRC
10. CSRC list
But I want to add additional parameters in the RTP header so that I can send it to another PEER. Also, please do update me how to add information and update the RTP header which is of 12 bytes.
Here are the files from webrtc native stack.
How can I insert additional values/Parameters with RTP header in WEBRTC?
If you're implementing an RTP packet with additional parameters, you need to put them in the "Extension header". The extension is located right after the default RTP header values. Don't forget to set "profile-specific extension header ID"(your extension id) and "extension header length"(length of extension excludes the extension header). After you add the extension, you need to make sure that the receiver application is familiar with the extension. Otherwise, it will be ignored(in the best case).
Regarding the Google Chromium implementation, I'd recommend diving into the implementation.
Copied from the comment below:
#pragma pack(1) // in order to avoid padding
struct RtpExtension {
// Use strict types such as uint8_t/int8_t, uint32_t/int32_t, etc
// to avoid possible compatibility issues between
// different CPUs
// Extension Header
uint16_t profile_id;
uint16_t length;
// Actual extension values
uint32_t enery;
};
#pragma pop
Here I assume that you already have a structure for the RTP packet. In case you don't, please refer to Manuel's comment or lookup on the Internet.
#pragma pack(1)
struct RtpHeader {
// default fields...
struct RtpExtension extension;
};
// Actual usage
struct RtpHeader h;
// Fill the header with the default values(sequence number, timestamp, whatever)
// Fill the extension:
// if the value that you want to end is longer than 1 byte,
// don't forget to convert it to the network byte order(htol).
h.extension.energy = htol(some_energy_value);
// length of the extention
// h.extension.length = htons(<length of the extension>);
// In this specific case it can be calculated as:
h.extension.length = htons(sizeof(RtpExtension) - sizeof(uint16_t) - sizoef(uint16_t));
// Make sure that RTP header reflects that it has the extension:
h.x = 1; // x is a bitfield, in your implementation, it may be called differently and set in another way.
Thanks for your answer. Actually, I want to add energy of every recorded voice packet in RTP headers. As you said, I can do it by using the "RTP Extension Header". So, can you please give me any programmatic example to add extension because I am unable to find any example related to this on Google and Google WebRTC groups.
Unfortunately, I am not familiar with the concept of the energy of the voice packet. If it is an integer, let us say uint32_t, then you need to create a struct: ``` #pragma pack(1) struct RtpExtension { uint32_t enery; }; #pragma pop ``` Then add it to the end of your RTP packet struct: ``` #pragma pack(1) struct RtpHeader { default fields... struct RtpExtension extension; }; struct RtpHeader h; h.extension.energy = htol(soem_energy_value); ````
Sir, can you please modify your answer in a programmatic way based on your comment given above? It would be really appreciated. I would be glad to accept it as my first valuable answer on "Stack overflow". Thanks
@Abdulahad, yeah it was a bit messy, I've updated the answer, hope it helps.
I have tried your method by providing the valid id and length to the new added extension element but it doesn't send this new added element to the other peer connection.