Repository: pion/rtp
Pull request #227 (2023-06-12 21:10:17)

Rollback to v1
#### Description

As discussed in #221, this reverts the library to /v1 by including only backward-compatible changes, in order to restore the release cycle of this library, that has been stuck for over a year.

In particular, i did the following:

1. the library was reverted to the last commit before bumping to v2 (4e87540)
2. all non-breaking commits from the v1 branch were cherry-picked
3. all non-breaking commits from the master branch were cherry-picked
4. the following breaking commits from master were edited and merged:
    * #150 - this removed some structs, that have been re-added and marked as deprecated
5. the following breaking commits were left out and will be readded with a PR in a non-breaking form:
   * #119
   * #160



codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) Report
Patch coverage: **`68.96`**% and project coverage change: **`-0.29`** :warning:
> Comparison is base [(`c5ca73a`)](https://app.codecov.io/gh/pion/rtp/commit/c5ca73a6fa1244ceb419fc021a39f41e6c44c47b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) 87.81% compared to head [(`574b1c8`)](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) 87.53%.

> :exclamation: Current head 574b1c8 differs from pull request most recent head ff7a88c. Consider uploading reports for the commit ff7a88c to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
- Coverage   87.81%   87.53%   -0.29%     
==========================================
  Files          20       20              
  Lines        1863     1877      +14     
==========================================
+ Hits         1636     1643       +7     
- Misses        197      204       +7     
  Partials       30       30              
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `87.53% <68.96%> (-0.29%)` | :arrow_down: |
| wasm | `86.57% <68.96%> (-0.28%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | |
|---|---|---|
| [codecs/av1\_packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y29kZWNzL2F2MV9wYWNrZXQuZ28=) | `100.00% <ø> (ø)` | |
| [codecs/h264\_packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y29kZWNzL2gyNjRfcGFja2V0Lmdv) | `97.89% <0.00%> (-1.05%)` | :arrow_down: |
| [codecs/opus\_packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y29kZWNzL29wdXNfcGFja2V0Lmdv) | `88.23% <0.00%> (-11.77%)` | :arrow_down: |
| [codecs/vp8\_packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y29kZWNzL3ZwOF9wYWNrZXQuZ28=) | `89.93% <0.00%> (-1.15%)` | :arrow_down: |
| [codecs/vp9\_packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y29kZWNzL3ZwOV9wYWNrZXQuZ28=) | `94.87% <0.00%> (-0.82%)` | :arrow_down: |
| [pkg/frame/av1.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGtnL2ZyYW1lL2F2MS5nbw==) | `100.00% <ø> (ø)` | |
| [packet.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGFja2V0Lmdv) | `88.40% <94.73%> (+0.46%)` | :arrow_up: |
| [packetizer.go](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGFja2V0aXplci5nbw==) | `79.24% <100.00%> (+0.39%)` | :arrow_up: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pion/rtp/pull/227?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).

Sean-Der: Fantastic! Thank you @aler9 

Patch:
diff --git a/codecs/av1_packet.go b/codecs/av1_packet.go
index b074ab5..01aa89b 100644
--- a/codecs/av1_packet.go
+++ b/codecs/av1_packet.go
@@ -4,7 +4,7 @@
 package codecs
 
 import (
-	"github.com/pion/rtp/v2/pkg/obu"
+	"github.com/pion/rtp/pkg/obu"
 )
 
 const (
diff --git a/codecs/h264_packet.go b/codecs/h264_packet.go
index 5dc3a2e..17ca1bb 100644
--- a/codecs/h264_packet.go
+++ b/codecs/h264_packet.go
@@ -268,9 +268,18 @@ func (p *H264Packet) Unmarshal(payload []byte) ([]byte, error) {
 	return nil, fmt.Errorf("%w: %d", errUnhandledNALUType, naluType)
 }
 
-// H264PartitionHeadChecker is obsolete
+// H264PartitionHeadChecker checks H264 partition head.
+//
+// Deprecated: replaced by H264Packet.IsPartitionHead()
 type H264PartitionHeadChecker struct{}
 
+// IsPartitionHead checks if this is the head of a packetized nalu stream.
+//
+// Deprecated: replaced by H264Packet.IsPartitionHead()
+func (*H264PartitionHeadChecker) IsPartitionHead(packet []byte) bool {
+	return (&H264Packet{}).IsPartitionHead(packet)
+}
+
 // IsPartitionHead checks if this is the head of a packetized nalu stream.
 func (*H264Packet) IsPartitionHead(payload []byte) bool {
 	if len(payload) < 2 {
diff --git a/codecs/opus_packet.go b/codecs/opus_packet.go
index d8d441e..00ee903 100644
--- a/codecs/opus_packet.go
+++ b/codecs/opus_packet.go
@@ -36,5 +36,14 @@ func (p *OpusPacket) Unmarshal(packet []byte) ([]byte, error) {
 	return packet, nil
 }
 
-// OpusPartitionHeadChecker is obsolete
+// OpusPartitionHeadChecker checks Opus partition head.
+//
+// Deprecated: replaced by OpusPacket.IsPartitionHead()
 type OpusPartitionHeadChecker struct{}
+
+// IsPartitionHead checks whether if this is a head of the Opus partition.
+//
+// Deprecated: replaced by OpusPacket.IsPartitionHead()
+func (*OpusPartitionHeadChecker) IsPartitionHead(packet []byte) bool {
+	return (&OpusPacket{}).IsPartitionHead(packet)
+}
diff --git a/codecs/vp8_packet.go b/codecs/vp8_packet.go
index e2d1e24..5d0a654 100644
--- a/codecs/vp8_packet.go
+++ b/codecs/vp8_packet.go
@@ -210,9 +210,18 @@ func (p *VP8Packet) Unmarshal(payload []byte) ([]byte, error) {
 	return p.Payload, nil
 }
 
-// VP8PartitionHeadChecker is obsolete
+// VP8PartitionHeadChecker checks VP8 partition head
+//
+// Deprecated: replaced by VP8Packet.IsPartitionHead()
 type VP8PartitionHeadChecker struct{}
 
+// IsPartitionHead checks whether if this is a head of the VP8 partition.
+//
+// Deprecated: replaced by VP8Packet.IsPartitionHead()
+func (*VP8PartitionHeadChecker) IsPartitionHead(packet []byte) bool {
+	return (&VP8Packet{}).IsPartitionHead(packet)
+}
+
 // IsPartitionHead checks whether if this is a head of the VP8 partition
 func (*VP8Packet) IsPartitionHead(payload []byte) bool {
 	if len(payload) < 1 {
diff --git a/codecs/vp9_packet.go b/codecs/vp9_packet.go
index 093cde5..6a6e0b0 100644
--- a/codecs/vp9_packet.go
+++ b/codecs/vp9_packet.go
@@ -396,9 +396,18 @@ func (p *VP9Packet) parseSSData(packet []byte, pos int) (int, error) {
 	return pos, nil
 }
 
-// VP9PartitionHeadChecker is obsolete
+// VP9PartitionHeadChecker checks VP9 partition head.
+//
+// Deprecated: replaced by VP9Packet.IsPartitionHead()
 type VP9PartitionHeadChecker struct{}
 
+// IsPartitionHead checks whether if this is a head of the VP9 partition.
+//
+// Deprecated: replaced by VP9Packet.IsPartitionHead()
+func (*VP9PartitionHeadChecker) IsPartitionHead(packet []byte) bool {
+	return (&VP9Packet{}).IsPartitionHead(packet)
+}
+
 // IsPartitionHead checks whether if this is a head of the VP9 partition
 func (*VP9Packet) IsPartitionHead(payload []byte) bool {
 	if len(payload) < 1 {
diff --git a/go.mod b/go.mod
index 19a0cc0..753a4d7 100644
--- a/go.mod
+++ b/go.mod
@@ -1,5 +1,5 @@
-module github.com/pion/rtp/v2
+module github.com/pion/rtp
 
-go 1.13
+go 1.19
 
 require github.com/pion/randutil v0.1.0
diff --git a/packet.go b/packet.go
index ef4e5d8..2796a09 100644
--- a/packet.go
+++ b/packet.go
@@ -16,11 +16,13 @@ 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
@@ -31,8 +33,10 @@ type Header struct {
 }
 
 // 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
 }
@@ -78,10 +82,9 @@ func (p Packet) String() string {
 }
 
 // Unmarshal parses the passed byte slice and stores the result in the Header.
-// It returns the number of bytes read n and any error.
-func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
+func (h *Header) Unmarshal(buf []byte) error { //nolint:gocognit
 	if len(buf) < headerLength {
-		return 0, fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficient, len(buf), headerLength)
+		return fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficient, len(buf), headerLength)
 	}
 
 	/*
@@ -109,10 +112,9 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
 		h.CSRC = h.CSRC[:nCSRC]
 	}
 
-	n = csrcOffset + (nCSRC * csrcLength)
+	n := csrcOffset + (nCSRC * csrcLength)
 	if len(buf) < n {
-		return n, fmt.Errorf("size %d < %d: %w", len(buf), n,
-			errHeaderSizeInsufficient)
+		return fmt.Errorf("size %d < %d: %w", len(buf), n, errHeaderSizeInsufficient)
 	}
 
 	h.Marker = (buf[1] >> markerShift & markerMask) > 0
@@ -133,7 +135,7 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
 
 	if h.Extension {
 		if expected := n + 4; len(buf) < expected {
-			return n, fmt.Errorf("size %d < %d: %w",
+			return fmt.Errorf("size %d < %d: %w",
 				len(buf), expected,
 				errHeaderSizeInsufficientForExtension,
 			)
@@ -145,7 +147,7 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
 		n += 2
 
 		if expected := n + extensionLength; len(buf) < expected {
-			return n, fmt.Errorf("size %d < %d: %w",
+			return fmt.Errorf("size %d < %d: %w",
 				len(buf), expected,
 				errHeaderSizeInsufficientForExtension,
 			)
@@ -196,8 +198,7 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
 
 		default: // RFC3550 Extension
 			if len(buf) < n+extensionLength {
-				return n, fmt.Errorf("%w: %d < %d",
-					errHeaderSizeInsufficientForExtension, len(buf), n+extensionLength)
+				return fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficientForExtension, len(buf), n+extensionLength)
 			}
 
 			extension := Extension{id: 0, payload: buf[n : n+extensionLength]}
@@ -205,24 +206,30 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
 			n += len(h.Extensions[0].payload)
 		}
 	}
-	return n, nil
+
+	h.PayloadOffset = n
+
+	return nil
 }
 
 // Unmarshal parses the passed byte slice and stores the result in the Packet.
 func (p *Packet) Unmarshal(buf []byte) error {
-	n, err := p.Header.Unmarshal(buf)
-	if err != nil {
+	if err := p.Header.Unmarshal(buf); err != nil {
 		return err
 	}
+
 	end := len(buf)
 	if p.Header.Padding {
 		p.PaddingSize = buf[end-1]
 		end -= int(p.PaddingSize)
 	}
-	if end < n {
+	if end < p.PayloadOffset {
 		return errTooSmall
 	}
-	p.Payload = buf[n:end]
+
+	p.Payload = buf[p.PayloadOffset:end]
+	p.Raw = buf
+
 	return nil
 }
 
@@ -234,6 +241,7 @@ func (h Header) Marshal() (buf []byte, err error) {
 	if err != nil {
 		return nil, err
 	}
+
 	return buf[:n], nil
 }
 
@@ -331,6 +339,8 @@ func (h Header) MarshalTo(buf []byte) (n int, err error) {
 		}
 	}
 
+	h.PayloadOffset = n
+
 	return n, nil
 }
 
@@ -472,7 +482,8 @@ func (p Packet) Marshal() (buf []byte, err error) {
 }
 
 // MarshalTo serializes the packet and writes to the buffer.
-func (p Packet) MarshalTo(buf []byte) (n int, err error) {
+func (p *Packet) MarshalTo(buf []byte) (n int, err error) {
+	p.Header.Padding = p.PaddingSize != 0
 	n, err = p.Header.MarshalTo(buf)
 	if err != nil {
 		return 0, err
@@ -484,6 +495,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/packetizer.go b/packetizer.go
index c9e3a93..c412732 100644
--- a/packetizer.go
+++ b/packetizer.go
@@ -26,6 +26,7 @@ type packetizer struct {
 	Payloader        Payloader
 	Sequencer        Sequencer
 	Timestamp        uint32
+	ClockRate        uint32
 	extensionNumbers struct { // put extension numbers in here. If they're 0, the extension is disabled (0 is not a legal extension number)
 		AbsSendTime int // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
 	}
@@ -33,7 +34,7 @@ type packetizer struct {
 }
 
 // NewPacketizer returns a new instance of a Packetizer for a specific payloader
-func NewPacketizer(mtu uint16, pt uint8, ssrc uint32, payloader Payloader, sequencer Sequencer) Packetizer {
+func NewPacketizer(mtu uint16, pt uint8, ssrc uint32, payloader Payloader, sequencer Sequencer, clockRate uint32) Packetizer {
 	return &packetizer{
 		MTU:         mtu,
 		PayloadType: pt,
@@ -41,6 +42,7 @@ func NewPacketizer(mtu uint16, pt uint8, ssrc uint32, payloader Payloader, seque
 		Payloader:   payloader,
 		Sequencer:   sequencer,
 		Timestamp:   globalMathRandomGenerator.Uint32(),
+		ClockRate:   clockRate,
 		timegen:     time.Now,
 	}
 }
diff --git a/pkg/frame/av1.go b/pkg/frame/av1.go
index 1a13a5a..0dadde6 100644
--- a/pkg/frame/av1.go
+++ b/pkg/frame/av1.go
@@ -4,7 +4,7 @@
 // Package frame provides code to construct complete media frames from packetized media
 package frame
 
-import "github.com/pion/rtp/v2/codecs"
+import "github.com/pion/rtp/codecs"
 
 // AV1 represents a collection of OBUs given a stream of AV1 Packets.
 // Each AV1 RTP Packet is a collection of OBU Elements. Each OBU Element may be a full OBU, or just a fragment of one.


Test patch:
diff --git a/codecs/av1_packet_test.go b/codecs/av1_packet_test.go
index 3761c3a..746353f 100644
--- a/codecs/av1_packet_test.go
+++ b/codecs/av1_packet_test.go
@@ -8,7 +8,7 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/pion/rtp/v2/pkg/obu"
+	"github.com/pion/rtp/pkg/obu"
 )
 
 func TestAV1_Marshal(t *testing.T) {
diff --git a/packet_test.go b/packet_test.go
index 3044c0d..40cb1a0 100644
--- a/packet_test.go
+++ b/packet_test.go
@@ -35,6 +35,7 @@ func TestBasic(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  20,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -42,6 +43,7 @@ func TestBasic(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload:     rawPkt[20:],
+		Raw:         rawPkt,
 		PaddingSize: 0,
 	}
 
@@ -60,12 +62,20 @@ func TestBasic(t *testing.T) {
 				t.Errorf("wrong computed marshal size")
 			}
 
+			if p.PayloadOffset != 20 {
+				t.Errorf("wrong payload offset: %d != %d", p.PayloadOffset, 20)
+			}
+
 			raw, err := p.Marshal()
 			if err != nil {
 				t.Error(err)
 			} else if !reflect.DeepEqual(raw, rawPkt) {
 				t.Errorf("TestBasic marshal: got %#v, want %#v", raw, rawPkt)
 			}
+
+			if p.PayloadOffset != 20 {
+				t.Errorf("wrong payload offset: %d != %d", p.PayloadOffset, 20)
+			}
 		})
 	}
 
@@ -91,8 +101,10 @@ func TestBasic(t *testing.T) {
 			Timestamp:      3653407706,
 			SSRC:           476325762,
 			CSRC:           []uint32{},
+			PayloadOffset:  20,
 		},
 		Payload:     rawPkt[20:21],
+		Raw:         rawPkt,
 		PaddingSize: 4,
 	}
 	if err := p.Unmarshal(rawPkt); err != nil {
@@ -123,8 +135,10 @@ func TestBasic(t *testing.T) {
 			Timestamp:      3653407706,
 			SSRC:           476325762,
 			CSRC:           []uint32{},
+			PayloadOffset:  20,
 		},
 		Payload:     []byte{},
+		Raw:         rawPkt,
 		PaddingSize: 5,
 	}
 	if err := p.Unmarshal(rawPkt); err != nil {
@@ -254,7 +268,6 @@ func TestBasic(t *testing.T) {
 				}},
 			},
 			Version:        2,
-			Padding:        true,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -332,6 +345,7 @@ func TestRFC8285OneByteExtension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  18,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -339,6 +353,7 @@ func TestRFC8285OneByteExtension(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload: rawPkt[20:],
+		Raw:     rawPkt,
 	}
 
 	dstData, _ := p.Marshal()
@@ -394,6 +409,7 @@ func TestRFC8285OneByteTwoExtensionOfTwoBytes(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -401,6 +417,7 @@ func TestRFC8285OneByteTwoExtensionOfTwoBytes(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload: rawPkt[20:],
+		Raw:     rawPkt,
 	}
 
 	dstData, _ := p.Marshal()
@@ -517,6 +534,7 @@ func TestRFC8285OneByteMultipleExtensions(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -524,6 +542,7 @@ func TestRFC8285OneByteMultipleExtensions(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload: rawPkt[28:],
+		Raw:     rawPkt,
 	}
 
 	dstData, _ := p.Marshal()
@@ -559,6 +578,7 @@ func TestRFC8285TwoByteExtension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  42,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -566,6 +586,7 @@ func TestRFC8285TwoByteExtension(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload: rawPkt[44:],
+		Raw:     rawPkt,
 	}
 
 	dstData, _ := p.Marshal()
@@ -660,6 +681,7 @@ func TestRFC8285TwoByteMultipleExtensionsWithLargeExtension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  40,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -667,6 +689,7 @@ func TestRFC8285TwoByteMultipleExtensionsWithLargeExtension(t *testing.T) {
 			CSRC:           []uint32{},
 		},
 		Payload: rawPkt[40:],
+		Raw:     rawPkt,
 	}
 
 	dstData, _ := p.Marshal()
@@ -685,6 +708,7 @@ func TestRFC8285GetExtensionReturnsNilWhenExtensionsDisabled(t *testing.T) {
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -716,6 +740,7 @@ func TestRFC8285DelExtension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -765,6 +790,7 @@ func TestRFC8285GetExtensionIDs(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -800,6 +826,7 @@ func TestRFC8285GetExtensionIDsReturnsErrorWhenExtensionsDisabled(t *testing.T)
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -825,6 +852,7 @@ func TestRFC8285DelExtensionReturnsErrorWhenExtensionsDisabled(t *testing.T) {
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -850,6 +878,7 @@ func TestRFC8285OneByteSetExtensionShouldEnableExensionsWhenAdding(t *testing.T)
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -892,6 +921,7 @@ func TestRFC8285OneByteSetExtensionShouldSetCorrectExtensionProfileFor16ByteExte
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -933,6 +963,7 @@ func TestRFC8285OneByteSetExtensionShouldUpdateExistingExension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -973,6 +1004,7 @@ func TestRFC8285OneByteSetExtensionShouldErrorWhenInvalidIDProvided(t *testing.T
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1030,6 +1062,7 @@ func TestRFC8285OneByteSetExtensionShouldErrorWhenPayloadTooLarge(t *testing.T)
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1057,6 +1090,7 @@ func TestRFC8285TwoByteSetExtensionShouldEnableExensionsWhenAdding(t *testing.T)
 			Marker:         true,
 			Extension:      false,
 			Version:        2,
+			PayloadOffset:  31,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1108,6 +1142,7 @@ func TestRFC8285TwoByteSetExtensionShouldUpdateExistingExension(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1151,6 +1186,7 @@ func TestRFC8285TwoByteSetExtensionShouldErrorWhenPayloadTooLarge(t *testing.T)
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1208,6 +1244,7 @@ func TestRFC3550SetExtensionShouldErrorWhenNonZero(t *testing.T) {
 				}},
 			},
 			Version:        2,
+			PayloadOffset:  26,
 			PayloadType:    96,
 			SequenceNumber: 27023,
 			Timestamp:      3653407706,
@@ -1239,6 +1276,7 @@ func TestRFC3550SetExtensionShouldRaiseErrorWhenSettingNonzeroID(t *testing.T) {
 			Extension:        true,
 			ExtensionProfile: 0x1111,
 			Version:          2,
+			PayloadOffset:    26,
 			PayloadType:      96,
 			SequenceNumber:   27023,
 			Timestamp:        3653407706,
@@ -1307,7 +1345,7 @@ func TestUnmarshal_ErrorHandling(t *testing.T) {
 		testCase := testCase
 		t.Run(name, func(t *testing.T) {
 			h := &Header{}
-			_, err := h.Unmarshal(testCase.input)
+			err := h.Unmarshal(testCase.input)
 			if !errors.Is(err, testCase.err) {
 				t.Errorf("Expected error: %v, got: %v", testCase.err, err)
 			}
@@ -1326,6 +1364,9 @@ 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,
@@ -1339,6 +1380,9 @@ 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 c7e91c4..a4ac3b8 100644
--- a/packetizer_test.go
+++ b/packetizer_test.go
@@ -9,13 +9,13 @@ import (
 	"testing"
 	"time"
 
-	"github.com/pion/rtp/v2/codecs"
+	"github.com/pion/rtp/codecs"
 )
 
 func TestPacketizer(t *testing.T) {
 	multiplepayload := make([]byte, 128)
 	// use the G722 payloader here, because it's very simple and all 0s is valid G722 data.
-	packetizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewRandomSequencer())
+	packetizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewRandomSequencer(), 90000)
 	packets := packetizer.Packetize(multiplepayload, 2000)
 
 	if len(packets) != 2 {
@@ -29,7 +29,7 @@ func TestPacketizer(t *testing.T) {
 
 func TestPacketizer_AbsSendTime(t *testing.T) {
 	// use the G722 payloader here, because it's very simple and all 0s is valid G722 data.
-	pktizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewFixedSequencer(1234))
+	pktizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewFixedSequencer(1234), 90000)
 	p, ok := pktizer.(*packetizer)
 	if !ok {
 		t.Fatal("Failed to access packetizer")
@@ -51,6 +51,7 @@ func TestPacketizer_AbsSendTime(t *testing.T) {
 			Padding:          false,
 			Extension:        true,
 			Marker:           true,
+			PayloadOffset:    0, // not set by Packetize() at now
 			PayloadType:      98,
 			SequenceNumber:   1234,
 			Timestamp:        45678,
@@ -77,7 +78,7 @@ func TestPacketizer_AbsSendTime(t *testing.T) {
 
 func TestPacketizer_Roundtrip(t *testing.T) {
 	multiplepayload := make([]byte, 128)
-	packetizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewRandomSequencer())
+	packetizer := NewPacketizer(100, 98, 0x1234ABCD, &codecs.G722Payloader{}, NewRandomSequencer(), 90000)
 	packets := packetizer.Packetize(multiplepayload, 1000)
 
 	rawPkts := make([][]byte, 0, 1400)
@@ -143,6 +144,10 @@ func TestPacketizer_Roundtrip(t *testing.T) {
 			t.Errorf("Packet versions don't match, expected %v but got %v", expectedPkt.Payload, pkt.Payload)
 		}
 
+		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)
 		}
diff --git a/pkg/frame/av1_test.go b/pkg/frame/av1_test.go
index 3f9d9da..aa6c73c 100644
--- a/pkg/frame/av1_test.go
+++ b/pkg/frame/av1_test.go
@@ -7,7 +7,7 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/pion/rtp/v2/codecs"
+	"github.com/pion/rtp/codecs"
 )
 
 // First is Fragment (and no buffer)