annotate audioDB_API.h @ 548:e18843dc0aea

Implement a rudimentary API for audioDB::liszt The API is rudimentary because we've dropped support for the incremental retrieval of tracks and their number of vectors (at the API level; the SOAP and command-line support is still there -- no changes should be visible). This is potentially bad for the large-scale databases, of course; one million tracks will take of the order of 16MB of RAM, more if I'm unlucky about how std::string.c_str() is implemented. Both this liszt operation and querying (and sampling, forthcoming...) would benefit from a `cursor-like' interface to retrieval results: for an API like that, instead of getting a struct with the data there, you get a cookie with which you can ask the database for successive results. This would be neat for all sorts of reasons. In the meantime, at least this change fixes SOAP memory leaks related to liszt. Make liszt.o part of LIBOBJS rather than ordinary OBJS, so that the liszt functionality is actually compiled into the library. Add a test for this library functionality; also modify the command-line test file to run the SOAP server on its own port.
author mas01cr
date Wed, 11 Feb 2009 12:38:03 +0000
parents cc2b97d020b1
children 633614461994
rev   line source
mas01cr@498 1 #ifndef AUDIODB_API_H
mas01cr@498 2 #define AUDIODB_API_H
mas01cr@498 3
mas01cr@498 4 #include <stdbool.h>
mas01cr@498 5 #include <stdint.h>
mas01cr@498 6
mas01ik@355 7 /* for API questions contact
mas01ik@355 8 * Christophe Rhodes c.rhodes@gold.ac.uk
mas01ik@355 9 * Ian Knopke mas01ik@gold.ac.uk, ian.knopke@gmail.com */
mas01ik@355 10
mas01cr@498 11 /* Temporary workarounds */
mas01cr@498 12 int acquire_lock(int, bool);
mas01cr@498 13 int divest_lock(int);
mas01cr@498 14
mas01ik@355 15
mas01ik@355 16 /*******************************************************************/
mas01ik@355 17 /* Data types for API */
mas01ik@355 18
mas01ik@355 19 /* The main struct that stores the name of the database, and in future will hold all
mas01ik@355 20 * kinds of other interesting information */
mas01ik@355 21 /* This basically gets passed around to all of the other functions */
mas01ik@355 22
mas01cr@498 23 /* FIXME: it might be that "adb_" isn't such a good prefix to use, and
mas01cr@498 24 that we should prefer "audiodb_". Or else maybe we should be
mas01cr@498 25 calling ourselves libadb? */
mas01cr@498 26 typedef struct adb adb_t, *adb_ptr;
mas01ik@355 27
mas01cr@498 28 struct adb_datum {
mas01cr@498 29 uint32_t nvectors;
mas01cr@498 30 uint32_t dim;
mas01cr@498 31 const char *key;
mas01cr@498 32 double *data;
mas01cr@498 33 double *power;
mas01cr@498 34 double *times;
mas01ik@355 35 };
mas01cr@498 36 typedef struct adb_datum adb_datum_t;
mas01ik@355 37
mas01ik@355 38 //used for both insert and batchinsert
mas01ik@355 39 struct adbinsert {
mas01cr@498 40 const char *features;
mas01cr@498 41 const char *power;
mas01cr@498 42 const char *key;
mas01cr@498 43 const char *times;
mas01ik@355 44 };
mas01cr@498 45 typedef struct adbinsert adb_insert_t, adb_reference_t, *adb_insert_ptr;
mas01ik@355 46
mas01ik@355 47 /* struct for returning status results */
mas01ik@355 48 struct adbstatus {
mas01ik@355 49 unsigned int numFiles;
mas01ik@355 50 unsigned int dim;
mas01ik@355 51 unsigned int dudCount;
mas01ik@355 52 unsigned int nullCount;
mas01ik@355 53 unsigned int flags;
mas01cr@498 54 uint64_t length;
mas01cr@498 55 uint64_t data_region_size;
mas01ik@355 56 };
mas01ik@355 57 typedef struct adbstatus adb_status_t, *adb_status_ptr;
mas01ik@355 58
mas01ik@355 59 /* needed for constructing a query */
mas01ik@355 60 struct adbquery {
mas01ik@355 61
mas01ik@355 62 char * querytype;
mas01ik@355 63 char * feature; //usually a file of some kind
mas01ik@396 64 char * key;
mas01ik@355 65 char * power; //also a file
mas01ik@355 66 char * keylist; //also a file
mas01ik@355 67 char * qpoint; //position
mas01ik@355 68 char * numpoints;
mas01ik@355 69 char * radius;
mas01ik@355 70 char * resultlength; //how many results to make
mas01ik@355 71 char * sequencelength;
mas01ik@355 72 char * sequencehop;
mas01ik@355 73 double absolute_threshold;
mas01ik@355 74 double relative_threshold;
mas01ik@355 75 int exhaustive; //hidden option in gengetopt
mas01ik@355 76 double expandfactor; //hidden
mas01ik@355 77 int rotate; //hidden
mas01ik@355 78
mas01ik@355 79 };
mas01ik@355 80 typedef struct adbquery adb_query_t,*adb_query_ptr;
mas01ik@355 81
mas01ik@355 82 /* ... and for getting query results back */
mas01ik@355 83 struct adbqueryresult {
mas01ik@355 84
mas01ik@355 85 int sizeRlist; /* do I really need to return all 4 sizes here */
mas01ik@355 86 int sizeDist;
mas01ik@355 87 int sizeQpos;
mas01ik@355 88 int sizeSpos;
mas01ik@355 89 char **Rlist;
mas01ik@355 90 double *Dist;
mas01ik@355 91 unsigned int *Qpos;
mas01ik@355 92 unsigned int *Spos;
mas01ik@355 93
mas01ik@355 94 };
mas01ik@355 95 typedef struct adbqueryresult adb_queryresult_t, *adb_queryresult_ptr;
mas01ik@355 96
mas01cr@498 97 /* New ("new" == December 2008) query API */
mas01cr@498 98
mas01cr@498 99 typedef struct adbresult {
mas01cr@498 100 const char *key;
mas01cr@498 101 double dist;
mas01cr@498 102 uint32_t qpos;
mas01cr@498 103 uint32_t ipos;
mas01cr@498 104 } adb_result_t;
mas01cr@498 105
mas01cr@498 106 #define ADB_REFINE_INCLUDE_KEYLIST 1
mas01cr@498 107 #define ADB_REFINE_EXCLUDE_KEYLIST 2
mas01cr@498 108 #define ADB_REFINE_RADIUS 4
mas01cr@498 109 #define ADB_REFINE_ABSOLUTE_THRESHOLD 8
mas01cr@498 110 #define ADB_REFINE_RELATIVE_THRESHOLD 16
mas01cr@498 111 #define ADB_REFINE_DURATION_RATIO 32
mas01cr@498 112 #define ADB_REFINE_HOP_SIZE 64
mas01cr@498 113
mas01cr@498 114 typedef struct adbkeylist {
mas01cr@498 115 uint32_t nkeys;
mas01cr@498 116 const char **keys;
mas01cr@498 117 } adb_keylist_t;
mas01cr@498 118
mas01cr@498 119 typedef struct adbqueryrefine {
mas01cr@498 120 uint32_t flags;
mas01cr@498 121 adb_keylist_t include;
mas01cr@498 122 adb_keylist_t exclude;
mas01cr@498 123 double radius;
mas01cr@498 124 double absolute_threshold;
mas01cr@498 125 double relative_threshold;
mas01cr@498 126 double duration_ratio; /* expandfactor */
mas01cr@498 127 uint32_t hopsize;
mas01cr@498 128 } adb_query_refine_t;
mas01cr@498 129
mas01cr@498 130 #define ADB_ACCUMULATION_DB 1
mas01cr@498 131 #define ADB_ACCUMULATION_PER_TRACK 2
mas01cr@498 132 #define ADB_ACCUMULATION_ONE_TO_ONE 3
mas01cr@498 133
mas01cr@498 134 #define ADB_DISTANCE_DOT_PRODUCT 1
mas01cr@498 135 #define ADB_DISTANCE_EUCLIDEAN_NORMED 2
mas01cr@498 136 #define ADB_DISTANCE_EUCLIDEAN 3
mas01cr@498 137
mas01cr@498 138 typedef struct adbqueryparameters {
mas01cr@498 139 uint32_t accumulation;
mas01cr@498 140 uint32_t distance;
mas01cr@498 141 uint32_t npoints;
mas01cr@498 142 uint32_t ntracks;
mas01cr@498 143 } adb_query_parameters_t;
mas01cr@498 144
mas01cr@498 145 typedef struct adbqueryresults {
mas01cr@498 146 uint32_t nresults;
mas01cr@498 147 adb_result_t *results;
mas01cr@498 148 } adb_query_results_t;
mas01cr@498 149
mas01cr@498 150 #define ADB_QID_FLAG_EXHAUSTIVE 1
mas01cr@498 151 #define ADB_QID_FLAG_ALLOW_FALSE_POSITIVES 2
mas01cr@498 152
mas01cr@498 153 typedef struct adbqueryid {
mas01cr@498 154 adb_datum_t *datum;
mas01cr@498 155 uint32_t sequence_length;
mas01cr@498 156 uint32_t flags;
mas01cr@498 157 uint32_t sequence_start;
mas01cr@498 158 } adb_query_id_t;
mas01cr@498 159
mas01cr@498 160 typedef struct adbqueryspec {
mas01cr@498 161 adb_query_id_t qid;
mas01cr@498 162 adb_query_parameters_t params;
mas01cr@498 163 adb_query_refine_t refine;
mas01cr@498 164 } adb_query_spec_t;
mas01ik@355 165
mas01cr@548 166 typedef struct adbtrackentry {
mas01cr@548 167 uint32_t nvectors;
mas01cr@548 168 const char *key;
mas01cr@548 169 } adb_track_entry_t;
mas01cr@548 170
mas01cr@548 171 typedef struct adblisztresults {
mas01cr@548 172 uint32_t nresults;
mas01cr@548 173 adb_track_entry_t *entries;
mas01cr@548 174 } adb_liszt_results_t;
mas01cr@548 175
mas01ik@355 176 /*******************************************************************/
mas01ik@355 177 /* Function prototypes for API */
mas01ik@355 178
mas01ik@355 179 /* open an existing database */
mas01ik@355 180 /* returns a struct or NULL on failure */
mas01cr@498 181 adb_ptr audiodb_open(const char *path, int flags);
mas01ik@355 182
mas01ik@355 183 /* create a new database */
mas01ik@355 184 /* returns a struct or NULL on failure */
mas01cr@381 185 adb_ptr audiodb_create(const char *path, unsigned datasize, unsigned ntracks, unsigned datadim);
mas01ik@355 186
mas01ik@355 187 /* close a database */
mas01ik@355 188 void audiodb_close(adb_ptr db);
mas01ik@355 189
mas01ik@355 190 /* You'll need to turn both of these on to do anything useful */
mas01ik@355 191 int audiodb_l2norm(adb_ptr mydb);
mas01ik@355 192 int audiodb_power(adb_ptr mydb);
mas01ik@355 193
mas01ik@355 194 /* insert functions */
mas01cr@498 195 int audiodb_insert_datum(adb_t *, const adb_datum_t *);
mas01cr@498 196 int audiodb_insert_reference(adb_t *, const adb_reference_t *);
mas01ik@355 197 int audiodb_insert(adb_ptr mydb, adb_insert_ptr ins);
mas01ik@355 198 int audiodb_batchinsert(adb_ptr mydb, adb_insert_ptr ins, unsigned int size);
mas01ik@355 199
mas01ik@355 200 /* query function */
mas01ik@355 201 int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqres);
mas01cr@498 202 adb_query_results_t *audiodb_query_spec(adb_t *, const adb_query_spec_t *);
mas01cr@498 203 int audiodb_query_free_results(adb_t *, const adb_query_spec_t *, adb_query_results_t *);
mas01cr@498 204
mas01ik@355 205 /* database status */
mas01ik@355 206 int audiodb_status(adb_ptr mydb, adb_status_ptr status);
mas01ik@355 207
mas01ik@355 208 /* varoius dump formats */
mas01cr@498 209 int audiodb_dump(adb_ptr mydb, const char *outputdir);
mas01ik@355 210
mas01cr@548 211 /* liszt */
mas01cr@548 212 adb_liszt_results_t *audiodb_liszt(adb_t *);
mas01cr@548 213 int audiodb_liszt_free_results(adb_t *, adb_liszt_results_t *);
mas01cr@548 214
mas01cr@498 215 #endif