From b148165bd1ddf3e7bd9244177b75c8a3d1935917 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 16 Jul 2023 23:27:16 +0200 Subject: [PATCH] Readd non-breaking version of #119 --- packet.go | 13 +++++++------ packet_test.go | 14 -------------- packetizer_test.go | 1 - 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/packet.go b/packet.go index 2796a09..80dcc05 100644 --- a/packet.go +++ b/packet.go @@ -16,13 +16,11 @@ type Extension struct { } // Header represents an RTP packet header -// NOTE: PayloadOffset is populated by Marshal/Unmarshal and should not be modified type Header struct { Version uint8 Padding bool Extension bool Marker bool - PayloadOffset int PayloadType uint8 SequenceNumber uint16 Timestamp uint32 @@ -30,15 +28,19 @@ type Header struct { CSRC []uint32 ExtensionProfile uint16 Extensions []Extension + + // Deprecated: will be removed in a future version. + PayloadOffset int } // Packet represents an RTP Packet -// NOTE: Raw is populated by Marshal/Unmarshal and should not be modified type Packet struct { Header - Raw []byte Payload []byte PaddingSize byte + + // Deprecated: will be removed in a future version. + Raw []byte } const ( @@ -228,7 +230,6 @@ func (p *Packet) Unmarshal(buf []byte) error { } p.Payload = buf[p.PayloadOffset:end] - p.Raw = buf return nil } @@ -495,7 +496,7 @@ func (p *Packet) MarshalTo(buf []byte) (n int, err error) { } m := copy(buf[n:], p.Payload) - p.Raw = buf[:n+m] + if p.Header.Padding { buf[n+m+int(p.PaddingSize-1)] = p.PaddingSize } diff --git a/packet_test.go b/packet_test.go index 40cb1a0..ab12d21 100644 --- a/packet_test.go +++ b/packet_test.go @@ -43,7 +43,6 @@ func TestBasic(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[20:], - Raw: rawPkt, PaddingSize: 0, } @@ -104,7 +103,6 @@ func TestBasic(t *testing.T) { PayloadOffset: 20, }, Payload: rawPkt[20:21], - Raw: rawPkt, PaddingSize: 4, } if err := p.Unmarshal(rawPkt); err != nil { @@ -138,7 +136,6 @@ func TestBasic(t *testing.T) { PayloadOffset: 20, }, Payload: []byte{}, - Raw: rawPkt, PaddingSize: 5, } if err := p.Unmarshal(rawPkt); err != nil { @@ -353,7 +350,6 @@ func TestRFC8285OneByteExtension(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[20:], - Raw: rawPkt, } dstData, _ := p.Marshal() @@ -417,7 +413,6 @@ func TestRFC8285OneByteTwoExtensionOfTwoBytes(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[20:], - Raw: rawPkt, } dstData, _ := p.Marshal() @@ -542,7 +537,6 @@ func TestRFC8285OneByteMultipleExtensions(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[28:], - Raw: rawPkt, } dstData, _ := p.Marshal() @@ -586,7 +580,6 @@ func TestRFC8285TwoByteExtension(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[44:], - Raw: rawPkt, } dstData, _ := p.Marshal() @@ -689,7 +682,6 @@ func TestRFC8285TwoByteMultipleExtensionsWithLargeExtension(t *testing.T) { CSRC: []uint32{}, }, Payload: rawPkt[40:], - Raw: rawPkt, } dstData, _ := p.Marshal() @@ -1364,9 +1356,6 @@ func TestRoundtrip(t *testing.T) { if err := p.Unmarshal(rawPkt); err != nil { t.Fatal(err) } - if !bytes.Equal(rawPkt, p.Raw) { - t.Errorf("p.Raw must be same as rawPkt.\n p.Raw: %+v,\nrawPkt: %+v", p.Raw, rawPkt) - } if !bytes.Equal(payload, p.Payload) { t.Errorf("p.Payload must be same as payload.\n payload: %+v,\np.Payload: %+v", payload, p.Payload, @@ -1380,9 +1369,6 @@ func TestRoundtrip(t *testing.T) { if !bytes.Equal(rawPkt, buf) { t.Errorf("buf must be same as rawPkt.\n buf: %+v,\nrawPkt: %+v", buf, rawPkt) } - if !bytes.Equal(rawPkt, p.Raw) { - t.Errorf("p.Raw must be same as rawPkt.\n p.Raw: %+v,\nrawPkt: %+v", p.Raw, rawPkt) - } if !bytes.Equal(payload, p.Payload) { t.Errorf("p.Payload must be same as payload.\n payload: %+v,\np.Payload: %+v", payload, p.Payload, diff --git a/packetizer_test.go b/packetizer_test.go index a4ac3b8..362a555 100644 --- a/packetizer_test.go +++ b/packetizer_test.go @@ -146,7 +146,6 @@ func TestPacketizer_Roundtrip(t *testing.T) { pkt.PayloadOffset = 0 pkt.PaddingSize = 0 - pkt.Raw = nil if !reflect.DeepEqual(expectedPkt, pkt) { t.Errorf("Packets don't match, expected %v but got %v", expectedPkt, pkt)