stereolabs / zed-sdk

⚡️The spatial perception framework for rapidly building smart robots and spaces
https://stereolabs.com
MIT License
822 stars 466 forks source link

SDK4.2.1: SVO2 recorder hangs when enable and disable too frequently #658

Open MartinChowYW opened 3 weeks ago

MartinChowYW commented 3 weeks ago

Preliminary Checks

Description

I have seen this issue from SDK 4.1 and it looks like it has not been resolved. There is a need for me to keep creating a fixed length of SVO2 recording files. I did that by calling "enableRecording" and "disableRecording" and it worked perfectly fine in SVO version one. After switching to SVO2, the SDK will hang with the below backtrack:

`#0 __pthread_clockjoin_ex (threadid=281468863297792, thread_return=0x0, clockid=0, abstime=, block=) at pthread_join_common.c:145

1 0x0000ffff92bb0230 in std::thread::join() () from /lib/aarch64-linux-gnu/libstdc++.so.6

2 0x0000ffff93e88324 in MCAPWriter::close() () from /usr/local/zed/lib/libsl_zed.so

3 0x0000ffff93dba2c8 in sl::svorw::SVOGen2Writer::~SVOGen2Writer() () from /usr/local/zed/lib/libsl_zed.so

4 0x0000ffff93dba734 in sl::svorw::SVOGen2Writer::~SVOGen2Writer() () from /usr/local/zed/lib/libsl_zed.so

5 0x0000ffff93dc9f04 in sl::svorw::SVOVideo::close() () from /usr/local/zed/lib/libsl_zed.so

6 0x0000ffff94dce074 in sl::Camera::disableRecording() () from /usr/local/zed/lib/libsl_zed.so`

Steps to Reproduce

  1. Write a python and C++ app to keep enabling and disabling the SVO2 recorder. I found that the faster you switch, the faster it will happen.

Expected Result

The SDK will not hang and continue to produce SVO2 file.

Actual Result

The SDK hanged with the below backtrack: `#0 __pthread_clockjoin_ex (threadid=281468863297792, thread_return=0x0, clockid=0, abstime=, block=) at pthread_join_common.c:145

1 0x0000ffff92bb0230 in std::thread::join() () from /lib/aarch64-linux-gnu/libstdc++.so.6

2 0x0000ffff93e88324 in MCAPWriter::close() () from /usr/local/zed/lib/libsl_zed.so

3 0x0000ffff93dba2c8 in sl::svorw::SVOGen2Writer::~SVOGen2Writer() () from /usr/local/zed/lib/libsl_zed.so

4 0x0000ffff93dba734 in sl::svorw::SVOGen2Writer::~SVOGen2Writer() () from /usr/local/zed/lib/libsl_zed.so

5 0x0000ffff93dc9f04 in sl::svorw::SVOVideo::close() () from /usr/local/zed/lib/libsl_zed.so

6 0x0000ffff94dce074 in sl::Camera::disableRecording() () from /usr/local/zed/lib/libsl_zed.so`

ZED Camera model

ZED2i

Environment

aarch64
Jetson Xavier, Orin
SDK 4.1 to 4.2 all have this problem

Anything else?

No response

Myzhar commented 3 weeks ago

Hi @MartinChowYW please share a snippet of code to reproduce this issue. It will be useful to replicate and fix the bug.

MartinChowYW commented 3 weeks ago

Hi @MartinChowYW please share a snippet of code to reproduce this issue. It will be useful to replicate and fix the bug.

Thanks @Myzhar for coming back to me. I do not have the C++ code snippet at this moment but I am able to reproduce the same bug using the python script below:

Please run the provided python script to open the zed camera and start recording e.g. "./recorder.py ${PATH_TO_SVO2_FILE}"

import sys
import pyzed.sl as sl
import time
import os

zed = sl.Camera()
zed.open()
# Enable recording with the filename specified in argument
output_path = sys.argv[1]
recordingParameters = sl.RecordingParameters()
recordingParameters.compression_mode = sl.SVO_COMPRESSION_MODE.H264
recordingParameters.video_filename = output_path
err = zed.enable_recording(recordingParameters)

frame_counter = 0
zed.enable_recording(recordingParameters)

while True:
    # Each new frame is added to the SVO file
    print("Before Grab")
    if (zed.grab() == sl.ERROR_CODE.SUCCESS):
        print("Grabbed")
        time.sleep(0.1)
        frame_counter += 1

        if frame_counter == 3:
            print("Disabling recording ......")
            zed.disable_recording()
            print("Disabled recording ......")

            # Reset frame counter
            frame_counter = 0

            print("Enabling SVO recorder")
            zed.enable_recording(recordingParameters)

Changing the sleep time or the condition check on the frame_counter will the time to reproduce. I found that the shorter the sleep/frame_counter, the faster the bug will happen.

Please let me know if the python script is sufficient enough, happy to draft a C++ version of it. Hope to hear you back. Cheers.

MartinChowYW commented 3 weeks ago

Hi @Myzhar, please find the above python script and it would be awesome if I can hear some feedback from you. Cheers.