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