#include "fifo.h"
#define BITS 8
-struct playermem {
+typedef struct {
ao_device* aodev;
mpg123_handle* mh;
unsigned char* buffer;
fifo* queue;
-};
+ pthread_t decode_thread;
+} playermem;
-struct playersettings {
+typedef struct {
const char* file;
bool loop;
-};
+} playersettings;
typedef struct {
fifo* queue;
static void cleanupThread(void* arg)
{
- struct playermem* mem = (struct playermem*) arg;
+ playermem* mem = (playermem*) arg;
free(mem->buffer);
+ pthread_cancel(mem->decode_thread);
+ pthread_join(mem->decode_thread, NULL);
ao_close(mem->aodev);
mpg123_close(mem->mh);
mpg123_delete(mem->mh);
static void* playFunc(void* arg)
{
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
- //pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
bool running = true;
- struct playermem* mem = (struct playermem*) malloc(sizeof(struct playermem));
- struct playersettings* settings = (struct playersettings*) arg;
+ playermem* mem = (playermem*) malloc(sizeof(playermem));
+ playersettings* settings = (playersettings*) arg;
//mpg123_handle* mh;
//unsigned char* buffer;
int err;
ao_option options = {"debug","",NULL};
mem->aodev = ao_open_live(driver, &format, &options);
mem->queue = create_fifo(5);
- pthread_t dt;
decodeData dd;
dd.file = settings->file;
dd.queue = mem->queue;
dd.mh = mem->mh;
- pthread_create(&dt, NULL, decodeFunc, &dd);
+ pthread_create(&mem->decode_thread, NULL, decodeFunc, &dd);
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
// do {
while (running)
{
pthread_t startPlayThread(const char* file, bool loop)
{
pthread_t thread;
- struct playersettings* settings = malloc(sizeof(struct playersettings));
+ playersettings* settings = malloc(sizeof(playersettings));
settings->file=file;
settings->loop=loop;
pthread_create(&thread, NULL, playFunc, (void*) settings);