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