ReFormationPro / Gstreamer-H264-Encryption

Experimental GStreamer plugin for encrypting / decrypting H264 streams with AES
https://medium.com/@oguzhanoztaskin/gstreamer-h264-encryption-plugin-cf2c7b43c383
GNU General Public License v3.0
5 stars 1 forks source link

`h264decrypt` (during receiving `rtp` over `udp`) fails after few seconds #5

Closed inobelar closed 2 months ago

inobelar commented 2 months ago

Greetings! This issue is similar to https://github.com/ReFormationPro/Gstreamer-H264-Encryption/issues/4 , but now I'm tried to send h264-encoded video, wrapped intortp protocol via udp (on localhost).

I launch 'Receiver' first, and 'Sender' after it. 'Receiver' show few first frames (so it decrypt them correctly) then glitches, than completely fails.

inobelar commented 2 months ago

Update: Even without udp usage h264decrypt fails in the next case (rtp payload and immediate depayload):

$ GST_PLUGIN_PATH=/home/vuser/work/Gstreamer-H264-Encryption/build \
  GST_DEBUG=5 \
  DISPLAY=:0.0 \
  gst-launch-1.0 --verbose \
    videotestsrc do-timestamp=true pattern=ball ! \
        "video/x-raw, width=640, height=480, framerate=30/1" ! \
    timeoverlay ! \
    x264enc ! \
    \
    h264encrypt \
        iv-seed=1869052520 \
        key=01234567012345670123456701234567 \
        encryption-mode=aes-cbc ! \
    \
    rtph264pay config-interval=1 ! \
    rtph264depay ! \
    \
    h264decrypt \
        key=01234567012345670123456701234567 \
        encryption-mode=aes-cbc ! \
    \
    avdec_h264 ! \
    videoconvert ! \
    ximagesink \
        sync=true
End of huge STDOUT log (GST_DEBUG=5) ``` 0:00:10.290624942 4462 0x717508000b70 DEBUG h264encryptionbase h264_encryption_base.c:235:gst_h264_encryption_base_transform: A buffer is received 0:00:10.290646279 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:250:gst_h264_parse_nalu_header: Nal type 9, ref_idc 0 0:00:10.290784355 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1577:gst_h264_parser_identify_nalu: Complete nal found. Off: 4, Size: 2 0:00:10.290802990 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:250:gst_h264_parse_nalu_header: Nal type 6, ref_idc 0 0:00:10.290818619 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1577:gst_h264_parser_identify_nalu: Complete nal found. Off: 10, Size: 36 0:00:10.290908812 4462 0x717508000b70 DEBUG h264decrypt h264_decrypt.c:150:gst_h264_decrypt_before_nalu_copy: found SEI 0:00:10.290926120 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:2731:gst_h264_parser_parse_sei: parsing SEI nal 0:00:10.290941057 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1317:gst_h264_parser_parse_sei_message: parsing "SEI message" 0:00:10.290992918 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1337:gst_h264_parser_parse_sei_message: SEI message received: payloadType 5, payloadSize = 256 bits 0:00:10.291044951 4462 0x717508000b70 DEBUG h264decrypt h264_decrypt.c:160:gst_h264_decrypt_before_nalu_copy: found the User Data Unregistered SEI 0:00:10.291060145 4462 0x717508000b70 DEBUG h264decrypt h264_decrypt.c:177:gst_h264_decrypt_before_nalu_copy: IV is found 0:00:10.291076283 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:250:gst_h264_parse_nalu_header: Nal type 1, ref_idc 2 0:00:10.291164505 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1562:gst_h264_parser_identify_nalu: Nal start 50, No end found 0:00:10.291181687 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:250:gst_h264_parse_nalu_header: Nal type 1, ref_idc 2 0:00:10.291196691 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:1562:gst_h264_parser_identify_nalu: Nal start 10, No end found 0:00:10.291388981 4462 0x717508000b70 DEBUG h264encryptionbase h264_encryption_base.c:287:gst_h264_encryption_base_transform: Source nal unit is copied. Type 1 sc_offset 46 total_size 488 0:00:10.291407508 4462 0x717508000b70 DEBUG h264encryptionbase h264_encryption_base.c:293:gst_h264_encryption_base_transform: Copied nal unit is parsed. Type 1 sc_offset 6 total_size 488 expected size 488 0:00:10.291424456 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:2467:gst_h264_parser_parse_slice_hdr: parsing "Slice header", slice type 5 0:00:10.291440802 4462 0x717508000b70 DEBUG codecparsers_h264 gsth264parser.c:709:gst_h264_slice_parse_dec_ref_pic_marking: parsing "Decoded reference picture marking" 0:00:10.291458311 4462 0x717508000b70 ERROR h264decrypt h264_decrypt.c:276:gst_h264_decrypt_decrypt_slice_nalu: Encrypted block size (479) is not a multiple of AES_BLOCKLEN (16). Not attempting to decrypt. 0:00:10.291476784 4462 0x717508000b70 ERROR h264decrypt h264_decrypt.c:200:gst_h264_decrypt_process_slice_nalu: Failed to decrypt slice nal unit 0:00:10.291491048 4462 0x717508000b70 ERROR h264encryptionbase h264_encryption_base.c:309:gst_h264_encryption_base_transform: Subclass failed to parse slice nalu ```
ReFormationPro commented 2 months ago

Yes, this seems to be related. Off-by-one error again. I will compare payloads to see where in the payload the error occurs.

ReFormationPro commented 2 months ago

This is also fixed because of the fix for #4 so I am closing it.