Skip to content
Snippets Groups Projects
Commit 8e3710ee authored by Minecrell's avatar Minecrell
Browse files

Initial Commit


linux-postmarketos-qcom-msm8916 now supports voice call audio.
However, at the moment the audio stream needs to be explicitly started
by opening some PCM audio devices when the call is started
(even though no audio data is written to the PCM device).

Eventually this should go away by implementing codec2codec support
for q6voice in the kernel. In that case, the stream would be started
once the audio routes are set up using ALSA UCM. However, this is a bit
complicated actually so for now it's nice to have a workaround:

q6voiced listens on dbus for signals from oFono, and opens/closes the
PCM device when a call is initiated/ended in oFono. This essentially
makes voice call audio work out of the box (provided that the audio
routing, e.g. Earpiece and a microphone is set up appropriately).

Co-Authored-By: default avatarNikita Travkin <nikitos.tr@gmail.com>
parents
No related branches found
No related tags found
No related merge requests found
LICENSE 0 → 100644
The MIT License (MIT)
Copyright (c) 2020 postmarketOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# q6voiced
q6voiced is a userspace daemon for the QDSP6 voice call audio driver.
Voice call audio is directly routed from the modem to the input/output audio
devices, but something needs to start the audio streams for that to happen.
q6voiced listens on dbus for signals from oFono, and opens/closes the
PCM device when a call is initiated/ended in oFono. This essentially
makes voice call audio work out of the box (provided that the audio
routing, e.g. Earpiece and a microphone is set up appropriately).
The q6voiced patches can be currently found in the [msm8916-mainline/linux]
repository (look for `ASoC: qdsp6:`) commits). It may also work for downstream
since the currently implemented approach is very similar.
## Note
It is expected that this daemon will be obsolete eventually.
Different approaches exists for activating such audio streams that are not
processed directly by Linux. (See [Hostless PCM streams]) At the moment the
kernel driver implements the "Hostless FE" approach (as on downstream), but
eventually this should be replaced by a Codec <-> Codec link.
In that case the audio streams would be activated by setting some ALSA mixers
(e.g. through ALSA UCM) and this daemon could be removed. However, there is
quite some work involved to make that work properly. Until then, this daemon
allows voice call audio to work without activating audio manually.
[msm8916-mainline/linux]: https://github.com/msm8916-mainline/linux
[Hostless PCM streams]: https://www.kernel.org/doc/html/latest/sound/soc/dpcm.html#hostless-pcm-streams
// SPDX-License-Identifier: MIT
#include <stdio.h>
#include <dbus/dbus.h>
#include <tinyalsa/asoundlib.h>
/* Note: These parameters have little relevance (no audio data written) */
struct pcm_config pcm_config_voice_call = {
.channels = 1,
.rate = 8000,
.period_size = 160,
.period_count = 2,
.format = PCM_FORMAT_S16_LE,
};
int main(int argc, char **argv)
{
struct pcm *tx = NULL, *rx = NULL;
unsigned int card, device;
DBusMessage *msg;
DBusConnection *conn;
DBusError err;
if (argc != 2 || sscanf(argv[1], "hw:%u,%u", &card, &device) != 2) {
fprintf(stderr, "Usage: q6voiced hw:<card>,<device>\n");
return 1;
}
// See: http://web.archive.org/web/20100309103206/http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html
// "Receiving a Signal"
dbus_error_init(&err);
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Connection error: %s\n", err.message);
dbus_error_free(&err);
return 1;
}
if (!conn)
return 1;
dbus_bus_add_match(conn, "type='signal',interface='org.ofono.VoiceCallManager'", &err);
dbus_connection_flush(conn);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Match error: %s\n", err.message);
dbus_error_free(&err);
return 1;
}
printf("Listening for VoiceCallManager signals.\n");
// Loop listening for signals being emmitted
while (dbus_connection_read_write(conn, -1)) {
// We need to process all received messages
while (msg = dbus_connection_pop_message(conn)) {
// Check if the message is a signal from the correct interface and with the correct name
if (dbus_message_is_signal(msg, "org.ofono.VoiceCallManager", "CallAdded")) {
if (!tx) {
/*
* Opening the PCM devices starts the stream.
* This should be replaced by a codec2codec link probably.
*/
tx = pcm_open(card, device, PCM_IN, &pcm_config_voice_call);
if (!pcm_is_ready(tx))
perror("Failed to open tx");
rx = pcm_open(card, device, PCM_OUT, &pcm_config_voice_call);
if (!pcm_is_ready(rx))
perror("Failed to open rx");
printf("PCM devices were opened.\n");
} else
printf("PCM is already opened!\n");
} else if (dbus_message_is_signal(msg, "org.ofono.VoiceCallManager", "CallRemoved")) {
if (rx) {
pcm_close(rx);
pcm_close(tx);
printf("PCM devices were closed.\n");
rx = tx = NULL;
} else
printf("PCM is already closed!\n");
}
dbus_message_unref(msg);
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment