feat: 打通音频整链,被控端送 PCM、主控端 waveOut 播放
- android_receiver:音频改为直接送 PCM16(FLAG_PCM=0x80),不再走 Opus 编码 (仓库未打包 libopus,MediaCodec Opus 多数设备不可用,主控端也无解码器) - rust_core:新增 media/audio 播放队列(上限 1 秒、按帧对齐切分、超出丢最旧) - rust_core:音频分片校验 MAC 后按 FLAG_PCM 入队,旧 Opus 包明确丢弃并记日志 - rust_core:新增 ttstd_audio_next / ttstd_audio_pending / ttstd_audio_stats - flutter_sender:新增 audio_player(waveOut)轮询播放队列,有数据才打开设备、静音 3 秒自动关闭 - docs:README 增加音频链路章节与 PCM 取舍,AGENTS 记录 FLAG_PCM 约定
This commit is contained in:
1 parent
c6925d0890
commit
37b2cff82b
14 files changed
+468
-19
No files matched your search
@@ -19,7 +19,6 @@ import com.ttstd.lancast.receiver.discovery.AnnouncedDevice
|
||||
import com.ttstd.lancast.receiver.discovery.HostBeacon
|
||||
import com.ttstd.lancast.receiver.discovery.NsdAdvertiser
|
||||
import com.ttstd.lancast.receiver.discovery.ReceiverAnnouncer
|
||||
import com.ttstd.lancast.receiver.encode.OpusEncoder
|
||||
import com.ttstd.lancast.receiver.encode.VideoEncoder
|
||||
import com.ttstd.lancast.receiver.file.FileBrowser
|
||||
import com.ttstd.lancast.receiver.file.FileService
|
||||
@@ -65,7 +64,6 @@ class ReceiverSession(
|
||||
private val clipboard = ClipboardBridge(context)
|
||||
private val injector = InputInjector(context)
|
||||
private val fileService = FileService(File(context.filesDir, "file-inbox"), FileBrowser(context))
|
||||
private val opusEncoder = OpusEncoder()
|
||||
private val displayManager = context.getSystemService(DisplayManager::class.java)
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
/** 本机身份指纹(应用签名证书 SHA-256),用于主控端 TOFU pinning。 */
|
||||
@@ -143,7 +141,6 @@ class ReceiverSession(
|
||||
running = true
|
||||
maxLongSide = computeMaxLongSide()
|
||||
displayManager?.registerDisplayListener(displayListener, mainHandler)
|
||||
opusEncoder.start()
|
||||
clipboard.start { text ->
|
||||
if (clipboardSyncEnabled) transport?.sendControl(ControlEvent.Clipboard(text))
|
||||
}
|
||||
@@ -252,9 +249,8 @@ class ReceiverSession(
|
||||
} else {
|
||||
audio = AudioCapturer(active) { pcm ->
|
||||
val transport = transport ?: return@AudioCapturer
|
||||
opusEncoder.encode(pcm).forEach { packet ->
|
||||
transport.sendAudio(packet, SystemClock.elapsedRealtimeNanos() / 1000)
|
||||
}
|
||||
// 主控端没有 Opus 解码器:直接把 PCM 送过去,省掉一次编解码。
|
||||
transport.sendAudio(pcm, SystemClock.elapsedRealtimeNanos() / 1000)
|
||||
}.also { it.start() }
|
||||
}
|
||||
} else if (active == null) {
|
||||
@@ -428,7 +424,6 @@ class ReceiverSession(
|
||||
clipboard.stop()
|
||||
announcer?.stop()
|
||||
nsdAdvertiser?.stop()
|
||||
opusEncoder.stop()
|
||||
transport?.stop()
|
||||
transport = null
|
||||
runCatching { encoder.stop() }
|
||||
|
||||
@@ -10,6 +10,9 @@ object MediaPackets {
|
||||
const val FLAG_AUDIO = 2
|
||||
// 与 Rust Core 的 media::stream 保持一致的扩展标志位。
|
||||
const val FLAG_HEVC = 0x08
|
||||
// 音频负载是裸 PCM16(48 kHz 双声道小端)。主控端没有 Opus 解码器,
|
||||
// 因此实时链路直接送 PCM;未置位时主控端会把音频当不支持的编码丢弃。
|
||||
const val FLAG_PCM = 0x80
|
||||
const val FLAG_FRAGMENT_START = 0x10
|
||||
const val FLAG_FRAGMENT_CONTINUE = 0x20
|
||||
const val FLAG_FRAGMENT_END = 0x40
|
||||
|
||||
+4
-2
@@ -400,10 +400,12 @@ class ReceiverTransport(
|
||||
}
|
||||
}
|
||||
|
||||
fun sendAudio(opusPacket: ByteArray, pts: Long) {
|
||||
/** 发送一段 PCM16(48 kHz 双声道);主控端直接播放,不做解码。 */
|
||||
fun sendAudio(pcm: ByteArray, pts: Long) {
|
||||
val key = keys?.audio ?: return
|
||||
if (!running) return
|
||||
val packet = MediaPackets.encode(opusPacket, pts, MediaPackets.FLAG_AUDIO, key)
|
||||
val flags = MediaPackets.FLAG_AUDIO or MediaPackets.FLAG_PCM
|
||||
val packet = MediaPackets.encode(pcm, pts, flags, key)
|
||||
dispatchMedia(false, packet, InetSocketAddress(host, audioPort))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user