summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorRicardo Garcia <rago@google.com>2015-02-23 15:42:26 -0800
committerRicardo Garcia <rago@google.com>2015-03-17 15:50:05 -0700
commit37cd77257b07d6f078763e9435487698dfb353c4 (patch)
treeb8836a7a62ee8671acbe2124928d1efdb431ca5d /modules
parent2ae2ec9c937193109a086513584e892581760ab5 (diff)
downloadhardware_libhardware-37cd77257b07d6f078763e9435487698dfb353c4.zip
hardware_libhardware-37cd77257b07d6f078763e9435487698dfb353c4.tar.gz
hardware_libhardware-37cd77257b07d6f078763e9435487698dfb353c4.tar.bz2
Creating audio.stub.default for default HAL audio output
Creating a simple "stub" audio HAL to be used in systems with no hardware output. This stub HAL allows systems to run CTS tests and other audio system calls without crashing or unexpected behavior. The stub can be used also as a starting point for creating a new HAL. This is needed for audio_output feature support. bug: 19439530 Change-Id: I9e8e06e5b7fea7c7f3ff1de303db015b51e8acde
Diffstat (limited to 'modules')
-rw-r--r--modules/audio/Android.mk17
-rw-r--r--modules/audio/audio_hw.c61
2 files changed, 71 insertions, 7 deletions
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index a31c85f..ef4b8f5 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -31,6 +31,23 @@ LOCAL_CFLAGS := -Wno-unused-parameter
include $(BUILD_SHARED_LIBRARY)
+# The stub audio HAL module, identical to the default audio hal, but with
+# different name to be loaded concurrently with other audio HALs if necessary.
+# This can also be used as skeleton for new implementations
+#
+# The format of the name is audio.<type>.<hardware/etc>.so where the only
+# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio.stub.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := audio_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wno-unused-parameter
+
+include $(BUILD_SHARED_LIBRARY)
+
# The stub audio policy HAL module that can be used as a skeleton for
# new implementations.
include $(CLEAR_VARS)
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index 637e3f4..de8685d 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -48,65 +48,78 @@ static uint32_t out_get_sample_rate(const struct audio_stream *stream)
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ ALOGV("out_set_sample_rate: %d", 0);
+ return -ENOSYS;
}
static size_t out_get_buffer_size(const struct audio_stream *stream)
{
+ ALOGV("out_get_buffer_size: %d", 4096);
return 4096;
}
static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
{
+ ALOGV("out_get_channels");
return AUDIO_CHANNEL_OUT_STEREO;
}
static audio_format_t out_get_format(const struct audio_stream *stream)
{
+ ALOGV("out_get_format");
return AUDIO_FORMAT_PCM_16_BIT;
}
static int out_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ ALOGV("out_set_format: %d",format);
+ return -ENOSYS;
}
static int out_standby(struct audio_stream *stream)
{
+ ALOGV("out_standby");
+
return 0;
}
static int out_dump(const struct audio_stream *stream, int fd)
{
+ ALOGV("out_dump");
return 0;
}
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
+ ALOGV("out_set_parameters");
return 0;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
{
+ ALOGV("out_get_parameters");
return strdup("");
}
static uint32_t out_get_latency(const struct audio_stream_out *stream)
{
+ ALOGV("out_get_latency");
return 0;
}
static int out_set_volume(struct audio_stream_out *stream, float left,
float right)
{
+ ALOGV("out_set_volume: Left:%f Right:%f", left, right);
return 0;
}
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
size_t bytes)
{
+ ALOGV("out_write: bytes: %d", bytes);
/* XXX: fake timing for audio output */
- usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) /
+ usleep((int64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) /
out_get_sample_rate(&stream->common));
return bytes;
}
@@ -114,43 +127,53 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
static int out_get_render_position(const struct audio_stream_out *stream,
uint32_t *dsp_frames)
{
+ *dsp_frames = 0;
+ ALOGV("out_get_render_position: dsp_frames: %d", (int)dsp_frames);
return -EINVAL;
}
static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
+ ALOGV("out_add_audio_effect: %d", (int)effect);
return 0;
}
static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
+ ALOGV("out_remove_audio_effect: %d", (int)effect);
return 0;
}
static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
int64_t *timestamp)
{
+ *timestamp = 0;
+ ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp));
return -EINVAL;
}
/** audio_stream_in implementation **/
static uint32_t in_get_sample_rate(const struct audio_stream *stream)
{
+ ALOGV("in_get_sample_rate");
return 8000;
}
static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ ALOGV("in_set_sample_rate: %d", rate);
+ return -ENOSYS;
}
static size_t in_get_buffer_size(const struct audio_stream *stream)
{
+ ALOGV("in_get_buffer_size: %d", 320);
return 320;
}
static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
{
+ ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
return AUDIO_CHANNEL_IN_MONO;
}
@@ -161,7 +184,7 @@ static audio_format_t in_get_format(const struct audio_stream *stream)
static int in_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ return -ENOSYS;
}
static int in_standby(struct audio_stream *stream)
@@ -193,9 +216,11 @@ static int in_set_gain(struct audio_stream_in *stream, float gain)
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
size_t bytes)
{
+ ALOGV("in_read: bytes %d", bytes);
/* XXX: fake timing for audio input */
- usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
+ usleep((int64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) /
in_get_sample_rate(&stream->common));
+ memset(buffer, 0, bytes);
return bytes;
}
@@ -222,6 +247,8 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
struct audio_stream_out **stream_out,
const char *address __unused)
{
+ ALOGV("adev_open_output_stream...");
+
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
struct stub_stream_out *out;
int ret;
@@ -260,68 +287,81 @@ err_open:
static void adev_close_output_stream(struct audio_hw_device *dev,
struct audio_stream_out *stream)
{
+ ALOGV("adev_close_output_stream...");
free(stream);
}
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
+ ALOGV("adev_set_parameters");
return -ENOSYS;
}
static char * adev_get_parameters(const struct audio_hw_device *dev,
const char *keys)
{
- return NULL;
+ ALOGV("adev_get_parameters");
+ return strdup("");
}
static int adev_init_check(const struct audio_hw_device *dev)
{
+ ALOGV("adev_init_check");
return 0;
}
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
{
+ ALOGV("adev_set_voice_volume: %f", volume);
return -ENOSYS;
}
static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
{
+ ALOGV("adev_set_master_volume: %f", volume);
return -ENOSYS;
}
static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
{
+ ALOGV("adev_get_master_volume: %f", *volume);
return -ENOSYS;
}
static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
{
+ ALOGV("adev_set_master_mute: %d", muted);
return -ENOSYS;
}
static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
{
+ ALOGV("adev_get_master_mute: %d", *muted);
return -ENOSYS;
}
static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
+ ALOGV("adev_set_mode: %d", mode);
return 0;
}
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
{
+ ALOGV("adev_set_mic_mute: %d",state);
return -ENOSYS;
}
static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
{
+ ALOGV("adev_get_mic_mute");
return -ENOSYS;
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
const struct audio_config *config)
{
+ ALOGV("adev_get_input_buffer_size: %d", 320);
return 320;
}
@@ -334,6 +374,8 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
const char *address __unused,
audio_source_t source __unused)
{
+ ALOGV("adev_open_input_stream...");
+
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
struct stub_stream_in *in;
int ret;
@@ -370,16 +412,19 @@ err_open:
static void adev_close_input_stream(struct audio_hw_device *dev,
struct audio_stream_in *in)
{
+ ALOGV("adev_close_input_stream...");
return;
}
static int adev_dump(const audio_hw_device_t *device, int fd)
{
+ ALOGV("adev_dump");
return 0;
}
static int adev_close(hw_device_t *device)
{
+ ALOGV("adev_close");
free(device);
return 0;
}
@@ -387,6 +432,8 @@ static int adev_close(hw_device_t *device)
static int adev_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
+ ALOGV("adev_open: %s", name);
+
struct stub_audio_device *adev;
int ret;