Skip to content

Commit

Permalink
Implement AppendToSample for AV1Packet
Browse files Browse the repository at this point in the history
AV1 RTP payload cannot be concatenated without first recovering
the omitted OBU length.
  • Loading branch information
jech committed Apr 15, 2024
1 parent cf7c330 commit 89c2b75
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions codecs/av1_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,42 @@ func (p *AV1Packet) IsPartitionHead(payload []byte) bool {
// 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
}

0 comments on commit 89c2b75

Please sign in to comment.