Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AV1 samplebuilder support (WIP) #264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions codecs/av1_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
// 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
OBUElements [][]byte

videoDepacketizer
}

// Unmarshal parses the passed byte slice and stores the result in the AV1Packet this method is called upon
Expand Down Expand Up @@ -186,3 +188,48 @@

return payload[1:], nil
}

func (p *AV1Packet) IsPartitionHead(payload []byte) bool {

Check warning on line 192 in codecs/av1_packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method AV1Packet.IsPartitionHead should have comment or be unexported (revive)

Check warning on line 192 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L192

Added line #L192 was not covered by tests
// at this point, p.Unmarshal may not have been called yet. Check
// manually for Z == 0 & N == 1.
return len(payload) > 0 && (payload[0] & 0x88) != 0x08

Check failure on line 195 in codecs/av1_packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

File is not `gofmt`-ed with `-s` (gofmt)

Check warning on line 195 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L195

Added line #L195 was not covered by tests
}

// AppendToSample appends the contents of the packet to a sample. It
// reconstructs the size of the last OBU if required.
func (p *AV1Packet) AppendToSample(sample, payload []byte) []byte {
if len(payload) < 1 {
return sample

Check warning on line 202 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L200-L202

Added lines #L200 - L202 were not covered by tests
}

switch p.W {
case 0:
sample = append(sample, payload...)
case 1:
sample = append(sample, obu.WriteToLeb128(uint(len(payload)))...)
sample = append(sample, payload...)
case 2:
l1, ll1, err := obu.ReadLeb128(payload)
if err != nil {
return sample

Check warning on line 214 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L205-L214

Added lines #L205 - L214 were not covered by tests
}
sample = append(sample, payload[:l1+ll1]...)
l2 := uint(len(payload)) - (l1 + ll1)
sample = append(sample, obu.WriteToLeb128(l2)...)
sample = append(sample, payload[l1+ll1:]...)
case 3:
l1, ll1, err := obu.ReadLeb128(payload)
if err != nil {
return sample

Check warning on line 223 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L216-L223

Added lines #L216 - L223 were not covered by tests
}
l2, ll2, err := obu.ReadLeb128(payload[l1+ll1:])
if err != nil {
return sample

Check warning on line 227 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L225-L227

Added lines #L225 - L227 were not covered by tests
}
l3 := uint(len(payload)) - (l1 + ll1 + l2 + ll2)
sample = append(sample, payload[:l1+ll1+l2+ll2]...)
sample = append(sample, obu.WriteToLeb128(l3)...)
sample = append(sample, payload[l1+ll1+l2+ll2:]...)

Check warning on line 232 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L229-L232

Added lines #L229 - L232 were not covered by tests
}
return sample

Check warning on line 234 in codecs/av1_packet.go

View check run for this annotation

Codecov / codecov/patch

codecs/av1_packet.go#L234

Added line #L234 was not covered by tests
}