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