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 eced0cb commit 3ee215c
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 @@ -192,3 +192,42 @@ func (p *AV1Packet) Unmarshal(payload []byte) ([]byte, error) {
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)
return !p.Z && p.N
}

// 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
}

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
}
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
}
l2, ll2, err := obu.ReadLeb128(payload[l1+ll1:])
if err != nil {
return sample
}
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:]...)
}
return sample
}

0 comments on commit 3ee215c

Please sign in to comment.