Fix global Power menu key handling, SIP G.711 audio routing, Webarchy audio playback, and ReMEdy Call menu key

This commit is contained in:
Luxferre committed 2026-10-31 19:39:28 +02:00
1 parent d7335b5ebe
commit 0af39d9fa0
76 files changed
+506 -104

No files matched your search

+6
View File
@@ -818,6 +818,12 @@ int calllog_run_main(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, ev.xkey.keycode)) {
hideWindow(false);
openPowerMenuFromPlugin(dpy);
continue;
}
if (mode == ViewMode::AddBlock) {
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
if (dialCh == '#') {
+28 -6
View File
@@ -506,7 +506,8 @@ int callscreen_run_main(int argc, char** argv) {
};
auto isVoipCallId = [&](const std::string& cid) -> bool {
return cid.rfind("sip:", 0) == 0 || cid.rfind("tox:", 0) == 0;
return cid.rfind("sip:", 0) == 0 || cid.rfind("tox:", 0) == 0 ||
activeSimSlot == 3 || activeSimSlot == 4;
};
auto setSpeakerRoute = [&](bool toSpeaker) {
@@ -572,8 +573,15 @@ int callscreen_run_main(int argc, char** argv) {
setOutDevFile("Earpiece");
statusNotice = "Audio routed to Earpiece";
}
runAsyncCmd("PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_statusbar.sh volume >/dev/null 2>&1");
if (voip) {
runAsyncCmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
"PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_statusbar.sh volume >/dev/null 2>&1");
} else {
runAsyncCmd("PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_statusbar.sh volume >/dev/null 2>&1");
}
statusNoticeUntilMs = nowMs() + 2000;
};
@@ -1305,14 +1313,28 @@ int callscreen_run_main(int argc, char** argv) {
alsa.setBoolean("PRI_MI2S_RX Voice Mixer VoiceMMode1", false);
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", false);
alsa.setEnum("EAR_S", 0);
alsa.setEnum("RX1 MIX1 INP1", 0);
alsa.setInteger("RX1 Digital Volume", 0);
alsa.setEnum("RX3 MIX1 INP1", 3);
alsa.setBoolean("SPK DAC Switch", true);
int spkPct = readIntFile(getHomeDirPath() + "/.config/sxmo/speaker_vol", 85);
alsa.setInteger("RX3 Digital Volume", pctToHwVol(spkPct, true, false));
{
bool jackPlugged = (readIntFile("/tmp/sxmo_jack_plugged", 0) == 1);
std::ofstream out("/tmp/sxmo_audio_out_device", std::ios::trunc);
if (out.is_open()) out << (jackPlugged ? "Headphones" : "Speaker") << "\n";
}
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
"pkill -TERM -f 'mpv.*ring' >/dev/null 2>&1; "
"pkill -TERM -x sxmo_vibrate >/dev/null 2>&1; "
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1; "
"if [ \"$(cat /tmp/sxmo_jack_plugged 2>/dev/null)\" = \"1\" ]; then "
" sxmo_audio.sh out set Headphones >/dev/null 2>&1; "
"else "
" sxmo_audio.sh out set Speaker >/dev/null 2>&1; "
"fi");
render();
};
@@ -1320,9 +1342,9 @@ int callscreen_run_main(int argc, char** argv) {
std::string cid = resolveActiveModemCallId();
bool wasIncoming = (callState == CallState::Incoming);
stopRingingJobs();
if (cid.rfind("sip:", 0) == 0) {
if (cid.rfind("sip:", 0) == 0 || activeSimSlot == 3) {
sendPluginCommand("sip", "CALL_HANGUP " + cid);
} else if (cid.rfind("tox:", 0) == 0) {
} else if (cid.rfind("tox:", 0) == 0 || activeSimSlot == 4) {
sendPluginCommand("tox", "CALL_HANGUP " + cid);
} else if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
+7 -1
View File
@@ -800,7 +800,13 @@ int runCameraApp(int argc, char** argv) {
continue;
}
if (sym == XK_Escape || kc == 124 || sym == XF86XK_PowerOff) {
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape) {
hideWindow();
continue;
}
+6
View File
@@ -1234,6 +1234,12 @@ int runContactsApp(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, ev.xkey.keycode)) {
hideWindow(false);
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape) {
if (mode == ViewMode::List) {
writeSoftkeySuppress(nowMs() + 300);
+6
View File
@@ -747,6 +747,12 @@ int dialer_run_main(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, ev.xkey.keycode)) {
hideWindow(false);
openPowerMenuFromPlugin(dpy);
continue;
}
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
if (modal == DialerModal::SelectSim) {
+7 -1
View File
@@ -311,8 +311,14 @@ int engmenu_run_main(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, kc)) {
closeWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (isRightSoftkey(sym, kc) || sym == XK_Escape ||
sym == XK_BackSpace || kc == 124 || sym == XF86XK_HangupPhone ||
sym == XK_BackSpace || sym == XF86XK_HangupPhone ||
sym == XK_Cancel) {
writeSoftkeySuppress(nowMs() + 300);
closeWindow();
+7 -1
View File
@@ -2506,7 +2506,13 @@ int runFilesApp(int argc, char** argv) {
continue;
}
if (sym == XK_Escape || kc == 124 || sym == XF86XK_PowerOff) {
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape) {
hideWindow();
continue;
}
+6
View File
@@ -1895,6 +1895,12 @@ int runModemApp(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
hideWindow();
continue;
+7 -2
View File
@@ -1298,8 +1298,13 @@ int runMusicApp(int argc, char** argv) {
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel || kc == 124 ||
sym == XF86XK_PowerOff) {
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
hideWindow();
continue;
}
+6
View File
@@ -1365,6 +1365,12 @@ int runNetworksApp(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
hideWindow();
continue;
+7 -1
View File
@@ -628,7 +628,13 @@ int passcode_run_main(int argc, char** argv) {
continue;
}
if (sym == XK_Escape || kc == 124 || sym == XF86XK_HangupPhone ||
if (isPowerKey(sym, kc)) {
closeWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape || sym == XF86XK_HangupPhone ||
sym == XK_Cancel) {
writeSoftkeySuppress(nowMs() + 300);
closeWindow();
+23
View File
@@ -1949,6 +1949,29 @@ inline void grabPluginKeyboard(Display* dpy, Window win) {
XSetInputFocus(dpy, win, RevertToPointerRoot, CurrentTime);
}
inline bool isPowerKey(KeySym sym, unsigned int kc) {
return sym == XF86XK_PowerOff || kc == 124;
}
inline void openPowerMenuFromPlugin(Display* dpy) {
if (dpy) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
}
if (isCallActiveOrRingingFast()) {
if (!sendPluginCommand("callscreen", "HANGUP")) {
runAsyncArgv("xcallscreen", "hangup");
}
return;
}
if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
return;
}
if (!sendPluginCommand("dmenu", "OPEN power")) {
runAsyncArgv("dmenu", "power");
}
}
inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
static const char* kPlugins[] = {
"dmenu",
+6
View File
@@ -1073,6 +1073,12 @@ int runRingtonesApp(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
hideWindow();
continue;
+189 -67
View File
@@ -137,7 +137,7 @@ std::string normalizePreferredCodec(const std::string& raw) {
std::string cyclePreferredCodec(const std::string& cur) {
static const char* kList[] = {
"AUTO", "OPUS", "G722", "PCMU", "PCMA", "GSM", "G726-32", "DVI4", "L16"
"AUTO", "PCMU", "PCMA", "GSM", "OPUS", "G722", "G726-32", "DVI4", "L16"
};
std::string norm = normalizePreferredCodec(cur);
for (size_t i = 0; i < sizeof(kList) / sizeof(kList[0]); ++i) {
@@ -152,14 +152,15 @@ std::string cyclePreferredCodec(const std::string& cur) {
uint8_t linearToUlaw(int16_t pcmVal) {
constexpr int kBias = 0x84;
constexpr int kClip = 32635;
int mask = (pcmVal < 0) ? 0x7f : 0xff;
if (pcmVal < 0) pcmVal = static_cast<int16_t>(-pcmVal);
if (pcmVal > kClip) pcmVal = kClip;
pcmVal = static_cast<int16_t>(pcmVal + kBias);
int pcm = pcmVal;
int mask = (pcm < 0) ? 0x7f : 0xff;
if (pcm < 0) pcm = -pcm;
if (pcm > kClip) pcm = kClip;
pcm += kBias;
int seg = 0;
for (int thr = 0xFF; seg < 7 && pcmVal > thr; ++seg, thr = (thr << 1) | 1) {
for (int thr = 0xFF; seg < 7 && pcm > thr; ++seg, thr = (thr << 1) | 1) {
}
uint8_t uval = static_cast<uint8_t>((seg << 4) | ((pcmVal >> (seg + 3)) & 0x0f));
uint8_t uval = static_cast<uint8_t>((seg << 4) | ((pcm >> (seg + 3)) & 0x0f));
return static_cast<uint8_t>(uval ^ mask);
}
@@ -170,18 +171,20 @@ int16_t ulawToLinear(uint8_t uval) {
}
uint8_t linearToAlaw(int16_t pcmVal) {
int pcm = pcmVal;
int mask = 0x55;
if (pcmVal >= 0) {
if (pcm >= 0) {
mask |= 0x80;
} else {
pcmVal = static_cast<int16_t>(-pcmVal - 1);
pcm = -pcm - 1;
}
if (pcm > 32767) pcm = 32767;
int seg = 0;
for (int thr = 0xFF; seg < 7 && pcmVal > thr; ++seg, thr = (thr << 1) | 1) {
for (int thr = 0xFF; seg < 7 && pcm > thr; ++seg, thr = (thr << 1) | 1) {
}
uint8_t aval = (seg == 0)
? static_cast<uint8_t>((pcmVal >> 4) & 0x0f)
: static_cast<uint8_t>((seg << 4) | ((pcmVal >> (seg + 3)) & 0x0f));
? static_cast<uint8_t>((pcm >> 4) & 0x0f)
: static_cast<uint8_t>((seg << 4) | ((pcm >> (seg + 3)) & 0x0f));
return static_cast<uint8_t>(aval ^ mask);
}
@@ -424,7 +427,6 @@ class G722State {
int il = (el < 0) ? kMisn[mila] : kMisp[mila];
int ril = il >> 2;
int dlt = (band_[0].det * kQ6m4[ril]) >> 15;
if (il < 32) dlt = -dlt;
updateBand(0, dlt, ril, true);
// Higher sub-band (2-bit quantizer)
@@ -451,8 +453,7 @@ class G722State {
int ril = il >> 2;
int dlt = (band_[0].det * kQ6b[il]) >> 15;
int rlow = std::clamp(band_[0].s + dlt, -16384, 16383);
updateBand(0, (band_[0].det * ((il < 32) ? -kQ6m4[ril] : kQ6m4[ril])) >> 15,
ril, true);
updateBand(0, (band_[0].det * kQ6m4[ril]) >> 15, ril, true);
// Higher sub-band reconstruction (2-bit)
int dhy = (band_[1].det * kQm2[ih]) >> 15;
@@ -573,18 +574,18 @@ class G722State {
41, 40, 39, 38, 37, 36, 35, 34, 33, 32
};
static constexpr int kQ6m4[16] = {
0, 20456, 12896, 8968, 6288, 4240, 2584, 1200,
20456, 12896, 8968, 6288, 4240, 2584, 1200, 296
0, -20456, -12896, -8968, -6288, -4240, -2584, -1200,
20456, 12896, 8968, 6288, 4240, 2584, 1200, 0
};
static constexpr int kQ6b[64] = {
-152, -28000, -21984, -18256, -15800, -13864, -12240, -10840,
-9608, -8512, -7528, -6624, -5792, -5032, -4328, -3664,
-3056, -2480, -1936, -1424, -936, -464, -152, -152,
-26400, -20912, -17600, -15288, -13448, -11880, -10520, -9320,
28000, 21984, 18256, 15800, 13864, 12240, 10840, 9608,
8512, 7528, 6624, 5792, 5032, 4328, 3664, 3056,
2480, 1936, 1424, 936, 464, 152, 26400, 20912,
17600, 15288, 13448, 11880, 10520, 9320, -8232, 8232
-136, -136, -136, -136, -24808, -21904, -19008, -16704,
-14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856,
-7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576,
-3168, -2776, -2400, -2032, -1688, -1360, -1040, -728,
24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192,
10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456,
4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032,
1688, 1360, 1040, 728, 432, 136, -432, -136
};
static constexpr int kQm2[4] = { -7408, -1616, 7408, 1616 };
static constexpr int kWl[16] = {
@@ -1403,16 +1404,16 @@ bool codecMatchesPreference(SipCodecId id, const std::string& pref) {
std::vector<SipCodecId> orderedCodecsForPreference(const std::string& pref) {
static const SipCodecId kDefaultOrder[] = {
SipCodecId::Opus,
SipCodecId::G722,
SipCodecId::Pcmu,
SipCodecId::Pcma,
SipCodecId::Gsm,
SipCodecId::Opus,
SipCodecId::G722,
SipCodecId::G726_32,
SipCodecId::Dvi4_16k,
SipCodecId::Dvi4_8k,
SipCodecId::L16_16k,
SipCodecId::L16_8k
SipCodecId::Dvi4_16k,
SipCodecId::L16_8k,
SipCodecId::L16_16k
};
std::vector<SipCodecId> out;
for (SipCodecId c : kDefaultOrder) {
@@ -1434,7 +1435,9 @@ std::string codecRtpmapLine(int pt, SipCodecId id) {
switch (id) {
case SipCodecId::Opus:
oss << "opus/48000/2\r\n"
<< "a=fmtp:" << pt << " minptime=10;useinbandfec=1;maxaveragebitrate=24000\r\n";
<< "a=fmtp:" << pt
<< " minptime=10;useinbandfec=1;maxaveragebitrate=24000;"
"maxplaybackrate=16000;sprop-maxcapturerate=16000;stereo=0;sprop-stereo=0\r\n";
break;
case SipCodecId::G722:
oss << "G722/8000\r\n";
@@ -1579,7 +1582,20 @@ void parseSdpMedia(const std::string& msg, const std::string& preferredCodec,
}
}
// 2. Otherwise pick the first mutually supported codec in peer's m=audio line
// 2. In AUTO mode, prefer our ordered priority list (G.711 PCMU/PCMA first)
// among all codecs offered by the peer.
for (SipCodecId prefId : orderedCodecsForPreference("AUTO")) {
for (int pt : offeredPts) {
auto it = outPtMap.find(pt);
if (it != outPtMap.end() && it->second == prefId) {
outCodec = it->second;
outPayloadType = pt;
return;
}
}
}
// 3. Otherwise pick the first mutually supported codec in peer's m=audio line
for (int pt : offeredPts) {
auto it = outPtMap.find(pt);
if (it != outPtMap.end()) {
@@ -1619,8 +1635,17 @@ class RtpAudioSession {
SipCodecId codec, int payloadType, int dtmfPt,
const std::map<int, SipCodecId>& ptMap, bool enableZrtp,
bool peerHasZrtpSdp = false) {
if (remoteIp.empty() || remotePort <= 0) {
stop();
return false;
}
if (running_.load() && sock_ >= 0 && remoteIp == activeRemoteIp_ &&
remotePort == activeRemotePort_ && codec == codec_ &&
payloadType == payloadType_) {
dtmfPt_ = (dtmfPt > 0 && dtmfPt <= 127) ? dtmfPt : 101;
return true;
}
stop();
if (remoteIp.empty() || remotePort <= 0) return false;
int sock = ::socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
if (sock < 0) return false;
@@ -1667,6 +1692,8 @@ class RtpAudioSession {
sock_ = sock;
remAddr_ = remAddr;
activeRemoteIp_ = remoteIp;
activeRemotePort_ = remotePort;
codec_ = codec;
payloadType_ = payloadType;
dtmfPt_ = (dtmfPt > 0 && dtmfPt <= 127) ? dtmfPt : 101;
@@ -1679,6 +1706,10 @@ class RtpAudioSession {
void stop() {
running_.store(false);
pid_t cp = capPid_.load();
if (cp > 1) ::kill(cp, SIGTERM);
pid_t pp = playPid_.load();
if (pp > 1) ::kill(pp, SIGTERM);
if (worker_.joinable()) {
worker_.join();
}
@@ -1686,6 +1717,8 @@ class RtpAudioSession {
::close(sock_);
sock_ = -1;
}
activeRemoteIp_.clear();
activeRemotePort_ = 0;
std::lock_guard<std::mutex> lk(zrtpMtx_);
localHelloMsg_.clear();
srtpActive_.store(false);
@@ -2319,18 +2352,69 @@ class RtpAudioSession {
"amixer -c 0 cset \"name='MultiMedia2 Mixer TERT_MI2S_TX'\" 1 >/dev/null 2>&1");
int audioRate = codecAudioSampleRate(codec_);
size_t frameSamples = static_cast<size_t>(audioRate / 50); // 160 @ 8k, 320 @ 16k
std::string capCmd = "arecord -q -D plughw:0,1 --buffer-time=80000 --period-time=20000 "
"-f S16_LE -r " + std::to_string(audioRate) +
" -c 1 -t raw 2>/dev/null";
std::string playCmd = "aplay -q --buffer-time=80000 --period-time=20000 "
"-f S16_LE -r " + std::to_string(audioRate) +
" -c 1 -t raw 2>/dev/null";
FILE* capFp = ::popen(capCmd.c_str(), "r");
FILE* playFp = ::popen(playCmd.c_str(), "w");
int capFd = capFp ? ::fileno(capFp) : -1;
if (capFd >= 0) {
int fl = ::fcntl(capFd, F_GETFL, 0);
::fcntl(capFd, F_SETFL, fl | O_NONBLOCK);
size_t frameBytes = frameSamples * sizeof(int16_t);
std::string rateStr = std::to_string(audioRate);
int capPipe[2] = {-1, -1};
int capFd = -1;
pid_t capPid = -1;
if (::pipe(capPipe) == 0) {
capPid = ::fork();
if (capPid == 0) {
::close(capPipe[0]);
::dup2(capPipe[1], STDOUT_FILENO);
::close(capPipe[1]);
int nullFd = ::open("/dev/null", O_RDWR);
if (nullFd >= 0) {
::dup2(nullFd, STDIN_FILENO);
::dup2(nullFd, STDERR_FILENO);
if (nullFd > 2) ::close(nullFd);
}
::execlp("arecord", "arecord", "-q", "--buffer-time=160000",
"--period-time=20000", "-f", "S16_LE", "-r", rateStr.c_str(),
"-c", "1", "-t", "raw", static_cast<char*>(nullptr));
::_exit(1);
} else if (capPid > 0) {
::close(capPipe[1]);
capFd = capPipe[0];
int fl = ::fcntl(capFd, F_GETFL, 0);
::fcntl(capFd, F_SETFL, fl | O_NONBLOCK);
capPid_.store(capPid);
} else {
::close(capPipe[0]);
::close(capPipe[1]);
}
}
int playPipe[2] = {-1, -1};
int playFd = -1;
pid_t playPid = -1;
if (::pipe(playPipe) == 0) {
playPid = ::fork();
if (playPid == 0) {
::close(playPipe[1]);
::dup2(playPipe[0], STDIN_FILENO);
::close(playPipe[0]);
int nullFd = ::open("/dev/null", O_RDWR);
if (nullFd >= 0) {
::dup2(nullFd, STDOUT_FILENO);
::dup2(nullFd, STDERR_FILENO);
if (nullFd > 2) ::close(nullFd);
}
::execlp("aplay", "aplay", "-q", "--buffer-time=200000",
"--period-time=20000", "-f", "S16_LE", "-r", rateStr.c_str(),
"-c", "1", "-t", "raw", static_cast<char*>(nullptr));
::_exit(1);
} else if (playPid > 0) {
::close(playPipe[0]);
playFd = playPipe[1];
int fl = ::fcntl(playFd, F_GETFL, 0);
::fcntl(playFd, F_SETFL, fl | O_NONBLOCK);
playPid_.store(playPid);
} else {
::close(playPipe[0]);
::close(playPipe[1]);
}
}
int opusErr = OPUS_OK;
@@ -2356,8 +2440,19 @@ class RtpAudioSession {
uint32_t ts = static_cast<uint32_t>(nowMs() * 8);
uint32_t ssrc = 0x51504241u ^ static_cast<uint32_t>(::getpid());
int64_t nextTxMs = nowMs() + 20;
bool playPrimed = false;
uint8_t capRing[2560];
size_t capAvail = 0;
while (running_.load()) {
// Drain available microphone capture bytes into capRing without blocking
if (capFd >= 0 && capAvail < sizeof(capRing)) {
ssize_t r = ::read(capFd, capRing + capAvail, sizeof(capRing) - capAvail);
if (r > 0) {
capAvail += static_cast<size_t>(r);
}
}
// 1. Receive incoming RTP / SRTP / ZRTP packets
uint8_t rxPkt[1500];
while (true) {
@@ -2388,9 +2483,9 @@ class RtpAudioSession {
const uint8_t* payload = rxPkt + hdrLen;
size_t payLen = pktLen - hdrLen;
if (!playFp || payLen == 0) continue;
if (playFd < 0 || payLen == 0) continue;
int16_t pcmDecoded[960];
int16_t pcmDecoded[1920];
size_t decodedSamples = 0;
switch (rxCodec) {
@@ -2398,28 +2493,28 @@ class RtpAudioSession {
if (opusDec) {
int r = opus_decode(opusDec, payload,
static_cast<opus_int32>(payLen),
pcmDecoded, 960, 0);
pcmDecoded, 1920, 0);
if (r > 0) decodedSamples = static_cast<size_t>(r);
}
break;
case SipCodecId::G722:
decodedSamples = g722Dec.decodeFrame(payload, payLen, pcmDecoded, 960);
decodedSamples = g722Dec.decodeFrame(payload, payLen, pcmDecoded, 1920);
break;
case SipCodecId::Pcmu:
decodedSamples = std::min<size_t>(payLen, 960);
decodedSamples = std::min<size_t>(payLen, 1920);
for (size_t i = 0; i < decodedSamples; ++i) {
pcmDecoded[i] = ulawToLinear(payload[i]);
}
break;
case SipCodecId::Pcma:
decodedSamples = std::min<size_t>(payLen, 960);
decodedSamples = std::min<size_t>(payLen, 1920);
for (size_t i = 0; i < decodedSamples; ++i) {
pcmDecoded[i] = alawToLinear(payload[i]);
}
break;
case SipCodecId::Gsm:
if (gsmDec) {
for (size_t off = 0; off + 33 <= payLen && decodedSamples + 160 <= 960; off += 33) {
for (size_t off = 0; off + 33 <= payLen && decodedSamples + 160 <= 1920; off += 33) {
gsm_byte frame[33];
std::memcpy(frame, payload + off, 33);
if (gsm_decode(gsmDec, frame, pcmDecoded + decodedSamples) == 0) {
@@ -2429,15 +2524,15 @@ class RtpAudioSession {
}
break;
case SipCodecId::G726_32:
decodedSamples = g726Dec.decodeFrame(payload, payLen, pcmDecoded, 960);
decodedSamples = g726Dec.decodeFrame(payload, payLen, pcmDecoded, 1920);
break;
case SipCodecId::Dvi4_8k:
case SipCodecId::Dvi4_16k:
decodedSamples = dvi4Dec.decodeFrame(payload, payLen, pcmDecoded, 960);
decodedSamples = dvi4Dec.decodeFrame(payload, payLen, pcmDecoded, 1920);
break;
case SipCodecId::L16_8k:
case SipCodecId::L16_16k:
for (size_t i = 0; i + 1 < payLen && decodedSamples < 960; i += 2) {
for (size_t i = 0; i + 1 < payLen && decodedSamples < 1920; i += 2) {
uint16_t be = (static_cast<uint16_t>(payload[i]) << 8) | payload[i + 1];
pcmDecoded[decodedSamples++] = static_cast<int16_t>(be);
}
@@ -2445,9 +2540,14 @@ class RtpAudioSession {
}
if (decodedSamples > 0) {
if (!playPrimed) {
playPrimed = true;
int16_t silence[960] = {0};
(void)::write(playFd, silence, frameSamples * 3 * sizeof(int16_t));
}
int rxRate = codecAudioSampleRate(rxCodec);
if (rxRate == audioRate) {
std::fwrite(pcmDecoded, sizeof(int16_t), decodedSamples, playFp);
(void)::write(playFd, pcmDecoded, decodedSamples * sizeof(int16_t));
} else if (rxRate == 8000 && audioRate == 16000) {
int16_t pcmUp[1920];
size_t upCount = 0;
@@ -2457,17 +2557,16 @@ class RtpAudioSession {
pcmUp[upCount++] = s0;
pcmUp[upCount++] = static_cast<int16_t>((static_cast<int>(s0) + s1) / 2);
}
std::fwrite(pcmUp, sizeof(int16_t), upCount, playFp);
(void)::write(playFd, pcmUp, upCount * sizeof(int16_t));
} else if (rxRate == 16000 && audioRate == 8000) {
int16_t pcmDown[480];
int16_t pcmDown[960];
size_t downCount = 0;
for (size_t i = 0; i + 1 < decodedSamples && downCount < 480; i += 2) {
for (size_t i = 0; i + 1 < decodedSamples && downCount < 960; i += 2) {
pcmDown[downCount++] = static_cast<int16_t>(
(static_cast<int>(pcmDecoded[i]) + pcmDecoded[i + 1]) / 2);
}
std::fwrite(pcmDown, sizeof(int16_t), downCount, playFp);
(void)::write(playFd, pcmDown, downCount * sizeof(int16_t));
}
std::fflush(playFp);
}
}
@@ -2476,7 +2575,10 @@ class RtpAudioSession {
periodicZrtpTick(ssrc, now);
if (now >= nextTxMs) {
nextTxMs = now + 20;
nextTxMs += 20;
if (now - nextTxMs > 60) {
nextTxMs = now + 20;
}
char dtmfCh = '\0';
{
std::lock_guard<std::mutex> lk(dtmfMtx_);
@@ -2513,9 +2615,12 @@ class RtpAudioSession {
ts += codecRtpTimestampStep20ms(codec_) * 3;
} else {
int16_t pcmIn[320] = {0};
if (capFd >= 0) {
ssize_t r = ::read(capFd, pcmIn, frameSamples * sizeof(int16_t));
(void)r;
if (capAvail >= frameBytes) {
std::memcpy(pcmIn, capRing, frameBytes);
capAvail -= frameBytes;
if (capAvail > 0) {
std::memmove(capRing, capRing + frameBytes, capAvail);
}
}
uint8_t pkt[12 + 768 + 16];
uint16_t curSeq = seq++;
@@ -2596,17 +2701,31 @@ class RtpAudioSession {
if (opusDec) opus_decoder_destroy(opusDec);
if (gsmEnc) gsm_destroy(gsmEnc);
if (gsmDec) gsm_destroy(gsmDec);
if (capFp) ::pclose(capFp);
if (playFp) ::pclose(playFp);
if (capFd >= 0) ::close(capFd);
if (playFd >= 0) ::close(playFd);
capPid_.store(-1);
playPid_.store(-1);
if (capPid > 1) {
::kill(capPid, SIGKILL);
::waitpid(capPid, nullptr, 0);
}
if (playPid > 1) {
::kill(playPid, SIGKILL);
::waitpid(playPid, nullptr, 0);
}
}
int sock_ = -1;
struct sockaddr_in remAddr_ {};
std::string activeRemoteIp_;
int activeRemotePort_ = 0;
SipCodecId codec_ = SipCodecId::Pcmu;
int payloadType_ = 0;
int dtmfPt_ = 101;
std::map<int, SipCodecId> rxPtMap_;
std::atomic<bool> running_{false};
std::atomic<pid_t> capPid_{-1};
std::atomic<pid_t> playPid_{-1};
std::thread worker_;
std::mutex dtmfMtx_;
std::string dtmfQueue_;
@@ -3635,6 +3754,9 @@ int sip_run_main(int argc, char** argv) {
} else if (cmd.rfind("CALL_HANGUP", 0) == 0) {
hangupActiveSipCall(false);
if (visible) render();
} else if (cmd == "HANGUP" || cmd.rfind("HANGUP ", 0) == 0) {
hangupActiveSipCall(true);
if (visible) render();
} else if (cmd.rfind("CALL_MUTE_RING", 0) == 0) {
::unlink("/tmp/sxmo_call_ringing");
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
+7 -1
View File
@@ -1411,7 +1411,13 @@ int runSmsApp(int argc, char** argv) {
continue;
}
if (sym == XK_Escape || kc == 124 || sym == XF86XK_PowerOff) {
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape) {
hideWindow();
continue;
}
+7 -1
View File
@@ -1138,7 +1138,13 @@ int runThemesApp(int argc, char** argv) {
continue;
}
if (sym == XK_Escape || kc == 124 || sym == XF86XK_PowerOff) {
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XK_Escape) {
hideWindow();
continue;
}
+6
View File
@@ -589,6 +589,12 @@ int runWallpapersApp(int argc, char** argv) {
continue;
}
if (isPowerKey(sym, kc)) {
hideWindow();
openPowerMenuFromPlugin(dpy);
continue;
}
if (sym == XF86XK_HangupPhone || sym == XK_Cancel) {
hideWindow();
continue;
+31 -14
View File
@@ -785,14 +785,19 @@ gboolean onWebProcessTerminated(WebKitWebView* webView,
}
void ensureAlsaMultimediaRouting() {
static bool routed = false;
if (routed) return;
routed = true;
runAsyncCmd("amixer -q -c 0 cset name='PRI_MI2S_RX Audio Mixer MultiMedia1' 1 >/dev/null 2>&1; "
"amixer -q -c 0 cset name='RX1 MIX1 INP1' 'RX1' >/dev/null 2>&1; "
"amixer -q -c 0 cset name='RX2 MIX1 INP1' 'RX2' >/dev/null 2>&1; "
"amixer -q -c 0 cset name='RDAC2 MUX' 'RX2' >/dev/null 2>&1; "
"amixer -q -c 0 cset name='SPK DAC Switch' 1 >/dev/null 2>&1");
if (isCallActiveOrRingingFast()) return;
runAsyncCmd(
"outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
"if [ \"$outdev\" = \"Earpiece\" ] || [ -z \"$outdev\" ]; then "
" if [ \"$(cat /tmp/sxmo_jack_plugged 2>/dev/null)\" = \"1\" ]; then "
" sxmo_audio.sh out set Headphones >/dev/null 2>&1; "
" else "
" sxmo_audio.sh out set Speaker >/dev/null 2>&1; "
" fi; "
"fi; "
"amixer -q -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
"amixer -q -c 0 cset \"name='RX3 MIX1 INP1'\" 'RX1' >/dev/null 2>&1; "
"amixer -q -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1");
}
bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
@@ -801,6 +806,7 @@ bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
// Hardware acceleration & Cortex-A7 / 512 MB RAM environment tuning
::setenv("GDK_BACKEND", "x11", 1);
::setenv("GTK_THEME", "Adwaita:dark", 1);
::setenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS", "1", 1);
::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "0", 0);
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "0", 0);
::setenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING", "0", 0);
@@ -863,6 +869,7 @@ bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
WebKitWebContext* webCtx = webkit_web_context_new_with_website_data_manager(dataMgr);
g_object_unref(dataMgr);
webkit_web_context_set_sandbox_enabled(webCtx, FALSE);
webkit_web_context_set_cache_model(webCtx, WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
WebKitCookieManager* cookieMgr = webkit_web_context_get_cookie_manager(webCtx);
@@ -1093,8 +1100,6 @@ int webarchy_run_main(int argc, char** argv) {
} else if (visible) {
// Shift subwindow outside 240px parent clip while modal is open so media continues playing
XMoveResizeWindow(neo.dpy, br.webkitXid, 240, 35, 240, 217);
} else {
XUnmapWindow(neo.dpy, br.webkitXid);
}
XFlush(neo.dpy);
};
@@ -1309,8 +1314,10 @@ int webarchy_run_main(int argc, char** argv) {
if (isPhonePasscodeLocked()) return;
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("webarchy");
ensureAlsaMultimediaRouting();
visible = true;
neoui_show();
grabPluginKeyboard(neo.dpy, neo.win);
if (!br.initialized) {
br.statusMsg = "Starting WPE/WebKit engine...";
render();
@@ -1320,6 +1327,9 @@ int webarchy_run_main(int argc, char** argv) {
br.statusMsg = "Failed to initialize WebKit display";
}
}
if (br.initialized && br.webView) {
webkit_web_view_set_is_muted(br.webView, FALSE);
}
syncWebkitVisibility();
grabPluginKeyboard(neo.dpy, neo.win);
render();
@@ -1335,6 +1345,10 @@ int webarchy_run_main(int argc, char** argv) {
controlsModalOpen = false;
infoModalOpen = false;
chordPrefix.clear();
if (br.initialized && br.webView) {
evalJs(br, "try{document.querySelectorAll('audio,video').forEach(function(m){m.pause();});}catch(e){}");
webkit_web_view_set_is_muted(br.webView, TRUE);
}
syncWebkitVisibility();
neoui_hide();
::unlink(activePidPath.c_str());
@@ -1353,16 +1367,19 @@ int webarchy_run_main(int argc, char** argv) {
neo.reloadTheme();
if (visible) render();
} else if (cmd == "OPEN" || cmd.rfind("OPEN ", 0) == 0) {
std::string newUrl;
if (cmd.size() > 5) {
std::string arg = trimStr(cmd.substr(5));
if (!arg.empty()) {
br.currentUrl = normalizeInputUrlOrSearch(arg);
if (br.initialized && br.webView) {
webkit_web_view_load_uri(br.webView, br.currentUrl.c_str());
}
newUrl = normalizeInputUrlOrSearch(arg);
br.currentUrl = newUrl;
}
}
bool wasInitialized = br.initialized;
openWindow();
if (wasInitialized && !newUrl.empty() && br.initialized && br.webView) {
webkit_web_view_load_uri(br.webView, newUrl.c_str());
}
}
}
+14
View File
@@ -2138,6 +2138,20 @@ int main(int argc, char** argv) {
unsigned int kc = ev.xkey.keycode;
KeySym sym = XLookupKeysym(&ev.xkey, 0);
if (isPress && (sym == XF86XK_PowerOff || kc == 124)) {
unfocusWindow(false);
int64_t tNow = nowMs();
writeSoftkeySuppress(tNow + 500);
overlayCooldownUntilMs = tNow + 500;
int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) {
(void)::write(ffd, "OPEN power\n", 11);
::close(ffd);
}
continue;
}
if (isPress && (sym == XF86XK_AudioLowerVolume ||
sym == XF86XK_AudioRaiseVolume)) {
audioOut.adjustSpeakerVol(
+32 -5
View File
@@ -143,7 +143,7 @@ static std::string keysymLabel(KeySym ks) {
case XK_Super_L:
case XK_F1: return "LSoft";
case XK_F2: return "RSoft";
case XK_Escape: return "End/Esc";
case XK_Escape: return "Call/Esc";
case XK_asterisk: return "* (Star)";
case XK_numbersign: return "# (Hash)";
default: {
@@ -1211,15 +1211,37 @@ class RemedyEmulator {
}
bool handleKeyPress(KeySym ks, unsigned int keycode = 0) {
// Normalize Nokia 8110 4G hardware softkeys & End key
// Normalize Nokia 8110 4G hardware softkeys, Call key, & End/Power key
if (keycode == 135 || ks == XK_Menu || ks == XF86XK_KbdLcdMenu1 ||
ks == _EVDEVK(0x246)) {
ks = XK_F1;
} else if (keycode == 166 || ks == XF86XK_Back || ks == XF86XK_KbdLcdMenu2 ||
ks == _EVDEVK(0x247)) {
ks = XK_F2;
} else if (keycode == 124 || ks == XF86XK_PowerOff) {
} else if (keycode == 169 || ks == XF86XK_Phone ||
ks == XF86XK_PickupPhone || ks == _EVDEVK(0x0e7)) {
ks = XK_Escape;
} else if (keycode == 124 || ks == XF86XK_PowerOff) {
cldcRuntime.sound.setPaused(true);
ungrabKeyboard();
int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) {
(void)::write(ffd, "OPEN power\n", 11);
::close(ffd);
} else {
std::system("dmenu power >/dev/null 2>&1");
}
usleep(120000);
for (int wait = 0; wait < 600; ++wait) {
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) != 0) break;
usleep(50000);
}
XRaiseWindow(neoWin.dpy, neoWin.win);
XSetInputFocus(neoWin.dpy, neoWin.win, RevertToParent, CurrentTime);
grabKeyboard();
appCtx.repaintPending = true;
return true;
}
if (ks == XF86XK_AudioLowerVolume || ks == XF86XK_AudioRaiseVolume) {
@@ -1329,8 +1351,9 @@ class RemedyEmulator {
return true;
}
if (mode == EmuUiMode::PAUSED) {
if (softIdx == 2) {
if (softIdx == 1 || softIdx == 2) {
mode = hasLoadedMidlet ? EmuUiMode::RUNNING : EmuUiMode::BROWSER;
if (mode == EmuUiMode::BROWSER) renderBrowserMenu();
appCtx.repaintPending = true;
}
return true;
@@ -1397,6 +1420,7 @@ class RemedyEmulator {
}
if (ks == XK_Escape) {
mode = hasLoadedMidlet ? EmuUiMode::RUNNING : EmuUiMode::BROWSER;
if (mode == EmuUiMode::BROWSER) renderBrowserMenu();
appCtx.repaintPending = true;
return true;
}
@@ -1493,7 +1517,10 @@ class RemedyEmulator {
}
}
} else if (ks == XK_Escape) {
return false;
pauseSel = 0;
pauseScroll = 0;
mode = EmuUiMode::PAUSED;
renderPauseMenu();
}
return true;
}
+10
View File
@@ -993,6 +993,16 @@ int main() {
continue;
}
if (evType == NEO_EV_CLOSE_REQ) {
if (neoui_event_keysym() == XF86XK_PowerOff ||
neoui_event_keycode() == 124) {
::usleep(80000);
while (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) {
::usleep(50000);
}
neoui_raise_and_grab();
render();
continue;
}
gRunning = 0;
break;
}
+37
View File
@@ -155,6 +155,30 @@ bool sendPluginFifoMsg(const char* name, const std::string& cmdLine) {
return w == static_cast<ssize_t>(msg.size());
}
bool isCallActiveOrRingingInNeoui() {
if (::access("/tmp/sxmo_call_ringing", F_OK) == 0 ||
::access("/tmp/sxmo_active_call", F_OK) == 0) {
return true;
}
const char* rdir = std::getenv("XDG_RUNTIME_DIR");
std::string base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
if (::access((base + "/sxmo_jobs/ringing").c_str(), F_OK) == 0) {
return true;
}
DIR* d = ::opendir((base + "/sxmo_calls").c_str());
if (d) {
struct dirent* ent;
while ((ent = ::readdir(d)) != nullptr) {
if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') {
::closedir(d);
return true;
}
}
::closedir(d);
}
return false;
}
int mapHardwareKey(KeySym sym, unsigned int keycode, unsigned int state) {
if (keycode == 135 || sym == XK_Super_L || sym == XK_Menu ||
static_cast<uint32_t>(sym) == _EVDEVK(0x8b)) {
@@ -2709,6 +2733,19 @@ int neoui_poll_event(int timeout_ms) {
}
if (ev.type == KeyPress) {
if (sym == XF86XK_PowerOff || kc == 124) {
if (bananarchy::isCallActiveOrRingingInNeoui()) {
bananarchy::sendPluginFifoMsg("callscreen", "HANGUP");
continue;
}
if (::access("/tmp/bananarchy_screen_locked", F_OK) != 0) {
neoui_ungrab();
XFlush(dpy);
bananarchy::sendPluginFifoMsg("dmenu", "OPEN power");
ctx->lastEventType = NEO_EV_CLOSE_REQ;
return NEO_EV_CLOSE_REQ;
}
}
if (ctx->chordXdrawer &&
(nkey == NEO_KEY_SOFT_LEFT || nkey == NEO_KEY_SOFT_RIGHT)) {
int curBit = (nkey == NEO_KEY_SOFT_LEFT) ? 1 : 2;
+15 -1
View File
@@ -779,6 +779,8 @@ query_trigger_keys_down(void)
mask |= 4;
if (km[104 / 8] & (1 << (104 % 8)))
mask |= 8;
if (km[124 / 8] & (1 << (124 % 8)))
mask |= 16;
return mask;
}
@@ -1572,6 +1574,8 @@ keypress(XKeyEvent *ev)
len = Xutf8LookupString(xic, ev, buf, sizeof buf, &ksym, &status);
else {
len = XLookupString(ev, buf, sizeof buf, &ksym, NULL);
if (ksym == NoSymbol && ev->keycode == 124)
ksym = XF86XK_PowerOff;
status = (len > 0 && ksym != NoSymbol) ? XLookupBoth :
(len > 0) ? XLookupChars :
(ksym != NoSymbol) ? XLookupKeySym : XLookupNone;
@@ -1688,7 +1692,16 @@ insert:
sel = matchend;
break;
case XK_Escape:
cancel_session();
return;
case XF86XK_PowerOff:
if (daemon_mode &&
(menu_mode != MODE_BUILTIN || strcmp(current_builtin_menu, "power") != 0)) {
if (active_client_fd >= 0)
finish_client_session(1, NULL);
open_builtin_menu("power", 0);
return;
}
cancel_session();
return;
case XF86XK_Back:
@@ -3569,6 +3582,7 @@ process_x11_events(void)
int is_enter = (ks == XK_Return || ks == XK_KP_Enter ||
ks == XF86XK_Phone || ks == XF86XK_PickupPhone ||
ev.xkey.keycode == 36 || ev.xkey.keycode == 104);
int is_power = (ks == XF86XK_PowerOff || ev.xkey.keycode == 124);
if (is_left || is_right) {
long long now = dmenu_now_ms();
int which = (is_left ? 1 : 0) | (is_right ? 2 : 0);
@@ -3595,7 +3609,7 @@ process_x11_events(void)
soft_deadline = now + 30;
continue;
}
if (is_enter) {
if (is_enter || is_power) {
if (ev.type == KeyRelease) {
initial_released = 1;
continue;
+13
View File
@@ -2261,6 +2261,19 @@ keypress(XEvent *e)
return;
}
if (!is_phone_locked() && CLEANMASK(ev->state) == 0 &&
(keysym == XF86XK_PowerOff || ev->keycode == 124)) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
if (is_plugin_loaded("dmenu")) {
host_spawn_plugin("dmenu", "power");
return;
}
const Arg pwrcmd = { .v = (const char*[]){ "sxmo_appmenu.sh", "power", NULL } };
spawn(&pwrcmd);
return;
}
if (!selmon->sel && !is_phone_locked()) {
if (dispatch_plugin_idle_key(keysym, ev->keycode, CLEANMASK(ev->state)))
return;
+13
View File
@@ -1212,6 +1212,19 @@ static int xdrawer_run_main(int argc, char** argv) {
continue;
}
if (sym == XF86XK_PowerOff || ev.xkey.keycode == 124) {
hideWindow(false);
int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) {
(void)::write(ffd, "OPEN power\n", 11);
::close(ffd);
} else {
runAsyncCmd("dmenu power >/dev/null 2>&1");
}
break;
}
switch (sym) {
case XK_Escape:
case XK_BackSpace: