Warm tip: This article is reproduced from serverfault.com, please click

c++-如何在RTP标头中添加其他值/参数

(c++ - How to add additional value/parameters in RTP header)

发布于 2020-12-08 12:19:49

基本上,我正在使用VOIP应用程序,并尝试使用WebRTC构建应用程序。我已经知道完整的实现和有关RTP标头的详细信息,其中包含类似以下内容的信息

 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

但是我想在RTP标头中添加其他参数,以便可以将其发送到另一个PEER。另外,请确实更新我如何添加信息并更新12字节的RTP标头。

这是来自webrtc本机堆栈的文件。

如何在WEBRTC中使用RTP标头插入其他值/参数?

Questioner
Abdul ahad
Viewed
11
fsquirrel 2020-12-10 00:06:26

如果要使用其他参数实现RTP数据包,则需要将它们放在“扩展头”中。该扩展名位于默认RTP标头值之后。不要忘记设置“特定于配置文件的扩展头ID”(你的扩展ID)和“扩展头长度”(扩展长度不包括扩展头)。添加扩展名后,需要确保接收方应用程序熟悉该扩展名。否则,它将被忽略(在最佳情况下)。

关于Google Chromium实施,我建议你深入研究该实施。

复制自以下评论:

#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

在这里,我假设你已经具有RTP数据包的结构。如果你不这样做,请参考Manuel的评论或在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.