• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef CALLBACK_WRAPPER_H
17 #define CALLBACK_WRAPPER_H
18 
19 #include <iostream>
20 #include <vector>
21 #include <mutex>
22 #include "sink/i_audio_render_sink.h"
23 #include "source/i_audio_capture_source.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 class SinkCallbackWrapper : public IAudioSinkCallback {
28 public:
29     SinkCallbackWrapper() = default;
30     ~SinkCallbackWrapper() = default;
31 
32     void RegistCallback(uint32_t type, std::shared_ptr<IAudioSinkCallback> cb);
33     void RegistCallback(uint32_t type, IAudioSinkCallback *cb);
34     std::shared_ptr<IAudioSinkCallback> GetCallback(uint32_t type);
35     IAudioSinkCallback *GetRawCallback(uint32_t type);
36 
37     void OnRenderSinkParamChange(const std::string &networkId, const AudioParamKey key,
38         const std::string &condition, const std::string &value) override;
39     void OnRenderSinkStateChange(uint32_t uniqueId, bool started) override;
40 
41 private:
42     std::unordered_map<uint32_t, std::shared_ptr<IAudioSinkCallback> > cbs_;
43     std::unordered_map<uint32_t, IAudioSinkCallback *> rawCbs_;
44     std::mutex cbMtx_;
45     std::mutex rawCbMtx_;
46 };
47 
48 class SourceCallbackWrapper : public IAudioSourceCallback {
49 public:
50     SourceCallbackWrapper() = default;
51     ~SourceCallbackWrapper() = default;
52 
53     void RegistCallback(uint32_t type, std::shared_ptr<IAudioSourceCallback> cb);
54     void RegistCallback(uint32_t type, IAudioSourceCallback *cb);
55     std::shared_ptr<IAudioSourceCallback> GetCallback(uint32_t type);
56     IAudioSourceCallback *GetRawCallback(uint32_t type);
57 
58     void OnCaptureSourceParamChange(const std::string &networkId, const AudioParamKey key,
59         const std::string &condition, const std::string &value) override;
60     void OnCaptureState(bool isActive) override;
61     void OnWakeupClose(void) override;
62 
63 private:
64     std::unordered_map<uint32_t, std::shared_ptr<IAudioSourceCallback> > cbs_;
65     std::unordered_map<uint32_t, IAudioSourceCallback *> rawCbs_;
66     std::mutex cbMtx_;
67     std::mutex rawCbMtx_;
68 };
69 
70 } // namespace AudioStandard
71 } // namespace OHOS
72 
73 #endif // CALLBACK_WRAPPER_H
74