Skip to content

Commit

Permalink
m4a files quit properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol committed Nov 28, 2023
1 parent b941f0c commit 9765caa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ typedef struct
} PixelData;
#endif

const char VERSION[] = "1.7.4";
const char VERSION[] = "1.8";
const int LOGO_COLOR = 3;
const int VERSION_COLOR = 6;
const int VERSION_COLOR = 2;
const int ABSOLUTE_MIN_WIDTH = 38;
volatile bool refresh = true;
bool visualizerEnabled = true;
Expand Down
39 changes: 20 additions & 19 deletions src/playerops.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ volatile bool clearingErrors = false;
volatile bool songLoading = false;
GDBusConnection *connection = NULL;

UserData userData;

void updateLastSongSwitchTime()
{
clock_gettime(CLOCK_MONOTONIC, &start_time);
Expand Down Expand Up @@ -328,28 +326,13 @@ Node *getSongByNumber(int songNumber)

void assignLoadedData()
{
if (usingSongDataA)
{
if (loadingdata.songdataB != NULL)
{
userData.filenameB = loadingdata.songdataB->pcmFilePath;
userData.songdataB = loadingdata.songdataB;
if (hasBuiltinDecoder(loadingdata.songdataB->filePath))
prepareNextDecoder(loadingdata.songdataB->filePath);
else if (endsWith(loadingdata.songdataB->filePath, "opus"))
prepareNextOpusDecoder(loadingdata.songdataB->filePath);
else if (endsWith(loadingdata.songdataB->filePath, "ogg"))
prepareNextVorbisDecoder(loadingdata.songdataB->filePath);
}
else
userData.filenameB = NULL;
}
else
if (loadingdata.loadA)
{
if (loadingdata.songdataA != NULL)
{
userData.filenameA = loadingdata.songdataA->pcmFilePath;
userData.songdataA = loadingdata.songdataA;

if (hasBuiltinDecoder(loadingdata.songdataA->filePath))
prepareNextDecoder(loadingdata.songdataA->filePath);
else if (endsWith(loadingdata.songdataA->filePath, "opus"))
Expand All @@ -360,6 +343,24 @@ void assignLoadedData()
else
userData.filenameA = NULL;
}
else
{
if (loadingdata.songdataB != NULL)
{
userData.filenameB = loadingdata.songdataB->pcmFilePath;
userData.songdataB = loadingdata.songdataB;

if (hasBuiltinDecoder(loadingdata.songdataB->filePath))
prepareNextDecoder(loadingdata.songdataB->filePath);
else if (endsWith(loadingdata.songdataB->filePath, "opus"))
prepareNextOpusDecoder(loadingdata.songdataB->filePath);
else if (endsWith(loadingdata.songdataB->filePath, "ogg"))
prepareNextVorbisDecoder(loadingdata.songdataB->filePath);
}
else
userData.filenameB = NULL;
}

}

void *songDataReaderThread(void *arg)
Expand Down
37 changes: 28 additions & 9 deletions src/soundgapless.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ soundgapless.c
*/

ma_context context;
UserData *g_userData;

UserData userData;

PCMFileDataSource pcmDataSource;

ma_result initFirstDatasource(PCMFileDataSource *pPCMDataSource, UserData *pUserData)
Expand Down Expand Up @@ -58,11 +60,16 @@ ma_result initFirstDatasource(PCMFileDataSource *pPCMDataSource, UserData *pUser
}
else
{
if (pPCMDataSource->fileA == NULL)
if ((pPCMDataSource->currentFileIndex == 0) && pPCMDataSource->fileA == NULL)
{
pPCMDataSource->filenameA = pUserData->filenameA;
pPCMDataSource->fileA = fopen(pUserData->filenameA, "rb");
}
else if ((pPCMDataSource->currentFileIndex == 1) && pPCMDataSource->fileB == NULL)
{
pPCMDataSource->filenameB = pUserData->filenameB;
pPCMDataSource->fileB = fopen(pUserData->filenameB, "rb");
}

pPCMDataSource->format = SAMPLE_FORMAT;
pPCMDataSource->channels = CHANNELS;
Expand Down Expand Up @@ -171,14 +178,27 @@ void switchAudioImplementation()
{
enum AudioImplementation currentImplementation = getCurrentImplementationType();

if (g_userData->currentSongData == NULL)
if (pcmDataSource.currentFileIndex == 0)
{
userData.currentSongData = userData.songdataA;
}
else
{
userData.currentSongData = userData.songdataB;
}

if (userData.currentSongData == NULL)
{
setEOFNotReached();
return;
}

char *filePath = strdup(g_userData->currentSongData->filePath);
char *filePath = strdup(userData.currentSongData->filePath);

if (filePath == NULL || filePath[0] == '\0' || filePath[0] == '\r')
{
free(filePath);
setEOFNotReached();
return;
}

Expand Down Expand Up @@ -210,7 +230,7 @@ void switchAudioImplementation()

cleanupPlaybackDevice();

builtin_createAudioDevice(g_userData, getDevice(), &context, &builtin_file_data_source_vtable);
builtin_createAudioDevice(&userData, getDevice(), &context, &builtin_file_data_source_vtable);

pthread_mutex_unlock(&dataSourceMutex);

Expand Down Expand Up @@ -258,7 +278,7 @@ void switchAudioImplementation()

cleanupPlaybackDevice();

opus_createAudioDevice(g_userData, getDevice(), &context, &pcm_file_data_source_vtable);
opus_createAudioDevice(&userData, getDevice(), &context, &pcm_file_data_source_vtable);

pthread_mutex_unlock(&dataSourceMutex);

Expand Down Expand Up @@ -306,7 +326,7 @@ void switchAudioImplementation()

cleanupPlaybackDevice();

vorbis_createAudioDevice(g_userData, getDevice(), &context, &pcm_file_data_source_vtable);
vorbis_createAudioDevice(&userData, getDevice(), &context, &pcm_file_data_source_vtable);

pthread_mutex_unlock(&dataSourceMutex);

Expand All @@ -327,7 +347,7 @@ void switchAudioImplementation()
resetOpusDecoders();
resetAudioBuffer();
cleanupPlaybackDevice();
pcm_createAudioDevice(g_userData, getDevice(), &context, &pcm_file_data_source_vtable);
pcm_createAudioDevice(&userData, getDevice(), &context, &pcm_file_data_source_vtable);

pthread_mutex_unlock(&dataSourceMutex);

Expand All @@ -345,7 +365,6 @@ void cleanupAudioContext()

void createAudioDevice(UserData *userData)
{
g_userData = userData;
ma_context_init(NULL, 0, NULL, &context);
switchAudioImplementation();
}
2 changes: 2 additions & 0 deletions src/soundgapless.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ typedef struct
} UserData;
#endif

extern UserData userData;

void setDecoders(bool usingA, char *filePath);

void createAudioDevice(UserData *userData);
Expand Down
5 changes: 1 addition & 4 deletions src/soundpcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ void pcm_read_pcm_frames(ma_data_source *pDataSource, void *pFramesOut, ma_uint6

if (currentFile != NULL)
bytesRead = (ma_uint32)fread((char *)pFramesOut + (framesRead * bytesPerFrame), 1, bytesToRead, currentFile);
else if (pPCMDataSource->pUserData->currentSongData == NULL ||
hasBuiltinDecoder(pPCMDataSource->pUserData->currentSongData->filePath) ||
(endsWith(pPCMDataSource->pUserData->currentSongData->filePath, "opus")) ||
(endsWith(pPCMDataSource->pUserData->currentSongData->filePath, "ogg")))
else
return;

// If file is empty, skip
Expand Down

0 comments on commit 9765caa

Please sign in to comment.