From 8f18a0d83b9d63cd61e620ba3740b0c384b3dc1e Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Fri, 1 Sep 2023 18:31:52 +0200 Subject: [PATCH] check SPS/PPS of H264/H265 SDPs (#394) --- client_record_test.go | 13 ++++++++++--- pkg/format/h264.go | 6 ++++++ pkg/format/h265.go | 12 ++++++++++++ server_record_test.go | 8 ++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/client_record_test.go b/client_record_test.go index 9564e30f..21716a49 100644 --- a/client_record_test.go +++ b/client_record_test.go @@ -26,9 +26,16 @@ import ( var testH264Media = &description.Media{ Type: description.MediaTypeVideo, Formats: []format.Format{&format.H264{ - PayloadTyp: 96, - SPS: []byte{0x01, 0x02, 0x03, 0x04}, - PPS: []byte{0x01, 0x02, 0x03, 0x04}, + PayloadTyp: 96, + SPS: []byte{ + 0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00, 0x78, 0x02, + 0x27, 0xe5, 0x84, 0x00, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, + 0x20, + }, + PPS: []byte{ + 0x44, 0x01, 0xc0, 0x25, 0x2f, 0x05, 0x32, 0x40, + }, PacketizationMode: 1, }}, } diff --git a/pkg/format/h264.go b/pkg/format/h264.go index 6fc8e98d..428c549c 100644 --- a/pkg/format/h264.go +++ b/pkg/format/h264.go @@ -43,6 +43,12 @@ func (f *H264) unmarshal(ctx *unmarshalContext) error { return fmt.Errorf("invalid sprop-parameter-sets (%v)", val) } + var spsp h264.SPS + err = spsp.Unmarshal(sps) + if err != nil { + return fmt.Errorf("invalid SPS: %v", err) + } + f.SPS = sps f.PPS = pps } diff --git a/pkg/format/h265.go b/pkg/format/h265.go index 44cfb89c..7a1c4069 100644 --- a/pkg/format/h265.go +++ b/pkg/format/h265.go @@ -43,6 +43,12 @@ func (f *H265) unmarshal(ctx *unmarshalContext) error { return fmt.Errorf("invalid sprop-sps (%v)", ctx.fmtp) } + var spsp h265.SPS + err = spsp.Unmarshal(f.SPS) + if err != nil { + return fmt.Errorf("invalid SPS: %v", err) + } + case "sprop-pps": var err error f.PPS, err = base64.StdEncoding.DecodeString(val) @@ -50,6 +56,12 @@ func (f *H265) unmarshal(ctx *unmarshalContext) error { return fmt.Errorf("invalid sprop-pps (%v)", ctx.fmtp) } + var ppsp h265.PPS + err = ppsp.Unmarshal(f.PPS) + if err != nil { + return fmt.Errorf("invalid PPS: %v", err) + } + case "sprop-max-don-diff": tmp, err := strconv.ParseUint(val, 10, 31) if err != nil { diff --git a/server_record_test.go b/server_record_test.go index 3b7701a4..fd05cabb 100644 --- a/server_record_test.go +++ b/server_record_test.go @@ -586,8 +586,8 @@ func TestServerRecord(t *testing.T) { Type: description.MediaTypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, - SPS: []byte{0x01, 0x02, 0x03, 0x04}, - PPS: []byte{0x01, 0x02, 0x03, 0x04}, + SPS: testH264Media.Formats[0].(*format.H264).SPS, + PPS: testH264Media.Formats[0].(*format.H264).PPS, PacketizationMode: 1, }}, }, @@ -595,8 +595,8 @@ func TestServerRecord(t *testing.T) { Type: description.MediaTypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, - SPS: []byte{0x01, 0x02, 0x03, 0x04}, - PPS: []byte{0x01, 0x02, 0x03, 0x04}, + SPS: testH264Media.Formats[0].(*format.H264).SPS, + PPS: testH264Media.Formats[0].(*format.H264).PPS, PacketizationMode: 1, }}, },