-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundTriggerDevice.h
executable file
·100 lines (89 loc) · 3.6 KB
/
SoundTriggerDevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SOUND_TRIGGER_DEVICE_H
#define SOUND_TRIGGER_DEVICE_H
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <dlfcn.h>
#include <unistd.h>
#include <vector>
#include <memory>
#include <mutex>
#include <hardware/sound_trigger.h>
#include <cutils/properties.h>
#include "SoundTriggerSession.h"
#include "SoundTriggerPropIntf.h"
#define AUDIO_HAL_NAME_PREFIX "audio.primary"
#if LINUX_ENABLED
#ifdef __LP64__
#define AUDIO_HAL_LIBRARY_PATH1 "/usr/lib64"
#define AUDIO_HAL_LIBRARY_PATH2 AUDIO_HAL_LIBRARY_PATH1
#else
#define AUDIO_HAL_LIBRARY_PATH1 "/usr/lib"
#define AUDIO_HAL_LIBRARY_PATH2 AUDIO_HAL_LIBRARY_PATH1
#endif
#else
#ifdef __LP64__
#define AUDIO_HAL_LIBRARY_PATH1 "/vendor/lib64/hw"
#define AUDIO_HAL_LIBRARY_PATH2 "/system/lib64/hw"
#else
#define AUDIO_HAL_LIBRARY_PATH1 "/vendor/lib/hw"
#define AUDIO_HAL_LIBRARY_PATH2 "/system/lib/hw"
#endif
#endif
class SoundTriggerDevice {
public:
SoundTriggerDevice() {}
~SoundTriggerDevice() {}
static std::shared_ptr<SoundTriggerDevice> GetInstance();
static std::shared_ptr<SoundTriggerDevice> GetInstance(
const hw_device_t *device);
static std::shared_ptr<SoundTriggerDevice> GetInstance(
const struct sound_trigger_hw_device *st_device);
int Init(hw_device_t **device, const hw_module_t *module);
int LoadAudioHal();
int PlatformInit();
SoundTriggerSession* GetSession(sound_model_handle_t handle);
int RegisterSession(SoundTriggerSession* session);
int DeregisterSession(SoundTriggerSession* session);
audio_hw_call_back_t ahal_callback_;
volatile int session_id_;
bool conc_capture_supported_;
protected:
static std::shared_ptr<SoundTriggerDevice> stdev_;
static std::shared_ptr<struct sound_trigger_hw_device> device_;
struct sound_trigger_properties *hw_properties_;
std::vector<SoundTriggerSession *> session_list_;
std::mutex mutex_;
audio_devices_t available_devices_;
void *ahal_handle_;
unsigned int sthal_prop_api_version_;
};
#endif // SOUND_TRIGGER_DEVICE_H