1 /* 2 * Copyright (c) 2023 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_AV_TRANS_RECEIVER_TRANS_H 17 #define OHOS_AV_TRANS_RECEIVER_TRANS_H 18 19 #include <condition_variable> 20 #include <mutex> 21 #include <string> 22 23 #include "audio_data.h" 24 #include "audio_param.h" 25 #include "av_receiver_engine_adapter.h" 26 #include "iaudio_data_transport.h" 27 #include "iaudio_datatrans_callback.h" 28 #include "i_av_receiver_engine_callback.h" 29 #include "i_av_receiver_engine.h" 30 #include "i_av_engine_provider.h" 31 32 namespace OHOS { 33 namespace DistributedHardware { 34 class AVReceiverTransportCallback { 35 public: AVReceiverTransportCallback()36 AVReceiverTransportCallback() {}; 37 virtual ~AVReceiverTransportCallback() = default; 38 virtual void OnEngineTransEvent(const AVTransEvent &event) = 0; 39 virtual void OnEngineTransMessage(const std::shared_ptr<AVTransMessage> &message) = 0; 40 virtual void OnEngineTransDataAvailable(const std::shared_ptr<AudioData> &audioData) = 0; 41 }; 42 43 class AVTransReceiverTransport : public IAudioDataTransport, 44 public AVReceiverAdapterCallback, 45 public std::enable_shared_from_this<AVTransReceiverTransport> { 46 public: AVTransReceiverTransport(const std::string & devId,const std::shared_ptr<AVReceiverTransportCallback> & callback)47 AVTransReceiverTransport(const std::string &devId, 48 const std::shared_ptr<AVReceiverTransportCallback> &callback) 49 : transCallback_(callback), devId_(devId) {}; ~AVTransReceiverTransport()50 ~AVTransReceiverTransport() override {}; 51 52 int32_t SetUp(const AudioParam &localParam, const AudioParam &remoteParam, 53 const std::shared_ptr<IAudioDataTransCallback> &callback, const PortCapType capType) override; 54 int32_t Start() override; 55 int32_t Stop() override; 56 int32_t Release() override; 57 int32_t Pause() override; 58 int32_t Restart(const AudioParam &localParam, const AudioParam &remoteParam) override; 59 int32_t FeedAudioData(std::shared_ptr<AudioData> &audioData) override; 60 int32_t CreateCtrl() override; 61 int32_t InitEngine(IAVEngineProvider *providerPtr) override; 62 int32_t SendMessage(uint32_t type, std::string content, std::string dstDevId) override; 63 64 void OnEngineEvent(const AVTransEvent &event) override; 65 void OnEngineMessage(const std::shared_ptr<AVTransMessage> &message) override; 66 void OnEngineDataAvailable(const std::shared_ptr<AVTransBuffer> &buffer) override; 67 68 private: 69 int32_t SetParameter(const AudioParam &audioParam); 70 71 private: 72 std::shared_ptr<AVTransReceiverAdapter> receiverAdapter_; 73 std::shared_ptr<AVReceiverTransportCallback> transCallback_; 74 std::string devId_; 75 }; 76 } // namespace DistributedHardware 77 } // namespace OHOS 78 #endif