[SCM] libgroove/upstream: fingerprinter: API refactor
andrewrk-guest at users.alioth.debian.org
andrewrk-guest at users.alioth.debian.org
Tue May 13 03:19:10 UTC 2014
The following commit has been merged in the upstream branch:
commit a65d3a2b5761d1865e33e25e2a24e14638e6fd9c
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sun May 11 14:54:26 2014 -0700
fingerprinter: API refactor
* info struct contains raw fingerprint instead of compressed string. closes #61
* encode/decode functions return < 0 on error, consistent with rest of API
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7889ea4..47e745c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,9 @@
* GrooveBuffer struct contains the presentation time stamp
* move include statements to outside of extern C
* player: specify device by index rather than name. closes #44
+ * fingerprinter: encode/decode return 0 on success, < 0 on error
+ * fingerprinter: info struct contains raw fingerprint instead of
+ compressed string. closes #61
### Version 3.1.1 (2014-04-21)
diff --git a/example/fingerprint.c b/example/fingerprint.c
index e45a4d8..ae769d2 100644
--- a/example/fingerprint.c
+++ b/example/fingerprint.c
@@ -52,14 +52,19 @@ int main(int argc, char * argv[]) {
info.duration,
info.item->file->filename);
if (raw) {
- int size;
- int32_t *raw_fingerprint;
- groove_fingerprinter_decode(info.fingerprint, &raw_fingerprint, &size);
- for (int i = 0; i < size; i += 1) {
- printf("%"PRId32"\n", raw_fingerprint[i]);
+ for (int i = 0; i < info.fingerprint_size; i += 1) {
+ printf("%"PRId32"\n", info.fingerprint[i]);
}
} else {
- printf("%s\n", info.fingerprint);
+ char *encoded_fp;
+ if (groove_fingerprinter_encode(info.fingerprint,
+ info.fingerprint_size, &encoded_fp) < 0)
+ {
+ fprintf(stderr, "Unable to encode fingerprint\n");
+ } else {
+ printf("%s\n", encoded_fp);
+ groove_fingerprinter_dealloc(encoded_fp);
+ }
}
groove_fingerprinter_free_info(&info);
} else {
diff --git a/groovefingerprinter/fingerprinter.c b/groovefingerprinter/fingerprinter.c
index 018b10a..4f21dc3 100644
--- a/groovefingerprinter/fingerprinter.c
+++ b/groovefingerprinter/fingerprinter.c
@@ -63,7 +63,9 @@ static int emit_track_info(struct GrooveFingerprinterPrivate *p) {
av_log(NULL, AV_LOG_ERROR, "unable to finish chromaprint\n");
return -1;
}
- if (!chromaprint_get_fingerprint(p->chroma_ctx, &info->fingerprint)) {
+ if (!chromaprint_get_raw_fingerprint(p->chroma_ctx,
+ (void**)&info->fingerprint, &info->fingerprint_size))
+ {
av_log(NULL, AV_LOG_ERROR, "unable to get fingerprint\n");
return -1;
}
@@ -385,15 +387,17 @@ void groove_fingerprinter_free_info(struct GrooveFingerprinterInfo *info) {
int groove_fingerprinter_encode(int32_t *fp, int size, char **encoded_fp) {
int encoded_size;
- return chromaprint_encode_fingerprint(fp, size,
+ int err = chromaprint_encode_fingerprint(fp, size,
CHROMAPRINT_ALGORITHM_DEFAULT, (void*)encoded_fp, &encoded_size, 1);
+ return err == 1 ? 0 : -1;
}
int groove_fingerprinter_decode(char *encoded_fp, int32_t **fp, int *size) {
int algorithm;
int encoded_size = strlen(encoded_fp);
- return chromaprint_decode_fingerprint(encoded_fp, encoded_size, (void**)fp, size,
+ int err = chromaprint_decode_fingerprint(encoded_fp, encoded_size, (void**)fp, size,
&algorithm, 1);
+ return err == 1 ? 0 : -1;
}
void groove_fingerprinter_dealloc(void *ptr) {
diff --git a/groovefingerprinter/fingerprinter.h b/groovefingerprinter/fingerprinter.h
index 69aa012..7f3f7de 100644
--- a/groovefingerprinter/fingerprinter.h
+++ b/groovefingerprinter/fingerprinter.h
@@ -18,8 +18,11 @@ extern "C"
/* use this to find out the unique id of an audio track */
struct GrooveFingerprinterInfo {
- /* Compressed string. */
- char *fingerprint;
+ /* raw fingerprint. A fingerprint is an array of signed 32-bit integers. */
+ int32_t *fingerprint;
+ /* the number of 32-bit integers in the fingerprint array */
+ int fingerprint_size;
+
/* how many seconds long this song is */
double duration;
@@ -93,7 +96,7 @@ void groove_fingerprinter_position(struct GrooveFingerprinter *printer,
* stored
*
* Returns:
- * - 0 on error, 1 on success
+ * - 0 on success, < 0 on error
*/
int groove_fingerprinter_encode(int32_t *fp, int size, char **encoded_fp);
@@ -111,7 +114,7 @@ int groove_fingerprinter_encode(int32_t *fp, int size, char **encoded_fp);
* - size: Number of items in the returned raw fingerprint
*
* Returns:
- * - 0 on error, 1 on success
+ * - 0 on success, < 0 on error
*/
int groove_fingerprinter_decode(char *encoded_fp, int32_t **fp, int *size);
--
libgroove packaging
More information about the pkg-multimedia-commits
mailing list