Skip to content

Add Clone to rtp.Packet #88

Closed
Closed

Description

@jech

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.

Activity

  1. transferred this issue frompion/webrtcon Sep 16, 2020
  2. changed the title [-]No easy way to clone a packet[/-] [+]Add Clone to rtp.Packet[/+] on Sep 16, 2020
  3. Sean-Der commented on Sep 16, 2020

    @Sean-Der
    Member

    Hey @jech

    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.

  4. added 4 commits that reference this issue on Feb 3, 2021
    133684c
    087a4ea
    35b3607
    1774656
  5. added a commit that references this issue on May 16, 2021
    3d32f84
  6. added 2 commits that reference this issue on Aug 5, 2021
    7fd88cb
    89ef314
  7. added 2 commits that reference this issue on Aug 5, 2021
    b670290
    0f062a1
  8. added 8 commits that reference this issue on Jun 12, 2023
    8a1694f
    0be2eaa
    209c811
    574b1c8
    8b8bcd7
    ff7a88c
    3957fd9
    e020e24
  9. added a commit that references this issue on Jun 14, 2023
    e655591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址