aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Hung2014-03-10 20:08:15 -0500
committerAndy Hung2014-03-19 16:32:37 -0500
commita5b44d9bba0c5df52b37850bb929eb53817fb4a4 (patch)
treef151785ae3b1f8f5274a9baa3d80e34a5ddbaf8d
parent1ddcfa32c259c49c24e0792215b97d87b4ffeb68 (diff)
downloadplatform-external-tinyalsa-a5b44d9bba0c5df52b37850bb929eb53817fb4a4.tar.gz
platform-external-tinyalsa-a5b44d9bba0c5df52b37850bb929eb53817fb4a4.tar.xz
platform-external-tinyalsa-a5b44d9bba0c5df52b37850bb929eb53817fb4a4.zip
Update tinypcminfo to display format information
Change-Id: I0e6a04da5a4b122a3748b16c7eb01c4a224c3d84 Signed-off-by: Andy Hung <hunga@google.com>
-rw-r--r--include/tinyalsa/asoundlib.h13
-rw-r--r--pcm.c23
-rw-r--r--tinypcminfo.c106
3 files changed, 142 insertions, 0 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index a4806fe..03e3c13 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -79,6 +79,11 @@ enum pcm_format {
79 PCM_FORMAT_MAX, 79 PCM_FORMAT_MAX,
80}; 80};
81 81
82/* Bitmask has 256 bits (32 bytes) in asound.h */
83struct pcm_mask {
84 unsigned int bits[32 / sizeof(unsigned int)];
85};
86
82/* Configuration for a stream */ 87/* Configuration for a stream */
83struct pcm_config { 88struct pcm_config {
84 unsigned int channels; 89 unsigned int channels;
@@ -109,6 +114,11 @@ struct pcm_config {
109/* PCM parameters */ 114/* PCM parameters */
110enum pcm_param 115enum pcm_param
111{ 116{
117 /* mask parameters */
118 PCM_PARAM_ACCESS,
119 PCM_PARAM_FORMAT,
120 PCM_PARAM_SUBFORMAT,
121 /* interval parameters */
112 PCM_PARAM_SAMPLE_BITS, 122 PCM_PARAM_SAMPLE_BITS,
113 PCM_PARAM_FRAME_BITS, 123 PCM_PARAM_FRAME_BITS,
114 PCM_PARAM_CHANNELS, 124 PCM_PARAM_CHANNELS,
@@ -146,6 +156,9 @@ int pcm_is_ready(struct pcm *pcm);
146struct pcm_params *pcm_params_get(unsigned int card, unsigned int device, 156struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
147 unsigned int flags); 157 unsigned int flags);
148void pcm_params_free(struct pcm_params *pcm_params); 158void pcm_params_free(struct pcm_params *pcm_params);
159
160struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
161 enum pcm_param param);
149unsigned int pcm_params_get_min(struct pcm_params *pcm_params, 162unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
150 enum pcm_param param); 163 enum pcm_param param);
151unsigned int pcm_params_get_max(struct pcm_params *pcm_params, 164unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
diff --git a/pcm.c b/pcm.c
index 2842e9e..7c05a87 100644
--- a/pcm.c
+++ b/pcm.c
@@ -514,6 +514,12 @@ void pcm_params_free(struct pcm_params *pcm_params)
514static int pcm_param_to_alsa(enum pcm_param param) 514static int pcm_param_to_alsa(enum pcm_param param)
515{ 515{
516 switch (param) { 516 switch (param) {
517 case PCM_PARAM_ACCESS:
518 return SNDRV_PCM_HW_PARAM_ACCESS;
519 case PCM_PARAM_FORMAT:
520 return SNDRV_PCM_HW_PARAM_FORMAT;
521 case PCM_PARAM_SUBFORMAT:
522 return SNDRV_PCM_HW_PARAM_SUBFORMAT;
517 case PCM_PARAM_SAMPLE_BITS: 523 case PCM_PARAM_SAMPLE_BITS:
518 return SNDRV_PCM_HW_PARAM_SAMPLE_BITS; 524 return SNDRV_PCM_HW_PARAM_SAMPLE_BITS;
519 break; 525 break;
@@ -556,6 +562,23 @@ static int pcm_param_to_alsa(enum pcm_param param)
556 } 562 }
557} 563}
558 564
565struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
566 enum pcm_param param)
567{
568 int p;
569 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
570 if (params == NULL) {
571 return NULL;
572 }
573
574 p = pcm_param_to_alsa(param);
575 if (p < 0 || !param_is_mask(p)) {
576 return NULL;
577 }
578
579 return (struct pcm_mask *)param_to_mask(params, p);
580}
581
559unsigned int pcm_params_get_min(struct pcm_params *pcm_params, 582unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
560 enum pcm_param param) 583 enum pcm_param param)
561{ 584{
diff --git a/tinypcminfo.c b/tinypcminfo.c
index 3282186..b2d11bc 100644
--- a/tinypcminfo.c
+++ b/tinypcminfo.c
@@ -31,6 +31,72 @@
31#include <stdlib.h> 31#include <stdlib.h>
32#include <string.h> 32#include <string.h>
33 33
34#ifndef ARRAY_SIZE
35#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
36#endif
37
38/* The format_lookup is in order of SNDRV_PCM_FORMAT_##index and
39 * matches the grouping in sound/asound.h. Note this is not
40 * continuous and has an empty gap from (25 - 30).
41 */
42static const char *format_lookup[] = {
43 /*[0] =*/ "S8",
44 "U8",
45 "S16_LE",
46 "S16_BE",
47 "U16_LE",
48 "U16_BE",
49 "S24_LE",
50 "S24_BE",
51 "U24_LE",
52 "U24_BE",
53 "S32_LE",
54 "S32_BE",
55 "U32_LE",
56 "U32_BE",
57 "FLOAT_LE",
58 "FLOAT_BE",
59 "FLOAT64_LE",
60 "FLOAT64_BE",
61 "IEC958_SUBFRAME_LE",
62 "IEC958_SUBFRAME_BE",
63 "MU_LAW",
64 "A_LAW",
65 "IMA_ADPCM",
66 "MPEG",
67 /*[24] =*/ "GSM",
68 [31] = "SPECIAL",
69 "S24_3LE",
70 "S24_3BE",
71 "U24_3LE",
72 "U24_3BE",
73 "S20_3LE",
74 "S20_3BE",
75 "U20_3LE",
76 "U20_3BE",
77 "S18_3LE",
78 "S18_3BE",
79 "U18_3LE",
80 /*[43] =*/ "U18_3BE",
81#if 0
82 /* recent additions, may not be present on local asound.h */
83 "G723_24",
84 "G723_24_1B",
85 "G723_40",
86 "G723_40_1B",
87 "DSD_U8",
88 "DSD_U16_LE",
89#endif
90};
91
92/* Returns a human readable name for the format associated with bit_index,
93 * NULL if bit_index is not known.
94 */
95inline const char *pcm_get_format_name(unsigned bit_index)
96{
97 return bit_index < ARRAY_SIZE(format_lookup) ? format_lookup[bit_index] : NULL;
98}
99
34int main(int argc, char **argv) 100int main(int argc, char **argv)
35{ 101{
36 unsigned int device = 0; 102 unsigned int device = 0;
@@ -63,6 +129,7 @@ int main(int argc, char **argv)
63 129
64 for (i = 0; i < 2; i++) { 130 for (i = 0; i < 2; i++) {
65 struct pcm_params *params; 131 struct pcm_params *params;
132 struct pcm_mask *m;
66 unsigned int min; 133 unsigned int min;
67 unsigned int max; 134 unsigned int max;
68 135
@@ -74,6 +141,45 @@ int main(int argc, char **argv)
74 continue; 141 continue;
75 } 142 }
76 143
144 m = pcm_params_get_mask(params, PCM_PARAM_ACCESS);
145 if (m) { /* bitmask, refer to SNDRV_PCM_ACCESS_*, generally interleaved */
146 printf(" Access:\t%#08x\n", m->bits[0]);
147 }
148 m = pcm_params_get_mask(params, PCM_PARAM_FORMAT);
149 if (m) { /* bitmask, refer to: SNDRV_PCM_FORMAT_* */
150 unsigned j, k, count = 0;
151 const unsigned bitcount = sizeof(m->bits[0]) * 8;
152
153 /* we only check first two format masks (out of 8) - others are zero. */
154 printf(" Format[0]:\t%#08x\n", m->bits[0]);
155 printf(" Format[1]:\t%#08x\n", m->bits[1]);
156
157 /* print friendly format names, if they exist */
158 for (k = 0; k < 2; ++k) {
159 for (j = 0; j < bitcount; ++j) {
160 const char *name;
161
162 if (m->bits[k] & (1 << j)) {
163 name = pcm_get_format_name(j + k*bitcount);
164 if (name) {
165 if (count++ == 0) {
166 printf(" Format Name:\t");
167 } else {
168 printf (", ");
169 }
170 printf("%s", name);
171 }
172 }
173 }
174 }
175 if (count) {
176 printf("\n");
177 }
178 }
179 m = pcm_params_get_mask(params, PCM_PARAM_SUBFORMAT);
180 if (m) { /* bitmask, should be 1: SNDRV_PCM_SUBFORMAT_STD */
181 printf(" Subformat:\t%#08x\n", m->bits[0]);
182 }
77 min = pcm_params_get_min(params, PCM_PARAM_RATE); 183 min = pcm_params_get_min(params, PCM_PARAM_RATE);
78 max = pcm_params_get_max(params, PCM_PARAM_RATE); 184 max = pcm_params_get_max(params, PCM_PARAM_RATE);
79 printf(" Rate:\tmin=%uHz\tmax=%uHz\n", min, max); 185 printf(" Rate:\tmin=%uHz\tmax=%uHz\n", min, max);