blob: abb0e9be1e78efe4a9844556f98154cae32faf9d
1 | /** |
2 | * \file audiodsp-ctl.c |
3 | * \brief Functions of Auduodsp control |
4 | * \version 1.0.0 |
5 | * \date 2011-03-08 |
6 | */ |
7 | /* Copyright (C) 2007-2011, Amlogic Inc. |
8 | * All right reserved |
9 | * |
10 | */ |
11 | #include <stdio.h> |
12 | #include <stdlib.h> |
13 | #include <fcntl.h> |
14 | #include <string.h> |
15 | #include <syslog.h> |
16 | #include <unistd.h> |
17 | #include <errno.h> |
18 | #include <sys/ioctl.h> |
19 | #include <sys/mman.h> |
20 | |
21 | #include <audio-dec.h> |
22 | #include <audiodsp.h> |
23 | #include <log-print.h> |
24 | #include <cutils/properties.h> |
25 | |
26 | #include "adec-external-ctrl.h" |
27 | #include "Amsysfsutils.h" |
28 | #include "amconfigutils.h" |
29 | |
30 | static int reset_track_enable = 0; |
31 | void adec_reset_track_enable(int enable_flag) |
32 | { |
33 | reset_track_enable = enable_flag; |
34 | adec_print("reset_track_enable=%d\n", reset_track_enable); |
35 | } |
36 | |
37 | static int get_sysfs_int(const char *path) |
38 | { |
39 | return amsysfs_get_sysfs_int(path); |
40 | } |
41 | |
42 | static int set_sysfs_int(const char *path, int val) |
43 | { |
44 | return amsysfs_set_sysfs_int(path, val); |
45 | } |
46 | |
47 | static int audiodsp_get_format_changed_flag() |
48 | { |
49 | return get_sysfs_int("/sys/class/audiodsp/format_change_flag"); |
50 | |
51 | } |
52 | |
53 | void audiodsp_set_format_changed_flag(int val) |
54 | { |
55 | set_sysfs_int("/sys/class/audiodsp/format_change_flag", val); |
56 | |
57 | } |
58 | |
59 | static int audiodsp_get_pcm_resample_enable() |
60 | { |
61 | int utils_fd, ret; |
62 | unsigned long value; |
63 | |
64 | utils_fd = open("/dev/amaudio_utils", O_RDWR); |
65 | if (utils_fd >= 0) { |
66 | ret = ioctl(utils_fd, AMAUDIO_IOC_GET_RESAMPLE_ENA, &value); |
67 | if (ret < 0) { |
68 | adec_print("AMAUDIO_IOC_GET_RESAMPLE_ENA failed\n"); |
69 | close(utils_fd); |
70 | return -1; |
71 | } |
72 | close(utils_fd); |
73 | return value; |
74 | } |
75 | return -1; |
76 | } |
77 | |
78 | static int audiodsp_set_pcm_resample_enable(unsigned long enable) |
79 | { |
80 | int utils_fd, ret; |
81 | |
82 | utils_fd = open("/dev/amaudio_utils", O_RDWR); |
83 | if (utils_fd >= 0) { |
84 | ret = ioctl(utils_fd, AMAUDIO_IOC_SET_RESAMPLE_ENA, enable); |
85 | if (ret < 0) { |
86 | adec_print("AMAUDIO_IOC_SET_RESAMPLE_ENA failed\n"); |
87 | close(utils_fd); |
88 | return -1; |
89 | } |
90 | close(utils_fd); |
91 | return 0; |
92 | } |
93 | return -1; |
94 | } |
95 | |
96 | void adec_reset_track(aml_audio_dec_t *audec) |
97 | { |
98 | if (audec->format_changed_flag && audec->state >= INITTED && !audec->need_stop) { |
99 | buffer_stream_t *g_bst = audec->g_bst; |
100 | adec_print("reset audio_track: samplerate=%d channels=%d\n", (g_bst == NULL) ? audec->samplerate : g_bst->samplerate, (g_bst == NULL) ? audec->channels : g_bst->channels); |
101 | audio_out_operations_t *out_ops = &audec->aout_ops; |
102 | out_ops->mute(audec, 1); |
103 | out_ops->pause(audec); |
104 | out_ops->stop(audec); |
105 | if (g_bst != NULL) { |
106 | //4.4 code maybe run on 4.2 hardware platform: g_bst==NULL on 4.2,so add this condition |
107 | audec->channels = g_bst->channels; |
108 | audec->samplerate = g_bst->samplerate; |
109 | } |
110 | out_ops->init(audec); |
111 | if (audec->state == ACTIVE) { |
112 | out_ops->start(audec); |
113 | } |
114 | audec->format_changed_flag = 0; |
115 | } |
116 | } |
117 | |
118 | int audiodsp_format_update(aml_audio_dec_t *audec) |
119 | { |
120 | int m_fmt; |
121 | int ret = -1; |
122 | unsigned long val; |
123 | dsp_operations_t *dsp_ops = &audec->adsp_ops; |
124 | |
125 | if (dsp_ops->dsp_file_fd < 0 || get_audio_decoder() != AUDIO_ARC_DECODER) { |
126 | return ret; |
127 | } |
128 | |
129 | ret = 0; |
130 | if (1/*audiodsp_get_format_changed_flag()*/) { |
131 | ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_CHANNELS_NUM, &val); |
132 | if (val != (unsigned long) - 1) { |
133 | if (audec->channels != val) { |
134 | //adec_print("dsp_format_update: pre_channels=%d cur_channels=%d\n", audec->channels,val); |
135 | audec->channels = val; |
136 | ret = 1; |
137 | } |
138 | } |
139 | |
140 | ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_SAMPLERATE, &val); |
141 | if (val != (unsigned long) - 1) { |
142 | if (audec->samplerate != val) { |
143 | //adec_print("dsp_format_update: pre_samplerate=%d cur_samplerate=%d\n", audec->samplerate,val); |
144 | audec->samplerate = val; |
145 | ret = 2; |
146 | } |
147 | } |
148 | #if 1 |
149 | ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_BITS_PER_SAMPLE, &val); |
150 | if (val != (unsigned long) - 1) { |
151 | if (audec->data_width != val) { |
152 | //adec_print("dsp_format_update: pre_data_width=%d cur_data_width=%d\n", audec->data_width,val); |
153 | audec->data_width = val; |
154 | ret = 3; |
155 | } |
156 | } |
157 | #endif |
158 | //audiodsp_set_format_changed_flag(0); |
159 | |
160 | if (am_getconfig_bool("media.libplayer.wfd")) { |
161 | ret = ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_PCM_LEVEL, &val); |
162 | if (ret == 0) { |
163 | //adec_print("pcm level == 0x%x\n", val); |
164 | if ((val < 0x1000) && (1 == audiodsp_get_pcm_resample_enable())) { |
165 | // adec_print("disable pcm down resample"); |
166 | // audiodsp_set_pcm_resample_enable(0); |
167 | } |
168 | } |
169 | } |
170 | } |
171 | if (ret > 0) { |
172 | audec->format_changed_flag = ret; |
173 | adec_print("dsp_format_update: audec->format_changed_flag = %d \n", audec->format_changed_flag); |
174 | } |
175 | return ret; |
176 | } |
177 | |
178 | |
179 | |
180 | int audiodsp_get_pcm_left_len() |
181 | { |
182 | return get_sysfs_int("/sys/class/audiodsp/pcm_left_len"); |
183 | |
184 | } |
185 | |
186 | |
187 | |
188 | |
189 |