• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 };
AudioParamCallbackContext(::ParamCallback callback,void * cookie)44 AudioParamCallbackContext::AudioParamCallbackContext(::ParamCallback callback, void *cookie)
45 {
46     callbackStub_ = new AudioParamCallbackImpl(callback, cookie);
47 }
48 
RenderCallback(AudioCallbackType type,int8_t & reserved,int8_t & cookie)49 int32_t AudioParamCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie)
50 {
51     (void) type;
52     (void) reserved;
53     (void) cookie;
54     return DH_SUCCESS;
55 }
56 
ParamCallback(AudioExtParamKey key,const std::string & condition,const std::string & value,int8_t & reserved,int8_t & cookie)57 int32_t AudioParamCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition,
58     const std::string& value, int8_t &reserved, int8_t &cookie)
59 {
60     (void) cookie;
61     if (callback_ != nullptr) {
62         callback_(static_cast<::AudioExtParamKey>(key), condition.c_str(),
63             value.c_str(), static_cast<void *>(&reserved), cookie_);
64         return DH_SUCCESS;
65     } else {
66         return ERR_DH_AUDIO_HDI_CALL_FAILED;
67     }
68 }
69 } // namespace DistributedHardware
70 } // namespace OHOS