blob: d0d75fc78b460e8c86f7dc3b87eb5564be65faaa [file] [log] [blame]
Jackeagled3ba2282018-11-17 20:49:22 -07001From 8508cdce9a6a1b3806972ca7c44ab49823863fdb Mon Sep 17 00:00:00 2001
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +02002From: Pierre-Hugues Husson <phh@phh.me>
3Date: Tue, 24 Apr 2018 00:14:28 +0200
Jackeagled3ba2282018-11-17 20:49:22 -07004Subject: [PATCH 1/4] FIH devices: Fix "Earpiece" audio output
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +02005
6On some FIH devices (confirmed on Razer, and probably on Aquos SS2),
7Earpiece is not listed in attachedDevices, and devicePort's profile
8mentions it is AUDIO_CHANNEL_IN_MONO, instead of AUDIO_CHANNEL_OUT_MONO.
9
10Detect such cases (output device, but got only AUDIO_CHANNEL_IN_MONO),
11and fix both channelMasks and attachedDevices
12
13Change-Id: I4a88ba6d34d0fcd346eeea2ca903772f0271040a
14---
Jackeagled3ba2282018-11-17 20:49:22 -070015 .../managerdefinitions/src/Serializer.cpp | 25 ++++++++++++++++---
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020016 1 file changed, 22 insertions(+), 3 deletions(-)
17
18diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
Jackeagled3ba2282018-11-17 20:49:22 -070019index a2531131d..380e2f82b 100644
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020020--- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
21+++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
22@@ -191,16 +191,25 @@ const char AudioProfileTraits::Attributes::name[] = "name";
23 const char AudioProfileTraits::Attributes::samplingRates[] = "samplingRates";
24 const char AudioProfileTraits::Attributes::format[] = "format";
25 const char AudioProfileTraits::Attributes::channelMasks[] = "channelMasks";
26+static bool fixedEarpieceChannels = false;
27
28 status_t AudioProfileTraits::deserialize(_xmlDoc */*doc*/, const _xmlNode *root, PtrElement &profile,
29- PtrSerializingCtx /*serializingContext*/)
30+ PtrSerializingCtx serializingContext)
31 {
32+ bool isOutput = serializingContext != nullptr;
33 string samplingRates = getXmlAttribute(root, Attributes::samplingRates);
34 string format = getXmlAttribute(root, Attributes::format);
35 string channels = getXmlAttribute(root, Attributes::channelMasks);
36+ ChannelTraits::Collection channelsMask = channelMasksFromString(channels, ",");
37+
38+ //Some Foxconn devices have wrong earpiece channel mask, leading to no channel mask
39+ if(channelsMask.size() == 1 && channelsMask[0] == AUDIO_CHANNEL_IN_MONO && isOutput) {
40+ fixedEarpieceChannels = true;
41+ channelsMask = channelMasksFromString("AUDIO_CHANNEL_OUT_MONO", ",");
42+ }
43
44 profile = new Element(formatFromString(format, gDynamicFormat),
45- channelMasksFromString(channels, ","),
46+ channelsMask,
47 samplingRatesFromString(samplingRates, ","));
48
49 profile->setDynamicFormat(profile->getFormat() == gDynamicFormat);
Jon West1fd60302018-08-11 19:14:03 -040050@@ -326,7 +335,10 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020051 }
52
53 AudioProfileTraits::Collection profiles;
54- deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
55+ if(audio_is_output_devices(type))
56+ deserializeCollection<AudioProfileTraits>(doc, root, profiles, (PtrSerializingCtx)1);
57+ else
58+ deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
59 if (profiles.isEmpty()) {
60 sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat,
61 ChannelsVector(), SampleRateVector());
Jon West1fd60302018-08-11 19:14:03 -040062@@ -491,6 +503,13 @@ status_t ModuleTraits::deserialize(xmlDocPtr doc, const xmlNode *root, PtrElemen
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020063 }
64 children = children->next;
65 }
66+ if(fixedEarpieceChannels) {
67+ sp<DeviceDescriptor> device =
68+ module->getDeclaredDevices().getDeviceFromTagName(String8("Earpiece"));
69+ if(device != 0)
70+ ctx->addAvailableDevice(device);
71+ fixedEarpieceChannels = false;
72+ }
73 return NO_ERROR;
74 }
75
76--
Jackeagled3ba2282018-11-17 20:49:22 -0700772.17.1
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020078