42#define DB_BASE_VERSION_MAJOR 1
43#define DB_BASE_VERSION_MINOR 0
45#define DB_VERSION_MAJOR 1
46#define DB_VERSION_MINOR 97
48#define DB_MIN_VERSION_MAJOR 1
49#define DB_MIN_VERSION_MINOR 97
107 typedef std::map<cache_key_t, Cache_Entry *>
cache_t;
150 explicit sqlite_t(
const std::string &
filename,
int flags,
const char *zVfs =
nullptr);
162#ifdef HAVE_SQLITE_CACHEFLUSH
262 bool remove_cachefile(
const std::string & filename,
const std::string &fileext);
283 bool delete_info(
const std::string & filename,
const std::string & desttype);
341 int cmp_version(
int version_major_l,
int version_minor_l,
int version_major_r,
int version_minor_r);
370 bool upgrade_db(
int *db_version_major,
int *db_version_minor);
#define CACHE_CLOSE_NOOPT
Dummy, do nothing special.
struct sqlite3 sqlite3
Forward declaration of sqlite3 handle.
RESULTCODE * LPRESULTCODE
Pointer to const version of RESULTCODE.
RESULTCODE
RESULTCODE of transcoding operation.
@ FINISHED_ERROR
Transcode finished with error.
@ FINISHED_INCOMPLETE
Transcode finished, but incomplete.
@ NONE
No result code available.
@ FINISHED_SUCCESS
Transcode finished successfully.
RESULTCODE const * LPCRESULTCODE
Pointer version of RESULTCODE.
CACHE_INFO * LPCACHE_INFO
Pointer to const version of CACHE_INFO.
CACHE_INFO const * LPCCACHE_INFO
Pointer version of CACHE_INFO.
struct CACHE_INFO CACHE_INFO
Cache information block.
struct sqlite3_stmt sqlite3_stmt
Forward declaration of sqlite3 statement handle.
The sqlite_t class Wrapper for sqlite3 struct to make use of std::shared_ptr.
sqlite3_stmt * m_insert_stmt
Prepared insert statement.
sqlite3 * m_db_handle
SQLite handle of cache index database.
std::string m_filename
Name of SQLite cache index database.
virtual ~sqlite_t()
Free sqlite_t object.
sqlite_t(const std::string &filename, int flags, const char *zVfs=nullptr)
Construct sqlite_t object.
const std::string & filename() const
Get current database file name.
int ret() const
Return code of last Sqlite operation.
sqlite3_stmt * m_delete_stmt
Prepared delete statement.
int m_ret
Return code of last SQL operation.
sqlite3_stmt * m_select_stmt
Prepared select statement.
Cache_Entry * openio(LPVIRTUALFILE virtualfile)
Open cache entry.
static const TABLECOLUMNS_VEC m_columns_cache_entry
Columns of table "cache_entry".
bool prune_disk_space(size_t predicted_filesize)
Prune cache entries to ensure disk space.
bool delete_info(const std::string &filename, const std::string &desttype)
Delete cache file info.
bool delete_entry(Cache_Entry **cache_entry, int flags)
Delete cache entry object.
TABLECOLUMNS_VEC * LPTABLECOLUMNS_VEC
Pointer to const version of TABLECOLUMNS_VEC.
int cmp_version(int version_major_l, int version_minor_l, int version_major_r, int version_minor_r)
Compare two versions.
bool create_table_cache_entry(LPCTABLE_DEF table, const TABLECOLUMNS_VEC &columns)
Create cache_entry table.
bool clear()
Clear cache: deletes all entries.
cache_t m_cache
Cache file (memory mapped file)
bool prepare_stmts()
Prepare all SQL statements.
bool remove_cachefile(const std::string &filename, const std::string &fileext)
Remove a cache file from disk.
bool maintenance(size_t predicted_filesize=0)
Run disk maintenance.
Cache()
Construct Cache object.
TABLE_COLUMNS * LPTABLE_COLUMNS
Pointer to const version of TABLE_COLUMNS.
std::map< cache_key_t, Cache_Entry * > cache_t
Map of cache entries.
std::vector< TABLE_COLUMNS > TABLECOLUMNS_VEC
Table columns array.
std::string expanded_sql(sqlite3_stmt *pStmt)
Get expanded SQL string for a statement.
TABLE_DEF const * LPCTABLE_DEF
Pointer version of TABLE_DEF.
bool load_index()
Load cache index from disk.
bool write_info(LPCCACHE_INFO cache_info)
Write cache file info.
std::unique_ptr< sqlite_t > m_cacheidx_db
SQLite handle of cache index database.
std::pair< std::string, std::string > cache_key_t
Filenames and destination types.
static const TABLECOLUMNS_VEC m_columns_version
Columns of table "version".
static const TABLE_DEF m_table_version
Definition and indexes of table "version".
bool rollback_transaction()
Rollback a database transaction.
void close_index()
Close cache index.
bool begin_transaction()
Begin a database transactio.n.
bool read_info(LPCACHE_INFO cache_info)
Read cache file info.
bool table_exists(const char *table)
Check if SQL table exists in database.
bool end_transaction()
End a database transaction.
bool upgrade_db(int *db_version_major, int *db_version_minor)
Upgrade database from version below 1.95.
bool prune_cache_size()
Prune cache entries to keep cache size within limit.
std::recursive_mutex m_mutex
Access mutex.
bool closeio(Cache_Entry **cache_entry, int flags=CACHE_CLOSE_NOOPT)
Close a cache entry.
TABLE_DEF * LPTABLE_DEF
Pointer to const version of TABLE_DEF.
TABLECOLUMNS_VEC const * LPCTABLECOLUMNS_VEC
Pointer version of TABLECOLUMNS_VEC.
TABLE_COLUMNS const * LPCTABLE_COLUMNS
Pointer version of TABLE_COLUMNS.
Cache_Entry * create_entry(LPVIRTUALFILE virtualfile, const std::string &desttype)
Create cache entry object for a VIRTUALFILE.
bool column_exists(const char *table, const char *column)
Check if column exists in SQL table.
bool prune_expired()
Prune expired cache entries.
bool check_min_version(int *db_version_major, int *db_version_minor)
Check the db version if upgrade needed.
virtual ~Cache()
Destruct Cache object.
static const TABLE_DEF m_table_cache_entry
Definition and indexes of table "cache_entry".
uint32_t m_video_frame_count
Number of frames in video or 0 if not a video.
int64_t m_audiobitrate
Audio bitrate in bit/s.
size_t m_file_size
Source file file size.
time_t m_access_time
Source file last access time.
RESULTCODE m_result
Result code:
bool m_deinterlace
true if video was deinterlaced
int64_t m_duration
File duration, in AV_TIME_BASE fractional seconds.
uint32_t m_segment_count
Number of segments for HLS.
size_t m_encoded_filesize
Actual file size after encode.
int m_audiosamplerate
Audio sample rate in Hz.
bool m_error
true if encode failed
size_t m_predicted_filesize
Predicted file size.
std::string m_destfile
Destination filename after transcode.
int m_averror
FFmpeg error code if encode failed.
std::string m_origfile
Original filename before transcode.
time_t m_file_time
Source file file time.
std::array< char, 11 > m_desttype
Destination type.
int m_videowidth
Video width.
int m_videoheight
Video height.
int64_t m_videobitrate
Video bitrate in bit/s.
unsigned int m_access_count
Read access counter.
int m_errno
errno if encode failed
time_t m_creation_time
Source file creation time.
Column definition of sql table.
const char * name
Column name.
const char * type
Column type (INT, CHAR etc)
const char * name
Table name.
const char * primary_key
Primary key of table.