From 30dd8d38b36751bdec6fc04cbcc8a3c1ef412762 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:07:54 +0200 Subject: [PATCH] fix VP9 decoding on iOS (https://github.com/bluenviron/mediamtx/issues/3060) --- go.mod | 2 ++ go.sum | 4 ++-- pkg/format/rtpvp9/encoder_test.go | 30 +++++++++++++++++++++++------- pkg/format/vp9_test.go | 4 ++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index fc6eb1e0..a1fc5bf1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a5650d04..0c7a777c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/format/rtpvp9/encoder_test.go b/pkg/format/rtpvp9/encoder_test.go index 7910a7d0..6745b0e8 100644 --- a/pkg/format/rtpvp9/encoder_test.go +++ b/pkg/format/rtpvp9/encoder_test.go @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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)), }, }, }, diff --git a/pkg/format/vp9_test.go b/pkg/format/vp9_test.go index bbe988a8..46bcf66d 100644 --- a/pkg/format/vp9_test.go +++ b/pkg/format/vp9_test.go @@ -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) @@ -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) }