Merge changes Id6c040c2,I92575d4a
* changes:
Refactor parsing of pcm properties
Load pcm properties on HAL start
diff --git a/audio/entry.cpp b/audio/entry.cpp
index d11c620..1f07044 100644
--- a/audio/entry.cpp
+++ b/audio/entry.cpp
@@ -15,11 +15,14 @@
*/
#include "device_factory.h"
+#include "talsa.h"
using android::hardware::audio::CPP_VERSION::IDevicesFactory;
using android::hardware::audio::CPP_VERSION::implementation::DevicesFactory;
+namespace talsa = android::hardware::audio::CPP_VERSION::implementation::talsa;
extern "C" IDevicesFactory* HIDL_FETCH_IDevicesFactory(const char* name) {
(void)name;
+ talsa::init();
return new DevicesFactory();
}
diff --git a/audio/talsa.cpp b/audio/talsa.cpp
index e538c4e..27076f0 100644
--- a/audio/talsa.cpp
+++ b/audio/talsa.cpp
@@ -32,9 +32,7 @@
struct mixer *gMixer0 = nullptr;
int gMixerRefcounter0 = 0;
std::mutex gMixerMutex;
-const PcmPeriodSettings kDefaultPcmPeriodSettings = { 4, 1 };
PcmPeriodSettings gPcmPeriodSettings;
-std::once_flag gPcmPeriodSettingsFlag;
void mixerSetValueAll(struct mixer_ctl *ctl, int value) {
const unsigned int n = mixer_ctl_get_num_values(ctl);
@@ -99,35 +97,27 @@
return mixerUnrefImpl(mixer, gMixer0, gMixerRefcounter0);
}
-bool initPcmPeriodSettings(PcmPeriodSettings *dst) {
- char prop_value[PROPERTY_VALUE_MAX];
+unsigned readUnsignedProperty(const char *propName, const unsigned defaultValue) {
+ char propValue[PROPERTY_VALUE_MAX];
- if (property_get("ro.hardware.audio.tinyalsa.period_count", prop_value, nullptr) < 0) {
- return false;
- }
- if (sscanf(prop_value, "%u", &dst->periodCount) != 1) {
- return false;
+ if (property_get(propName, propValue, nullptr) < 0) {
+ return defaultValue;
}
- if (property_get("ro.hardware.audio.tinyalsa.period_size_multiplier", prop_value, nullptr) < 0) {
- return false;
- }
- if (sscanf(prop_value, "%u", &dst->periodSizeMultiplier) != 1) {
- return false;
- }
-
- return true;
+ unsigned value;
+ return (sscanf(propValue, "%u", &value) == 1) ? value : defaultValue;
}
-
} // namespace
-PcmPeriodSettings pcmGetPcmPeriodSettings() {
- std::call_once(gPcmPeriodSettingsFlag, [](){
- if (!initPcmPeriodSettings(&gPcmPeriodSettings)) {
- gPcmPeriodSettings = kDefaultPcmPeriodSettings;
- }
- });
+void init() {
+ gPcmPeriodSettings.periodCount =
+ readUnsignedProperty("ro.hardware.audio.tinyalsa.period_count", 4);
+ gPcmPeriodSettings.periodSizeMultiplier =
+ readUnsignedProperty("ro.hardware.audio.tinyalsa.period_size_multiplier", 1);
+}
+
+PcmPeriodSettings pcmGetPcmPeriodSettings() {
return gPcmPeriodSettings;
}
diff --git a/audio/talsa.h b/audio/talsa.h
index 1854f1e..8cc3c8f 100644
--- a/audio/talsa.h
+++ b/audio/talsa.h
@@ -33,6 +33,7 @@
unsigned periodSizeMultiplier;
};
+void init();
PcmPeriodSettings pcmGetPcmPeriodSettings();
typedef struct pcm pcm_t;
diff --git a/init.ranchu.rc b/init.ranchu.rc
index 5c6bc9f..a5edf26 100644
--- a/init.ranchu.rc
+++ b/init.ranchu.rc
@@ -59,6 +59,9 @@
chmod 0664 /dev/cpuctl/top-app/tasks
chmod 0664 /dev/cpuctl/rt/tasks
+ setprop ro.hardware.audio.tinyalsa.period_count 4
+ setprop ro.hardware.audio.tinyalsa.period_size_multiplier 4
+
start qemu-props
on post-fs-data
@@ -94,8 +97,6 @@
chown root system /sys/power/wake_lock
chown root system /sys/power/wake_unlock
setprop ro.hardware.audio.primary goldfish
- setprop ro.hardware.audio.tinyalsa.period_count 4
- setprop ro.hardware.audio.tinyalsa.period_size_multiplier 4
setprop wifi.interface wlan0
setprop wifi.direct.interface p2p-dev-wlan0