mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-11-28 08:14:18 +00:00
refactor: fix sonar cpp:S936 (#5905)
This commit is contained in:
1 parent
d1fc311f6b
commit
b261a1b95e
24 files changed
+295
-111
No files matched your search
+1
-1
@@ -32,7 +32,7 @@ namespace cbs {
|
||||
/**
|
||||
* @brief Owning coded bitstream context pointer that calls ff_cbs_close.
|
||||
*/
|
||||
using ctx_t = util::safe_ptr<CodedBitstreamContext, close>;
|
||||
using ctx_t = util::safe_ptr<CodedBitstreamContext, &close>;
|
||||
|
||||
/**
|
||||
* @brief Owns an FFmpeg coded bitstream fragment and frees fragment buffers on destruction.
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace crypto {
|
||||
/**
|
||||
* @brief OpenSSL ASN.1 string pointer with automatic release.
|
||||
*/
|
||||
using asn1_string_t = util::safe_ptr<ASN1_STRING, ASN1_STRING_free>;
|
||||
using asn1_string_t = util::safe_ptr<ASN1_STRING, &ASN1_STRING_free>;
|
||||
/**
|
||||
* @brief OpenSSL X.509 subject/issuer name pointer with automatic release.
|
||||
*/
|
||||
|
||||
+9
-9
@@ -44,39 +44,39 @@ namespace crypto {
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL X.509 certificate.
|
||||
*/
|
||||
using x509_t = util::safe_ptr<X509, X509_free>;
|
||||
using x509_t = util::safe_ptr<X509, &X509_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL certificate store.
|
||||
*/
|
||||
using x509_store_t = util::safe_ptr<X509_STORE, X509_STORE_free>;
|
||||
using x509_store_t = util::safe_ptr<X509_STORE, &X509_STORE_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL certificate verification context.
|
||||
*/
|
||||
using x509_store_ctx_t = util::safe_ptr<X509_STORE_CTX, X509_STORE_CTX_free>;
|
||||
using x509_store_ctx_t = util::safe_ptr<X509_STORE_CTX, &X509_STORE_CTX_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL cipher context.
|
||||
*/
|
||||
using cipher_ctx_t = util::safe_ptr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free>;
|
||||
using cipher_ctx_t = util::safe_ptr<EVP_CIPHER_CTX, &EVP_CIPHER_CTX_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL message digest context.
|
||||
*/
|
||||
using md_ctx_t = util::safe_ptr<EVP_MD_CTX, md_ctx_destroy>;
|
||||
using md_ctx_t = util::safe_ptr<EVP_MD_CTX, &md_ctx_destroy>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL BIO chain.
|
||||
*/
|
||||
using bio_t = util::safe_ptr<BIO, BIO_free_all>;
|
||||
using bio_t = util::safe_ptr<BIO, &BIO_free_all>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL public or private key.
|
||||
*/
|
||||
using pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>;
|
||||
using pkey_t = util::safe_ptr<EVP_PKEY, &EVP_PKEY_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL key-generation context.
|
||||
*/
|
||||
using pkey_ctx_t = util::safe_ptr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
|
||||
using pkey_ctx_t = util::safe_ptr<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
|
||||
/**
|
||||
* @brief Owning pointer for an OpenSSL BIGNUM.
|
||||
*/
|
||||
using bignum_t = util::safe_ptr<BIGNUM, BN_free>;
|
||||
using bignum_t = util::safe_ptr<BIGNUM, &BN_free>;
|
||||
|
||||
/**
|
||||
* @brief Hashes the given plaintext using SHA-256.
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ namespace net {
|
||||
/**
|
||||
* @brief Owning ENet host pointer released with `enet_host_destroy`.
|
||||
*/
|
||||
using host_t = util::safe_ptr<ENetHost, free_host>;
|
||||
using host_t = util::safe_ptr<ENetHost, &free_host>;
|
||||
/**
|
||||
* @brief Raw ENet peer handle owned by an ENet host.
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ namespace net {
|
||||
/**
|
||||
* @brief Owning ENet packet pointer released with `enet_packet_destroy`.
|
||||
*/
|
||||
using packet_t = util::safe_ptr<ENetPacket, enet_packet_destroy>;
|
||||
using packet_t = util::safe_ptr<ENetPacket, &enet_packet_destroy>;
|
||||
|
||||
/**
|
||||
* @brief Enumerates supported net options.
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace platf {
|
||||
* @brief PulseAudio recording stream and channel metadata.
|
||||
*/
|
||||
struct mic_attr_t: public mic_t {
|
||||
util::safe_ptr<pa_simple, pa_simple_free> mic; ///< PulseAudio simple recording stream for microphone capture.
|
||||
util::safe_ptr<pa_simple, &pa_simple_free> mic; ///< PulseAudio simple recording stream for microphone capture.
|
||||
|
||||
/**
|
||||
* @brief Deliver a captured audio sample to Sunshine's audio pipeline.
|
||||
@@ -218,19 +218,19 @@ namespace platf {
|
||||
/**
|
||||
* @brief Owning pointer for a PulseAudio context.
|
||||
*/
|
||||
using ctx_t = util::safe_ptr<pa_context, pa_context_unref>;
|
||||
using ctx_t = util::safe_ptr<pa_context, &pa_context_unref>;
|
||||
/**
|
||||
* @brief Owning pointer for a PulseAudio mainloop.
|
||||
*/
|
||||
using loop_t = util::safe_ptr<pa_mainloop, pa_mainloop_free>;
|
||||
using loop_t = util::safe_ptr<pa_mainloop, &pa_mainloop_free>;
|
||||
/**
|
||||
* @brief Owning pointer for a PulseAudio asynchronous operation.
|
||||
*/
|
||||
using op_t = util::safe_ptr<pa_operation, pa_operation_unref>;
|
||||
using op_t = util::safe_ptr<pa_operation, &pa_operation_unref>;
|
||||
/**
|
||||
* @brief Owning pointer for PulseAudio strings allocated with `pa_xmalloc`.
|
||||
*/
|
||||
using string_t = util::safe_ptr<char, pa_free<char>>;
|
||||
using string_t = util::safe_ptr<char, &pa_free<char>>;
|
||||
|
||||
/**
|
||||
* @brief Callback wrapper for PulseAudio introspection results without an end marker.
|
||||
|
||||
@@ -63,7 +63,7 @@ void free_frame(AVFrame *frame);
|
||||
/**
|
||||
* @brief Owning pointer for an EGL frame object.
|
||||
*/
|
||||
using frame_t = util::safe_ptr<AVFrame, free_frame>;
|
||||
using frame_t = util::safe_ptr<AVFrame, &free_frame>;
|
||||
|
||||
namespace gl {
|
||||
extern GladGLContext ctx;
|
||||
|
||||
@@ -300,19 +300,19 @@ namespace platf {
|
||||
/**
|
||||
* @brief DRM plane resource list released with `drmModeFreePlaneResources`.
|
||||
*/
|
||||
using plane_res_t = util::safe_ptr<drmModePlaneRes, drmModeFreePlaneResources>;
|
||||
using plane_res_t = util::safe_ptr<drmModePlaneRes, &drmModeFreePlaneResources>;
|
||||
/**
|
||||
* @brief DRM encoder pointer released with `drmModeFreeEncoder`.
|
||||
*/
|
||||
using encoder_t = util::safe_ptr<drmModeEncoder, drmModeFreeEncoder>;
|
||||
using encoder_t = util::safe_ptr<drmModeEncoder, &drmModeFreeEncoder>;
|
||||
/**
|
||||
* @brief DRM resource list released with `drmModeFreeResources`.
|
||||
*/
|
||||
using res_t = util::safe_ptr<drmModeRes, drmModeFreeResources>;
|
||||
using res_t = util::safe_ptr<drmModeRes, &drmModeFreeResources>;
|
||||
/**
|
||||
* @brief DRM plane pointer released with `drmModeFreePlane`.
|
||||
*/
|
||||
using plane_t = util::safe_ptr<drmModePlane, drmModeFreePlane>;
|
||||
using plane_t = util::safe_ptr<drmModePlane, &drmModeFreePlane>;
|
||||
/**
|
||||
* @brief DRM framebuffer pointer released with `drmModeFreeFB2`.
|
||||
*/
|
||||
@@ -320,23 +320,23 @@ namespace platf {
|
||||
/**
|
||||
* @brief DRM CRTC pointer released with `drmModeFreeCrtc`.
|
||||
*/
|
||||
using crtc_t = util::safe_ptr<drmModeCrtc, drmModeFreeCrtc>;
|
||||
using crtc_t = util::safe_ptr<drmModeCrtc, &drmModeFreeCrtc>;
|
||||
/**
|
||||
* @brief DRM object-property list released with `drmModeFreeObjectProperties`.
|
||||
*/
|
||||
using obj_prop_t = util::safe_ptr<drmModeObjectProperties, drmModeFreeObjectProperties>;
|
||||
using obj_prop_t = util::safe_ptr<drmModeObjectProperties, &drmModeFreeObjectProperties>;
|
||||
/**
|
||||
* @brief DRM property pointer released with `drmModeFreeProperty`.
|
||||
*/
|
||||
using prop_t = util::safe_ptr<drmModePropertyRes, drmModeFreeProperty>;
|
||||
using prop_t = util::safe_ptr<drmModePropertyRes, &drmModeFreeProperty>;
|
||||
/**
|
||||
* @brief DRM property-blob pointer released with `drmModeFreePropertyBlob`.
|
||||
*/
|
||||
using prop_blob_t = util::safe_ptr<drmModePropertyBlobRes, drmModeFreePropertyBlob>;
|
||||
using prop_blob_t = util::safe_ptr<drmModePropertyBlobRes, &drmModeFreePropertyBlob>;
|
||||
/**
|
||||
* @brief DRM version pointer released with `drmFreeVersion`.
|
||||
*/
|
||||
using version_t = util::safe_ptr<drmVersion, drmFreeVersion>;
|
||||
using version_t = util::safe_ptr<drmVersion, &drmFreeVersion>;
|
||||
|
||||
/**
|
||||
* @brief Counter map keyed by DRM connector type.
|
||||
@@ -689,7 +689,7 @@ namespace platf {
|
||||
/**
|
||||
* @brief Internal connector metadata tuple used while selecting a monitor.
|
||||
*/
|
||||
using connector_interal_t = util::safe_ptr<drmModeConnector, drmModeFreeConnector>;
|
||||
using connector_interal_t = util::safe_ptr<drmModeConnector, &drmModeFreeConnector>;
|
||||
|
||||
/**
|
||||
* @brief Open a DRM connector and cache its monitor metadata.
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace platf {
|
||||
/**
|
||||
* @brief Owning pointer for `getifaddrs` results.
|
||||
*/
|
||||
using ifaddr_t = util::safe_ptr<ifaddrs, freeifaddrs>;
|
||||
using ifaddr_t = util::safe_ptr<ifaddrs, &freeifaddrs>;
|
||||
|
||||
/**
|
||||
* @brief Open a DRM card node, dropping implicit DRM master when possible.
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace va {
|
||||
/**
|
||||
* @brief VA display handle released with `vaTerminate`.
|
||||
*/
|
||||
using display_t = util::safe_ptr_v2<void, VAStatus, vaTerminate>;
|
||||
using display_t = util::safe_ptr_v2<void, VAStatus, &vaTerminate>;
|
||||
|
||||
/**
|
||||
* @brief Create an FFmpeg VA-API hardware device context from a Sunshine encode device.
|
||||
|
||||
@@ -296,11 +296,11 @@ namespace platf {
|
||||
/**
|
||||
* @brief XImage pointer released with `XDestroyImage`.
|
||||
*/
|
||||
using ximg_t = util::safe_ptr<XImage, freeImage>;
|
||||
using ximg_t = util::safe_ptr<XImage, &freeImage>;
|
||||
/**
|
||||
* @brief XFixes cursor image pointer released with `XFree`.
|
||||
*/
|
||||
using xcursor_t = util::safe_ptr<XFixesCursorImage, freeX>;
|
||||
using xcursor_t = util::safe_ptr<XFixesCursorImage, &freeX>;
|
||||
|
||||
/**
|
||||
* @brief XRandR CRTC info pointer released with `XRRFreeCrtcInfo`.
|
||||
|
||||
@@ -36,11 +36,11 @@ namespace platf::x11 {
|
||||
/**
|
||||
* @brief XFixes cursor image pointer released with `XFree`.
|
||||
*/
|
||||
using cursor_ctx_t = util::safe_ptr<cursor_ctx_raw_t, freeCursorCtx>;
|
||||
using cursor_ctx_t = util::safe_ptr<cursor_ctx_raw_t, &freeCursorCtx>;
|
||||
/**
|
||||
* @brief X11 display pointer released with `XCloseDisplay`.
|
||||
*/
|
||||
using xdisplay_t = util::safe_ptr<_XDisplay, freeDisplay>;
|
||||
using xdisplay_t = util::safe_ptr<_XDisplay, &freeDisplay>;
|
||||
|
||||
/**
|
||||
* @brief X11 cursor image and positioning state used during capture.
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace platf {
|
||||
CVPixelBufferRelease((CVPixelBufferRef) data);
|
||||
}
|
||||
|
||||
util::safe_ptr<AVFrame, free_frame> av_frame; ///< AV frame.
|
||||
util::safe_ptr<AVFrame, &free_frame> av_frame; ///< AV frame.
|
||||
|
||||
int nv12_zero_device::convert(platf::img_t &img) {
|
||||
auto *av_img = (av_img_t *) &img;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace platf {
|
||||
int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override;
|
||||
|
||||
private:
|
||||
util::safe_ptr<AVFrame, free_frame> av_frame;
|
||||
util::safe_ptr<AVFrame, &free_frame> av_frame;
|
||||
};
|
||||
|
||||
} // namespace platf
|
||||
@@ -246,43 +246,43 @@ namespace platf::audio {
|
||||
/**
|
||||
* @brief COM device enumerator pointer for WASAPI endpoint discovery.
|
||||
*/
|
||||
using device_enum_t = util::safe_ptr<IMMDeviceEnumerator, Release<IMMDeviceEnumerator>>;
|
||||
using device_enum_t = util::safe_ptr<IMMDeviceEnumerator, &Release<IMMDeviceEnumerator>>;
|
||||
/**
|
||||
* @brief COM pointer to a Windows audio endpoint device.
|
||||
*/
|
||||
using device_t = util::safe_ptr<IMMDevice, Release<IMMDevice>>;
|
||||
using device_t = util::safe_ptr<IMMDevice, &Release<IMMDevice>>;
|
||||
/**
|
||||
* @brief COM pointer to a collection of Windows audio endpoint devices.
|
||||
*/
|
||||
using collection_t = util::safe_ptr<IMMDeviceCollection, Release<IMMDeviceCollection>>;
|
||||
using collection_t = util::safe_ptr<IMMDeviceCollection, &Release<IMMDeviceCollection>>;
|
||||
/**
|
||||
* @brief COM pointer to the WASAPI audio client interface.
|
||||
*/
|
||||
using audio_client_t = util::safe_ptr<IAudioClient, Release<IAudioClient>>;
|
||||
using audio_client_t = util::safe_ptr<IAudioClient, &Release<IAudioClient>>;
|
||||
/**
|
||||
* @brief COM pointer to the WASAPI capture client interface.
|
||||
*/
|
||||
using audio_capture_t = util::safe_ptr<IAudioCaptureClient, Release<IAudioCaptureClient>>;
|
||||
using audio_capture_t = util::safe_ptr<IAudioCaptureClient, &Release<IAudioCaptureClient>>;
|
||||
/**
|
||||
* @brief CoTaskMem-allocated WAVEFORMATEX pointer.
|
||||
*/
|
||||
using wave_format_t = util::safe_ptr<WAVEFORMATEX, co_task_free<WAVEFORMATEX>>;
|
||||
using wave_format_t = util::safe_ptr<WAVEFORMATEX, &co_task_free<WAVEFORMATEX>>;
|
||||
/**
|
||||
* @brief CoTaskMem-allocated wide string pointer.
|
||||
*/
|
||||
using wstring_t = util::safe_ptr<WCHAR, co_task_free<WCHAR>>;
|
||||
using wstring_t = util::safe_ptr<WCHAR, &co_task_free<WCHAR>>;
|
||||
/**
|
||||
* @brief Windows HANDLE wrapper closed with `CloseHandle`.
|
||||
*/
|
||||
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
||||
using handle_t = util::safe_ptr_v2<void, BOOL, &CloseHandle>;
|
||||
/**
|
||||
* @brief COM pointer to the Windows policy configuration interface.
|
||||
*/
|
||||
using policy_t = util::safe_ptr<IPolicyConfig, Release<IPolicyConfig>>;
|
||||
using policy_t = util::safe_ptr<IPolicyConfig, &Release<IPolicyConfig>>;
|
||||
/**
|
||||
* @brief COM pointer to a Windows property store.
|
||||
*/
|
||||
using prop_t = util::safe_ptr<IPropertyStore, Release<IPropertyStore>>;
|
||||
using prop_t = util::safe_ptr<IPropertyStore, &Release<IPropertyStore>>;
|
||||
|
||||
/**
|
||||
* @brief Initializes COM for the current thread and uninitializes it on exit.
|
||||
|
||||
@@ -42,149 +42,149 @@ namespace platf::dxgi {
|
||||
/**
|
||||
* @brief Owning COM pointer for the DXGI factory used to enumerate adapters.
|
||||
*/
|
||||
using factory1_t = util::safe_ptr<IDXGIFactory1, Release<IDXGIFactory1>>;
|
||||
using factory1_t = util::safe_ptr<IDXGIFactory1, &Release<IDXGIFactory1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI device interface.
|
||||
*/
|
||||
using dxgi_t = util::safe_ptr<IDXGIDevice, Release<IDXGIDevice>>;
|
||||
using dxgi_t = util::safe_ptr<IDXGIDevice, &Release<IDXGIDevice>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI 1.1 device interface.
|
||||
*/
|
||||
using dxgi1_t = util::safe_ptr<IDXGIDevice1, Release<IDXGIDevice1>>;
|
||||
using dxgi1_t = util::safe_ptr<IDXGIDevice1, &Release<IDXGIDevice1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the D3D11 device used by capture and conversion.
|
||||
*/
|
||||
using device_t = util::safe_ptr<ID3D11Device, Release<ID3D11Device>>;
|
||||
using device_t = util::safe_ptr<ID3D11Device, &Release<ID3D11Device>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the D3D11.1 device interface.
|
||||
*/
|
||||
using device1_t = util::safe_ptr<ID3D11Device1, Release<ID3D11Device1>>;
|
||||
using device1_t = util::safe_ptr<ID3D11Device1, &Release<ID3D11Device1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the immediate D3D11 device context.
|
||||
*/
|
||||
using device_ctx_t = util::safe_ptr<ID3D11DeviceContext, Release<ID3D11DeviceContext>>;
|
||||
using device_ctx_t = util::safe_ptr<ID3D11DeviceContext, &Release<ID3D11DeviceContext>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI display adapter.
|
||||
*/
|
||||
using adapter_t = util::safe_ptr<IDXGIAdapter1, Release<IDXGIAdapter1>>;
|
||||
using adapter_t = util::safe_ptr<IDXGIAdapter1, &Release<IDXGIAdapter1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI output.
|
||||
*/
|
||||
using output_t = util::safe_ptr<IDXGIOutput, Release<IDXGIOutput>>;
|
||||
using output_t = util::safe_ptr<IDXGIOutput, &Release<IDXGIOutput>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI output that supports duplication.
|
||||
*/
|
||||
using output1_t = util::safe_ptr<IDXGIOutput1, Release<IDXGIOutput1>>;
|
||||
using output1_t = util::safe_ptr<IDXGIOutput1, &Release<IDXGIOutput1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI output with HDR metadata support.
|
||||
*/
|
||||
using output5_t = util::safe_ptr<IDXGIOutput5, Release<IDXGIOutput5>>;
|
||||
using output5_t = util::safe_ptr<IDXGIOutput5, &Release<IDXGIOutput5>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a DXGI output with modern display descriptors.
|
||||
*/
|
||||
using output6_t = util::safe_ptr<IDXGIOutput6, Release<IDXGIOutput6>>;
|
||||
using output6_t = util::safe_ptr<IDXGIOutput6, &Release<IDXGIOutput6>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the DXGI desktop duplication session.
|
||||
*/
|
||||
using dup_t = util::safe_ptr<IDXGIOutputDuplication, Release<IDXGIOutputDuplication>>;
|
||||
using dup_t = util::safe_ptr<IDXGIOutputDuplication, &Release<IDXGIOutputDuplication>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 2D texture.
|
||||
*/
|
||||
using texture2d_t = util::safe_ptr<ID3D11Texture2D, Release<ID3D11Texture2D>>;
|
||||
using texture2d_t = util::safe_ptr<ID3D11Texture2D, &Release<ID3D11Texture2D>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 1D texture.
|
||||
*/
|
||||
using texture1d_t = util::safe_ptr<ID3D11Texture1D, Release<ID3D11Texture1D>>;
|
||||
using texture1d_t = util::safe_ptr<ID3D11Texture1D, &Release<ID3D11Texture1D>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the DXGI resource view of a shared texture.
|
||||
*/
|
||||
using resource_t = util::safe_ptr<IDXGIResource, Release<IDXGIResource>>;
|
||||
using resource_t = util::safe_ptr<IDXGIResource, &Release<IDXGIResource>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the DXGI 1.1 resource sharing interface.
|
||||
*/
|
||||
using resource1_t = util::safe_ptr<IDXGIResource1, Release<IDXGIResource1>>;
|
||||
using resource1_t = util::safe_ptr<IDXGIResource1, &Release<IDXGIResource1>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the D3D11 multithread-protection interface.
|
||||
*/
|
||||
using multithread_t = util::safe_ptr<ID3D11Multithread, Release<ID3D11Multithread>>;
|
||||
using multithread_t = util::safe_ptr<ID3D11Multithread, &Release<ID3D11Multithread>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 vertex shader.
|
||||
*/
|
||||
using vs_t = util::safe_ptr<ID3D11VertexShader, Release<ID3D11VertexShader>>;
|
||||
using vs_t = util::safe_ptr<ID3D11VertexShader, &Release<ID3D11VertexShader>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 pixel shader.
|
||||
*/
|
||||
using ps_t = util::safe_ptr<ID3D11PixelShader, Release<ID3D11PixelShader>>;
|
||||
using ps_t = util::safe_ptr<ID3D11PixelShader, &Release<ID3D11PixelShader>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 blend state.
|
||||
*/
|
||||
using blend_t = util::safe_ptr<ID3D11BlendState, Release<ID3D11BlendState>>;
|
||||
using blend_t = util::safe_ptr<ID3D11BlendState, &Release<ID3D11BlendState>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 input layout.
|
||||
*/
|
||||
using input_layout_t = util::safe_ptr<ID3D11InputLayout, Release<ID3D11InputLayout>>;
|
||||
using input_layout_t = util::safe_ptr<ID3D11InputLayout, &Release<ID3D11InputLayout>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 render-target view.
|
||||
*/
|
||||
using render_target_t = util::safe_ptr<ID3D11RenderTargetView, Release<ID3D11RenderTargetView>>;
|
||||
using render_target_t = util::safe_ptr<ID3D11RenderTargetView, &Release<ID3D11RenderTargetView>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 shader-resource view.
|
||||
*/
|
||||
using shader_res_t = util::safe_ptr<ID3D11ShaderResourceView, Release<ID3D11ShaderResourceView>>;
|
||||
using shader_res_t = util::safe_ptr<ID3D11ShaderResourceView, &Release<ID3D11ShaderResourceView>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 buffer.
|
||||
*/
|
||||
using buf_t = util::safe_ptr<ID3D11Buffer, Release<ID3D11Buffer>>;
|
||||
using buf_t = util::safe_ptr<ID3D11Buffer, &Release<ID3D11Buffer>>;
|
||||
/**
|
||||
* @brief D3D rasterizer state handle type.
|
||||
*/
|
||||
using raster_state_t = util::safe_ptr<ID3D11RasterizerState, Release<ID3D11RasterizerState>>;
|
||||
using raster_state_t = util::safe_ptr<ID3D11RasterizerState, &Release<ID3D11RasterizerState>>;
|
||||
/**
|
||||
* @brief D3D sampler state handle type.
|
||||
*/
|
||||
using sampler_state_t = util::safe_ptr<ID3D11SamplerState, Release<ID3D11SamplerState>>;
|
||||
using sampler_state_t = util::safe_ptr<ID3D11SamplerState, &Release<ID3D11SamplerState>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a compiled shader bytecode blob.
|
||||
*/
|
||||
using blob_t = util::safe_ptr<ID3DBlob, Release<ID3DBlob>>;
|
||||
using blob_t = util::safe_ptr<ID3DBlob, &Release<ID3DBlob>>;
|
||||
/**
|
||||
* @brief D3D depth-stencil state handle type.
|
||||
*/
|
||||
using depth_stencil_state_t = util::safe_ptr<ID3D11DepthStencilState, Release<ID3D11DepthStencilState>>;
|
||||
using depth_stencil_state_t = util::safe_ptr<ID3D11DepthStencilState, &Release<ID3D11DepthStencilState>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 depth-stencil view.
|
||||
*/
|
||||
using depth_stencil_view_t = util::safe_ptr<ID3D11DepthStencilView, Release<ID3D11DepthStencilView>>;
|
||||
using depth_stencil_view_t = util::safe_ptr<ID3D11DepthStencilView, &Release<ID3D11DepthStencilView>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a keyed mutex on a shared DXGI resource.
|
||||
*/
|
||||
using keyed_mutex_t = util::safe_ptr<IDXGIKeyedMutex, Release<IDXGIKeyedMutex>>;
|
||||
using keyed_mutex_t = util::safe_ptr<IDXGIKeyedMutex, &Release<IDXGIKeyedMutex>>;
|
||||
|
||||
namespace video {
|
||||
/**
|
||||
* @brief Owning COM pointer for the D3D11 video device interface.
|
||||
*/
|
||||
using device_t = util::safe_ptr<ID3D11VideoDevice, Release<ID3D11VideoDevice>>;
|
||||
using device_t = util::safe_ptr<ID3D11VideoDevice, &Release<ID3D11VideoDevice>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for the D3D11 video context interface.
|
||||
*/
|
||||
using ctx_t = util::safe_ptr<ID3D11VideoContext, Release<ID3D11VideoContext>>;
|
||||
using ctx_t = util::safe_ptr<ID3D11VideoContext, &Release<ID3D11VideoContext>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a D3D11 video processor.
|
||||
*/
|
||||
using processor_t = util::safe_ptr<ID3D11VideoProcessor, Release<ID3D11VideoProcessor>>;
|
||||
using processor_t = util::safe_ptr<ID3D11VideoProcessor, &Release<ID3D11VideoProcessor>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a video processor output view.
|
||||
*/
|
||||
using processor_out_t = util::safe_ptr<ID3D11VideoProcessorOutputView, Release<ID3D11VideoProcessorOutputView>>;
|
||||
using processor_out_t = util::safe_ptr<ID3D11VideoProcessorOutputView, &Release<ID3D11VideoProcessorOutputView>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a video processor input view.
|
||||
*/
|
||||
using processor_in_t = util::safe_ptr<ID3D11VideoProcessorInputView, Release<ID3D11VideoProcessorInputView>>;
|
||||
using processor_in_t = util::safe_ptr<ID3D11VideoProcessorInputView, &Release<ID3D11VideoProcessorInputView>>;
|
||||
/**
|
||||
* @brief Owning COM pointer for a video processor capability enumerator.
|
||||
*/
|
||||
using processor_enum_t = util::safe_ptr<ID3D11VideoProcessorEnumerator, Release<ID3D11VideoProcessorEnumerator>>;
|
||||
using processor_enum_t = util::safe_ptr<ID3D11VideoProcessorEnumerator, &Release<ID3D11VideoProcessorEnumerator>>;
|
||||
} // namespace video
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ static void free_frame(AVFrame *frame) {
|
||||
/**
|
||||
* @brief FFmpeg hardware frame pointer released with `av_frame_free`.
|
||||
*/
|
||||
using frame_t = util::safe_ptr<AVFrame, free_frame>;
|
||||
using frame_t = util::safe_ptr<AVFrame, &free_frame>;
|
||||
|
||||
namespace platf::dxgi {
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ namespace platf {
|
||||
/**
|
||||
* @brief ViGEm client pointer released with `vigem_free`.
|
||||
*/
|
||||
using client_t = util::safe_ptr<_VIGEM_CLIENT_T, vigem_free>;
|
||||
using client_t = util::safe_ptr<_VIGEM_CLIENT_T, &vigem_free>;
|
||||
/**
|
||||
* @brief ViGEm target pointer released with `vigem_target_free`.
|
||||
*/
|
||||
using target_t = util::safe_ptr<_VIGEM_TARGET_T, vigem_target_free>;
|
||||
using target_t = util::safe_ptr<_VIGEM_TARGET_T, &vigem_target_free>;
|
||||
|
||||
/**
|
||||
* @brief Handle Xbox 360 virtual gamepad notification events.
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace nvprefs {
|
||||
/**
|
||||
* @brief Owning Windows HANDLE wrapper that closes handles automatically.
|
||||
*/
|
||||
struct safe_handle: public util::safe_ptr_v2<void, BOOL, CloseHandle> {
|
||||
using util::safe_ptr_v2<void, BOOL, CloseHandle>::safe_ptr_v2;
|
||||
struct safe_handle: public util::safe_ptr_v2<void, BOOL, &CloseHandle> {
|
||||
using util::safe_ptr_v2<void, BOOL, &CloseHandle>::safe_ptr_v2;
|
||||
|
||||
/**
|
||||
* @brief Check whether the wrapped Windows handle is valid.
|
||||
@@ -54,7 +54,7 @@ namespace nvprefs {
|
||||
/**
|
||||
* @brief Safe pointer for Windows security identifiers released with `FreeSid`.
|
||||
*/
|
||||
using safe_sid = util::safe_ptr_v2<void, PVOID, FreeSid>;
|
||||
using safe_sid = util::safe_ptr_v2<void, PVOID, &FreeSid>;
|
||||
|
||||
/**
|
||||
* @brief Forward an informational NVPrefs message to the logger.
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ namespace proc {
|
||||
/**
|
||||
* @brief Boost.Process pipe stream used for child-process I/O.
|
||||
*/
|
||||
using file_t = util::safe_ptr_v2<FILE, int, fclose>;
|
||||
using file_t = util::safe_ptr_v2<FILE, int, &fclose>;
|
||||
|
||||
/**
|
||||
* @brief Parsed command arguments used when launching a child process.
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ namespace rtsp_stream {
|
||||
/**
|
||||
* @brief Owning pointer for an RTSP message allocated by moonlight-common-c.
|
||||
*/
|
||||
using msg_t = util::safe_ptr<RTSP_MESSAGE, free_msg>;
|
||||
using msg_t = util::safe_ptr<RTSP_MESSAGE, &free_msg>;
|
||||
/**
|
||||
* @brief RTSP command handler signature used by the server dispatch table.
|
||||
*/
|
||||
|
||||
+8
-8
@@ -99,21 +99,21 @@ namespace video {
|
||||
void free_buffer(AVBufferRef *ref);
|
||||
|
||||
/**
|
||||
* @brief Owning pointer for an FFmpeg codec context.
|
||||
* @brief Owning pointer for an FFmpeg codec context released with free_ctx().
|
||||
*/
|
||||
using avcodec_ctx_t = util::safe_ptr<AVCodecContext, free_ctx>;
|
||||
using avcodec_ctx_t = util::safe_ptr<AVCodecContext, &free_ctx>;
|
||||
/**
|
||||
* @brief Owning pointer for an FFmpeg frame.
|
||||
* @brief Owning pointer for an FFmpeg frame released with free_frame().
|
||||
*/
|
||||
using avcodec_frame_t = util::safe_ptr<AVFrame, free_frame>;
|
||||
using avcodec_frame_t = util::safe_ptr<AVFrame, &free_frame>;
|
||||
/**
|
||||
* @brief Owning pointer for an FFmpeg buffer reference.
|
||||
* @brief Owning pointer for an FFmpeg buffer reference released with free_buffer().
|
||||
*/
|
||||
using avcodec_buffer_t = util::safe_ptr<AVBufferRef, free_buffer>;
|
||||
using avcodec_buffer_t = util::safe_ptr<AVBufferRef, &free_buffer>;
|
||||
/**
|
||||
* @brief Owning pointer for an FFmpeg software-scaling context.
|
||||
* @brief Owning pointer for an FFmpeg software-scaling context released with sws_freeContext().
|
||||
*/
|
||||
using sws_t = util::safe_ptr<SwsContext, sws_freeContext>;
|
||||
using sws_t = util::safe_ptr<SwsContext, &sws_freeContext>;
|
||||
/**
|
||||
* @brief Shared event that transports captured images between capture and encode threads.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* @file tests/unit/test_resource_ownership.cpp
|
||||
* @brief Tests for resource lifetime through Sunshine's owning pointer aliases.
|
||||
*/
|
||||
|
||||
// test includes
|
||||
#include "../tests_common.h"
|
||||
|
||||
// standard includes
|
||||
#include <bit>
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
// platform includes
|
||||
#ifdef _WIN32
|
||||
// Winsock must precede Windows.h.
|
||||
// clang-format off
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
// clang-format on
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
// local includes
|
||||
#include <src/network.h>
|
||||
#include <src/process.h>
|
||||
#include <src/video.h>
|
||||
#ifdef _WIN32
|
||||
#include <src/platform/windows/nvprefs/nvprefs_common.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @brief Allocate an FFmpeg buffer that records its final release.
|
||||
*
|
||||
* @param releases Counter incremented when the buffer has no remaining references.
|
||||
* @param data Storage kept alive until the buffer is released.
|
||||
* @return Owning reference to the tracked buffer.
|
||||
*/
|
||||
video::avcodec_buffer_t tracked_buffer(int &releases, uint8_t &data) {
|
||||
return video::avcodec_buffer_t {av_buffer_create(&data, 1, [](auto *opaque, uint8_t *) {
|
||||
++*static_cast<int *>(opaque);
|
||||
},
|
||||
&releases,
|
||||
0)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* @brief Moving and resetting a frame releases its attached buffer exactly once.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, FrameMoveTransfersBufferOwnership) {
|
||||
int releases = 0;
|
||||
uint8_t data = 0;
|
||||
auto buffer = tracked_buffer(releases, data);
|
||||
ASSERT_TRUE(buffer);
|
||||
video::avcodec_frame_t frame {av_frame_alloc()};
|
||||
ASSERT_TRUE(frame);
|
||||
frame->buf[0] = buffer.release();
|
||||
|
||||
auto moved = std::move(frame);
|
||||
EXPECT_FALSE(frame);
|
||||
EXPECT_EQ(releases, 0);
|
||||
moved.reset();
|
||||
EXPECT_EQ(releases, 1);
|
||||
moved.reset();
|
||||
EXPECT_EQ(releases, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroying a codec context releases its hardware-frame context reference.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, CodecContextDestructionReleasesHardwareFramesReference) {
|
||||
int releases = 0;
|
||||
uint8_t data = 0;
|
||||
{
|
||||
auto buffer = tracked_buffer(releases, data);
|
||||
ASSERT_TRUE(buffer);
|
||||
video::avcodec_ctx_t context {avcodec_alloc_context3(nullptr)};
|
||||
ASSERT_TRUE(context);
|
||||
context->hw_frames_ctx = buffer.release();
|
||||
EXPECT_EQ(releases, 0);
|
||||
}
|
||||
EXPECT_EQ(releases, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief An FFmpeg buffer remains alive until its final owning reference is destroyed.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, BufferDestructionPreservesOtherReferences) {
|
||||
int releases = 0;
|
||||
uint8_t data = 0;
|
||||
{
|
||||
auto first = tracked_buffer(releases, data);
|
||||
ASSERT_TRUE(first);
|
||||
video::avcodec_buffer_t second {av_buffer_ref(first.get())};
|
||||
ASSERT_TRUE(second);
|
||||
first.reset();
|
||||
EXPECT_EQ(releases, 0);
|
||||
EXPECT_EQ(av_buffer_get_ref_count(second.get()), 1);
|
||||
}
|
||||
EXPECT_EQ(releases, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resetting a packet owner destroys each displaced ENet packet exactly once.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, PacketResetReleasesReplacedPacket) {
|
||||
int releases = 0;
|
||||
const auto make_packet = [&releases]() {
|
||||
net::packet_t packet {enet_packet_create(nullptr, 0, 0)};
|
||||
if (packet) {
|
||||
packet->userData = &releases;
|
||||
packet->freeCallback = [](ENetPacket *released) {
|
||||
++*static_cast<int *>(released->userData);
|
||||
};
|
||||
}
|
||||
return packet;
|
||||
};
|
||||
|
||||
{
|
||||
auto packet = make_packet();
|
||||
auto replacement = make_packet();
|
||||
ASSERT_TRUE(packet);
|
||||
ASSERT_TRUE(replacement);
|
||||
packet.reset(replacement.release());
|
||||
EXPECT_EQ(releases, 1);
|
||||
}
|
||||
EXPECT_EQ(releases, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resetting a file owner closes a securely created temporary file's underlying resource.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, FileResetClosesUnderlyingDescriptor) {
|
||||
#ifdef _WIN32
|
||||
FILE *temporary_file = nullptr;
|
||||
ASSERT_EQ(tmpfile_s(&temporary_file), 0);
|
||||
proc::file_t file {temporary_file};
|
||||
#else
|
||||
proc::file_t file {std::tmpfile()};
|
||||
#endif
|
||||
ASSERT_TRUE(file);
|
||||
#ifdef _WIN32
|
||||
const auto handle = std::bit_cast<HANDLE>(_get_osfhandle(_fileno(file.get())));
|
||||
ASSERT_NE(handle, INVALID_HANDLE_VALUE);
|
||||
file.reset();
|
||||
DWORD flags = 0;
|
||||
EXPECT_FALSE(GetHandleInformation(handle, &flags));
|
||||
EXPECT_EQ(GetLastError(), ERROR_INVALID_HANDLE);
|
||||
#else
|
||||
const auto descriptor = fileno(file.get());
|
||||
ASSERT_GE(descriptor, 0);
|
||||
file.reset();
|
||||
errno = 0;
|
||||
EXPECT_EQ(fcntl(descriptor, F_GETFD), -1);
|
||||
EXPECT_EQ(errno, EBADF);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/**
|
||||
* @brief Moving an NVPrefs handle transfers responsibility for closing it.
|
||||
*/
|
||||
TEST(ResourceOwnershipTest, WindowsHandleMoveClosesHandleOnDestruction) {
|
||||
HANDLE raw_handle = nullptr;
|
||||
{
|
||||
nvprefs::safe_handle handle {CreateEventW(nullptr, TRUE, FALSE, nullptr)};
|
||||
ASSERT_TRUE(handle);
|
||||
raw_handle = handle.get();
|
||||
auto moved = std::move(handle);
|
||||
EXPECT_FALSE(handle);
|
||||
EXPECT_TRUE(moved);
|
||||
EXPECT_EQ(WaitForSingleObject(raw_handle, 0), WAIT_TIMEOUT);
|
||||
}
|
||||
DWORD flags = 0;
|
||||
EXPECT_FALSE(GetHandleInformation(raw_handle, &flags));
|
||||
EXPECT_EQ(GetLastError(), ERROR_INVALID_HANDLE);
|
||||
}
|
||||
#endif
|
||||
+9
-9
@@ -35,17 +35,17 @@ namespace audio {
|
||||
CoTaskMemFree(static_cast<LPVOID>(p));
|
||||
}
|
||||
|
||||
using device_enum_t = util::safe_ptr<IMMDeviceEnumerator, Release<IMMDeviceEnumerator>>;
|
||||
using collection_t = util::safe_ptr<IMMDeviceCollection, Release<IMMDeviceCollection>>;
|
||||
using prop_t = util::safe_ptr<IPropertyStore, Release<IPropertyStore>>;
|
||||
using device_t = util::safe_ptr<IMMDevice, Release<IMMDevice>>;
|
||||
using audio_client_t = util::safe_ptr<IAudioClient, Release<IAudioClient>>;
|
||||
using audio_capture_t = util::safe_ptr<IAudioCaptureClient, Release<IAudioCaptureClient>>;
|
||||
using wave_format_t = util::safe_ptr<WAVEFORMATEX, co_task_free<WAVEFORMATEX>>;
|
||||
using device_enum_t = util::safe_ptr<IMMDeviceEnumerator, &Release<IMMDeviceEnumerator>>;
|
||||
using collection_t = util::safe_ptr<IMMDeviceCollection, &Release<IMMDeviceCollection>>;
|
||||
using prop_t = util::safe_ptr<IPropertyStore, &Release<IPropertyStore>>;
|
||||
using device_t = util::safe_ptr<IMMDevice, &Release<IMMDevice>>;
|
||||
using audio_client_t = util::safe_ptr<IAudioClient, &Release<IAudioClient>>;
|
||||
using audio_capture_t = util::safe_ptr<IAudioCaptureClient, &Release<IAudioCaptureClient>>;
|
||||
using wave_format_t = util::safe_ptr<WAVEFORMATEX, &co_task_free<WAVEFORMATEX>>;
|
||||
|
||||
using wstring_t = util::safe_ptr<WCHAR, co_task_free<WCHAR>>;
|
||||
using wstring_t = util::safe_ptr<WCHAR, &co_task_free<WCHAR>>;
|
||||
|
||||
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
||||
using handle_t = util::safe_ptr_v2<void, BOOL, &CloseHandle>;
|
||||
|
||||
class prop_var_t {
|
||||
public:
|
||||
|
||||
+3
-3
@@ -19,9 +19,9 @@ namespace dxgi {
|
||||
dxgi->Release();
|
||||
}
|
||||
|
||||
using factory1_t = util::safe_ptr<IDXGIFactory1, Release<IDXGIFactory1>>;
|
||||
using adapter_t = util::safe_ptr<IDXGIAdapter1, Release<IDXGIAdapter1>>;
|
||||
using output_t = util::safe_ptr<IDXGIOutput, Release<IDXGIOutput>>;
|
||||
using factory1_t = util::safe_ptr<IDXGIFactory1, &Release<IDXGIFactory1>>;
|
||||
using adapter_t = util::safe_ptr<IDXGIAdapter1, &Release<IDXGIAdapter1>>;
|
||||
using output_t = util::safe_ptr<IDXGIOutput, &Release<IDXGIOutput>>;
|
||||
} // namespace dxgi
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
Reference in new issue
Block a user