This commit is contained in:
2026-02-25 09:58:51 +01:00
parent b14e6e3fca
commit 7fc4cde76f
4 changed files with 23 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ typedef struct _queue_ {
void *buf;
int buflen;
double at_second;
double music_duration;
struct _queue_ *next;
struct _queue_ *prev;
} Queue_t;
@@ -63,6 +64,7 @@ typedef struct {
pthread_t thread;
#endif
double at_second;
double music_duration;
ao_play_func_t ao_play_f;
int buf_size;
} AO_Handle;
@@ -106,7 +108,7 @@ static void add(AO_Handle *h, Queue_t *elem)
h->buf_size += elem->buflen;
}
static Queue_t *new_elem(int command, double at_second, int buf_len, void *buf)
static Queue_t *new_elem(int command, double at_second, double music_duration, int buf_len, void *buf)
{
Queue_t *q = (Queue_t *) malloc(sizeof(Queue_t));
void *new_buf;
@@ -118,6 +120,7 @@ static Queue_t *new_elem(int command, double at_second, int buf_len, void *buf)
new_buf = NULL;
}
q->at_second = at_second;
q->music_duration = music_duration;
q->buf = new_buf;
q->buflen = buf_len;
q->command = command;
@@ -220,7 +223,7 @@ void ao_stop_async(void *ao_handle)
MUTEX_LOCK(h->mutex);
clear(h);
Queue_t *q = new_elem(STOP, 0.0, 0, NULL);
Queue_t *q = new_elem(STOP, 0.0, 0.0, 0, NULL);
add(h, q);
MUTEX_UNLOCK(h->mutex);
@@ -236,10 +239,10 @@ void ao_stop_async(void *ao_handle)
free(h);
}
void ao_play_async(void *ao_handle, double at_second, int buf_size, void *mem)
void ao_play_async(void *ao_handle, double at_second, double music_duration, int buf_size, void *mem)
{
AO_Handle *h = (AO_Handle *) ao_handle;
Queue_t *q = new_elem(PLAY, at_second, buf_size, mem);
Queue_t *q = new_elem(PLAY, at_second, music_duration, buf_size, mem);
MUTEX_LOCK(h->mutex);
add(h, q);
MUTEX_UNLOCK(h->mutex);
@@ -262,6 +265,16 @@ double ao_is_at_second_async(void *ao_handle)
return s;
}
double ao_music_duration_async(void *ao_handle)
{
AO_Handle *h = (AO_Handle *) ao_handle;
MUTEX_LOCK(h->mutex);
double duration = h->at_second;
MUTEX_UNLOCK(h->mutex);
return duration;
}
int ao_bufsize_async(void *ao_handle)
{
AO_Handle *h = (AO_Handle *) ao_handle;

View File

@@ -13,9 +13,12 @@
AOPLAYASYNC_EXPORT void *ao_create_async(void *ao_handle, void *ao_play_f);
AOPLAYASYNC_EXPORT void ao_stop_async(void *handle);
AOPLAYASYNC_EXPORT void ao_play_async(void *handle, double at_second, int buf_size, void *mem);
AOPLAYASYNC_EXPORT void ao_play_async(void *handle, double at_second, double music_duration, int buf_size, void *mem);
AOPLAYASYNC_EXPORT void ao_clear_async(void *handle);
AOPLAYASYNC_EXPORT double ao_is_at_second_async(void *handle);
AOPLAYASYNC_EXPORT double ao_music_duration_async(void *handle);
AOPLAYASYNC_EXPORT int ao_bufsize_async(void *handle);
#endif // AO_PLAYASYNC_H