blob: efd70ecaa89e19818aef734c25246b87e14542ff
1 | /* |
2 | * Copyright (C) 2010 Amlogic Corporation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | #ifndef _AUDIO_HW_H_ |
17 | |
18 | #include <audio_utils/resampler.h> |
19 | #include "audio_hwsync.h" |
20 | |
21 | #define _AUDIO_HW_H_ |
22 | #define _AUDIO_HW_H_ |
23 | /* ALSA cards for AML */ |
24 | #define CARD_AMLOGIC_BOARD 0 |
25 | #define CARD_AMLOGIC_DEFAULT CARD_AMLOGIC_BOARD |
26 | /* ALSA ports for AML */ |
27 | #define PORT_MM 1 |
28 | |
29 | /* number of frames per period */ |
30 | /* |
31 | * change DEFAULT_PERIOD_SIZE from 1024 to 512 for passing CTS |
32 | * test case test4_1MeasurePeakRms(android.media.cts.VisualizerTest) |
33 | */ |
34 | #define DEFAULT_PERIOD_SIZE 512 //1024 //(1024 * 2) |
35 | static unsigned PERIOD_SIZE = DEFAULT_PERIOD_SIZE; |
36 | /* number of periods for low power playback */ |
37 | #define PLAYBACK_PERIOD_COUNT 4 |
38 | /* number of periods for capture */ |
39 | #define CAPTURE_PERIOD_COUNT 4 |
40 | |
41 | /* minimum sleep time in out_write() when write threshold is not reached */ |
42 | #define MIN_WRITE_SLEEP_US 5000 |
43 | |
44 | #define RESAMPLER_BUFFER_FRAMES (PERIOD_SIZE * 6) |
45 | #define RESAMPLER_BUFFER_SIZE (4 * RESAMPLER_BUFFER_FRAMES) |
46 | |
47 | static unsigned int DEFAULT_OUT_SAMPLING_RATE = 48000; |
48 | |
49 | /* sampling rate when using MM low power port */ |
50 | #define MM_LOW_POWER_SAMPLING_RATE 44100 |
51 | /* sampling rate when using MM full power port */ |
52 | #define MM_FULL_POWER_SAMPLING_RATE 48000 |
53 | /* sampling rate when using VX port for narrow band */ |
54 | #define VX_NB_SAMPLING_RATE 8000 |
55 | |
56 | #define AUDIO_PARAMETER_STREAM_EQ "audioeffect_eq" |
57 | #define AUDIO_PARAMETER_STREAM_SRS "audioeffect_srs_param" |
58 | #define AUDIO_PARAMETER_STREAM_SRS_GAIN "audioeffect_srs_gain" |
59 | #define AUDIO_PARAMETER_STREAM_SRS_SWITCH "audioeffect_srs_switch" |
60 | |
61 | /* Get a new HW synchronization source identifier. |
62 | * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs |
63 | * or no HW sync is available. */ |
64 | #define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync" |
65 | |
66 | #define AUDIO_PARAMETER_HW_AV_EAC3_SYNC "HwAvSyncEAC3Supported" |
67 | |
68 | enum { |
69 | TYPE_PCM = 0, |
70 | TYPE_AC3 = 2, |
71 | TYPE_DTS = 3, |
72 | TYPE_EAC3 = 4, |
73 | TYPE_DTS_HD = 5 , |
74 | TYPE_MULTI_PCM = 6, |
75 | TYPE_TRUE_HD = 7, |
76 | TYPE_DTS_HD_MA = 8,//should not used after we unify DTS-HD&DTS-HD MA |
77 | TYPE_PCM_HIGH_SR = 9, |
78 | }; |
79 | |
80 | #define AML_HAL_MIXER_BUF_SIZE 64*1024 |
81 | struct aml_hal_mixer { |
82 | unsigned char start_buf[AML_HAL_MIXER_BUF_SIZE]; |
83 | unsigned int wp; |
84 | unsigned int rp; |
85 | unsigned int buf_size; |
86 | unsigned char need_cache_flag;//flag to check if need cache some data before write to mix |
87 | pthread_mutex_t lock; |
88 | }; |
89 | |
90 | #define MAX_STREAM_NUM 5 |
91 | #define HDMI_ARC_MAX_FORMAT 20 |
92 | struct aml_audio_device { |
93 | struct audio_hw_device hw_device; |
94 | |
95 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
96 | pthread_mutex_t pcm_write_lock; |
97 | int mode; |
98 | audio_devices_t in_device; |
99 | audio_devices_t out_device; |
100 | int in_call; |
101 | struct aml_stream_in *active_input; |
102 | struct aml_stream_out *active_output[MAX_STREAM_NUM]; |
103 | unsigned char active_output_count; |
104 | bool mic_mute; |
105 | unsigned int card; |
106 | struct audio_route *ar; |
107 | struct echo_reference_itfe *echo_reference; |
108 | bool low_power; |
109 | struct aml_stream_out *hwsync_output; |
110 | struct aml_hal_mixer hal_mixer; |
111 | struct pcm *pcm; |
112 | bool pcm_paused; |
113 | unsigned hdmi_arc_ad[HDMI_ARC_MAX_FORMAT]; |
114 | bool hi_pcm_mode; |
115 | }; |
116 | |
117 | struct aml_stream_out { |
118 | struct audio_stream_out stream; |
119 | /* see note below on mutex acquisition order */ |
120 | pthread_mutex_t lock; |
121 | /* config which set to ALSA device */ |
122 | struct pcm_config config; |
123 | /* channel mask exposed to AudioFlinger. */ |
124 | audio_channel_mask_t hal_channel_mask; |
125 | /* format mask exposed to AudioFlinger. */ |
126 | audio_format_t hal_format; |
127 | /* samplerate exposed to AudioFlinger. */ |
128 | unsigned int hal_rate; |
129 | audio_output_flags_t flags; |
130 | audio_devices_t out_device; |
131 | struct pcm *pcm; |
132 | struct resampler_itfe *resampler; |
133 | char *buffer; |
134 | size_t buffer_frames; |
135 | bool standby; |
136 | struct echo_reference_itfe *echo_reference; |
137 | struct aml_audio_device *dev; |
138 | int write_threshold; |
139 | bool low_power; |
140 | unsigned multich; |
141 | int codec_type; |
142 | uint64_t frame_write_sum; |
143 | uint64_t frame_skip_sum; |
144 | uint64_t last_frames_postion; |
145 | uint64_t spdif_enc_init_frame_write_sum; |
146 | int skip_frame; |
147 | int32_t *tmp_buffer_8ch; |
148 | int is_tv_platform; |
149 | void *audioeffect_tmp_buffer; |
150 | int has_SRS_lib; |
151 | int has_EQ_lib; |
152 | unsigned char pause_status; |
153 | bool hw_sync_mode; |
154 | int has_aml_IIR_lib; |
155 | int has_Virtualizer; |
156 | float volume_l; |
157 | float volume_r; |
158 | int last_codec_type; |
159 | //as raw audio framesize is 1 computed by audio_stream_out_frame_size |
160 | //we need divide more when we got 61937 audio package |
161 | int raw_61937_frame_size;//61937 frame size |
162 | unsigned last_dsp_frame;//recorded for wraparound print info |
163 | audio_hwsync_t hwsync; |
164 | struct timespec timestamp; |
165 | }; |
166 | |
167 | #define MAX_PREPROCESSORS 3 /* maximum one AGC + one NS + one AEC per input stream */ |
168 | struct aml_stream_in { |
169 | struct audio_stream_in stream; |
170 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
171 | struct pcm_config config; |
172 | struct pcm *pcm; |
173 | int device; |
174 | struct resampler_itfe *resampler; |
175 | struct resampler_buffer_provider buf_provider; |
176 | int16_t *buffer; |
177 | size_t frames_in; |
178 | unsigned int requested_rate; |
179 | bool standby; |
180 | int source; |
181 | struct echo_reference_itfe *echo_reference; |
182 | bool need_echo_reference; |
183 | effect_handle_t preprocessors[MAX_PREPROCESSORS]; |
184 | int num_preprocessors; |
185 | int16_t *proc_buf; |
186 | size_t proc_buf_size; |
187 | size_t proc_frames_in; |
188 | int16_t *ref_buf; |
189 | size_t ref_buf_size; |
190 | size_t ref_frames_in; |
191 | int read_status; |
192 | struct aml_audio_device *dev; |
193 | }; |
194 | typedef int (*do_standby_func)(struct aml_stream_out *out); |
195 | typedef int (*do_startup_func)(struct aml_stream_out *out); |
196 | #endif |
197 |