HarmonyOSClibmpvVela Player

Shutdown Deadlock, 8 MiB Cutoffs, and an API 20 Crash in Vela Player 1.3.x

Before shipping Vela Player 1.3.1 and 1.3.2 on HUAWEI AppGallery (where downloads have now passed 4,000), a deep code audit uncovered 44 issues. The four P0 bugs were all in native C boundaries, TLS threading, and HarmonyOS API gating.

Vela Player has moved from 1.0.4 to 1.3.2 on HUAWEI AppGallery and passed 4,000 downloads. Right before 1.3.1, a full audit against 8e9a082 (docs/deep-review-2026-11-19.md) logged 44 issues, 43 of which were fixed and verified locally.

Most UI fixes are routine. The four P0 bugs, however, lived at the boundaries between libmpv, FFmpeg avio, mbedTLS, and HarmonyOS SDK versions — the exact places normal happy-path clicks miss.

DR-01: Three-Way Shutdown Deadlock With MPV_RENDER_PARAM_ADVANCED_CONTROL

Enabling MPV_RENDER_PARAM_ADVANCED_CONTROL introduced an occasional hang when tearing down the player.

mq_mpv_destroy() used to set g_mpv.alive = 0 before calling mpv_command("quit"), while OnMpvRenderUpdate() checked g_mpv.alive before waking RenderThreadMain. With ADVANCED_CONTROL on, mpv’s core blocks synchronously inside mp_dispatch_run during quit, waiting for the render thread to call mpv_render_context_update(). Because alive was already 0, the render thread stayed asleep on pthread_cond_wait, leaving the JS main thread stuck waiting on "quit" and pthread_join. A second issue cleared frameWanted outside g_mpv_lock, leaving a lost-wakeup window.

The fix in entry/src/main/cpp/player/mpv_player.c separates callback detachment from render wakeup teardown:

pthread_mutex_lock(&g_mpv_lock);
g_mpv.cb = NULL;
g_mpv.cbCtx = NULL;
pthread_mutex_unlock(&g_mpv_lock);
if (g_mpv.mpv != NULL) {
    const char *cmd[] = { "quit", NULL };
    mpv_command(g_mpv.mpv, cmd);
}
if (g_mpv.eventThreadUp) {
    pthread_join(g_mpv.eventThread, NULL);
    g_mpv.eventThreadUp = 0;
}
pthread_mutex_lock(&g_mpv_lock);
g_mpv.alive = 0;
atomic_store(&g_mpv.quitting, 1);
pthread_cond_broadcast(&g_mpv_cond);
pthread_mutex_unlock(&g_mpv_lock);

OnMpvRenderUpdate() now checks g_mpv.renderThreadUp && !atomic_load(&g_mpv.quitting), and frameWanted is cleared inside g_mpv_lock. Verified by code-path timing review and release/debug hvigorw assembleHap native compilation (not separately stress-tested on physical hardware).

DR-02: Non-Range HTTP Streams Stopping Dead at 8 MiB

Vela’s stream bridge reads HTTP sources in bounded 8 MiB Range chunks so flaky links can reopen cleanly. Some cloud drives and DLNA servers ignore Range and respond with 200 OK.

Setting r->httpNoRange = 1 wasn’t enough because r->chunkEnd remained 8 MiB and FFmpeg’s avio retained its default "end_offset". Once 8 MiB arrived, raw_read_phys tried reopening at off = 8 MiB, tripped r->httpNoRange && off > 0, and failed playback. Unknown-length streams shorter than 8 MiB failed the same way when AVERROR_EOF triggered a tail probe.

In entry/src/main/cpp/transcode/transcoder.c, non-Range streams now clear av_opt_set_int(r->avio, "end_offset", 0, AV_OPT_SEARCH_CHILDREN), set r->chunkEnd = INT64_MAX, and mark httpEof = 1 on AVERROR_EOF or n == 0 instead of reopening. Verified with 11 raw-I/O cases in tools/test-native-io.sh.

DR-03: Instant Crash on API 20–22 Devices

Vela targets minAPIVersion 19 and targetAPIVersion 20, yet pages/Index imported @hms.hds.hdsMaterial and used .barFloatingStyle — both introduced in @since 6.1.0(23).

Device.mainPage() routed sdkApiVersion >= 20 straight to pages/Index, crashing API 20–22 devices on launch. Routing now gates strictly on deviceInfo.sdkApiVersion >= 23 && !Device.isTv() (reused by the privacy-consent transition so the two never drift), covered by tools/test-core-regressions.cjs (52/52 passing).

DR-04: Unsynchronized TLS 1.3 PSA State in mbedTLS and LGPL libmpv

Our prebuilt mbedtls 3.6.2 enabled TLS 1.3 and MBEDTLS_PSA_CRYPTO_C without MBEDTLS_THREADING_C or MBEDTLS_THREADING_PTHREAD. The old --wrap=mbedtls_ctr_drbg_* linker wrapper left global PSA key slots, entropy, x509, and libmpv.so’s copy unprotected. Meanwhile, build-mpv.sh defaulted to -Dgpl=true.

Rebuilding mbedtls, libssh2, ffmpeg, and mpv with pthread threading enabled (verifying mbedtls_threading_key_slot_mutex via llvm-nm before removing the old --wrap shim) and switching build-mpv.sh to -Dgpl=false resolved both. Verified via tools/test-native-tls.py (6/6) and bash tools/check-hap-deps.sh.

✦

Comments

  • Loading…

Comments are reviewed before publishing; email is visible only to me.