1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Miika Pekkarinen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 enum tag_type
{ tag_artist
= 0, tag_album
, tag_genre
, tag_title
,
26 tag_filename
, tag_composer
, tag_comment
, tag_albumartist
, tag_year
,
27 tag_tracknumber
, tag_bitrate
, tag_length
, tag_playcount
, tag_rating
,
28 tag_playtime
, tag_lastplayed
, tag_commitid
,
30 tag_virt_length_min
, tag_virt_length_sec
,
31 tag_virt_playtime_min
, tag_virt_playtime_sec
,
32 tag_virt_entryage
, tag_virt_autoscore
};
36 /* Maximum length of a single tag. */
37 #define TAG_MAXLEN (MAX_PATH*2)
39 /* Allow a little drift to the filename ordering (should not be too high/low). */
40 #define POS_HISTORY_COUNT 4
42 /* How much to pre-load entries while committing to prevent seeking. */
43 #define IDX_BUF_DEPTH 64
45 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
46 #define TAGCACHE_MAGIC 0x54434809
48 /* How much to allocate extra space for ramcache. */
49 #define TAGCACHE_RESERVE 32768
52 * Define how long one entry must be at least (longer -> less memory at commit).
53 * Must be at least 4 bytes in length for correct alignment.
55 #define TAGFILE_ENTRY_CHUNK_LENGTH 8
57 /* Used to guess the necessary buffer size at commit. */
58 #define TAGFILE_ENTRY_AVG_LENGTH 16
60 /* How many entries to fetch to the seek table at once while searching. */
61 #define SEEK_LIST_SIZE 32
63 /* Always strict align entries for best performance and binary compatability. */
64 #define TAGCACHE_STRICT_ALIGN 1
66 #define TAGCACHE_MAX_FILTERS 4
67 #define TAGCACHE_MAX_CLAUSES 32
69 /* Tag database files. */
70 #define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd"
71 #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd"
72 #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd"
73 #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt"
74 #define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd"
77 #define FLAG_DELETED 0x0001 /* Entry has been removed from db */
78 #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
79 #define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
80 #define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
81 #define FLAG_GET_ATTR(flag) ((flag >> 16) & 0x0000ffff)
82 #define FLAG_SET_ATTR(flag,attr) flag = (flag & 0x0000ffff) | (attr << 16)
84 enum clause
{ clause_none
, clause_is
, clause_is_not
, clause_gt
, clause_gteq
,
85 clause_lt
, clause_lteq
, clause_contains
, clause_not_contains
,
86 clause_begins_with
, clause_not_begins_with
, clause_ends_with
,
87 clause_not_ends_with
, clause_oneof
};
89 struct tagcache_stat
{
90 bool initialized
; /* Is tagcache currently busy? */
91 bool readyvalid
; /* Has tagcache ready status been ascertained */
92 bool ready
; /* Is tagcache ready to be used? */
93 bool ramcache
; /* Is tagcache loaded in ram? */
94 bool commit_delayed
; /* Has commit been delayed until next reboot? */
95 bool econ
; /* Is endianess correction enabled? */
96 int commit_step
; /* Commit progress */
97 int ramcache_allocated
; /* Has ram been allocated for ramcache? */
98 int ramcache_used
; /* How much ram has been really used */
99 int progress
; /* Current progress of disk scan */
100 int processed_entries
; /* Scanned disk entries so far */
103 struct tagcache_search_clause
113 struct tagcache_search
{
114 /* For internal use only. */
116 int idxfd
[TAG_COUNT
];
117 long seek_list
[SEEK_LIST_SIZE
];
118 long seek_flags
[SEEK_LIST_SIZE
];
119 long filter_tag
[TAGCACHE_MAX_FILTERS
];
120 long filter_seek
[TAGCACHE_MAX_FILTERS
];
122 struct tagcache_search_clause
*clause
[TAGCACHE_MAX_CLAUSES
];
130 unsigned long *unique_list
;
131 int unique_list_capacity
;
132 int unique_list_count
;
134 /* Exported variables. */
145 void build_tagcache(const char *path
);
146 void tagcache_reverse_scan(void);
149 const char* tagcache_tag_to_str(int tag
);
151 bool tagcache_is_numeric_tag(int type
);
152 bool tagcache_is_unique_tag(int type
);
153 bool tagcache_is_sorted_tag(int type
);
154 bool tagcache_find_index(struct tagcache_search
*tcs
, const char *filename
);
155 bool tagcache_check_clauses(struct tagcache_search
*tcs
,
156 struct tagcache_search_clause
**clause
, int count
);
157 bool tagcache_search(struct tagcache_search
*tcs
, int tag
);
158 void tagcache_search_set_uniqbuf(struct tagcache_search
*tcs
,
159 void *buffer
, long length
);
160 bool tagcache_search_add_filter(struct tagcache_search
*tcs
,
162 bool tagcache_search_add_clause(struct tagcache_search
*tcs
,
163 struct tagcache_search_clause
*clause
);
164 bool tagcache_get_next(struct tagcache_search
*tcs
);
165 bool tagcache_retrieve(struct tagcache_search
*tcs
, int idxid
,
166 int tag
, char *buf
, long size
);
167 void tagcache_search_finish(struct tagcache_search
*tcs
);
168 long tagcache_get_numeric(const struct tagcache_search
*tcs
, int tag
);
169 long tagcache_increase_serial(void);
170 long tagcache_get_serial(void);
171 bool tagcache_import_changelog(void);
172 bool tagcache_create_changelog(struct tagcache_search
*tcs
);
173 bool tagcache_modify_numeric_entry(struct tagcache_search
*tcs
,
176 struct tagcache_stat
* tagcache_get_stat(void);
177 int tagcache_get_commit_step(void);
178 bool tagcache_prepare_shutdown(void);
179 void tagcache_shutdown(void);
181 #ifdef HAVE_TC_RAMCACHE
182 bool tagcache_is_ramcache(void);
183 bool tagcache_fill_tags(struct mp3entry
*id3
, const char *filename
);
184 void tagcache_unload_ramcache(void);
186 void tagcache_init(void);
187 bool tagcache_is_initialized(void);
188 bool tagcache_is_usable(void);
189 void tagcache_start_scan(void);
190 void tagcache_stop_scan(void);
191 bool tagcache_update(void);
192 bool tagcache_rebuild(void);
193 int tagcache_get_max_commit_step(void);