Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use pulseaudio for A3 call audio routing

  • Loading branch information...
commit 9f78985e8119961cc520e4d050c88bf1e589b879 1 parent 4683e5c
@neiljerram authored
Showing with 49 additions and 41 deletions.
  1. +49 −41 devices/gta04/src/plugins/audiohardware/neo/neoaudioplugin.cpp
View
90 devices/gta04/src/plugins/audiohardware/neo/neoaudioplugin.cpp
@@ -148,65 +148,73 @@ static bool writeToFile(const char *filename, const char *val, int len)
return (bool) Qtopia::writeFile(filename, val, len);
}
-QProcess *voicePs = NULL;
+// Run a command and return the first line of its output.
+static QString backtick(QString cmd)
+{
+ QProcess p;
+
+ qLog(AudioState) << cmd;
+
+ // Run the command and wait for it to finish.
+ p.start(cmd);
+ p.waitForFinished();
+
+ // Get its standard output.
+ QString output = p.readAllStandardOutput();
+
+ qLog(AudioState) << "=>" << output;
+
+ // Return the first line of the output.
+ return output.split("\n").at(0);
+}
+
+QString moduleIdGsmToEar;
+QString moduleIdMicToGsm;
static bool gsmVoiceStop()
{
+ if (!moduleIdGsmToEar.isEmpty()) {
+
+ // Stop loopback from the modem to the earpiece.
+ backtick(QString("pactl unload-module %1").arg(moduleIdGsmToEar));
+ moduleIdGsmToEar.clear();
+
+ // Stop loopback from the microphone to the modem.
+ backtick(QString("pactl unload-module %1").arg(moduleIdMicToGsm));
+ moduleIdMicToGsm.clear();
+ }
+
// Move back alsa config (used e.g. by blueooth a2dp sound)
if(QFile::exists("/home/root/.asoundrc.tmp")) {
QFile::rename("/home/root/.asoundrc.tmp", "/home/root/.asoundrc");
}
- if (voicePs == NULL) {
- return true;
- }
- qLog(AudioState) << "terminating gsm-voice-routing pid " << voicePs->pid();
- voicePs->terminate();
- if (!voicePs->waitForFinished(1000)) {
- qWarning() << "gsm-voice-routing process failed to terminate";
- voicePs->kill();
- }
- delete(voicePs);
- voicePs = NULL;
return true;
}
static bool gsmVoiceStart()
{
- if (voicePs != NULL) {
- return true;
- }
-
// Move away alsa config (used e.g. by blueooth a2dp sound)
if(QFile::exists("/home/root/.asoundrc")) {
QFile::rename("/home/root/.asoundrc", "/home/root/.asoundrc.tmp");
}
-
- voicePs = new QProcess();
-
- // Forward gsm-voice-routing's output to the process running this
- // code. That means the mediaserver process, whose output is in
- // turn forwarded to qpe, whose output is logged by
- // /etc/init.d/qtmoko-gta04. Hence this means that
- // gsm-voice-routing's stdout and stderr will end up in the log.
- voicePs->setProcessChannelMode(QProcess::ForwardedChannels);
-
- if(usePulse) {
- QStringList args;
- args.insert(0, "gsm-voice-routing");
- args.insert(0, "--");
- qLog(AudioState) << "pasuspender " << args;
- voicePs->start("pasuspender", args);
- } else
- voicePs->start("gsm-voice-routing");
-
- if (voicePs->waitForStarted(3000)) {
- qLog(AudioState) << "starting gsm-voice-routing pid " << voicePs->pid();
- return true;
+
+ if (moduleIdGsmToEar.isEmpty()) {
+
+ // Start loopback from the modem to the earpiece.
+ moduleIdGsmToEar =
+ backtick("pactl load-module module-loopback"
+ " source=alsa_input.platform-soc-audio.1.analog-mono"
+ " sink=alsa_output.platform-soc-audio.0.analog-stereo");
+
+ // Start loopback from the microphone to the modem.
+ moduleIdMicToGsm =
+ backtick("pactl load-module module-loopback"
+ " source=alsa_input.platform-soc-audio.0.analog-stereo"
+ " sink=alsa_output.platform-soc-audio.1.analog-mono");
}
- qWarning() << "failed to start gsm-voice-routing: " <<
- voicePs->errorString();
- return false;
+
+ return true;
}
/* Class for an audio state based on an ALSA state file. */
Please sign in to comment.
Something went wrong with that request. Please try again.