From 378ef6fd2293f19b402da4829ddce5258053e8f4 Mon Sep 17 00:00:00 2001 From: Redi Kim Date: Thu, 2 May 2024 12:18:13 +0900 Subject: [PATCH] Add test case for broken second nalu in STAP-A --- codecs/h264_packet_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/codecs/h264_packet_test.go b/codecs/h264_packet_test.go index 8e3b221..ca8a92c 100644 --- a/codecs/h264_packet_test.go +++ b/codecs/h264_packet_test.go @@ -109,6 +109,9 @@ func TestH264Packet_Unmarshal(t *testing.T) { singlePayloadMultiNALU := []byte{0x78, 0x00, 0x0f, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8, 0x00, 0x05, 0x68, 0x1a, 0x34, 0xe3, 0xc8} singlePayloadMultiNALUUnmarshaled := []byte{0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8, 0x00, 0x00, 0x00, 0x01, 0x68, 0x1a, 0x34, 0xe3, 0xc8} singlePayloadMultiNALUUnmarshaledAVC := []byte{0x00, 0x00, 0x00, 0x0f, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8, 0x00, 0x00, 0x00, 0x05, 0x68, 0x1a, 0x34, 0xe3, 0xc8} + singlePayloadWithBrokenSecondNALU := []byte{0x78, 0x00, 0x0f, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8, 0x00} + singlePayloadWithBrokenSecondNALUUnmarshaled := []byte{0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8} + singlePayloadWithBrokenSecondUnmarshaledAVC := []byte{0x00, 0x00, 0x00, 0x0f, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11, 0xa8} incompleteSinglePayloadMultiNALU := []byte{0x78, 0x00, 0x0f, 0x67, 0x42, 0xc0, 0x1f, 0x1a, 0x32, 0x35, 0x01, 0x40, 0x7a, 0x40, 0x3c, 0x22, 0x11} @@ -189,6 +192,20 @@ func TestH264Packet_Unmarshal(t *testing.T) { } else if !reflect.DeepEqual(res, singlePayloadMultiNALUUnmarshaledAVC) { t.Fatal("Failed to unmarshal a single packet with multiple NALUs into avc stream") } + + res, err = pkt.Unmarshal(singlePayloadWithBrokenSecondNALU) + if err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(res, singlePayloadWithBrokenSecondNALUUnmarshaled) { + t.Fatal("Failed to unmarshal a single packet with broken second NALUs") + } + + res, err = avcPkt.Unmarshal(singlePayloadWithBrokenSecondNALU) + if err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(res, singlePayloadWithBrokenSecondUnmarshaledAVC) { + t.Fatal("Failed to unmarshal a single packet with broken second NALUs into avc stream") + } } func TestH264IsPartitionHead(t *testing.T) {