blob: 437be259d454967abddd14fa916b6753c91d512f [file] [log] [blame]
Mikhail Naganove4f1f632016-08-31 11:35:10 -07001/*
2 * Copyright (C) 2016 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#define LOG_TAG "AudioFlinger::DevicesFactoryHalLocal"
18//#define LOG_NDEBUG 0
19
20#include <string.h>
21
22#include <hardware/audio.h>
23#include <utils/Log.h>
24
25#include "DeviceHalLocal.h"
26#include "DevicesFactoryHalLocal.h"
27
28namespace android {
29
30// static
31sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
32 return new DevicesFactoryHalLocal();
33}
34
35static status_t load_audio_interface(const char *if_name, audio_hw_device_t **dev)
36{
37 const hw_module_t *mod;
38 int rc;
39
40 rc = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, if_name, &mod);
41 if (rc) {
42 ALOGE("%s couldn't load audio hw module %s.%s (%s)", __func__,
43 AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
44 goto out;
45 }
46 rc = audio_hw_device_open(mod, dev);
47 if (rc) {
48 ALOGE("%s couldn't open audio hw device in %s.%s (%s)", __func__,
49 AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
50 goto out;
51 }
52 if ((*dev)->common.version < AUDIO_DEVICE_API_VERSION_MIN) {
53 ALOGE("%s wrong audio hw device version %04x", __func__, (*dev)->common.version);
54 rc = BAD_VALUE;
55 audio_hw_device_close(*dev);
56 goto out;
57 }
58 return OK;
59
60out:
61 *dev = NULL;
62 return rc;
63}
64
65status_t DevicesFactoryHalLocal::openDevice(const char *name, sp<DeviceHalInterface> *device) {
66 audio_hw_device_t *dev;
67 status_t rc = load_audio_interface(name, &dev);
68 if (rc == OK) {
69 *device = new DeviceHalLocal(dev);
70 }
71 return rc;
72}
73
74} // namespace android