OSDN Git Service

Add const qualifiers to alsa device profile.
authorAndy Hung <hunga@google.com>
Sat, 28 Oct 2017 03:20:27 +0000 (20:20 -0700)
committerAndy Hung <hunga@google.com>
Sat, 28 Oct 2017 03:59:46 +0000 (20:59 -0700)
Test: make
Bug: 68211730
Change-Id: I97e5ca3bded99f7005332b38d9e6aa33a6cc271d

alsa_utils/alsa_device_profile.c
alsa_utils/alsa_device_proxy.c
alsa_utils/include/alsa_device_profile.h
alsa_utils/include/alsa_device_proxy.h

index 734edd7..10ab3e4 100644 (file)
@@ -79,16 +79,16 @@ void profile_init(alsa_device_profile* profile, int direction)
     profile_reset(profile);
 }
 
-bool profile_is_initialized(alsa_device_profile* profile)
+bool profile_is_initialized(const alsa_device_profile* profile)
 {
     return profile->card >= 0 && profile->device >= 0;
 }
 
-bool profile_is_valid(alsa_device_profile* profile) {
+bool profile_is_valid(const alsa_device_profile* profile) {
     return profile->is_valid;
 }
 
-bool profile_is_cached_for(alsa_device_profile* profile, int card, int device) {
+bool profile_is_cached_for(const alsa_device_profile* profile, int card, int device) {
     return card == profile->card && device == profile->device;
 }
 
@@ -107,7 +107,7 @@ static unsigned int round_to_16_mult(unsigned int size)
 /*
  * Returns the system defined minimum period size based on the supplied sample rate.
  */
-unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate)
+unsigned profile_calc_min_period_size(const alsa_device_profile* profile, unsigned sample_rate)
 {
     ALOGV("profile_calc_min_period_size(%p, rate:%d)", profile, sample_rate);
     if (profile == NULL) {
@@ -123,7 +123,7 @@ unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sam
     }
 }
 
-unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate)
+unsigned int profile_get_period_size(const alsa_device_profile* profile, unsigned sample_rate)
 {
     unsigned int period_size = profile_calc_min_period_size(profile, sample_rate);
     ALOGV("profile_get_period_size(rate:%d) = %d", sample_rate, period_size);
@@ -133,7 +133,7 @@ unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned samp
 /*
  * Sample Rate
  */
-unsigned profile_get_default_sample_rate(alsa_device_profile* profile)
+unsigned profile_get_default_sample_rate(const alsa_device_profile* profile)
 {
     /*
      * TODO this won't be right in general. we should store a preferred rate as we are scanning.
@@ -142,7 +142,7 @@ unsigned profile_get_default_sample_rate(alsa_device_profile* profile)
     return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE;
 }
 
-bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate)
+bool profile_is_sample_rate_valid(const alsa_device_profile* profile, unsigned rate)
 {
     if (profile_is_valid(profile)) {
         size_t index;
@@ -161,7 +161,7 @@ bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate)
 /*
  * Format
  */
-enum pcm_format profile_get_default_format(alsa_device_profile* profile)
+enum pcm_format profile_get_default_format(const alsa_device_profile* profile)
 {
     /*
      * TODO this won't be right in general. we should store a preferred format as we are scanning.
@@ -169,7 +169,7 @@ enum pcm_format profile_get_default_format(alsa_device_profile* profile)
     return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT;
 }
 
-bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt) {
+bool profile_is_format_valid(const alsa_device_profile* profile, enum pcm_format fmt) {
     if (profile_is_valid(profile)) {
         size_t index;
         for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
@@ -187,12 +187,12 @@ bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt)
 /*
  * Channels
  */
-unsigned profile_get_default_channel_count(alsa_device_profile* profile)
+unsigned profile_get_default_channel_count(const 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)
+unsigned profile_get_closest_channel_count(const alsa_device_profile* profile, unsigned count)
 {
     if (profile_is_valid(profile)) {
         if (count < profile->min_channel_count) {
@@ -207,7 +207,7 @@ unsigned profile_get_closest_channel_count(alsa_device_profile* profile, unsigne
     }
 }
 
-bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count)
+bool profile_is_channel_count_valid(const alsa_device_profile* profile, unsigned count)
 {
     if (profile_is_initialized(profile)) {
         return count >= profile->min_channel_count && count <= profile->max_channel_count;
@@ -216,7 +216,7 @@ bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count
     }
 }
 
-static bool profile_test_sample_rate(alsa_device_profile* profile, unsigned rate)
+static bool profile_test_sample_rate(const alsa_device_profile* profile, unsigned rate)
 {
     struct pcm_config config = profile->default_config;
     config.rate = rate;
@@ -418,7 +418,7 @@ bool profile_read_device_info(alsa_device_profile* profile)
     return true;
 }
 
-char * profile_get_sample_rate_strs(alsa_device_profile* profile)
+char * profile_get_sample_rate_strs(const alsa_device_profile* profile)
 {
     /* if we assume that rate strings are about 5 characters (48000 is 5), plus ~1 for a
      * delimiter "|" this buffer has room for about 22 rate strings which seems like
@@ -451,7 +451,7 @@ char * profile_get_sample_rate_strs(alsa_device_profile* profile)
     return strdup(buffer);
 }
 
-char * profile_get_format_strs(alsa_device_profile* profile)
+char * profile_get_format_strs(const alsa_device_profile* profile)
 {
     /* if we assume that format strings are about 24 characters (AUDIO_FORMAT_PCM_16_BIT is 23),
      * plus ~1 for a delimiter "|" this buffer has room for about 10 format strings which seems
@@ -482,7 +482,7 @@ char * profile_get_format_strs(alsa_device_profile* profile)
     return strdup(buffer);
 }
 
-char * profile_get_channel_count_strs(alsa_device_profile* profile)
+char * profile_get_channel_count_strs(const alsa_device_profile* profile)
 {
     // FIXME implicit fixed channel count assumption here (FCC_8).
     // we use only the canonical even number channel position masks.
index 300ed22..e64a42e 100644 (file)
@@ -41,7 +41,7 @@ static const unsigned format_byte_size_map[] = {
     3, /* PCM_FORMAT_S24_3LE */
 };
 
-int proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile,
+int proxy_prepare(alsa_device_proxy * proxy, const alsa_device_profile* profile,
                    struct pcm_config * config)
 {
     int ret = 0;
@@ -126,7 +126,7 @@ int proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile,
 
 int proxy_open(alsa_device_proxy * proxy)
 {
-    alsa_device_profile* profile = proxy->profile;
+    const alsa_device_profile* profile = proxy->profile;
     ALOGV("proxy_open(card:%d device:%d %s)", profile->card, profile->device,
           profile->direction == PCM_OUT ? "PCM_OUT" : "PCM_IN");
 
@@ -262,8 +262,8 @@ void proxy_dump(const alsa_device_proxy* proxy, int fd)
     }
 }
 
-int proxy_scan_rates(alsa_device_proxy * proxy, unsigned sample_rates[]) {
-    alsa_device_profile* profile = proxy->profile;
+int proxy_scan_rates(alsa_device_proxy * proxy, const unsigned sample_rates[]) {
+    const alsa_device_profile* profile = proxy->profile;
     if (profile->card < 0 || profile->device < 0) {
         return -EINVAL;
     }
index 8307d0a..8f581d9 100644 (file)
@@ -60,34 +60,34 @@ typedef struct  {
 } alsa_device_profile;
 
 void profile_init(alsa_device_profile* profile, int direction);
-bool profile_is_initialized(alsa_device_profile* profile);
-bool profile_is_valid(alsa_device_profile* profile);
-bool profile_is_cached_for(alsa_device_profile* profile, int card, int device);
+bool profile_is_initialized(const alsa_device_profile* profile);
+bool profile_is_valid(const alsa_device_profile* profile);
+bool profile_is_cached_for(const alsa_device_profile* profile, int card, int device);
 void profile_decache(alsa_device_profile* profile);
 
 bool profile_read_device_info(alsa_device_profile* profile);
 
 /* Audio Config Strings Methods */
-char * profile_get_sample_rate_strs(alsa_device_profile* profile);
-char * profile_get_format_strs(alsa_device_profile* profile);
-char * profile_get_channel_count_strs(alsa_device_profile* profile);
+char * profile_get_sample_rate_strs(const alsa_device_profile* profile);
+char * profile_get_format_strs(const alsa_device_profile* profile);
+char * profile_get_channel_count_strs(const alsa_device_profile* profile);
 
 /* Sample Rate Methods */
-unsigned profile_get_default_sample_rate(alsa_device_profile* profile);
-bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate);
+unsigned profile_get_default_sample_rate(const alsa_device_profile* profile);
+bool profile_is_sample_rate_valid(const alsa_device_profile* profile, unsigned rate);
 
 /* Format Methods */
-enum pcm_format profile_get_default_format(alsa_device_profile* profile);
-bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt);
+enum pcm_format profile_get_default_format(const alsa_device_profile* profile);
+bool profile_is_format_valid(const 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);
+unsigned profile_get_default_channel_count(const alsa_device_profile* profile);
+unsigned profile_get_closest_channel_count(const alsa_device_profile* profile, unsigned count);
+bool profile_is_channel_count_valid(const 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);
+unsigned profile_calc_min_period_size(const alsa_device_profile* profile, unsigned sample_rate);
+unsigned int profile_get_period_size(const alsa_device_profile* profile, unsigned sample_rate);
 
 /* Debugging */
 void profile_dump(const alsa_device_profile* profile, int fd);
index 677bb5e..64565e1 100644 (file)
@@ -22,7 +22,7 @@
 #include "alsa_device_profile.h"
 
 typedef struct {
-    alsa_device_profile* profile;
+    const alsa_device_profile* profile;
 
     struct pcm_config alsa_config;
 
@@ -34,7 +34,7 @@ typedef struct {
 
 
 /* State */
-int proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile * profile,
+int proxy_prepare(alsa_device_proxy * proxy, const alsa_device_profile * profile,
                    struct pcm_config * config);
 int proxy_open(alsa_device_proxy * proxy);
 void proxy_close(alsa_device_proxy * proxy);
@@ -54,7 +54,7 @@ unsigned proxy_get_latency(const alsa_device_proxy * proxy);
  * returns the index of the first rate for which the ALSA device can be opened.
  * return negative value if none work or an error occurs.
  */
-int proxy_scan_rates(alsa_device_proxy * proxy, unsigned sample_rates[]);
+int proxy_scan_rates(alsa_device_proxy * proxy, const unsigned sample_rates[]);
 
 /* I/O */
 int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count);