2011-04-21 01:38:05 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "audio_hw_default"
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <cutils/log.h>
|
|
|
|
|
|
|
|
#include <hardware/hardware.h>
|
2011-05-11 23:15:53 +02:00
|
|
|
#include <system/audio.h>
|
2011-06-14 02:59:54 +02:00
|
|
|
#include <hardware/audio.h>
|
2011-04-21 01:38:05 +02:00
|
|
|
|
|
|
|
struct stub_audio_device {
|
|
|
|
struct audio_hw_device device;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stub_stream_out {
|
|
|
|
struct audio_stream_out stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stub_stream_in {
|
|
|
|
struct audio_stream_in stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t out_get_sample_rate(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 44100;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t out_get_buffer_size(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 4096;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t out_get_channels(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return AUDIO_CHANNEL_OUT_STEREO;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:55:57 +01:00
|
|
|
static audio_format_t out_get_format(const struct audio_stream *stream)
|
2011-04-21 01:38:05 +02:00
|
|
|
{
|
|
|
|
return AUDIO_FORMAT_PCM_16_BIT;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:55:57 +01:00
|
|
|
static int out_set_format(struct audio_stream *stream, audio_format_t format)
|
2011-04-21 01:38:05 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_standby(struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_dump(const struct audio_stream *stream, int fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
|
|
|
|
{
|
|
|
|
return strdup("");
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t out_get_latency(const struct audio_stream_out *stream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_set_volume(struct audio_stream_out *stream, float left,
|
|
|
|
float right)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
|
|
|
size_t bytes)
|
|
|
|
{
|
|
|
|
/* XXX: fake timing for audio output */
|
|
|
|
usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
|
|
|
|
out_get_sample_rate(&stream->common));
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_get_render_position(const struct audio_stream_out *stream,
|
|
|
|
uint32_t *dsp_frames)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-06-18 01:53:12 +02:00
|
|
|
static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-15 21:05:00 +02:00
|
|
|
static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
|
|
|
|
int64_t *timestamp)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:38:05 +02:00
|
|
|
/** audio_stream_in implementation **/
|
|
|
|
static uint32_t in_get_sample_rate(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 8000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t in_get_buffer_size(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 320;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t in_get_channels(const struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return AUDIO_CHANNEL_IN_MONO;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:55:57 +01:00
|
|
|
static audio_format_t in_get_format(const struct audio_stream *stream)
|
2011-04-21 01:38:05 +02:00
|
|
|
{
|
|
|
|
return AUDIO_FORMAT_PCM_16_BIT;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:55:57 +01:00
|
|
|
static int in_set_format(struct audio_stream *stream, audio_format_t format)
|
2011-04-21 01:38:05 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_standby(struct audio_stream *stream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_dump(const struct audio_stream *stream, int fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char * in_get_parameters(const struct audio_stream *stream,
|
|
|
|
const char *keys)
|
|
|
|
{
|
|
|
|
return strdup("");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_set_gain(struct audio_stream_in *stream, float gain)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
|
|
|
|
size_t bytes)
|
|
|
|
{
|
|
|
|
/* XXX: fake timing for audio input */
|
|
|
|
usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
|
|
|
|
in_get_sample_rate(&stream->common));
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-18 01:53:12 +02:00
|
|
|
static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-21 01:38:05 +02:00
|
|
|
|
|
|
|
static int adev_open_output_stream(struct audio_hw_device *dev,
|
2012-01-12 23:55:57 +01:00
|
|
|
uint32_t devices, audio_format_t *format,
|
2011-04-21 01:38:05 +02:00
|
|
|
uint32_t *channels, uint32_t *sample_rate,
|
|
|
|
struct audio_stream_out **stream_out)
|
|
|
|
{
|
|
|
|
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
|
|
|
|
struct stub_stream_out *out;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
out = (struct stub_stream_out *)calloc(1, sizeof(struct stub_stream_out));
|
|
|
|
if (!out)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
out->stream.common.get_sample_rate = out_get_sample_rate;
|
|
|
|
out->stream.common.set_sample_rate = out_set_sample_rate;
|
|
|
|
out->stream.common.get_buffer_size = out_get_buffer_size;
|
|
|
|
out->stream.common.get_channels = out_get_channels;
|
|
|
|
out->stream.common.get_format = out_get_format;
|
|
|
|
out->stream.common.set_format = out_set_format;
|
|
|
|
out->stream.common.standby = out_standby;
|
|
|
|
out->stream.common.dump = out_dump;
|
|
|
|
out->stream.common.set_parameters = out_set_parameters;
|
|
|
|
out->stream.common.get_parameters = out_get_parameters;
|
2011-06-18 01:53:12 +02:00
|
|
|
out->stream.common.add_audio_effect = out_add_audio_effect;
|
|
|
|
out->stream.common.remove_audio_effect = out_remove_audio_effect;
|
2011-04-21 01:38:05 +02:00
|
|
|
out->stream.get_latency = out_get_latency;
|
|
|
|
out->stream.set_volume = out_set_volume;
|
|
|
|
out->stream.write = out_write;
|
|
|
|
out->stream.get_render_position = out_get_render_position;
|
2011-08-15 21:05:00 +02:00
|
|
|
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
|
2011-04-21 01:38:05 +02:00
|
|
|
|
|
|
|
*stream_out = &out->stream;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_open:
|
|
|
|
free(out);
|
|
|
|
*stream_out = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adev_close_output_stream(struct audio_hw_device *dev,
|
|
|
|
struct audio_stream_out *stream)
|
|
|
|
{
|
|
|
|
free(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char * adev_get_parameters(const struct audio_hw_device *dev,
|
|
|
|
const char *keys)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_init_check(const struct audio_hw_device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-08-15 21:05:00 +02:00
|
|
|
static int adev_get_master_volume(struct audio_hw_device *dev,
|
|
|
|
float *volume)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2012-01-09 19:41:30 +01:00
|
|
|
static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
|
2011-04-21 01:38:05 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
|
2012-01-12 23:55:57 +01:00
|
|
|
uint32_t sample_rate, audio_format_t format,
|
2011-04-21 01:38:05 +02:00
|
|
|
int channel_count)
|
|
|
|
{
|
|
|
|
return 320;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_open_input_stream(struct audio_hw_device *dev, uint32_t devices,
|
2012-01-12 23:55:57 +01:00
|
|
|
audio_format_t *format, uint32_t *channels,
|
2011-04-21 01:38:05 +02:00
|
|
|
uint32_t *sample_rate,
|
|
|
|
audio_in_acoustics_t acoustics,
|
|
|
|
struct audio_stream_in **stream_in)
|
|
|
|
{
|
|
|
|
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
|
|
|
|
struct stub_stream_in *in;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in));
|
|
|
|
if (!in)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
in->stream.common.get_sample_rate = in_get_sample_rate;
|
|
|
|
in->stream.common.set_sample_rate = in_set_sample_rate;
|
|
|
|
in->stream.common.get_buffer_size = in_get_buffer_size;
|
|
|
|
in->stream.common.get_channels = in_get_channels;
|
|
|
|
in->stream.common.get_format = in_get_format;
|
|
|
|
in->stream.common.set_format = in_set_format;
|
|
|
|
in->stream.common.standby = in_standby;
|
|
|
|
in->stream.common.dump = in_dump;
|
|
|
|
in->stream.common.set_parameters = in_set_parameters;
|
|
|
|
in->stream.common.get_parameters = in_get_parameters;
|
2011-06-18 01:53:12 +02:00
|
|
|
in->stream.common.add_audio_effect = in_add_audio_effect;
|
|
|
|
in->stream.common.remove_audio_effect = in_remove_audio_effect;
|
2011-04-21 01:38:05 +02:00
|
|
|
in->stream.set_gain = in_set_gain;
|
|
|
|
in->stream.read = in_read;
|
|
|
|
in->stream.get_input_frames_lost = in_get_input_frames_lost;
|
|
|
|
|
|
|
|
*stream_in = &in->stream;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_open:
|
|
|
|
free(in);
|
|
|
|
*stream_in = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adev_close_input_stream(struct audio_hw_device *dev,
|
|
|
|
struct audio_stream_in *in)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_dump(const audio_hw_device_t *device, int fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_close(hw_device_t *device)
|
|
|
|
{
|
|
|
|
free(device);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
|
|
|
|
{
|
|
|
|
return (/* OUT */
|
|
|
|
AUDIO_DEVICE_OUT_EARPIECE |
|
|
|
|
AUDIO_DEVICE_OUT_SPEAKER |
|
|
|
|
AUDIO_DEVICE_OUT_WIRED_HEADSET |
|
|
|
|
AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
|
|
|
|
AUDIO_DEVICE_OUT_AUX_DIGITAL |
|
|
|
|
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
|
|
|
|
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
|
|
|
|
AUDIO_DEVICE_OUT_ALL_SCO |
|
|
|
|
AUDIO_DEVICE_OUT_DEFAULT |
|
|
|
|
/* IN */
|
|
|
|
AUDIO_DEVICE_IN_COMMUNICATION |
|
|
|
|
AUDIO_DEVICE_IN_AMBIENT |
|
|
|
|
AUDIO_DEVICE_IN_BUILTIN_MIC |
|
|
|
|
AUDIO_DEVICE_IN_WIRED_HEADSET |
|
|
|
|
AUDIO_DEVICE_IN_AUX_DIGITAL |
|
|
|
|
AUDIO_DEVICE_IN_BACK_MIC |
|
|
|
|
AUDIO_DEVICE_IN_ALL_SCO |
|
|
|
|
AUDIO_DEVICE_IN_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adev_open(const hw_module_t* module, const char* name,
|
|
|
|
hw_device_t** device)
|
|
|
|
{
|
|
|
|
struct stub_audio_device *adev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
adev = calloc(1, sizeof(struct stub_audio_device));
|
|
|
|
if (!adev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
adev->device.common.tag = HARDWARE_DEVICE_TAG;
|
|
|
|
adev->device.common.version = 0;
|
|
|
|
adev->device.common.module = (struct hw_module_t *) module;
|
|
|
|
adev->device.common.close = adev_close;
|
|
|
|
|
|
|
|
adev->device.get_supported_devices = adev_get_supported_devices;
|
|
|
|
adev->device.init_check = adev_init_check;
|
|
|
|
adev->device.set_voice_volume = adev_set_voice_volume;
|
|
|
|
adev->device.set_master_volume = adev_set_master_volume;
|
2011-08-15 21:05:00 +02:00
|
|
|
adev->device.get_master_volume = adev_get_master_volume;
|
2011-04-21 01:38:05 +02:00
|
|
|
adev->device.set_mode = adev_set_mode;
|
|
|
|
adev->device.set_mic_mute = adev_set_mic_mute;
|
|
|
|
adev->device.get_mic_mute = adev_get_mic_mute;
|
|
|
|
adev->device.set_parameters = adev_set_parameters;
|
|
|
|
adev->device.get_parameters = adev_get_parameters;
|
|
|
|
adev->device.get_input_buffer_size = adev_get_input_buffer_size;
|
|
|
|
adev->device.open_output_stream = adev_open_output_stream;
|
|
|
|
adev->device.close_output_stream = adev_close_output_stream;
|
|
|
|
adev->device.open_input_stream = adev_open_input_stream;
|
|
|
|
adev->device.close_input_stream = adev_close_input_stream;
|
|
|
|
adev->device.dump = adev_dump;
|
|
|
|
|
|
|
|
*device = &adev->device.common;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hw_module_methods_t hal_module_methods = {
|
|
|
|
.open = adev_open,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_module HAL_MODULE_INFO_SYM = {
|
|
|
|
.common = {
|
|
|
|
.tag = HARDWARE_MODULE_TAG,
|
|
|
|
.version_major = 1,
|
|
|
|
.version_minor = 0,
|
|
|
|
.id = AUDIO_HARDWARE_MODULE_ID,
|
|
|
|
.name = "Default audio HW HAL",
|
|
|
|
.author = "The Android Open Source Project",
|
|
|
|
.methods = &hal_module_methods,
|
|
|
|
},
|
|
|
|
};
|