fix(native-worker): preserve requested output container in finalizer

When the native worker result advertises a requested non-FLAC output extension (for example '.m4a'), skip the m4a-to-flac container conversion in both the Dart and Kotlin finalizers so the native output container is preserved end-to-end.

- ffmpeg_service: propagate the top-level 'output_extension' hint into the download-result descriptor for both the map-backed and legacy paths; expose a normalized getter for consistent comparisons.

- download_queue_provider: short-circuit the native-worker container-conversion step when the descriptor's requested extension is not '.flac', with a debug log describing the skip.

- NativeDownloadFinalizer: mirror the guard on the Kotlin side so the finalizer does not force a container conversion that would clobber the requested native output.
This commit is contained in:
zarzet
2026-05-09 01:18:17 +07:00
parent 904b45e8f6
commit 20ac6b2cd4
3 changed files with 30 additions and 3 deletions
@@ -501,6 +501,8 @@ object NativeDownloadFinalizer {
shouldCancel: () -> Boolean,
) {
if (requestQuality(input) == "HIGH" || outputExt(input) != ".flac") return
val requestedDecryptionExt = requestedDecryptionOutputExt(input)
if (requestedDecryptionExt.isNotBlank() && requestedDecryptionExt != ".flac") return
if (!looksLikeM4a(state.filePath, state.fileName) && !shouldForceContainerConversion(input, state)) return
val localInput = materializeForFFmpeg(context, input, state)
@@ -1330,6 +1332,14 @@ object NativeDownloadFinalizer {
return container == "m4a" || container == "mp4" || container == "mov" || container == "aac"
}
private fun requestedDecryptionOutputExt(input: FinalizeInput): String {
val descriptor = input.result.optJSONObject("decryption")
return normalizeExt(
descriptor?.optString("output_extension", "")
?.ifBlank { input.result.optString("output_extension", "") }
)
}
private fun validateRequestContract(request: JSONObject) {
val version = request.optInt("contract_version", -1)
if (version != NATIVE_WORKER_CONTRACT_VERSION) {