This commit is contained in:
parent
3eccbfcab2
commit
cf058bd113
|
|
@ -205,9 +205,12 @@ if (MSVC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Process Embeddeds ##
|
## Process Embeddeds ##
|
||||||
|
find_program(XXD_EXE
|
||||||
find_program(XXD_EXE xxd
|
NAMES xxd xxd.exe
|
||||||
DOC "Location of the xxd executable"
|
DOC "Location of the xxd executable"
|
||||||
|
HINTS
|
||||||
|
ENV PATH
|
||||||
|
/usr/bin /usr/local/bin .
|
||||||
)
|
)
|
||||||
|
|
||||||
macro(ProcessWithXXD outvar inputfile outdir)
|
macro(ProcessWithXXD outvar inputfile outdir)
|
||||||
|
|
|
||||||
118
src/alstream.cpp
118
src/alstream.cpp
|
|
@ -56,8 +56,7 @@ ALStream::ALStream(LoopMode loopMode,
|
||||||
threadName = std::string("al_stream (") + threadId + ")";
|
threadName = std::string("al_stream (") + threadId + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
ALStream::~ALStream()
|
ALStream::~ALStream(){
|
||||||
{
|
|
||||||
close();
|
close();
|
||||||
|
|
||||||
AL::Source::clearQueue(alSrc);
|
AL::Source::clearQueue(alSrc);
|
||||||
|
|
@ -69,12 +68,10 @@ ALStream::~ALStream()
|
||||||
SDL_DestroyMutex(pauseMut);
|
SDL_DestroyMutex(pauseMut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::close()
|
void ALStream::close(){
|
||||||
{
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
switch (state)
|
switch (state){
|
||||||
{
|
|
||||||
case Playing:
|
case Playing:
|
||||||
case Paused:
|
case Paused:
|
||||||
stopStream();
|
stopStream();
|
||||||
|
|
@ -88,12 +85,10 @@ void ALStream::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::open(const std::string &filename)
|
void ALStream::open(const std::string &filename){
|
||||||
{
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
switch (state)
|
switch (state){
|
||||||
{
|
|
||||||
case Playing:
|
case Playing:
|
||||||
case Paused:
|
case Paused:
|
||||||
stopStream();
|
stopStream();
|
||||||
|
|
@ -108,12 +103,10 @@ void ALStream::open(const std::string &filename)
|
||||||
state = Stopped;
|
state = Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::stop()
|
void ALStream::stop(){
|
||||||
{
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
switch (state)
|
switch (state){
|
||||||
{
|
|
||||||
case Closed:
|
case Closed:
|
||||||
case Stopped:
|
case Stopped:
|
||||||
return;
|
return;
|
||||||
|
|
@ -125,15 +118,13 @@ void ALStream::stop()
|
||||||
state = Stopped;
|
state = Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::play(float offset)
|
void ALStream::play(float offset){
|
||||||
{
|
|
||||||
if (!source)
|
if (!source)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
switch (state)
|
switch (state){
|
||||||
{
|
|
||||||
case Closed:
|
case Closed:
|
||||||
case Playing:
|
case Playing:
|
||||||
return;
|
return;
|
||||||
|
|
@ -147,12 +138,10 @@ void ALStream::play(float offset)
|
||||||
state = Playing;
|
state = Playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::pause()
|
void ALStream::pause(){
|
||||||
{
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
switch (state)
|
switch (state){
|
||||||
{
|
|
||||||
case Closed:
|
case Closed:
|
||||||
case Stopped:
|
case Stopped:
|
||||||
case Paused:
|
case Paused:
|
||||||
|
|
@ -164,13 +153,11 @@ void ALStream::pause()
|
||||||
state = Paused;
|
state = Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::setVolume(float value)
|
void ALStream::setVolume(float value){
|
||||||
{
|
|
||||||
AL::Source::setVolume(alSrc, value);
|
AL::Source::setVolume(alSrc, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::setPitch(float value)
|
void ALStream::setPitch(float value){
|
||||||
{
|
|
||||||
/* If the source supports setting pitch natively,
|
/* If the source supports setting pitch natively,
|
||||||
* we don't have to do it via OpenAL */
|
* we don't have to do it via OpenAL */
|
||||||
if (source && source->setPitch(value))
|
if (source && source->setPitch(value))
|
||||||
|
|
@ -179,15 +166,13 @@ void ALStream::setPitch(float value)
|
||||||
AL::Source::setPitch(alSrc, value);
|
AL::Source::setPitch(alSrc, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALStream::State ALStream::queryState()
|
ALStream::State ALStream::queryState(){
|
||||||
{
|
|
||||||
checkStopped();
|
checkStopped();
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ALStream::queryOffset()
|
float ALStream::queryOffset(){
|
||||||
{
|
|
||||||
if (state == Closed)
|
if (state == Closed)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -196,13 +181,11 @@ float ALStream::queryOffset()
|
||||||
return procOffset + AL::Source::getSecOffset(alSrc);
|
return procOffset + AL::Source::getSecOffset(alSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::closeSource()
|
void ALStream::closeSource(){
|
||||||
{
|
|
||||||
delete source;
|
delete source;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ALStreamOpenHandler : FileSystem::OpenHandler
|
struct ALStreamOpenHandler : FileSystem::OpenHandler{
|
||||||
{
|
|
||||||
SDL_IOStream *srcOps;
|
SDL_IOStream *srcOps;
|
||||||
bool looped;
|
bool looped;
|
||||||
ALDataSource *source;
|
ALDataSource *source;
|
||||||
|
|
@ -212,8 +195,7 @@ struct ALStreamOpenHandler : FileSystem::OpenHandler
|
||||||
: srcOps(srcOps), looped(looped), source(0)
|
: srcOps(srcOps), looped(looped), source(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool tryRead(SDL_IOStream* &ops, const char *ext)
|
bool tryRead(SDL_IOStream* &ops, const char *ext){
|
||||||
{
|
|
||||||
/* Copy this because we need to keep it around,
|
/* Copy this because we need to keep it around,
|
||||||
* as we will continue reading data from it later */
|
* as we will continue reading data from it later */
|
||||||
srcOps = ops;
|
srcOps = ops;
|
||||||
|
|
@ -223,18 +205,15 @@ struct ALStreamOpenHandler : FileSystem::OpenHandler
|
||||||
SDL_ReadIO(srcOps, sig, 4);
|
SDL_ReadIO(srcOps, sig, 4);
|
||||||
SDL_SeekIO(srcOps, 0, SDL_IO_SEEK_SET);
|
SDL_SeekIO(srcOps, 0, SDL_IO_SEEK_SET);
|
||||||
|
|
||||||
try
|
try{
|
||||||
{
|
if (!strcmp(sig, "OggS")){
|
||||||
if (!strcmp(sig, "OggS"))
|
|
||||||
{
|
|
||||||
source = createVorbisSource(*srcOps, looped);
|
source = createVorbisSource(*srcOps, looped);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
source = createSDLSource(*srcOps, ext, STREAM_BUF_SIZE, looped);
|
source = createSDLSource(*srcOps, ext, STREAM_BUF_SIZE, looped);
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e){
|
||||||
{
|
|
||||||
/* All source constructors will close the passed ops
|
/* All source constructors will close the passed ops
|
||||||
* before throwing errors */
|
* before throwing errors */
|
||||||
errorMsg = e.msg;
|
errorMsg = e.msg;
|
||||||
|
|
@ -245,15 +224,13 @@ struct ALStreamOpenHandler : FileSystem::OpenHandler
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ALStream::openSource(const std::string &filename)
|
void ALStream::openSource(const std::string &filename){
|
||||||
{
|
|
||||||
ALStreamOpenHandler handler(srcOps, looped);
|
ALStreamOpenHandler handler(srcOps, looped);
|
||||||
shState->fileSystem().openRead(handler, filename.c_str());
|
shState->fileSystem().openRead(handler, filename.c_str());
|
||||||
source = handler.source;
|
source = handler.source;
|
||||||
needsRewind.clear();
|
needsRewind.clear();
|
||||||
|
|
||||||
if (!source)
|
if (!source){
|
||||||
{
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s: %s",
|
snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s: %s",
|
||||||
filename.c_str(), handler.errorMsg.c_str());
|
filename.c_str(), handler.errorMsg.c_str());
|
||||||
|
|
@ -262,12 +239,10 @@ void ALStream::openSource(const std::string &filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::stopStream()
|
void ALStream::stopStream(){
|
||||||
{
|
|
||||||
threadTermReq.set();
|
threadTermReq.set();
|
||||||
|
|
||||||
if (thread)
|
if (thread){
|
||||||
{
|
|
||||||
SDL_WaitThread(thread, 0);
|
SDL_WaitThread(thread, 0);
|
||||||
thread = 0;
|
thread = 0;
|
||||||
needsRewind.set();
|
needsRewind.set();
|
||||||
|
|
@ -281,8 +256,7 @@ void ALStream::stopStream()
|
||||||
procFrames = 0;
|
procFrames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::startStream(float offset)
|
void ALStream::startStream(float offset){
|
||||||
{
|
|
||||||
AL::Source::clearQueue(alSrc);
|
AL::Source::clearQueue(alSrc);
|
||||||
|
|
||||||
preemptPause = false;
|
preemptPause = false;
|
||||||
|
|
@ -297,8 +271,7 @@ void ALStream::startStream(float offset)
|
||||||
<ALStream, &ALStream::streamData>(this, threadName);
|
<ALStream, &ALStream::streamData>(this, threadName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::pauseStream()
|
void ALStream::pauseStream(){
|
||||||
{
|
|
||||||
SDL_LockMutex(pauseMut);
|
SDL_LockMutex(pauseMut);
|
||||||
|
|
||||||
if (AL::Source::getState(alSrc) != AL_PLAYING)
|
if (AL::Source::getState(alSrc) != AL_PLAYING)
|
||||||
|
|
@ -309,8 +282,7 @@ void ALStream::pauseStream()
|
||||||
SDL_UnlockMutex(pauseMut);
|
SDL_UnlockMutex(pauseMut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::resumeStream()
|
void ALStream::resumeStream(){
|
||||||
{
|
|
||||||
SDL_LockMutex(pauseMut);
|
SDL_LockMutex(pauseMut);
|
||||||
|
|
||||||
if (preemptPause)
|
if (preemptPause)
|
||||||
|
|
@ -321,8 +293,7 @@ void ALStream::resumeStream()
|
||||||
SDL_UnlockMutex(pauseMut);
|
SDL_UnlockMutex(pauseMut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALStream::checkStopped()
|
void ALStream::checkStopped(){
|
||||||
{
|
|
||||||
/* This only concerns the scenario where
|
/* This only concerns the scenario where
|
||||||
* state is still 'Playing', but the stream
|
* state is still 'Playing', but the stream
|
||||||
* has already ended on its own (EOF, Error) */
|
* has already ended on its own (EOF, Error) */
|
||||||
|
|
@ -349,8 +320,7 @@ void ALStream::checkStopped()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* thread func */
|
/* thread func */
|
||||||
void ALStream::streamData()
|
void ALStream::streamData(){
|
||||||
{
|
|
||||||
/* Fill up queue */
|
/* Fill up queue */
|
||||||
bool firstBuffer = true;
|
bool firstBuffer = true;
|
||||||
ALDataSource::Status status;
|
ALDataSource::Status status;
|
||||||
|
|
@ -358,13 +328,11 @@ void ALStream::streamData()
|
||||||
if (threadTermReq)
|
if (threadTermReq)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (needsRewind)
|
if (needsRewind){
|
||||||
{
|
|
||||||
source->seekToOffset(startOffset);
|
source->seekToOffset(startOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < STREAM_BUFS; ++i)
|
for (int i = 0; i < STREAM_BUFS; ++i){
|
||||||
{
|
|
||||||
if (threadTermReq)
|
if (threadTermReq)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -377,8 +345,7 @@ void ALStream::streamData()
|
||||||
|
|
||||||
AL::Source::queueBuffer(alSrc, buf);
|
AL::Source::queueBuffer(alSrc, buf);
|
||||||
|
|
||||||
if (firstBuffer)
|
if (firstBuffer){
|
||||||
{
|
|
||||||
resumeStream();
|
resumeStream();
|
||||||
|
|
||||||
firstBuffer = false;
|
firstBuffer = false;
|
||||||
|
|
@ -388,8 +355,7 @@ void ALStream::streamData()
|
||||||
if (threadTermReq)
|
if (threadTermReq)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (status == ALDataSource::EndOfStream)
|
if (status == ALDataSource::EndOfStream){
|
||||||
{
|
|
||||||
sourceExhausted.set();
|
sourceExhausted.set();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -397,14 +363,12 @@ void ALStream::streamData()
|
||||||
|
|
||||||
/* Wait for buffers to be consumed, then
|
/* Wait for buffers to be consumed, then
|
||||||
* refill and queue them up again */
|
* refill and queue them up again */
|
||||||
while (true)
|
while (true){
|
||||||
{
|
|
||||||
shState->rtData().syncPoint.passSecondarySync();
|
shState->rtData().syncPoint.passSecondarySync();
|
||||||
|
|
||||||
ALint procBufs = AL::Source::getProcBufferCount(alSrc);
|
ALint procBufs = AL::Source::getProcBufferCount(alSrc);
|
||||||
|
|
||||||
while (procBufs--)
|
while (procBufs--){
|
||||||
{
|
|
||||||
if (threadTermReq)
|
if (threadTermReq)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -414,15 +378,12 @@ void ALStream::streamData()
|
||||||
if (buf == AL::Buffer::ID(0))
|
if (buf == AL::Buffer::ID(0))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (buf == lastBuf)
|
if (buf == lastBuf){
|
||||||
{
|
|
||||||
/* Reset the processed sample count so
|
/* Reset the processed sample count so
|
||||||
* querying the playback offset returns 0.0 again */
|
* querying the playback offset returns 0.0 again */
|
||||||
procFrames = source->loopStartFrames();
|
procFrames = source->loopStartFrames();
|
||||||
lastBuf = AL::Buffer::ID(0);
|
lastBuf = AL::Buffer::ID(0);
|
||||||
}
|
}else{
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Add the frame count contained in this
|
/* Add the frame count contained in this
|
||||||
* buffer to the total count */
|
* buffer to the total count */
|
||||||
ALint bits = AL::Buffer::getBits(buf);
|
ALint bits = AL::Buffer::getBits(buf);
|
||||||
|
|
@ -438,8 +399,7 @@ void ALStream::streamData()
|
||||||
|
|
||||||
status = source->fillBuffer(buf);
|
status = source->fillBuffer(buf);
|
||||||
|
|
||||||
if (status == ALDataSource::Error)
|
if (status == ALDataSource::Error){
|
||||||
{
|
|
||||||
sourceExhausted.set();
|
sourceExhausted.set();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,7 @@ char * xdg_user_dir_lookup_with_fallback (const char *type, const char *fallback
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
config_home = getenv ("XDG_CONFIG_HOME");
|
config_home = getenv ("XDG_CONFIG_HOME");
|
||||||
if (config_home == NULL || config_home[0] == 0)
|
if (config_home == NULL || config_home[0] == 0){
|
||||||
{
|
|
||||||
config_file = (char*) malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1);
|
config_file = (char*) malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1);
|
||||||
if (config_file == NULL)
|
if (config_file == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -87,8 +86,7 @@ char * xdg_user_dir_lookup_with_fallback (const char *type, const char *fallback
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
user_dir = NULL;
|
user_dir = NULL;
|
||||||
while (fgets (buffer, sizeof (buffer), file))
|
while (fgets (buffer, sizeof (buffer), file)){
|
||||||
{
|
|
||||||
/* Remove newline at end */
|
/* Remove newline at end */
|
||||||
len = strlen (buffer);
|
len = strlen (buffer);
|
||||||
if (len > 0 && buffer[len-1] == '\n')
|
if (len > 0 && buffer[len-1] == '\n')
|
||||||
|
|
@ -187,9 +185,7 @@ error2:
|
||||||
* The return value is newly allocated and must be freed with
|
* The return value is newly allocated and must be freed with
|
||||||
* free().
|
* free().
|
||||||
**/
|
**/
|
||||||
char *
|
char *xdg_user_dir_lookup (const char *type){
|
||||||
xdg_user_dir_lookup (const char *type)
|
|
||||||
{
|
|
||||||
char *dir, *home_dir, *user_dir;
|
char *dir, *home_dir, *user_dir;
|
||||||
|
|
||||||
dir = xdg_user_dir_lookup_with_fallback (type, NULL);
|
dir = xdg_user_dir_lookup_with_fallback (type, NULL);
|
||||||
|
|
@ -202,8 +198,7 @@ xdg_user_dir_lookup (const char *type)
|
||||||
return strdup ("/tmp");
|
return strdup ("/tmp");
|
||||||
|
|
||||||
/* Special case desktop for historical compatibility */
|
/* Special case desktop for historical compatibility */
|
||||||
if (strcmp (type, "DESKTOP") == 0)
|
if (strcmp (type, "DESKTOP") == 0){
|
||||||
{
|
|
||||||
user_dir = (char*) malloc (strlen (home_dir) + strlen ("/Desktop") + 1);
|
user_dir = (char*) malloc (strlen (home_dir) + strlen ("/Desktop") + 1);
|
||||||
if (user_dir == NULL)
|
if (user_dir == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue