mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-12-04 14:46:31 -05:00
Make playlist_t a truly opaque type
... and don't initialize global values twice while here
This commit is contained in:
parent
e3f43db0c9
commit
bf4150dcce
@ -153,7 +153,7 @@ cmdline_parse(int argc, char *argv[], int *ret_p)
|
|||||||
cfg_set_program_verbosity(verbosity, NULL);
|
cfg_set_program_verbosity(verbosity, NULL);
|
||||||
|
|
||||||
if (playlistFile) {
|
if (playlistFile) {
|
||||||
playlist_t *pl;
|
playlist_t pl;
|
||||||
const char *entry;
|
const char *entry;
|
||||||
|
|
||||||
if (0 > playlist_init()) {
|
if (0 > playlist_init()) {
|
||||||
|
@ -41,26 +41,26 @@
|
|||||||
#define STREAM_SERVERR 3
|
#define STREAM_SERVERR 3
|
||||||
#define STREAM_UPDMDATA 4
|
#define STREAM_UPDMDATA 4
|
||||||
|
|
||||||
playlist_t *playlist = NULL;
|
playlist_t playlist;
|
||||||
int playlistMode = 0;
|
int playlistMode;
|
||||||
unsigned int resource_errors = 0;
|
unsigned int resource_errors;
|
||||||
|
|
||||||
#ifdef HAVE_SIGNALS
|
#ifdef HAVE_SIGNALS
|
||||||
const int ezstream_signals[] = {
|
const int ezstream_signals[] = {
|
||||||
SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2
|
SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2
|
||||||
};
|
};
|
||||||
|
|
||||||
volatile sig_atomic_t rereadPlaylist = 0;
|
volatile sig_atomic_t rereadPlaylist;
|
||||||
volatile sig_atomic_t rereadPlaylist_notify = 0;
|
volatile sig_atomic_t rereadPlaylist_notify;
|
||||||
volatile sig_atomic_t skipTrack = 0;
|
volatile sig_atomic_t skipTrack;
|
||||||
volatile sig_atomic_t queryMetadata = 0;
|
volatile sig_atomic_t queryMetadata;
|
||||||
volatile sig_atomic_t quit = 0;
|
volatile sig_atomic_t quit;
|
||||||
#else
|
#else
|
||||||
int rereadPlaylist = 0;
|
int rereadPlaylist;
|
||||||
int rereadPlaylist_notify = 0;
|
int rereadPlaylist_notify;
|
||||||
int skipTrack = 0;
|
int skipTrack;
|
||||||
int queryMetadata = 0;
|
int queryMetadata;
|
||||||
int quit = 0;
|
int quit;
|
||||||
#endif /* HAVE_SIGNALS */
|
#endif /* HAVE_SIGNALS */
|
||||||
|
|
||||||
typedef struct tag_ID3Tag {
|
typedef struct tag_ID3Tag {
|
||||||
|
@ -39,24 +39,24 @@ struct playlist {
|
|||||||
char *prog_track;
|
char *prog_track;
|
||||||
};
|
};
|
||||||
|
|
||||||
static playlist_t * playlist_create(const char *);
|
static struct playlist * _playlist_create(const char *);
|
||||||
static int playlist_add(playlist_t *, const char *);
|
static int _playlist_add(struct playlist *, const char *);
|
||||||
static unsigned int playlist_random(void);
|
static unsigned int _playlist_random(void);
|
||||||
static const char * playlist_run_program(playlist_t *);
|
static const char * _playlist_run_program(struct playlist *);
|
||||||
|
|
||||||
static playlist_t *
|
static struct playlist *
|
||||||
playlist_create(const char *filename)
|
_playlist_create(const char *filename)
|
||||||
{
|
{
|
||||||
playlist_t *pl;
|
struct playlist *pl;
|
||||||
|
|
||||||
pl = xcalloc(1UL, sizeof(playlist_t));
|
pl = xcalloc(1UL, sizeof(*pl));
|
||||||
pl->filename = xstrdup(filename);
|
pl->filename = xstrdup(filename);
|
||||||
|
|
||||||
return (pl);
|
return (pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
playlist_add(playlist_t *pl, const char *entry)
|
_playlist_add(struct playlist *pl, const char *entry)
|
||||||
{
|
{
|
||||||
size_t num;
|
size_t num;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ playlist_add(playlist_t *pl, const char *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
playlist_random(void)
|
_playlist_random(void)
|
||||||
{
|
{
|
||||||
unsigned int ret = 0;
|
unsigned int ret = 0;
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ playlist_random(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
playlist_run_program(playlist_t *pl)
|
_playlist_run_program(struct playlist *pl)
|
||||||
{
|
{
|
||||||
FILE *filep;
|
FILE *filep;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
@ -173,16 +173,16 @@ playlist_init(void)
|
|||||||
|
|
||||||
void playlist_exit(void) {}
|
void playlist_exit(void) {}
|
||||||
|
|
||||||
playlist_t *
|
struct playlist *
|
||||||
playlist_read(const char *filename)
|
playlist_read(const char *filename)
|
||||||
{
|
{
|
||||||
playlist_t *pl;
|
struct playlist *pl;
|
||||||
unsigned long line;
|
unsigned long line;
|
||||||
FILE *filep;
|
FILE *filep;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
if (filename != NULL) {
|
if (filename != NULL) {
|
||||||
pl = playlist_create(filename);
|
pl = _playlist_create(filename);
|
||||||
|
|
||||||
if ((filep = fopen(filename, "r")) == NULL) {
|
if ((filep = fopen(filename, "r")) == NULL) {
|
||||||
log_error("%s: %s", filename, strerror(errno));
|
log_error("%s: %s", filename, strerror(errno));
|
||||||
@ -190,7 +190,7 @@ playlist_read(const char *filename)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pl = playlist_create("stdin");
|
pl = _playlist_create("stdin");
|
||||||
|
|
||||||
if ((filep = fdopen(STDIN_FILENO, "r")) == NULL) {
|
if ((filep = fdopen(STDIN_FILENO, "r")) == NULL) {
|
||||||
log_error("stdin: %s", strerror(errno));
|
log_error("stdin: %s", strerror(errno));
|
||||||
@ -233,7 +233,7 @@ playlist_read(const char *filename)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We got one. */
|
/* We got one. */
|
||||||
if (!playlist_add(pl, buf)) {
|
if (!_playlist_add(pl, buf)) {
|
||||||
fclose(filep);
|
fclose(filep);
|
||||||
playlist_free(&pl);
|
playlist_free(&pl);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -251,17 +251,17 @@ playlist_read(const char *filename)
|
|||||||
return (pl);
|
return (pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_t *
|
struct playlist *
|
||||||
playlist_program(const char *filename)
|
playlist_program(const char *filename)
|
||||||
{
|
{
|
||||||
playlist_t *pl;
|
struct playlist *pl;
|
||||||
#ifdef HAVE_STAT
|
#ifdef HAVE_STAT
|
||||||
struct stat st;
|
struct stat st;
|
||||||
#else
|
#else
|
||||||
FILE *filep;
|
FILE *filep;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pl = playlist_create(filename);
|
pl = _playlist_create(filename);
|
||||||
pl->program = 1;
|
pl->program = 1;
|
||||||
|
|
||||||
#ifdef HAVE_STAT
|
#ifdef HAVE_STAT
|
||||||
@ -294,10 +294,10 @@ playlist_program(const char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
playlist_free(playlist_t **pl_p)
|
playlist_free(struct playlist **pl_p)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
playlist_t *pl;
|
struct playlist *pl;
|
||||||
|
|
||||||
if (pl_p == NULL || (pl = *pl_p) == NULL)
|
if (pl_p == NULL || (pl = *pl_p) == NULL)
|
||||||
return;
|
return;
|
||||||
@ -330,10 +330,10 @@ playlist_free(playlist_t **pl_p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
playlist_get_next(playlist_t *pl)
|
playlist_get_next(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program)
|
if (pl->program)
|
||||||
return (playlist_run_program(pl));
|
return (_playlist_run_program(pl));
|
||||||
|
|
||||||
if (pl->num == 0)
|
if (pl->num == 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -342,7 +342,7 @@ playlist_get_next(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
playlist_peek_next(playlist_t *pl)
|
playlist_peek_next(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program || pl->num == 0)
|
if (pl->program || pl->num == 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -351,7 +351,7 @@ playlist_peek_next(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
playlist_skip_next(playlist_t *pl)
|
playlist_skip_next(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program || pl->num == 0)
|
if (pl->program || pl->num == 0)
|
||||||
return;
|
return;
|
||||||
@ -361,7 +361,7 @@ playlist_skip_next(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
playlist_get_num_items(playlist_t *pl)
|
playlist_get_num_items(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program)
|
if (pl->program)
|
||||||
return (0);
|
return (0);
|
||||||
@ -370,7 +370,7 @@ playlist_get_num_items(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
playlist_get_position(playlist_t *pl)
|
playlist_get_position(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program)
|
if (pl->program)
|
||||||
return (0);
|
return (0);
|
||||||
@ -379,7 +379,7 @@ playlist_get_position(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
playlist_set_position(playlist_t *pl, unsigned long idx)
|
playlist_set_position(struct playlist *pl, unsigned long idx)
|
||||||
{
|
{
|
||||||
if (pl->program || idx > pl->num - 1)
|
if (pl->program || idx > pl->num - 1)
|
||||||
return (0);
|
return (0);
|
||||||
@ -390,7 +390,7 @@ playlist_set_position(playlist_t *pl, unsigned long idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
playlist_goto_entry(playlist_t *pl, const char *entry)
|
playlist_goto_entry(struct playlist *pl, const char *entry)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ playlist_goto_entry(playlist_t *pl, const char *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
playlist_rewind(playlist_t *pl)
|
playlist_rewind(struct playlist *pl)
|
||||||
{
|
{
|
||||||
if (pl->program)
|
if (pl->program)
|
||||||
return;
|
return;
|
||||||
@ -417,9 +417,9 @@ playlist_rewind(playlist_t *pl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
playlist_reread(playlist_t **plist)
|
playlist_reread(struct playlist **plist)
|
||||||
{
|
{
|
||||||
playlist_t *new_pl, *pl;
|
struct playlist *new_pl, *pl;
|
||||||
|
|
||||||
pl = *plist;
|
pl = *plist;
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ playlist_reread(playlist_t **plist)
|
|||||||
* Yet another implementation of the "Knuth Shuffle":
|
* Yet another implementation of the "Knuth Shuffle":
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
playlist_shuffle(playlist_t *pl)
|
playlist_shuffle(struct playlist *pl)
|
||||||
{
|
{
|
||||||
size_t d, i, range;
|
size_t d, i, range;
|
||||||
char *temp;
|
char *temp;
|
||||||
@ -455,7 +455,7 @@ playlist_shuffle(playlist_t *pl)
|
|||||||
* largest multiple of our range. This reduces PRNG bias.
|
* largest multiple of our range. This reduces PRNG bias.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
d = (unsigned long)playlist_random();
|
d = (unsigned long)_playlist_random();
|
||||||
} while (d > RAND_MAX - (RAND_MAX % range));
|
} while (d > RAND_MAX - (RAND_MAX % range));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#ifndef __PLAYLIST_H__
|
#ifndef __PLAYLIST_H__
|
||||||
#define __PLAYLIST_H__
|
#define __PLAYLIST_H__
|
||||||
|
|
||||||
typedef struct playlist playlist_t;
|
typedef struct playlist * playlist_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the playlist routines. Should be called before any of the other
|
* Initialize the playlist routines. Should be called before any of the other
|
||||||
@ -34,26 +34,26 @@ void playlist_exit(void);
|
|||||||
* Read a playlist file (in .M3U format), and return a new playlist handler
|
* Read a playlist file (in .M3U format), and return a new playlist handler
|
||||||
* on success, or NULL on failure.
|
* on success, or NULL on failure.
|
||||||
*/
|
*/
|
||||||
playlist_t * playlist_read(const char * /* filename */);
|
playlist_t playlist_read(const char * /* filename */);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For each call to playlist_get_next(), the specified program is run. This
|
* For each call to playlist_get_next(), the specified program is run. This
|
||||||
* program is supposed to print one line to standard output, containing the
|
* program is supposed to print one line to standard output, containing the
|
||||||
* path and filename of a media file.
|
* path and filename of a media file.
|
||||||
*/
|
*/
|
||||||
playlist_t * playlist_program(const char * /* program name */);
|
playlist_t playlist_program(const char * /* program name */);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free all memory used by a playlist handler that was created with
|
* Free all memory used by a playlist handler that was created with
|
||||||
* playlist_read().
|
* playlist_read().
|
||||||
*/
|
*/
|
||||||
void playlist_free(playlist_t **);
|
void playlist_free(playlist_t *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the next item in the playlist. Returns a NUL-terminated string of a
|
* Get the next item in the playlist. Returns a NUL-terminated string of a
|
||||||
* playlist entry, or NULL if the end of the list has been reached.
|
* playlist entry, or NULL if the end of the list has been reached.
|
||||||
*/
|
*/
|
||||||
const char * playlist_get_next(playlist_t *);
|
const char * playlist_get_next(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The functions below work on playlist handlers obtained with playlist_read()
|
* The functions below work on playlist handlers obtained with playlist_read()
|
||||||
@ -65,40 +65,40 @@ const char * playlist_get_next(playlist_t *);
|
|||||||
* Returns a NUL-terminated string of the next playlist entry, or NULL if the
|
* Returns a NUL-terminated string of the next playlist entry, or NULL if the
|
||||||
* currently playing song is the last one in the list.
|
* currently playing song is the last one in the list.
|
||||||
*/
|
*/
|
||||||
const char * playlist_peek_next(playlist_t *);
|
const char * playlist_peek_next(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip the playlist item that would be played next.
|
* Skip the playlist item that would be played next.
|
||||||
*/
|
*/
|
||||||
void playlist_skip_next(playlist_t *);
|
void playlist_skip_next(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the number of items in the playlist.
|
* Get the number of items in the playlist.
|
||||||
*/
|
*/
|
||||||
unsigned long playlist_get_num_items(playlist_t *);
|
unsigned long playlist_get_num_items(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the current position in the playlist.
|
* Get the current position in the playlist.
|
||||||
*/
|
*/
|
||||||
unsigned long playlist_get_position(playlist_t *);
|
unsigned long playlist_get_position(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a position in the playlist. Returns 1 on success, and 0 on failure.
|
* Set a position in the playlist. Returns 1 on success, and 0 on failure.
|
||||||
*/
|
*/
|
||||||
int playlist_set_position(playlist_t *, unsigned long /* index */);
|
int playlist_set_position(playlist_t, unsigned long /* index */);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for a given entry in the playlist and reposition to it. Returns 1 on
|
* Search for a given entry in the playlist and reposition to it. Returns 1 on
|
||||||
* success and 0 on failure. A subsequent call to playlist_get_next() will
|
* success and 0 on failure. A subsequent call to playlist_get_next() will
|
||||||
* return this list item again.
|
* return this list item again.
|
||||||
*/
|
*/
|
||||||
int playlist_goto_entry(playlist_t *, const char * /* name */);
|
int playlist_goto_entry(playlist_t, const char * /* name */);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rewind the playlist to the beginning, so that it can be replayed. Does
|
* Rewind the playlist to the beginning, so that it can be replayed. Does
|
||||||
* not reread the playlist file.
|
* not reread the playlist file.
|
||||||
*/
|
*/
|
||||||
void playlist_rewind(playlist_t *);
|
void playlist_rewind(playlist_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reread the playlist file and rewind to the beginning. Equivalent to calling
|
* Reread the playlist file and rewind to the beginning. Equivalent to calling
|
||||||
@ -106,11 +106,11 @@ void playlist_rewind(playlist_t *);
|
|||||||
* after calling this function.
|
* after calling this function.
|
||||||
* Returns 1 on success, and 0 on error.
|
* Returns 1 on success, and 0 on error.
|
||||||
*/
|
*/
|
||||||
int playlist_reread(playlist_t **);
|
int playlist_reread(playlist_t*);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shuffle the entries of the playlist randomly.
|
* Shuffle the entries of the playlist randomly.
|
||||||
*/
|
*/
|
||||||
void playlist_shuffle(playlist_t *);
|
void playlist_shuffle(playlist_t);
|
||||||
|
|
||||||
#endif /* __PLAYLIST_H__ */
|
#endif /* __PLAYLIST_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user