• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "hcapture_session.h"
17 
18 #include "camera_util.h"
19 #include "camera_log.h"
20 #include "surface.h"
21 #include "ipc_skeleton.h"
22 #include "metadata_utils.h"
23 #include "bundle_mgr_interface.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26 
27 using namespace OHOS::AppExecFwk;
28 using namespace OHOS::AAFwk;
29 
30 namespace OHOS {
31 namespace CameraStandard {
32 static std::map<int32_t, sptr<HCaptureSession>> session_;
33 static std::mutex sessionLock_;
34 static std::map<CaptureSessionState, std::string> sessionState_ = {
35     {CaptureSessionState::SESSION_INIT, "Init"},
36     {CaptureSessionState::SESSION_CONFIG_INPROGRESS, "Config_In-progress"},
37     {CaptureSessionState::SESSION_CONFIG_COMMITTED, "Committed"}
38 };
GetClientBundle(int uid)39 static std::string GetClientBundle(int uid)
40 {
41     std::string bundleName = "";
42     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
43     if (samgr == nullptr) {
44         MEDIA_ERR_LOG("Get ability manager failed");
45         return bundleName;
46     }
47 
48     sptr<IRemoteObject> object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
49     if (object == nullptr) {
50         MEDIA_DEBUG_LOG("object is NULL.");
51         return bundleName;
52     }
53 
54     sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(object);
55     if (bms == nullptr) {
56         MEDIA_DEBUG_LOG("bundle manager service is NULL.");
57         return bundleName;
58     }
59 
60     auto result = bms->GetBundleNameForUid(uid, bundleName);
61     if (!result) {
62         MEDIA_ERR_LOG("GetBundleNameForUid fail");
63         return "";
64     }
65     MEDIA_INFO_LOG("bundle name is %{public}s ", bundleName.c_str());
66 
67     return bundleName;
68 }
69 
HCaptureSession(sptr<HCameraHostManager> cameraHostManager,sptr<StreamOperatorCallback> streamOperatorCb,const uint32_t callingTokenId)70 HCaptureSession::HCaptureSession(sptr<HCameraHostManager> cameraHostManager,
71     sptr<StreamOperatorCallback> streamOperatorCb, const uint32_t callingTokenId)
72     : cameraHostManager_(cameraHostManager), streamOperatorCallback_(streamOperatorCb),
73     sessionCallback_(nullptr)
74 {
75     pid_ = IPCSkeleton::GetCallingPid();
76     uid_ = IPCSkeleton::GetCallingUid();
77     MEDIA_DEBUG_LOG("HCaptureSession: camera stub services(%{public}zu) pid(%{public}d).", session_.size(), pid_);
78     std::map<int32_t, sptr<HCaptureSession>> oldSessions;
79     for (auto it = session_.begin(); it != session_.end(); it++) {
80         sptr<HCaptureSession> session = it->second;
81         oldSessions[it->first] = session;
82     }
83     for (auto it = oldSessions.begin(); it != oldSessions.end(); it++) {
84         if (it->second != nullptr) {
85             sptr<HCaptureSession> session = it->second;
86             sptr<HCameraDevice> disconnectDevice;
87             int32_t rc = session->GetCameraDevice(disconnectDevice);
88             if (rc == CAMERA_OK) {
89                 disconnectDevice->OnError(DEVICE_PREEMPT, 0);
90             }
91             session->Release(it->first);
92             MEDIA_ERR_LOG("currently multi-session not supported, release session for pid(%{public}d)", it->first);
93         }
94     }
95     std::lock_guard<std::mutex> lock(sessionLock_);
96     session_[pid_] = this;
97     callerToken_ = callingTokenId;
98     MEDIA_DEBUG_LOG("HCaptureSession: camera stub services(%{public}zu).", session_.size());
99 }
100 
~HCaptureSession()101 HCaptureSession::~HCaptureSession()
102 {}
103 
BeginConfig()104 int32_t HCaptureSession::BeginConfig()
105 {
106     CAMERA_SYNC_TRACE;
107     if (curState_ == CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
108         MEDIA_ERR_LOG("HCaptureSession::BeginConfig Already in config inprogress state!");
109         return CAMERA_INVALID_STATE;
110     }
111     std::lock_guard<std::mutex> lock(sessionLock_);
112     prevState_ = curState_;
113     curState_ = CaptureSessionState::SESSION_CONFIG_INPROGRESS;
114     tempCameraDevices_.clear();
115     tempStreams_.clear();
116     deletedStreamIds_.clear();
117     return CAMERA_OK;
118 }
119 
AddInput(sptr<ICameraDeviceService> cameraDevice)120 int32_t HCaptureSession::AddInput(sptr<ICameraDeviceService> cameraDevice)
121 {
122     CAMERA_SYNC_TRACE;
123     sptr<HCameraDevice> localCameraDevice = nullptr;
124 
125     if (cameraDevice == nullptr) {
126         MEDIA_ERR_LOG("HCaptureSession::AddInput cameraDevice is null");
127         return CAMERA_INVALID_ARG;
128     }
129     std::lock_guard<std::mutex> lock(sessionLock_);
130     if (curState_ != CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
131         MEDIA_ERR_LOG("HCaptureSession::AddInput Need to call BeginConfig before adding input");
132         return CAMERA_INVALID_STATE;
133     }
134     if (!tempCameraDevices_.empty() || (cameraDevice_ != nullptr && !cameraDevice_->IsReleaseCameraDevice())) {
135         MEDIA_ERR_LOG("HCaptureSession::AddInput Only one input is supported");
136         return CAMERA_INVALID_SESSION_CFG;
137     }
138     localCameraDevice = static_cast<HCameraDevice*>(cameraDevice.GetRefPtr());
139     if (cameraDevice_ == localCameraDevice && cameraDevice_ != nullptr) {
140         cameraDevice_->SetReleaseCameraDevice(false);
141     } else {
142         tempCameraDevices_.emplace_back(localCameraDevice);
143         CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddInput"));
144     }
145 
146     sptr<IStreamOperator> streamOperator;
147     int32_t rc = localCameraDevice->GetStreamOperator(streamOperatorCallback_, streamOperator);
148     if (rc != CAMERA_OK) {
149         MEDIA_ERR_LOG("HCaptureSession::GetCameraDevice GetStreamOperator returned %{public}d", rc);
150         localCameraDevice->Close();
151         return rc;
152     }
153     return CAMERA_OK;
154 }
155 
AddOutputStream(sptr<HStreamCommon> stream)156 int32_t HCaptureSession::AddOutputStream(sptr<HStreamCommon> stream)
157 {
158     std::lock_guard<std::mutex> lock(sessionLock_);
159     if (stream == nullptr) {
160         MEDIA_ERR_LOG("HCaptureSession::AddOutputStream stream is null");
161         return CAMERA_INVALID_ARG;
162     }
163     if (curState_ != CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
164         MEDIA_ERR_LOG("HCaptureSession::AddOutputStream Need to call BeginConfig before adding output");
165         return CAMERA_INVALID_STATE;
166     }
167     if (std::find(tempStreams_.begin(), tempStreams_.end(), stream) != tempStreams_.end()) {
168         MEDIA_ERR_LOG("HCaptureSession::AddOutputStream Adding same output multiple times in tempStreams_");
169         return CAMERA_INVALID_SESSION_CFG;
170     }
171     int32_t rc = FindRepeatStream(stream);
172     if (rc != STREAM_NOT_FOUNT) {
173         return rc;
174     }
175     if (stream) {
176         stream->SetReleaseStream(false);
177     }
178     tempStreams_.emplace_back(stream);
179     return CAMERA_OK;
180 }
FindRepeatStream(sptr<HStreamCommon> stream)181 int32_t HCaptureSession::FindRepeatStream(sptr<HStreamCommon> stream)
182 {
183     std::lock_guard<std::mutex> lock(streamsLock_);
184     auto it = std::find(streams_.begin(), streams_.end(), stream);
185     if (it != streams_.end()) {
186         if (stream && stream->IsReleaseStream()) {
187             stream->SetReleaseStream(false);
188             auto it2 = std::find(deletedStreamIds_.begin(), deletedStreamIds_.end(), stream->GetStreamId());
189             if (it2 != deletedStreamIds_.end()) {
190                 deletedStreamIds_.erase(it2);
191             }
192             return CAMERA_OK;
193         } else {
194             MEDIA_ERR_LOG("HCaptureSession::AddOutputStream Adding same output multiple times in streams_");
195             return CAMERA_INVALID_SESSION_CFG;
196         }
197     }
198     return STREAM_NOT_FOUNT;
199 }
200 
AddOutput(StreamType streamType,sptr<IStreamCommon> stream)201 int32_t HCaptureSession::AddOutput(StreamType streamType, sptr<IStreamCommon> stream)
202 {
203     int32_t rc = CAMERA_INVALID_ARG;
204     if (stream == nullptr) {
205         MEDIA_ERR_LOG("HCaptureSession::AddOutput stream is null");
206         return rc;
207     }
208     // Temp hack to fix the library linking issue
209     sptr<Surface> captureSurface = Surface::CreateSurfaceAsConsumer();
210 
211     if (streamType == StreamType::CAPTURE) {
212         rc = AddOutputStream(static_cast<HStreamCapture *>(stream.GetRefPtr()));
213     } else if (streamType == StreamType::REPEAT) {
214         rc = AddOutputStream(static_cast<HStreamRepeat *>(stream.GetRefPtr()));
215     }  else if (streamType == StreamType::METADATA) {
216         rc = AddOutputStream(static_cast<HStreamMetadata *>(stream.GetRefPtr()));
217     }
218     CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddOutput with %d", streamType));
219     MEDIA_INFO_LOG("CaptureSession::AddOutput with with %{public}d, rc = %{public}d", streamType, rc);
220     return rc;
221 }
222 
RemoveInput(sptr<ICameraDeviceService> cameraDevice)223 int32_t HCaptureSession::RemoveInput(sptr<ICameraDeviceService> cameraDevice)
224 {
225     if (cameraDevice == nullptr) {
226         MEDIA_ERR_LOG("HCaptureSession::RemoveInput cameraDevice is null");
227         return CAMERA_INVALID_ARG;
228     }
229     if (curState_ != CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
230         MEDIA_ERR_LOG("HCaptureSession::RemoveInput Need to call BeginConfig before removing input");
231         return CAMERA_INVALID_STATE;
232     }
233     std::lock_guard<std::mutex> lock(sessionLock_);
234     sptr<HCameraDevice> localCameraDevice;
235     localCameraDevice = static_cast<HCameraDevice*>(cameraDevice.GetRefPtr());
236     auto it = std::find(tempCameraDevices_.begin(), tempCameraDevices_.end(), localCameraDevice);
237     if (it != tempCameraDevices_.end()) {
238         tempCameraDevices_.erase(it);
239     } else if (cameraDevice_ != nullptr && cameraDevice_ == localCameraDevice) {
240         cameraDevice_->SetReleaseCameraDevice(true);
241     } else {
242         MEDIA_ERR_LOG("HCaptureSession::RemoveInput Invalid camera device");
243         return CAMERA_INVALID_SESSION_CFG;
244     }
245     CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveInput"));
246     return CAMERA_OK;
247 }
248 
RemoveOutputStream(sptr<HStreamCommon> stream)249 int32_t HCaptureSession::RemoveOutputStream(sptr<HStreamCommon> stream)
250 {
251     if (stream == nullptr) {
252         MEDIA_ERR_LOG("HCaptureSession::RemoveOutputStream stream is null");
253         return CAMERA_INVALID_ARG;
254     }
255     if (curState_ != CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
256         MEDIA_ERR_LOG("HCaptureSession::RemoveOutputStream Need to call BeginConfig before removing output");
257         return CAMERA_INVALID_STATE;
258     }
259     auto it = std::find(tempStreams_.begin(), tempStreams_.end(), stream);
260     if (it != tempStreams_.end()) {
261         tempStreams_.erase(it);
262     } else {
263         std::lock_guard<std::mutex> lock(streamsLock_);
264         it = std::find(streams_.begin(), streams_.end(), stream);
265         if (it != streams_.end()) {
266             if (stream && !stream->IsReleaseStream()) {
267                 deletedStreamIds_.emplace_back(stream->GetStreamId());
268                 stream->SetReleaseStream(true);
269             }
270         } else {
271             MEDIA_ERR_LOG("HCaptureSession::RemoveOutputStream Invalid output");
272             return CAMERA_INVALID_SESSION_CFG;
273         }
274     }
275     return CAMERA_OK;
276 }
277 
RemoveOutput(StreamType streamType,sptr<IStreamCommon> stream)278 int32_t HCaptureSession::RemoveOutput(StreamType streamType, sptr<IStreamCommon> stream)
279 {
280     int32_t rc = CAMERA_INVALID_ARG;
281     if (stream == nullptr) {
282         MEDIA_ERR_LOG("HCaptureSession::RemoveOutput stream is null");
283         return rc;
284     }
285     std::lock_guard<std::mutex> lock(sessionLock_);
286     if (streamType == StreamType::CAPTURE) {
287         rc = RemoveOutputStream(static_cast<HStreamCapture *>(stream.GetRefPtr()));
288     } else if (streamType == StreamType::REPEAT) {
289         rc = RemoveOutputStream(static_cast<HStreamRepeat *>(stream.GetRefPtr()));
290     } else if (streamType == StreamType::METADATA) {
291         rc = RemoveOutputStream(static_cast<HStreamMetadata *>(stream.GetRefPtr()));
292     }
293     CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveOutput with %d", streamType));
294     return rc;
295 }
296 
ValidateSessionInputs()297 int32_t HCaptureSession::ValidateSessionInputs()
298 {
299     if (tempCameraDevices_.empty() && (cameraDevice_ == nullptr || cameraDevice_->IsReleaseCameraDevice())) {
300         MEDIA_ERR_LOG("HCaptureSession::ValidateSessionInputs No inputs present");
301         return CAMERA_INVALID_SESSION_CFG;
302     }
303     return CAMERA_OK;
304 }
305 
ValidateSessionOutputs()306 int32_t HCaptureSession::ValidateSessionOutputs()
307 {
308     if (tempStreams_.size() + streams_.size() - deletedStreamIds_.size() == 0) {
309         MEDIA_ERR_LOG("HCaptureSession::ValidateSessionOutputs No outputs present");
310         return CAMERA_INVALID_SESSION_CFG;
311     }
312     return CAMERA_OK;
313 }
314 
GetCameraDevice(sptr<HCameraDevice> & device)315 int32_t HCaptureSession::GetCameraDevice(sptr<HCameraDevice> &device)
316 {
317     if (cameraDevice_ != nullptr && !cameraDevice_->IsReleaseCameraDevice()) {
318         MEDIA_DEBUG_LOG("HCaptureSession::GetCameraDevice Camera device has not changed");
319         device = cameraDevice_;
320         return CAMERA_OK;
321     } else if (!tempCameraDevices_.empty()) {
322         device = tempCameraDevices_[0];
323         return CAMERA_OK;
324     }
325 
326     MEDIA_ERR_LOG("HCaptureSession::GetCameraDevice Failed because don't have camera device");
327     return CAMERA_INVALID_STATE;
328 }
329 
GetCurrentStreamInfos(sptr<HCameraDevice> & device,std::shared_ptr<OHOS::Camera::CameraMetadata> & deviceSettings,std::vector<StreamInfo> & streamInfos)330 int32_t HCaptureSession::GetCurrentStreamInfos(sptr<HCameraDevice> &device,
331                                                std::shared_ptr<OHOS::Camera::CameraMetadata> &deviceSettings,
332                                                std::vector<StreamInfo> &streamInfos)
333 {
334     int32_t rc;
335     int32_t streamId = streamId_;
336     bool isNeedLink;
337     StreamInfo curStreamInfo;
338     sptr<IStreamOperator> streamOperator;
339     if (device != nullptr) {
340         streamOperator = device->GetStreamOperator();
341     }
342     isNeedLink = (device != cameraDevice_);
343     std::lock_guard<std::mutex> lock(streamsLock_);
344     sptr<HStreamCommon> curStream;
345     for (auto item = streams_.begin(); item != streams_.end(); ++item) {
346         curStream = *item;
347         if (curStream && curStream->IsReleaseStream()) {
348             continue;
349         }
350         if (curStream && isNeedLink) {
351             rc = curStream->LinkInput(streamOperator, deviceSettings, streamId);
352             if (rc != CAMERA_OK) {
353                 MEDIA_ERR_LOG("HCaptureSession::GetCurrentStreamInfos() Failed to link Output, %{public}d", rc);
354                 return rc;
355             }
356             streamId++;
357         }
358         if (curStream) {
359             curStream->SetStreamInfo(curStreamInfo);
360         }
361         streamInfos.push_back(curStreamInfo);
362     }
363     if (streamId != streamId_) {
364         streamId_ = streamId;
365     }
366     return CAMERA_OK;
367 }
368 
CreateAndCommitStreams(sptr<HCameraDevice> & device,std::shared_ptr<OHOS::Camera::CameraMetadata> & deviceSettings,std::vector<StreamInfo> & streamInfos)369 int32_t HCaptureSession::CreateAndCommitStreams(sptr<HCameraDevice> &device,
370                                                 std::shared_ptr<OHOS::Camera::CameraMetadata> &deviceSettings,
371                                                 std::vector<StreamInfo> &streamInfos)
372 {
373     CamRetCode hdiRc = HDI::Camera::V1_0::NO_ERROR;
374     StreamInfo curStreamInfo;
375     sptr<IStreamOperator> streamOperator;
376     if (device != nullptr) {
377         streamOperator = device->GetStreamOperator();
378     }
379     if (streamOperator != nullptr && !streamInfos.empty()) {
380         hdiRc = (CamRetCode)(streamOperator->CreateStreams(streamInfos));
381     } else {
382         MEDIA_INFO_LOG("HCaptureSession::CreateAndCommitStreams(), No new streams to create");
383     }
384     if (streamOperator != nullptr && hdiRc == HDI::Camera::V1_0::NO_ERROR) {
385         std::vector<uint8_t> setting;
386         OHOS::Camera::MetadataUtils::ConvertMetadataToVec(deviceSettings, setting);
387         hdiRc = (CamRetCode)(streamOperator->CommitStreams(NORMAL, setting));
388         if (hdiRc != HDI::Camera::V1_0::NO_ERROR) {
389             MEDIA_ERR_LOG("HCaptureSession::CreateAndCommitStreams(), Failed to commit %{public}d", hdiRc);
390             std::vector<int32_t> streamIds;
391             for (auto item = streamInfos.begin(); item != streamInfos.end(); ++item) {
392                 curStreamInfo = *item;
393                 streamIds.emplace_back(curStreamInfo.streamId_);
394             }
395             if (!streamIds.empty() && streamOperator->ReleaseStreams(streamIds) != HDI::Camera::V1_0::NO_ERROR) {
396                 MEDIA_ERR_LOG("HCaptureSession::CreateAndCommitStreams(), Failed to release streams");
397             }
398         }
399     }
400     return HdiToServiceError(hdiRc);
401 }
402 
CheckAndCommitStreams(sptr<HCameraDevice> & device,std::shared_ptr<OHOS::Camera::CameraMetadata> & deviceSettings,std::vector<StreamInfo> & allStreamInfos,std::vector<StreamInfo> & newStreamInfos)403 int32_t HCaptureSession::CheckAndCommitStreams(sptr<HCameraDevice> &device,
404                                                std::shared_ptr<OHOS::Camera::CameraMetadata> &deviceSettings,
405                                                std::vector<StreamInfo> &allStreamInfos,
406                                                std::vector<StreamInfo> &newStreamInfos)
407 {
408     return CreateAndCommitStreams(device, deviceSettings, newStreamInfos);
409 }
410 
DeleteReleasedStream()411 void HCaptureSession::DeleteReleasedStream()
412 {
413     auto matchFunction = [](const auto& curStream) { return curStream->IsReleaseStream();};
414     captureStreams_.erase(std::remove_if(captureStreams_.begin(), captureStreams_.end(), matchFunction),
415         captureStreams_.end());
416     repeatStreams_.erase(std::remove_if(repeatStreams_.begin(), repeatStreams_.end(), matchFunction),
417         repeatStreams_.end());
418     metadataStreams_.erase(std::remove_if(metadataStreams_.begin(), metadataStreams_.end(), matchFunction),
419         metadataStreams_.end());
420     {
421         std::lock_guard<std::mutex> lock(streamsLock_);
422         sptr<HStreamCommon> curStream;
423         for (auto item = streams_.begin(); item != streams_.end(); ++item) {
424             curStream = *item;
425             if (curStream && curStream->IsReleaseStream()) {
426                 curStream->Release();
427                 streams_.erase(item--);
428             }
429         }
430     }
431 }
432 
RestorePreviousState(sptr<HCameraDevice> & device,bool isCreateReleaseStreams)433 void HCaptureSession::RestorePreviousState(sptr<HCameraDevice> &device, bool isCreateReleaseStreams)
434 {
435     std::vector<StreamInfo> streamInfos;
436     StreamInfo streamInfo;
437     std::shared_ptr<OHOS::Camera::CameraMetadata> settings;
438     sptr<HStreamCommon> curStream;
439 
440     MEDIA_DEBUG_LOG("HCaptureSession::RestorePreviousState, Restore to previous state");
441     {
442         std::lock_guard<std::mutex> lock(streamsLock_);
443         for (auto item = streams_.begin(); item != streams_.end(); ++item) {
444             curStream = *item;
445             if (curStream && isCreateReleaseStreams && curStream->IsReleaseStream()) {
446                 curStream->SetStreamInfo(streamInfo);
447                 streamInfos.push_back(streamInfo);
448             }
449             if (curStream) {
450                 curStream->SetReleaseStream(false);
451             }
452         }
453     }
454     for (auto item = tempStreams_.begin(); item != tempStreams_.end(); ++item) {
455         curStream = *item;
456         if (curStream) {
457             curStream->Release();
458         }
459     }
460     tempStreams_.clear();
461     deletedStreamIds_.clear();
462     tempCameraDevices_.clear();
463     if (device != nullptr) {
464         device->SetReleaseCameraDevice(false);
465         if (isCreateReleaseStreams) {
466             settings = device->GetSettings();
467             if (settings != nullptr) {
468                 CreateAndCommitStreams(device, settings, streamInfos);
469             }
470         }
471     }
472     curState_ = prevState_;
473 }
474 
UpdateSessionConfig(sptr<HCameraDevice> & device)475 void HCaptureSession::UpdateSessionConfig(sptr<HCameraDevice> &device)
476 {
477     DeleteReleasedStream();
478     deletedStreamIds_.clear();
479     {
480         std::lock_guard<std::mutex> lock(streamsLock_);
481         sptr<HStreamCommon> curStream;
482         for (auto item = tempStreams_.begin(); item != tempStreams_.end(); ++item) {
483             curStream = *item;
484             if (curStream && curStream->GetStreamType() == StreamType::REPEAT) {
485                 repeatStreams_.emplace_back(curStream);
486             } else if (curStream && curStream->GetStreamType() == StreamType::CAPTURE) {
487                 captureStreams_.emplace_back(curStream);
488             } else if (curStream && curStream->GetStreamType() == StreamType::METADATA) {
489                 metadataStreams_.emplace_back(curStream);
490             }
491             streams_.emplace_back(curStream);
492         }
493     }
494     tempStreams_.clear();
495     if (streamOperatorCallback_ == nullptr) {
496         MEDIA_ERR_LOG("HCaptureSession::UpdateSessionConfig streamOperatorCallback_ is nullptr");
497         return;
498     }
499     streamOperatorCallback_->SetCaptureSession(this);
500     cameraDevice_ = device;
501     curState_ = CaptureSessionState::SESSION_CONFIG_COMMITTED;
502 }
503 
HandleCaptureOuputsConfig(sptr<HCameraDevice> & device)504 int32_t HCaptureSession::HandleCaptureOuputsConfig(sptr<HCameraDevice> &device)
505 {
506     int32_t rc;
507     int32_t streamId;
508     std::vector<StreamInfo> newStreamInfos;
509     std::vector<StreamInfo> allStreamInfos;
510     StreamInfo curStreamInfo;
511     std::shared_ptr<OHOS::Camera::CameraMetadata> settings;
512     sptr<IStreamOperator> streamOperator;
513     sptr<HStreamCommon> curStream;
514     if (device != nullptr) {
515         settings = device->GetSettings();
516     }
517     if (device == nullptr || settings == nullptr) {
518         return CAMERA_UNKNOWN_ERROR;
519     }
520 
521     rc = GetCurrentStreamInfos(device, settings, allStreamInfos);
522     if (rc != CAMERA_OK) {
523         MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() Failed to get streams info, %{public}d", rc);
524         return rc;
525     }
526 
527     if (cameraDevice_ != device) {
528         newStreamInfos = allStreamInfos;
529     }
530 
531     streamOperator = device->GetStreamOperator();
532     streamId = streamId_;
533     for (auto item = tempStreams_.begin(); item != tempStreams_.end(); ++item) {
534         curStream = *item;
535         if (curStream == nullptr) {
536             MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() curStream is null");
537             return CAMERA_UNKNOWN_ERROR;
538         }
539         if (curStream) {
540             rc = curStream->LinkInput(streamOperator, settings, streamId);
541             if (rc != CAMERA_OK) {
542                 MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() Failed to link Output, %{public}d", rc);
543                 return rc;
544             }
545         }
546         if (curStream) {
547             curStream->SetStreamInfo(curStreamInfo);
548         }
549         newStreamInfos.push_back(curStreamInfo);
550         allStreamInfos.push_back(curStreamInfo);
551         streamId++;
552     }
553 
554     rc = CheckAndCommitStreams(device, settings, allStreamInfos, newStreamInfos);
555     if (rc == CAMERA_OK) {
556         streamId_ = streamId;
557     }
558     return rc;
559 }
560 
CommitConfig()561 int32_t HCaptureSession::CommitConfig()
562 {
563     sptr<HCameraDevice> device = nullptr;
564 
565     if (curState_ != CaptureSessionState::SESSION_CONFIG_INPROGRESS) {
566         MEDIA_ERR_LOG("HCaptureSession::CommitConfig() Need to call BeginConfig before committing configuration");
567         return CAMERA_INVALID_STATE;
568     }
569 
570     std::lock_guard<std::mutex> lock(sessionLock_);
571     int32_t rc = ValidateSessionInputs();
572     if (rc != CAMERA_OK) {
573         return rc;
574     }
575     rc = ValidateSessionOutputs();
576     if (rc != CAMERA_OK) {
577         return rc;
578     }
579 
580     rc = GetCameraDevice(device);
581     if ((rc == CAMERA_OK) && (device == cameraDevice_) && !deletedStreamIds_.empty()) {
582         rc = HdiToServiceError((CamRetCode)(device->GetStreamOperator()->ReleaseStreams(deletedStreamIds_)));
583     }
584 
585     if (rc != CAMERA_OK) {
586         MEDIA_ERR_LOG("HCaptureSession::CommitConfig() Failed to commit config. camera device rc: %{public}d", rc);
587         if (device != nullptr && device != cameraDevice_) {
588             device->Close();
589         }
590         RestorePreviousState(cameraDevice_, false);
591         return rc;
592     }
593 
594     rc = HandleCaptureOuputsConfig(device);
595     if (rc != CAMERA_OK) {
596         MEDIA_ERR_LOG("HCaptureSession::CommitConfig() Failed to commit config. rc: %{public}d", rc);
597         if (device != nullptr && device != cameraDevice_) {
598             device->Close();
599         }
600         RestorePreviousState(cameraDevice_, !deletedStreamIds_.empty());
601         return rc;
602     }
603     if (device != nullptr) {
604         int32_t pid = IPCSkeleton::GetCallingPid();
605         int32_t uid = IPCSkeleton::GetCallingUid();
606         POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, device->GetCameraId().c_str(),
607                                          GetClientBundle(uid));
608     }
609 
610     if (cameraDevice_ != nullptr && device != cameraDevice_) {
611         cameraDevice_->Close();
612         cameraDevice_ = nullptr;
613     }
614     UpdateSessionConfig(device);
615     return rc;
616 }
617 
GetSessionState(CaptureSessionState & sessionState)618 int32_t HCaptureSession::GetSessionState(CaptureSessionState &sessionState)
619 {
620     int32_t rc = CAMERA_OK;
621     sessionState = curState_;
622     return rc;
623 }
624 
Start()625 int32_t HCaptureSession::Start()
626 {
627     uint32_t callerToken = IPCSkeleton::GetCallingTokenID();
628     if (callerToken_ != callerToken) {
629         MEDIA_ERR_LOG("Failed to Start Session, createSession token is : %{public}d, now token is %{public}d",
630             callerToken_, callerToken);
631         return CAMERA_OPERATION_NOT_ALLOWED;
632     }
633     if (curState_ != CaptureSessionState::SESSION_CONFIG_COMMITTED) {
634         MEDIA_ERR_LOG("HCaptureSession::Start(), Invalid session state: %{public}d", curState_);
635         return CAMERA_INVALID_STATE;
636     }
637     std::lock_guard<std::mutex> lock(sessionLock_);
638     if (IsValidTokenId(callerToken)) {
639         if (!Security::AccessToken::PrivacyKit::IsAllowedUsingPermission(callerToken, OHOS_PERMISSION_CAMERA)) {
640             MEDIA_ERR_LOG("Start session is not allowed!");
641             return CAMERA_ALLOC_ERROR;
642         }
643         StartUsingPermissionCallback(callerToken, OHOS_PERMISSION_CAMERA);
644         RegisterPermissionCallback(callerToken, OHOS_PERMISSION_CAMERA);
645     }
646     sptr<HStreamRepeat> curStreamRepeat;
647     int32_t rc = CAMERA_OK;
648     for (auto item = repeatStreams_.begin(); item != repeatStreams_.end(); ++item) {
649         curStreamRepeat = static_cast<HStreamRepeat *>((*item).GetRefPtr());
650         if (!curStreamRepeat->IsVideo()) {
651             rc = curStreamRepeat->Start();
652             if (rc != CAMERA_OK) {
653                 MEDIA_ERR_LOG("HCaptureSession::Start(), Failed to start preview, rc: %{public}d", rc);
654                 break;
655             }
656         }
657     }
658     return rc;
659 }
660 
Stop()661 int32_t HCaptureSession::Stop()
662 {
663     int32_t rc = CAMERA_OK;
664     sptr<HStreamRepeat> curStreamRepeat;
665     if (curState_ != CaptureSessionState::SESSION_CONFIG_COMMITTED) {
666         return CAMERA_INVALID_STATE;
667     }
668     std::lock_guard<std::mutex> lock(sessionLock_);
669     for (auto item = repeatStreams_.begin(); item != repeatStreams_.end(); ++item) {
670         curStreamRepeat = static_cast<HStreamRepeat *>((*item).GetRefPtr());
671         if (!curStreamRepeat->IsVideo()) {
672             rc = curStreamRepeat->Stop();
673             if (rc != CAMERA_OK) {
674                 MEDIA_ERR_LOG("HCaptureSession::Stop(), Failed to stop preview, rc: %{public}d", rc);
675                 break;
676             }
677         }
678     }
679 
680     return rc;
681 }
682 
ClearCaptureSession(pid_t pid)683 void HCaptureSession::ClearCaptureSession(pid_t pid)
684 {
685     MEDIA_DEBUG_LOG("ClearCaptureSession: camera stub services(%{public}zu) pid(%{public}d).", session_.size(), pid);
686     auto it = session_.find(pid);
687     if (it != session_.end()) {
688         session_.erase(it);
689     }
690     MEDIA_DEBUG_LOG("ClearCaptureSession: camera stub services(%{public}zu).", session_.size());
691 }
692 
ReleaseStreams()693 void HCaptureSession::ReleaseStreams()
694 {
695     std::vector<int32_t> streamIds;
696     {
697         std::lock_guard<std::mutex> lock(streamsLock_);
698         sptr<HStreamCommon> curStream;
699         for (auto item = streams_.begin(); item != streams_.end(); ++item) {
700             curStream = *item;
701             if (curStream) {
702                 streamIds.emplace_back(curStream->GetStreamId());
703                 curStream->Release();
704             }
705         }
706         streams_.clear();
707     }
708     repeatStreams_.clear();
709     captureStreams_.clear();
710     metadataStreams_.clear();
711     if ((cameraDevice_ != nullptr) && (cameraDevice_->GetStreamOperator() != nullptr) && !streamIds.empty()) {
712         cameraDevice_->GetStreamOperator()->ReleaseStreams(streamIds);
713     }
714 }
715 
ReleaseInner()716 int32_t HCaptureSession::ReleaseInner()
717 {
718     MEDIA_INFO_LOG("HCaptureSession::ReleaseInner enter");
719     return Release(pid_);
720 }
721 
Release(pid_t pid)722 int32_t HCaptureSession::Release(pid_t pid)
723 {
724     std::lock_guard<std::mutex> lock(sessionLock_);
725     MEDIA_INFO_LOG("HCaptureSession::Release pid(%{public}d).", pid);
726     auto it = session_.find(pid);
727     if (it == session_.end()) {
728         MEDIA_DEBUG_LOG("HCaptureSession::Release session for pid(%{public}d) already released.", pid);
729         return CAMERA_OK;
730     }
731     ReleaseStreams();
732     tempCameraDevices_.clear();
733     if (streamOperatorCallback_ != nullptr) {
734         streamOperatorCallback_->SetCaptureSession(nullptr);
735         streamOperatorCallback_ = nullptr;
736     }
737     if (cameraDevice_ != nullptr) {
738         cameraDevice_->Close();
739         POWERMGR_SYSEVENT_CAMERA_DISCONNECT(cameraDevice_->GetCameraId().c_str());
740         cameraDevice_ = nullptr;
741     }
742     if (IsValidTokenId(callerToken_)) {
743         StopUsingPermissionCallback(callerToken_, OHOS_PERMISSION_CAMERA);
744         UnregisterPermissionCallback(callerToken_);
745     }
746     tempStreams_.clear();
747     ClearCaptureSession(pid);
748     sessionCallback_ = nullptr;
749     cameraHostManager_ = nullptr;
750     return CAMERA_OK;
751 }
752 
RegisterPermissionCallback(const uint32_t callingTokenId,const std::string permissionName)753 void HCaptureSession::RegisterPermissionCallback(const uint32_t callingTokenId, const std::string permissionName)
754 {
755     Security::AccessToken::PermStateChangeScope scopeInfo;
756     scopeInfo.permList = {permissionName};
757     scopeInfo.tokenIDs = {callingTokenId};
758     callbackPtr_ = std::make_shared<PermissionStatusChangeCb>(scopeInfo);
759     callbackPtr_->SetCaptureSession(this);
760     MEDIA_DEBUG_LOG("after tokenId:%{public}d register", callingTokenId);
761     int32_t res = Security::AccessToken::AccessTokenKit::RegisterPermStateChangeCallback(callbackPtr_);
762     if (res != CAMERA_OK) {
763         MEDIA_ERR_LOG("RegisterPermStateChangeCallback failed.");
764     }
765 }
766 
UnregisterPermissionCallback(const uint32_t callingTokenId)767 void HCaptureSession::UnregisterPermissionCallback(const uint32_t callingTokenId)
768 {
769     if (callbackPtr_ == nullptr) {
770         MEDIA_ERR_LOG("callbackPtr_ is null.");
771         return;
772     }
773     int32_t res = Security::AccessToken::AccessTokenKit::UnRegisterPermStateChangeCallback(callbackPtr_);
774     if (res != CAMERA_OK) {
775         MEDIA_ERR_LOG("UnRegisterPermStateChangeCallback failed.");
776     }
777     if (callbackPtr_) {
778         callbackPtr_->SetCaptureSession(nullptr);
779         callbackPtr_ = nullptr;
780     }
781     MEDIA_DEBUG_LOG("after tokenId:%{public}d unregister", callingTokenId);
782 }
783 
DestroyStubObjectForPid(pid_t pid)784 void HCaptureSession::DestroyStubObjectForPid(pid_t pid)
785 {
786     MEDIA_DEBUG_LOG("camera stub services(%{public}zu) pid(%{public}d).", session_.size(), pid);
787     sptr<HCaptureSession> session;
788 
789     auto it = session_.find(pid);
790     if (it != session_.end()) {
791         if (it->second != nullptr) {
792             session = it->second;
793             session->Release(pid);
794         }
795     }
796     MEDIA_DEBUG_LOG("camera stub services(%{public}zu).", session_.size());
797 }
798 
SetCallback(sptr<ICaptureSessionCallback> & callback)799 int32_t HCaptureSession::SetCallback(sptr<ICaptureSessionCallback> &callback)
800 {
801     if (callback == nullptr) {
802         MEDIA_ERR_LOG("HCaptureSession::SetCallback callback is null");
803         return CAMERA_INVALID_ARG;
804     }
805 
806     sessionCallback_ = callback;
807     return CAMERA_OK;
808 }
809 
GetSessionState()810 std::string HCaptureSession::GetSessionState()
811 {
812     std::map<CaptureSessionState, std::string>::const_iterator iter =
813         sessionState_.find(curState_);
814     if (iter != sessionState_.end()) {
815         return iter->second;
816     }
817     return nullptr;
818 }
819 
CameraSessionSummary(std::string & dumpString)820 void HCaptureSession::CameraSessionSummary(std::string& dumpString)
821 {
822     dumpString += "# Number of Camera clients:[" + std::to_string(session_.size()) + "]:\n";
823 }
824 
dumpSessions(std::string & dumpString)825 void HCaptureSession::dumpSessions(std::string& dumpString)
826 {
827     for (auto it = session_.begin(); it != session_.end(); it++) {
828         if (it->second != nullptr) {
829             sptr<HCaptureSession> session = it->second;
830             dumpString += "No. of sessions for client:[" + std::to_string(1) + "]:\n";
831             session->dumpSessionInfo(dumpString);
832         }
833     }
834 }
835 
dumpSessionInfo(std::string & dumpString)836 void HCaptureSession::dumpSessionInfo(std::string& dumpString)
837 {
838     dumpString += "Client pid:[" + std::to_string(pid_)
839         + "]    Client uid:[" + std::to_string(uid_) + "]:\n";
840     dumpString += "session state:[" + GetSessionState() + "]:\n";
841     if (cameraDevice_ != nullptr) {
842         dumpString += "session Camera Id:[" + cameraDevice_->GetCameraId() + "]:\n";
843         dumpString += "session Camera release status:["
844         + std::to_string(cameraDevice_->IsReleaseCameraDevice()) + "]:\n";
845     }
846     for (const auto& stream : captureStreams_) {
847         stream->DumpStreamInfo(dumpString);
848     }
849     for (const auto& stream : repeatStreams_) {
850         stream->DumpStreamInfo(dumpString);
851     }
852     for (const auto& stream : metadataStreams_) {
853         stream->DumpStreamInfo(dumpString);
854     }
855 }
856 
StartUsingPermissionCallback(const uint32_t callingTokenId,const std::string permissionName)857 void HCaptureSession::StartUsingPermissionCallback(const uint32_t callingTokenId, const std::string permissionName)
858 {
859     if (cameraUseCallbackPtr_) {
860         MEDIA_ERR_LOG("has StartUsingPermissionCallback!");
861         return;
862     }
863     cameraUseCallbackPtr_ = std::make_shared<CameraUseStateChangeCb>();
864     cameraUseCallbackPtr_->SetCaptureSession(this);
865     int32_t res = Security::AccessToken::PrivacyKit::StartUsingPermission(
866         callingTokenId, permissionName, cameraUseCallbackPtr_);
867     MEDIA_DEBUG_LOG("after StartUsingPermissionCallback tokenId:%{public}d", callingTokenId);
868     if (res != CAMERA_OK) {
869         MEDIA_ERR_LOG("StartUsingPermissionCallback failed.");
870     }
871 }
872 
StopUsingPermissionCallback(const uint32_t callingTokenId,const std::string permissionName)873 void HCaptureSession::StopUsingPermissionCallback(const uint32_t callingTokenId, const std::string permissionName)
874 {
875     MEDIA_DEBUG_LOG("enter StopUsingPermissionCallback tokenId:%{public}d", callingTokenId);
876     int32_t res = Security::AccessToken::PrivacyKit::StopUsingPermission(callingTokenId, permissionName);
877     if (res != CAMERA_OK) {
878         MEDIA_ERR_LOG("StopUsingPermissionCallback failed.");
879     }
880     if (cameraUseCallbackPtr_) {
881         cameraUseCallbackPtr_->SetCaptureSession(nullptr);
882         cameraUseCallbackPtr_ = nullptr;
883     }
884 }
885 
~PermissionStatusChangeCb()886 PermissionStatusChangeCb::~PermissionStatusChangeCb()
887 {
888     captureSession_ = nullptr;
889 }
890 
SetCaptureSession(sptr<HCaptureSession> captureSession)891 void PermissionStatusChangeCb::SetCaptureSession(sptr<HCaptureSession> captureSession)
892 {
893     captureSession_ = captureSession;
894 }
895 
PermStateChangeCallback(Security::AccessToken::PermStateChangeInfo & result)896 void PermissionStatusChangeCb::PermStateChangeCallback(Security::AccessToken::PermStateChangeInfo& result)
897 {
898     auto item = captureSession_.promote();
899     if ((result.PermStateChangeType == 0) && (item != nullptr)) {
900         item->ReleaseInner();
901     }
902 };
903 
~CameraUseStateChangeCb()904 CameraUseStateChangeCb::~CameraUseStateChangeCb()
905 {
906     captureSession_ = nullptr;
907 }
908 
SetCaptureSession(sptr<HCaptureSession> captureSession)909 void CameraUseStateChangeCb::SetCaptureSession(sptr<HCaptureSession> captureSession)
910 {
911     captureSession_ = captureSession;
912 }
913 
StateChangeNotify(Security::AccessToken::AccessTokenID tokenId,bool isShowing)914 void CameraUseStateChangeCb::StateChangeNotify(Security::AccessToken::AccessTokenID tokenId, bool isShowing)
915 {
916     const int32_t delayProcessTime = 200000;
917     usleep(delayProcessTime);
918     MEDIA_INFO_LOG("enter CameraUseStateChangeNotify tokenId:%{public}d", tokenId);
919     auto item = captureSession_.promote();
920     if ((isShowing == false) && (item != nullptr)) {
921         item->ReleaseInner();
922     }
923 };
924 
925 
StreamOperatorCallback(sptr<HCaptureSession> session)926 StreamOperatorCallback::StreamOperatorCallback(sptr<HCaptureSession> session)
927 {
928     captureSession_ = session;
929 }
930 
~StreamOperatorCallback()931 StreamOperatorCallback::~StreamOperatorCallback()
932 {
933     captureSession_ = nullptr;
934 }
935 
GetStreamByStreamID(int32_t streamId)936 sptr<HStreamCommon> StreamOperatorCallback::GetStreamByStreamID(int32_t streamId)
937 {
938     sptr<HStreamCommon> result = nullptr;
939     if (captureSession_ != nullptr) {
940         std::lock_guard<std::mutex> lock(captureSession_->streamsLock_);
941         for (const auto &item : captureSession_->streams_) {
942             if (item && item->GetStreamId() == streamId) {
943                 result = item;
944                 break;
945             }
946         }
947     }
948     return result;
949 }
950 
OnCaptureStarted(int32_t captureId,const std::vector<int32_t> & streamIds)951 int32_t StreamOperatorCallback::OnCaptureStarted(int32_t captureId,
952                                                  const std::vector<int32_t> &streamIds)
953 {
954     sptr<HStreamCommon> curStream;
955     std::lock_guard<std::mutex> lock(cbMutex_);
956     for (auto item = streamIds.begin(); item != streamIds.end(); ++item) {
957         curStream = GetStreamByStreamID(*item);
958         if (curStream == nullptr) {
959             MEDIA_ERR_LOG("StreamOperatorCallback::OnCaptureStarted StreamId: %{public}d not found", *item);
960             return CAMERA_INVALID_ARG;
961         } else if (curStream->GetStreamType() == StreamType::REPEAT) {
962             static_cast<HStreamRepeat *>(curStream.GetRefPtr())->OnFrameStarted();
963         } else if (curStream->GetStreamType() == StreamType::CAPTURE) {
964             static_cast<HStreamCapture *>(curStream.GetRefPtr())->OnCaptureStarted(captureId);
965         }
966     }
967     return CAMERA_OK;
968 }
969 
OnCaptureEnded(int32_t captureId,const std::vector<CaptureEndedInfo> & infos)970 int32_t StreamOperatorCallback::OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo>& infos)
971 {
972     sptr<HStreamCommon> curStream;
973     CaptureEndedInfo captureInfo;
974     std::lock_guard<std::mutex> lock(cbMutex_);
975     for (auto item = infos.begin(); item != infos.end(); ++item) {
976         captureInfo = *item;
977         curStream = GetStreamByStreamID(captureInfo.streamId_);
978         if (curStream == nullptr) {
979             MEDIA_ERR_LOG("StreamOperatorCallback::OnCaptureEnded StreamId: %{public}d not found."
980                           " Framecount: %{public}d", captureInfo.streamId_, captureInfo.frameCount_);
981             return CAMERA_INVALID_ARG;
982         } else if (curStream->GetStreamType() == StreamType::REPEAT) {
983             static_cast<HStreamRepeat *>(curStream.GetRefPtr())->OnFrameEnded(captureInfo.frameCount_);
984         } else if (curStream->GetStreamType() == StreamType::CAPTURE) {
985             static_cast<HStreamCapture *>(curStream.GetRefPtr())->OnCaptureEnded(captureId, captureInfo.frameCount_);
986         }
987     }
988     return CAMERA_OK;
989 }
990 
OnCaptureError(int32_t captureId,const std::vector<CaptureErrorInfo> & infos)991 int32_t StreamOperatorCallback::OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo>& infos)
992 {
993     sptr<HStreamCommon> curStream;
994     CaptureErrorInfo errInfo;
995     std::lock_guard<std::mutex> lock(cbMutex_);
996     for (auto item = infos.begin(); item != infos.end(); ++item) {
997         errInfo = *item;
998         curStream = GetStreamByStreamID(errInfo.streamId_);
999         if (curStream == nullptr) {
1000             MEDIA_ERR_LOG("StreamOperatorCallback::OnCaptureError StreamId: %{public}d not found."
1001                           " Error: %{public}d", errInfo.streamId_, errInfo.error_);
1002             return CAMERA_INVALID_ARG;
1003         } else if (curStream->GetStreamType() == StreamType::REPEAT) {
1004             static_cast<HStreamRepeat *>(curStream.GetRefPtr())->OnFrameError(errInfo.error_);
1005         } else if (curStream->GetStreamType() == StreamType::CAPTURE) {
1006             static_cast<HStreamCapture *>(curStream.GetRefPtr())->OnCaptureError(captureId, errInfo.error_);
1007         }
1008     }
1009     return CAMERA_OK;
1010 }
1011 
OnFrameShutter(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)1012 int32_t StreamOperatorCallback::OnFrameShutter(int32_t captureId,
1013                                                const std::vector<int32_t> &streamIds,
1014                                                uint64_t timestamp)
1015 {
1016     sptr<HStreamCommon> curStream;
1017     std::lock_guard<std::mutex> lock(cbMutex_);
1018     for (auto item = streamIds.begin(); item != streamIds.end(); ++item) {
1019         curStream = GetStreamByStreamID(*item);
1020         if ((curStream != nullptr) && (curStream->GetStreamType() == StreamType::CAPTURE)) {
1021             static_cast<HStreamCapture *>(curStream.GetRefPtr())->OnFrameShutter(captureId, timestamp);
1022         } else {
1023             MEDIA_ERR_LOG("StreamOperatorCallback::OnFrameShutter StreamId: %{public}d not found", *item);
1024             return CAMERA_INVALID_ARG;
1025         }
1026     }
1027     return CAMERA_OK;
1028 }
1029 
SetCaptureSession(sptr<HCaptureSession> captureSession)1030 void StreamOperatorCallback::SetCaptureSession(sptr<HCaptureSession> captureSession)
1031 {
1032     std::lock_guard<std::mutex> lock(cbMutex_);
1033     captureSession_ = captureSession;
1034 }
1035 } // namespace CameraStandard
1036 } // namespace OHOS
1037