music_pipe: renamed "ob" to "music_pipe"
Last music_pipe rename patch: renamed the global variable (singleton).
This commit is contained in:
parent
d430b1dc54
commit
e9e9d2bc2d
86
src/pipe.c
86
src/pipe.c
@ -24,41 +24,41 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct music_pipe ob;
|
struct music_pipe music_pipe;
|
||||||
|
|
||||||
void
|
void
|
||||||
music_pipe_init(unsigned int size, struct notify *notify)
|
music_pipe_init(unsigned int size, struct notify *notify)
|
||||||
{
|
{
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
ob.chunks = g_new(struct music_chunk, size);
|
music_pipe.chunks = g_new(struct music_chunk, size);
|
||||||
ob.size = size;
|
music_pipe.size = size;
|
||||||
ob.begin = 0;
|
music_pipe.begin = 0;
|
||||||
ob.end = 0;
|
music_pipe.end = 0;
|
||||||
ob.lazy = false;
|
music_pipe.lazy = false;
|
||||||
ob.notify = notify;
|
music_pipe.notify = notify;
|
||||||
ob.chunks[0].chunkSize = 0;
|
music_pipe.chunks[0].chunkSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void music_pipe_free(void)
|
void music_pipe_free(void)
|
||||||
{
|
{
|
||||||
assert(ob.chunks != NULL);
|
assert(music_pipe.chunks != NULL);
|
||||||
g_free(ob.chunks);
|
g_free(music_pipe.chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void music_pipe_clear(void)
|
void music_pipe_clear(void)
|
||||||
{
|
{
|
||||||
ob.end = ob.begin;
|
music_pipe.end = music_pipe.begin;
|
||||||
ob.chunks[ob.end].chunkSize = 0;
|
music_pipe.chunks[music_pipe.end].chunkSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** return the index of the chunk after i */
|
/** return the index of the chunk after i */
|
||||||
static inline unsigned successor(unsigned i)
|
static inline unsigned successor(unsigned i)
|
||||||
{
|
{
|
||||||
assert(i <= ob.size);
|
assert(i <= music_pipe.size);
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
return i == ob.size ? 0 : i;
|
return i == music_pipe.size ? 0 : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,27 +67,27 @@ static inline unsigned successor(unsigned i)
|
|||||||
*/
|
*/
|
||||||
static void output_buffer_expand(unsigned i)
|
static void output_buffer_expand(unsigned i)
|
||||||
{
|
{
|
||||||
int was_empty = ob.notify != NULL && (!ob.lazy || music_pipe_is_empty());
|
int was_empty = music_pipe.notify != NULL && (!music_pipe.lazy || music_pipe_is_empty());
|
||||||
|
|
||||||
assert(i == (ob.end + 1) % ob.size);
|
assert(i == (music_pipe.end + 1) % music_pipe.size);
|
||||||
assert(i != ob.end);
|
assert(i != music_pipe.end);
|
||||||
|
|
||||||
ob.end = i;
|
music_pipe.end = i;
|
||||||
ob.chunks[i].chunkSize = 0;
|
music_pipe.chunks[i].chunkSize = 0;
|
||||||
if (was_empty)
|
if (was_empty)
|
||||||
/* 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(ob.notify);
|
notify_signal(music_pipe.notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void music_pipe_flush(void)
|
void music_pipe_flush(void)
|
||||||
{
|
{
|
||||||
struct music_chunk *chunk = music_pipe_get_chunk(ob.end);
|
struct music_chunk *chunk = music_pipe_get_chunk(music_pipe.end);
|
||||||
|
|
||||||
if (chunk->chunkSize > 0) {
|
if (chunk->chunkSize > 0) {
|
||||||
unsigned int next = successor(ob.end);
|
unsigned int next = successor(music_pipe.end);
|
||||||
if (next == ob.begin)
|
if (next == music_pipe.begin)
|
||||||
/* all buffers are full; we have to wait for
|
/* all buffers are full; we have to wait for
|
||||||
the player to free one, so don't flush
|
the player to free one, so don't flush
|
||||||
right now */
|
right now */
|
||||||
@ -99,43 +99,43 @@ void music_pipe_flush(void)
|
|||||||
|
|
||||||
void music_pipe_set_lazy(bool lazy)
|
void music_pipe_set_lazy(bool lazy)
|
||||||
{
|
{
|
||||||
ob.lazy = lazy;
|
music_pipe.lazy = lazy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void music_pipe_shift(void)
|
void music_pipe_shift(void)
|
||||||
{
|
{
|
||||||
assert(ob.begin != ob.end);
|
assert(music_pipe.begin != music_pipe.end);
|
||||||
assert(ob.begin < ob.size);
|
assert(music_pipe.begin < music_pipe.size);
|
||||||
|
|
||||||
ob.begin = successor(ob.begin);
|
music_pipe.begin = successor(music_pipe.begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int music_pipe_relative(const unsigned i)
|
unsigned int music_pipe_relative(const unsigned i)
|
||||||
{
|
{
|
||||||
if (i >= ob.begin)
|
if (i >= music_pipe.begin)
|
||||||
return i - ob.begin;
|
return i - music_pipe.begin;
|
||||||
else
|
else
|
||||||
return i + ob.size - ob.begin;
|
return i + music_pipe.size - music_pipe.begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned music_pipe_available(void)
|
unsigned music_pipe_available(void)
|
||||||
{
|
{
|
||||||
return music_pipe_relative(ob.end);
|
return music_pipe_relative(music_pipe.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
int music_pipe_absolute(const unsigned relative)
|
int music_pipe_absolute(const unsigned relative)
|
||||||
{
|
{
|
||||||
unsigned i, max;
|
unsigned i, max;
|
||||||
|
|
||||||
max = ob.end;
|
max = music_pipe.end;
|
||||||
if (max < ob.begin)
|
if (max < music_pipe.begin)
|
||||||
max += ob.size;
|
max += music_pipe.size;
|
||||||
i = (unsigned)ob.begin + relative;
|
i = (unsigned)music_pipe.begin + relative;
|
||||||
if (i >= max)
|
if (i >= max)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (i >= ob.size)
|
if (i >= music_pipe.size)
|
||||||
i -= ob.size;
|
i -= music_pipe.size;
|
||||||
|
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
@ -143,9 +143,9 @@ int music_pipe_absolute(const unsigned relative)
|
|||||||
struct music_chunk *
|
struct music_chunk *
|
||||||
music_pipe_get_chunk(const unsigned i)
|
music_pipe_get_chunk(const unsigned i)
|
||||||
{
|
{
|
||||||
assert(i < ob.size);
|
assert(i < music_pipe.size);
|
||||||
|
|
||||||
return &ob.chunks[i];
|
return &music_pipe.chunks[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,12 +160,12 @@ tail_chunk(float data_time, uint16_t bitRate, size_t frame_size)
|
|||||||
unsigned int next;
|
unsigned int next;
|
||||||
struct music_chunk *chunk;
|
struct music_chunk *chunk;
|
||||||
|
|
||||||
chunk = music_pipe_get_chunk(ob.end);
|
chunk = music_pipe_get_chunk(music_pipe.end);
|
||||||
assert(chunk->chunkSize <= sizeof(chunk->data));
|
assert(chunk->chunkSize <= sizeof(chunk->data));
|
||||||
if (chunk->chunkSize + frame_size > sizeof(chunk->data)) {
|
if (chunk->chunkSize + frame_size > sizeof(chunk->data)) {
|
||||||
/* this chunk is full; allocate a new chunk */
|
/* this chunk is full; allocate a new chunk */
|
||||||
next = successor(ob.end);
|
next = successor(music_pipe.end);
|
||||||
if (ob.begin == next)
|
if (music_pipe.begin == next)
|
||||||
/* no chunks available */
|
/* no chunks available */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -227,5 +227,5 @@ void music_pipe_skip(unsigned num)
|
|||||||
{
|
{
|
||||||
int i = music_pipe_absolute(num);
|
int i = music_pipe_absolute(num);
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
ob.begin = i;
|
music_pipe.begin = i;
|
||||||
}
|
}
|
||||||
|
12
src/pipe.h
12
src/pipe.h
@ -57,7 +57,7 @@ struct music_pipe {
|
|||||||
struct notify *notify;
|
struct notify *notify;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct music_pipe ob;
|
extern struct music_pipe music_pipe;
|
||||||
|
|
||||||
void
|
void
|
||||||
music_pipe_init(unsigned int size, struct notify *notify);
|
music_pipe_init(unsigned int size, struct notify *notify);
|
||||||
@ -79,25 +79,25 @@ void music_pipe_set_lazy(bool lazy);
|
|||||||
static inline unsigned
|
static inline unsigned
|
||||||
music_pipe_size(void)
|
music_pipe_size(void)
|
||||||
{
|
{
|
||||||
return ob.size;
|
return music_pipe.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** is the buffer empty? */
|
/** is the buffer empty? */
|
||||||
static inline bool music_pipe_is_empty(void)
|
static inline bool music_pipe_is_empty(void)
|
||||||
{
|
{
|
||||||
return ob.begin == ob.end;
|
return music_pipe.begin == music_pipe.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
music_pipe_head_is(unsigned i)
|
music_pipe_head_is(unsigned i)
|
||||||
{
|
{
|
||||||
return !music_pipe_is_empty() && ob.begin == i;
|
return !music_pipe_is_empty() && music_pipe.begin == i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
music_pipe_tail_index(void)
|
music_pipe_tail_index(void)
|
||||||
{
|
{
|
||||||
return ob.end;
|
return music_pipe.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
void music_pipe_shift(void);
|
void music_pipe_shift(void);
|
||||||
@ -126,7 +126,7 @@ music_pipe_peek(void)
|
|||||||
if (music_pipe_is_empty())
|
if (music_pipe_is_empty())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return music_pipe_get_chunk(ob.begin);
|
return music_pipe_get_chunk(music_pipe.begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user