1 /* 2 * Copyright (C) 2018 The Android Open Source Project 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 17 #ifndef AUDIO_HW_H 18 #define AUDIO_HW_H 19 20 #include <pthread.h> 21 22 #include <cutils/hashmap.h> 23 #include <hardware/audio.h> 24 #include <tinyalsa/asoundlib.h> 25 26 #include "audio_vbuffer.h" 27 28 struct generic_audio_device { 29 struct audio_hw_device device; // Constant after init 30 pthread_mutex_t lock; 31 unsigned int last_patch_id; // Protected by this->lock 32 bool main_mute; // Protected by this->lock 33 bool mic_mute; // Protected by this->lock 34 struct mixer *mixer; // Protected by this->lock 35 Hashmap *out_bus_stream_map; // Extended field. Constant after init 36 Hashmap *in_bus_tone_frequency_map; // Extended field. Constant after init 37 int next_tone_frequency_to_assign; // Protected by this->lock 38 // Play on Speaker zone selection 39 int last_zone_selected_to_play; // Protected by this->lock 40 }; 41 42 enum output_channel_enable { 43 LEFT_CHANNEL = 1, 44 RIGHT_CHANNEL = 1 << 1, 45 BOTH_CHANNELS = LEFT_CHANNEL | RIGHT_CHANNEL 46 }; 47 48 struct generic_stream_out { 49 struct audio_stream_out stream; // Constant after init 50 pthread_mutex_t lock; 51 struct generic_audio_device *dev; // Constant after init 52 audio_devices_t device; // Protected by this->lock 53 struct audio_config req_config; // Constant after init 54 struct pcm_config pcm_config; // Constant after init 55 audio_vbuffer_t buffer; // Constant after init 56 const char *bus_address; // Extended field. Constant after init 57 struct audio_gain gain_stage; // Constant after init 58 float amplitude_ratio; // Protected by this->lock 59 enum output_channel_enable enabled_channels; // Constant after init 60 61 // Time & Position Keeping 62 bool standby; // Protected by this->lock 63 uint64_t underrun_position; // Protected by this->lock 64 struct timespec underrun_time; // Protected by this->lock 65 uint64_t last_write_time_us; // Protected by this->lock 66 uint64_t frames_total_buffered; // Protected by this->lock 67 uint64_t frames_written; // Protected by this->lock 68 uint64_t frames_rendered; // Protected by this->lock 69 70 // Worker 71 pthread_t worker_thread; // Constant after init 72 pthread_cond_t worker_wake; // Protected by this->lock 73 pthread_cond_t write_wake; // Protected by this->lock 74 bool worker_standby; // Protected by this->lock 75 bool worker_exit; // Protected by this->lock 76 }; 77 78 struct oscillator { 79 float phase; 80 float phase_increment; 81 }; 82 83 struct generic_stream_in { 84 struct audio_stream_in stream; // Constant after init 85 pthread_mutex_t lock; 86 struct generic_audio_device *dev; // Constant after init 87 audio_devices_t device; // Protected by this->lock 88 struct audio_config req_config; // Constant after init 89 struct pcm *pcm; // Protected by this->lock 90 struct pcm_config pcm_config; // Constant after init 91 int16_t *stereo_to_mono_buf; // Protected by this->lock 92 size_t stereo_to_mono_buf_size; // Protected by this->lock 93 audio_vbuffer_t buffer; // Protected by this->lock 94 const char *bus_address; // Extended field. Constant after init 95 96 // Time & Position Keeping 97 bool standby; // Protected by this->lock 98 int64_t standby_position; // Protected by this->lock 99 struct timespec standby_exit_time; // Protected by this->lock 100 int64_t standby_frames_read; // Protected by this->lock 101 102 // Worker 103 pthread_t worker_thread; // Constant after init 104 pthread_cond_t worker_wake; // Protected by this->lock 105 bool worker_standby; // Protected by this->lock 106 bool worker_exit; // Protected by this->lock 107 108 // Tone Oscillator 109 struct oscillator oscillator; // Protected by this->lock 110 }; 111 112 #endif // AUDIO_HW_H 113