Repository: pion/rtp
Pull request #175 (2022-04-11 13:52:31)

Move AV1 Frame to new frame pkg
Codecs only contains RTP Payload processing

codecov[bot]: # [Codecov](https://codecov.io/gh/pion/rtp/pull/175?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) Report
> Merging [#175](https://codecov.io/gh/pion/rtp/pull/175?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) (3f2d0f6) into [master](https://codecov.io/gh/pion/rtp/commit/62d67826f627d2b0828fb64291e889ba945158ad?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) (62d6782) will **not change** coverage.
> The diff coverage is `100.00%`.

> :exclamation: Current head 3f2d0f6 differs from pull request most recent head 13238fc. Consider uploading reports for the commit 13238fc to get more accurate results

```diff
@@           Coverage Diff           @@
##           master     #175   +/-   ##
=======================================
  Coverage   87.35%   87.35%           
=======================================
  Files          18       18           
  Lines        1772     1772           
=======================================
  Hits         1548     1548           
  Misses        195      195           
  Partials       29       29           
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `87.35% <100.00%> (ø)` | |
| wasm | `86.34% <100.00%> (-0.40%)` | :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://codecov.io/gh/pion/rtp/pull/175?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | |
|---|---|---|
| [pkg/frame/av1.go](https://codecov.io/gh/pion/rtp/pull/175/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGtnL2ZyYW1lL2F2MS5nbw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/rtp/pull/175?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/rtp/pull/175?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Last update [62d6782...13238fc](https://codecov.io/gh/pion/rtp/pull/175?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).


Patch:
diff --git a/AUTHORS.txt b/AUTHORS.txt
index e44a836..b0e3855 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -28,6 +28,7 @@ Michael Uti <utimichael9@gmail.com>
 Raphael Derosso Pereira <raphaelpereira@gmail.com>
 Rob Lofthouse <ri.lofthouse@gmail.com>
 Robin Raymond <robin@goheadroom.com>
+Sean DuBois <duboisea@twitch.tv>
 Sean DuBois <seaduboi@amazon.com>
 Sean DuBois <sean@siobud.com>
 Simone Gotti <simone.gotti@gmail.com>
diff --git a/codecs/av1_frame.go b/pkg/frame/av1.go
similarity index 62%
rename from codecs/av1_frame.go
rename to pkg/frame/av1.go
index 6f0db4c..e6017da 100644
--- a/codecs/av1_frame.go
+++ b/pkg/frame/av1.go
@@ -1,16 +1,19 @@
-package codecs
+// Package frame provides code to construct complete media frames from packetized media
+package frame
 
-// AV1Frame represents a collection of OBUs given a stream of AV1 Packets.
+import "github.com/pion/rtp/v2/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.
-// AV1Frame provides the tools to construct a collection of OBUs from a collection of OBU Elements. This structure
+// AV1 provides the tools to construct a collection of OBUs from a collection of OBU Elements. This structure
 // contains an internal cache and should be used for the entire RTP Stream.
-type AV1Frame struct {
+type AV1 struct {
 	// Buffer for fragmented OBU. If ReadFrames is called on a RTP Packet
 	// that doesn't contain a fully formed OBU
 	obuBuffer []byte
 }
 
-func (f *AV1Frame) pushOBUElement(isFirstOBUFragment *bool, obuElement []byte, obuList [][]byte) [][]byte {
+func (f *AV1) pushOBUElement(isFirstOBUFragment *bool, obuElement []byte, obuList [][]byte) [][]byte {
 	if *isFirstOBUFragment {
 		*isFirstOBUFragment = false
 		// Discard pushed because we don't have a fragment to combine it with
@@ -23,8 +26,8 @@ func (f *AV1Frame) pushOBUElement(isFirstOBUFragment *bool, obuElement []byte, o
 	return append(obuList, obuElement)
 }
 
-// ReadFrames processes the AV1Packet and returns fully constructed frames
-func (f *AV1Frame) ReadFrames(pkt *AV1Packet) ([][]byte, error) {
+// ReadFrames processes the codecs.AV1Packet and returns fully constructed frames
+func (f *AV1) ReadFrames(pkt *codecs.AV1Packet) ([][]byte, error) {
 	OBUs := [][]byte{}
 	isFirstOBUFragment := pkt.Z
 


Test patch:
diff --git a/codecs/av1_frame_test.go b/pkg/frame/av1_test.go
similarity index 76%
rename from codecs/av1_frame_test.go
rename to pkg/frame/av1_test.go
index 544ba7d..11538cf 100644
--- a/codecs/av1_frame_test.go
+++ b/pkg/frame/av1_test.go
@@ -1,8 +1,10 @@
-package codecs
+package frame
 
 import (
 	"reflect"
 	"testing"
+
+	"github.com/pion/rtp/v2/codecs"
 )
 
 // First is Fragment (and no buffer)
@@ -10,31 +12,31 @@ import (
 // OBU spread across 3 packets
 func TestAV1_ReadFrames(t *testing.T) {
 	// First is Fragment of OBU, but no OBU Elements is cached
-	f := &AV1Frame{}
-	frames, err := f.ReadFrames(&AV1Packet{Z: true, OBUElements: [][]byte{{0x01}}})
+	f := &AV1{}
+	frames, err := f.ReadFrames(&codecs.AV1Packet{Z: true, OBUElements: [][]byte{{0x01}}})
 	if err != nil {
 		t.Fatal(err)
 	} else if !reflect.DeepEqual(frames, [][]byte{}) {
 		t.Fatalf("No frames should be generated, %v", frames)
 	}
 
-	f = &AV1Frame{}
-	frames, err = f.ReadFrames(&AV1Packet{OBUElements: [][]byte{{0x01}}})
+	f = &AV1{}
+	frames, err = f.ReadFrames(&codecs.AV1Packet{OBUElements: [][]byte{{0x01}}})
 	if err != nil {
 		t.Fatal(err)
 	} else if !reflect.DeepEqual(frames, [][]byte{{0x01}}) {
 		t.Fatalf("One frame should be generated, %v", frames)
 	}
 
-	f = &AV1Frame{}
-	frames, err = f.ReadFrames(&AV1Packet{Y: true, OBUElements: [][]byte{{0x00}}})
+	f = &AV1{}
+	frames, err = f.ReadFrames(&codecs.AV1Packet{Y: true, OBUElements: [][]byte{{0x00}}})
 	if err != nil {
 		t.Fatal(err)
 	} else if !reflect.DeepEqual(frames, [][]byte{}) {
 		t.Fatalf("No frames should be generated, %v", frames)
 	}
 
-	frames, err = f.ReadFrames(&AV1Packet{Z: true, OBUElements: [][]byte{{0x01}}})
+	frames, err = f.ReadFrames(&codecs.AV1Packet{Z: true, OBUElements: [][]byte{{0x01}}})
 	if err != nil {
 		t.Fatal(err)
 	} else if !reflect.DeepEqual(frames, [][]byte{{0x00, 0x01}}) {
@@ -42,7 +44,7 @@ func TestAV1_ReadFrames(t *testing.T) {
 	}
 }
 
-// Marshal some AV1 Frames to RTP, assert that AV1Frame can get them back in the original format
+// Marshal some AV1 Frames to RTP, assert that AV1 can get them back in the original format
 func TestAV1_ReadFrames_E2E(t *testing.T) {
 	const mtu = 1500
 	frames := [][]byte{
@@ -62,11 +64,11 @@ func TestAV1_ReadFrames_E2E(t *testing.T) {
 		frames[len(frames)-1] = append(frames[len(frames)-1], []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}...)
 	}
 
-	payloader := &AV1Payloader{}
-	f := &AV1Frame{}
+	payloader := &codecs.AV1Payloader{}
+	f := &AV1{}
 	for _, originalFrame := range frames {
 		for _, payload := range payloader.Payload(mtu, originalFrame) {
-			rtpPacket := &AV1Packet{}
+			rtpPacket := &codecs.AV1Packet{}
 			if _, err := rtpPacket.Unmarshal(payload); err != nil {
 				t.Fatal(err)
 			}