Feature: Support voice monitoring on Android hosts

The master's voice monitoring menu sends COMMAND_AUDIO; the client opens a
ConnAuth sub-connection with TOKEN_AUDIO_START, the server opens CAudioDlg
and answers COMMAND_NEXT, then audio flows both ways. The protocol matches
the Windows client, so the server needs no changes.

The server's ACM format was read from Audio.cpp and AudioDlg.cpp first:
WAVE_FORMAT_GSM610, 8000 Hz mono, 65-byte blocks of 320 samples (40 ms),
about 1625 B/s. libgsm 1.0.13 (AOSP external/libgsm mirror) is vendored
under cpp/gsm and built with -DSASR -DWAV49 so its MS-GSM packing is
byte-identical to ACM GSM610. Encode and decode use separate gsm states
because frame_index/frame_chain live in the state.

Uplink packets are always exactly 1000 bytes: CAudio::PlayBuffer copies
1000 bytes from the buffer start regardless of packet length, so a short
packet would over-read. Since 1000 is not a multiple of 65, blocks
straddle packets; the stream is continuous and codec state carries over.

AudioMonitor.kt owns AudioRecord (8 kHz/16-bit/mono, 320 samples a read)
and AudioTrack playback of decoded downlink PCM. RECORD_AUDIO is requested
with POST_NOTIFICATIONS before the projection dialog, and CaptureService
adds the microphone FGS type only when held, falling back on failure. An
8-second dialog wait or missing microphone reports a tip to the master
instead of failing silently.

Verified on an Android 15 emulator against the Debug server: dialog
opened, uplink started, server receive counter grew at ~1.6 KB/s.
Downlink playback was not exercised (the test machine has no recording
device); that path is code-reviewed only.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-11 21:58:54 +01:00
1 parent 3ab5154db1
commit 4aedca8ee0
31 files changed
+4979 -22

No files matched your search

+25
View File
@@ -34,6 +34,29 @@ set(ANDROID_SOURCES
main.cpp
)
# ---- libgsm(语音监听:服务端 AudioDlg 要 GSM 6.10/WAV49,见 gsm/README.md)----
# WAV49 = MS-GSM 打包(65 字节/320 采样),与 Windows ACM 的 WAVE_FORMAT_GSM610 一致。
# SASR 是 AOSP Android.mk 里的定点右移开关,必须与它保持一致。
set(GSM_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/add.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/code.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/decode.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/gsm_create.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/gsm_decode.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/gsm_destroy.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/gsm_encode.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/gsm_option.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/long_term.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/lpc.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/preprocess.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/rpe.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/short_term.c
${CMAKE_CURRENT_SOURCE_DIR}/gsm/src/table.c
)
add_library(gsm610 STATIC ${GSM_SOURCES})
target_include_directories(gsm610 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gsm/inc")
target_compile_options(gsm610 PRIVATE -DSASR -DWAV49 -O2 -fvisibility=hidden -Wno-unused-parameter)
add_library(yama SHARED ${CORE_SOURCES} ${ANDROID_SOURCES})
# ---- 预编译静态库(由 android/build_android_libs.ps1 产出)----
@@ -55,6 +78,8 @@ target_link_libraries(yama PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}/libssl.a"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}/libcrypto.a"
)
# 语音监听(GSM 6.10/WAV49);符号由下面的 --exclude-libs,ALL 一并隐藏
target_link_libraries(yama PRIVATE gsm610)
# 不把静态库(OpenSSL/sign/zstd)的符号导出到 libyama.so 之外,与 Java 层 Conscrypt 隔离;
# JNI 入口来自目标文件(非归档),不受影响,仍正常导出。
target_link_options(yama PRIVATE "-Wl,--exclude-libs,ALL")