1 /* 2 * Copyright (c) 2022-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 OHOS_DAUDIO_HDI_HANDLER_H 17 #define OHOS_DAUDIO_HDI_HANDLER_H 18 19 #include <map> 20 #include <mutex> 21 #include <set> 22 23 #include <v2_1/id_audio_callback.h> 24 #include <v2_1/id_audio_manager.h> 25 #include "iremote_object.h" 26 27 #include "audio_event.h" 28 #include "daudio_manager_callback.h" 29 #include "distributed_hardware_fwk_kit.h" 30 #include "idaudio_hdi_callback.h" 31 #include "single_instance.h" 32 33 namespace OHOS { 34 namespace DistributedHardware { 35 using OHOS::HDI::DistributedAudio::Audioext::V2_1::DAudioEvent; 36 using OHOS::HDI::DistributedAudio::Audioext::V2_1::IDAudioCallback; 37 using OHOS::HDI::DistributedAudio::Audioext::V2_1::IDAudioManager; 38 class DAudioHdiHandler { 39 DECLARE_SINGLE_INSTANCE_BASE(DAudioHdiHandler); 40 41 public: 42 int32_t InitHdiHandler(); 43 44 int32_t UninitHdiHandler(); 45 46 int32_t RegisterAudioDevice(const std::string &devId, const int32_t dhId, const std::string &capability, 47 const std::shared_ptr<IDAudioHdiCallback> &callbackObjParam); 48 49 int32_t UnRegisterAudioDevice(const std::string &devId, const int32_t dhId); 50 51 int32_t NotifyEvent(const std::string &devId, const int32_t dhId, 52 const int32_t streamId, const AudioEvent &audioEvent); 53 54 private: 55 DAudioHdiHandler(); 56 ~DAudioHdiHandler(); 57 void ProcessEventMsg(const AudioEvent &audioEvent, DAudioEvent &newEvent); 58 std::shared_ptr<DistributedHardwareFwkKit> GetDHFwkKit(); 59 60 class AudioHdiRecipient : public IRemoteObject::DeathRecipient { 61 public: 62 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 63 }; 64 sptr<AudioHdiRecipient> audioHdiRecipient_; 65 66 const std::string HDF_AUDIO_SERVICE_NAME = "daudio_ext_service"; 67 std::mutex devMapMtx_; 68 sptr<IDAudioManager> audioSrvHdf_; 69 std::map<std::string, sptr<DAudioManagerCallback>> mapAudioMgrCallback_; 70 std::map<std::string, std::set<int32_t>> mapAudioMgrDhIds_; 71 sptr<IRemoteObject> remote_; 72 std::shared_ptr<DistributedHardwareFwkKit> dHFwkKit_; 73 std::mutex dHFwkKitMutex_; 74 }; 75 } // DistributedHardware 76 } // OHOS 77 #endif // OHOS_DAUDIO_HDI_HANDLER_H 78