|
|
|
@ -1755,6 +1755,23 @@ err:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *media_player_make_cache_entry_name(unsigned long long id) {
|
|
|
|
|
return g_strdup_printf("%s/%llu.blob", rtpe_config.db_media_cache, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void media_player_add_cache_file(const char *s, size_t len, unsigned long long id) {
|
|
|
|
|
if (!rtpe_config.db_media_cache)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_autoptr(char) fn = media_player_make_cache_entry_name(id);
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
gboolean ok = g_file_set_contents(fn, s, len, &err);
|
|
|
|
|
if (!ok) {
|
|
|
|
|
ilog(LOG_WARN, "Failed to write to cache file '%s': %s", fn, err->message);
|
|
|
|
|
g_error_free(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *media_player_get_db_id(str *out, unsigned long long id, str (*dup_fn)(const char *, size_t))
|
|
|
|
|
{
|
|
|
|
@ -1802,6 +1819,8 @@ success:;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
media_player_add_cache_file(row[0], lengths[0], id);
|
|
|
|
|
|
|
|
|
|
*out = dup_fn(row[0], lengths[0]);
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
@ -1828,6 +1847,24 @@ static mp_cached_code __media_player_add_db(struct media_player *mp,
|
|
|
|
|
return media_player_set_media_file(mp, opts, dst_pt, fo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// or maybe we have a cache file for it
|
|
|
|
|
if (rtpe_config.db_media_cache) {
|
|
|
|
|
g_autoptr(char) fn = media_player_make_cache_entry_name(opts.db_id);
|
|
|
|
|
gchar *buf = NULL;
|
|
|
|
|
gsize len = -1;
|
|
|
|
|
gboolean ret = g_file_get_contents(fn, &buf, &len, NULL);
|
|
|
|
|
if (ret && len > 0) {
|
|
|
|
|
// use this as blob and play it
|
|
|
|
|
ilog(LOG_DEBUG, "Using cached file of DB media for playback");
|
|
|
|
|
// use a `media_player_media_file` object to hold a reference on the g_malloc'd
|
|
|
|
|
// data to avoid having to memcpy it
|
|
|
|
|
fo = media_player_media_file_new(STR_LEN(buf, len));
|
|
|
|
|
return media_player_set_media_file(mp, opts, dst_pt, fo);
|
|
|
|
|
}
|
|
|
|
|
if (ret) // zero-length file
|
|
|
|
|
g_free(buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = media_player_get_db_id(&opts.blob, opts.db_id, call_str_cpy_len);
|
|
|
|
|
if (err)
|
|
|
|
|
return MPC_ERR;
|
|
|
|
|