Fix playback bug & don't stop on every file select

Fixed a bug where ctrmus would freeze after selecting an unsupported
file.
Fixed a bug whereby selecting an unsupported file would stop playback.

Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
Mahyar Koshkouei
2017-02-15 15:50:20 +00:00
parent 825db2f713
commit 02746ec1d0
3 changed files with 35 additions and 15 deletions

View File

@@ -82,6 +82,13 @@ static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
s32 prio; s32 prio;
static Thread thread = NULL; static Thread thread = NULL;
if(ep_file != NULL && getFileType(ep_file) == FILE_TYPE_ERROR)
{
*playbackInfo->errInfo->error = errno;
svcSignalEvent(*playbackInfo->errInfo->failEvent);
return -1;
}
/** /**
* If music is playing, stop it. Only one playback thread should be playing * If music is playing, stop it. Only one playback thread should be playing
* at any time. * at any time.
@@ -94,9 +101,6 @@ static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
threadJoin(thread, U64_MAX); threadJoin(thread, U64_MAX);
threadFree(thread); threadFree(thread);
thread = NULL; thread = NULL;
/* free allocated file string */
delete(playbackInfo->file);
} }
if(ep_file == NULL || playbackInfo == NULL) if(ep_file == NULL || playbackInfo == NULL)

View File

@@ -47,7 +47,7 @@ bool isPlaying(void)
* \param file File location. * \param file File location.
* \return File type, else negative and errno set. * \return File type, else negative and errno set.
*/ */
static int getFileType(const char *file) int getFileType(const char *file)
{ {
FILE* ftest = fopen(file, "rb"); FILE* ftest = fopen(file, "rb");
uint32_t fileSig; uint32_t fileSig;
@@ -136,6 +136,7 @@ void playFile(void* infoIn)
bool lastbuf = false; bool lastbuf = false;
int ret = -1; int ret = -1;
const char* file = info->file; const char* file = info->file;
bool isNdspInit = false;
/* Reset previous stop command */ /* Reset previous stop command */
stop = false; stop = false;
@@ -168,6 +169,8 @@ void playFile(void* infoIn)
goto err; goto err;
} }
isNdspInit = true;
if((ret = (*decoder.init)(file)) != 0) if((ret = (*decoder.init)(file)) != 0)
{ {
errno = DECODER_INIT_FAIL; errno = DECODER_INIT_FAIL;
@@ -253,8 +256,13 @@ void playFile(void* infoIn)
(*decoder.exit)(); (*decoder.exit)();
out: out:
ndspChnWaveBufClear(CHANNEL); if(isNdspInit == true)
ndspExit(); {
ndspChnWaveBufClear(CHANNEL);
ndspExit();
}
delete(info->file);
linearFree(buffer1); linearFree(buffer1);
linearFree(buffer2); linearFree(buffer2);
threadExit(0); threadExit(0);

View File

@@ -30,15 +30,6 @@ struct playbackInfo_t
struct errInfo_t* errInfo; struct errInfo_t* errInfo;
}; };
/**
* Should only be called from a new thread only, and have only one playback
* thread at time. This function has not been written for more than one
* playback thread in mind.
*
* \param infoIn Playback information.
*/
void playFile(void* infoIn);
/** /**
* Pause or play current file. * Pause or play current file.
* *
@@ -56,4 +47,21 @@ void stopPlayback(void);
*/ */
bool isPlaying(void); bool isPlaying(void);
/**
* Obtains file type.
*
* \param file File location.
* \return File type, else negative and errno set.
*/
int getFileType(const char *file);
/**
* Should only be called from a new thread only, and have only one playback
* thread at time. This function has not been written for more than one
* playback thread in mind.
*
* \param infoIn Playback information.
*/
void playFile(void* infoIn);
#endif #endif