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 #ifndef OHOS_DAUDIO_HANDLER_H
17 #define OHOS_DAUDIO_HANDLER_H
18 
19 #include <set>
20 #include "cJSON.h"
21 
22 #include "ihardware_handler.h"
23 #include "single_instance.h"
24 #include "audio_param.h"
25 #include "audio_capturer.h"
26 #include "audio_info.h"
27 #include "audio_renderer.h"
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 typedef struct {
32     std::vector<AudioStandard::AudioSamplingRate> sampleRates;
33     std::vector<AudioStandard::AudioChannel> channels;
34     std::vector<AudioStandard::AudioSampleFormat> formats;
35 } AudioInfo;
36 
37 class DAudioHandler : public IHardwareHandler {
38 DECLARE_SINGLE_INSTANCE_BASE(DAudioHandler);
39 
40 public:
41     int32_t Initialize() override;
42     std::vector<DHItem> QueryMeta() override;
43     std::vector<DHItem> Query() override;
44     std::map<std::string, std::string> QueryExtraInfo() override;
45     bool IsSupportPlugin() override;
46     void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
47     void UnRegisterPluginListener() override;
48     std::vector<DHItem> ablityForDump();
49     std::vector<DHItem> ablityForDumpVec_;
50 private:
51     DAudioHandler();
52     ~DAudioHandler();
53     int32_t QueryAudioInfo();
54     bool AddItemsToObject(DHItem &dhItem, cJSON *infoJson, const int32_t &dhId);
55     std::vector<DHItem> RealQuery(const std::string &dataType);
56 private:
57     AudioInfo spkInfos_;
58     AudioInfo micInfos_;
59     std::shared_ptr<PluginListener> listener_ = nullptr;
60 };
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 __attribute__((visibility("default"))) IHardwareHandler *GetHardwareHandler();
66 #ifdef __cplusplus
67 }
68 #endif
69 } // DistributedHardware
70 } // OHOS
71 #endif // OHOS_DAUDIO_HANDLER_H
72