summaryrefslogtreecommitdiff
path: root/audio_hw.h (plain)
blob: 83d3080c573a24f22414028c72fbd451ba73b317
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
36enum {
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
49struct 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
60struct 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 hw_sync_mode;
81 audio_hwsync_t hwsync;
82};
83
84struct 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 struct pcm *pcm;
98 struct resampler_itfe *resampler;
99 char *buffer;
100 size_t buffer_frames;
101 bool standby;
102 struct echo_reference_itfe *echo_reference;
103 struct aml_audio_device *dev;
104 int write_threshold;
105 bool low_power;
106 unsigned multich;
107 int codec_type;
108 uint64_t frame_write_sum;
109 uint64_t frame_skip_sum;
110 uint64_t last_frames_postion;
111 uint8_t hw_sync_header[16];
112 int hw_sync_header_cnt;
113 int hw_sync_state;
114 int hw_sync_body_cnt;
115 uint64_t spdif_enc_init_frame_write_sum;
116 uint64_t bytes_write_total;
117 int skip_frame;
118 uint8_t body_align[64];
119 uint8_t body_align_cnt;
120 int32_t *tmp_buffer_8ch;
121 int is_tv_platform;
122 void *audioeffect_tmp_buffer;
123 int has_SRS_lib;
124 int has_EQ_lib;
125 unsigned char pause_status;
126 bool hw_sync_mode;
127 bool first_apts_flag;//flag to indicate set first apts
128 uint64_t first_apts;
129 int64_t last_apts_from_header;
130 int has_aml_IIR_lib;
131 float volume_l;
132 float volume_r;
133 int last_codec_type;
134 //as raw audio framesize is 1 computed by audio_stream_out_frame_size
135 //we need divide more when we got 61937 audio package
136 int raw_61937_frame_size;//61937 frame size
137 unsigned last_dsp_frame;//recorded for wraparound print info
138};
139
140#define MAX_PREPROCESSORS 3 /* maximum one AGC + one NS + one AEC per input stream */
141struct aml_stream_in {
142 struct audio_stream_in stream;
143 pthread_mutex_t lock; /* see note below on mutex acquisition order */
144 struct pcm_config config;
145 struct pcm *pcm;
146 int device;
147 struct resampler_itfe *resampler;
148 struct resampler_buffer_provider buf_provider;
149 int16_t *buffer;
150 size_t frames_in;
151 unsigned int requested_rate;
152 bool standby;
153 int source;
154 struct echo_reference_itfe *echo_reference;
155 bool need_echo_reference;
156 effect_handle_t preprocessors[MAX_PREPROCESSORS];
157 int num_preprocessors;
158 int16_t *proc_buf;
159 size_t proc_buf_size;
160 size_t proc_frames_in;
161 int16_t *ref_buf;
162 size_t ref_buf_size;
163 size_t ref_frames_in;
164 int read_status;
165 struct aml_audio_device *dev;
166};
167typedef int (*do_standby_func)(struct aml_stream_out *out);
168typedef int (*do_startup_func)(struct aml_stream_out *out);
169#endif
170