From 0c0839d15d3e3f4c95a7bb9983d1f0f994ef8ee7 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Mon, 15 Apr 2024 17:49:03 +0200 Subject: [PATCH] Remove codecs/av1/frame/av1.go It used to depend on the now removed OBU parsing code. --- codecs/av1/frame/av1.go | 47 -------------------- codecs/av1/frame/av1_test.go | 86 ------------------------------------ pkg/frame/av1.go | 17 ------- 3 files changed, 150 deletions(-) delete mode 100644 codecs/av1/frame/av1.go delete mode 100644 codecs/av1/frame/av1_test.go delete mode 100644 pkg/frame/av1.go diff --git a/codecs/av1/frame/av1.go b/codecs/av1/frame/av1.go deleted file mode 100644 index 1e001a30..00000000 --- a/codecs/av1/frame/av1.go +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-FileCopyrightText: 2023 The Pion community -// SPDX-License-Identifier: MIT - -// Package frame provides code to construct complete media frames from packetized media. -package frame - -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. -// 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 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 *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 - if f.obuBuffer == nil { - return obuList - } - obuElement = append(f.obuBuffer, obuElement...) - f.obuBuffer = nil - } - return append(obuList, obuElement) -} - -// ReadFrames processes the codecs.AV1Packet and returns fully constructed frames -func (f *AV1) ReadFrames(pkt *codecs.AV1Packet) ([][]byte, error) { - OBUs := [][]byte{} - isFirstOBUFragment := pkt.Z - - for i := range pkt.OBUElements { - OBUs = f.pushOBUElement(&isFirstOBUFragment, pkt.OBUElements[i], OBUs) - } - - if pkt.Y && len(OBUs) > 0 { - // Take copy of OBUElement that is being cached - f.obuBuffer = append(f.obuBuffer, append([]byte{}, OBUs[len(OBUs)-1]...)...) - OBUs = OBUs[:len(OBUs)-1] - } - return OBUs, nil -} diff --git a/codecs/av1/frame/av1_test.go b/codecs/av1/frame/av1_test.go deleted file mode 100644 index aa6c73cf..00000000 --- a/codecs/av1/frame/av1_test.go +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-FileCopyrightText: 2023 The Pion community -// SPDX-License-Identifier: MIT - -package frame - -import ( - "reflect" - "testing" - - "github.com/pion/rtp/codecs" -) - -// First is Fragment (and no buffer) -// Self contained OBU -// OBU spread across 3 packets -func TestAV1_ReadFrames(t *testing.T) { - // First is Fragment of OBU, but no OBU Elements is cached - 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 = &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 = &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(&codecs.AV1Packet{Z: true, OBUElements: [][]byte{{0x01}}}) - if err != nil { - t.Fatal(err) - } else if !reflect.DeepEqual(frames, [][]byte{{0x00, 0x01}}) { - t.Fatalf("One frame should be generated, %v", frames) - } -} - -// 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{ - {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}, - {0x00, 0x01}, - {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}, - {0x00, 0x01}, - } - - frames = append(frames, []byte{}) - for i := 0; i <= 5; i++ { - frames[len(frames)-1] = append(frames[len(frames)-1], []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}...) - } - - frames = append(frames, []byte{}) - for i := 0; i <= 500; i++ { - frames[len(frames)-1] = append(frames[len(frames)-1], []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}...) - } - - payloader := &codecs.AV1Payloader{} - f := &AV1{} - for _, originalFrame := range frames { - for _, payload := range payloader.Payload(mtu, originalFrame) { - rtpPacket := &codecs.AV1Packet{} - if _, err := rtpPacket.Unmarshal(payload); err != nil { - t.Fatal(err) - } - decodedFrame, err := f.ReadFrames(rtpPacket) - if err != nil { - t.Fatal(err) - } else if len(decodedFrame) != 0 && !reflect.DeepEqual(originalFrame, decodedFrame[0]) { - t.Fatalf("Decode(%02x) and Original(%02x) are not equal", decodedFrame[0], originalFrame) - } - } - } -} diff --git a/pkg/frame/av1.go b/pkg/frame/av1.go deleted file mode 100644 index 73edea61..00000000 --- a/pkg/frame/av1.go +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2023 The Pion community -// SPDX-License-Identifier: MIT - -// Package frame is deprecated. -package frame - -import ( - "github.com/pion/rtp/codecs/av1/frame" -) - -// 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. -// 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. -// -// Deprecated: moved into codecs/av1/frame. -type AV1 = frame.AV1