基本上,我在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头中添加额外的参数,这样我就可以将它发送到另一个对等点。此外,请更新我如何添加信息和更新的RTP头,这是12个字节。
以下是来自webrtc本机堆栈的文件。
如何在WEBRTC中使用RTP头插入附加值/参数?
发布于 2020-12-08 15:35:37
如果要使用附加参数实现RTP数据包,则需要将它们放在"Extension“中。扩展位于默认的RTP头值之后。不要忘记设置“特定于配置文件的扩展头id”(扩展id)和“扩展头长度”(扩展长度不包括扩展头)。添加扩展后,需要确保接收方应用程序熟悉扩展。否则,它将被忽略(在最好的情况下)。
关于Google的实现,我建议深入研究这个实现。
抄录自以下评论:
#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的评论或在互联网上查找。
#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.https://stackoverflow.com/questions/65198821
复制相似问题