PageRenderTime 26ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/playlist.h

https://github.com/jdgordon/rockbox
C Header | 183 lines | 138 code | 17 blank | 28 comment | 0 complexity | b23a8a2333e16757345d49b038fa99c2 MD5 | raw file
  1. /***************************************************************************
  2. * __________ __ ___.
  3. * Open \______ \ ____ ____ | | _\_ |__ _______ ___
  4. * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
  5. * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
  6. * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
  7. * \/ \/ \/ \/ \/
  8. * $Id$
  9. *
  10. * Copyright (C) 2002 by wavey@wavey.org
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  18. * KIND, either express or implied.
  19. *
  20. ****************************************************************************/
  21. #ifndef __PLAYLIST_H__
  22. #define __PLAYLIST_H__
  23. #include <stdbool.h>
  24. #include "file.h"
  25. #include "kernel.h"
  26. #include "metadata.h"
  27. #define PLAYLIST_ATTR_QUEUED 0x01
  28. #define PLAYLIST_ATTR_INSERTED 0x02
  29. #define PLAYLIST_ATTR_SKIPPED 0x04
  30. #define PLAYLIST_MAX_CACHE 16
  31. #define PLAYLIST_DISPLAY_COUNT 10
  32. #define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
  33. enum playlist_command {
  34. PLAYLIST_COMMAND_PLAYLIST,
  35. PLAYLIST_COMMAND_ADD,
  36. PLAYLIST_COMMAND_QUEUE,
  37. PLAYLIST_COMMAND_DELETE,
  38. PLAYLIST_COMMAND_SHUFFLE,
  39. PLAYLIST_COMMAND_UNSHUFFLE,
  40. PLAYLIST_COMMAND_RESET,
  41. PLAYLIST_COMMAND_COMMENT
  42. };
  43. enum {
  44. PLAYLIST_PREPEND = -1,
  45. PLAYLIST_INSERT = -2,
  46. PLAYLIST_INSERT_LAST = -3,
  47. PLAYLIST_INSERT_FIRST = -4,
  48. PLAYLIST_INSERT_SHUFFLED = -5,
  49. PLAYLIST_REPLACE = -6,
  50. PLAYLIST_INSERT_LAST_SHUFFLED = -7
  51. };
  52. enum {
  53. PLAYLIST_DELETE_CURRENT = -1
  54. };
  55. struct playlist_control_cache {
  56. enum playlist_command command;
  57. int i1;
  58. int i2;
  59. const char* s1;
  60. const char* s2;
  61. void* data;
  62. };
  63. struct playlist_info
  64. {
  65. bool current; /* current playing playlist */
  66. char filename[MAX_PATH]; /* path name of m3u playlist on disk */
  67. char control_filename[MAX_PATH]; /* full path of control file */
  68. bool utf8; /* playlist is in .m3u8 format */
  69. int fd; /* descriptor of the open playlist file */
  70. int control_fd; /* descriptor of the open control file */
  71. bool control_created; /* has control file been created? */
  72. int dirlen; /* Length of the path to the playlist file */
  73. volatile unsigned long *indices; /* array of indices */
  74. volatile int *filenames; /* Array of dircache indices */
  75. int max_playlist_size; /* Max number of files in playlist. Mirror of
  76. global_settings.max_files_in_playlist */
  77. bool in_ram; /* playlist stored in ram (dirplay) */
  78. int buffer_handle; /* handle to the below buffer (-1 if non-buflib) */
  79. union {
  80. volatile char *buffer;/* buffer for in-ram playlists */
  81. int *seek_buf; /* buffer for seeks in real playlists */
  82. };
  83. int buffer_size; /* size of buffer */
  84. int buffer_end_pos; /* last position where buffer was written */
  85. int index; /* index of current playing track */
  86. int first_index; /* index of first song in playlist */
  87. int amount; /* number of tracks in the index */
  88. int last_insert_pos; /* last position we inserted a track */
  89. int seed; /* shuffle seed */
  90. bool shuffle_modified; /* has playlist been shuffled with
  91. inserted tracks? */
  92. bool deleted; /* have any tracks been deleted? */
  93. int num_inserted_tracks; /* number of tracks inserted */
  94. bool started; /* has playlist been started? */
  95. /* cache of playlist control commands waiting to be flushed to
  96. to disk */
  97. struct playlist_control_cache control_cache[PLAYLIST_MAX_CACHE];
  98. int num_cached; /* number of cached entries */
  99. bool pending_control_sync; /* control file needs to be synced */
  100. struct mutex *control_mutex; /* mutex for control file access */
  101. int last_shuffled_start; /* number of tracks when insert last
  102. shuffled command start */
  103. };
  104. struct playlist_track_info
  105. {
  106. char filename[MAX_PATH]; /* path name of mp3 file */
  107. int attr; /* playlist attributes for track */
  108. int index; /* index of track in playlist */
  109. int display_index; /* index of track for display */
  110. };
  111. /* Exported functions only for current playlist. */
  112. void playlist_init(void) INIT_ATTR;
  113. void playlist_shutdown(void);
  114. int playlist_create(const char *dir, const char *file);
  115. int playlist_resume(void);
  116. int playlist_add(const char *filename);
  117. int playlist_shuffle(int random_seed, int start_index);
  118. void playlist_start(int start_index, int offset);
  119. bool playlist_check(int steps);
  120. const char *playlist_peek(int steps, char* buf, size_t buf_size);
  121. int playlist_next(int steps);
  122. bool playlist_next_dir(int direction);
  123. int playlist_get_resume_info(int *resume_index);
  124. int playlist_update_resume_info(const struct mp3entry* id3);
  125. int playlist_get_display_index(void);
  126. int playlist_amount(void);
  127. void playlist_set_last_shuffled_start(void);
  128. struct playlist_info *playlist_get_current(void);
  129. /* Exported functions for all playlists. Pass NULL for playlist_info
  130. structure to work with current playlist. */
  131. int playlist_create_ex(struct playlist_info* playlist,
  132. const char* dir, const char* file,
  133. void* index_buffer, int index_buffer_size,
  134. void* temp_buffer, int temp_buffer_size);
  135. int playlist_set_current(struct playlist_info* playlist);
  136. void playlist_close(struct playlist_info* playlist);
  137. void playlist_sync(struct playlist_info* playlist);
  138. int playlist_insert_track(struct playlist_info* playlist, const char *filename,
  139. int position, bool queue, bool sync);
  140. int playlist_insert_directory(struct playlist_info* playlist,
  141. const char *dirname, int position, bool queue,
  142. bool recurse);
  143. int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
  144. int position, bool queue);
  145. void playlist_skip_entry(struct playlist_info *playlist, int steps);
  146. int playlist_delete(struct playlist_info* playlist, int index);
  147. int playlist_move(struct playlist_info* playlist, int index, int new_index);
  148. int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
  149. bool start_current);
  150. int playlist_sort(struct playlist_info* playlist, bool start_current);
  151. bool playlist_modified(const struct playlist_info* playlist);
  152. int playlist_get_first_index(const struct playlist_info* playlist);
  153. int playlist_get_seed(const struct playlist_info* playlist);
  154. int playlist_amount_ex(const struct playlist_info* playlist);
  155. char *playlist_name(const struct playlist_info* playlist, char *buf,
  156. int buf_size);
  157. char *playlist_get_name(const struct playlist_info* playlist, char *buf,
  158. int buf_size);
  159. int playlist_get_track_info(struct playlist_info* playlist, int index,
  160. struct playlist_track_info* info);
  161. int playlist_save(struct playlist_info* playlist, char *filename);
  162. int playlist_directory_tracksearch(const char* dirname, bool recurse,
  163. int (*callback)(char*, void*),
  164. void* context);
  165. int playlist_remove_all_tracks(struct playlist_info *playlist);
  166. #endif /* __PLAYLIST_H__ */