Developer World
Spresense SDK Library v3.2.0-ebc0364
playlist.h
1/****************************************************************************
2 * modules/include/audio/utilities/playlist.h
3 *
4 * Copyright 2019 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef MODULES_INCLUDE_AUDIO_UTILITIES_PLAYLIST_H
37#define MODULES_INCLUDE_AUDIO_UTILITIES_PLAYLIST_H
38
39#include "memutils/s_stl/queue.h"
41
42/* Track information */
43
44struct Track
45{
48 char title[64];
49
52 char author[64];
53
56 char album[64];
57
61
64 uint8_t bit_length;
65
68 uint32_t sampling_rate;
69
72 uint8_t codec_type;
73};
74
75/* Playlist class definition */
76
78{
79public:
81 {
85
89
90 NumOfPlayMode,
91 };
92
94 {
98
102
103 NumOfRepeatMode,
104 };
105
107 {
111
115
119
123
124 NumOfListType,
125 };
126
133 Playlist(FAR const char* file_name) :
134 m_play_mode(PlayModeNormal),
135 m_repeat_mode(RepeatModeOff),
136 m_list_type(ListTypeAllTrack),
137 m_play_idx(-1),
138 m_track_db_fp(NULL)
139 {
140 strncpy(m_track_db_file_name, file_name, sizeof(m_track_db_file_name));
141 memset(m_playlist_path, 0, sizeof(m_playlist_path));
142 }
143
149 {
150 close();
151 }
152
162 bool init(const char *playlist_path);
163
173 bool setPlayMode(PlayMode play_mode);
174
184 bool setRepeatMode(RepeatMode repeat_mode);
185
197 bool select(ListType type, FAR const char *key_str);
198
211 bool updatePlaylist(ListType type, FAR const char *key_str);
212
224 bool addTrack(FAR const char *key_str, int track_no);
225
237 bool removeTrack(FAR const char *key_str, uint32_t remove_pos);
238
249 bool updateTrackDb(const char *audiofile_root_path);
250
260 bool deleteAll(void);
261
272 bool deleteOne(ListType type, FAR const char *key_str);
273
284 bool getNextTrack(FAR Track *track);
285
296 bool getPrevTrack(FAR Track *track);
297
306 bool restart(void);
307
308private:
309 bool open(FAR const char *mode);
310 bool close(void);
311 bool readLine(FAR char *line, uint32_t line_size);
312 bool isTargetTrack(ListType type,
313 FAR const char *key_str,
314 FAR Track *track);
315 bool loadAliasList(void);
316 bool shuffleList(int idx_top);
317 bool parseTrackInfo(FAR Track *track, FAR char *line, uint32_t line_size);
318 bool getFileName(ListType type,
319 FAR const char *key_str,
320 FAR char *file_name,
321 uint8_t max_length);
322
323 static const int FileNameMaxLength = 128;
324 static const int LineMaxLength = 256;
325
326 char m_playlist_path[FileNameMaxLength];
327 PlayMode m_play_mode;
328 RepeatMode m_repeat_mode;
329 ListType m_list_type;
330 int m_play_idx;
331 char m_list_key[64];
332 char m_line_buffer[LineMaxLength];
333 char m_track_db_file_name[FileNameMaxLength];
334 FAR FILE *m_track_db_fp;
335
336 s_std::Queue<uint32_t, 256> m_alias_list;
337};
338
339#endif /* MODULES_INCLUDE_AUDIO_UTILITIES_PLAYLIST_H */
340
CXD5602 Audio High Level API.
Definition: playlist.h:78
bool addTrack(FAR const char *key_str, int track_no)
Add track to playlist.
bool getPrevTrack(FAR Track *track)
Get previous track.
PlayMode
Definition: playlist.h:81
@ PlayModeNormal
Normal play mode.
Definition: playlist.h:84
@ PlayModeShuffle
Shuffle play mode.
Definition: playlist.h:88
RepeatMode
Definition: playlist.h:94
@ RepeatModeOff
Play all track at once.
Definition: playlist.h:97
@ RepeatModeOn
Play all track repeat.
Definition: playlist.h:101
bool select(ListType type, FAR const char *key_str)
Select playlist to play.
bool init(const char *playlist_path)
Init playlist.
bool setPlayMode(PlayMode play_mode)
Set play mode.
Playlist(FAR const char *file_name)
Playlist Constructor.
Definition: playlist.h:133
bool setRepeatMode(RepeatMode repeat_mode)
Set repeat mode.
bool restart(void)
Restart playlist.
ListType
Definition: playlist.h:107
@ ListTypeAlbum
Album categorized track list.
Definition: playlist.h:118
@ ListTypeUser
User defined track list.
Definition: playlist.h:122
@ ListTypeArtist
Artist categorized track list.
Definition: playlist.h:114
@ ListTypeAllTrack
All track (which is written in playlist file) list.
Definition: playlist.h:110
bool deleteOne(ListType type, FAR const char *key_str)
Delete playlist.
bool getNextTrack(FAR Track *track)
Get next track.
bool updatePlaylist(ListType type, FAR const char *key_str)
Update playlist.
~Playlist()
Playlist Destructor.
Definition: playlist.h:148
bool removeTrack(FAR const char *key_str, uint32_t remove_pos)
Remove track from playlist.
bool updateTrackDb(const char *audiofile_root_path)
Update track database.
bool deleteAll(void)
Delete all playlist.
Definition: playlist.h:45
char author[64]
Author name.
Definition: playlist.h:52
char album[64]
Album name.
Definition: playlist.h:56
uint8_t codec_type
Codec type of the track.
Definition: playlist.h:72
char title[64]
Track title (file name)
Definition: playlist.h:48
uint8_t channel_number
Number of channels.
Definition: playlist.h:60
uint32_t sampling_rate
Sampling rate of the track.
Definition: playlist.h:68
uint8_t bit_length
Bit length of the track.
Definition: playlist.h:64