blob: 6bd599c04938ea473d560713408e38b8cbbd290a
1 | #ifndef _AUDIO_HW_H_ |
2 | |
3 | #include <audio_utils/resampler.h> |
4 | #include "audio_hwsync.h" |
5 | |
6 | #define _AUDIO_HW_H_ |
7 | #define _AUDIO_HW_H_ |
8 | /* ALSA cards for AML */ |
9 | #define CARD_AMLOGIC_BOARD 0 |
10 | #define CARD_AMLOGIC_DEFAULT CARD_AMLOGIC_BOARD |
11 | /* ALSA ports for AML */ |
12 | #define PORT_MM 1 |
13 | /* number of frames per period */ |
14 | #define DEFAULT_PERIOD_SIZE 1024 //(1024 * 2) |
15 | static unsigned PERIOD_SIZE = DEFAULT_PERIOD_SIZE; |
16 | /* number of periods for low power playback */ |
17 | #define PLAYBACK_PERIOD_COUNT 4 |
18 | /* number of periods for capture */ |
19 | #define CAPTURE_PERIOD_COUNT 4 |
20 | |
21 | /* minimum sleep time in out_write() when write threshold is not reached */ |
22 | #define MIN_WRITE_SLEEP_US 5000 |
23 | |
24 | #define RESAMPLER_BUFFER_FRAMES (PERIOD_SIZE * 6) |
25 | #define RESAMPLER_BUFFER_SIZE (4 * RESAMPLER_BUFFER_FRAMES) |
26 | |
27 | static unsigned int DEFAULT_OUT_SAMPLING_RATE = 48000; |
28 | |
29 | /* sampling rate when using MM low power port */ |
30 | #define MM_LOW_POWER_SAMPLING_RATE 44100 |
31 | /* sampling rate when using MM full power port */ |
32 | #define MM_FULL_POWER_SAMPLING_RATE 48000 |
33 | /* sampling rate when using VX port for narrow band */ |
34 | #define VX_NB_SAMPLING_RATE 8000 |
35 | |
36 | enum { |
37 | TYPE_PCM = 0, |
38 | TYPE_AC3 = 2, |
39 | TYPE_DTS = 3, |
40 | TYPE_EAC3 = 4, |
41 | TYPE_DTS_HD = 5 , |
42 | TYPE_MULTI_PCM = 6, |
43 | TYPE_TRUE_HD = 7, |
44 | TYPE_DTS_HD_MA = 8,//should not used after we unify DTS-HD&DTS-HD MA |
45 | TYPE_PCM_HIGH_SR = 9, |
46 | }; |
47 | |
48 | #define AML_HAL_MIXER_BUF_SIZE 64*1024 |
49 | struct aml_hal_mixer { |
50 | unsigned char start_buf[AML_HAL_MIXER_BUF_SIZE]; |
51 | unsigned int wp; |
52 | unsigned int rp; |
53 | unsigned int buf_size; |
54 | unsigned char need_cache_flag;//flag to check if need cache some data before write to mix |
55 | pthread_mutex_t lock; |
56 | }; |
57 | |
58 | #define MAX_STREAM_NUM 5 |
59 | #define HDMI_ARC_MAX_FORMAT 20 |
60 | struct aml_audio_device { |
61 | struct audio_hw_device hw_device; |
62 | |
63 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
64 | pthread_mutex_t pcm_write_lock; |
65 | int mode; |
66 | audio_devices_t in_device; |
67 | audio_devices_t out_device; |
68 | int in_call; |
69 | struct aml_stream_in *active_input; |
70 | struct aml_stream_out *active_output[MAX_STREAM_NUM]; |
71 | unsigned char active_output_count; |
72 | bool mic_mute; |
73 | unsigned int card; |
74 | struct audio_route *ar; |
75 | struct echo_reference_itfe *echo_reference; |
76 | bool low_power; |
77 | struct aml_stream_out *hwsync_output; |
78 | struct aml_hal_mixer hal_mixer; |
79 | struct pcm *pcm; |
80 | bool pcm_paused; |
81 | unsigned hdmi_arc_ad[HDMI_ARC_MAX_FORMAT]; |
82 | }; |
83 | |
84 | struct aml_stream_out { |
85 | struct audio_stream_out stream; |
86 | /* see note below on mutex acquisition order */ |
87 | pthread_mutex_t lock; |
88 | /* config which set to ALSA device */ |
89 | struct pcm_config config; |
90 | /* channel mask exposed to AudioFlinger. */ |
91 | audio_channel_mask_t hal_channel_mask; |
92 | /* format mask exposed to AudioFlinger. */ |
93 | audio_format_t hal_format; |
94 | /* samplerate exposed to AudioFlinger. */ |
95 | unsigned int hal_rate; |
96 | audio_output_flags_t flags; |
97 | audio_devices_t out_device; |
98 | struct pcm *pcm; |
99 | struct resampler_itfe *resampler; |
100 | char *buffer; |
101 | size_t buffer_frames; |
102 | bool standby; |
103 | struct echo_reference_itfe *echo_reference; |
104 | struct aml_audio_device *dev; |
105 | int write_threshold; |
106 | bool low_power; |
107 | unsigned multich; |
108 | int codec_type; |
109 | uint64_t frame_write_sum; |
110 | uint64_t frame_skip_sum; |
111 | uint64_t last_frames_postion; |
112 | uint64_t spdif_enc_init_frame_write_sum; |
113 | int skip_frame; |
114 | int32_t *tmp_buffer_8ch; |
115 | int is_tv_platform; |
116 | void *audioeffect_tmp_buffer; |
117 | int has_SRS_lib; |
118 | int has_EQ_lib; |
119 | unsigned char pause_status; |
120 | bool hw_sync_mode; |
121 | int has_aml_IIR_lib; |
122 | float volume_l; |
123 | float volume_r; |
124 | int last_codec_type; |
125 | //as raw audio framesize is 1 computed by audio_stream_out_frame_size |
126 | //we need divide more when we got 61937 audio package |
127 | int raw_61937_frame_size;//61937 frame size |
128 | unsigned last_dsp_frame;//recorded for wraparound print info |
129 | audio_hwsync_t hwsync; |
130 | struct timespec timestamp; |
131 | }; |
132 | |
133 | #define MAX_PREPROCESSORS 3 /* maximum one AGC + one NS + one AEC per input stream */ |
134 | struct aml_stream_in { |
135 | struct audio_stream_in stream; |
136 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
137 | struct pcm_config config; |
138 | struct pcm *pcm; |
139 | int device; |
140 | struct resampler_itfe *resampler; |
141 | struct resampler_buffer_provider buf_provider; |
142 | int16_t *buffer; |
143 | size_t frames_in; |
144 | unsigned int requested_rate; |
145 | bool standby; |
146 | int source; |
147 | struct echo_reference_itfe *echo_reference; |
148 | bool need_echo_reference; |
149 | effect_handle_t preprocessors[MAX_PREPROCESSORS]; |
150 | int num_preprocessors; |
151 | int16_t *proc_buf; |
152 | size_t proc_buf_size; |
153 | size_t proc_frames_in; |
154 | int16_t *ref_buf; |
155 | size_t ref_buf_size; |
156 | size_t ref_frames_in; |
157 | int read_status; |
158 | struct aml_audio_device *dev; |
159 | }; |
160 | typedef int (*do_standby_func)(struct aml_stream_out *out); |
161 | typedef int (*do_startup_func)(struct aml_stream_out *out); |
162 | #endif |
163 |