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 EXT_PCM_H 18 #define EXT_PCM_H 19 20 #include <pthread.h> 21 22 #include <cutils/hashmap.h> 23 #include <tinyalsa/asoundlib.h> 24 25 // Holds up to 4KB buffer for each mixer pipeline, this value is arbitrary chosen 26 #define MIXER_BUFFER_SIZE (1024 * 4) 27 28 struct ext_mixer_pipeline { 29 int16_t buffer[MIXER_BUFFER_SIZE]; 30 unsigned int position; 31 }; 32 33 struct ext_pcm { 34 struct pcm *pcm; 35 pthread_mutex_t lock; 36 unsigned int ref_count; 37 pthread_mutex_t mixer_lock; 38 struct ext_mixer_pipeline mixer_pipeline; 39 pthread_t mixer_thread; 40 Hashmap *mixer_pipeline_map; 41 }; 42 43 struct ext_pcm *ext_pcm_open(unsigned int card, unsigned int device, 44 unsigned int flags, struct pcm_config *config); 45 int ext_pcm_close(struct ext_pcm *ext_pcm); 46 int ext_pcm_is_ready(struct ext_pcm *ext_pcm); 47 int ext_pcm_write(struct ext_pcm *ext_pcm, const char *bus_address, 48 const void *data, unsigned int count); 49 const char *ext_pcm_get_error(struct ext_pcm *ext_pcm); 50 unsigned int ext_pcm_frames_to_bytes(struct ext_pcm *ext_pcm, 51 unsigned int frames); 52 53 #endif // EXT_PCM_H 54