From ea873d1a6ae6b5ee4b75a56998ff0a93649ca226 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 9 Jan 2014 14:47:36 +0200 Subject: [PATCH] android/haltest: Add support for loading Audio HAL This makes audio.a2dp.default.so to be loaded by haltest. --- android/Android.mk | 1 + android/Makefile.am | 1 + android/client/haltest.c | 10 ++++-- android/client/if-audio.c | 67 +++++++++++++++++++++++++++++++++++++++ android/client/if-main.h | 4 +++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 android/client/if-audio.c diff --git a/android/Android.mk b/android/Android.mk index 99882bb1f..5a55a7692 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -126,6 +126,7 @@ LOCAL_SRC_FILES := \ client/terminal.c \ client/history.c \ client/tabcompletion.c \ + client/if-audio.c \ client/if-av.c \ client/if-bt.c \ client/if-hf.c \ diff --git a/android/Makefile.am b/android/Makefile.am index f5e8c994e..87676cd14 100644 --- a/android/Makefile.am +++ b/android/Makefile.am @@ -89,6 +89,7 @@ android_haltest_SOURCES = android/client/haltest.c \ android/client/if-hh.c \ android/client/if-pan.c \ android/client/if-sock.c \ + android/client/if-audio.c \ android/hardware/hardware.c \ android/hal-utils.h android/hal-utils.c diff --git a/android/client/haltest.c b/android/client/haltest.c index 7154d2788..7c314c0df 100644 --- a/android/client/haltest.c +++ b/android/client/haltest.c @@ -31,6 +31,7 @@ #include "history.h" const struct interface *interfaces[] = { + &audio_if, &bluetooth_if, &av_if, #if PLATFORM_SDK_VERSION > 17 @@ -393,10 +394,13 @@ static void init(void) }; const struct method *m; const char *argv[4]; - char init_line[] = "bluetooth init"; + char init_audio[] = "audio init"; + char init_bt[] = "bluetooth init"; uint32_t i; - process_line(init_line); + process_line(init_audio); + process_line(init_bt); + m = get_interface_method("bluetooth", "get_profile_interface"); for (i = 0; i < NELEM(inames); ++i) { @@ -405,7 +409,7 @@ static void init(void) } /* Init what is available to init */ - for (i = 1; i < NELEM(interfaces) - 1; ++i) { + for (i = 2; i < NELEM(interfaces) - 1; ++i) { m = get_interface_method(interfaces[i]->name, "init"); if (m != NULL) m->func(2, argv); diff --git a/android/client/if-audio.c b/android/client/if-audio.c new file mode 100644 index 000000000..203e08805 --- /dev/null +++ b/android/client/if-audio.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2014 Intel Corporation + * + * 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. + * + */ + +#include "if-main.h" +#include "../hal-utils.h" + +audio_hw_device_t *if_audio = NULL; + +static void init_p(int argc, const char **argv) +{ + int err; + const hw_module_t *module; + audio_hw_device_t *device; + + err = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, + AUDIO_HARDWARE_MODULE_ID_A2DP, &module); + if (err) { + haltest_error("hw_get_module_by_class returned %d\n", err); + return; + } + + err = audio_hw_device_open(module, &device); + if (err) + haltest_error("audio_hw_device_open returned %d\n", err); + + if_audio = device; +} + +static void cleanup_p(int argc, const char **argv) +{ + int err; + + RETURN_IF_NULL(if_audio); + + err = audio_hw_device_close(if_audio); + if (err < 0) { + haltest_error("audio_hw_device_close returned %d\n", err); + return; + } + + if_audio = NULL; +} + +static struct method methods[] = { + STD_METHOD(init), + STD_METHOD(cleanup), + END_METHOD +}; + +const struct interface audio_if = { + .name = "audio", + .methods = methods +}; diff --git a/android/client/if-main.h b/android/client/if-main.h index 4a5d4ccc5..0371c3e7b 100644 --- a/android/client/if-main.h +++ b/android/client/if-main.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,8 @@ #include #endif +extern audio_hw_device_t *if_audio; + /* Interfaces from hal that can be populated during application lifetime */ extern const bt_interface_t *if_bluetooth; extern const btav_interface_t *if_av; @@ -66,6 +69,7 @@ struct interface { struct method *methods; /* methods available for this interface */ }; +extern const struct interface audio_if; extern const struct interface bluetooth_if; extern const struct interface av_if; #if PLATFORM_SDK_VERSION > 17 -- 2.47.3