blob: e8c42341ab05a349671ea76fdc560b7f2d7312e6
1 | /** |
2 | * \file feeder.c |
3 | * \brief Functions of Feeder |
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 <string.h> |
14 | #include <fcntl.h> |
15 | |
16 | #include <feeder.h> |
17 | #include <audiodsp.h> |
18 | |
19 | #include "audiodsp.h" |
20 | #include "Amsysfsutils.h" |
21 | #include "amconfigutils.h" |
22 | |
23 | extern int audiodsp_start(aml_audio_dec_t *audec); |
24 | /** |
25 | * \brief get audio format |
26 | * \return audio format on success otherwise ADEC_AUDIO_FORMAT_UNKNOWN |
27 | */ |
28 | static adec_audio_format_t get_audio_format(void) |
29 | { |
30 | char format[21]; |
31 | int len; |
32 | |
33 | format[0] = 0; |
34 | |
35 | amsysfs_get_sysfs_str(FORMAT_PATH, format, 21); |
36 | if (strncmp(format, "NA", 2) == 0) { |
37 | return ADEC_AUDIO_FORMAT_UNKNOWN; |
38 | } |
39 | |
40 | adec_print("amadec format: %s", format); |
41 | |
42 | if (strncmp(format, "amadec_mpeg", 11) == 0) { |
43 | return ADEC_AUDIO_FORMAT_MPEG; |
44 | } |
45 | |
46 | if (strncmp(format, "amadec_pcm_s16le", 16) == 0) { |
47 | /*TODO: get format/channel numer/sample rate etc */ |
48 | return ADEC_AUDIO_FORMAT_PCM_S16LE; |
49 | } |
50 | |
51 | if (strncmp(format, "amadec_pcm_s16be", 16) == 0) { |
52 | /*TODO: get format/channel numer/sample rate etc */ |
53 | return ADEC_AUDIO_FORMAT_PCM_S16BE; |
54 | } |
55 | |
56 | if (strncmp(format, "amadec_pcm_u8", 13) == 0) { |
57 | /*TODO: get format/channel numer/sample rate etc */ |
58 | return ADEC_AUDIO_FORMAT_PCM_U8; |
59 | } |
60 | |
61 | if (strncmp(format, "amadec_adpcm", 12) == 0) { |
62 | /*TODO: get format/channel numer/sample rate etc */ |
63 | return ADEC_AUDIO_FORMAT_ADPCM; |
64 | } |
65 | |
66 | if (strncmp(format, "amadec_aac_latm", 15) == 0) { |
67 | /*TODO: get format/channel numer/sample rate etc */ |
68 | return ADEC_AUDIO_FORMAT_AAC_LATM; |
69 | } |
70 | |
71 | if (strncmp(format, "amadec_aac", 10) == 0) { |
72 | /*TODO: get format/channel numer/sample rate etc */ |
73 | return ADEC_AUDIO_FORMAT_AAC; |
74 | } |
75 | |
76 | if (strncmp(format, "amadec_ac3", 10) == 0) { |
77 | /*TODO: get format/channel numer/sample rate etc */ |
78 | return ADEC_AUDIO_FORMAT_AC3; |
79 | } |
80 | if (strncmp(format, "amadec_eac3", 11) == 0) { |
81 | /*TODO: get format/channel numer/sample rate etc */ |
82 | return ADEC_AUDIO_FORMAT_EAC3; |
83 | } |
84 | |
85 | if (strncmp(format, "amadec_alaw", 11) == 0) { |
86 | /*TODO: get format/channel numer/sample rate etc */ |
87 | return ADEC_AUDIO_FORMAT_ALAW; |
88 | } |
89 | |
90 | if (strncmp(format, "amadec_mulaw", 12) == 0) { |
91 | /*TODO: get format/channel numer/sample rate etc */ |
92 | return ADEC_AUDIO_FORMAT_MULAW; |
93 | } |
94 | |
95 | if (strncmp(format, "amadec_dts", 10) == 0) { |
96 | /*TODO: get format/channel numer/sample rate etc */ |
97 | return ADEC_AUDIO_FORMAT_DTS; |
98 | } |
99 | |
100 | if (strncmp(format, "amadec_flac", 11) == 0) { |
101 | /*TODO: get format/channel numer/sample rate etc */ |
102 | return ADEC_AUDIO_FORMAT_FLAC; |
103 | } |
104 | |
105 | if (strncmp(format, "amadec_cook", 11) == 0) { |
106 | /*TODO: get format/channel numer/sample rate etc */ |
107 | return ADEC_AUDIO_FORMAT_COOK; |
108 | } |
109 | |
110 | if (strncmp(format, "amadec_amr", 10) == 0) { |
111 | /*TODO: get format/channel numer/sample rate etc */ |
112 | return ADEC_AUDIO_FORMAT_AMR; |
113 | } |
114 | |
115 | if (strncmp(format, "amadec_raac", 11) == 0) { |
116 | /*TODO: get format/channel numer/sample rate etc */ |
117 | return ADEC_AUDIO_FORMAT_RAAC; |
118 | } |
119 | |
120 | if (strncmp(format, "amadec_wmapro", 13) == 0) { |
121 | /*TODO: get format/channel numer/sample rate etc */ |
122 | return ADEC_AUDIO_FORMAT_WMAPRO; |
123 | } |
124 | |
125 | if (strncmp(format, "amadec_wma", 10) == 0) { |
126 | /*TODO: get format/channel numer/sample rate etc */ |
127 | return ADEC_AUDIO_FORMAT_WMA; |
128 | } |
129 | |
130 | if (strncmp(format, "amadec_pcm_bluray", 10) == 0) { |
131 | /*TODO: get format/channel numer/sample rate etc */ |
132 | return ADEC_AUDIO_AFORMAT_PCM_BLURAY; |
133 | } |
134 | if (strncmp(format, "amadec_alac", 11) == 0) { |
135 | /*TODO: get format/channel numer/sample rate etc */ |
136 | return ADEC_AUDIO_AFORMAT_ALAC; |
137 | } |
138 | if (strncmp(format, "amadec_vorbis", 13) == 0) { |
139 | /*TODO: get format/channel numer/sample rate etc */ |
140 | return ADEC_AUDIO_AFORMAT_VORBIS; |
141 | } |
142 | if (strncmp(format, "amadec_ape", 10) == 0) { |
143 | /*TODO: get format/channel numer/sample rate etc */ |
144 | return ADEC_AUDIO_FORMAT_APE; |
145 | } |
146 | if (strncmp(format, "amadec_pcm_widi", 15) == 0) { |
147 | /*TODO: get format/channel numer/sample rate etc */ |
148 | return ADEC_AUDIO_FORMAT_PCM_WIFIDISPLAY; |
149 | } |
150 | |
151 | adec_print("audio format unknow."); |
152 | |
153 | return ADEC_AUDIO_FORMAT_UNKNOWN; |
154 | } |
155 | |
156 | /** |
157 | * \brief init feeder |
158 | * \param audec pointer to audec |
159 | * \return 0 on success otherwise -1 if an error occurred |
160 | */ |
161 | int feeder_init(aml_audio_dec_t *audec) |
162 | { |
163 | int ret; |
164 | dsp_operations_t *dsp_ops; |
165 | |
166 | dsp_ops = &audec->adsp_ops; |
167 | |
168 | audec->format = get_audio_format(); |
169 | if (audec->format == ADEC_AUDIO_FORMAT_UNKNOWN) { |
170 | adec_print("Unknown audio format!"); |
171 | return -1; |
172 | } |
173 | |
174 | ret = audiodsp_init(dsp_ops); |
175 | if (ret) { |
176 | adec_print("audio dsp init failed!"); |
177 | return -1; |
178 | } |
179 | |
180 | ret = audiodsp_start(audec); |
181 | if (ret == 0) { |
182 | dsp_ops->dsp_on = 1; |
183 | dsp_ops->dsp_read = audiodsp_stream_read; |
184 | dsp_ops->get_cur_pts = audiodsp_get_pts; |
185 | dsp_ops->get_cur_pcrscr = audiodsp_get_pcrscr; |
186 | dsp_ops->set_cur_apts = audiodsp_set_apts; |
187 | dsp_ops->set_skip_bytes = audiodsp_set_skip_bytes; |
188 | audec->audio_decoder_enabled = 0x1; |
189 | } else { |
190 | audiodsp_release(dsp_ops); |
191 | dsp_ops->dsp_on = 0; |
192 | dsp_ops->dsp_read = NULL; |
193 | dsp_ops->get_cur_pts = NULL; |
194 | dsp_ops->get_cur_pcrscr = NULL; |
195 | dsp_ops->set_skip_bytes = NULL; |
196 | |
197 | /* TODO: amport init */ |
198 | } |
199 | |
200 | return ret; |
201 | } |
202 | |
203 | /** |
204 | * \brief release feeder |
205 | * \param audec pointer to audec |
206 | * \return 0 on success otherwise -1 if an error occurred |
207 | */ |
208 | int feeder_release(aml_audio_dec_t *audec) |
209 | { |
210 | int ret; |
211 | dsp_operations_t *dsp_ops; |
212 | |
213 | dsp_ops = &audec->adsp_ops; |
214 | |
215 | ret = audiodsp_stop(dsp_ops); |
216 | if (ret) { |
217 | adec_print("audiodsp stop failed!"); |
218 | return -1; |
219 | } |
220 | |
221 | ret = audiodsp_release(dsp_ops); |
222 | if (ret) { |
223 | adec_print("audiodsp release failed!"); |
224 | return -1; |
225 | } |
226 | |
227 | dsp_ops->dsp_on = 0; |
228 | dsp_ops->dsp_read = NULL; |
229 | |
230 | return ret; |
231 | } |
232 |