wasapi: Replace tabs with strings in source code.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 18 May 2017 15:46:06 -0400
changeset 1101096de7fe65e32
parent 11009 cca512965b67
child 11011 d3ac11b79213
wasapi: Replace tabs with strings in source code.
src/audio/wasapi/SDL_wasapi.c
     1.1 --- a/src/audio/wasapi/SDL_wasapi.c	Thu May 18 15:43:51 2017 -0400
     1.2 +++ b/src/audio/wasapi/SDL_wasapi.c	Thu May 18 15:46:06 2017 -0400
     1.3 @@ -49,8 +49,8 @@
     1.4  /* This is a list of device id strings we have inflight, so we have consistent pointers to the same device. */
     1.5  typedef struct DevIdList
     1.6  {
     1.7 -	WCHAR *str;
     1.8 -	struct DevIdList *next;
     1.9 +    WCHAR *str;
    1.10 +    struct DevIdList *next;
    1.11  } DevIdList;
    1.12  
    1.13  static DevIdList *deviceid_list = NULL;
    1.14 @@ -113,7 +113,7 @@
    1.15  static ULONG STDMETHODCALLTYPE
    1.16  SDLMMNotificationClient_AddRef(IMMNotificationClient *ithis)
    1.17  {
    1.18 -	SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
    1.19 +    SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
    1.20      return (ULONG) (SDL_AtomicIncRef(&this->refcount) + 1);
    1.21  }
    1.22  
    1.23 @@ -121,7 +121,7 @@
    1.24  SDLMMNotificationClient_Release(IMMNotificationClient *ithis)
    1.25  {
    1.26      /* this is a static object; we don't ever free it. */
    1.27 -	SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
    1.28 +    SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
    1.29      const ULONG retval = SDL_AtomicDecRef(&this->refcount);
    1.30      if (retval == 0) {
    1.31          SDL_AtomicSet(&this->refcount, 0);  /* uhh... */
    1.32 @@ -134,21 +134,21 @@
    1.33  static HRESULT STDMETHODCALLTYPE
    1.34  SDLMMNotificationClient_OnDefaultDeviceChanged(IMMNotificationClient *ithis, EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId)
    1.35  {
    1.36 -	if (role != SDL_WASAPI_role) {
    1.37 -		return S_OK;  /* ignore it. */
    1.38 -	}
    1.39 +    if (role != SDL_WASAPI_role) {
    1.40 +        return S_OK;  /* ignore it. */
    1.41 +    }
    1.42  
    1.43      /* Increment the "generation," so opened devices will pick this up in their threads. */
    1.44 -	switch (flow) {
    1.45 -    	case eRender:
    1.46 +    switch (flow) {
    1.47 +        case eRender:
    1.48              SDL_AtomicAdd(&default_playback_generation, 1);
    1.49              break;
    1.50  
    1.51 -	    case eCapture:
    1.52 +        case eCapture:
    1.53              SDL_AtomicAdd(&default_capture_generation, 1);
    1.54              break;
    1.55  
    1.56 -    	case eAll:
    1.57 +        case eAll:
    1.58              SDL_AtomicAdd(&default_playback_generation, 1);
    1.59              SDL_AtomicAdd(&default_capture_generation, 1);
    1.60              break;
    1.61 @@ -156,53 +156,53 @@
    1.62          default:
    1.63              SDL_assert(!"uhoh, unexpected OnDefaultDeviceChange flow!");
    1.64              break;
    1.65 -	}
    1.66 +    }
    1.67  
    1.68 -	return S_OK;
    1.69 +    return S_OK;
    1.70  }
    1.71  
    1.72  static HRESULT STDMETHODCALLTYPE
    1.73  SDLMMNotificationClient_OnDeviceAdded(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId)
    1.74  {
    1.75 -	/* we ignore this; devices added here then progress to ACTIVE, if appropriate, in 
    1.76 -	   OnDeviceStateChange, making that a better place to deal with device adds. More 
    1.77 -	   importantly: the first time you plug in a USB audio device, this callback will 
    1.78 -	   fire, but when you unplug it, it isn't removed (it's state changes to NOTPRESENT).
    1.79 -	   Plugging it back in won't fire this callback again. */
    1.80 -	return S_OK;
    1.81 +    /* we ignore this; devices added here then progress to ACTIVE, if appropriate, in 
    1.82 +       OnDeviceStateChange, making that a better place to deal with device adds. More 
    1.83 +       importantly: the first time you plug in a USB audio device, this callback will 
    1.84 +       fire, but when you unplug it, it isn't removed (it's state changes to NOTPRESENT).
    1.85 +       Plugging it back in won't fire this callback again. */
    1.86 +    return S_OK;
    1.87  }
    1.88  
    1.89  static HRESULT STDMETHODCALLTYPE
    1.90  SDLMMNotificationClient_OnDeviceRemoved(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId)
    1.91  {
    1.92 -	/* See notes in OnDeviceAdded handler about why we ignore this. */
    1.93 -	return S_OK;
    1.94 +    /* See notes in OnDeviceAdded handler about why we ignore this. */
    1.95 +    return S_OK;
    1.96  }
    1.97  
    1.98  static HRESULT STDMETHODCALLTYPE
    1.99  SDLMMNotificationClient_OnDeviceStateChanged(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId, DWORD dwNewState)
   1.100  {
   1.101 -	SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
   1.102 -	IMMDevice *device = NULL;
   1.103 +    SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
   1.104 +    IMMDevice *device = NULL;
   1.105  
   1.106 -	if (SUCCEEDED(IMMDeviceEnumerator_GetDevice(enumerator, pwstrDeviceId, &device))) {
   1.107 -		IMMEndpoint *endpoint = NULL;
   1.108 -		if (SUCCEEDED(IMMDevice_QueryInterface(device, &SDL_IID_IMMEndpoint, (void **) &endpoint))) {
   1.109 -			EDataFlow flow;
   1.110 -			if (SUCCEEDED(IMMEndpoint_GetDataFlow(endpoint, &flow))) {
   1.111 -				const SDL_bool iscapture = (flow == eCapture);
   1.112 -				if (dwNewState == DEVICE_STATE_ACTIVE) {
   1.113 -					AddWASAPIDevice(iscapture, device, pwstrDeviceId);
   1.114 -				} else {
   1.115 -					RemoveWASAPIDevice(iscapture, pwstrDeviceId);
   1.116 -				}
   1.117 -			}
   1.118 -			IMMEndpoint_Release(endpoint);
   1.119 -		}
   1.120 -		IMMDevice_Release(device);
   1.121 -	}
   1.122 +    if (SUCCEEDED(IMMDeviceEnumerator_GetDevice(enumerator, pwstrDeviceId, &device))) {
   1.123 +        IMMEndpoint *endpoint = NULL;
   1.124 +        if (SUCCEEDED(IMMDevice_QueryInterface(device, &SDL_IID_IMMEndpoint, (void **) &endpoint))) {
   1.125 +            EDataFlow flow;
   1.126 +            if (SUCCEEDED(IMMEndpoint_GetDataFlow(endpoint, &flow))) {
   1.127 +                const SDL_bool iscapture = (flow == eCapture);
   1.128 +                if (dwNewState == DEVICE_STATE_ACTIVE) {
   1.129 +                    AddWASAPIDevice(iscapture, device, pwstrDeviceId);
   1.130 +                } else {
   1.131 +                    RemoveWASAPIDevice(iscapture, pwstrDeviceId);
   1.132 +                }
   1.133 +            }
   1.134 +            IMMEndpoint_Release(endpoint);
   1.135 +        }
   1.136 +        IMMDevice_Release(device);
   1.137 +    }
   1.138  
   1.139 -	return S_OK;
   1.140 +    return S_OK;
   1.141  }
   1.142  
   1.143  static HRESULT STDMETHODCALLTYPE
   1.144 @@ -227,58 +227,58 @@
   1.145  static SDL_bool
   1.146  WStrEqual(const WCHAR *a, const WCHAR *b)
   1.147  {
   1.148 -	while (*a) {
   1.149 -		if (*a != *b) {
   1.150 -			return SDL_FALSE;
   1.151 -		}
   1.152 -		a++;
   1.153 -		b++;
   1.154 -	}
   1.155 -	return *b == 0;
   1.156 +    while (*a) {
   1.157 +        if (*a != *b) {
   1.158 +            return SDL_FALSE;
   1.159 +        }
   1.160 +        a++;
   1.161 +        b++;
   1.162 +    }
   1.163 +    return *b == 0;
   1.164  }
   1.165  
   1.166  static WCHAR *
   1.167  WStrDupe(const WCHAR *wstr)
   1.168  {
   1.169 -	const int len = (lstrlenW(wstr) + 1) * sizeof (WCHAR);
   1.170 -	WCHAR *retval = (WCHAR *) SDL_malloc(len);
   1.171 -	if (retval) {
   1.172 -		SDL_memcpy(retval, wstr, len);
   1.173 -	}
   1.174 -	return retval;
   1.175 +    const int len = (lstrlenW(wstr) + 1) * sizeof (WCHAR);
   1.176 +    WCHAR *retval = (WCHAR *) SDL_malloc(len);
   1.177 +    if (retval) {
   1.178 +        SDL_memcpy(retval, wstr, len);
   1.179 +    }
   1.180 +    return retval;
   1.181  }
   1.182  
   1.183  static void 
   1.184  RemoveWASAPIDevice(const SDL_bool iscapture, LPCWSTR devid)
   1.185  {
   1.186 -	DevIdList *i;
   1.187 -	DevIdList *next;
   1.188 -	DevIdList *prev = NULL;
   1.189 -	for (i = deviceid_list; i; i = next) {
   1.190 -		next = i->next;
   1.191 -		if (WStrEqual(i->str, devid)) {
   1.192 -			if (prev) {
   1.193 -				prev->next = next;
   1.194 -			} else {
   1.195 -				deviceid_list = next;
   1.196 -			}
   1.197 -			SDL_RemoveAudioDevice(iscapture, i->str);
   1.198 -			SDL_free(i->str);
   1.199 -			SDL_free(i);
   1.200 -		}
   1.201 -		prev = i;
   1.202 -	}
   1.203 +    DevIdList *i;
   1.204 +    DevIdList *next;
   1.205 +    DevIdList *prev = NULL;
   1.206 +    for (i = deviceid_list; i; i = next) {
   1.207 +        next = i->next;
   1.208 +        if (WStrEqual(i->str, devid)) {
   1.209 +            if (prev) {
   1.210 +                prev->next = next;
   1.211 +            } else {
   1.212 +                deviceid_list = next;
   1.213 +            }
   1.214 +            SDL_RemoveAudioDevice(iscapture, i->str);
   1.215 +            SDL_free(i->str);
   1.216 +            SDL_free(i);
   1.217 +        }
   1.218 +        prev = i;
   1.219 +    }
   1.220  }
   1.221  
   1.222  static void
   1.223  AddWASAPIDevice(const SDL_bool iscapture, IMMDevice *device, LPCWSTR devid)
   1.224  {
   1.225 -	IPropertyStore *props = NULL;
   1.226 +    IPropertyStore *props = NULL;
   1.227      char *utf8dev = NULL;
   1.228 -	DevIdList *devidlist;
   1.229 +    DevIdList *devidlist;
   1.230      PROPVARIANT var;
   1.231  
   1.232 -	/* You can have multiple endpoints on a device that are mutually exclusive ("Speakers" vs "Line Out" or whatever).
   1.233 +    /* You can have multiple endpoints on a device that are mutually exclusive ("Speakers" vs "Line Out" or whatever).
   1.234         In a perfect world, things that are unplugged won't be in this collection. The only gotcha is probably for
   1.235         phones and tablets, where you might have an internal speaker and a headphone jack and expect both to be
   1.236         available and switch automatically. (!!! FIXME...?) */
   1.237 @@ -287,40 +287,40 @@
   1.238         "SoundBlaster Pro (Speakers)" but I guess that's developers vs users. Windows uses the FriendlyName in
   1.239         its own UIs, like Volume Control, etc. */
   1.240  
   1.241 -	/* see if we already have this one. */
   1.242 -	for (devidlist = deviceid_list; devidlist; devidlist = devidlist->next) {
   1.243 -		if (WStrEqual(devidlist->str, devid)) {
   1.244 -			return;  /* we already have this. */
   1.245 -		}
   1.246 -	}
   1.247 +    /* see if we already have this one. */
   1.248 +    for (devidlist = deviceid_list; devidlist; devidlist = devidlist->next) {
   1.249 +        if (WStrEqual(devidlist->str, devid)) {
   1.250 +            return;  /* we already have this. */
   1.251 +        }
   1.252 +    }
   1.253  
   1.254 -	devidlist = (DevIdList *) SDL_malloc(sizeof (*devidlist));
   1.255 -	if (!devidlist) {
   1.256 -		return;  /* oh well. */
   1.257 -	}
   1.258 +    devidlist = (DevIdList *) SDL_malloc(sizeof (*devidlist));
   1.259 +    if (!devidlist) {
   1.260 +        return;  /* oh well. */
   1.261 +    }
   1.262  
   1.263 -	devid = WStrDupe(devid);
   1.264 -	if (!devid) {
   1.265 -		SDL_free(devidlist);
   1.266 -		return;  /* oh well. */
   1.267 -	}
   1.268 +    devid = WStrDupe(devid);
   1.269 +    if (!devid) {
   1.270 +        SDL_free(devidlist);
   1.271 +        return;  /* oh well. */
   1.272 +    }
   1.273  
   1.274 -	devidlist->str = (WCHAR *) devid;
   1.275 -	devidlist->next = deviceid_list;
   1.276 -	deviceid_list = devidlist;
   1.277 +    devidlist->str = (WCHAR *) devid;
   1.278 +    devidlist->next = deviceid_list;
   1.279 +    deviceid_list = devidlist;
   1.280  
   1.281      if (SUCCEEDED(IMMDevice_OpenPropertyStore(device, STGM_READ, &props))) {
   1.282 -	    PropVariantInit(&var);
   1.283 -	    if (SUCCEEDED(IPropertyStore_GetValue(props, &SDL_PKEY_Device_FriendlyName, &var))) {
   1.284 -			utf8dev = WIN_StringToUTF8(var.pwszVal);
   1.285 -			if (utf8dev) {
   1.286 -				SDL_AddAudioDevice(iscapture, utf8dev, (void *) devid);
   1.287 -		        SDL_free(utf8dev);
   1.288 -			}
   1.289 -		}
   1.290 -	    PropVariantClear(&var);
   1.291 -	    IPropertyStore_Release(props);
   1.292 -	}
   1.293 +        PropVariantInit(&var);
   1.294 +        if (SUCCEEDED(IPropertyStore_GetValue(props, &SDL_PKEY_Device_FriendlyName, &var))) {
   1.295 +            utf8dev = WIN_StringToUTF8(var.pwszVal);
   1.296 +            if (utf8dev) {
   1.297 +                SDL_AddAudioDevice(iscapture, utf8dev, (void *) devid);
   1.298 +                SDL_free(utf8dev);
   1.299 +            }
   1.300 +        }
   1.301 +        PropVariantClear(&var);
   1.302 +        IPropertyStore_Release(props);
   1.303 +    }
   1.304  }
   1.305  
   1.306  static void
   1.307 @@ -344,14 +344,14 @@
   1.308      for (i = 0; i < total; i++) {
   1.309          IMMDevice *device = NULL;
   1.310          if (SUCCEEDED(IMMDeviceCollection_Item(collection, i, &device))) {
   1.311 -			LPWSTR devid = NULL;
   1.312 -			if (SUCCEEDED(IMMDevice_GetId(device, &devid))) {
   1.313 -				AddWASAPIDevice(iscapture, device, devid);
   1.314 -				CoTaskMemFree(devid);
   1.315 -			}
   1.316 -	        IMMDevice_Release(device);
   1.317 -		}
   1.318 -	}
   1.319 +            LPWSTR devid = NULL;
   1.320 +            if (SUCCEEDED(IMMDevice_GetId(device, &devid))) {
   1.321 +                AddWASAPIDevice(iscapture, device, devid);
   1.322 +                CoTaskMemFree(devid);
   1.323 +            }
   1.324 +            IMMDevice_Release(device);
   1.325 +        }
   1.326 +    }
   1.327  
   1.328      IMMDeviceCollection_Release(collection);
   1.329  }
   1.330 @@ -389,8 +389,8 @@
   1.331      if (err == AUDCLNT_E_DEVICE_INVALIDATED) {
   1.332          this->hidden->device_lost = SDL_TRUE;
   1.333      } else if (SDL_AtomicGet(&this->enabled)) {
   1.334 -    	IAudioClient_Stop(this->hidden->client);
   1.335 -	    SDL_OpenedAudioDeviceDisconnected(this);
   1.336 +        IAudioClient_Stop(this->hidden->client);
   1.337 +        SDL_OpenedAudioDeviceDisconnected(this);
   1.338          SDL_assert(!SDL_AtomicGet(&this->enabled));
   1.339      }
   1.340  
   1.341 @@ -531,18 +531,18 @@
   1.342  static void
   1.343  WASAPI_WaitDevice(_THIS)
   1.344  {
   1.345 -	const UINT32 maxpadding = this->spec.samples;
   1.346 +    const UINT32 maxpadding = this->spec.samples;
   1.347      while (RecoverWasapiIfLost(this)) {
   1.348 -		UINT32 padding = 0;
   1.349 +        UINT32 padding = 0;
   1.350  
   1.351          if (!WasapiFailed(this, IAudioClient_GetCurrentPadding(this->hidden->client, &padding))) {
   1.352              if (padding <= maxpadding) {
   1.353 -	            break;
   1.354 +                break;
   1.355              }
   1.356 -		    /* Sleep long enough for half the buffer to be free. */
   1.357 -    		SDL_Delay(((padding - maxpadding) * 1000) / this->spec.freq);
   1.358 +            /* Sleep long enough for half the buffer to be free. */
   1.359 +            SDL_Delay(((padding - maxpadding) * 1000) / this->spec.freq);
   1.360          }
   1.361 -	}
   1.362 +    }
   1.363  }
   1.364  
   1.365  static int
   1.366 @@ -626,7 +626,7 @@
   1.367  static void
   1.368  ReleaseWasapiDevice(_THIS)
   1.369  {
   1.370 -	if (this->hidden->client) {
   1.371 +    if (this->hidden->client) {
   1.372          IAudioClient_Stop(this->hidden->client);
   1.373          this->hidden->client = NULL;
   1.374      }
   1.375 @@ -757,15 +757,15 @@
   1.376          return WIN_SetErrorFromHRESULT("WASAPI can't initialize audio client", ret);
   1.377      }
   1.378  
   1.379 -	ret = IAudioClient_GetBufferSize(client, &bufsize);
   1.380 +    ret = IAudioClient_GetBufferSize(client, &bufsize);
   1.381      if (FAILED(ret)) {
   1.382          return WIN_SetErrorFromHRESULT("WASAPI can't determine buffer size", ret);
   1.383      }
   1.384  
   1.385      this->spec.samples = (Uint16) bufsize;
   1.386 -	if (!iscapture) {
   1.387 -		this->spec.samples /= 2;  /* fill half of the DMA buffer on each run. */
   1.388 -	}
   1.389 +    if (!iscapture) {
   1.390 +        this->spec.samples /= 2;  /* fill half of the DMA buffer on each run. */
   1.391 +    }
   1.392  
   1.393      /* Update the fragment size as size in bytes */
   1.394      SDL_CalculateAudioSpec(&this->spec);
   1.395 @@ -827,7 +827,7 @@
   1.396          const EDataFlow dataflow = iscapture ? eCapture : eRender;
   1.397          this->hidden->default_device_generation = SDL_AtomicGet(iscapture ? &default_capture_generation : &default_playback_generation);
   1.398          ret = IMMDeviceEnumerator_GetDefaultAudioEndpoint(enumerator, dataflow, SDL_WASAPI_role, &device);
   1.399 -	} else {
   1.400 +    } else {
   1.401          ret = IMMDeviceEnumerator_GetDevice(enumerator, (LPCWSTR) handle, &device);
   1.402      }
   1.403  
   1.404 @@ -871,8 +871,8 @@
   1.405  static void
   1.406  WASAPI_Deinitialize(void)
   1.407  {
   1.408 -	DevIdList *devidlist;
   1.409 -	DevIdList *next;
   1.410 +    DevIdList *devidlist;
   1.411 +    DevIdList *next;
   1.412  
   1.413      if (enumerator) {
   1.414          IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(enumerator, (IMMNotificationClient *) &notification_client);
   1.415 @@ -890,12 +890,12 @@
   1.416      pAvSetMmThreadCharacteristicsW = NULL;
   1.417      pAvRevertMmThreadCharacteristics = NULL;
   1.418  
   1.419 -	for (devidlist = deviceid_list; devidlist; devidlist = next) {
   1.420 -		next = devidlist->next;
   1.421 -		SDL_free(devidlist->str);
   1.422 -		SDL_free(devidlist);
   1.423 -	}
   1.424 -	deviceid_list = NULL;
   1.425 +    for (devidlist = deviceid_list; devidlist; devidlist = next) {
   1.426 +        next = devidlist->next;
   1.427 +        SDL_free(devidlist->str);
   1.428 +        SDL_free(devidlist);
   1.429 +    }
   1.430 +    deviceid_list = NULL;
   1.431  
   1.432      WIN_CoUninitialize();
   1.433  }
   1.434 @@ -903,22 +903,22 @@
   1.435  static int
   1.436  WASAPI_Init(SDL_AudioDriverImpl * impl)
   1.437  {
   1.438 -	HRESULT ret;
   1.439 +    HRESULT ret;
   1.440  
   1.441 -	/* just skip the discussion with COM here. */
   1.442 -	if (!WIN_IsWindowsVistaOrGreater()) {
   1.443 -		return SDL_SetError("WASAPI support requires Windows Vista or later");
   1.444 -	}
   1.445 +    /* just skip the discussion with COM here. */
   1.446 +    if (!WIN_IsWindowsVistaOrGreater()) {
   1.447 +        return SDL_SetError("WASAPI support requires Windows Vista or later");
   1.448 +    }
   1.449  
   1.450      SDL_AtomicSet(&default_playback_generation, 1);
   1.451      SDL_AtomicSet(&default_capture_generation, 1);
   1.452  
   1.453 -	if (FAILED(WIN_CoInitialize())) {
   1.454 +    if (FAILED(WIN_CoInitialize())) {
   1.455          SDL_SetError("WASAPI: CoInitialize() failed");
   1.456          return 0;
   1.457      }
   1.458  
   1.459 -	ret = CoCreateInstance(&SDL_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_IMMDeviceEnumerator, (LPVOID) &enumerator);
   1.460 +    ret = CoCreateInstance(&SDL_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_IMMDeviceEnumerator, (LPVOID) &enumerator);
   1.461      if (FAILED(ret)) {
   1.462          WIN_CoUninitialize();
   1.463          WIN_SetErrorFromHRESULT("WASAPI CoCreateInstance(MMDeviceEnumerator)", ret);