Skip to content

Commit

Permalink
Readd non-breaking version of #119
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 16, 2023
1 parent 5d59489 commit b148165
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
13 changes: 7 additions & 6 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ 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
SSRC uint32
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 (
Expand Down Expand Up @@ -228,7 +230,6 @@ func (p *Packet) Unmarshal(buf []byte) error {
}

p.Payload = buf[p.PayloadOffset:end]
p.Raw = buf

return nil
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 0 additions & 14 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestBasic(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[20:],
Raw: rawPkt,
PaddingSize: 0,
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -138,7 +136,6 @@ func TestBasic(t *testing.T) {
PayloadOffset: 20,
},
Payload: []byte{},
Raw: rawPkt,
PaddingSize: 5,
}
if err := p.Unmarshal(rawPkt); err != nil {
Expand Down Expand Up @@ -353,7 +350,6 @@ func TestRFC8285OneByteExtension(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[20:],
Raw: rawPkt,
}

dstData, _ := p.Marshal()
Expand Down Expand Up @@ -417,7 +413,6 @@ func TestRFC8285OneByteTwoExtensionOfTwoBytes(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[20:],
Raw: rawPkt,
}

dstData, _ := p.Marshal()
Expand Down Expand Up @@ -542,7 +537,6 @@ func TestRFC8285OneByteMultipleExtensions(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[28:],
Raw: rawPkt,
}

dstData, _ := p.Marshal()
Expand Down Expand Up @@ -586,7 +580,6 @@ func TestRFC8285TwoByteExtension(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[44:],
Raw: rawPkt,
}

dstData, _ := p.Marshal()
Expand Down Expand Up @@ -689,7 +682,6 @@ func TestRFC8285TwoByteMultipleExtensionsWithLargeExtension(t *testing.T) {
CSRC: []uint32{},
},
Payload: rawPkt[40:],
Raw: rawPkt,
}

dstData, _ := p.Marshal()
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packetizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b148165

Please sign in to comment.