Home | History | Annotate | Download | only in driver
      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   bool master_mute;             // Proteced by this->lock
     32   bool mic_mute;                // Proteced by this->lock
     33   struct mixer *mixer;          // Proteced by this->lock
     34   Hashmap *out_bus_stream_map;  // Extended field. Constant after init
     35 };
     36 
     37 struct generic_stream_out {
     38   struct audio_stream_out stream;  // Constant after init
     39   pthread_mutex_t lock;
     40   struct generic_audio_device *dev;  // Constant after init
     41   audio_devices_t device;            // Protected by this->lock
     42   struct audio_config req_config;    // Constant after init
     43   struct pcm_config pcm_config;      // Constant after init
     44   audio_vbuffer_t buffer;            // Constant after init
     45   const char *bus_address;           // Extended field. Constant after init
     46   struct audio_gain gain_stage;      // Constant after init
     47   float amplitude_ratio;             // Protected by this->lock
     48 
     49   // Time & Position Keeping
     50   bool standby;                    // Protected by this->lock
     51   uint64_t underrun_position;      // Protected by this->lock
     52   struct timespec underrun_time;   // Protected by this->lock
     53   uint64_t last_write_time_us;     // Protected by this->lock
     54   uint64_t frames_total_buffered;  // Protected by this->lock
     55   uint64_t frames_written;         // Protected by this->lock
     56   uint64_t frames_rendered;        // Protected by this->lock
     57 
     58   // Worker
     59   pthread_t worker_thread;     // Constant after init
     60   pthread_cond_t worker_wake;  // Protected by this->lock
     61   bool worker_standby;         // Protected by this->lock
     62   bool worker_exit;            // Protected by this->lock
     63 };
     64 
     65 struct generic_stream_in {
     66   struct audio_stream_in stream;  // Constant after init
     67   pthread_mutex_t lock;
     68   struct generic_audio_device *dev;  // Constant after init
     69   audio_devices_t device;            // Protected by this->lock
     70   struct audio_config req_config;    // Constant after init
     71   struct pcm *pcm;                   // Protected by this->lock
     72   struct pcm_config pcm_config;      // Constant after init
     73   int16_t *stereo_to_mono_buf;       // Protected by this->lock
     74   size_t stereo_to_mono_buf_size;    // Protected by this->lock
     75   audio_vbuffer_t buffer;            // Protected by this->lock
     76   const char *bus_address;           // Extended field. Constant after init
     77 
     78   // Time & Position Keeping
     79   bool standby;                       // Protected by this->lock
     80   int64_t standby_position;           // Protected by this->lock
     81   struct timespec standby_exit_time;  // Protected by this->lock
     82   int64_t standby_frames_read;        // Protected by this->lock
     83 
     84   // Worker
     85   pthread_t worker_thread;     // Constant after init
     86   pthread_cond_t worker_wake;  // Protected by this->lock
     87   bool worker_standby;         // Protected by this->lock
     88   bool worker_exit;            // Protected by this->lock
     89 };
     90 
     91 #endif  // AUDIO_HW_H
     92