Fax: over T.38 end to end; none on mobile calls

T.38 tested end to end (SipFaxTest): the app's engine dialling dmodemd,
which asks for T.38 a second after it answers, before its CED; the
engine's call progress then waited for a CED that never came on audio.
D-Modem-RE's claude/t38-caller (the submodule here) takes T.38 on a fax
call still waiting for its answer tone as the answer. With ECM and
without, and on audio with T.38 off.

Fax through a mobile call's speech codec doesn't train even at 2400
bit/s (CellFaxTest: AMR-NB 12.2, about a bit in sixteen wrong), so the
app turns fax down on the mobile-call line with why.

The interop test receiving without ECM from D-Modem-RE's T.30 at 12000:
at 14400 a page's row of 1-pel runs comes spoilt the same way each time
on a clean line, before our T.30 (D-Modem-RE's DSP; ECM hides it).
sip_fax_line waits for its dmodemd to end; the README's fax section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
Claude committed 2026-10-17 19:30:16 +00:00
1 parent 97a816ee45
commit 58de26df2e
9 files changed
+139 -8

No files matched your search

+19
View File
@@ -28,6 +28,25 @@ speech through codecs that wreck modem signals; native-test's
So the mobile-call line starts the modem at V.21 (+MS=V21), with 1200 and
2400 bit/s as settings to try.
Fax doesn't get through at all (V.27ter's training at 2400 bit/s comes
through AMR 12.2 with about one bit in sixteen wrong), so the app turns
fax down on that line.
Two phones with the app can also be each other's line, over Wi-Fi or
Bluetooth, with no SIP account: the modems connect as over a perfect line.
An optional PIN, the same on both phones, keeps other callers out (a
challenge and response: the PIN never goes over the connection).
## Fax
Class 1 fax (T.30, MH coding, V.27ter, V.29 and V.17 up to 14400 bit/s),
sending PDFs and images and receiving into PDFs, on the SIP line (audio,
or T.38 when the far end asks for it) and the line to another phone.
Error correction mode (T.30 Annex A) when the other machine has it: the
page in numbered HDLC frames, those a noisy line spoils sent again. Tested
against efax, against D-Modem-RE's own T.30 machine (native-test's
`t30_line`, on a clean line and a noisy one), and over SIP with T.38
between the app's engine and dmodemd (`sip_fax_line`).
## The app
@@ -8,6 +8,7 @@ import com.neodesktop.dmodem.bridge.Bridges
import com.neodesktop.dmodem.modem.ModemState
import com.neodesktop.dmodem.settings.FaxSettings
import com.neodesktop.dmodem.settings.FaxSettingsStore
import com.neodesktop.dmodem.settings.ModemSettings
import com.neodesktop.dmodem.terminal.JsonListStore
import com.neodesktop.dmodem.terminal.TerminalLink
import com.neodesktop.dmodem.transfer.DownloadsIncoming
@@ -86,10 +87,19 @@ object Fax {
val running: Boolean get() = _state.value?.running == true
/**
* (a mobile call's speech codec spoils the fax modulations: through
* AMR-NB 12.2, the best of them, V.27ter's training at 2400 bit/s
* comes with about one bit in sixteen wrong, more than ECM can mend;
* CellFaxTest)
*/
private const val CELL_NO_FAX = "fax doesn't go through a mobile call (its speech codec spoils the fax signals): use a SIP account or the line to another phone"
/** why a fax can't start now, or null */
private fun busy(): String? = when {
ModemState.run.value != ModemState.Run.RUNNING -> "the modem is off"
running -> "a fax call is going on"
ModemState.line == ModemSettings.LINE_CELL -> CELL_NO_FAX
ModemState.status.value.offhook -> "the modem is in a call"
Bridges.serial.client.value != null -> "the modem is in use by ${Bridges.serial.client.value?.name}"
else -> null
@@ -226,6 +226,7 @@ class ModemService : Service() {
ModemState.dte.attach(pfd)
ModemState.setStatus(ModemState.IDLE)
ModemState.speaker.enabled = settings.speaker
ModemState.line = settings.line
// (the speaker's sound: one socket for the process, read for good once started)
NativeModem.speakerSound()?.let { s ->
speakerSocket = s
@@ -32,6 +32,9 @@ object ModemState {
/** The modem's DTE, shared by the console, the terminal and the bridges. */
val dte = DteHub()
/** the line the running modem is on (ModemSettings.LINE_*) */
@Volatile var line: String = com.neodesktop.dmodem.settings.ModemSettings.LINE_SIP
/** the modem's speaker on the phone's (ATM, ATL) */
val speaker = ModemSpeaker()
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Neo-Desktop
package com.neodesktop.dmodem.fax
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assume.assumeTrue
import org.junit.Test
/**
* Fax on a mobile call: two modems through a speech codec each way
* (native-test's codec_line, AMR-NB 12.2 kbit/s as a 3G/4G call has it,
* or DMODEM_CODEC_LINE; skipped without it), our T.30 on both. It
* doesn't get through: the app turns fax down on that line (Fax).
*/
class CellFaxTest {
private var line: FaxLineProcess? = null
@After
fun tearDown() {
line?.close()
}
private fun call(codec: String, maxBps: Int, ecm: Boolean): Pair<FaxProgress?, List<FaxPage>> {
val bin = nativeTool("DMODEM_CODEC_LINE", "codec_line")
assumeTrue("codec_line isn't built (native-test)", bin != null)
val l = FaxLineProcess(listOf(bin!!.path, codec))
line = l
val tx = l.modem("modemA", "a")
val rx = l.modem("modemB", "b")
assertEquals("OK", tx.command("E0X3+FCLASS=1"))
assertEquals("OK", rx.command("E0+FCLASS=1"))
val txRates = T30.modemRates(tx, maxBps)
val rxRates = T30.modemRates(rx, maxBps)
val pages = listOf(FaxTestPage.of(false, rows = 300, seed = 1))
val got = ArrayList<FaxPage>()
var rxError: Throwable? = null
rx.send("A")
tx.send("D")
val receiver = Thread {
try {
assertEquals("CONNECT", rx.result(20_000))
T30.receive(rx, "+1 555 0199", rxRates, ecm = ecm) { pg, _ -> got.add(pg) }
} catch (e: Throwable) {
rxError = e
}
}
receiver.start()
assertEquals(l.dump(), "CONNECT", tx.result(30_000))
val sent = try {
T30.send(tx, pages, "+1 555 0100", txRates, ecm = ecm)
} catch (e: Exception) {
println("$codec $maxBps ecm=$ecm: $e")
null
}
receiver.join(90_000)
println("$codec $maxBps ecm=$ecm: sent ${sent?.pages} at ${sent?.bps}, got ${got.size}, rx error $rxError")
if (sent != null && got.isNotEmpty()) {
println(" page same: ${pages[0].bits.contentEquals(got[0].bits)}")
}
println(l.log.filter { it.contains("frame") }.takeLast(40).joinToString("\n"))
return sent to got
}
@Test
fun throughNoCodecTheFaxGoes() {
// (the line itself, the codec out of it: the same modems, the same pacing)
val (sent, got) = call("none", 4800, ecm = true)
assertEquals(1, sent?.pages)
assertEquals(1, got.size)
}
@Test
fun throughAmrTheTrainingFails() {
// AMR-NB 12.2, the best a mobile call has: V.27ter's training at 2400 bit/s
// with about one bit in sixteen wrong, more than ECM's frames survive.
// (Why the app turns fax down on the mobile-call line.)
val (sent, got) = call("amr122", 4800, ecm = true)
assertEquals(null, sent)
assertEquals(0, got.size)
}
}
@@ -41,17 +41,23 @@ class SipFaxTest {
var rxDone: FaxProgress? = null
var rxError: Throwable? = null
tx.send("D5551000")
assertEquals(l.dump(), "RING", rx.result(20_000))
val ring = rx.result(20_000)
assertEquals(l.dump(), "RING", ring)
val receiver = Thread {
try {
assertEquals("CONNECT", rx.command("A", 20_000))
rx.send("A")
// (the RINGs still coming before it)
var r = rx.result(30_000)
while (r == "RING") r = rx.result(30_000)
assertEquals("CONNECT", r)
rxDone = T30.receive(rx, "+1 555 0199", rxRates, ecm = ecm) { pg, _ -> got.add(pg) }
} catch (e: Throwable) {
rxError = e
}
}
receiver.start()
assertEquals(l.dump(), "CONNECT", tx.result(30_000))
val connect = tx.result(30_000)
assertEquals(l.dump(200), "CONNECT", connect)
val sent = try {
T30.send(tx, pages, "+1 555 0100", txRates, ecm = ecm)
} catch (e: Exception) {
@@ -85,9 +85,9 @@ class T30InteropTest {
}
}
private fun theySend(ecm: Boolean, snr: Double = 0.0): List<FaxPage> {
private fun theySend(ecm: Boolean, snr: Double = 0.0, maxBps: Int = 14400): List<FaxPage> {
val dir = tmp.newFolder()
val args = mutableListOf("send", dir.path)
val args = mutableListOf("send", dir.path, "--bps", maxBps.toString())
if (snr > 0) args += listOf("--snr", snr.toString())
val c = start(*args.toTypedArray())
assertEquals("OK", c.command("+FCLASS=1"))
@@ -124,9 +124,13 @@ class T30InteropTest {
theySend(ecm = true)
}
// (at 12000: at V.17's 14400 its first page's row 90, 1-pel runs across
// the page, comes with its second half spoilt, the same place each time,
// on a clean line: from D-Modem-RE's T.30 sender to its class 1 receiver,
// before our T.30 sees it; ECM's frames sent again hide it)
@Test
fun weReceiveWithoutEcm() {
theySend(ecm = false)
theySend(ecm = false, maxBps = 12000)
}
@Test
+7 -1
View File
@@ -128,10 +128,16 @@ void relay(int a, int b)
}
}
/* dmodemd ended too (its SIP port free for the next one), then us */
void on_signal(int)
{
if (dmodemd_pid > 0)
if (dmodemd_pid > 0) {
kill(dmodemd_pid, SIGTERM);
for (int i = 0; i < 50 && waitpid(dmodemd_pid, nullptr, WNOHANG) == 0; i++)
usleep(100000);
kill(dmodemd_pid, SIGKILL);
waitpid(dmodemd_pid, nullptr, 0);
}
_exit(0);
}