From b776eb3998732bc0278cce84c0ecfd1d91d5874f Mon Sep 17 00:00:00 2001 From: Paul McLean Date: Wed, 11 May 2016 16:48:57 -0600 Subject: Adding dump functions to report state in dumpsys media.audio_flinger Change-Id: Icca1d817d56086f61290fc0a46aacd0c577752df --- alsa_utils/alsa_device_profile.c | 60 ++++++++++++++++++++++++++++++++ alsa_utils/alsa_device_proxy.c | 36 +++++++++++++++++-- alsa_utils/include/alsa_device_profile.h | 2 ++ alsa_utils/include/alsa_device_proxy.h | 5 +++ 4 files changed, 101 insertions(+), 2 deletions(-) diff --git a/alsa_utils/alsa_device_profile.c b/alsa_utils/alsa_device_profile.c index 0d9bd883..6a92668b 100644 --- a/alsa_utils/alsa_device_profile.c +++ b/alsa_utils/alsa_device_profile.c @@ -566,3 +566,63 @@ char * profile_get_channel_count_strs(alsa_device_profile* profile) return strdup(buffer); } + +void profile_dump(const alsa_device_profile* profile, int fd) +{ + char msg[128]; + int numBytes; + + write(fd, msg, sprintf(msg, " profile: %p\n", profile)); + + if (!profile->is_valid) { + write(fd, msg, sprintf(msg, " Profile is INVALID")); + } + + numBytes = sprintf(msg, " card:%d, device:%d - %s\n", + profile->card, profile->device, profile->direction == PCM_OUT ? "OUT" : "IN"); + write(fd, msg, numBytes); + + // enum pcm_format formats[MAX_PROFILE_FORMATS]; + write(fd, msg, sprintf(msg, " Formats: ")); + for(int fmtIndex = 0; + profile->formats[fmtIndex] != PCM_FORMAT_INVALID && fmtIndex < MAX_PROFILE_FORMATS; + fmtIndex++) { + numBytes = sprintf(msg, "%d ", profile->formats[fmtIndex]); + write(fd, &msg, numBytes); + } + write(fd, "\n", 1); + + // unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES]; + write(fd, msg, sprintf(msg, " Rates: ")); + for(int rateIndex = 0; + profile->sample_rates[rateIndex] != 0 && rateIndex < MAX_PROFILE_SAMPLE_RATES; + rateIndex++) { + numBytes = sprintf(msg, "%u ", profile->sample_rates[rateIndex]); + write(fd, &msg, numBytes); + } + write(fd, "\n", 1); + + // unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS]; + write(fd, msg, sprintf(msg, " Channel Counts: ")); + for(int cntIndex = 0; + profile->channel_counts[cntIndex] != 0 && cntIndex < MAX_PROFILE_CHANNEL_COUNTS; + cntIndex++) { + numBytes = sprintf(msg, "%u ", profile->channel_counts[cntIndex]); + write(fd, &msg, numBytes); + } + write(fd, "\n", 1); + + write(fd, msg, sprintf(msg, " min/max period size [%u : %u]\n", + profile->min_period_size,profile-> max_period_size)); + write(fd, msg, sprintf(msg, " min/max channel count [%u : %u]\n", + profile->min_channel_count, profile->max_channel_count)); + + // struct pcm_config default_config; + write(fd, msg, sprintf(msg, " Default Config:\n")); + write(fd, msg, sprintf(msg, " channels: %d\n", profile->default_config.channels)); + write(fd, msg, sprintf(msg, " rate: %d\n", profile->default_config.rate)); + write(fd, msg, sprintf(msg, " period_size: %d\n", profile->default_config.period_size)); + write(fd, msg, sprintf(msg, " period_count: %d\n", profile->default_config.period_count)); + write(fd, msg, sprintf(msg, " format: %d\n", profile->default_config.format)); +} + diff --git a/alsa_utils/alsa_device_proxy.c b/alsa_utils/alsa_device_proxy.c index ee92ed0c..62bbe047 100644 --- a/alsa_utils/alsa_device_proxy.c +++ b/alsa_utils/alsa_device_proxy.c @@ -15,7 +15,7 @@ */ #define LOG_TAG "alsa_device_proxy" -/*#define LOG_NDEBUG 0*/ +#define LOG_NDEBUG 0 /*#define LOG_PCM_PARAMS 0*/ #include @@ -43,7 +43,10 @@ void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile, struct pcm_config * config) { ALOGV("proxy_prepare(c:%d, d:%d)", profile->card, profile->device); - + if (profile->card < 0 || profile->device < 0) { + ALOGV("INVALID PROXY!"); + return; + } proxy->profile = profile; #ifdef LOG_PCM_PARAMS @@ -218,3 +221,32 @@ int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count) { return pcm_read(proxy->pcm, data, count); } + +/* + * Debugging + */ +void proxy_log(alsa_device_proxy * proxy, const char* tag) { + ALOGI("proxy_dump() - %s", tag); + + // struct pcm_config alsa_config; + ALOGI(" channels:%d", proxy->alsa_config.channels); + ALOGI(" rate:%d", proxy->alsa_config.rate); + ALOGI(" period_size:%d", proxy->alsa_config.period_size); + ALOGI(" period_count:%d", proxy->alsa_config.period_count); + ALOGI(" format:%d", proxy->alsa_config.format); + + // struct pcm * pcm; + +} + +void proxy_dump(const alsa_device_proxy* proxy, int fd) +{ + char msg[128]; + + write(fd, msg, sprintf(msg, " proxy: %p\n", proxy)); + write(fd, msg, sprintf(msg, " channels: %d\n", proxy->alsa_config.channels)); + write(fd, msg, sprintf(msg, " rate: %d\n", proxy->alsa_config.rate)); + write(fd, msg, sprintf(msg, " period_size: %d\n", proxy->alsa_config.period_size)); + write(fd, msg, sprintf(msg, " period_count: %d\n", proxy->alsa_config.period_count)); + write(fd, msg, sprintf(msg, " format: %d\n", proxy->alsa_config.format)); +} diff --git a/alsa_utils/include/alsa_device_profile.h b/alsa_utils/include/alsa_device_profile.h index 5520b8a7..0c6f6b4c 100644 --- a/alsa_utils/include/alsa_device_profile.h +++ b/alsa_utils/include/alsa_device_profile.h @@ -87,4 +87,6 @@ bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate); unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate); +void profile_dump(const alsa_device_profile* profile, int fd); + #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */ diff --git a/alsa_utils/include/alsa_device_proxy.h b/alsa_utils/include/alsa_device_proxy.h index e1ff8f5f..d0367513 100644 --- a/alsa_utils/include/alsa_device_proxy.h +++ b/alsa_utils/include/alsa_device_proxy.h @@ -52,4 +52,9 @@ void proxy_close(alsa_device_proxy * proxy); int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count); int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count); +/* Debugging */ +void proxy_log(alsa_device_proxy * proxy, const char* tag); + +void proxy_dump(const alsa_device_proxy * proxy, int fd); + #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H */ -- cgit v1.2.3 From 2a3925e95a9d4954be789dc4594233d4cc2d251c Mon Sep 17 00:00:00 2001 From: Paul Mclean Date: Thu, 2 Jun 2016 14:48:10 +0000 Subject: Revert "Adding dump functions to report state in dumpsys media.audio_flinger" This reverts commit b776eb3998732bc0278cce84c0ecfd1d91d5874f. Change-Id: I7c0806abe5052afb46ca96d506cc5cadc79ee5fe --- alsa_utils/alsa_device_profile.c | 60 -------------------------------- alsa_utils/alsa_device_proxy.c | 36 ++----------------- alsa_utils/include/alsa_device_profile.h | 2 -- alsa_utils/include/alsa_device_proxy.h | 5 --- 4 files changed, 2 insertions(+), 101 deletions(-) diff --git a/alsa_utils/alsa_device_profile.c b/alsa_utils/alsa_device_profile.c index 6a92668b..0d9bd883 100644 --- a/alsa_utils/alsa_device_profile.c +++ b/alsa_utils/alsa_device_profile.c @@ -566,63 +566,3 @@ char * profile_get_channel_count_strs(alsa_device_profile* profile) return strdup(buffer); } - -void profile_dump(const alsa_device_profile* profile, int fd) -{ - char msg[128]; - int numBytes; - - write(fd, msg, sprintf(msg, " profile: %p\n", profile)); - - if (!profile->is_valid) { - write(fd, msg, sprintf(msg, " Profile is INVALID")); - } - - numBytes = sprintf(msg, " card:%d, device:%d - %s\n", - profile->card, profile->device, profile->direction == PCM_OUT ? "OUT" : "IN"); - write(fd, msg, numBytes); - - // enum pcm_format formats[MAX_PROFILE_FORMATS]; - write(fd, msg, sprintf(msg, " Formats: ")); - for(int fmtIndex = 0; - profile->formats[fmtIndex] != PCM_FORMAT_INVALID && fmtIndex < MAX_PROFILE_FORMATS; - fmtIndex++) { - numBytes = sprintf(msg, "%d ", profile->formats[fmtIndex]); - write(fd, &msg, numBytes); - } - write(fd, "\n", 1); - - // unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES]; - write(fd, msg, sprintf(msg, " Rates: ")); - for(int rateIndex = 0; - profile->sample_rates[rateIndex] != 0 && rateIndex < MAX_PROFILE_SAMPLE_RATES; - rateIndex++) { - numBytes = sprintf(msg, "%u ", profile->sample_rates[rateIndex]); - write(fd, &msg, numBytes); - } - write(fd, "\n", 1); - - // unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS]; - write(fd, msg, sprintf(msg, " Channel Counts: ")); - for(int cntIndex = 0; - profile->channel_counts[cntIndex] != 0 && cntIndex < MAX_PROFILE_CHANNEL_COUNTS; - cntIndex++) { - numBytes = sprintf(msg, "%u ", profile->channel_counts[cntIndex]); - write(fd, &msg, numBytes); - } - write(fd, "\n", 1); - - write(fd, msg, sprintf(msg, " min/max period size [%u : %u]\n", - profile->min_period_size,profile-> max_period_size)); - write(fd, msg, sprintf(msg, " min/max channel count [%u : %u]\n", - profile->min_channel_count, profile->max_channel_count)); - - // struct pcm_config default_config; - write(fd, msg, sprintf(msg, " Default Config:\n")); - write(fd, msg, sprintf(msg, " channels: %d\n", profile->default_config.channels)); - write(fd, msg, sprintf(msg, " rate: %d\n", profile->default_config.rate)); - write(fd, msg, sprintf(msg, " period_size: %d\n", profile->default_config.period_size)); - write(fd, msg, sprintf(msg, " period_count: %d\n", profile->default_config.period_count)); - write(fd, msg, sprintf(msg, " format: %d\n", profile->default_config.format)); -} - diff --git a/alsa_utils/alsa_device_proxy.c b/alsa_utils/alsa_device_proxy.c index 62bbe047..ee92ed0c 100644 --- a/alsa_utils/alsa_device_proxy.c +++ b/alsa_utils/alsa_device_proxy.c @@ -15,7 +15,7 @@ */ #define LOG_TAG "alsa_device_proxy" -#define LOG_NDEBUG 0 +/*#define LOG_NDEBUG 0*/ /*#define LOG_PCM_PARAMS 0*/ #include @@ -43,10 +43,7 @@ void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile, struct pcm_config * config) { ALOGV("proxy_prepare(c:%d, d:%d)", profile->card, profile->device); - if (profile->card < 0 || profile->device < 0) { - ALOGV("INVALID PROXY!"); - return; - } + proxy->profile = profile; #ifdef LOG_PCM_PARAMS @@ -221,32 +218,3 @@ int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count) { return pcm_read(proxy->pcm, data, count); } - -/* - * Debugging - */ -void proxy_log(alsa_device_proxy * proxy, const char* tag) { - ALOGI("proxy_dump() - %s", tag); - - // struct pcm_config alsa_config; - ALOGI(" channels:%d", proxy->alsa_config.channels); - ALOGI(" rate:%d", proxy->alsa_config.rate); - ALOGI(" period_size:%d", proxy->alsa_config.period_size); - ALOGI(" period_count:%d", proxy->alsa_config.period_count); - ALOGI(" format:%d", proxy->alsa_config.format); - - // struct pcm * pcm; - -} - -void proxy_dump(const alsa_device_proxy* proxy, int fd) -{ - char msg[128]; - - write(fd, msg, sprintf(msg, " proxy: %p\n", proxy)); - write(fd, msg, sprintf(msg, " channels: %d\n", proxy->alsa_config.channels)); - write(fd, msg, sprintf(msg, " rate: %d\n", proxy->alsa_config.rate)); - write(fd, msg, sprintf(msg, " period_size: %d\n", proxy->alsa_config.period_size)); - write(fd, msg, sprintf(msg, " period_count: %d\n", proxy->alsa_config.period_count)); - write(fd, msg, sprintf(msg, " format: %d\n", proxy->alsa_config.format)); -} diff --git a/alsa_utils/include/alsa_device_profile.h b/alsa_utils/include/alsa_device_profile.h index 0c6f6b4c..5520b8a7 100644 --- a/alsa_utils/include/alsa_device_profile.h +++ b/alsa_utils/include/alsa_device_profile.h @@ -87,6 +87,4 @@ bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate); unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate); -void profile_dump(const alsa_device_profile* profile, int fd); - #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */ diff --git a/alsa_utils/include/alsa_device_proxy.h b/alsa_utils/include/alsa_device_proxy.h index d0367513..e1ff8f5f 100644 --- a/alsa_utils/include/alsa_device_proxy.h +++ b/alsa_utils/include/alsa_device_proxy.h @@ -52,9 +52,4 @@ void proxy_close(alsa_device_proxy * proxy); int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count); int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count); -/* Debugging */ -void proxy_log(alsa_device_proxy * proxy, const char* tag); - -void proxy_dump(const alsa_device_proxy * proxy, int fd); - #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H */ -- cgit v1.2.3 From 21b04ade57e5cbf33eff11f3f400f77eed5e2e75 Mon Sep 17 00:00:00 2001 From: Paul McLean Date: Wed, 25 May 2016 14:07:00 -0600 Subject: Add dump() (i.e dumpsys media.audio_flinger) functionality to USB HAL Bug: 28960293 Change-Id: Ice8a72b77ba00a816d12d2028b4ea5e7fe4bd319 --- alsa_utils/alsa_device_profile.c | 56 ++++++++++++++++++++++++++++++++ alsa_utils/alsa_device_proxy.c | 14 ++++++++ alsa_utils/include/alsa_device_profile.h | 3 ++ alsa_utils/include/alsa_device_proxy.h | 19 ++++++----- 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/alsa_utils/alsa_device_profile.c b/alsa_utils/alsa_device_profile.c index 0d9bd883..f3ee7bbe 100644 --- a/alsa_utils/alsa_device_profile.c +++ b/alsa_utils/alsa_device_profile.c @@ -566,3 +566,59 @@ char * profile_get_channel_count_strs(alsa_device_profile* profile) return strdup(buffer); } + +void profile_dump(const alsa_device_profile* profile, int fd) +{ + if (profile == NULL) { + dprintf(fd, " %s\n", "No USB Profile"); + return; /* bail early */ + } + + if (!profile->is_valid) { + dprintf(fd, " Profile is INVALID"); + } + + /* card/device/direction */ + dprintf(fd, " card:%d, device:%d - %s\n", + profile->card, profile->device, profile->direction == PCM_OUT ? "OUT" : "IN"); + + /* formats */ + dprintf(fd, " Formats: "); + for (int fmtIndex = 0; + profile->formats[fmtIndex] != PCM_FORMAT_INVALID && fmtIndex < MAX_PROFILE_FORMATS; + fmtIndex++) { + dprintf(fd, "%d ", profile->formats[fmtIndex]); + } + dprintf(fd, "\n"); + + /* sample rates */ + dprintf(fd, " Rates: "); + for (int rateIndex = 0; + profile->sample_rates[rateIndex] != 0 && rateIndex < MAX_PROFILE_SAMPLE_RATES; + rateIndex++) { + dprintf(fd, "%u ", profile->sample_rates[rateIndex]); + } + dprintf(fd, "\n"); + + // channel counts + dprintf(fd, " Channel Counts: "); + for (int cntIndex = 0; + profile->channel_counts[cntIndex] != 0 && cntIndex < MAX_PROFILE_CHANNEL_COUNTS; + cntIndex++) { + dprintf(fd, "%u ", profile->channel_counts[cntIndex]); + } + dprintf(fd, "\n"); + + dprintf(fd, " min/max period size [%u : %u]\n", + profile->min_period_size,profile-> max_period_size); + dprintf(fd, " min/max channel count [%u : %u]\n", + profile->min_channel_count, profile->max_channel_count); + + // struct pcm_config default_config; + dprintf(fd, " Default Config:\n"); + dprintf(fd, " channels: %d\n", profile->default_config.channels); + dprintf(fd, " rate: %d\n", profile->default_config.rate); + dprintf(fd, " period_size: %d\n", profile->default_config.period_size); + dprintf(fd, " period_count: %d\n", profile->default_config.period_count); + dprintf(fd, " format: %d\n", profile->default_config.format); +} diff --git a/alsa_utils/alsa_device_proxy.c b/alsa_utils/alsa_device_proxy.c index ee92ed0c..7f56b04e 100644 --- a/alsa_utils/alsa_device_proxy.c +++ b/alsa_utils/alsa_device_proxy.c @@ -218,3 +218,17 @@ int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count) { return pcm_read(proxy->pcm, data, count); } + +/* + * Debugging + */ +void proxy_dump(const alsa_device_proxy* proxy, int fd) +{ + if (proxy != NULL) { + dprintf(fd, " channels: %d\n", proxy->alsa_config.channels); + dprintf(fd, " rate: %d\n", proxy->alsa_config.rate); + dprintf(fd, " period_size: %d\n", proxy->alsa_config.period_size); + dprintf(fd, " period_count: %d\n", proxy->alsa_config.period_count); + dprintf(fd, " format: %d\n", proxy->alsa_config.format); + } +} diff --git a/alsa_utils/include/alsa_device_profile.h b/alsa_utils/include/alsa_device_profile.h index 5520b8a7..fcde7ac2 100644 --- a/alsa_utils/include/alsa_device_profile.h +++ b/alsa_utils/include/alsa_device_profile.h @@ -87,4 +87,7 @@ bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate); unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate); +/* Debugging */ +void profile_dump(const alsa_device_profile* profile, int fd); + #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */ diff --git a/alsa_utils/include/alsa_device_proxy.h b/alsa_utils/include/alsa_device_proxy.h index e1ff8f5f..0bc0731a 100644 --- a/alsa_utils/include/alsa_device_proxy.h +++ b/alsa_utils/include/alsa_device_proxy.h @@ -32,24 +32,27 @@ typedef struct { uint64_t transferred; /* the total frames transferred, not cleared on standby */ } alsa_device_proxy; + +/* State */ void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile * profile, struct pcm_config * config); +int proxy_open(alsa_device_proxy * proxy); +void proxy_close(alsa_device_proxy * proxy); +int proxy_get_presentation_position(const alsa_device_proxy * proxy, + uint64_t *frames, struct timespec *timestamp); +/* Attributes */ unsigned proxy_get_sample_rate(const alsa_device_proxy * proxy); enum pcm_format proxy_get_format(const alsa_device_proxy * proxy); unsigned proxy_get_channel_count(const alsa_device_proxy * proxy); - unsigned int proxy_get_period_size(const alsa_device_proxy * proxy); - unsigned proxy_get_latency(const alsa_device_proxy * proxy); -int proxy_get_presentation_position(const alsa_device_proxy * proxy, - uint64_t *frames, struct timespec *timestamp); - -int proxy_open(alsa_device_proxy * proxy); -void proxy_close(alsa_device_proxy * proxy); - +/* I/O */ int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count); int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count); +/* Debugging */ +void proxy_dump(const alsa_device_proxy * proxy, int fd); + #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H */ -- cgit v1.2.3 From eafa18a241f1e1f82f8586d7686f16470506640e Mon Sep 17 00:00:00 2001 From: Paul McLean Date: Fri, 10 Jun 2016 11:47:43 -0600 Subject: Add a function to get a "closest" match to supported channel counts. Bug: 29154372 Change-Id: I5ac51eb2cb250b42fe638ec96e5dfff9425d67f6 --- alsa_utils/alsa_device_profile.c | 15 +++++++++++++++ alsa_utils/alsa_device_proxy.c | 7 +++---- alsa_utils/include/alsa_device_profile.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/alsa_utils/alsa_device_profile.c b/alsa_utils/alsa_device_profile.c index f3ee7bbe..79ffcfc9 100644 --- a/alsa_utils/alsa_device_profile.c +++ b/alsa_utils/alsa_device_profile.c @@ -192,6 +192,21 @@ unsigned profile_get_default_channel_count(alsa_device_profile* profile) return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT; } +unsigned profile_get_closest_channel_count(alsa_device_profile* profile, unsigned count) +{ + if (profile_is_valid(profile)) { + if (count < profile->min_channel_count) { + return profile->min_channel_count; + } else if (count > profile->max_channel_count) { + return profile->max_channel_count; + } else { + return count; + } + } else { + return 0; + } +} + bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count) { if (profile_is_initialized(profile)) { diff --git a/alsa_utils/alsa_device_proxy.c b/alsa_utils/alsa_device_proxy.c index 7f56b04e..73e43758 100644 --- a/alsa_utils/alsa_device_proxy.c +++ b/alsa_utils/alsa_device_proxy.c @@ -69,10 +69,9 @@ void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile, if (config->channels != 0 && profile_is_channel_count_valid(profile, config->channels)) { proxy->alsa_config.channels = config->channels; } else { - ALOGW("Invalid channel count %u - using default %u.", - config->channels, profile->default_config.channels); - proxy->alsa_config.channels = profile->default_config.channels; - + proxy->alsa_config.channels = profile_get_closest_channel_count(profile, config->channels); + ALOGW("Invalid channel count %u - using closest %u.", + config->channels, proxy->alsa_config.channels); } proxy->alsa_config.period_count = profile->default_config.period_count; diff --git a/alsa_utils/include/alsa_device_profile.h b/alsa_utils/include/alsa_device_profile.h index fcde7ac2..e056d70c 100644 --- a/alsa_utils/include/alsa_device_profile.h +++ b/alsa_utils/include/alsa_device_profile.h @@ -81,6 +81,7 @@ bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt); /* Channel Methods */ unsigned profile_get_default_channel_count(alsa_device_profile* profile); +unsigned profile_get_closest_channel_count(alsa_device_profile* profile, unsigned count); bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count); /* Utility */ -- cgit v1.2.3 From 57a4158dc4c4ce62bc6a2b8a0072ba43305548d4 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 7 Jul 2016 18:53:19 -0700 Subject: Add Dolby TrueHD audio format Bug: 30024357 Change-Id: I2ca8d24e9b9b053a42e1bcf3802fdf866f82053d --- audio/include/system/audio.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/audio/include/system/audio.h b/audio/include/system/audio.h index 2d9839ec..b81b379c 100644 --- a/audio/include/system/audio.h +++ b/audio/include/system/audio.h @@ -316,6 +316,7 @@ typedef enum { AUDIO_FORMAT_DTS_HD = 0x0C000000UL, // IEC61937 is encoded audio wrapped in 16-bit PCM. AUDIO_FORMAT_IEC61937 = 0x0D000000UL, + AUDIO_FORMAT_DOLBY_TRUEHD = 0x0E000000UL, AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, /* Deprecated. Use audio_get_main_format() */ AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, @@ -1442,6 +1443,7 @@ static inline bool audio_is_valid_format(audio_format_t format) case AUDIO_FORMAT_DTS: case AUDIO_FORMAT_DTS_HD: case AUDIO_FORMAT_IEC61937: + case AUDIO_FORMAT_DOLBY_TRUEHD: return true; default: return false; -- cgit v1.2.3 From 23b643a5e8ae4f185222bfe4c0aba02df2aa22ca Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Fri, 8 Jul 2016 14:10:33 -0700 Subject: Add host native build of primitives_test Change-Id: Ib3271c787363e63800cdf40984e2b345e0e4ed6e --- audio_utils/tests/Android.mk | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/audio_utils/tests/Android.mk b/audio_utils/tests/Android.mk index 0db09dc3..cd76cf03 100644 --- a/audio_utils/tests/Android.mk +++ b/audio_utils/tests/Android.mk @@ -1,25 +1,36 @@ # Build the unit tests for audio_utils LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) +include $(CLEAR_VARS) LOCAL_SHARED_LIBRARIES := \ liblog \ libcutils \ libaudioutils - LOCAL_C_INCLUDES := \ $(call include-path-for, audio-utils) - LOCAL_SRC_FILES := \ primitives_tests.cpp - LOCAL_MODULE := primitives_tests LOCAL_MODULE_TAGS := tests - LOCAL_CFLAGS := -Werror -Wall include $(BUILD_NATIVE_TEST) +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils +LOCAL_STATIC_LIBRARIES := \ + libaudioutils +LOCAL_C_INCLUDES := \ + $(call include-path-for, audio-utils) +LOCAL_SRC_FILES := \ + primitives_tests.cpp +LOCAL_MODULE := primitives_tests +LOCAL_MODULE_TAGS := tests +LOCAL_CFLAGS := -Werror -Wall +include $(BUILD_HOST_NATIVE_TEST) + include $(CLEAR_VARS) LOCAL_SRC_FILES := fifo_tests.cpp LOCAL_MODULE := fifo_tests -- cgit v1.2.3 From bad0898a944d6a7886b4ab8ca8e0157885d9aadf Mon Sep 17 00:00:00 2001 From: Haynes Mathew George Date: Tue, 28 Jun 2016 13:52:18 -0700 Subject: audio_utils: Support more format conversions Support conversion from 32 bit pcm to 24 bit packed pcm. Support conversion from 8_24 bit to 24 bit packed pcm. Support conversion from 24 bit packed pcm to 32 bit pcm. authored-by: Ashish Jain Change-Id: I328ef6ed865f73e49be50ffa1b4e07e865df0339 --- audio_utils/format.c | 9 +++++++++ audio_utils/tests/primitives_tests.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/audio_utils/format.c b/audio_utils/format.c index 66b0a6db..3eda4849 100644 --- a/audio_utils/format.c +++ b/audio_utils/format.c @@ -102,6 +102,12 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, case AUDIO_FORMAT_PCM_FLOAT: memcpy_to_p24_from_float((uint8_t*)dst, (float*)src, count); return; + case AUDIO_FORMAT_PCM_32_BIT: + memcpy_to_p24_from_i32((uint8_t*)dst, (int32_t*)src, count); + return; + case AUDIO_FORMAT_PCM_8_24_BIT: + memcpy_to_p24_from_q8_23((uint8_t*)dst, (int32_t*)src, count); + return; default: break; } @@ -114,6 +120,9 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, case AUDIO_FORMAT_PCM_FLOAT: memcpy_to_i32_from_float((int32_t*)dst, (float*)src, count); return; + case AUDIO_FORMAT_PCM_24_BIT_PACKED: + memcpy_to_i32_from_p24((int32_t*)dst, (uint8_t *)src, count); + return; default: break; } diff --git a/audio_utils/tests/primitives_tests.cpp b/audio_utils/tests/primitives_tests.cpp index 5b3cd2d7..178490b4 100644 --- a/audio_utils/tests/primitives_tests.cpp +++ b/audio_utils/tests/primitives_tests.cpp @@ -103,6 +103,14 @@ void checkMonotone(const T *ary, size_t size) } } +void checkMonotonep24(uint8_t * pary, size_t size) +{ + size_t frames = size/3; + for (size_t i = 1; i < frames; ++i) { + EXPECT_LT(i32_from_p24(pary + 3*(i-1)), i32_from_p24(pary + 3*i)); + } +} + TEST(audio_utils_primitives, clamp_to_int) { static const float testArray[] = { -NAN, -INFINITY, @@ -256,6 +264,31 @@ TEST(audio_utils_primitives, memcpy) { memset(i32ary, 0, 65536 * sizeof(i32ary[0])); checkMonotone(i16ary, 65536); + // do round-trip test i16 -> p24 -> i32 -> p24 -> q8_23 -> p24 -> i16 + memcpy_to_p24_from_i16(pary, i16ary, 65536); + memset(i16ary, 0, 65536 * sizeof(i16ary[0])); + checkMonotonep24(pary, 65536 * 3); + + memcpy_to_i32_from_p24(i32ary, pary, 65536); + memset(pary, 0, 65536 * 3 * sizeof(pary[0])); + checkMonotone(i32ary, 65536); + + memcpy_to_p24_from_i32(pary, i32ary, 65536); + memset(i32ary, 0, 65536 * sizeof(i32ary[0])); + checkMonotonep24(pary, 65536 * 3); + + memcpy_to_q8_23_from_p24(i32ary, pary, 65536); + memset(pary, 0, 65536 * 3 * sizeof(pary[0])); + checkMonotone(i32ary, 65536); + + memcpy_to_p24_from_q8_23(pary, i32ary, 65536); + memset(i32ary, 0, 65536 * sizeof(i32ary[0])); + checkMonotonep24(pary, 65536 * 3); + + memcpy_to_i16_from_p24(i16ary, pary, 65536); + memset(pary, 0, 65536 * 3 * sizeof(pary[0])); + checkMonotone(i16ary, 65536); + // do partial round-trip testing q4_27 to i16 and float memcpy_to_float_from_i16(fary, i16ary, 65536); //memset(i16ary, 0, 65536 * sizeof(i16ary[0])); // not cleared: we don't do full roundtrip -- cgit v1.2.3 From 62d8d87dd3cef5e06acaf617961db38ec4ea8b73 Mon Sep 17 00:00:00 2001 From: Chien-Yu Chen Date: Fri, 12 Aug 2016 15:40:16 -0700 Subject: Camera: Prevent data size overflow Add a function to check overflow when calculating metadata data size. Bug: 30741779 Change-Id: I6405fe608567a4f4113674050f826f305ecae030 --- camera/src/camera_metadata.c | 57 +++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/camera/src/camera_metadata.c b/camera/src/camera_metadata.c index c58a9669..92926872 100644 --- a/camera/src/camera_metadata.c +++ b/camera/src/camera_metadata.c @@ -25,9 +25,10 @@ #include #include -#define OK 0 -#define ERROR 1 -#define NOT_FOUND -ENOENT +#define OK 0 +#define ERROR 1 +#define NOT_FOUND -ENOENT +#define SN_EVENT_LOG_ID 0x534e4554 #define ALIGN_TO(val, alignment) \ (((uintptr_t)(val) + ((alignment) - 1)) & ~((alignment) - 1)) @@ -299,6 +300,38 @@ camera_metadata_t* copy_camera_metadata(void *dst, size_t dst_size, return metadata; } +// This method should be used when the camera metadata cannot be trusted. For example, when it's +// read from Parcel. +static int validate_and_calculate_camera_metadata_entry_data_size(size_t *data_size, uint8_t type, + size_t data_count) { + if (type >= NUM_TYPES) return ERROR; + + // Check for overflow + if (data_count != 0 && + camera_metadata_type_size[type] > (SIZE_MAX - DATA_ALIGNMENT + 1) / data_count) { + android_errorWriteLog(SN_EVENT_LOG_ID, "30741779"); + return ERROR; + } + + size_t data_bytes = data_count * camera_metadata_type_size[type]; + + if (data_size) { + *data_size = data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); + } + + return OK; +} + +size_t calculate_camera_metadata_entry_data_size(uint8_t type, + size_t data_count) { + if (type >= NUM_TYPES) return 0; + + size_t data_bytes = data_count * + camera_metadata_type_size[type]; + + return data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); +} + int validate_camera_metadata_structure(const camera_metadata_t *metadata, const size_t *expected_size) { @@ -414,9 +447,13 @@ int validate_camera_metadata_structure(const camera_metadata_t *metadata, return ERROR; } - size_t data_size = - calculate_camera_metadata_entry_data_size(entry.type, - entry.count); + size_t data_size; + if (validate_and_calculate_camera_metadata_entry_data_size(&data_size, entry.type, + entry.count) != OK) { + ALOGE("%s: Entry data size is invalid. type: %u count: %u", __FUNCTION__, entry.type, + entry.count); + return ERROR; + } if (data_size != 0) { camera_metadata_data_t *data = @@ -508,14 +545,6 @@ camera_metadata_t *clone_camera_metadata(const camera_metadata_t *src) { return clone; } -size_t calculate_camera_metadata_entry_data_size(uint8_t type, - size_t data_count) { - if (type >= NUM_TYPES) return 0; - size_t data_bytes = data_count * - camera_metadata_type_size[type]; - return data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); -} - static int add_camera_metadata_entry_raw(camera_metadata_t *dst, uint32_t tag, uint8_t type, -- cgit v1.2.3 From 97a9cd6748fb7d5ef99e7d68c346ecaba1318e94 Mon Sep 17 00:00:00 2001 From: Chien-Yu Chen Date: Fri, 12 Aug 2016 15:40:16 -0700 Subject: Camera: Prevent data size overflow Add a function to check overflow when calculating metadata data size. Bug: 30741779 Change-Id: I6405fe608567a4f4113674050f826f305ecae030 --- camera/src/camera_metadata.c | 57 +++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/camera/src/camera_metadata.c b/camera/src/camera_metadata.c index a413f66c..3f435ebd 100644 --- a/camera/src/camera_metadata.c +++ b/camera/src/camera_metadata.c @@ -22,9 +22,10 @@ #include #include -#define OK 0 -#define ERROR 1 -#define NOT_FOUND -ENOENT +#define OK 0 +#define ERROR 1 +#define NOT_FOUND -ENOENT +#define SN_EVENT_LOG_ID 0x534e4554 #define _Alignas(T) \ ({struct _AlignasStruct { char c; T field; }; \ @@ -291,6 +292,38 @@ camera_metadata_t* copy_camera_metadata(void *dst, size_t dst_size, return metadata; } +// This method should be used when the camera metadata cannot be trusted. For example, when it's +// read from Parcel. +static int validate_and_calculate_camera_metadata_entry_data_size(size_t *data_size, uint8_t type, + size_t data_count) { + if (type >= NUM_TYPES) return ERROR; + + // Check for overflow + if (data_count != 0 && + camera_metadata_type_size[type] > (SIZE_MAX - DATA_ALIGNMENT + 1) / data_count) { + android_errorWriteLog(SN_EVENT_LOG_ID, "30741779"); + return ERROR; + } + + size_t data_bytes = data_count * camera_metadata_type_size[type]; + + if (data_size) { + *data_size = data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); + } + + return OK; +} + +size_t calculate_camera_metadata_entry_data_size(uint8_t type, + size_t data_count) { + if (type >= NUM_TYPES) return 0; + + size_t data_bytes = data_count * + camera_metadata_type_size[type]; + + return data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); +} + int validate_camera_metadata_structure(const camera_metadata_t *metadata, const size_t *expected_size) { @@ -400,9 +433,13 @@ int validate_camera_metadata_structure(const camera_metadata_t *metadata, return ERROR; } - size_t data_size = - calculate_camera_metadata_entry_data_size(entry.type, - entry.count); + size_t data_size; + if (validate_and_calculate_camera_metadata_entry_data_size(&data_size, entry.type, + entry.count) != OK) { + ALOGE("%s: Entry data size is invalid. type: %u count: %u", __FUNCTION__, entry.type, + entry.count); + return ERROR; + } if (data_size != 0) { camera_metadata_data_t *data = @@ -492,14 +529,6 @@ camera_metadata_t *clone_camera_metadata(const camera_metadata_t *src) { return clone; } -size_t calculate_camera_metadata_entry_data_size(uint8_t type, - size_t data_count) { - if (type >= NUM_TYPES) return 0; - size_t data_bytes = data_count * - camera_metadata_type_size[type]; - return data_bytes <= 4 ? 0 : ALIGN_TO(data_bytes, DATA_ALIGNMENT); -} - static int add_camera_metadata_entry_raw(camera_metadata_t *dst, uint32_t tag, uint8_t type, -- cgit v1.2.3 From 4633133e74e33846fe87ac6033cc6d479ecfe828 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Tue, 16 Aug 2016 15:48:05 -0700 Subject: Camera metadata: Check for inconsistent data count Also check for overflow of data/entry count on append. Bug: 30591838 Change-Id: Ibf4c3c6e236cdb28234f3125055d95ef0a2416a2 --- camera/src/camera_metadata.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/camera/src/camera_metadata.c b/camera/src/camera_metadata.c index 92926872..e369c642 100644 --- a/camera/src/camera_metadata.c +++ b/camera/src/camera_metadata.c @@ -390,6 +390,14 @@ int validate_camera_metadata_structure(const camera_metadata_t *metadata, return ERROR; } + if (metadata->data_count > metadata->data_capacity) { + ALOGE("%s: Data count (%" PRIu32 ") should be <= data capacity " + "(%" PRIu32 ")", + __FUNCTION__, metadata->data_count, metadata->data_capacity); + android_errorWriteLog(SN_EVENT_LOG_ID, "30591838"); + return ERROR; + } + const metadata_uptrdiff_t entries_end = metadata->entries_start + metadata->entry_capacity; if (entries_end < metadata->entries_start || // overflow check @@ -496,6 +504,10 @@ int append_camera_metadata(camera_metadata_t *dst, const camera_metadata_t *src) { if (dst == NULL || src == NULL ) return ERROR; + // Check for overflow + if (src->entry_count + dst->entry_count < src->entry_count) return ERROR; + if (src->data_count + dst->data_count < src->data_count) return ERROR; + // Check for space if (dst->entry_capacity < src->entry_count + dst->entry_count) return ERROR; if (dst->data_capacity < src->data_count + dst->data_count) return ERROR; -- cgit v1.2.3 From 241ff3e1cea259072fc0de34badf57aefe02f27c Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Tue, 16 Aug 2016 15:48:05 -0700 Subject: Camera metadata: Check for inconsistent data count Also check for overflow of data/entry count on append. Bug: 30591838 Change-Id: Ibf4c3c6e236cdb28234f3125055d95ef0a2416a2 --- camera/src/camera_metadata.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/camera/src/camera_metadata.c b/camera/src/camera_metadata.c index 3f435ebd..e9ad689e 100644 --- a/camera/src/camera_metadata.c +++ b/camera/src/camera_metadata.c @@ -14,6 +14,7 @@ * limitations under the License. */ #define _GNU_SOURCE // for fdprintf +#include #include #define LOG_TAG "camera_metadata" @@ -380,6 +381,14 @@ int validate_camera_metadata_structure(const camera_metadata_t *metadata, return ERROR; } + if (metadata->data_count > metadata->data_capacity) { + ALOGE("%s: Data count (%" PRIu32 ") should be <= data capacity " + "(%" PRIu32 ")", + __FUNCTION__, metadata->data_count, metadata->data_capacity); + android_errorWriteLog(SN_EVENT_LOG_ID, "30591838"); + return ERROR; + } + uptrdiff_t entries_end = metadata->entries_start + metadata->entry_capacity; if (entries_end < metadata->entries_start || // overflow check entries_end > metadata->data_start) { @@ -482,6 +491,10 @@ int append_camera_metadata(camera_metadata_t *dst, const camera_metadata_t *src) { if (dst == NULL || src == NULL ) return ERROR; + // Check for overflow + if (src->entry_count + dst->entry_count < src->entry_count) return ERROR; + if (src->data_count + dst->data_count < src->data_count) return ERROR; + // Check for space if (dst->entry_capacity < src->entry_count + dst->entry_count) return ERROR; if (dst->data_capacity < src->data_count + dst->data_count) return ERROR; -- cgit v1.2.3 From 7bbd5008747431d42e2f8cfbc0ddcb8465cdb4a5 Mon Sep 17 00:00:00 2001 From: rago Date: Tue, 23 Aug 2016 11:09:52 -0700 Subject: Fix potential overflow in Visualizer effect Bug: 30229821 Change-Id: Ia07041a5a149d7d3e120aa6ea0345fb86da37c9b (cherry picked from commit b61dd321d08b21a5629044eca7f96e2ecd348e5f) --- audio_effects/include/audio_effects/effect_visualizer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/audio_effects/include/audio_effects/effect_visualizer.h b/audio_effects/include/audio_effects/effect_visualizer.h index cfd99f50..fe46d7fc 100644 --- a/audio_effects/include/audio_effects/effect_visualizer.h +++ b/audio_effects/include/audio_effects/effect_visualizer.h @@ -41,6 +41,7 @@ const effect_uuid_t * const SL_IID_VISUALIZATION = &SL_IID_VISUALIZATION_; #define MEASUREMENT_IDX_PEAK 0 #define MEASUREMENT_IDX_RMS 1 +#define MEASUREMENT_COUNT 2 /* enumerated parameters for Visualizer effect */ typedef enum -- cgit v1.2.3 From ff3e6f401eb371bd51eaed91bfec1728ec22f3d1 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 12 Oct 2016 10:38:12 -0700 Subject: audio_route: add check on enum values Bug: 31906753 Bug: 32064030 Change-Id: Id57ad136b2c314040e6cbf62a3319ecef2c2114b --- audio_route/audio_route.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/audio_route/audio_route.c b/audio_route/audio_route.c index 90b114d5..bd5c1124 100644 --- a/audio_route/audio_route.c +++ b/audio_route/audio_route.c @@ -420,13 +420,24 @@ static int path_reset(struct audio_route *ar, struct mixer_path *path) static int mixer_enum_string_to_value(struct mixer_ctl *ctl, const char *string) { unsigned int i; + unsigned int num_values = mixer_ctl_get_num_enums(ctl); + + if (string == NULL) { + ALOGE("NULL enum value string passed to mixer_enum_string_to_value() for ctl %s", + mixer_ctl_get_name(ctl)); + return 0; + } /* Search the enum strings for a particular one */ - for (i = 0; i < mixer_ctl_get_num_enums(ctl); i++) { + for (i = 0; i < num_values; i++) { if (strcmp(mixer_ctl_get_enum_string(ctl, i), string) == 0) break; } - + if (i == num_values) { + ALOGE("unknown enum value string %s for ctl %s", + string, mixer_ctl_get_name(ctl)); + return 0; + } return i; } -- cgit v1.2.3