基本上,我正在使用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标头插入其他值/参数?
如果要使用其他参数实现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.
感谢您的回答。实际上,我想在RTP标头中添加每个记录的语音数据包的能量。如您所说,我可以使用“ RTP扩展标题”来做到这一点。因此,您能给我任何程序示例来添加扩展名吗,因为我无法在Google和Google WebRTC组上找到与此相关的任何示例。
不幸的是,我对语音包能量的概念并不熟悉。如果是整数,我们说uint32_t,则需要创建一个结构:```#pragma pack(1)struct RtpExtension {uint32_t enery; }; #pragma pop```然后将其添加到RTP数据包结构的末尾:```#pragma pack(1)struct RtpHeader {默认字段... struct RtpExtension扩展;}; struct RtpHeader h; h.extension.energy = htol(soem_energy_value); ``
先生,您能否根据上述意见以编程方式修改您的答案?我们将不胜感激。我很高兴接受它作为我对“堆栈溢出”的第一个有价值的答案。谢谢
@Abdulahad,是的,有点混乱,我已经更新了答案,希望对您有所帮助。
我通过为新添加的扩展元素提供有效的ID和长度来尝试您的方法,但是它不会将此新添加的元素发送到其他对等连接。