1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "daudio_adapter_internal.h"
17
18 #include <securec.h>
19 #include <string>
20
21 #include <v1_0/iaudio_render.h>
22 #include <v1_0/iaudio_capture.h>
23 #include <v1_0/audio_types.h>
24
25 #include "daudio_errorcode.h"
26 #include "daudio_log.h"
27
28 #undef DH_LOG_TAG
29 #define DH_LOG_TAG "DAudioAdapterInternal"
30
31 namespace OHOS {
32 namespace DistributedHardware {
33 using namespace OHOS::HDI::DistributedAudio::Audio::V1_0;
34
InitAllPortsInternal(struct AudioAdapter * adapter)35 static int32_t InitAllPortsInternal(struct AudioAdapter *adapter)
36 {
37 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
38 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
39 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
40 return context->proxy_->InitAllPorts();
41 }
42
SetAudioSampleAttributesHAL(const struct::AudioSampleAttributes * attrs,AudioSampleAttributes & attrsHal)43 static void SetAudioSampleAttributesHAL(const struct ::AudioSampleAttributes *attrs,
44 AudioSampleAttributes &attrsHal)
45 {
46 attrsHal.type = static_cast<AudioCategory>(attrs->type);
47 attrsHal.interleaved = attrs->interleaved;
48 attrsHal.format = static_cast<AudioFormat>(attrs->format);
49 attrsHal.sampleRate = attrs->sampleRate;
50 attrsHal.channelCount = attrs->channelCount;
51 attrsHal.period = attrs->period;
52 attrsHal.frameSize = attrs->frameSize;
53 attrsHal.isBigEndian = attrs->isBigEndian;
54 attrsHal.isSignedData = attrs->isSignedData;
55 attrsHal.startThreshold = attrs->startThreshold;
56 attrsHal.stopThreshold = attrs->stopThreshold;
57 attrsHal.silenceThreshold = attrs->silenceThreshold;
58 attrsHal.streamId = attrs->streamId;
59 }
60
CreateRenderInternal(struct AudioAdapter * adapter,const struct::AudioDeviceDescriptor * desc,const struct::AudioSampleAttributes * attrs,struct AudioRender ** render)61 static int32_t CreateRenderInternal(struct AudioAdapter *adapter, const struct ::AudioDeviceDescriptor *desc,
62 const struct ::AudioSampleAttributes *attrs, struct AudioRender **render)
63 {
64 DHLOGI("Create distributed audio render.");
65 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
66 CHECK_NULL_RETURN(desc, ERR_DH_AUDIO_HDI_INVALID_PARAM);
67 CHECK_NULL_RETURN(attrs, ERR_DH_AUDIO_HDI_INVALID_PARAM);
68 CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM);
69
70 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
71 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
72 AudioDeviceDescriptor descHal = {
73 .portId = desc->portId,
74 .pins = static_cast<AudioPortPin>(desc->pins),
75 };
76 descHal.desc = desc->desc == nullptr ? "" : desc->desc;
77
78 AudioSampleAttributes attrsHal;
79 SetAudioSampleAttributesHAL(attrs, attrsHal);
80 sptr<IAudioRender> renderProxy = nullptr;
81 uint32_t renderId;
82 int32_t ret = context->proxy_->CreateRender(descHal, attrsHal, renderProxy, renderId);
83 if (ret != DH_SUCCESS) {
84 *render = nullptr;
85 return ret;
86 }
87 auto renderContext = std::make_unique<AudioRenderContext>();
88 *render = &renderContext->instance_;
89 renderContext->proxy_ = renderProxy;
90 renderContext->descHal_ = descHal;
91 DHLOGI("The render ID: %u.", renderId);
92 {
93 std::lock_guard<std::mutex> lock(context->mtx_);
94 context->renders_.push_back(std::make_pair(renderId, std::move(renderContext)));
95 }
96 return DH_SUCCESS;
97 }
98
DestroyRenderInternal(struct AudioAdapter * adapter,struct AudioRender * render)99 static int32_t DestroyRenderInternal(struct AudioAdapter *adapter, struct AudioRender *render)
100 {
101 DHLOGI("Destroy distributed audio render.");
102 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
103 CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM);
104 AudioAdapterContext *adapterContext = reinterpret_cast<AudioAdapterContext *>(adapter);
105 AudioRenderContext *renderContext = reinterpret_cast<AudioRenderContext *>(render);
106 CHECK_NULL_RETURN(adapterContext->proxy_, ERR_DH_AUDIO_NULLPTR);
107
108 std::lock_guard<std::mutex> lock(adapterContext->mtx_);
109 for (auto it = adapterContext->renders_.begin(); it != adapterContext->renders_.end(); ++it) {
110 if ((it->second).get() == renderContext) {
111 int32_t ret = adapterContext->proxy_->DestroyRender(it->first);
112 if (ret != DH_SUCCESS) {
113 return ret;
114 }
115 adapterContext->renders_.erase(it);
116 break;
117 }
118 }
119 return DH_SUCCESS;
120 }
121
CreateCaptureInternal(struct AudioAdapter * adapter,const struct::AudioDeviceDescriptor * desc,const struct::AudioSampleAttributes * attrs,struct AudioCapture ** capture)122 static int32_t CreateCaptureInternal(struct AudioAdapter *adapter, const struct ::AudioDeviceDescriptor *desc,
123 const struct ::AudioSampleAttributes *attrs, struct AudioCapture **capture)
124 {
125 DHLOGI("Create distributed audio capture.");
126 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
127 CHECK_NULL_RETURN(desc, ERR_DH_AUDIO_HDI_INVALID_PARAM);
128 CHECK_NULL_RETURN(attrs, ERR_DH_AUDIO_HDI_INVALID_PARAM);
129 CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM);
130 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
131 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
132
133 AudioDeviceDescriptor descHal = {
134 .portId = desc->portId,
135 .pins = static_cast<AudioPortPin>(desc->pins),
136 };
137 descHal.desc = desc->desc == nullptr ? "" : desc->desc;
138 AudioSampleAttributes attrsHal;
139 SetAudioSampleAttributesHAL(attrs, attrsHal);
140 sptr<IAudioCapture> captureProxy = nullptr;
141 uint32_t captureId;
142 int32_t ret = context->proxy_->CreateCapture(descHal, attrsHal, captureProxy, captureId);
143 if (ret != DH_SUCCESS) {
144 *capture = nullptr;
145 return ret;
146 }
147
148 auto captureContext = std::make_unique<AudioCaptureContext>();
149 *capture = &captureContext->instance_;
150 captureContext->proxy_ = captureProxy;
151 captureContext->descHal_ = descHal;
152 DHLOGI("The capture ID: %u.", captureId);
153 {
154 std::lock_guard<std::mutex> lock(context->mtx_);
155 context->captures_.push_back(std::make_pair(captureId, std::move(captureContext)));
156 }
157 return DH_SUCCESS;
158 }
159
DestroyCaptureInternal(struct AudioAdapter * adapter,struct AudioCapture * capture)160 static int32_t DestroyCaptureInternal(struct AudioAdapter *adapter, struct AudioCapture *capture)
161 {
162 DHLOGI("Destroy distributed audio capture.");
163 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
164 CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM);
165 AudioAdapterContext *adapterContext = reinterpret_cast<AudioAdapterContext *>(adapter);
166 AudioCaptureContext *captureContext = reinterpret_cast<AudioCaptureContext *>(capture);
167 CHECK_NULL_RETURN(adapterContext->proxy_, ERR_DH_AUDIO_NULLPTR);
168
169 std::lock_guard<std::mutex> lock(adapterContext->mtx_);
170 for (auto it = adapterContext->captures_.begin(); it != adapterContext->captures_.end(); ++it) {
171 if ((it->second).get() == captureContext) {
172 int32_t ret = adapterContext->proxy_->DestroyCapture(it->first);
173 if (ret != DH_SUCCESS) {
174 return ret;
175 }
176 adapterContext->captures_.erase(it);
177 break;
178 }
179 }
180 return DH_SUCCESS;
181 }
182
GetPassthroughModeInternal(struct AudioAdapter * adapter,const struct::AudioPort * port,enum::AudioPortPassthroughMode * mode)183 static int32_t GetPassthroughModeInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port,
184 enum ::AudioPortPassthroughMode *mode)
185 {
186 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
187 CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM);
188 CHECK_NULL_RETURN(mode, ERR_DH_AUDIO_HDI_INVALID_PARAM);
189 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
190 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
191
192 AudioPort portHal = {
193 .dir = static_cast<AudioPortDirection>(port->dir),
194 .portId = port->portId,
195 .portName= port->portName,
196 };
197 return context->proxy_->GetPassthroughMode(portHal, *(reinterpret_cast<AudioPortPassthroughMode *>(mode)));
198 }
199
InitAudioPortCapability(std::unique_ptr<::AudioPortCapability> & capInternal,AudioPortCapability & capabilityHal)200 static int32_t InitAudioPortCapability(std::unique_ptr<::AudioPortCapability> &capInternal,
201 AudioPortCapability &capabilityHal)
202 {
203 DHLOGI("Init audio port capability internal, formatNum: %zu.", capabilityHal.formatNum);
204 constexpr uint32_t maxFormatNum = 100;
205 constexpr uint32_t minFormatNum = 1;
206 if (capabilityHal.formatNum < minFormatNum || capabilityHal.formatNum > maxFormatNum) {
207 DHLOGE("Init audio port capability, formatNum: %zu.", capabilityHal.formatNum);
208 return ERR_DH_AUDIO_HDI_INVALID_PARAM;
209 }
210 ::AudioFormat *audioFormats = (::AudioFormat *)malloc(capabilityHal.formatNum * sizeof(::AudioFormat));
211 CHECK_NULL_RETURN(audioFormats, ERR_DH_AUDIO_HDI_CALL_FAILED);
212
213 capInternal->deviceType = capabilityHal.deviceType;
214 capInternal->deviceId = capabilityHal.deviceId;
215 capInternal->hardwareMode = static_cast<bool>(capabilityHal.hardwareMode);
216 capInternal->formatNum = capabilityHal.formatNum;
217 capInternal->formats = audioFormats;
218 for (auto format : capabilityHal.formats) {
219 *audioFormats = static_cast<::AudioFormat>(format);
220 audioFormats++;
221 }
222 capInternal->sampleRateMasks = capabilityHal.sampleRateMasks;
223 capInternal->channelMasks = static_cast<::AudioChannelMask>(capabilityHal.channelMasks);
224 capInternal->channelCount = capabilityHal.channelCount;
225 capInternal->subPortsNum = 0;
226 capInternal->subPorts = nullptr;
227 return DH_SUCCESS;
228 }
229
GetPortCapabilityInternal(struct AudioAdapter * adapter,const struct::AudioPort * port,struct::AudioPortCapability * capability)230 static int32_t GetPortCapabilityInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port,
231 struct ::AudioPortCapability *capability)
232 {
233 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
234 CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM);
235 CHECK_NULL_RETURN(port->portName, ERR_DH_AUDIO_HDI_INVALID_PARAM);
236 CHECK_NULL_RETURN(capability, ERR_DH_AUDIO_HDI_INVALID_PARAM);
237 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
238 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
239
240 {
241 std::lock_guard<std::mutex> lock(context->mtx_);
242 auto iter = context->caps_.find(port->portId);
243 if (iter != context->caps_.end()) {
244 *capability = *(iter->second);
245 return DH_SUCCESS;
246 }
247 }
248 AudioPort portHal = {
249 .dir = static_cast<AudioPortDirection>(port->dir),
250 .portId = port->portId,
251 .portName = port->portName,
252 };
253
254 AudioPortCapability capabilityHal;
255 int32_t ret = context->proxy_->GetPortCapability(portHal, capabilityHal);
256 if (ret != DH_SUCCESS) {
257 return ret;
258 }
259
260 auto capInternal = std::make_unique<::AudioPortCapability>();
261 ret = InitAudioPortCapability(capInternal, capabilityHal);
262 if (ret != DH_SUCCESS) {
263 return ret;
264 }
265 *capability = *capInternal;
266 {
267 std::lock_guard<std::mutex> lock(context->mtx_);
268 context->caps_[port->portId] = std::move(capInternal);
269 }
270 return DH_SUCCESS;
271 }
272
ReleaseAudioRouteInternal(struct AudioAdapter * adapter,int32_t routeHandle)273 static int32_t ReleaseAudioRouteInternal(struct AudioAdapter *adapter, int32_t routeHandle)
274 {
275 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
276 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
277 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
278 return context->proxy_->ReleaseAudioRoute(routeHandle);
279 }
280
SetPassthroughModeInternal(struct AudioAdapter * adapter,const struct::AudioPort * port,enum::AudioPortPassthroughMode mode)281 static int32_t SetPassthroughModeInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port,
282 enum ::AudioPortPassthroughMode mode)
283 {
284 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
285 CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM);
286 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
287 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
288
289 AudioPort portHal = {
290 .dir = static_cast<AudioPortDirection>(port->dir),
291 .portId = port->portId,
292 .portName = port->portName,
293 };
294 AudioPortPassthroughMode modeHal = static_cast<AudioPortPassthroughMode>(static_cast<int32_t>(mode));
295 return context->proxy_->SetPassthroughMode(portHal, modeHal);
296 }
297
ConvertAudioRouteNodeToHAL(const::AudioRouteNode & node,AudioRouteNode & halNode)298 static void ConvertAudioRouteNodeToHAL(const ::AudioRouteNode &node, AudioRouteNode &halNode)
299 {
300 halNode.portId = node.portId;
301 halNode.role = static_cast<AudioPortRole>(node.role);
302 halNode.type = static_cast<AudioPortType>(node.type);
303 DHLOGD("Convert audio route node To HAL, portId: %d role: %d type: %d.", halNode.portId, halNode.role,
304 halNode.type);
305
306 switch (node.type) {
307 case AUDIO_PORT_UNASSIGNED_TYPE:
308 break;
309 case AUDIO_PORT_DEVICE_TYPE: {
310 size_t descLength = DESCRIPTOR_LENGTH;
311 halNode.ext.device.moduleId = node.ext.device.moduleId;
312 halNode.ext.device.type = static_cast<AudioPortPin>(node.ext.device.type);
313 if (node.ext.device.desc != nullptr) {
314 size_t length = strlen(node.ext.device.desc);
315 length = length < descLength ? length : descLength;
316 halNode.ext.device.desc = std::string(node.ext.device.desc, node.ext.device.desc + length);
317 }
318 break;
319 }
320 case AUDIO_PORT_MIX_TYPE: {
321 halNode.ext.mix.moduleId = node.ext.mix.moduleId;
322 halNode.ext.mix.streamId = node.ext.mix.streamId;
323
324 DHLOGD("Convert audio route node To HAL, [Mix] moduleId: %d streamId: %d.",
325 halNode.ext.mix.moduleId, halNode.ext.mix.streamId);
326 break;
327 }
328 case AUDIO_PORT_SESSION_TYPE: {
329 halNode.ext.session.sessionType = static_cast<AudioSessionType>(node.ext.session.sessionType);
330 DHLOGD("Convert audio route node To HAL, [Session] sessionType: %d.", halNode.ext.session.sessionType);
331 break;
332 }
333 default :
334 DHLOGD("Unknown node Type");
335 }
336 }
UpdateAudioRouteInternal(struct AudioAdapter * adapter,const struct::AudioRoute * route,int32_t * routeHandle)337 static int32_t UpdateAudioRouteInternal(struct AudioAdapter *adapter, const struct ::AudioRoute *route,
338 int32_t *routeHandle)
339 {
340 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
341 CHECK_NULL_RETURN(route, ERR_DH_AUDIO_HDI_INVALID_PARAM);
342 CHECK_NULL_RETURN(routeHandle, ERR_DH_AUDIO_HDI_INVALID_PARAM);
343 AudioRoute audioRoute;
344 for (uint32_t i = 0; i < route->sourcesNum; ++i) {
345 AudioRouteNode halNode = {0};
346 ConvertAudioRouteNodeToHAL(route->sources[i], halNode);
347 audioRoute.sources.push_back(halNode);
348 }
349
350 for (uint32_t i = 0; i < route->sinksNum; ++i) {
351 AudioRouteNode halNode = {0};
352 ConvertAudioRouteNodeToHAL(route->sinks[i], halNode);
353 audioRoute.sinks.push_back(halNode);
354 }
355
356 int32_t handle = -1;
357 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
358 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
359 int32_t ret = context->proxy_->UpdateAudioRoute(audioRoute, handle);
360 *routeHandle = handle;
361 return ret;
362 }
363
SetExtraParamsInternal(struct AudioAdapter * adapter,enum::AudioExtParamKey key,const char * condition,const char * value)364 static int32_t SetExtraParamsInternal(struct AudioAdapter *adapter, enum ::AudioExtParamKey key,
365 const char *condition, const char *value)
366 {
367 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
368 CHECK_NULL_RETURN(condition, ERR_DH_AUDIO_HDI_INVALID_PARAM);
369 CHECK_NULL_RETURN(value, ERR_DH_AUDIO_HDI_INVALID_PARAM);
370
371 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
372 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
373 return context->proxy_->SetExtraParams(static_cast<AudioExtParamKey>(key),
374 std::string(condition), std::string(value));
375 }
376
GetExtraParamsInternal(struct AudioAdapter * adapter,enum::AudioExtParamKey key,const char * condition,char * value,int32_t length)377 static int32_t GetExtraParamsInternal(struct AudioAdapter *adapter, enum ::AudioExtParamKey key,
378 const char *condition, char *value, int32_t length)
379 {
380 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
381 CHECK_NULL_RETURN(condition, ERR_DH_AUDIO_HDI_INVALID_PARAM);
382 CHECK_NULL_RETURN(value, ERR_DH_AUDIO_HDI_INVALID_PARAM);
383 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
384 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
385
386 std::string valueHal;
387 int32_t ret =
388 context->proxy_->GetExtraParams(static_cast<AudioExtParamKey>(key),
389 std::string(condition), valueHal);
390 if (ret != DH_SUCCESS) {
391 return ret;
392 }
393 ret = strcpy_s(value, length, valueHal.c_str());
394 if (ret != EOK) {
395 DHLOGE("Strcpy_s failed!, ret: %d", ret);
396 return ERR_DH_AUDIO_HDI_CALL_FAILED;
397 }
398 return DH_SUCCESS;
399 }
400
RegExtraParamObserverInternal(struct AudioAdapter * adapter,ParamCallback callback,void * cookie)401 static int32_t RegExtraParamObserverInternal(struct AudioAdapter *adapter, ParamCallback callback, void* cookie)
402 {
403 CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM);
404 CHECK_NULL_RETURN(callback, ERR_DH_AUDIO_HDI_INVALID_PARAM);
405 AudioAdapterContext *context = reinterpret_cast<AudioAdapterContext *>(adapter);
406 CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR);
407
408 std::lock_guard<std::mutex> lock(context->mtx_);
409 if (context->callbackInternal_ == nullptr || callback != context->callback_) {
410 context->callbackInternal_ = std::make_unique<AudioParamCallbackContext>(callback, cookie);
411 } else {
412 return DH_SUCCESS;
413 }
414
415 if (context->callbackInternal_->callbackStub_ == nullptr) {
416 context->callbackInternal_ = nullptr;
417 return ERR_DH_AUDIO_HDI_CALL_FAILED;
418 }
419
420 int32_t ret = context->proxy_->RegExtraParamObserver(context->callbackInternal_->callbackStub_, 0);
421 if (ret == DH_SUCCESS) {
422 context->callback_ = callback;
423 } else {
424 context->callbackInternal_ = nullptr;
425 }
426
427 return ret;
428 }
429
AudioAdapterContext()430 AudioAdapterContext::AudioAdapterContext()
431 {
432 instance_.InitAllPorts = InitAllPortsInternal;
433 instance_.CreateRender = CreateRenderInternal;
434 instance_.DestroyRender = DestroyRenderInternal;
435 instance_.CreateCapture = CreateCaptureInternal;
436 instance_.DestroyCapture = DestroyCaptureInternal;
437 instance_.GetPassthroughMode = GetPassthroughModeInternal;
438 instance_.GetPortCapability = GetPortCapabilityInternal;
439 instance_.ReleaseAudioRoute = ReleaseAudioRouteInternal;
440 instance_.SetPassthroughMode = SetPassthroughModeInternal;
441 instance_.UpdateAudioRoute = UpdateAudioRouteInternal;
442 instance_.SetExtraParams = SetExtraParamsInternal;
443 instance_.GetExtraParams = GetExtraParamsInternal;
444 instance_.RegExtraParamObserver = RegExtraParamObserverInternal;
445
446 instance_.SetVoiceVolume = nullptr;
447 instance_.GetMicMute = nullptr;
448 instance_.SetMicMute = nullptr;
449 instance_.GetDeviceStatus = nullptr;
450 }
451
~AudioAdapterContext()452 AudioAdapterContext::~AudioAdapterContext()
453 {
454 captures_.clear();
455 renders_.clear();
456 for (auto &cap : caps_) {
457 if (cap.second->formats != nullptr) {
458 free(cap.second->formats);
459 }
460 }
461 caps_.clear();
462 }
463 } // namespace DistributedHardware
464 } // namespace OHOS
465