Commit 5df6ff8d authored by Max Kellermann's avatar Max Kellermann

added OutputBuffer.notify

OutputBuffer should be a more generic low-level library, without dependencies to the other headers. This patch adds the field "notify", which is used to signal the player thread. It is passed in the constructor, and removes the need to compile with the decode.h header.
parent 2a83ccdb
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "utils.h" #include "utils.h"
void ob_init(unsigned int size) void ob_init(unsigned int size, Notify *notify)
{ {
assert(size > 0); assert(size > 0);
...@@ -31,6 +31,7 @@ void ob_init(unsigned int size) ...@@ -31,6 +31,7 @@ void ob_init(unsigned int size)
ob.begin = 0; ob.begin = 0;
ob.end = 0; ob.end = 0;
ob.lazy = 0; ob.lazy = 0;
ob.notify = notify;
ob.chunks[0].chunkSize = 0; ob.chunks[0].chunkSize = 0;
} }
...@@ -61,7 +62,7 @@ static inline unsigned successor(unsigned i) ...@@ -61,7 +62,7 @@ static inline unsigned successor(unsigned i)
*/ */
static void output_buffer_expand(unsigned i) static void output_buffer_expand(unsigned i)
{ {
int was_empty = !ob.lazy || ob_is_empty(); int was_empty = ob.notify != NULL && (!ob.lazy || ob_is_empty());
assert(i == (ob.end + 1) % ob.size); assert(i == (ob.end + 1) % ob.size);
assert(i != ob.end); assert(i != ob.end);
...@@ -72,7 +73,7 @@ static void output_buffer_expand(unsigned i) ...@@ -72,7 +73,7 @@ static void output_buffer_expand(unsigned i)
/* if the buffer was empty, the player thread might be /* if the buffer was empty, the player thread might be
waiting for us; wake it up now that another decoded waiting for us; wake it up now that another decoded
buffer has become available. */ buffer has become available. */
notify_signal(&pc.notify); notify_signal(ob.notify);
} }
void ob_flush(void) void ob_flush(void)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef OUTPUT_BUFFER_H #ifndef OUTPUT_BUFFER_H
#define OUTPUT_BUFFER_H #define OUTPUT_BUFFER_H
#include "notify.h"
#include "pcm_utils.h" #include "pcm_utils.h"
#define OUTPUT_BUFFER_DC_STOP -1 #define OUTPUT_BUFFER_DC_STOP -1
...@@ -55,9 +56,11 @@ typedef struct _OutputBuffer { ...@@ -55,9 +56,11 @@ typedef struct _OutputBuffer {
AudioFormat audioFormat; AudioFormat audioFormat;
ConvState convState; ConvState convState;
Notify *notify;
} OutputBuffer; } OutputBuffer;
void ob_init(unsigned int size); void ob_init(unsigned int size, Notify *notify);
void ob_free(void); void ob_free(void);
......
...@@ -72,7 +72,7 @@ void initPlayerData(void) ...@@ -72,7 +72,7 @@ void initPlayerData(void)
buffered_before_play = buffered_chunks; buffered_before_play = buffered_chunks;
} }
ob_init(buffered_chunks); ob_init(buffered_chunks, &pc.notify);
notify_init(&pc.notify); notify_init(&pc.notify);
pc.error = PLAYER_ERROR_NOERROR; pc.error = PLAYER_ERROR_NOERROR;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment