The PS4 is ignoring the volume values in the report, so we don't need to fill them in.
authorSam Lantinga <slouken@libsdl.org>
Thu, 19 Sep 2019 16:50:49 -0700
changeset 13078ae4f9911321a
parent 13074 2ede888544ac
child 13079 82de37dd809d
The PS4 is ignoring the volume values in the report, so we don't need to fill them in.
src/joystick/hidapi/SDL_hidapi_ps4.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Wed Sep 11 15:08:37 2019 -0700
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Thu Sep 19 16:50:49 2019 -0700
     1.3 @@ -140,83 +140,6 @@
     1.4      return crc;
     1.5  }
     1.6  
     1.7 -#if defined(__WIN32__) && defined(HAVE_ENDPOINTVOLUME_H)
     1.8 -#include "../../core/windows/SDL_windows.h"
     1.9 -
    1.10 -#ifndef NTDDI_VISTA
    1.11 -#define NTDDI_VISTA    0x06000000
    1.12 -#endif
    1.13 -#ifndef _WIN32_WINNT_VISTA
    1.14 -#define _WIN32_WINNT_VISTA 0x0600
    1.15 -#endif
    1.16 -
    1.17 -/* Define Vista for the Audio related includes below to work */
    1.18 -#undef NTDDI_VERSION
    1.19 -#define NTDDI_VERSION NTDDI_VISTA
    1.20 -#undef _WIN32_WINNT
    1.21 -#define _WIN32_WINNT _WIN32_WINNT_VISTA
    1.22 -#define COBJMACROS
    1.23 -#include <mmdeviceapi.h>
    1.24 -#include <audioclient.h>
    1.25 -#include <endpointvolume.h>
    1.26 -
    1.27 -#undef DEFINE_GUID
    1.28 -#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
    1.29 -DEFINE_GUID(SDL_CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E);
    1.30 -DEFINE_GUID(SDL_IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6);
    1.31 -DEFINE_GUID(SDL_IID_IAudioEndpointVolume, 0x5CDF2C82, 0x841E, 0x4546, 0x97, 0x22, 0x0C, 0xF7, 0x40, 0x78, 0x22, 0x9A);
    1.32 -#endif
    1.33 -
    1.34 -
    1.35 -
    1.36 -static float GetSystemVolume(void)
    1.37 -{
    1.38 -    float volume = -1.0f;    /* Return this if we can't get system volume */
    1.39 -
    1.40 -#if defined(__WIN32__) && defined(HAVE_ENDPOINTVOLUME_H)
    1.41 -    HRESULT hr = WIN_CoInitialize();
    1.42 -    if (SUCCEEDED(hr)) {
    1.43 -        IMMDeviceEnumerator *pEnumerator;
    1.44 -
    1.45 -        /* This should gracefully fail on XP and succeed on everything Vista and above */
    1.46 -        hr = CoCreateInstance(&SDL_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &SDL_IID_IMMDeviceEnumerator, (LPVOID*)&pEnumerator);
    1.47 -        if (SUCCEEDED(hr)) {
    1.48 -            IMMDevice *pDevice;
    1.49 -
    1.50 -            hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(pEnumerator, eRender, eConsole, &pDevice);
    1.51 -            if (SUCCEEDED(hr)) {
    1.52 -                IAudioEndpointVolume *pEndpointVolume;
    1.53 -
    1.54 -                hr = IMMDevice_Activate(pDevice, &SDL_IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (LPVOID*)&pEndpointVolume);
    1.55 -                if (SUCCEEDED(hr)) {
    1.56 -                    IAudioEndpointVolume_GetMasterVolumeLevelScalar(pEndpointVolume, &volume);
    1.57 -                    IUnknown_Release(pEndpointVolume);
    1.58 -                }
    1.59 -                IUnknown_Release(pDevice);
    1.60 -            }
    1.61 -            IUnknown_Release(pEnumerator);
    1.62 -        }
    1.63 -        WIN_CoUninitialize();
    1.64 -    }
    1.65 -#endif /* __WIN32__ */
    1.66 -
    1.67 -    return volume;
    1.68 -}
    1.69 -
    1.70 -static uint8_t GetPlaystationVolumeFromFloat(float fVolume)
    1.71 -{
    1.72 -    const int k_nVolumeFitRatio = 15;
    1.73 -    const int k_nVolumeFitOffset = 9;
    1.74 -    float fVolLog;
    1.75 -
    1.76 -    if (fVolume > 1.0f || fVolume < 0.0f) {
    1.77 -        fVolume = 0.30f;
    1.78 -    }
    1.79 -    fVolLog = SDL_logf(fVolume * 100);
    1.80 -
    1.81 -    return (Uint8)((fVolLog * k_nVolumeFitRatio) + k_nVolumeFitOffset);
    1.82 -}
    1.83 -
    1.84  static SDL_bool
    1.85  HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
    1.86  {
    1.87 @@ -363,20 +286,6 @@
    1.88      effects->ucLedGreen = 0;
    1.89      effects->ucLedBlue = 80;
    1.90  
    1.91 -    if (ctx->audio_supported) {
    1.92 -        Uint32 now = SDL_GetTicks();
    1.93 -        if (!ctx->last_volume_check ||
    1.94 -            SDL_TICKS_PASSED(now, ctx->last_volume_check + VOLUME_CHECK_INTERVAL_MS)) {
    1.95 -            ctx->volume = GetPlaystationVolumeFromFloat(GetSystemVolume());
    1.96 -            ctx->last_volume_check = now;
    1.97 -        }
    1.98 -
    1.99 -        effects->ucVolumeRight = ctx->volume;
   1.100 -        effects->ucVolumeLeft = ctx->volume;
   1.101 -        effects->ucVolumeSpeaker = ctx->volume;
   1.102 -        effects->ucVolumeMic = 0xFF;
   1.103 -    }
   1.104 -
   1.105      if (ctx->is_bluetooth) {
   1.106          /* Bluetooth reports need a CRC at the end of the packet (at least on Linux) */
   1.107          Uint8 ubHdr = 0xA2; /* hidp header is part of the CRC calculation */