Encoding primary packet only if red encoding don't have enough space (#1196)

* Encoding primary packet only if red encoding don't have enough space

* clean code
This commit is contained in:
cnderrauber
2022-11-28 13:58:01 +08:00
committed by GitHub
parent aaeb3c933c
commit 711799ecf8
2 changed files with 31 additions and 0 deletions
+10
View File
@@ -131,6 +131,16 @@ func (r *RedReceiver) encodeRedForPrimary(pkt *rtp.Packet, redPayload []byte) (i
}
func encodeRedForPrimary(redPkts []*rtp.Packet, primary *rtp.Packet, redPayload []byte) (int, error) {
payloadSize := len(primary.Payload) + 1
for _, p := range redPkts {
payloadSize += len(p.Payload) + 4
}
// if required payload size is larger than the redPayload buffer, encode the primary packet only
if payloadSize > len(redPayload) {
redPkts = redPkts[:0]
}
var index int
for _, p := range redPkts {
/* RED payload https://datatracker.ietf.org/doc/html/rfc2198#section-3