feat(ncm): 首页顶栏「已缓存」入口 + 已缓存列表页(歌名/歌手/实际档位/大小,点播/单曲删除/清空)
入口:首页 topbar 新增动作 3(MEOW_ICON_DOWNLOAD 位图,原「回播放页」顺延动作 4)→ push ACT_CACHE;左缘返回弹回首页(app.c 路由补齐 tap/swipe/touch/tick)。 列表页 app/ui/cache.c(对齐 queue.c 惯例:圆角卡/红 mini-vinyl/按压红条/当前播放行高亮): - 行 = 歌名 / 歌手 · 实际档位 · 大小;空态/页脚(N 首 · 合计 X MB)。 - 点行 = 点播(NCM_QUEUE_CACHE 队列,上/下一首在缓存列表内循环);行右「删除」=单曲删除; 顶栏「清空」=确认框 + ncm_cache_clear(与设置页「清理缓存」同语义)。 - 数据全在 worker:cache_reload → appstate_cache_list_load → ncm_cache_scan(读目录 + 文件内 tag + 音频头探测)→ 快照;UI 线程零磁盘 IO。快照上限 512 条(最近访问优先, ≈116KB bss),更多条目按 mtime 保留最近的。 core: - ncm_cache_scan / ncm_cache_remove(songs/ 池,song_<id>_<请求档>.<实际格式> 解析, 跳过 .tmp/.part 与非数字 id;按 mtime 降序;历史双点名删除兜底)。 - ncm_api_level_from_key(缓存键后缀 ↔ 档位枚举,与 ncm_api_level_key 互逆)。 - **档位显示实际档而非请求档**:真机存在 song_171650_hires.mp3(无损请求被降级链落到 exhigh mp3),故 scan 用 ncm_audio_probe_file 读实际容器参数后只降不升地推断 (FLAC 16bit→无损 / 24bit→Hi-Res+,MP3 ≤128k→标准 / >128k→极高)。 播放:player_manager 对 NCM_QUEUE_CACHE 用条目真实键(id+请求档+实际扩展名)直读缓存 文件,不按用户当前档键重下;song_local_file/play_is_same_song/queue 页均支持第三种队列。 宿主 mock(NCM_PAGE=cache)造 3 条缓存 + 嵌入 tag + 同步扫描。
This commit is contained in:
1 parent
184ebd0ac9
commit
f392ee5c48
16 files changed
+829
-18
No files matched your search
@@ -783,6 +783,7 @@ void appstate_apply_play_mode(int m)
|
||||
int appstate_queue_count(void)
|
||||
{
|
||||
int c;
|
||||
if (g_st.queue_src == NCM_QUEUE_CACHE) return appstate_cache_count();
|
||||
pthread_mutex_lock(&g_search_mu);
|
||||
c = (g_st.queue_src == NCM_QUEUE_SEARCH) ? g_st.search_song_count : g_st.track_ids_count;
|
||||
pthread_mutex_unlock(&g_search_mu);
|
||||
@@ -792,6 +793,7 @@ int appstate_queue_count(void)
|
||||
int appstate_queue_song(int idx, ncm_song_t *out)
|
||||
{
|
||||
if (!out) return NCM_ERR_ARG;
|
||||
if (g_st.queue_src == NCM_QUEUE_CACHE) return appstate_cache_song(idx, out);
|
||||
if (g_st.queue_src == NCM_QUEUE_SEARCH) {
|
||||
pthread_mutex_lock(&g_search_mu);
|
||||
int ok = (idx >= 0 && idx < g_st.search_song_count);
|
||||
@@ -803,6 +805,105 @@ int appstate_queue_song(int idx, ncm_song_t *out)
|
||||
return appstate_song_fetch(idx, out);
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 已缓存列表(ACT_CACHE / NCM_QUEUE_CACHE;数据源 = songs/ 池 + 文件内 tag)
|
||||
* 数组读写经 g_cache_mu;扫描走 worker(磁盘 IO 不进 UI 线程)。
|
||||
* ============================================================ */
|
||||
static pthread_mutex_t g_cache_mu = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
int appstate_cache_list_load(void)
|
||||
{
|
||||
/* 堆上临时数组(≈116KB):扫描期间不持锁,UI/播放线程读旧快照不被 IO 阻塞。 */
|
||||
ncm_cache_item_t *tmp = (ncm_cache_item_t *)malloc(sizeof(ncm_cache_item_t) * NCM_CACHE_LIST_MAX);
|
||||
if (!tmp) return NCM_ERR_OOM;
|
||||
int n = ncm_cache_scan(&g_st.ctx.cache, tmp, NCM_CACHE_LIST_MAX);
|
||||
if (n < 0) { free(tmp); return n; }
|
||||
/* 旧无 tag 缓存:回退旁路元数据(songmeta)补名称/歌手,保持列表可读。 */
|
||||
for (int i = 0; i < n; i++) {
|
||||
ncm_song_t s;
|
||||
if (tmp[i].name[0] && tmp[i].artist[0]) continue;
|
||||
if (songmeta_load(g_st.cache_dir, tmp[i].id, &s) != NCM_OK) continue;
|
||||
if (!tmp[i].name[0]) ncm_strlcpy(tmp[i].name, s.name, sizeof tmp[i].name);
|
||||
if (!tmp[i].artist[0]) ncm_strlcpy(tmp[i].artist, s.art_name, sizeof tmp[i].artist);
|
||||
}
|
||||
pthread_mutex_lock(&g_cache_mu);
|
||||
memcpy(g_st.cache_items, tmp, sizeof(ncm_cache_item_t) * (size_t)n);
|
||||
g_st.cache_item_count = n;
|
||||
pthread_mutex_unlock(&g_cache_mu);
|
||||
free(tmp);
|
||||
return n;
|
||||
}
|
||||
|
||||
int appstate_cache_count(void)
|
||||
{
|
||||
int n;
|
||||
pthread_mutex_lock(&g_cache_mu);
|
||||
n = g_st.cache_item_count;
|
||||
pthread_mutex_unlock(&g_cache_mu);
|
||||
return n < 0 ? 0 : n;
|
||||
}
|
||||
|
||||
int appstate_cache_item(int i, ncm_cache_item_t *out)
|
||||
{
|
||||
if (!out) return NCM_ERR_ARG;
|
||||
pthread_mutex_lock(&g_cache_mu);
|
||||
int ok = (i >= 0 && i < g_st.cache_item_count);
|
||||
if (ok) *out = g_st.cache_items[i];
|
||||
pthread_mutex_unlock(&g_cache_mu);
|
||||
return ok ? NCM_OK : NCM_ERR_ARG;
|
||||
}
|
||||
|
||||
int appstate_cache_song(int i, ncm_song_t *out)
|
||||
{
|
||||
ncm_cache_item_t it;
|
||||
ncm_song_t m;
|
||||
if (!out) return NCM_ERR_ARG;
|
||||
if (appstate_cache_item(i, &it) != NCM_OK) return NCM_ERR_ARG;
|
||||
memset(out, 0, sizeof *out);
|
||||
ncm_strlcpy(out->id, it.id, sizeof out->id);
|
||||
ncm_strlcpy(out->name, it.name[0] ? it.name : it.id, sizeof out->name);
|
||||
ncm_strlcpy(out->art_name, it.artist, sizeof out->art_name);
|
||||
/* 旁路元数据(≤600B 单次读)补时长/封面/fee;播放页与上/下一首逻辑照旧可用。 */
|
||||
if (songmeta_load(g_st.cache_dir, it.id, &m) == NCM_OK) {
|
||||
if (!it.name[0] && m.name[0]) ncm_strlcpy(out->name, m.name, sizeof out->name);
|
||||
if (!it.artist[0] && m.art_name[0]) ncm_strlcpy(out->art_name, m.art_name, sizeof out->art_name);
|
||||
out->duration_ms = m.duration_ms;
|
||||
out->fee = m.fee;
|
||||
ncm_strlcpy(out->al_pic, m.al_pic, sizeof out->al_pic);
|
||||
}
|
||||
return NCM_OK;
|
||||
}
|
||||
|
||||
int appstate_cache_remove(int i)
|
||||
{
|
||||
ncm_cache_item_t it;
|
||||
int rc;
|
||||
if (appstate_cache_item(i, &it) != NCM_OK) return NCM_ERR_ARG;
|
||||
/* 条目可能已被 LRU/清空删掉:NOENT 也算「已不在」,照样摘除列表项。 */
|
||||
rc = ncm_cache_remove(&g_st.ctx.cache, it.id, it.level, it.ext);
|
||||
if (rc != NCM_OK && rc != NCM_ERR_NOENT) return rc;
|
||||
pthread_mutex_lock(&g_cache_mu);
|
||||
for (int k = 0; k < g_st.cache_item_count; k++) {
|
||||
if (strcmp(g_st.cache_items[k].id, it.id) != 0 ||
|
||||
strcmp(g_st.cache_items[k].level, it.level) != 0 ||
|
||||
strcmp(g_st.cache_items[k].ext, it.ext) != 0) continue;
|
||||
memmove(&g_st.cache_items[k], &g_st.cache_items[k + 1],
|
||||
sizeof(ncm_cache_item_t) * (size_t)(g_st.cache_item_count - k - 1));
|
||||
g_st.cache_item_count--;
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&g_cache_mu);
|
||||
return NCM_OK;
|
||||
}
|
||||
|
||||
void appstate_cache_clear(void)
|
||||
{
|
||||
ncm_cache_clear(&g_st.ctx.cache); /* songs/ + covers/ 的 song_*(设置页同语义) */
|
||||
pthread_mutex_lock(&g_cache_mu);
|
||||
g_st.cache_item_count = 0;
|
||||
pthread_mutex_unlock(&g_cache_mu);
|
||||
}
|
||||
|
||||
int appstate_search_count(int tab)
|
||||
{
|
||||
int c;
|
||||
|
||||
Reference in new issue
Block a user