Proper SDL library initialization for Audio and Joystick subsystems (ported from master)

This commit is contained in:
Damjan Adamic
2015-04-25 18:03:47 +02:00
parent df2318a45d
commit 2a667d1d53
5 changed files with 55 additions and 5 deletions
+19 -1
View File
@@ -48,6 +48,9 @@
#include <QSplashScreen> #include <QSplashScreen>
#include <QThread> #include <QThread>
#include <iostream> #include <iostream>
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#include <SDL.h>
#endif
#include "mainwindow.h" #include "mainwindow.h"
#include "eeprominterface.h" #include "eeprominterface.h"
#include "appdata.h" #include "appdata.h"
@@ -95,7 +98,18 @@ int main(int argc, char *argv[])
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
uint32_t sdlFlags = 0;
#ifdef JOYSTICKS
sdlFlags |= SDL_INIT_JOYSTICK;
#endif
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
SDL_Init(sdlFlags);
#endif
registerEEpromInterfaces(); registerEEpromInterfaces();
registerOpenTxFirmwares(); registerOpenTxFirmwares();
registerSimulators(); registerSimulators();
@@ -134,5 +148,9 @@ int main(int argc, char *argv[])
unregisterFirmwares(); unregisterFirmwares();
unregisterEEpromInterfaces(); unregisterEEpromInterfaces();
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
SDL_Quit();
#endif
return result; return result;
} }
+2 -4
View File
@@ -3,13 +3,13 @@
Joystick::Joystick(QObject *parent, int joystickEventTimeout, bool doAutoRepeat, int repeatDelay) Joystick::Joystick(QObject *parent, int joystickEventTimeout, bool doAutoRepeat, int repeatDelay)
: QObject(parent) : QObject(parent)
{ {
if ( SDL_Init(SDL_INIT_JOYSTICK) == 0 ) { if ( SDL_WasInit(SDL_INIT_JOYSTICK) ) {
int i; int i;
for (i = 0; i < SDL_NumJoysticks(); i++) for (i = 0; i < SDL_NumJoysticks(); i++)
joystickNames.append(SDL_JoystickName(i)); joystickNames.append(SDL_JoystickName(i));
connect(&joystickTimer, SIGNAL(timeout()), this, SLOT(processEvents())); connect(&joystickTimer, SIGNAL(timeout()), this, SLOT(processEvents()));
} else { } else {
fprintf(stderr, "ERROR: couldn't initialize SDL joystick support"); fprintf(stderr, "ERROR: couldn't initialize SDL joystick support\n");
} }
joystick = NULL; joystick = NULL;
@@ -23,8 +23,6 @@ Joystick::~Joystick()
{ {
if ( isOpen() ) if ( isOpen() )
close(); close();
SDL_Quit();
} }
bool Joystick::open(int stick) bool Joystick::open(int stick)
+18
View File
@@ -48,6 +48,9 @@
#include <QSplashScreen> #include <QSplashScreen>
#include <QThread> #include <QThread>
#include <iostream> #include <iostream>
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#include <SDL.h>
#endif
#include "simulatordialog.h" #include "simulatordialog.h"
#include "eeprominterface.h" #include "eeprominterface.h"
@@ -98,6 +101,17 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
uint32_t sdlFlags = 0;
#ifdef JOYSTICKS
sdlFlags |= SDL_INIT_JOYSTICK;
#endif
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
SDL_Init(sdlFlags);
#endif
SimulatorDialog *dialog; SimulatorDialog *dialog;
QString eepromFileName; QString eepromFileName;
QDir eedir; QDir eedir;
@@ -160,5 +174,9 @@ int main(int argc, char *argv[])
delete dialog; delete dialog;
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
SDL_Quit();
#endif
return result; return result;
} }
+11
View File
@@ -42,6 +42,9 @@
#include "opentx.h" #include "opentx.h"
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#if defined(SIMU_AUDIO)
#include <SDL.h>
#endif
#if LCD_W > 212 #if LCD_W > 212
#define LCD_ZOOM 1 #define LCD_ZOOM 1
@@ -95,6 +98,10 @@ Open9xSim::Open9xSim(FXApp* a):
memset(displayBuf, 0, DISPLAY_BUFER_SIZE); memset(displayBuf, 0, DISPLAY_BUFER_SIZE);
bmp = new FXPPMImage(getApp(),NULL,IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2); bmp = new FXPPMImage(getApp(),NULL,IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2);
#if defined(SIMU_AUDIO)
SDL_Init(SDL_INIT_AUDIO);
#endif
FXHorizontalFrame *hf11=new FXHorizontalFrame(this,LAYOUT_CENTER_X); FXHorizontalFrame *hf11=new FXHorizontalFrame(this,LAYOUT_CENTER_X);
FXHorizontalFrame *hf1=new FXHorizontalFrame(this,LAYOUT_FILL_X); FXHorizontalFrame *hf1=new FXHorizontalFrame(this,LAYOUT_FILL_X);
@@ -152,6 +159,10 @@ Open9xSim::~Open9xSim()
} }
delete bmf; delete bmf;
#if defined(SIMU_AUDIO)
SDL_Quit();
#endif
} }
void Open9xSim::makeSnapshot(const FXDrawable* drawable) void Open9xSim::makeSnapshot(const FXDrawable* drawable)
+5
View File
@@ -498,6 +498,11 @@ bool audio_thread_running = false;
void *audio_thread(void *) void *audio_thread(void *)
{ {
if ( !SDL_WasInit(SDL_INIT_AUDIO) ) {
fprintf(stderr, "ERROR: couldn't initialize SDL audio support\n");
return 0;
}
SDL_AudioSpec wanted, have; SDL_AudioSpec wanted, have;
/* Set the audio format */ /* Set the audio format */