|
|
@ -1,8 +1,8 @@ |
|
|
|
#include "tag_processor.hpp" |
|
|
|
#include "tag_processor.hpp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <esp_log.h> |
|
|
|
#include <ff.h> |
|
|
|
#include <ff.h> |
|
|
|
#include <tags.h> |
|
|
|
#include <tags.h> |
|
|
|
#include <esp_log.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace database { |
|
|
|
namespace database { |
|
|
|
|
|
|
|
|
|
|
@ -16,36 +16,41 @@ struct Aux { |
|
|
|
std::string title; |
|
|
|
std::string title; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static int read(Tagctx *ctx, void *buf, int cnt) { |
|
|
|
static int read(Tagctx* ctx, void* buf, int cnt) { |
|
|
|
Aux *aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
Aux* aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
UINT bytes_read; |
|
|
|
UINT bytes_read; |
|
|
|
if (f_read(&aux->file, buf, cnt, &bytes_read) != FR_OK) { |
|
|
|
if (f_read(&aux->file, buf, cnt, &bytes_read) != FR_OK) { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
return bytes_read; |
|
|
|
return bytes_read; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int seek(Tagctx *ctx, int offset, int whence) { |
|
|
|
static int seek(Tagctx* ctx, int offset, int whence) { |
|
|
|
Aux *aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
Aux* aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
FRESULT res; |
|
|
|
FRESULT res; |
|
|
|
if (whence == 0) { |
|
|
|
if (whence == 0) { |
|
|
|
// Seek from the start of the file. This is f_lseek's behaviour.
|
|
|
|
// Seek from the start of the file. This is f_lseek's behaviour.
|
|
|
|
res = f_lseek(&aux->file, offset); |
|
|
|
res = f_lseek(&aux->file, offset); |
|
|
|
} else if (whence == 1) { |
|
|
|
} else if (whence == 1) { |
|
|
|
// Seek from current offset.
|
|
|
|
// Seek from current offset.
|
|
|
|
res = f_lseek(&aux->file, aux->file.fptr + offset); |
|
|
|
res = f_lseek(&aux->file, aux->file.fptr + offset); |
|
|
|
} else if (whence == 2) { |
|
|
|
} else if (whence == 2) { |
|
|
|
// Seek from the end of the file
|
|
|
|
// Seek from the end of the file
|
|
|
|
res = f_lseek(&aux->file, aux->info.fsize + offset); |
|
|
|
res = f_lseek(&aux->file, aux->info.fsize + offset); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void tag(Tagctx* ctx, |
|
|
|
tag(Tagctx *ctx, int t, const char *k, const char *v, int offset, int size, Tagread f) { |
|
|
|
int t, |
|
|
|
Aux *aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
const char* k, |
|
|
|
|
|
|
|
const char* v, |
|
|
|
|
|
|
|
int offset, |
|
|
|
|
|
|
|
int size, |
|
|
|
|
|
|
|
Tagread f) { |
|
|
|
|
|
|
|
Aux* aux = reinterpret_cast<Aux*>(ctx->aux); |
|
|
|
if (t == Ttitle) { |
|
|
|
if (t == Ttitle) { |
|
|
|
aux->title = v; |
|
|
|
aux->title = v; |
|
|
|
} else if (t == Tartist) { |
|
|
|
} else if (t == Tartist) { |
|
|
@ -55,30 +60,30 @@ tag(Tagctx *ctx, int t, const char *k, const char *v, int offset, int size, Tagr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void toc(Tagctx* ctx, int ms, int offset) {} |
|
|
|
toc(Tagctx *ctx, int ms, int offset) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace libtags
|
|
|
|
} // namespace libtags
|
|
|
|
|
|
|
|
|
|
|
|
static const std::size_t kBufSize = 1024; |
|
|
|
static const std::size_t kBufSize = 1024; |
|
|
|
static const char* kTag = "TAGS"; |
|
|
|
static const char* kTag = "TAGS"; |
|
|
|
|
|
|
|
|
|
|
|
auto GetInfo(const std::string& path, FileInfo* out) -> bool { |
|
|
|
auto GetInfo(const std::string& path, FileInfo* out) -> bool { |
|
|
|
libtags::Aux aux; |
|
|
|
libtags::Aux aux; |
|
|
|
if (f_stat(path.c_str(), &aux.info) != FR_OK || f_open(&aux.file, path.c_str(), FA_READ) != FR_OK) { |
|
|
|
if (f_stat(path.c_str(), &aux.info) != FR_OK || |
|
|
|
|
|
|
|
f_open(&aux.file, path.c_str(), FA_READ) != FR_OK) { |
|
|
|
ESP_LOGI(kTag, "failed to open file"); |
|
|
|
ESP_LOGI(kTag, "failed to open file"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
// Fine to have this on the stack; this is only called on the leveldb task.
|
|
|
|
// Fine to have this on the stack; this is only called on the leveldb task.
|
|
|
|
char buf[kBufSize]; |
|
|
|
char buf[kBufSize]; |
|
|
|
Tagctx ctx; |
|
|
|
Tagctx ctx; |
|
|
|
ctx.read = libtags::read; |
|
|
|
ctx.read = libtags::read; |
|
|
|
ctx.seek = libtags::seek; |
|
|
|
ctx.seek = libtags::seek; |
|
|
|
ctx.tag = libtags::tag; |
|
|
|
ctx.tag = libtags::tag; |
|
|
|
ctx.toc = libtags::toc; |
|
|
|
ctx.toc = libtags::toc; |
|
|
|
ctx.aux = &aux; |
|
|
|
ctx.aux = &aux; |
|
|
|
ctx.buf = buf; |
|
|
|
ctx.buf = buf; |
|
|
|
ctx.bufsz = kBufSize; |
|
|
|
ctx.bufsz = kBufSize; |
|
|
|
int res = tagsget(&ctx); |
|
|
|
int res = tagsget(&ctx); |
|
|
|
f_close(&aux.file); |
|
|
|
f_close(&aux.file); |
|
|
|
|
|
|
|
|
|
|
|