• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "dcamera_softbus_session.h"
17 
18 #include <securec.h>
19 
20 #include "anonymous_string.h"
21 #include "dcamera_softbus_adapter.h"
22 #include "distributed_camera_constants.h"
23 #include "distributed_camera_errno.h"
24 #include "distributed_hardware_log.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
DCameraSoftbusSession()28 DCameraSoftbusSession::DCameraSoftbusSession()
29 {
30     sessionId_ = -1;
31     state_ = DCAMERA_SOFTBUS_STATE_CLOSED;
32     mode_ = DCAMERA_SESSION_MODE_CTRL;
33     ResetAssembleFrag();
34 }
35 
DCameraSoftbusSession(std::string myDevId,std::string mySessionName,std::string peerDevId,std::string peerSessionName,std::shared_ptr<ICameraChannelListener> listener,DCameraSessionMode mode)36 DCameraSoftbusSession::DCameraSoftbusSession(std::string myDevId, std::string mySessionName, std::string peerDevId,
37     std::string peerSessionName, std::shared_ptr<ICameraChannelListener> listener, DCameraSessionMode mode)
38     : myDevId_(myDevId), mySessionName_(mySessionName), peerDevId_(peerDevId), peerSessionName_(peerSessionName),
39     listener_(listener), sessionId_(-1), state_(DCAMERA_SOFTBUS_STATE_CLOSED), mode_(mode)
40 {
41     sendFuncMap_[DCAMERA_SESSION_MODE_CTRL] = &DCameraSoftbusSession::SendBytes;
42     sendFuncMap_[DCAMERA_SESSION_MODE_VIDEO] = &DCameraSoftbusSession::SendStream;
43     sendFuncMap_[DCAMERA_SESSION_MODE_JPEG] = &DCameraSoftbusSession::SendStream;
44     auto runner = AppExecFwk::EventRunner::Create(mySessionName);
45     eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
46     ResetAssembleFrag();
47 }
48 
~DCameraSoftbusSession()49 DCameraSoftbusSession::~DCameraSoftbusSession()
50 {
51     if (sessionId_ != -1) {
52         int32_t ret = DCameraSoftbusAdapter::GetInstance().CloseSoftbusSession(sessionId_);
53         if (ret != DCAMERA_OK) {
54             DHLOGE("DCameraSoftbusSession delete failed, ret: %d, sessId: %d peerDevId: %s peerSessionName: %s", ret,
55                 sessionId_, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
56         }
57     }
58     sendFuncMap_.clear();
59     eventHandler_ = nullptr;
60 }
61 
OpenSession()62 int32_t DCameraSoftbusSession::OpenSession()
63 {
64     DHLOGI("DCameraSoftbusSession OpenSession peerDevId: %s peerSessionName: %s",
65         GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
66     int32_t ret = DCameraSoftbusAdapter::GetInstance().OpenSoftbusSession(mySessionName_, peerSessionName_, mode_,
67         peerDevId_);
68     if (ret != DCAMERA_OK) {
69         DHLOGE("DCameraSoftbusSession OpenSession failed, ret: %d, peerDevId: %s peerSessionName: %s", ret,
70             GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
71         return ret;
72     }
73 
74     listener_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTING);
75     return DCAMERA_OK;
76 }
77 
CloseSession()78 int32_t DCameraSoftbusSession::CloseSession()
79 {
80     DHLOGI("DCameraSoftbusSession CloseSession sessionId: %d peerDevId: %s peerSessionName: %s", sessionId_,
81         GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
82     if (sessionId_ == -1) {
83         DHLOGI("DCameraSoftbusSession CloseSession has already close peerDevId: %s peerSessionName: %s",
84             GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
85         return DCAMERA_OK;
86     }
87     int32_t ret = DCameraSoftbusAdapter::GetInstance().CloseSoftbusSession(sessionId_);
88     if (ret != DCAMERA_OK) {
89         DHLOGE("DCameraSoftbusSession CloseSession failed, ret: %d, peerDevId: %s peerSessionName: %s", ret,
90             GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
91         return ret;
92     }
93 
94     sessionId_ = -1;
95     state_ = DCAMERA_SOFTBUS_STATE_CLOSED;
96     return DCAMERA_OK;
97 }
98 
OnSessionOpend(int32_t sessionId,int32_t result)99 int32_t DCameraSoftbusSession::OnSessionOpend(int32_t sessionId, int32_t result)
100 {
101     DHLOGI("DCameraSoftbusSession OnSessionOpend sessionId: %d result: %d peerDevId: %s peerSessionName: %s",
102         sessionId, result, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
103     if (result != DCAMERA_OK) {
104         DHLOGE("DCameraSoftbusSession OnSessionOpend sessionId: %d result: %d peerDevId: %s peerSessionName: %s",
105             sessionId_, result, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
106         listener_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED);
107         listener_->OnSessionError(DCAMERA_MESSAGE, DCAMERA_EVENT_OPEN_CHANNEL_ERROR,
108             std::string("softbus internal error"));
109         return result;
110     }
111 
112     sessionId_ = sessionId;
113     state_ = DCAMERA_SOFTBUS_STATE_OPENED;
114     listener_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED);
115     return DCAMERA_OK;
116 }
117 
OnSessionClose(int32_t sessionId)118 int32_t DCameraSoftbusSession::OnSessionClose(int32_t sessionId)
119 {
120     DHLOGI("DCameraSoftbusSession OnSessionClose sessionId: %d peerDevId: %s peerSessionName: %s", sessionId,
121         GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
122     sessionId_ = -1;
123     state_ = DCAMERA_SOFTBUS_STATE_CLOSED;
124     listener_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED);
125     return DCAMERA_OK;
126 }
127 
OnDataReceived(std::shared_ptr<DataBuffer> & buffer)128 int32_t DCameraSoftbusSession::OnDataReceived(std::shared_ptr<DataBuffer>& buffer)
129 {
130     auto recvDataFunc = [this, buffer]() mutable {
131         DealRecvData(buffer);
132     };
133     if (eventHandler_ != nullptr) {
134         eventHandler_->PostTask(recvDataFunc);
135     }
136     return DCAMERA_OK;
137 }
138 
DealRecvData(std::shared_ptr<DataBuffer> & buffer)139 void DCameraSoftbusSession::DealRecvData(std::shared_ptr<DataBuffer>& buffer)
140 {
141     if (mode_ == DCAMERA_SESSION_MODE_VIDEO) {
142         PostData(buffer);
143         return;
144     }
145     PackRecvData(buffer);
146     return;
147 }
148 
PackRecvData(std::shared_ptr<DataBuffer> & buffer)149 void DCameraSoftbusSession::PackRecvData(std::shared_ptr<DataBuffer>& buffer)
150 {
151     if (buffer->Size() < BINARY_HEADER_FRAG_LEN) {
152         DHLOGE("DCameraSoftbusSession PackRecvData failed, size: %d, sess: %s peerSess: %s",
153             buffer->Size(), mySessionName_.c_str(), peerSessionName_.c_str());
154         return;
155     }
156     uint8_t *ptrPacket = buffer->Data();
157     SessionDataHeader headerPara;
158     GetFragDataLen(ptrPacket, headerPara);
159     if (buffer->Size() != (headerPara.dataLen + BINARY_HEADER_FRAG_LEN) || headerPara.dataLen > headerPara.totalLen ||
160         headerPara.dataLen > BINARY_DATA_MAX_LEN || headerPara.totalLen > BINARY_DATA_MAX_TOTAL_LEN) {
161         DHLOGE("DCameraSoftbusSession PackRecvData failed, size: %d, dataLen: %d, totalLen: %d sess: %s peerSess: %s",
162             buffer->Size(), headerPara.dataLen, headerPara.totalLen, mySessionName_.c_str(), peerSessionName_.c_str());
163         return;
164     }
165 
166     DHLOGD("DCameraSoftbusSession PackRecvData Assemble, size: %d, dataLen: %d, totalLen: %d sess: %s peerSess: %s",
167         buffer->Size(), headerPara.dataLen, headerPara.totalLen, mySessionName_.c_str(), peerSessionName_.c_str());
168     if (headerPara.fragFlag == FRAG_START_END) {
169         AssembleNoFrag(buffer, headerPara);
170     } else {
171         AssembleFrag(buffer, headerPara);
172     }
173 }
174 
AssembleNoFrag(std::shared_ptr<DataBuffer> & buffer,SessionDataHeader & headerPara)175 void DCameraSoftbusSession::AssembleNoFrag(std::shared_ptr<DataBuffer>& buffer, SessionDataHeader& headerPara)
176 {
177     if (headerPara.dataLen != headerPara.totalLen) {
178         DHLOGE("DCameraSoftbusSession PackRecvData failed, dataLen: %d, totalLen: %d, sess: %s peerSess: %s",
179             headerPara.dataLen, headerPara.totalLen, mySessionName_.c_str(), peerSessionName_.c_str());
180         return;
181     }
182     std::shared_ptr<DataBuffer> postData = std::make_shared<DataBuffer>(headerPara.dataLen);
183     int32_t ret = memcpy_s(postData->Data(), postData->Size(), buffer->Data() + BINARY_HEADER_FRAG_LEN,
184         buffer->Size() - BINARY_HEADER_FRAG_LEN);
185     if (ret != EOK) {
186         DHLOGE("DCameraSoftbusSession PackRecvData failed, ret: %d, sess: %s peerSess: %s",
187             ret, mySessionName_.c_str(), peerSessionName_.c_str());
188         return;
189     }
190     PostData(postData);
191 }
192 
AssembleFrag(std::shared_ptr<DataBuffer> & buffer,SessionDataHeader & headerPara)193 void DCameraSoftbusSession::AssembleFrag(std::shared_ptr<DataBuffer>& buffer, SessionDataHeader& headerPara)
194 {
195     if (headerPara.fragFlag == FRAG_START) {
196         isWaiting_ = true;
197         nowSeq_ = headerPara.seqNum;
198         nowSubSeq_ = headerPara.subSeq;
199         offset_ = 0;
200         totalLen_ = headerPara.totalLen;
201         packBuffer_ = std::make_shared<DataBuffer>(headerPara.totalLen);
202         int32_t ret = memcpy_s(packBuffer_->Data(), packBuffer_->Size(), buffer->Data() + BINARY_HEADER_FRAG_LEN,
203             buffer->Size() - BINARY_HEADER_FRAG_LEN);
204         if (ret != EOK) {
205             DHLOGE("DCameraSoftbusSession AssembleFrag failed, ret: %d, sess: %s peerSess: %s",
206                 ret, mySessionName_.c_str(), peerSessionName_.c_str());
207             ResetAssembleFrag();
208             return;
209         }
210         offset_ += headerPara.dataLen;
211     }
212 
213     if (headerPara.fragFlag == FRAG_MID || headerPara.fragFlag == FRAG_END) {
214         int32_t ret = CheckUnPackBuffer(headerPara);
215         if (ret != DCAMERA_OK) {
216             ResetAssembleFrag();
217             return;
218         }
219 
220         nowSubSeq_ = headerPara.subSeq;
221         ret = memcpy_s(packBuffer_->Data() + offset_, packBuffer_->Size() - offset_,
222             buffer->Data() + BINARY_HEADER_FRAG_LEN, buffer->Size() - BINARY_HEADER_FRAG_LEN);
223         if (ret != EOK) {
224             DHLOGE("DCameraSoftbusSession AssembleFrag failed, memcpy_s ret: %d, sess: %s peerSess: %s",
225                 ret, mySessionName_.c_str(), peerSessionName_.c_str());
226             ResetAssembleFrag();
227             return;
228         }
229         offset_ += headerPara.dataLen;
230     }
231 
232     if (headerPara.fragFlag == FRAG_END) {
233         PostData(packBuffer_);
234         ResetAssembleFrag();
235     }
236 }
237 
CheckUnPackBuffer(SessionDataHeader & headerPara)238 int32_t DCameraSoftbusSession::CheckUnPackBuffer(SessionDataHeader& headerPara)
239 {
240     if (!isWaiting_) {
241         DHLOGE("DCameraSoftbusSession AssembleFrag failed, not start one, sess: %s peerSess: %s",
242             mySessionName_.c_str(), peerSessionName_.c_str());
243         return DCAMERA_BAD_VALUE;
244     }
245 
246     if (nowSeq_ != headerPara.seqNum) {
247         DHLOGE("DCameraSoftbusSession AssembleFrag seq error nowSeq: %d actualSeq: %d, sess: %s peerSess: %s",
248             nowSeq_, headerPara.seqNum, mySessionName_.c_str(), peerSessionName_.c_str());
249         return DCAMERA_BAD_VALUE;
250     }
251 
252     if (nowSubSeq_ + 1 != headerPara.subSeq) {
253         DHLOGE("DCameraSoftbusSession AssembleFrag subSeq error nowSeq: %d actualSeq: %d, sess: %s peerSess: %s",
254             nowSubSeq_, headerPara.subSeq, mySessionName_.c_str(), peerSessionName_.c_str());
255         return DCAMERA_BAD_VALUE;
256     }
257 
258     if (totalLen_ < headerPara.dataLen + offset_) {
259         DHLOGE("DCameraSoftbusSession AssembleFrag len error cap: %d size: %d, dataLen: %d sess: %s peerSess: %s",
260             totalLen_, offset_, headerPara.dataLen, mySessionName_.c_str(),
261             peerSessionName_.c_str());
262         return DCAMERA_BAD_VALUE;
263     }
264     return DCAMERA_OK;
265 }
266 
ResetAssembleFrag()267 void DCameraSoftbusSession::ResetAssembleFrag()
268 {
269     isWaiting_ = false;
270     nowSeq_ = 0;
271     nowSubSeq_ = 0;
272     offset_ = 0;
273     totalLen_ = 0;
274     packBuffer_ = nullptr;
275 }
276 
PostData(std::shared_ptr<DataBuffer> & buffer)277 void DCameraSoftbusSession::PostData(std::shared_ptr<DataBuffer>& buffer)
278 {
279     std::vector<std::shared_ptr<DataBuffer>> buffers;
280     buffers.push_back(buffer);
281     listener_->OnDataReceived(buffers);
282 }
283 
GetFragDataLen(uint8_t * ptrPacket,SessionDataHeader & headerPara)284 void DCameraSoftbusSession::GetFragDataLen(uint8_t *ptrPacket, SessionDataHeader& headerPara)
285 {
286     headerPara.version = U16Get(ptrPacket);
287     headerPara.fragFlag = ptrPacket[static_cast<int32_t>(BINARY_HEADER_FRAG_OFFSET)];
288     headerPara.dataType = U32Get(ptrPacket + BINARY_HEADER_DATATYPE_OFFSET);
289     headerPara.seqNum = U32Get(ptrPacket + BINARY_HEADER_SEQNUM_OFFSET);
290     headerPara.totalLen = U32Get(ptrPacket + BINARY_HEADER_TOTALLEN_OFFSET);
291     headerPara.subSeq = U16Get(ptrPacket + BINARY_HEADER_SUBSEQ_OFFSET);
292     headerPara.dataLen = U32Get(ptrPacket + BINARY_HEADER_DATALEN_OFFSET);
293 }
294 
U16Get(const uint8_t * ptr)295 uint16_t DCameraSoftbusSession::U16Get(const uint8_t *ptr)
296 {
297     return (ptr[0] << DCAMERA_SHIFT_8) | ptr[1];
298 }
299 
U32Get(const uint8_t * ptr)300 uint32_t DCameraSoftbusSession::U32Get(const uint8_t *ptr)
301 {
302     return (ptr[0] << DCAMERA_SHIFT_24) | (ptr[1] << DCAMERA_SHIFT_16) | (ptr[2] << DCAMERA_SHIFT_8) | ptr[3];
303 }
304 
SendData(DCameraSessionMode mode,std::shared_ptr<DataBuffer> & buffer)305 int32_t DCameraSoftbusSession::SendData(DCameraSessionMode mode, std::shared_ptr<DataBuffer>& buffer)
306 {
307     auto itFunc = sendFuncMap_.find(mode);
308     if (itFunc == sendFuncMap_.end()) {
309         return DCAMERA_NOT_FOUND;
310     }
311     auto memberFunc = itFunc->second;
312     if (mode == DCAMERA_SESSION_MODE_VIDEO) {
313         return (this->*memberFunc)(buffer);
314     }
315 
316     return UnPackSendData(buffer, memberFunc);
317 }
318 
UnPackSendData(std::shared_ptr<DataBuffer> & buffer,DCameraSendFuc memberFunc)319 int32_t DCameraSoftbusSession::UnPackSendData(std::shared_ptr<DataBuffer>& buffer, DCameraSendFuc memberFunc)
320 {
321     uint16_t subSeq = 0;
322     uint32_t seq = 0;
323     uint32_t totalLen = buffer->Size();
324     SessionDataHeader headPara = { PROTOCOL_VERSION, FRAG_START, mode_, seq, totalLen, subSeq };
325 
326     if (buffer->Size() <= BINARY_DATA_PACKET_MAX_LEN) {
327         headPara.fragFlag = FRAG_START_END;
328         headPara.dataLen = buffer->Size();
329         std::shared_ptr<DataBuffer> unpackData = std::make_shared<DataBuffer>(buffer->Size() + BINARY_HEADER_FRAG_LEN);
330         MakeFragDataHeader(headPara, unpackData->Data(), BINARY_HEADER_FRAG_LEN);
331         int32_t ret = memcpy_s(unpackData->Data() + BINARY_HEADER_FRAG_LEN, unpackData->Size() - BINARY_HEADER_FRAG_LEN,
332             buffer->Data(), buffer->Size());
333         if (ret != EOK) {
334             DHLOGE("DCameraSoftbusSession UnPackSendData START_END memcpy_s failed, ret: %d, sess: %s peerSess: %s",
335                 ret, mySessionName_.c_str(), peerSessionName_.c_str());
336             return ret;
337         }
338         return (this->*memberFunc)(unpackData);
339     }
340 
341     uint32_t offset = 0;
342     while (totalLen > offset) {
343         if (totalLen - offset > BINARY_DATA_PACKET_MAX_LEN) {
344             headPara.dataLen = BINARY_DATA_PACKET_MAX_LEN;
345         } else {
346             headPara.fragFlag = FRAG_END;
347             headPara.dataLen = totalLen - offset;
348         }
349 
350         std::shared_ptr<DataBuffer> unpackData =
351             std::make_shared<DataBuffer>(headPara.dataLen + BINARY_HEADER_FRAG_LEN);
352         MakeFragDataHeader(headPara, unpackData->Data(), BINARY_HEADER_FRAG_LEN);
353         int ret = memcpy_s(unpackData->Data() + BINARY_HEADER_FRAG_LEN, unpackData->Size() - BINARY_HEADER_FRAG_LEN,
354             buffer->Data() + offset, headPara.dataLen);
355         if (ret != EOK) {
356             DHLOGE("DCameraSoftbusSession UnPackSendData memcpy_s failed, ret: %d, sess: %s peerSess: %s",
357                 ret, mySessionName_.c_str(), peerSessionName_.c_str());
358             return ret;
359         }
360         ret = (this->*memberFunc)(unpackData);
361         if (ret != DCAMERA_OK) {
362             DHLOGE("DCameraSoftbusSession sendData failed, ret: %d, sess: %s peerSess: %s",
363                 ret, mySessionName_.c_str(), peerSessionName_.c_str());
364             return ret;
365         }
366         headPara.subSeq++;
367         headPara.fragFlag = FRAG_MID;
368         offset += headPara.dataLen;
369     }
370     return DCAMERA_OK;
371 }
372 
MakeFragDataHeader(const SessionDataHeader & headPara,uint8_t * header,uint32_t len)373 void DCameraSoftbusSession::MakeFragDataHeader(const SessionDataHeader& headPara, uint8_t *header, uint32_t len)
374 {
375     uint32_t headerLen = sizeof(uint8_t) * HEADER_UINT8_NUM + sizeof(uint16_t) * HEADER_UINT16_NUM +
376         sizeof(uint32_t) * HEADER_UINT32_NUM;
377     if (headerLen > len) {
378         DHLOGE("MakeFragDataHeader %d over len %d", headerLen, len);
379         return;
380     }
381     uint32_t i = 0;
382     header[i++] = headPara.version >> DCAMERA_SHIFT_8;
383     header[i++] = headPara.version & UINT16_SHIFT_MASK_0;
384     header[i++] = headPara.fragFlag;
385     header[i++] = (headPara.dataType & UINT32_SHIFT_MASK_24) >> DCAMERA_SHIFT_24;
386     header[i++] = (headPara.dataType & UINT32_SHIFT_MASK_16) >> DCAMERA_SHIFT_16;
387     header[i++] = (headPara.dataType & UINT32_SHIFT_MASK_8) >> DCAMERA_SHIFT_8;
388     header[i++] = (headPara.dataType & UINT32_SHIFT_MASK_0);
389     header[i++] = (headPara.seqNum & UINT32_SHIFT_MASK_24) >> DCAMERA_SHIFT_24;
390     header[i++] = (headPara.seqNum & UINT32_SHIFT_MASK_16) >> DCAMERA_SHIFT_16;
391     header[i++] = (headPara.seqNum & UINT32_SHIFT_MASK_8) >> DCAMERA_SHIFT_8;
392     header[i++] = (headPara.seqNum & UINT32_SHIFT_MASK_0);
393     header[i++] = (headPara.totalLen & UINT32_SHIFT_MASK_24) >> DCAMERA_SHIFT_24;
394     header[i++] = (headPara.totalLen & UINT32_SHIFT_MASK_16) >> DCAMERA_SHIFT_16;
395     header[i++] = (headPara.totalLen & UINT32_SHIFT_MASK_8) >> DCAMERA_SHIFT_8;
396     header[i++] = (headPara.totalLen & UINT32_SHIFT_MASK_0);
397     header[i++] = headPara.subSeq >> DCAMERA_SHIFT_8;
398     header[i++] = headPara.subSeq & UINT16_SHIFT_MASK_0;
399     header[i++] = (headPara.dataLen & UINT32_SHIFT_MASK_24) >> DCAMERA_SHIFT_24;
400     header[i++] = (headPara.dataLen & UINT32_SHIFT_MASK_16) >> DCAMERA_SHIFT_16;
401     header[i++] = (headPara.dataLen & UINT32_SHIFT_MASK_8) >> DCAMERA_SHIFT_8;
402     header[i++] = (headPara.dataLen & UINT32_SHIFT_MASK_0);
403 }
404 
SendBytes(std::shared_ptr<DataBuffer> & buffer)405 int32_t DCameraSoftbusSession::SendBytes(std::shared_ptr<DataBuffer>& buffer)
406 {
407     if (state_ != DCAMERA_SOFTBUS_STATE_OPENED) {
408         DHLOGE("DCameraSoftbusSession SendBytes session state %d is not opened sessionId: %d peerDev: %s peerName: %s",
409             state_, sessionId_, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
410         return DCAMERA_WRONG_STATE;
411     }
412 
413     int32_t ret = DCameraSoftbusAdapter::GetInstance().SendSofbusBytes(sessionId_, buffer);
414     if (ret != DCAMERA_OK) {
415         DHLOGE("DCameraSoftbusSession SendBytes sessionId: %d failed: %d peerDevId: %s peerSessionName: %s", sessionId_,
416             ret, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
417     }
418     return ret;
419 }
420 
SendStream(std::shared_ptr<DataBuffer> & buffer)421 int32_t DCameraSoftbusSession::SendStream(std::shared_ptr<DataBuffer>& buffer)
422 {
423     if (state_ != DCAMERA_SOFTBUS_STATE_OPENED) {
424         DHLOGE("DCameraSoftbusSession SendStream session state %d is not opened sessionId: %d peerDev: %s peerName: %s",
425             state_, sessionId_, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
426         return DCAMERA_WRONG_STATE;
427     }
428 
429     int32_t ret = DCameraSoftbusAdapter::GetInstance().SendSofbusStream(sessionId_, buffer);
430     if (ret != DCAMERA_OK) {
431         DHLOGE("DCameraSoftbusSession SendStream sessionId: %d failed: %d peerDevId: %s peerSessionName: %s",
432             sessionId_, ret, GetAnonyString(peerDevId_).c_str(), GetAnonyString(peerSessionName_).c_str());
433     }
434     return ret;
435 }
436 
GetPeerDevId()437 std::string DCameraSoftbusSession::GetPeerDevId()
438 {
439     return peerDevId_;
440 }
441 
GetPeerSessionName()442 std::string DCameraSoftbusSession::GetPeerSessionName()
443 {
444     return peerSessionName_;
445 }
446 
GetMySessionName()447 std::string DCameraSoftbusSession::GetMySessionName()
448 {
449     return mySessionName_;
450 }
451 } // namespace DistributedHardware
452 } // namespace OHOS
453