1 /* 2 * Copyright (c) 2024 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_SOURCE_CTRL_TRANS_H 17 #define OHOS_DAUDIO_SOURCE_CTRL_TRANS_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "iaudio_ctrl_transport.h" 23 24 namespace OHOS { 25 namespace DistributedHardware { 26 class DaudioSourceCtrlTrans : public IAudioCtrlTransport, 27 public ISoftbusChannelListener { 28 public: DaudioSourceCtrlTrans(const std::string & devId,const std::string & sessionName,const std::string & peerSessName,const std::shared_ptr<IAudioCtrlTransCallback> & callback)29 DaudioSourceCtrlTrans(const std::string &devId, const std::string &sessionName, 30 const std::string &peerSessName, const std::shared_ptr<IAudioCtrlTransCallback> &callback) 31 : ctrlTransCallback_(callback), devId_(devId), sessionName_(sessionName), peerSessName_(peerSessName) {}; ~DaudioSourceCtrlTrans()32 ~DaudioSourceCtrlTrans() override {}; 33 34 int32_t SetUp(const std::shared_ptr<IAudioCtrlTransCallback> &callback) override; 35 int32_t Start() override; 36 int32_t Stop() override; 37 int32_t Release() override; 38 int32_t SendAudioEvent(uint32_t type, const std::string &content, const std::string &dstDevId) override; 39 40 void OnChannelEvent(const AVTransEvent &event) override; 41 void OnStreamReceived(const StreamData *data, const StreamData *ext) override; 42 private: 43 int32_t WaitForChannelCreated(); 44 45 private: 46 std::weak_ptr<IAudioCtrlTransCallback> ctrlTransCallback_; 47 std::string devId_; 48 std::string sessionName_; 49 std::string peerSessName_; 50 std::mutex chnCreatedMtx_; 51 std::condition_variable chnCreatedCondVar_; 52 std::atomic<bool> chnCreateSuccess_ = false; 53 }; 54 } // namespace DistributedHardware 55 } // namespace OHOS 56 #endif