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_AUDIO_DATA_CHANNEL_H 17 #define OHOS_AUDIO_DATA_CHANNEL_H 18 19 #include <memory> 20 #include <string> 21 22 #include "iaudio_channel_listener.h" 23 #include "iaudio_channel.h" 24 #include "softbus_adapter.h" 25 26 namespace OHOS { 27 namespace DistributedHardware { 28 class AudioDataChannel : public IAudioChannel, 29 public ISoftbusListener, 30 public std::enable_shared_from_this<AudioDataChannel> { 31 public: AudioDataChannel(const std::string & peerDevId)32 explicit AudioDataChannel(const std::string &peerDevId) : peerDevId_(peerDevId) {}; 33 ~AudioDataChannel() override = default; 34 35 int32_t CreateSession(const std::shared_ptr<IAudioChannelListener> &listener, 36 const std::string &sessionName) override; 37 int32_t ReleaseSession() override; 38 int32_t OpenSession() override; 39 int32_t CloseSession() override; 40 int32_t SendData(const std::shared_ptr<AudioData> &audioData) override; 41 int32_t SendEvent(const AudioEvent &audioEvent) override; 42 43 void OnSessionOpened(int32_t sessionId, int32_t result) override; 44 void OnSessionClosed(int32_t sessionId) override; 45 void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override; 46 void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, 47 const StreamFrameInfo *streamFrameInfo) override; 48 49 private: 50 const std::string peerDevId_; 51 int32_t sessionId_ = 0; 52 std::string sessionName_; 53 std::weak_ptr<IAudioChannelListener> channelListener_; 54 }; 55 } // namespace DistributedHardware 56 } // namespace OHOS 57 #endif // OHOS_AUDIO_DATA_CHANNEL_H 58