2006-03-26 11:33:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Miika Pekkarinen
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _TAGCACHE_H
|
|
|
|
#define _TAGCACHE_H
|
|
|
|
|
|
|
|
#include "id3.h"
|
|
|
|
|
|
|
|
enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
|
2006-03-30 12:07:32 +00:00
|
|
|
tag_filename, tag_composer, tag_year, tag_tracknumber,
|
2006-07-15 17:36:25 +00:00
|
|
|
tag_bitrate, tag_length, tag_playcount, tag_playtime, tag_lastplayed,
|
|
|
|
/* Virtual tags */
|
|
|
|
tag_virt_autoscore };
|
2006-03-30 12:07:32 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
#define TAG_COUNT 13
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* Allow a little drift to the filename ordering (should not be too high/low). */
|
2006-03-26 11:33:42 +00:00
|
|
|
#define POS_HISTORY_COUNT 4
|
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* How much to pre-load entries while committing to prevent seeking. */
|
|
|
|
#define IDX_BUF_DEPTH 64
|
|
|
|
|
|
|
|
/* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
|
2006-07-20 12:19:31 +00:00
|
|
|
#define TAGCACHE_MAGIC 0x54434806
|
2006-04-18 18:56:56 +00:00
|
|
|
|
|
|
|
/* How much to allocate extra space for ramcache. */
|
|
|
|
#define TAGCACHE_RESERVE 32768
|
|
|
|
|
2006-04-23 18:47:26 +00:00
|
|
|
/**
|
|
|
|
* Define how long one entry must be at least (longer -> less memory at commit).
|
|
|
|
* Must be at least 4 bytes in length for correct alignment.
|
|
|
|
*/
|
|
|
|
#define TAGFILE_ENTRY_CHUNK_LENGTH 8
|
|
|
|
|
|
|
|
/* Used to guess the necessary buffer size at commit. */
|
|
|
|
#define TAGFILE_ENTRY_AVG_LENGTH 16
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* How many entries to fetch to the seek table at once while searching. */
|
2006-03-26 11:33:42 +00:00
|
|
|
#define SEEK_LIST_SIZE 50
|
2006-04-18 18:56:56 +00:00
|
|
|
|
|
|
|
/* Always strict align entries for best performance and binary compatability. */
|
|
|
|
#define TAGCACHE_STRICT_ALIGN 1
|
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
#define TAGCACHE_MAX_FILTERS 3
|
2006-04-03 18:57:34 +00:00
|
|
|
#define TAGCACHE_MAX_CLAUSES 10
|
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* Tag database files. */
|
2006-07-16 15:04:46 +00:00
|
|
|
#define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/tagcache_tmp.tcd"
|
|
|
|
#define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/tagcache_idx.tcd"
|
|
|
|
#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd"
|
|
|
|
#define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/tagcache_changelog.txt"
|
2006-08-05 20:19:10 +00:00
|
|
|
#define TAGCACHE_STATEFILE ROCKBOX_DIR "/tagcache_state.tcd"
|
2006-04-18 18:56:56 +00:00
|
|
|
|
|
|
|
/* Flags */
|
2006-07-10 16:22:03 +00:00
|
|
|
#define FLAG_DELETED 0x0001 /* Entry has been removed from db */
|
|
|
|
#define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
|
2006-07-15 17:36:25 +00:00
|
|
|
#define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
|
2006-04-18 18:56:56 +00:00
|
|
|
|
2006-04-03 18:57:34 +00:00
|
|
|
enum clause { clause_none, clause_is, clause_gt, clause_gteq, clause_lt,
|
|
|
|
clause_lteq, clause_contains, clause_begins_with, clause_ends_with };
|
2006-04-10 10:26:24 +00:00
|
|
|
enum modifiers { clause_mod_none, clause_mod_not };
|
2006-04-03 18:57:34 +00:00
|
|
|
|
2006-04-23 18:47:26 +00:00
|
|
|
struct tagcache_stat {
|
|
|
|
bool initialized; /* Is tagcache currently busy? */
|
2006-07-20 12:19:31 +00:00
|
|
|
bool ready; /* Is tagcache ready to be used? */
|
2006-04-23 18:47:26 +00:00
|
|
|
bool ramcache; /* Is tagcache loaded in ram? */
|
|
|
|
bool commit_delayed; /* Has commit been delayed until next reboot? */
|
|
|
|
int commit_step; /* Commit progress */
|
|
|
|
int ramcache_allocated; /* Has ram been allocated for ramcache? */
|
|
|
|
int ramcache_used; /* How much ram has been really used */
|
|
|
|
int progress; /* Current progress of disk scan */
|
|
|
|
int processed_entries; /* Scanned disk entries so far */
|
|
|
|
};
|
|
|
|
|
2006-04-03 18:57:34 +00:00
|
|
|
struct tagcache_search_clause
|
|
|
|
{
|
|
|
|
int tag;
|
|
|
|
int type;
|
|
|
|
bool numeric;
|
2006-04-04 19:28:13 +00:00
|
|
|
bool input;
|
2006-04-03 18:57:34 +00:00
|
|
|
long numeric_data;
|
|
|
|
char str[32];
|
|
|
|
};
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
struct tagcache_search {
|
|
|
|
/* For internal use only. */
|
2006-04-03 18:57:34 +00:00
|
|
|
int fd, masterfd;
|
2006-04-08 08:03:51 +00:00
|
|
|
int idxfd[TAG_COUNT];
|
2006-03-26 11:33:42 +00:00
|
|
|
long seek_list[SEEK_LIST_SIZE];
|
2006-07-10 16:22:03 +00:00
|
|
|
long seek_flags[SEEK_LIST_SIZE];
|
2006-03-26 11:33:42 +00:00
|
|
|
long filter_tag[TAGCACHE_MAX_FILTERS];
|
|
|
|
long filter_seek[TAGCACHE_MAX_FILTERS];
|
|
|
|
int filter_count;
|
2006-04-03 18:57:34 +00:00
|
|
|
struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
|
|
|
|
int clause_count;
|
2006-03-26 11:33:42 +00:00
|
|
|
int seek_list_count;
|
|
|
|
int seek_pos;
|
2006-03-30 12:07:32 +00:00
|
|
|
int idx_id;
|
2006-03-26 11:33:42 +00:00
|
|
|
long position;
|
|
|
|
int entry_count;
|
|
|
|
bool valid;
|
2006-08-02 17:39:34 +00:00
|
|
|
bool initialized;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
/* Exported variables. */
|
|
|
|
bool ramsearch;
|
|
|
|
int type;
|
|
|
|
char *result;
|
|
|
|
int result_len;
|
|
|
|
long result_seek;
|
|
|
|
};
|
|
|
|
|
2006-07-20 12:19:31 +00:00
|
|
|
int tagcache_str_to_tag(const char *str);
|
|
|
|
const char* tagcache_tag_to_str(int tag);
|
|
|
|
|
2006-04-03 18:57:34 +00:00
|
|
|
bool tagcache_is_numeric_tag(int type);
|
2006-04-10 10:26:24 +00:00
|
|
|
bool tagcache_is_unique_tag(int type);
|
|
|
|
bool tagcache_is_sorted_tag(int type);
|
2006-07-15 17:36:25 +00:00
|
|
|
bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
|
2006-03-26 11:33:42 +00:00
|
|
|
bool tagcache_search(struct tagcache_search *tcs, int tag);
|
|
|
|
bool tagcache_search_add_filter(struct tagcache_search *tcs,
|
|
|
|
int tag, int seek);
|
2006-04-03 18:57:34 +00:00
|
|
|
bool tagcache_search_add_clause(struct tagcache_search *tcs,
|
|
|
|
struct tagcache_search_clause *clause);
|
2006-03-26 11:33:42 +00:00
|
|
|
bool tagcache_get_next(struct tagcache_search *tcs);
|
2006-04-10 10:26:24 +00:00
|
|
|
bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
|
|
|
|
char *buf, long size);
|
2006-03-26 11:33:42 +00:00
|
|
|
void tagcache_search_finish(struct tagcache_search *tcs);
|
2006-03-30 12:07:32 +00:00
|
|
|
long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
|
2006-07-20 12:19:31 +00:00
|
|
|
long tagcache_increase_serial(void);
|
|
|
|
long tagcache_get_serial(void);
|
|
|
|
bool tagcache_import_changelog(void);
|
2006-07-16 15:04:46 +00:00
|
|
|
bool tagcache_create_changelog(struct tagcache_search *tcs);
|
2006-07-15 17:36:25 +00:00
|
|
|
bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
|
|
|
|
int tag, long data);
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-23 18:47:26 +00:00
|
|
|
struct tagcache_stat* tagcache_get_stat(void);
|
|
|
|
int tagcache_get_commit_step(void);
|
2006-08-05 20:19:10 +00:00
|
|
|
bool tagcache_prepare_shutdown(void);
|
2006-04-23 18:47:26 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
#ifdef HAVE_TC_RAMCACHE
|
|
|
|
bool tagcache_is_ramcache(void);
|
2006-03-26 16:37:18 +00:00
|
|
|
bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
|
2006-08-09 07:41:28 +00:00
|
|
|
void tagcache_unload_ramcache(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
#endif
|
|
|
|
void tagcache_init(void);
|
2006-04-12 10:31:24 +00:00
|
|
|
bool tagcache_is_initialized(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
void tagcache_start_scan(void);
|
|
|
|
void tagcache_stop_scan(void);
|
2006-07-10 16:22:03 +00:00
|
|
|
bool tagcache_update(void);
|
|
|
|
bool tagcache_rebuild(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
#endif
|