summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-06-24 20:46:20 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-06-24 20:46:20 +0200
commit328e87cc94bb0204ba557534c53f7c58c67b1580 (patch)
tree86b7943a59d57745864a7b2e8079dc2668f7a111 /plugins
parent40096d01c93b5b6d58b26a183b5cb641277ec52e (diff)
artwork: added vfs support for reading from flacs
Diffstat (limited to 'plugins')
-rw-r--r--plugins/artwork/artwork.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
index 9a3caa76..612e4f1e 100644
--- a/plugins/artwork/artwork.c
+++ b/plugins/artwork/artwork.c
@@ -906,6 +906,43 @@ id3v2_skip_str (int enc, uint8_t *ptr, uint8_t *end) {
return NULL;
}
+#ifdef USE_METAFLAC
+static size_t
+flac_io_read (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) {
+ return deadbeef->fread (ptr, size, nmemb, (DB_FILE *)handle);
+}
+
+static int
+flac_io_seek (FLAC__IOHandle handle, FLAC__int64 offset, int whence) {
+ return deadbeef->fseek ((DB_FILE *)handle, offset, whence);
+}
+
+static FLAC__int64
+flac_io_tell (FLAC__IOHandle handle) {
+ return deadbeef->ftell ((DB_FILE *)handle);
+}
+
+static int
+flac_io_eof (FLAC__IOHandle handle) {
+ int64_t pos = deadbeef->ftell ((DB_FILE *)handle);
+ return pos == deadbeef->fgetlength ((DB_FILE *)handle);
+}
+
+static int
+flac_io_close (FLAC__IOHandle handle) {
+ deadbeef->fclose ((DB_FILE *)handle);
+ return 0;
+}
+
+static FLAC__IOCallbacks iocb = {
+ .read = flac_io_read,
+ .write = NULL,
+ .seek = flac_io_seek,
+ .tell = flac_io_tell,
+ .eof = flac_io_eof,
+ .close = flac_io_close,
+};
+#endif
static void
fetcher_thread (void *none)
@@ -1112,11 +1149,18 @@ fetcher_thread (void *none)
is_ogg = 1;
}
- if(! (is_ogg? FLAC__metadata_chain_read_ogg(chain, filename) : FLAC__metadata_chain_read(chain, filename)) ) {
+ DB_FILE *file = deadbeef->fopen (filename);
+ if (!file) {
+ break;
+ }
+
+ if(! (is_ogg? FLAC__metadata_chain_read_ogg_with_callbacks(chain, (FLAC__IOHandle)file, iocb) : FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, iocb)) ) {
trace ("%s: ERROR: reading metadata", filename);
+ deadbeef->fclose (file);
FLAC__metadata_chain_delete(chain);
break;
}
+ deadbeef->fclose (file);
FLAC__StreamMetadata *picture = 0;
FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
FLAC__metadata_iterator_init(iterator, chain);