diff --git a/common/include/daudio_ipc_interface_code.h b/common/include/daudio_ipc_interface_code.h index 93cee7c86fb04d8ae7ab24b29d8d8d78bfdc7aa5..a18c0683f1ed76a4d4ec572c97dbc6f6363a1d84 100644 --- a/common/include/daudio_ipc_interface_code.h +++ b/common/include/daudio_ipc_interface_code.h @@ -37,6 +37,9 @@ enum class IDAudioSinkInterfaceCode : uint32_t { SUBSCRIBE_LOCAL_HARDWARE = 2, UNSUBSCRIBE_LOCAL_HARDWARE = 3, DAUDIO_NOTIFY = 4, + PAUSE_DISTRIBUTED_HARDWARE = 5, + RESUME_DISTRIBUTED_HARDWARE = 6, + STOP_DISTRIBUTED_HARDWARE = 7, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 0e55bae2fff081d60ffd300675818601187054c4..b6582433330623634a7b23c75df2c78e50c03b08 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -39,6 +39,8 @@ ohos_shared_library("distributed_audio_sink_sdk") { sources = [ "src/daudio_sink_handler.cpp", + "src/daudio_sink_ipc_callback_stub.cpp", + "src/daudio_sink_ipc_callback.cpp", "src/daudio_sink_load_callback.cpp", "src/daudio_sink_proxy.cpp", ] diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_handler.h b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_handler.h index ab4725cefa09a94b33e126f7829709e430593ff1..aefab2d7826a5ea1a7fb8fd9e908f700a09b8bc6 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_handler.h +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #define OHOS_DAUDIO_SINK_HANDLER_H #include "idistributed_hardware_sink.h" +#include "daudio_sink_ipc_callback.h" #include "single_instance.h" #include "idaudio_sink.h" @@ -32,6 +33,10 @@ public: int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void OnRemoteSinkSvrDied(const wptr &remote); void FinishStartSA(const std::string ¶m, const sptr &remoteObject); + int32_t RegisterPrivacyResources(std::shared_ptr listener) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; private: class DAudioSinkSvrRecipient : public IRemoteObject::DeathRecipient { @@ -46,6 +51,7 @@ private: std::condition_variable sinkProxyConVar_; sptr dAudioSinkProxy_ = nullptr; sptr sinkSvrRecipient_ = nullptr; + sptr dAudioSinkIpcCallback_ = nullptr; }; #ifdef __cplusplus diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback.h b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..da6bdc96a8e7ad38ff7754290c75d9ca002961eb --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DAUDIO_SINK_IPC_CALLBACK_H +#define OHOS_DAUDIO_SINK_IPC_CALLBACK_H + +#include +#include + +#include "daudio_sink_ipc_callback_stub.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class DAudioSinkIpcCallback : public DAudioSinkIpcCallbackStub { +public: + DAudioSinkIpcCallback() = default; + ~DAudioSinkIpcCallback() override = default; + + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; + void PushPrivacyResCallback(const std::shared_ptr &listener); + +private: + std::mutex privacyResMtx_; + std::vector> privacyResCallback_; +}; +} // DistributedHardware +} // OHOS +#endif // OHOS_DAUDIO_SINK_IPC_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback_stub.h b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..a983385104a34d048175e6d3fec9fb4690782d3e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_ipc_callback_stub.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DAUDIO_SINK_IPC_CALLBACK_STUB_H +#define OHOS_DAUDIO_SINK_IPC_CALLBACK_STUB_H + +#include + +#include "idaudio_sink_ipc_callback.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class DAudioSinkIpcCallbackStub : public IRemoteStub { +public: + DAudioSinkIpcCallbackStub(); + virtual ~DAudioSinkIpcCallbackStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); + + using DAudioSinkCallbackFunc = int32_t (DAudioSinkIpcCallbackStub::*)(MessageParcel &data, MessageParcel &reply, + MessageOption &option); + std::map memberFuncMap_; +}; +} // DistributedHardware +} // OHOS +#endif // OHOS_DAUDIO_SINK_IPC_CALLBACK_STUB_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_proxy.h b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_proxy.h index 5734ddba01c476fb74b996be25161400f5fc5414..027c76cf4fe31c040d54ec3bfe5040d30db04f2b 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_proxy.h +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/daudio_sink_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,12 +28,15 @@ public: explicit DAudioSinkProxy(const sptr impl) : IRemoteProxy(impl) {} ~DAudioSinkProxy() = default; - int32_t InitSink(const std::string ¶ms) override; + int32_t InitSink(const std::string ¶ms, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, const std::string &eventContent) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; private: static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink.h index ba07a29283dd120f81149add2cd432c172f81609..b6021b22bc31811fc00ab2b3e50b825e5ee7109d 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink.h +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink.h @@ -16,6 +16,7 @@ #ifndef OHOS_IDAUDIO_SINK_H #define OHOS_IDAUDIO_SINK_H +#include "idaudio_sink_ipc_callback.h" #include "iremote_broker.h" namespace OHOS { @@ -25,12 +26,15 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.distributedaudiosink"); ~IDAudioSink() override = default; - virtual int32_t InitSink(const std::string ¶ms) = 0; + virtual int32_t InitSink(const std::string ¶ms, const sptr &sinkCallback) = 0; virtual int32_t ReleaseSink() = 0; virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) = 0; virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0; virtual void DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, const std::string &eventContent) = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; }; } // DistributedHardware } // OHOS diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink_ipc_callback.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink_ipc_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..15974dfad3a53706a191e488be05d987243876da --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/idaudio_sink_ipc_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDAUDIO_SINK_IPC_CALLBACK_H +#define OHOS_IDAUDIO_SINK_IPC_CALLBACK_H + +#include "iremote_broker.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class IDAudioSinkIpcCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.distributedaudiosinkipccallback"); + enum { + NOTIFY_RESOURCEINFO = 0, + }; + + ~IDAudioSinkIpcCallback() override {} + virtual int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; +}; +} // DistributedHardware +} // OHOS +#endif // OHOS_IDAUDIO_SINK_IPC_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp index 8361fa6a8d1f33d2d442a41a5511daa1903ba62d..dbf1ec1974737df968cd1e9c352a12f7c2857b4a 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp @@ -35,6 +35,9 @@ IMPLEMENT_SINGLE_INSTANCE(DAudioSinkHandler); DAudioSinkHandler::DAudioSinkHandler() { DHLOGD("DAudio sink handler constructed."); + if (!dAudioSinkIpcCallback_) { + dAudioSinkIpcCallback_ = new DAudioSinkIpcCallback(); + } } DAudioSinkHandler::~DAudioSinkHandler() @@ -148,7 +151,7 @@ void DAudioSinkHandler::FinishStartSA(const std::string ¶m, const sptrInitSink(param); + dAudioSinkProxy_->InitSink(param, dAudioSinkIpcCallback_); sinkProxyConVar_.notify_one(); DAudioHisysevent::GetInstance().SysEventWriteBehavior(DAUDIO_INIT, "daudio sink sa load success."); } @@ -163,5 +166,45 @@ IDistributedHardwareSink *GetSinkHardwareHandler() DHLOGD("Get sink hardware handler."); return &DAudioSinkHandler::GetInstance(); } + +int32_t DAudioSinkHandler::RegisterPrivacyResources(std::shared_ptr listener) +{ + DHLOGI("RegisterPrivacyResources start."); + dAudioSinkIpcCallback_->PushPrivacyResCallback(listener); + return DH_SUCCESS; +} + +int32_t DAudioSinkHandler::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("pause distributed hardware."); + std::lock_guard lock(sinkProxyMutex_); + if (dAudioSinkProxy_ == nullptr) { + DHLOGE("daudio sink proxy not init."); + return ERR_DH_AUDIO_SA_PROXY_NOT_INIT; + } + return dAudioSinkProxy_->PauseDistributedHardware(networkId); +} + +int32_t DAudioSinkHandler::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("resume distributed hardware."); + std::lock_guard lock(sinkProxyMutex_); + if (dAudioSinkProxy_ == nullptr) { + DHLOGE("daudio sink proxy not init."); + return ERR_DH_AUDIO_SA_PROXY_NOT_INIT; + } + return dAudioSinkProxy_->ResumeDistributedHardware(networkId); +} + +int32_t DAudioSinkHandler::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("stop distributed hardware."); + std::lock_guard lock(sinkProxyMutex_); + if (dAudioSinkProxy_ == nullptr) { + DHLOGE("daudio sink proxy not init."); + return ERR_DH_AUDIO_SA_PROXY_NOT_INIT; + } + return dAudioSinkProxy_->StopDistributedHardware(networkId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c3c00353e91ef032250cb311b3fe9e18a0661bb --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "daudio_sink_ipc_callback.h" + +#include "daudio_constants.h" +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "DAudioSinkIpcCallback" + +namespace OHOS { +namespace DistributedHardware { +int32_t DAudioSinkIpcCallback::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + DHLOGI("On notify the resource info, subType: %s, networkId: %s, isSensitive: %d, isSameAccout: %d", + subType.c_str(), networkId.c_str(), isSensitive, isSameAccout); + + int32_t ret = DH_SUCCESS; + std::lock_guard resourceLck(privacyResMtx_); + auto iter = privacyResCallback_.begin(); + if (iter != privacyResCallback_.end()) { + ret = (*iter)->OnPrivaceResouceMessage(type, subType, networkId, isSensitive, isSameAccout); + } + return ret; +} + +void DAudioSinkIpcCallback::PushPrivacyResCallback(const std::shared_ptr &callback) +{ + DHLOGD("Push resource info callback"); + std::lock_guard resourceLck(privacyResMtx_); + privacyResCallback_.push_back(callback); +} +} // DistributedHardware +} // OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3119c1ed1ccd78124e530c75c6df92adbaefc74d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "daudio_sink_ipc_callback_stub.h" + +#include "daudio_errorcode.h" +#include "daudio_log.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "DAudioSinkIpcCallbackStub" + +namespace OHOS { +namespace DistributedHardware { +DAudioSinkIpcCallbackStub::DAudioSinkIpcCallbackStub() +{ + memberFuncMap_[NOTIFY_RESOURCEINFO] = &DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner; +} + +int32_t DAudioSinkIpcCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + DHLOGI("On remote request, code: %u", code); + std::u16string desc = DAudioSinkIpcCallbackStub::GetDescriptor(); + std::u16string remoteDesc = data.ReadInterfaceToken(); + if (desc != remoteDesc) { + DHLOGE("RemoteDesc is invalid."); + return ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN; + } + + std::map::iterator iter = memberFuncMap_.find(code); + if (iter == memberFuncMap_.end()) { + DHLOGE("Invalid request code."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + DAudioSinkCallbackFunc &func = iter->second; + return (this->*func)(data, reply, option); +} + +int32_t DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + ResourceEventType type = static_cast(data.ReadInt32()); + std::string subType = data.ReadString(); + std::string networkId = data.ReadString(); + bool isSensitive = data.ReadBool(); + bool isSameAccout = data.ReadBool(); + int32_t ret = OnNotifyResourceInfo(type, subType, networkId, isSensitive, isSameAccout); + return ret; +} +} // DistributedHardware +} // OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp index d33e6e390598bacd141188a626cec84bd0949741..94915c9684b341b4b81f22e0162ca93eb9a3a5d5 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace DistributedHardware { -int32_t DAudioSinkProxy::InitSink(const std::string ¶ms) +int32_t DAudioSinkProxy::InitSink(const std::string ¶ms, const sptr &sinkCallback) { MessageParcel data; MessageParcel reply; @@ -34,7 +34,7 @@ int32_t DAudioSinkProxy::InitSink(const std::string ¶ms) return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; } - if (!data.WriteString(params)) { + if (!data.WriteString(params) || !data.WriteRemoteObject(sinkCallback->AsObject())) { return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } @@ -118,5 +118,62 @@ void DAudioSinkProxy::DAudioNotify(const std::string &devId, const std::string & Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::DAUDIO_NOTIFY), data, reply, option); } + +int32_t DAudioSinkProxy::PauseDistributedHardware(const std::string &networkId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; + } + + if (!data.WriteString(networkId)) { + return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; + } + + Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t ret = reply.ReadInt32(); + return ret; +} + +int32_t DAudioSinkProxy::ResumeDistributedHardware(const std::string &networkId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; + } + + if (!data.WriteString(networkId)) { + return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; + } + + Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t ret = reply.ReadInt32(); + return ret; +} + +int32_t DAudioSinkProxy::StopDistributedHardware(const std::string &networkId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; + } + + if (!data.WriteString(networkId)) { + return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; + } + + Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t ret = reply.ReadInt32(); + return ret; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/audioclient/micclient/include/dmic_client.h b/services/audioclient/micclient/include/dmic_client.h index 40ba06d14547b544dde000543e953403e79ecd99..c453410bf22025f55fd6213916bfda9ad54374c0 100644 --- a/services/audioclient/micclient/include/dmic_client.h +++ b/services/audioclient/micclient/include/dmic_client.h @@ -64,6 +64,8 @@ public: int32_t SendMessage(uint32_t type, std::string content, std::string dstDevId) override; void OnReadData(size_t length) override; + int32_t PauseCapture(); + int32_t ResumeCapture(); private: void CaptureThreadRunning(); @@ -89,6 +91,7 @@ private: std::shared_ptr micTrans_ = nullptr; int64_t lastCaptureStartTime_ = 0; int64_t lastTransStartTime_ = 0; + std::atomic isPauseStatus_ = false; }; } // DistributedHardware } // OHOS diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 330fb618cb4db6fc80d552c132546545780ad14c..b777b27b79c17b9fe33ffcc3c15e5c275417035c 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -178,11 +178,11 @@ int32_t DMicClient::SetUp(const AudioParam ¶m) int32_t DMicClient::SendMessage(uint32_t type, std::string content, std::string dstDevId) { DHLOGI("Send message to remote."); - if (type != static_cast(NOTIFY_OPEN_MIC_RESULT) && - type != static_cast(NOTIFY_CLOSE_MIC_RESULT)) { - DHLOGE("event type is not NOTIFY_OPEN_MIC or NOTIFY_CLOSE_MIC. type: %u", type); - return ERR_DH_AUDIO_NULLPTR; - } + // if (type != static_cast(NOTIFY_OPEN_MIC_RESULT) && + // type != static_cast(NOTIFY_CLOSE_MIC_RESULT)) { + // DHLOGE("event type is not NOTIFY_OPEN_MIC or NOTIFY_CLOSE_MIC. type: %u", type); + // return ERR_DH_AUDIO_NULLPTR; + // } if (micTrans_ == nullptr) { DHLOGE("mic trans is null."); return ERR_DH_AUDIO_NULLPTR; @@ -280,6 +280,9 @@ void DMicClient::AudioFwkCaptureData() DHLOGE("Bytes read failed."); return; } + if (isPauseStatus_.load()) { + memset_s(audioData->Data(), audioData->Size(), 0, audioData->Size()); + } #ifdef DUMP_DMICCLIENT_FILE if (DaudioSinkHidumper::GetInstance().QueryDumpDataFlag()) { SaveFile(MIC_CLIENT_FILENAME, const_cast(audioData->Data()), audioData->Size()); @@ -391,5 +394,19 @@ void DMicClient::SetAttrs(const std::string &devId, const std::shared_ptr { public: - explicit DAudioSinkDev(const std::string &networkId); + explicit DAudioSinkDev(const std::string &networkId, const sptr &sinkCallback); ~DAudioSinkDev() override; int32_t AwakeAudioDev(); void SleepAudioDev(); void NotifyEvent(const AudioEvent &audioEvent) override; int32_t InitAVTransEngines(const ChannelState channelState, IAVEngineProvider *providerPtr); + int32_t PauseDistributedHardware(const std::string &networkId); + int32_t ResumeDistributedHardware(const std::string &networkId); + int32_t StopDistributedHardware(const std::string &networkId); private: int32_t TaskOpenDSpeaker(const std::string &args); @@ -92,8 +96,9 @@ private: std::map> spkClientMap_; std::shared_ptr micClient_ = nullptr; std::mutex micClientMutex_; - std::map> micClientMap_; + std::map> micClientMap_; std::shared_ptr audioCtrlMgr_ = nullptr; + sptr ipcSinkCallback_ = nullptr; std::atomic isSpkInUse_ = false; std::atomic isMicInUse_ = false; diff --git a/services/audiomanager/managersink/include/daudio_sink_manager.h b/services/audiomanager/managersink/include/daudio_sink_manager.h index 4c898f0a3c99780c22e232cc8a29f494c5025ab6..e9892a6d107fa015228184ff556774cea121a16a 100644 --- a/services/audiomanager/managersink/include/daudio_sink_manager.h +++ b/services/audiomanager/managersink/include/daudio_sink_manager.h @@ -23,6 +23,7 @@ #include "daudio_sink_dev.h" #include "idaudio_source.h" +#include "idaudio_sink_ipc_callback.h" #include "i_av_engine_provider_callback.h" namespace OHOS { @@ -38,7 +39,7 @@ public: class DAudioSinkManager { DECLARE_SINGLE_INSTANCE_BASE(DAudioSinkManager); public: - int32_t Init(); + int32_t Init(const sptr &sinkCallback); int32_t UnInit(); int32_t HandleDAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, const std::string &eventContent); @@ -49,6 +50,9 @@ public: void ClearAudioDev(const std::string &devId); int32_t CreateAudioDevice(const std::string &devId); void SetChannelState(const std::string &content); + int32_t PauseDistributedHardware(const std::string &networkId); + int32_t ResumeDistributedHardware(const std::string &networkId); + int32_t StopDistributedHardware(const std::string &networkId); private: DAudioSinkManager(); @@ -73,6 +77,7 @@ private: IAVEngineProvider *rcvProviderPtr_ = nullptr; void *pSHandler_ = nullptr; void *pRHandler_ = nullptr; + sptr ipcSinkCallback_ = nullptr; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersink/src/daudio_sink_dev.cpp b/services/audiomanager/managersink/src/daudio_sink_dev.cpp index 2ca248e390e631a7c73653745380f71efd2bb9ae..8b40e66151b20cb9b1a3588a506e42c4554051f8 100644 --- a/services/audiomanager/managersink/src/daudio_sink_dev.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_dev.cpp @@ -31,7 +31,8 @@ namespace OHOS { namespace DistributedHardware { -DAudioSinkDev::DAudioSinkDev(const std::string &devId) : devId_(devId) +DAudioSinkDev::DAudioSinkDev(const std::string &devId, const sptr &sinkCallback) : + devId_(devId), ipcSinkCallback_(sinkCallback) { DHLOGD("Distributed audio sink device constructed, devId: %s.", GetAnonyString(devId).c_str()); } @@ -243,12 +244,13 @@ int32_t DAudioSinkDev::TaskOpenDMic(const std::string &args) DHLOGE("Get audio param from json failed, error code %d.", ret); return ret; } + micDhId_ = std::string(jParam[KEY_DH_ID]); int32_t dhId = ConvertString2Int(std::string(jParam[KEY_DH_ID])); if (dhId == -1) { DHLOGE("Parse dhId error."); return ERR_DH_AUDIO_NULLPTR; } - std::shared_ptr micClient = nullptr; + std::shared_ptr micClient = nullptr; { std::lock_guard devLck(micClientMutex_); micClient = micClientMap_[dhId]; @@ -267,6 +269,11 @@ int32_t DAudioSinkDev::TaskOpenDMic(const std::string &args) DHLOGE("Start capture failed, ret: %d.", ret); return ERR_DH_AUDIO_FAILED; } + std::string subType = "AUDIO_MIC"; + bool isSensitive = false; + bool isSameAccout = false; + ipcSinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, subType, devId_, + isSensitive, isSameAccout); NotifySourceDev(NOTIFY_OPEN_MIC_RESULT, jParam[KEY_DH_ID], ret); DHLOGI("Open mic device task end, notify source ret %d.", ret); isMicInUse_.store(true); @@ -282,7 +289,7 @@ int32_t DAudioSinkDev::TaskCloseDMic(const std::string &args) return ERR_DH_AUDIO_FAILED; } std::lock_guard devLck(micClientMutex_); - std::shared_ptr micClient = micClientMap_[dhId]; + std::shared_ptr micClient = micClientMap_[dhId]; if (micClient == nullptr) { DHLOGE("Mic client is null or already closed."); return DH_SUCCESS; @@ -495,7 +502,7 @@ void DAudioSinkDev::NotifySourceDev(const AudioEventType type, const std::string if (speakerClient != nullptr) { speakerClient->SendMessage(static_cast(type), jEvent.dump(), devId_); } - std::shared_ptr micClient = nullptr; + std::shared_ptr micClient = nullptr; { std::lock_guard devLck(micClientMutex_); micClient = micClientMap_[dhIdInt]; @@ -875,5 +882,52 @@ int32_t DAudioSinkDev::SinkEventHandler::GetEventParam(const AppExecFwk::InnerEv eventParam = paramObj->content; return DH_SUCCESS; } + +int32_t DAudioSinkDev::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("DAudioSinkDev PauseDistributedHardware."); + int32_t dhId = ConvertString2Int(micDhId_); + std::shared_ptr micClient = nullptr; + { + std::lock_guard devLck(micClientMutex_); + micClient = micClientMap_[dhId]; + } + if (micClient == nullptr) { + DHLOGE("Mic client should be init by dev."); + return ERR_DH_AUDIO_NULLPTR; + } + int32_t ret = micClient->PauseCapture(); + if (ret != DH_SUCCESS) { + DHLOGE("Pause mic client failed, ret: %d.", ret); + } + return ret; +} + +int32_t DAudioSinkDev::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("DAudioSinkDev ResumeDistributedHardware."); + int32_t dhId = ConvertString2Int(micDhId_); + std::shared_ptr micClient = nullptr; + { + std::lock_guard devLck(micClientMutex_); + micClient = micClientMap_[dhId]; + } + if (micClient == nullptr) { + DHLOGE("Mic client should be init by dev."); + return ERR_DH_AUDIO_NULLPTR; + } + int32_t ret = micClient->ResumeCapture(); + if (ret != DH_SUCCESS) { + DHLOGE("Resume mic client failed, ret: %d.", ret); + } + return ret; +} + +int32_t DAudioSinkDev::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("DAudioSinkDev StopDistributedHardware."); + NotifySourceDev(CLOSE_MIC, micDhId_, DH_SUCCESS); + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiomanager/managersink/src/daudio_sink_manager.cpp b/services/audiomanager/managersink/src/daudio_sink_manager.cpp index 9fe44d4355599d92c1ab7694c6ae4cf1885c1f29..47749462a55dd95163e2419cf6d27fb6fa2b6d92 100644 --- a/services/audiomanager/managersink/src/daudio_sink_manager.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_manager.cpp @@ -59,9 +59,10 @@ DAudioSinkManager::~DAudioSinkManager() DHLOGD("Distributed audio sink manager deconstructed."); } -int32_t DAudioSinkManager::Init() +int32_t DAudioSinkManager::Init(const sptr &sinkCallback) { DHLOGI("Init audio sink manager."); + ipcSinkCallback_ = sinkCallback; int32_t ret = GetLocalDeviceNetworkId(localNetworkId_); if (ret != DH_SUCCESS) { DHLOGE("Get local network id failed, ret: %d.", ret); @@ -116,6 +117,7 @@ int32_t DAudioSinkManager::UnInit() if (devClearThread_.joinable()) { devClearThread_.join(); } + ipcSinkCallback_ = nullptr; return DH_SUCCESS; } @@ -170,7 +172,7 @@ int32_t DAudioSinkManager::CreateAudioDevice(const std::string &devId) DHLOGI("Audio sink dev in map. devId: %s.", GetAnonyString(devId).c_str()); dev = audioDevMap_[devId]; } else { - dev = std::make_shared(devId); + dev = std::make_shared(devId, ipcSinkCallback_); if (dev->AwakeAudioDev() != DH_SUCCESS) { DHLOGE("Awake audio dev failed."); return ERR_DH_AUDIO_FAILED; @@ -368,5 +370,35 @@ int32_t EngineProviderListener::OnProviderEvent(const AVTransEvent &event) } return DH_SUCCESS; } + +int32_t DAudioSinkManager::PauseDistributedHardware(const std::string &networkId) +{ + std::lock_guard lock(devMapMutex_); + if (audioDevMap_.find(networkId) != audioDevMap_.end()) { + DHLOGI("Audio sink dev in map. devId: %s.", GetAnonyString(networkId).c_str()); + audioDevMap_[networkId]->PauseDistributedHardware(networkId); + } + return DH_SUCCESS; +} + +int32_t DAudioSinkManager::ResumeDistributedHardware(const std::string &networkId) +{ + std::lock_guard lock(devMapMutex_); + if (audioDevMap_.find(networkId) != audioDevMap_.end()) { + DHLOGI("Audio sink dev in map. devId: %s.", GetAnonyString(networkId).c_str()); + audioDevMap_[networkId]->ResumeDistributedHardware(networkId); + } + return DH_SUCCESS; +} + +int32_t DAudioSinkManager::StopDistributedHardware(const std::string &networkId) +{ + std::lock_guard lock(devMapMutex_); + if (audioDevMap_.find(networkId) != audioDevMap_.end()) { + DHLOGI("Audio sink dev in map. devId: %s.", GetAnonyString(networkId).c_str()); + audioDevMap_[networkId]->StopDistributedHardware(networkId); + } + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index b93b70744d344180e7792bdb92c59d963a8d9750..ca5ca9d57500987b4c879846e55ca5bea075ff51 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -80,6 +80,7 @@ ohos_shared_library("distributed_audio_sink") { "${innerkits_path}/native_cpp/audio_source/src/daudio_source_proxy.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_dev.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_manager.cpp", + "src/daudio_sink_ipc_callback_proxy.cpp", "src/daudio_sink_hidumper.cpp", "src/daudio_sink_service.cpp", "src/daudio_sink_stub.cpp", @@ -95,6 +96,7 @@ ohos_shared_library("distributed_audio_sink") { deps = [ "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", "${services_path}/common:distributed_audio_utils", "//third_party/cJSON:cjson", ] diff --git a/services/audiomanager/servicesink/include/daudio_sink_ipc_callback_proxy.h b/services/audiomanager/servicesink/include/daudio_sink_ipc_callback_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..a5abac164859524b938dba2997adddf2416f4830 --- /dev/null +++ b/services/audiomanager/servicesink/include/daudio_sink_ipc_callback_proxy.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DAUDIO_SINK_IPC_CALLBACK_PROXY_H +#define OHOS_DAUDIO_SINK_IPC_CALLBACK_PROXY_H + +#include "idaudio_sink_ipc_callback.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +class DAudioSinkIpcCallbackProxy : public IRemoteProxy { +public: + explicit DAudioSinkIpcCallbackProxy(const sptr impl) : IRemoteProxy(impl) {} + + ~DAudioSinkIpcCallbackProxy() {} + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // DistributedHardware +} // OHOS +#endif // OHOS_DAUDIO_SINK_IPC_CALLBACK_PROXY_H diff --git a/services/audiomanager/servicesink/include/daudio_sink_service.h b/services/audiomanager/servicesink/include/daudio_sink_service.h index 633d39348231bf84dd212a5fa0387b7f866cbef2..c282ae567101580895bf1e4527ea377ab1993ffa 100644 --- a/services/audiomanager/servicesink/include/daudio_sink_service.h +++ b/services/audiomanager/servicesink/include/daudio_sink_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,13 +31,16 @@ public: DAudioSinkService(int32_t saId, bool runOnCreate); ~DAudioSinkService() override = default; - int32_t InitSink(const std::string ¶ms) override; + int32_t InitSink(const std::string ¶ms, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, const std::string &eventContent) override; int Dump(int32_t fd, const std::vector& args) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; protected: void OnStart() override; diff --git a/services/audiomanager/servicesink/include/daudio_sink_stub.h b/services/audiomanager/servicesink/include/daudio_sink_stub.h index f9000041dcc0adef89cb1974a3cd5b8212002eeb..d9882b4f06050a2f8093a7ddc712476c3f597789 100644 --- a/services/audiomanager/servicesink/include/daudio_sink_stub.h +++ b/services/audiomanager/servicesink/include/daudio_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,6 +37,9 @@ private: int32_t UnsubscribeLocalHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t DAudioNotifyInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); bool VerifyPermission(); + int32_t PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); + int32_t ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); + int32_t StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); using DAudioSinkServiceFunc = int32_t (DAudioSinkStub::*)(MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/audiomanager/servicesink/src/daudio_sink_ipc_callback_proxy.cpp b/services/audiomanager/servicesink/src/daudio_sink_ipc_callback_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..28d78ae429c96a2eb0b78a849b0d0af398bda472 --- /dev/null +++ b/services/audiomanager/servicesink/src/daudio_sink_ipc_callback_proxy.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "daudio_sink_ipc_callback_proxy.h" + +#include "daudio_errorcode.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "DAudioSinkIpcCallbackProxy" + +namespace OHOS { +namespace DistributedHardware { +int32_t DAudioSinkIpcCallbackProxy::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; + } + + int32_t resType = static_cast(type); + if (!data.WriteInt32(resType) || !data.WriteString(subType) || !data.WriteString(networkId) || + !data.WriteBool(isSensitive) || !data.WriteBool(isSameAccout)) { + return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; + } + + Remote()->SendRequest(NOTIFY_RESOURCEINFO, data, reply, option); + int32_t ret = reply.ReadInt32(); + return ret; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/audiomanager/servicesink/src/daudio_sink_service.cpp b/services/audiomanager/servicesink/src/daudio_sink_service.cpp index 624ebe1bfc5acf5acab1e8c0d2b226fb47e95655..8e504ec9ca5187e5f38d96cdffdd0f7389f7456d 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_service.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -72,9 +72,9 @@ bool DAudioSinkService::Init() return true; } -int32_t DAudioSinkService::InitSink(const std::string ¶ms) +int32_t DAudioSinkService::InitSink(const std::string ¶ms, const sptr &sinkCallback) { - DAudioSinkManager::GetInstance().Init(); + DAudioSinkManager::GetInstance().Init(sinkCallback); return DH_SUCCESS; } @@ -139,5 +139,26 @@ int DAudioSinkService::Dump(int32_t fd, const std::vector &args) return DH_SUCCESS; } + +int32_t DAudioSinkService::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("PauseDistributedHardware networkId:%s.", GetAnonyString(networkId).c_str()); + DAudioSinkManager::GetInstance().PauseDistributedHardware(networkId); + return DH_SUCCESS; +} + +int32_t DAudioSinkService::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("ResumeDistributedHardware networkId:%s.", GetAnonyString(networkId).c_str()); + DAudioSinkManager::GetInstance().ResumeDistributedHardware(networkId); + return DH_SUCCESS; +} + +int32_t DAudioSinkService::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("StopDistributedHardware networkId:%s.", GetAnonyString(networkId).c_str()); + DAudioSinkManager::GetInstance().StopDistributedHardware(networkId); + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp index 77d9b00fc9eebf79aa4f0a377da50824e1c351e0..5d72b5095eb138a8547d84cca2f8d6dfc04c1a62 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp @@ -23,6 +23,7 @@ #include "daudio_errorcode.h" #include "daudio_ipc_interface_code.h" #include "daudio_log.h" +#include "daudio_sink_ipc_callback_proxy.h" #undef DH_LOG_TAG #define DH_LOG_TAG "DAudioSinkStub" @@ -42,6 +43,12 @@ DAudioSinkStub::DAudioSinkStub() &DAudioSinkStub::UnsubscribeLocalHardwareInner; memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::DAUDIO_NOTIFY)] = &DAudioSinkStub::DAudioNotifyInner; + memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::PauseDistributedHardwareInner; + memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::ResumeDistributedHardwareInner; + memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::StopDistributedHardwareInner; } DAudioSinkStub::~DAudioSinkStub() @@ -85,7 +92,14 @@ int32_t DAudioSinkStub::InitSinkInner(MessageParcel &data, MessageParcel &reply, return ERR_DH_AUDIO_SA_PERMISSION_FAIED; } std::string param = data.ReadString(); - int32_t ret = InitSink(param); + sptr remoteObject = data.ReadRemoteObject(); + if (remoteObject == nullptr) { + DHLOGE("Read ReadRemoteObject failed."); + return ERR_DH_AUDIO_NULLPTR; + } + + sptr dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject)); + int32_t ret = InitSink(param, dAudioSinkIpcCallbackProxy); reply.WriteInt32(ret); return DH_SUCCESS; } @@ -128,5 +142,29 @@ int32_t DAudioSinkStub::DAudioNotifyInner(MessageParcel &data, MessageParcel &re DAudioNotify(networkId, dhId, eventType, eventContent); return DH_SUCCESS; } + +int32_t DAudioSinkStub::PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::string networkId = data.ReadString(); + int32_t ret = PauseDistributedHardware(networkId); + reply.WriteInt32(ret); + return DH_SUCCESS; +} + +int32_t DAudioSinkStub::ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::string networkId = data.ReadString(); + int32_t ret = ResumeDistributedHardware(networkId); + reply.WriteInt32(ret); + return DH_SUCCESS; +} + +int32_t DAudioSinkStub::StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::string networkId = data.ReadString(); + int32_t ret = StopDistributedHardware(networkId); + reply.WriteInt32(ret); + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file