forked from ubports/audioflingerglue
-
Notifications
You must be signed in to change notification settings - Fork 2
/
audioflingerglue.cpp
131 lines (106 loc) · 3.12 KB
/
audioflingerglue.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2015 Jolla Ltd.
*
* 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.
*
* Authored by: Juho Hämäläinen <juho.hamalainen@jolla.com>
*/
#define LOG_TAG "AfGlue"
#include <android/log.h>
#include "audioflingerglue.h"
#include <utils/String8.h>
#include <binder/IBinder.h>
#include <binder/BinderService.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <media/AudioParameter.h>
#include "IPrivateAfGlue.h"
#include "IPrivateAfGlueHandler.h"
#include "common.h"
using namespace android;
extern "C" {
struct _DroidAfGlue
{
_DroidAfGlue() :
m_cb_data(0)
{
memset(&m_cb, 0x0, sizeof(m_cb));
}
sp<IPrivateAfGlue> m_af;
DroidAfGlueCallbacks m_cb;
void *m_cb_data;
};
class GlueHandler : public BinderService<GlueHandler>,
public BnPrivateAfGlueHandler
{
public:
GlueHandler(DroidAfGlue *glue) :
BnPrivateAfGlueHandler(),
m_glue(glue)
{
}
~GlueHandler()
{
}
virtual status_t handleSetParameters(audio_io_handle_t ioHandle,
const String8 &keyValuePairs)
{
if (!m_glue)
return NO_ERROR;
return m_glue->m_cb.set_parameters(keyValuePairs.string(), m_glue->m_cb_data);
}
virtual String8 handleGetParameters(audio_io_handle_t ioHandle,
const String8 &keys) const
{
if (!m_glue)
return String8("");
char *r = 0;
if (m_glue->m_cb.get_parameters(keys.string(), &r, m_glue->m_cb_data) == NO_ERROR) {
String8 reply(r);
free(r);
return reply;
}
return String8("");
}
private:
DroidAfGlue *m_glue;
};
DroidAfGlue *droid_afglue_connect(DroidAfGlueCallbacks *cb, void *userdata)
{
sp<IPrivateAfGlue> af;
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
binder = sm->getService(String16(DROID_AFGLUE_SERVICE_NAME));
if (binder == 0) {
ALOGE("Couldn't find %s service", DROID_AFGLUE_SERVICE_NAME);
return NULL;
}
af = interface_cast<IPrivateAfGlue>(binder);
DroidAfGlue *glue = new DroidAfGlue;
if (!glue) {
ALOGE("Failed to allocate DroidAfGlue");
return NULL;
}
memcpy(&glue->m_cb, cb, sizeof(glue->m_cb));
glue->m_cb_data = userdata;
glue->m_af = af;
glue->m_af->registerHandler(new GlueHandler(glue));
ProcessState::self()->startThreadPool();
return glue;
}
void droid_afglue_disconnect(DroidAfGlue *glue)
{
glue->m_af->registerHandler(0);
delete glue;
}
};