summaryrefslogtreecommitdiffstats
path: root/alsa_utils
diff options
context:
space:
mode:
Diffstat (limited to 'alsa_utils')
-rw-r--r--alsa_utils/alsa_device_profile.c71
-rw-r--r--alsa_utils/alsa_device_proxy.c21
-rw-r--r--alsa_utils/include/alsa_device_profile.h4
-rw-r--r--alsa_utils/include/alsa_device_proxy.h19
4 files changed, 103 insertions, 12 deletions
diff --git a/alsa_utils/alsa_device_profile.c b/alsa_utils/alsa_device_profile.c
index 0d9bd88..79ffcfc 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)) {
@@ -566,3 +581,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 ee92ed0..73e4375 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;
@@ -218,3 +217,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 5520b8a..e056d70 100644
--- a/alsa_utils/include/alsa_device_profile.h
+++ b/alsa_utils/include/alsa_device_profile.h
@@ -81,10 +81,14 @@ 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 */
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 e1ff8f5..0bc0731 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 */