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_param_callback_internal.h"
17
18 #include <string>
19
20 #include <v1_0/iaudio_callback.h>
21 #include <v1_0/audio_types.h>
22
23 #include "daudio_errorcode.h"
24
25 #define HDF_LOG_TAG HDF_AUDIO
26 namespace OHOS {
27 namespace DistributedHardware {
28 using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback;
29 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCallbackType;
30 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey;
31
32 class AudioParamCallbackImpl final : public IAudioCallback {
33 public:
AudioParamCallbackImpl(::ParamCallback callback,void * cookie)34 AudioParamCallbackImpl(::ParamCallback callback, void *cookie) : callback_(callback), cookie_(cookie) {}
~AudioParamCallbackImpl()35 ~AudioParamCallbackImpl() override {}
36
37 int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override;
38 int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value,
39 int8_t &reserved, int8_t cookie) override;
40 private:
41 ::ParamCallback callback_ = nullptr;
42 void *cookie_ = nullptr;
43 };
44
AudioParamCallbackContext(::ParamCallback callback,void * cookie)45 AudioParamCallbackContext::AudioParamCallbackContext(::ParamCallback callback, void *cookie)
46 {
47 callbackStub_ = new AudioParamCallbackImpl(callback, cookie);
48 }
49
RenderCallback(AudioCallbackType type,int8_t & reserved,int8_t & cookie)50 int32_t AudioParamCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie)
51 {
52 (void) type;
53 (void) reserved;
54 (void) cookie;
55 return DH_SUCCESS;
56 }
57
ParamCallback(AudioExtParamKey key,const std::string & condition,const std::string & value,int8_t & reserved,int8_t cookie)58 int32_t AudioParamCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition,
59 const std::string& value, int8_t &reserved, int8_t cookie)
60 {
61 (void) cookie;
62 if (callback_ != nullptr) {
63 callback_(static_cast<::AudioExtParamKey>(key), condition.c_str(),
64 value.c_str(), static_cast<void *>(&reserved), cookie_);
65 return DH_SUCCESS;
66 } else {
67 return ERR_DH_AUDIO_HDI_CALL_FAILED;
68 }
69 }
70 } // namespace DistributedHardware
71 } // namespace OHOS