blob: 53c3127fc6b5ce0499e5836adb61fe0f7904fce5 [file] [log] [blame]
Cody Schuffelen134ff032019-11-22 00:25:32 -08001/*
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#include <errno.h>
17#include <stdint.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include <hardware/hardware.h>
22#include <system/audio.h>
23#include <system/audio_policy.h>
24#include <hardware/audio_policy.h>
25
26#include "guest/hals/audio/legacy/policy/vsoc_audio_policy_hal.h"
27
28namespace cvd {
29
30int GceAudioPolicy::Create(
31 const audio_policy_device* device,
32 audio_policy_service_ops* aps_ops,
33 void* service, audio_policy** ap) {
34 D("%s", __FUNCTION__);
35 audio_policy_device* dev;
36 gce_audio_policy* dap;
37 int ret;
38
39 *ap = NULL;
40
41 if (!service || !aps_ops) {
42 return -EINVAL;
43 }
44
45 dap = (gce_audio_policy*) calloc(1, sizeof(*dap));
46 if (!dap) {
47 return -ENOMEM;
48 }
49
50 dap->policy.set_device_connection_state =
51 &GceAudioPolicy::SetDeviceConnectionState;
52 dap->policy.get_device_connection_state =
53 &GceAudioPolicy::GetDeviceConnectionState;
54 dap->policy.set_phone_state = &GceAudioPolicy::SetPhoneState;
55 dap->policy.set_ringer_mode = &GceAudioPolicy::SetRingerMode;
56 dap->policy.set_force_use = &GceAudioPolicy::SetForceUse;
57 dap->policy.get_force_use = &GceAudioPolicy::GetForceUse;
58 dap->policy.set_can_mute_enforced_audible =
59 &GceAudioPolicy::SetCanMuteEnforcedAudible;
60 dap->policy.init_check = &GceAudioPolicy::InitCheck;
61 dap->policy.get_output = &GceAudioPolicy::GetOutput;
62 dap->policy.start_output = &GceAudioPolicy::StartOutput;
63 dap->policy.stop_output = &GceAudioPolicy::StopOutput;
64 dap->policy.release_output = &GceAudioPolicy::ReleaseOutput;
65 dap->policy.get_input = &GceAudioPolicy::GetInput;
66 dap->policy.start_input = &GceAudioPolicy::StartInput;
67 dap->policy.stop_input = &GceAudioPolicy::StopInput;
68 dap->policy.release_input = &GceAudioPolicy::ReleaseInput;
69 dap->policy.init_stream_volume = &GceAudioPolicy::InitStreamVolume;
70 dap->policy.set_stream_volume_index = &GceAudioPolicy::SetStreamVolumeIndex;
71 dap->policy.get_stream_volume_index = &GceAudioPolicy::GetStreamVolumeIndex;
72 dap->policy.set_stream_volume_index_for_device =
73 &GceAudioPolicy::SetStreamVolumeIndexForDevice;
74 dap->policy.get_stream_volume_index_for_device =
75 &GceAudioPolicy::GetStreamVolumeIndexForDevice;
76 dap->policy.get_strategy_for_stream = &GceAudioPolicy::GetStrategyForStream;
77 dap->policy.get_devices_for_stream = &GceAudioPolicy::GetDevicesForStream;
78 dap->policy.get_output_for_effect = &GceAudioPolicy::GetOutputForEffect;
79 dap->policy.register_effect = &GceAudioPolicy::RegisterEffect;
80 dap->policy.unregister_effect = &GceAudioPolicy::UnregisterEffect;
81 dap->policy.set_effect_enabled = &GceAudioPolicy::SetEffectEnabled;
82 dap->policy.is_stream_active = &GceAudioPolicy::IsStreamActive;
83 dap->policy.dump = &GceAudioPolicy::Dump;
84#ifdef ENABLE_OFFLOAD
85 dap->policy.is_offload_supported = &GceAudioPolicy::IsOffloadSupported;
86#endif
87
88 dap->service = service;
89 dap->aps_ops = aps_ops;
90
91 *ap = &dap->policy;
92 return 0;
93}
94
95
96int GceAudioPolicy::Destroy(const audio_policy_device* ap_dev,
97 audio_policy* ap) {
98 D("%s", __FUNCTION__);
99 free(ap);
100 return 0;
101}
102
103
104int GceAudioPolicy::Close(hw_device_t* device) {
105 D("%s", __FUNCTION__);
106 free(device);
107 return 0;
108}
109
110
111int GceAudioPolicy::Open(
112 const hw_module_t* module, const char* name, hw_device_t** device) {
113 D("%s", __FUNCTION__);
114 audio_policy_device* dev;
115
116 *device = NULL;
117
118 if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0) {
119 return -EINVAL;
120 }
121
122 dev = (audio_policy_device*) calloc(1, sizeof(*dev));
123 if (!dev) {
124 return -ENOMEM;
125 }
126
127 dev->common.tag = HARDWARE_DEVICE_TAG;
128 dev->common.version = 0;
129 dev->common.module = (hw_module_t*) module;
130 dev->common.close = &GceAudioPolicy::Close;
131 dev->create_audio_policy = &GceAudioPolicy::Create;
132 dev->destroy_audio_policy = &GceAudioPolicy::Destroy;
133
134 *device = &dev->common;
135
136 return 0;
137}
138
139}
140
141static hw_module_methods_t gce_audio_policy_module_methods = {
142 .open = &cvd::GceAudioPolicy::Open,
143};
144
145
146audio_policy_module HAL_MODULE_INFO_SYM = {
147 .common = {
148 .tag = HARDWARE_MODULE_TAG,
149 .version_major = 1,
150 .version_minor = 0,
151 .id = AUDIO_POLICY_HARDWARE_MODULE_ID,
152 .name = "GCE Audio Policy HAL",
153 .author = "The Android Open Source Project",
154 .methods = &gce_audio_policy_module_methods,
155 },
156};