2006-03-26 11:33:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Miika Pekkarinen
|
|
|
|
*
|
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.
|
2006-03-26 11:33:42 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-03-26 11:33:42 +00:00
|
|
|
#ifndef _TAGCACHE_H
|
|
|
|
#define _TAGCACHE_H
|
|
|
|
|
2009-06-06 00:00:58 +00:00
|
|
|
#include "system.h"
|
2008-10-15 06:38:51 +00:00
|
|
|
#include "metadata.h"
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2008-08-29 21:14:58 +00:00
|
|
|
/**
|
2011-02-27 20:25:11 +00:00
|
|
|
Note: When adding new tags, make sure to update index_entry_ec and tags_str in
|
2008-08-29 21:14:58 +00:00
|
|
|
tagcache.c and bump up the header version too.
|
|
|
|
*/
|
2006-03-26 11:33:42 +00:00
|
|
|
enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
|
2007-08-08 10:19:56 +00:00
|
|
|
tag_filename, tag_composer, tag_comment, tag_albumartist, tag_grouping, tag_year,
|
2007-08-03 10:00:42 +00:00
|
|
|
tag_discnumber, tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating,
|
2011-01-02 02:49:13 +00:00
|
|
|
tag_playtime, tag_lastplayed, tag_commitid, tag_mtime, tag_lastoffset,
|
2008-08-29 21:14:58 +00:00
|
|
|
/* Real tags end here, count them. */
|
|
|
|
TAG_COUNT,
|
2006-07-15 17:36:25 +00:00
|
|
|
/* Virtual tags */
|
2011-07-31 16:26:35 +00:00
|
|
|
tag_virt_basename, tag_virt_length_min, tag_virt_length_sec,
|
2007-04-12 20:21:56 +00:00
|
|
|
tag_virt_playtime_min, tag_virt_playtime_sec,
|
2007-02-25 20:41:51 +00:00
|
|
|
tag_virt_entryage, tag_virt_autoscore };
|
2006-03-30 12:07:32 +00:00
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
/* Maximum length of a single tag. */
|
|
|
|
#define TAG_MAXLEN (MAX_PATH*2)
|
|
|
|
|
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. */
|
2011-01-02 02:49:13 +00:00
|
|
|
#define TAGCACHE_MAGIC 0x5443480e
|
2006-04-18 18:56:56 +00:00
|
|
|
|
2011-07-01 13:48:28 +00:00
|
|
|
/* Dump store/restore header version 'TCSxx'. */
|
|
|
|
#define TAGCACHE_STATEFILE_MAGIC 0x54435301
|
|
|
|
|
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-08-25 13:22:46 +00:00
|
|
|
#define SEEK_LIST_SIZE 32
|
2006-04-18 18:56:56 +00:00
|
|
|
|
2008-03-25 15:47:31 +00:00
|
|
|
/* Always strict align entries for best performance and binary compatibility. */
|
2006-04-18 18:56:56 +00:00
|
|
|
#define TAGCACHE_STRICT_ALIGN 1
|
|
|
|
|
2007-07-21 17:35:19 +00:00
|
|
|
/* Max events in the internal tagcache command queue. */
|
|
|
|
#define TAGCACHE_COMMAND_QUEUE_LENGTH 32
|
|
|
|
/* Idle time before committing events in the command queue. */
|
|
|
|
#define TAGCACHE_COMMAND_QUEUE_COMMIT_DELAY HZ*2
|
|
|
|
|
2006-08-25 13:22:46 +00:00
|
|
|
#define TAGCACHE_MAX_FILTERS 4
|
2006-10-25 15:14:15 +00:00
|
|
|
#define TAGCACHE_MAX_CLAUSES 32
|
2006-04-03 18:57:34 +00:00
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* Tag database files. */
|
2007-12-16 21:10:26 +00:00
|
|
|
|
|
|
|
/* Temporary database containing new tags to be committed to the main db. */
|
2006-11-25 09:42:06 +00:00
|
|
|
#define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd"
|
2007-12-16 21:10:26 +00:00
|
|
|
|
|
|
|
/* The main database master index and numeric data. */
|
2006-11-25 09:42:06 +00:00
|
|
|
#define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd"
|
2007-12-16 21:10:26 +00:00
|
|
|
|
|
|
|
/* The main database string data. */
|
2006-11-25 09:42:06 +00:00
|
|
|
#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd"
|
2007-12-16 21:10:26 +00:00
|
|
|
|
|
|
|
/* ASCII dumpfile of the DB contents. */
|
2006-11-25 09:42:06 +00:00
|
|
|
#define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt"
|
2007-12-16 21:10:26 +00:00
|
|
|
|
|
|
|
/* Serialized DB. */
|
2006-11-25 09:42:06 +00:00
|
|
|
#define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd"
|
2010-05-20 13:24:50 +00:00
|
|
|
|
|
|
|
/* Tag to be used on untagged files. */
|
|
|
|
#define UNTAGGED "<Untagged>"
|
2006-04-18 18:56:56 +00:00
|
|
|
|
2009-06-03 08:19:32 +00:00
|
|
|
/* Numeric tags (we can use these tags with conditional clauses). */
|
|
|
|
#define TAGCACHE_NUMERIC_TAGS ((1LU << tag_year) | (1LU << tag_discnumber) | \
|
|
|
|
(1LU << tag_tracknumber) | (1LU << tag_length) | (1LU << tag_bitrate) | \
|
|
|
|
(1LU << tag_playcount) | (1LU << tag_rating) | (1LU << tag_playtime) | \
|
|
|
|
(1LU << tag_lastplayed) | (1LU << tag_commitid) | (1LU << tag_mtime) | \
|
2011-07-31 16:26:35 +00:00
|
|
|
(1LU << tag_lastoffset) | (1LU << tag_virt_basename) | \
|
2009-06-03 08:19:32 +00:00
|
|
|
(1LU << tag_virt_length_min) | (1LU << tag_virt_length_sec) | \
|
|
|
|
(1LU << tag_virt_playtime_min) | (1LU << tag_virt_playtime_sec) | \
|
|
|
|
(1LU << tag_virt_entryage) | (1LU << tag_virt_autoscore))
|
|
|
|
|
2009-06-06 00:00:58 +00:00
|
|
|
#define TAGCACHE_IS_NUMERIC(tag) (BIT_N(tag) & TAGCACHE_NUMERIC_TAGS)
|
2009-06-03 08:19:32 +00:00
|
|
|
|
2006-04-18 18:56:56 +00:00
|
|
|
/* Flags */
|
2007-12-18 21:50:29 +00:00
|
|
|
#define FLAG_DELETED 0x0001 /* Entry has been removed from db */
|
|
|
|
#define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
|
|
|
|
#define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
|
|
|
|
#define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
|
|
|
|
#define FLAG_RESURRECTED 0x0010 /* Statistics data has been resurrected */
|
2006-04-18 18:56:56 +00:00
|
|
|
|
2006-08-13 12:33:34 +00:00
|
|
|
enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
|
|
|
|
clause_lt, clause_lteq, clause_contains, clause_not_contains,
|
|
|
|
clause_begins_with, clause_not_begins_with, clause_ends_with,
|
2011-05-10 10:25:41 +00:00
|
|
|
clause_not_ends_with, clause_oneof, clause_logical_or };
|
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? */
|
2007-03-08 08:20:30 +00:00
|
|
|
bool readyvalid; /* Has tagcache ready status been ascertained */
|
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? */
|
2007-02-13 21:51:18 +00:00
|
|
|
bool econ; /* Is endianess correction enabled? */
|
2006-04-23 18:47:26 +00:00
|
|
|
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 */
|
2008-02-17 19:11:16 +00:00
|
|
|
int queue_length; /* Command queue length */
|
2007-10-21 11:06:30 +00:00
|
|
|
volatile const char
|
|
|
|
*curentry; /* Path of the current entry being scanned. */
|
|
|
|
volatile bool syncscreen;/* Synchronous operation with debug screen? */
|
|
|
|
// const char *uimessage; /* Pending error message. Implement soon. */
|
2006-04-23 18:47:26 +00:00
|
|
|
};
|
|
|
|
|
2007-10-30 10:02:57 +00:00
|
|
|
enum source_type {source_constant,
|
|
|
|
source_runtime,
|
|
|
|
source_current_path /* dont add items after this.
|
2007-10-29 14:10:24 +00:00
|
|
|
it is used as an index
|
|
|
|
into id3_to_search_mapping */
|
|
|
|
};
|
2007-10-29 12:02:55 +00:00
|
|
|
|
2006-04-03 18:57:34 +00:00
|
|
|
struct tagcache_search_clause
|
|
|
|
{
|
|
|
|
int tag;
|
|
|
|
int type;
|
|
|
|
bool numeric;
|
2007-10-29 12:02:55 +00:00
|
|
|
int source;
|
2006-04-03 18:57:34 +00:00
|
|
|
long numeric_data;
|
2006-10-15 11:01:18 +00:00
|
|
|
char *str;
|
2006-04-03 18:57:34 +00:00
|
|
|
};
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_seeklist_entry {
|
|
|
|
int32_t seek;
|
|
|
|
int32_t flag;
|
|
|
|
int32_t idx_id;
|
|
|
|
};
|
|
|
|
|
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];
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_seeklist_entry seeklist[SEEK_LIST_SIZE];
|
|
|
|
int seek_list_count;
|
|
|
|
int32_t filter_tag[TAGCACHE_MAX_FILTERS];
|
|
|
|
int32_t filter_seek[TAGCACHE_MAX_FILTERS];
|
2006-03-26 11:33:42 +00:00
|
|
|
int filter_count;
|
2006-04-03 18:57:34 +00:00
|
|
|
struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
|
|
|
|
int clause_count;
|
2009-06-20 16:17:54 +00:00
|
|
|
int list_position;
|
2006-03-26 11:33:42 +00:00
|
|
|
int seek_pos;
|
2009-06-20 16:48:56 +00:00
|
|
|
long position;
|
2006-03-26 11:33:42 +00:00
|
|
|
int entry_count;
|
|
|
|
bool valid;
|
2006-08-02 17:39:34 +00:00
|
|
|
bool initialized;
|
2006-11-10 08:03:33 +00:00
|
|
|
unsigned long *unique_list;
|
2006-08-25 13:22:46 +00:00
|
|
|
int unique_list_capacity;
|
|
|
|
int unique_list_count;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
/* Exported variables. */
|
2009-06-20 16:17:54 +00:00
|
|
|
bool ramsearch; /* Is ram copy of the tagcache being used. */
|
|
|
|
bool ramresult; /* False if result is not static, and must be copied. */
|
2011-06-06 22:49:02 +00:00
|
|
|
int type; /* The tag type to be searched. Only nonvirtual tags */
|
2009-06-20 16:17:54 +00:00
|
|
|
char *result; /* The result data for all tags. */
|
|
|
|
int result_len; /* Length of the result including \0 */
|
|
|
|
int32_t result_seek; /* Current position in the tag data. */
|
|
|
|
int32_t idx_id; /* Entry number in the master index. */
|
2006-03-26 11:33:42 +00:00
|
|
|
};
|
|
|
|
|
2008-05-03 16:23:37 +00:00
|
|
|
void tagcache_build(const char *path);
|
2008-05-03 08:35:14 +00:00
|
|
|
|
|
|
|
#ifdef __PCTOOL__
|
2006-11-19 19:11:30 +00:00
|
|
|
void tagcache_reverse_scan(void);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-20 12:19:31 +00:00
|
|
|
const char* tagcache_tag_to_str(int tag);
|
|
|
|
|
2009-06-03 08:19:32 +00:00
|
|
|
#ifdef CPU_SH
|
2006-04-03 18:57:34 +00:00
|
|
|
bool tagcache_is_numeric_tag(int type);
|
2009-06-03 08:19:32 +00:00
|
|
|
#endif
|
2006-07-15 17:36:25 +00:00
|
|
|
bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
|
2006-10-15 11:01:18 +00:00
|
|
|
bool tagcache_check_clauses(struct tagcache_search *tcs,
|
|
|
|
struct tagcache_search_clause **clause, int count);
|
2009-06-20 16:17:54 +00:00
|
|
|
bool tagcache_is_busy(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
bool tagcache_search(struct tagcache_search *tcs, int tag);
|
2006-08-25 13:22:46 +00:00
|
|
|
void tagcache_search_set_uniqbuf(struct tagcache_search *tcs,
|
|
|
|
void *buffer, long length);
|
2006-03-26 11:33:42 +00:00
|
|
|
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,
|
2006-10-24 16:20:48 +00:00
|
|
|
int tag, 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);
|
2007-07-21 17:35:19 +00:00
|
|
|
void tagcache_update_numeric(int idx_id, int tag, long data);
|
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-09-23 10:29:14 +00:00
|
|
|
void tagcache_shutdown(void);
|
2006-04-23 18:47:26 +00:00
|
|
|
|
2007-10-21 11:06:30 +00:00
|
|
|
void tagcache_screensync_event(void);
|
|
|
|
void tagcache_screensync_enable(bool state);
|
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
#ifdef HAVE_TC_RAMCACHE
|
|
|
|
bool tagcache_is_ramcache(void);
|
2010-09-30 13:09:50 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2006-03-26 16:37:18 +00:00
|
|
|
bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
|
2010-09-30 13:09:50 +00:00
|
|
|
#endif
|
2006-08-09 07:41:28 +00:00
|
|
|
void tagcache_unload_ramcache(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
#endif
|
2010-03-03 23:20:32 +00:00
|
|
|
void tagcache_init(void) INIT_ATTR;
|
2006-04-12 10:31:24 +00:00
|
|
|
bool tagcache_is_initialized(void);
|
2011-01-17 22:28:36 +00:00
|
|
|
bool tagcache_is_fully_initialized(void);
|
2007-03-01 11:14:46 +00:00
|
|
|
bool tagcache_is_usable(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);
|
2007-03-07 19:56:15 +00:00
|
|
|
int tagcache_get_max_commit_step(void);
|
2006-03-26 11:33:42 +00:00
|
|
|
#endif
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|