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 bool AddParamsToJson(DHItem &dhItem, cJSON* infoJson, const std::string &subtype, const AudioInfo &infos); 56 std::vector<DHItem> RealQuery(const std::string &dataType); 57 bool IsMimeSupported(const std::string &coder); 58 void AddToVec(std::vector<std::string> &container, const std::string &value); 59 private: 60 AudioInfo spkInfos_; 61 AudioInfo micInfos_; 62 std::vector<std::string> supportedStream_; 63 std::vector<std::string> codec_; 64 std::shared_ptr<PluginListener> listener_ = nullptr; 65 }; 66 67 #ifdef __cplusplus 68 extern "C" { 69 #endif 70 __attribute__((visibility("default"))) IHardwareHandler *GetHardwareHandler(); 71 #ifdef __cplusplus 72 } 73 #endif 74 } // DistributedHardware 75 } // OHOS 76 #endif // OHOS_DAUDIO_HANDLER_H 77