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