Enable SDL audio capture for SDL 2.0.5 and newer

The version check is required for supporting macOS PPC with SDL 2.0.1
and Travis-CI (Ubuntu Trusty) with SDL 2.0.2.

The client now requires SDL 2.0.5 runtime if compiled against SDL 2.0.5
or newer.
This commit is contained in:
Zack Middleton 2018-04-24 14:05:58 -05:00
parent 45af2594a0
commit 92935df37b
2 changed files with 27 additions and 11 deletions

View File

@ -47,11 +47,11 @@ static int dmasize = 0;
static SDL_AudioDeviceID sdlPlaybackDevice;
#ifdef USE_VOIP
#if defined USE_VOIP && SDL_VERSION_ATLEAST( 2, 0, 5 )
#define USE_SDL_AUDIO_CAPTURE
static SDL_AudioDeviceID sdlCaptureDevice;
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
static cvar_t *s_sdlCapture;
#endif
static float sdlMasterGain = 1.0f;
#endif
@ -96,7 +96,7 @@ static void SNDDMA_AudioCallback(void *userdata, Uint8 *stream, int len)
if (dmapos >= dmasize)
dmapos = 0;
#ifdef USE_VOIP
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlMasterGain != 1.0f)
{
int i;
@ -283,8 +283,7 @@ qboolean SNDDMA_Init(void)
dmasize = (dma.samples * (dma.samplebits/8));
dma.buffer = calloc(1, dmasize);
#ifdef USE_VOIP
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// !!! FIXME: some of these SDL_OpenAudioDevice() values should be cvars.
s_sdlCapture = Cvar_Get( "s_sdlCapture", "1", CVAR_ARCHIVE | CVAR_LATCH );
if (!s_sdlCapture->integer)
@ -310,10 +309,9 @@ qboolean SNDDMA_Init(void)
Com_Printf( "SDL capture device %s.\n",
(sdlCaptureDevice == 0) ? "failed to open" : "opened");
}
#endif
#endif
sdlMasterGain = 1.0f;
#endif
Com_Printf("Starting SDL audio callback...\n");
SDL_PauseAudioDevice(sdlPlaybackDevice, 0); // start callback.
@ -349,6 +347,7 @@ void SNDDMA_Shutdown(void)
sdlPlaybackDevice = 0;
}
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
Com_Printf("Closing SDL audio capture device...\n");
@ -356,6 +355,7 @@ void SNDDMA_Shutdown(void)
Com_Printf("SDL audio capture device closed.\n");
sdlCaptureDevice = 0;
}
#endif
SDL_QuitSubSystem(SDL_INIT_AUDIO);
free(dma.buffer);
@ -391,7 +391,7 @@ void SNDDMA_BeginPainting (void)
#ifdef USE_VOIP
void SNDDMA_StartCapture(void)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
SDL_ClearQueuedAudio(sdlCaptureDevice);
@ -402,7 +402,7 @@ void SNDDMA_StartCapture(void)
int SNDDMA_AvailableCaptureSamples(void)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// divided by 2 to convert from bytes to (mono16) samples.
return sdlCaptureDevice ? (SDL_GetQueuedAudioSize(sdlCaptureDevice) / 2) : 0;
#else
@ -412,7 +412,7 @@ int SNDDMA_AvailableCaptureSamples(void)
void SNDDMA_Capture(int samples, byte *data)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// multiplied by 2 to convert from (mono16) samples to bytes.
if (sdlCaptureDevice)
{
@ -427,15 +427,19 @@ void SNDDMA_Capture(int samples, byte *data)
void SNDDMA_StopCapture(void)
{
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
SDL_PauseAudioDevice(sdlCaptureDevice, 1);
}
#endif
}
void SNDDMA_MasterGain( float val )
{
#ifdef USE_SDL_AUDIO_CAPTURE
sdlMasterGain = val;
#endif
}
#endif

View File

@ -23,10 +23,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"
#ifndef DEDICATED
#ifdef USE_LOCAL_HEADERS
# include "SDL_version.h"
#else
# include <SDL_version.h>
#endif
// Require a minimum version of SDL
#define MINSDL_MAJOR 2
#define MINSDL_MINOR 0
#if SDL_VERSION_ATLEAST( 2, 0, 5 )
#define MINSDL_PATCH 5
#else
#define MINSDL_PATCH 0
#endif
#endif
// Console
void CON_Shutdown( void );