1 /* 2 * Copyright (C) 2014 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 ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H 18 #define ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H 19 20 #include <tinyalsa/asoundlib.h> 21 22 #include "alsa_device_profile.h" 23 24 typedef struct { 25 const alsa_device_profile* profile; 26 27 struct pcm_config alsa_config; 28 29 struct pcm * pcm; 30 31 size_t frame_size; /* valid after proxy_prepare(), the frame size in bytes */ 32 uint64_t transferred; /* the total frames transferred, not cleared on standby */ 33 } alsa_device_proxy; 34 35 36 /* State */ 37 int proxy_prepare(alsa_device_proxy * proxy, const alsa_device_profile * profile, 38 struct pcm_config * config, bool require_exact_match); 39 int proxy_prepare_from_default_config( 40 alsa_device_proxy * proxy, const alsa_device_profile * profile); 41 int proxy_open(alsa_device_proxy * proxy); 42 void proxy_close(alsa_device_proxy * proxy); 43 int proxy_get_presentation_position(const alsa_device_proxy * proxy, 44 uint64_t *frames, struct timespec *timestamp); 45 int proxy_get_capture_position(const alsa_device_proxy * proxy, 46 int64_t *frames, int64_t *time); 47 48 /* Attributes */ 49 unsigned proxy_get_sample_rate(const alsa_device_proxy * proxy); 50 enum pcm_format proxy_get_format(const alsa_device_proxy * proxy); 51 unsigned proxy_get_channel_count(const alsa_device_proxy * proxy); 52 unsigned int proxy_get_period_size(const alsa_device_proxy * proxy); 53 unsigned proxy_get_latency(const alsa_device_proxy * proxy); 54 55 /* 56 * Scans the provided list of sample rates and finds the first one that works. 57 * 58 * returns the index of the first rate for which the ALSA device can be opened. 59 * return negative value if none work or an error occurs. 60 */ 61 int proxy_scan_rates(alsa_device_proxy * proxy, const unsigned sample_rates[], 62 bool require_exact_match); 63 64 /* I/O */ 65 int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count); 66 int proxy_write_with_retries( 67 alsa_device_proxy * proxy, const void *data, unsigned int count, int tries); 68 int proxy_read(alsa_device_proxy * proxy, void *data, unsigned int count); 69 int proxy_read_with_retries( 70 alsa_device_proxy * proxy, void *data, unsigned int count, int tries); 71 72 /* Debugging */ 73 void proxy_dump(const alsa_device_proxy * proxy, int fd); 74 75 #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H */ 76