Skip to content

Commit

Permalink
fix VP9 decoding on iOS (bluenviron/mediamtx#3060)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Apr 27, 2024
1 parent 0c99fd6 commit 30dd8d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ require (
golang.org/x/sys v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/pion/rtp => github.com/aler9/rtp v0.0.0-20240427184751-2502db909c7a
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/aler9/rtp v0.0.0-20240427184751-2502db909c7a h1:e78syd2gamX/4n7nT2tc1LpZjIZXTLYkZLO9cFePgKc=
github.com/aler9/rtp v0.0.0-20240427184751-2502db909c7a/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflxkRsZA=
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
Expand All @@ -13,8 +15,6 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE=
github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4=
github.com/pion/rtp v1.8.5 h1:uYzINfaK+9yWs7r537z/Rc1SvT8ILjBcmDOpJcTB+OU=
github.com/pion/rtp v1.8.5/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY=
github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
Expand Down
30 changes: 23 additions & 7 deletions pkg/format/rtpvp9/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var cases = []struct {
}{
{
"single",
[]byte{0x01, 0x02, 0x03, 0x04},
[]byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34},
[]*rtp.Packet{
{
Header: rtp.Header{
Expand All @@ -49,13 +49,20 @@ var cases = []struct {
SequenceNumber: 17645,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x9c, 0xb5, 0xaf, 0x01, 0x02, 0x03, 0x04},
Payload: []byte{
0x8f, 0xb5, 0xaf, 0x18, 0x07, 0x80, 0x03, 0x24,
0x01, 0x14, 0x01, 0x82, 0x49, 0x83, 0x42, 0x00,
0x77, 0xf0, 0x32, 0x34,
},
},
},
},
{
"fragmented",
bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04}, 4096/4),
mergeBytes(
[]byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34},
bytes.Repeat([]byte{1, 2, 3, 4}, 4096/4),
),
[]*rtp.Packet{
{
Header: rtp.Header{
Expand All @@ -65,7 +72,13 @@ var cases = []struct {
SequenceNumber: 17645,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes([]byte{0x98, 0xb5, 0xaf}, bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04}, 364), []byte{0x01}),
Payload: mergeBytes(
[]byte{
0x8b, 0xb5, 0xaf, 0x18, 0x07, 0x80, 0x03, 0x24,
0x01, 0x14, 0x01, 0x82, 0x49, 0x83, 0x42, 0x00,
0x77, 0xf0, 0x32, 0x34,
},
bytes.Repeat([]byte{1, 2, 3, 4}, 360)),
},
{
Header: rtp.Header{
Expand All @@ -75,8 +88,9 @@ var cases = []struct {
SequenceNumber: 17646,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes([]byte{0x90, 0xb5, 0xaf, 0x02, 0x03, 0x04},
bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04}, 363), []byte{0x01, 0x02}),
Payload: mergeBytes(
[]byte{0x81, 0xb5, 0xaf},
bytes.Repeat([]byte{1, 2, 3, 4}, 364), []byte{1}),
},
{
Header: rtp.Header{
Expand All @@ -86,7 +100,9 @@ var cases = []struct {
SequenceNumber: 17647,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes([]byte{0x94, 0xb5, 0xaf, 0x03, 0x04}, bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04}, 295)),
Payload: mergeBytes(
[]byte{0x85, 0xb5, 0xaf, 2, 3, 4},
bytes.Repeat([]byte{1, 2, 3, 4}, 299)),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/format/vp9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestVP9DecEncoder(t *testing.T) {
enc, err := format.CreateEncoder()
require.NoError(t, err)

pkts, err := enc.Encode([]byte{0x01, 0x02, 0x03, 0x04})
pkts, err := enc.Encode([]byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34})
require.NoError(t, err)
require.Equal(t, format.PayloadType(), pkts[0].PayloadType)

Expand All @@ -31,5 +31,5 @@ func TestVP9DecEncoder(t *testing.T) {

byts, err := dec.Decode(pkts[0])
require.NoError(t, err)
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts)
require.Equal(t, []byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34}, byts)
}

0 comments on commit 30dd8d3

Please sign in to comment.