Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
738 stars 186 forks source link

Fix: Crash on the device that does not support NvEnc API . #1009

Closed kannan-xiao4 closed 6 months ago

kannan-xiao4 commented 6 months ago

Even on Nvidia devices that support CUDA, NvEncAPI may not be available. (ex MX450) refer https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new

On those devices, the DLLs (nvcuda.dll, nvencodeAPI.dll) can be found, but an error will occur when calling the open session API. Therefore, check whether you can open Session and determine whether NvEnc can be used on that device.

I think fix this https://github.com/Unity-Technologies/com.unity.webrtc/issues/806 maybe fix this https://github.com/Unity-Technologies/com.unity.webrtc/issues/1006

unity-cla-assistant commented 6 months ago

CLA assistant check
All committers have signed the CLA.

karasusan commented 6 months ago

It's been a long time!

There are two errors on Linux when building a native plugin.

/home/bokken/build/output/Unity-Technologies/com.unity.webrtc/Plugin~/WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:160:82: error: missing field 'reserved' initializer [-Werror,-Wmissing-field-initializers]
        NV_ENCODE_API_FUNCTION_LIST funclist = { NV_ENCODE_API_FUNCTION_LIST_VER };
                                                                                 ^
/home/bokken/build/output/Unity-Technologies/com.unity.webrtc/Plugin~/WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:168:113: error: missing field 'deviceType' initializer [-Werror,-Wmissing-field-initializers]
        NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS encodeSessionExParams = { NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER };

And we have clang-format errors.

[07:04:07.783 Information] ./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:172:13: error: code should be clang-formatted [-Wclang-format-violations]
        void *hEncoder = nullptr;
            ^
./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:172:15: error: code should be clang-formatted [-Wclang-format-violations]
        void *hEncoder = nullptr;
kannan-xiao4 commented 6 months ago

Hi, @karasusan, long time.

It is not necessary to prepare all Initializers for these Structs, but for some reason an error occurs. I would like to avoid this using attributes (d1c29e7), but is there anything else I can do?

I referred to implement https://github.com/Unity-Technologies/com.unity.webrtc/blob/main/Plugin~/NvCodec/NvCodec/NvEncoder/NvEncoder.cpp#L54

karasusan commented 6 months ago

NvCodecTest.cpp has a compile error.

/home/bokken/build/output/Unity-Technologies/com.unity.webrtc/Plugin~/WebRTCPluginTest/NvCodec/NvCodecTest.cpp:39:18: error: too few arguments to function call, expected 1, have 0; did you mean 'NvDecoder::IsSupported'?
            if (!NvEncoder::IsSupported())
                 ^~~~~~~~~
                 NvDecoder::IsSupported
/home/bokken/build/output/Unity-Technologies/com.unity.webrtc/Plugin~/WebRTCPluginTest/../WebRTCPlugin/Codec/NvCodec/NvCodec.h:47:21: note: 'NvDecoder::IsSupported' declared here
        static bool IsSupported();

And there are still format errors. It might be a pragma indent.

[08:53:28.818 Information] ./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:157:10: error: code should be clang-formatted [-Wclang-format-violations]
        }
         ^
./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:159:75: error: code should be clang-formatted [-Wclang-format-violations]
        // Check if this device can get the function list of nvencoder API
                                                                          ^
./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:166:10: error: code should be clang-formatted [-Wclang-format-violations]
        }
         ^
./WebRTCPlugin/Codec/NvCodec/NvCodec.cpp:168:56: error: code should be clang-formatted [-Wclang-format-violations]
        // Check if this device can open encode session