You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my SFU, packets go through a number of data structures, and finally end up in a static buffer that is passed to Track.WriteRTP. This works fine with ordinary tracks, but fails when trying to write data to disk: SampleBuilder.Push requires the packet to never be overwritten. This does not appear to be documented. (My personal opinion is that Push should clone the packet, but as a second choice I'd be okay if the requirement that the Packet and its underlying buffer never be reusied were clearly documented.)
What is more, there is no easy way to clone a packet. I'm currently using the following code:
func clonePacket(packet *rtp.Packet) *rtp.Packet {
buf, err := packet.Marshal()
if err != nil {
return nil
}
var p rtp.Packet
err = p.Unmarshal(buf)
if err != nil {
return nil
}
return &p
}
My suggestions are therefore:
document that SampleBuilder.Push requires its parameter to never be modified;
provide a function Packet.Clone() that clones a packet efficiently;
in v3, avoid the complication by having SampleBuilder.Push copy the packet internally.
I am all for Clone! I don't think it would be that hard to add either.
SampleBuilder.Push copying might be unpopular. Users who are implementing clients will have to do an extra copy. If we don't force a clone we support both uses cases.
We should for sure add a comment to SampleBuilder.Push I will do that now and tag this commit.
Activity
[-]No easy way to clone a packet[/-][+]Add Clone to rtp.Packet[/+]Sean-Der commentedon Sep 16, 2020
Hey @jech
I am all for
Clone! I don't think it would be that hard to add either.SampleBuilder.Pushcopying might be unpopular. Users who are implementing clients will have to do an extra copy. If we don't force a clone we support both uses cases.We should for sure add a comment to
SampleBuilder.PushI will do that now and tag this commit.Add note around memory ownership for SampleBuilder
Implement packet Clone method
Implement packet Clone method\n
Implement packet Clone method\n
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Implement packet clone method
Add note around memory ownership for SampleBuilder