Pierre-Hugues Husson | c642be2 | 2018-07-07 23:43:53 +0200 | [diff] [blame^] | 1 | From 25e8b3145db1134d114f54ab8b3f4bff9bb5a062 Mon Sep 17 00:00:00 2001 |
| 2 | From: Pierre-Hugues Husson <phh@phh.me> |
| 3 | Date: Tue, 24 Apr 2018 00:14:28 +0200 |
| 4 | Subject: [PATCH 1/2] FIH devices: Fix "Earpiece" audio output |
| 5 | |
| 6 | On some FIH devices (confirmed on Razer, and probably on Aquos SS2), |
| 7 | Earpiece is not listed in attachedDevices, and devicePort's profile |
| 8 | mentions it is AUDIO_CHANNEL_IN_MONO, instead of AUDIO_CHANNEL_OUT_MONO. |
| 9 | |
| 10 | Detect such cases (output device, but got only AUDIO_CHANNEL_IN_MONO), |
| 11 | and fix both channelMasks and attachedDevices |
| 12 | |
| 13 | Change-Id: I4a88ba6d34d0fcd346eeea2ca903772f0271040a |
| 14 | --- |
| 15 | .../common/managerdefinitions/src/Serializer.cpp | 25 +++++++++++++++++++--- |
| 16 | 1 file changed, 22 insertions(+), 3 deletions(-) |
| 17 | |
| 18 | diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp |
| 19 | index a224004..f58d7e5 100644 |
| 20 | --- 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); |
| 50 | @@ -316,7 +325,10 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl |
| 51 | } |
| 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()); |
| 62 | @@ -481,6 +493,13 @@ status_t ModuleTraits::deserialize(xmlDocPtr doc, const xmlNode *root, PtrElemen |
| 63 | } |
| 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 | -- |
| 77 | 2.7.4 |
| 78 | |