Home | History | Annotate | Download | only in libalsa-intf
      1 /*
      2 ** Copyright 2010, The Android Open-Source Project
      3 ** Copyright (c) 2011, Code Aurora Forum. All rights reserved.
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include <string.h>
     21 #include <errno.h>
     22 #include <ctype.h>
     23 
     24 #include <stdio.h>
     25 #include <stdlib.h>
     26 #include <fcntl.h>
     27 #include <unistd.h>
     28 #include <stdint.h>
     29 #include <string.h>
     30 
     31 #include "alsa_audio.h"
     32 
     33 
     34 struct mixer_ctl *get_ctl(struct mixer *mixer, char *name)
     35 {
     36     char *p;
     37     unsigned idx = 0;
     38 
     39     if (isdigit(name[0]))
     40         return mixer_get_nth_control(mixer, atoi(name) - 1);
     41 
     42     p = strrchr(name, '#');
     43     if (p) {
     44         *p++ = 0;
     45         idx = atoi(p);
     46     }
     47 
     48     return mixer_get_control(mixer, name, idx);
     49 }
     50 
     51 int main(int argc, char **argv)
     52 {
     53     struct mixer *mixer;
     54     struct mixer_ctl *ctl;
     55     unsigned value;
     56     int r;
     57     const char* device = "/dev/snd/controlC0";
     58 
     59     mixer = mixer_open(device);
     60     if (!mixer){
     61         fprintf(stderr,"oops: %s: %d\n", strerror(errno), __LINE__);
     62         return -1;
     63     }
     64 
     65     if (argc == 1) {
     66         mixer_dump(mixer);
     67         mixer_close(mixer);
     68         return 0;
     69     }
     70 
     71     ctl = get_ctl(mixer, argv[1]);
     72     argc -= 2;
     73     argv += 2;
     74 
     75     if (!ctl) {
     76         fprintf(stderr,"can't find control\n");
     77         mixer_close(mixer);
     78         return -1;
     79     }
     80     if (argc) {
     81         if (isdigit(argv[0][0]))
     82             r = mixer_ctl_set_value(ctl, argc, argv);
     83         else
     84             r = mixer_ctl_select(ctl, argv[0]);
     85         if (r)
     86             fprintf(stderr,"oops: %s: %d\n", strerror(errno), __LINE__);
     87     } else {
     88         mixer_ctl_get(ctl, &value);
     89     }
     90     mixer_close(mixer);
     91     return 0;
     92 }
     93