Enable build with iniparser v 3.1
[platform/core/multimedia/avsystem.git] / audiotest / avsys-audio-volume-dump.c
1 /*
2  * avsystem
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <alloca.h>
24 #include <string.h>
25 #include "../include/avsys-audio.h"
26 #include "../include/avsys-audio-logical-volume.h"
27
28 #define VERSION_NUM     0001
29
30
31 void usage(char *name)
32 {
33         printf("Usage: %s [FILE]...\n\n", name);
34         printf("Version %04d\n", VERSION_NUM);
35         printf("\n");
36         return;
37 }
38
39 int main(int argc, char* argv[])
40 {
41         int i = 0;
42         int j = 0;
43         int k = 0;
44         int err = 0;
45         char filepath[256]={0,};
46         FILE *fp = NULL;
47
48         if(argc > 2)
49         {
50                 usage(argv[0]);
51                 return 0;
52         }
53         else if(argc == 2)
54         {
55                 strncpy(filepath, argv[1], sizeof(filepath)-1);
56         }
57         else if(argc == 1)
58         {
59                 strncpy(filepath, AVSYS_VOLUME_INI_TEMP_PATH, sizeof(filepath)-1);
60                 fprintf(stderr,"Use default file path %s\n", filepath);
61         }
62
63         fp = fopen(filepath, "w");
64         if(!fp)
65         {
66                 fprintf(stderr,"Can not open file %s\n",filepath);
67                 return -1;
68         }
69
70         for(i=AVSYS_AUDIO_LVOL_GAIN_TYPE_0; i<AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX; i++)
71         {
72                 for(j=AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; j<=AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET;j++)
73                 {
74                         int lv = 0;
75                         int rv = 0;
76                         char *str_dev[] = { "SPK", "HEADSET", "BTHEADSET" };
77
78                         for(k=0;k<LVOLUME_MAX_MULTIMEDIA;k++)
79                         {
80                                 err = avsys_audio_get_volume_table(i, AVSYS_AUDIO_LVOL_DEV_TYPE_SPK, k, &lv, &rv);
81                                 if(err)
82                                         goto FAIL;
83
84                                 fprintf(fp,"%1d:%s:%d:%d:%d\n",i,str_dev[j],k,lv,rv);
85                         }
86                 }
87         }
88
89         if(fp != NULL)
90         {
91                 fclose(fp);
92         }
93         printf("Success\n");
94         return 0;
95
96 FAIL:
97         if(fp != NULL)
98         {
99                 fclose(fp);
100         }
101         unlink(filepath);
102         fprintf(stderr,"Can not dump volume table\n");
103         return -1;
104 }