2002-06-04 21:43:38 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by wavey@wavey.org
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-06-04 21:43:38 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __PLAYLIST_H__
|
|
|
|
#define __PLAYLIST_H__
|
|
|
|
|
2002-06-17 10:36:42 +00:00
|
|
|
#include <stdbool.h>
|
2011-12-19 20:12:52 +00:00
|
|
|
#include "config.h"
|
2002-07-17 23:23:57 +00:00
|
|
|
#include "file.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
#include "kernel.h"
|
2008-10-15 06:38:51 +00:00
|
|
|
#include "metadata.h"
|
2022-12-03 14:00:56 +00:00
|
|
|
#include "rbpaths.h"
|
2023-01-12 13:09:47 +00:00
|
|
|
#include "chunk_alloc.h"
|
2002-06-17 10:36:42 +00:00
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
#define PLAYLIST_ATTR_QUEUED 0x01
|
|
|
|
#define PLAYLIST_ATTR_INSERTED 0x02
|
|
|
|
#define PLAYLIST_ATTR_SKIPPED 0x04
|
|
|
|
#define PLAYLIST_MAX_CACHE 16
|
|
|
|
|
2008-10-12 16:47:59 +00:00
|
|
|
#define PLAYLIST_DISPLAY_COUNT 10
|
|
|
|
|
2006-11-29 19:22:44 +00:00
|
|
|
#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
enum playlist_command {
|
|
|
|
PLAYLIST_COMMAND_PLAYLIST,
|
|
|
|
PLAYLIST_COMMAND_ADD,
|
|
|
|
PLAYLIST_COMMAND_QUEUE,
|
|
|
|
PLAYLIST_COMMAND_DELETE,
|
|
|
|
PLAYLIST_COMMAND_SHUFFLE,
|
|
|
|
PLAYLIST_COMMAND_UNSHUFFLE,
|
|
|
|
PLAYLIST_COMMAND_RESET,
|
|
|
|
PLAYLIST_COMMAND_COMMENT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PLAYLIST_PREPEND = -1,
|
|
|
|
PLAYLIST_INSERT = -2,
|
|
|
|
PLAYLIST_INSERT_LAST = -3,
|
|
|
|
PLAYLIST_INSERT_FIRST = -4,
|
2006-12-26 13:31:04 +00:00
|
|
|
PLAYLIST_INSERT_SHUFFLED = -5,
|
2009-10-28 22:27:38 +00:00
|
|
|
PLAYLIST_REPLACE = -6,
|
|
|
|
PLAYLIST_INSERT_LAST_SHUFFLED = -7
|
2006-02-05 18:17:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PLAYLIST_DELETE_CURRENT = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
struct playlist_control_cache {
|
|
|
|
enum playlist_command command;
|
|
|
|
int i1;
|
|
|
|
int i2;
|
|
|
|
const char* s1;
|
|
|
|
const char* s2;
|
|
|
|
void* data;
|
|
|
|
};
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2002-08-23 20:04:31 +00:00
|
|
|
struct playlist_info
|
2002-06-04 21:43:38 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
bool current; /* current playing playlist */
|
2006-11-29 19:22:44 +00:00
|
|
|
bool utf8; /* playlist is in .m3u8 format */
|
2022-12-03 11:21:52 +00:00
|
|
|
bool control_created; /* has control file been created? */
|
|
|
|
bool in_ram; /* playlist stored in ram (dirplay) */
|
2003-07-01 21:05:43 +00:00
|
|
|
int fd; /* descriptor of the open playlist file */
|
|
|
|
int control_fd; /* descriptor of the open control file */
|
|
|
|
int max_playlist_size; /* Max number of files in playlist. Mirror of
|
2003-05-09 16:01:21 +00:00
|
|
|
global_settings.max_files_in_playlist */
|
2022-12-03 11:21:52 +00:00
|
|
|
int num_inserted_tracks; /* number of tracks inserted */
|
|
|
|
volatile unsigned long *indices; /* array of indices */
|
2023-01-12 13:09:47 +00:00
|
|
|
|
|
|
|
struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for
|
|
|
|
in-ram playlist */
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
int index; /* index of current playing track */
|
|
|
|
int first_index; /* index of first song in playlist */
|
2002-06-04 21:43:38 +00:00
|
|
|
int amount; /* number of tracks in the index */
|
2003-07-01 21:05:43 +00:00
|
|
|
int last_insert_pos; /* last position we inserted a track */
|
2004-01-14 00:13:04 +00:00
|
|
|
bool deleted; /* have any tracks been deleted? */
|
2006-04-19 02:22:23 +00:00
|
|
|
bool started; /* has playlist been started? */
|
2022-12-03 11:21:52 +00:00
|
|
|
bool pending_control_sync; /* control file needs to be synced */
|
|
|
|
bool shuffle_modified; /* has playlist been shuffled with
|
|
|
|
inserted tracks? */
|
|
|
|
int last_shuffled_start; /* number of tracks when insert last
|
|
|
|
shuffled command start */
|
|
|
|
int seed; /* shuffle seed */
|
2006-02-05 18:17:41 +00:00
|
|
|
/* cache of playlist control commands waiting to be flushed to
|
|
|
|
to disk */
|
|
|
|
struct playlist_control_cache control_cache[PLAYLIST_MAX_CACHE];
|
|
|
|
int num_cached; /* number of cached entries */
|
2022-12-03 14:00:56 +00:00
|
|
|
struct mutex mutex; /* mutex for control file access */
|
2022-12-03 11:21:52 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
struct dircache_fileref *dcfrefs; /* Dircache entry shortcuts */
|
|
|
|
#endif
|
|
|
|
int dirlen; /* Length of the path to the playlist file */
|
|
|
|
char filename[MAX_PATH]; /* path name of m3u playlist on disk */
|
2022-12-03 14:00:56 +00:00
|
|
|
/* full path of control file (with extra room for extensions) */
|
|
|
|
char control_filename[sizeof(PLAYLIST_CONTROL_FILE) + 8];
|
2006-02-05 18:17:41 +00:00
|
|
|
};
|
2005-06-24 16:32:30 +00:00
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
struct playlist_track_info
|
|
|
|
{
|
|
|
|
char filename[MAX_PATH]; /* path name of mp3 file */
|
|
|
|
int attr; /* playlist attributes for track */
|
|
|
|
int index; /* index of track in playlist */
|
|
|
|
int display_index; /* index of track for display */
|
|
|
|
};
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* Exported functions only for current playlist. */
|
2010-03-03 23:20:32 +00:00
|
|
|
void playlist_init(void) INIT_ATTR;
|
2006-02-05 18:17:41 +00:00
|
|
|
void playlist_shutdown(void);
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_create(const char *dir, const char *file);
|
2003-07-01 21:05:43 +00:00
|
|
|
int playlist_resume(void);
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_add(const char *filename);
|
2003-07-01 21:05:43 +00:00
|
|
|
int playlist_shuffle(int random_seed, int start_index);
|
2012-12-09 20:04:17 +00:00
|
|
|
unsigned int playlist_get_filename_crc32(struct playlist_info *playlist,
|
|
|
|
int index);
|
2013-07-14 11:59:39 +00:00
|
|
|
void playlist_resume_track(int start_index, unsigned int crc,
|
|
|
|
unsigned long elapsed, unsigned long offset);
|
|
|
|
void playlist_start(int start_index, unsigned long elapsed,
|
|
|
|
unsigned long offset);
|
2003-07-01 21:05:43 +00:00
|
|
|
bool playlist_check(int steps);
|
2010-08-11 19:01:50 +00:00
|
|
|
const char *playlist_peek(int steps, char* buf, size_t buf_size);
|
2003-07-01 21:05:43 +00:00
|
|
|
int playlist_next(int steps);
|
2005-11-02 22:32:04 +00:00
|
|
|
bool playlist_next_dir(int direction);
|
2004-01-14 00:13:04 +00:00
|
|
|
int playlist_get_resume_info(int *resume_index);
|
2005-07-04 22:50:57 +00:00
|
|
|
int playlist_update_resume_info(const struct mp3entry* id3);
|
2003-07-01 21:05:43 +00:00
|
|
|
int playlist_get_display_index(void);
|
2002-10-09 13:42:59 +00:00
|
|
|
int playlist_amount(void);
|
2009-10-28 22:27:38 +00:00
|
|
|
void playlist_set_last_shuffled_start(void);
|
2009-12-21 05:44:00 +00:00
|
|
|
struct playlist_info *playlist_get_current(void);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
/* Exported functions for all playlists. Pass NULL for playlist_info
|
|
|
|
structure to work with current playlist. */
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_create_ex(struct playlist_info* playlist,
|
|
|
|
const char* dir, const char* file,
|
2004-01-26 17:05:21 +00:00
|
|
|
void* index_buffer, int index_buffer_size,
|
|
|
|
void* temp_buffer, int temp_buffer_size);
|
|
|
|
int playlist_set_current(struct playlist_info* playlist);
|
|
|
|
void playlist_close(struct playlist_info* playlist);
|
2006-08-10 09:50:45 +00:00
|
|
|
void playlist_sync(struct playlist_info* playlist);
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_insert_track(struct playlist_info* playlist, const char *filename,
|
2006-08-10 09:50:45 +00:00
|
|
|
int position, bool queue, bool sync);
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_insert_directory(struct playlist_info* playlist,
|
|
|
|
const char *dirname, int position, bool queue,
|
|
|
|
bool recurse);
|
2008-05-12 17:52:50 +00:00
|
|
|
int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
|
2004-01-26 17:05:21 +00:00
|
|
|
int position, bool queue);
|
2005-10-21 06:40:45 +00:00
|
|
|
void playlist_skip_entry(struct playlist_info *playlist, int steps);
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_delete(struct playlist_info* playlist, int index);
|
|
|
|
int playlist_move(struct playlist_info* playlist, int index, int new_index);
|
|
|
|
int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
|
|
|
|
bool start_current);
|
|
|
|
int playlist_sort(struct playlist_info* playlist, bool start_current);
|
2004-08-18 01:09:31 +00:00
|
|
|
bool playlist_modified(const struct playlist_info* playlist);
|
|
|
|
int playlist_get_first_index(const struct playlist_info* playlist);
|
|
|
|
int playlist_get_seed(const struct playlist_info* playlist);
|
|
|
|
int playlist_amount_ex(const struct playlist_info* playlist);
|
|
|
|
char *playlist_name(const struct playlist_info* playlist, char *buf,
|
|
|
|
int buf_size);
|
|
|
|
char *playlist_get_name(const struct playlist_info* playlist, char *buf,
|
2004-01-26 17:05:21 +00:00
|
|
|
int buf_size);
|
2020-05-19 06:20:39 +00:00
|
|
|
size_t playlist_get_required_bufsz(struct playlist_info* playlist,
|
|
|
|
bool include_namebuf, int num_indices);
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_get_track_info(struct playlist_info* playlist, int index,
|
|
|
|
struct playlist_track_info* info);
|
2014-04-08 20:52:37 +00:00
|
|
|
int playlist_save(struct playlist_info* playlist, char *filename,
|
|
|
|
void* temp_buffer, size_t temp_buffer_size);
|
2006-07-18 13:54:12 +00:00
|
|
|
int playlist_directory_tracksearch(const char* dirname, bool recurse,
|
|
|
|
int (*callback)(char*, void*),
|
|
|
|
void* context);
|
2008-04-20 11:19:50 +00:00
|
|
|
int playlist_remove_all_tracks(struct playlist_info *playlist);
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2002-06-04 21:43:38 +00:00
|
|
|
#endif /* __PLAYLIST_H__ */
|