aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2012-12-03 13:18:57 -0600
committerSimon Wilson2012-12-03 13:19:34 -0600
commit42fc2d393c868d5db609e39551d64f1e60fefa0e (patch)
tree8242041a2037ac2acdb40591493097f5d65f5bcc
parentda39e0b09eb0a1b559a96e2108160d1d8dccf314 (diff)
downloadplatform-external-tinyalsa-42fc2d393c868d5db609e39551d64f1e60fefa0e.tar.gz
platform-external-tinyalsa-42fc2d393c868d5db609e39551d64f1e60fefa0e.tar.xz
platform-external-tinyalsa-42fc2d393c868d5db609e39551d64f1e60fefa0e.zip
Update to latest tinyalsa
f7f35cc Add tinypcminfo utility 4354488 pcm: add pcm_get_params API Change-Id: I50e196bc299734b6e020bdcededa4f903ee5c5c2
-rw-r--r--Android.mk9
-rw-r--r--include/tinyalsa/asoundlib.h26
-rw-r--r--pcm.c144
-rw-r--r--tinypcminfo.c97
4 files changed, 276 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
index 5b64934..4f6db22 100644
--- a/Android.mk
+++ b/Android.mk
@@ -45,3 +45,12 @@ LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
45LOCAL_MODULE_TAGS := optional 45LOCAL_MODULE_TAGS := optional
46 46
47include $(BUILD_EXECUTABLE) 47include $(BUILD_EXECUTABLE)
48
49include $(CLEAR_VARS)
50LOCAL_C_INCLUDES:= external/tinyalsa/include
51LOCAL_SRC_FILES:= tinypcminfo.c
52LOCAL_MODULE := tinypcminfo
53LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
54LOCAL_MODULE_TAGS := optional
55
56include $(BUILD_EXECUTABLE)
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 6148361..bb4005a 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -104,6 +104,23 @@ struct pcm_config {
104 int avail_min; 104 int avail_min;
105}; 105};
106 106
107/* PCM parameters */
108enum pcm_param
109{
110 PCM_PARAM_SAMPLE_BITS,
111 PCM_PARAM_FRAME_BITS,
112 PCM_PARAM_CHANNELS,
113 PCM_PARAM_RATE,
114 PCM_PARAM_PERIOD_TIME,
115 PCM_PARAM_PERIOD_SIZE,
116 PCM_PARAM_PERIOD_BYTES,
117 PCM_PARAM_PERIODS,
118 PCM_PARAM_BUFFER_TIME,
119 PCM_PARAM_BUFFER_SIZE,
120 PCM_PARAM_BUFFER_BYTES,
121 PCM_PARAM_TICK_TIME,
122};
123
107/* Mixer control types */ 124/* Mixer control types */
108enum mixer_ctl_type { 125enum mixer_ctl_type {
109 MIXER_CTL_TYPE_BOOL, 126 MIXER_CTL_TYPE_BOOL,
@@ -123,6 +140,15 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
123int pcm_close(struct pcm *pcm); 140int pcm_close(struct pcm *pcm);
124int pcm_is_ready(struct pcm *pcm); 141int pcm_is_ready(struct pcm *pcm);
125 142
143/* Obtain the parameters for a PCM */
144struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
145 unsigned int flags);
146void pcm_params_free(struct pcm_params *pcm_params);
147unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
148 enum pcm_param param);
149unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
150 enum pcm_param param);
151
126/* Set and get config */ 152/* Set and get config */
127int pcm_get_config(struct pcm *pcm, struct pcm_config *config); 153int pcm_get_config(struct pcm *pcm, struct pcm_config *config);
128int pcm_set_config(struct pcm *pcm, struct pcm_config *config); 154int pcm_set_config(struct pcm *pcm, struct pcm_config *config);
diff --git a/pcm.c b/pcm.c
index d841bd9..4b31c4d 100644
--- a/pcm.c
+++ b/pcm.c
@@ -93,6 +93,24 @@ static void param_set_min(struct snd_pcm_hw_params *p, int n, unsigned int val)
93 } 93 }
94} 94}
95 95
96static unsigned int param_get_min(struct snd_pcm_hw_params *p, int n)
97{
98 if (param_is_interval(n)) {
99 struct snd_interval *i = param_to_interval(p, n);
100 return i->min;
101 }
102 return 0;
103}
104
105static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n)
106{
107 if (param_is_interval(n)) {
108 struct snd_interval *i = param_to_interval(p, n);
109 return i->max;
110 }
111 return 0;
112}
113
96static void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned int val) 114static void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned int val)
97{ 115{
98 if (param_is_interval(n)) { 116 if (param_is_interval(n)) {
@@ -130,6 +148,9 @@ static void param_init(struct snd_pcm_hw_params *p)
130 i->min = 0; 148 i->min = 0;
131 i->max = ~0; 149 i->max = ~0;
132 } 150 }
151 p->rmask = ~0U;
152 p->cmask = 0;
153 p->info = ~0U;
133} 154}
134 155
135#define PCM_ERROR_MAX 128 156#define PCM_ERROR_MAX 128
@@ -433,6 +454,129 @@ static struct pcm bad_pcm = {
433 .fd = -1, 454 .fd = -1,
434}; 455};
435 456
457struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
458 unsigned int flags)
459{
460 struct snd_pcm_hw_params *params;
461 char fn[256];
462 int fd;
463
464 snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device,
465 flags & PCM_IN ? 'c' : 'p');
466
467 fd = open(fn, O_RDWR);
468 if (fd < 0) {
469 fprintf(stderr, "cannot open device '%s'\n", fn);
470 goto err_open;
471 }
472
473 params = calloc(1, sizeof(struct snd_pcm_hw_params));
474 if (!params)
475 goto err_calloc;
476
477 param_init(params);
478 if (ioctl(fd, SNDRV_PCM_IOCTL_HW_REFINE, params)) {
479 fprintf(stderr, "SNDRV_PCM_IOCTL_HW_REFINE error (%d)\n", errno);
480 goto err_hw_refine;
481 }
482
483 close(fd);
484
485 return (struct pcm_params *)params;
486
487err_hw_refine:
488 free(params);
489err_calloc:
490 close(fd);
491err_open:
492 return NULL;
493}
494
495void pcm_params_free(struct pcm_params *pcm_params)
496{
497 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
498
499 if (params)
500 free(params);
501}
502
503static int pcm_param_to_alsa(enum pcm_param param)
504{
505 switch (param) {
506 case PCM_PARAM_SAMPLE_BITS:
507 return SNDRV_PCM_HW_PARAM_SAMPLE_BITS;
508 break;
509 case PCM_PARAM_FRAME_BITS:
510 return SNDRV_PCM_HW_PARAM_FRAME_BITS;
511 break;
512 case PCM_PARAM_CHANNELS:
513 return SNDRV_PCM_HW_PARAM_CHANNELS;
514 break;
515 case PCM_PARAM_RATE:
516 return SNDRV_PCM_HW_PARAM_RATE;
517 break;
518 case PCM_PARAM_PERIOD_TIME:
519 return SNDRV_PCM_HW_PARAM_PERIOD_TIME;
520 break;
521 case PCM_PARAM_PERIOD_SIZE:
522 return SNDRV_PCM_HW_PARAM_PERIOD_SIZE;
523 break;
524 case PCM_PARAM_PERIOD_BYTES:
525 return SNDRV_PCM_HW_PARAM_PERIOD_BYTES;
526 break;
527 case PCM_PARAM_PERIODS:
528 return SNDRV_PCM_HW_PARAM_PERIODS;
529 break;
530 case PCM_PARAM_BUFFER_TIME:
531 return SNDRV_PCM_HW_PARAM_BUFFER_TIME;
532 break;
533 case PCM_PARAM_BUFFER_SIZE:
534 return SNDRV_PCM_HW_PARAM_BUFFER_SIZE;
535 break;
536 case PCM_PARAM_BUFFER_BYTES:
537 return SNDRV_PCM_HW_PARAM_BUFFER_BYTES;
538 break;
539 case PCM_PARAM_TICK_TIME:
540 return SNDRV_PCM_HW_PARAM_TICK_TIME;
541 break;
542
543 default:
544 return -1;
545 }
546}
547
548unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
549 enum pcm_param param)
550{
551 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
552 int p;
553
554 if (!params)
555 return 0;
556
557 p = pcm_param_to_alsa(param);
558 if (p < 0)
559 return 0;
560
561 return param_get_min(params, p);
562}
563
564unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
565 enum pcm_param param)
566{
567 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
568 int p;
569
570 if (!params)
571 return 0;
572
573 p = pcm_param_to_alsa(param);
574 if (p < 0)
575 return 0;
576
577 return param_get_max(params, p);
578}
579
436int pcm_close(struct pcm *pcm) 580int pcm_close(struct pcm *pcm)
437{ 581{
438 if (pcm == &bad_pcm) 582 if (pcm == &bad_pcm)
diff --git a/tinypcminfo.c b/tinypcminfo.c
new file mode 100644
index 0000000..3282186
--- /dev/null
+++ b/tinypcminfo.c
@@ -0,0 +1,97 @@
1/* tinypcminfo.c
2**
3** Copyright 2012, The Android Open Source Project
4**
5** Redistribution and use in source and binary forms, with or without
6** modification, are permitted provided that the following conditions are met:
7** * Redistributions of source code must retain the above copyright
8** notice, this list of conditions and the following disclaimer.
9** * Redistributions in binary form must reproduce the above copyright
10** notice, this list of conditions and the following disclaimer in the
11** documentation and/or other materials provided with the distribution.
12** * Neither the name of The Android Open Source Project nor the names of
13** its contributors may be used to endorse or promote products derived
14** from this software without specific prior written permission.
15**
16** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
17** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
20** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26** DAMAGE.
27*/
28
29#include <tinyalsa/asoundlib.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34int main(int argc, char **argv)
35{
36 unsigned int device = 0;
37 unsigned int card = 0;
38 int i;
39
40 if (argc < 3) {
41 fprintf(stderr, "Usage: %s -D card -d device\n", argv[0]);
42 return 1;
43 }
44
45 /* parse command line arguments */
46 argv += 1;
47 while (*argv) {
48 if (strcmp(*argv, "-D") == 0) {
49 argv++;
50 if (*argv)
51 card = atoi(*argv);
52 }
53 if (strcmp(*argv, "-d") == 0) {
54 argv++;
55 if (*argv)
56 device = atoi(*argv);
57 }
58 if (*argv)
59 argv++;
60 }
61
62 printf("Info for card %d, device %d:\n", card, device);
63
64 for (i = 0; i < 2; i++) {
65 struct pcm_params *params;
66 unsigned int min;
67 unsigned int max;
68
69 printf("\nPCM %s:\n", i == 0 ? "out" : "in");
70
71 params = pcm_params_get(card, device, i == 0 ? PCM_OUT : PCM_IN);
72 if (params == NULL) {
73 printf("Device does not exist.\n");
74 continue;
75 }
76
77 min = pcm_params_get_min(params, PCM_PARAM_RATE);
78 max = pcm_params_get_max(params, PCM_PARAM_RATE);
79 printf(" Rate:\tmin=%uHz\tmax=%uHz\n", min, max);
80 min = pcm_params_get_min(params, PCM_PARAM_CHANNELS);
81 max = pcm_params_get_max(params, PCM_PARAM_CHANNELS);
82 printf(" Channels:\tmin=%u\t\tmax=%u\n", min, max);
83 min = pcm_params_get_min(params, PCM_PARAM_SAMPLE_BITS);
84 max = pcm_params_get_max(params, PCM_PARAM_SAMPLE_BITS);
85 printf(" Sample bits:\tmin=%u\t\tmax=%u\n", min, max);
86 min = pcm_params_get_min(params, PCM_PARAM_PERIOD_SIZE);
87 max = pcm_params_get_max(params, PCM_PARAM_PERIOD_SIZE);
88 printf(" Period size:\tmin=%u\t\tmax=%u\n", min, max);
89 min = pcm_params_get_min(params, PCM_PARAM_PERIODS);
90 max = pcm_params_get_max(params, PCM_PARAM_PERIODS);
91 printf("Period count:\tmin=%u\t\tmax=%u\n", min, max);
92
93 pcm_params_free(params);
94 }
95
96 return 0;
97}