/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "stream_operator_service.h" #include "stream_operator_service_callback.h" #include "camera_service_type_converter.h" #include "camera_hal_hisysevent.h" namespace OHOS::Camera { StreamOperatorService::StreamOperatorService(OHOS::sptr streamOperatorVdi) : streamOperatorVdi_(streamOperatorVdi) { CAMERA_LOGD("ctor, instance"); } StreamOperatorService::~StreamOperatorService() { CAMERA_LOGD("dtor, instance"); } int32_t StreamOperatorService::IsStreamsSupported(OperationMode mode, const std::vector &modeSetting, const std::vector &infos, StreamSupportType &type) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); std::vector vdiInfos; for (auto info : infos) { VdiStreamInfo vdiInfo; ConvertStreamInfoHdiToVdi(info, vdiInfo); vdiInfos.push_back(vdiInfo); } VdiStreamSupportType vdiType = static_cast(type); int32_t ret = streamOperatorVdi_->IsStreamsSupported(static_cast(mode), modeSetting, vdiInfos, vdiType); type = static_cast(vdiType); return ret; } int32_t StreamOperatorService::CreateStreams(const std::vector &streamInfos) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); std::vector vdiStreamInfos; for (auto info : streamInfos) { VdiStreamInfo vdiInfo; ConvertStreamInfoHdiToVdi(info, vdiInfo); vdiStreamInfos.push_back(vdiInfo); } return streamOperatorVdi_->CreateStreams(vdiStreamInfos); } int32_t StreamOperatorService::ReleaseStreams(const std::vector &streamIds) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); return streamOperatorVdi_->ReleaseStreams(streamIds); } int32_t StreamOperatorService::CommitStreams(OperationMode mode, const std::vector &modeSetting) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); return streamOperatorVdi_->CommitStreams(static_cast(mode), modeSetting); } int32_t StreamOperatorService::GetStreamAttributes(std::vector &attributes) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); std::vector vdiAttributes; for (auto attribute : attributes) { VdiStreamAttribute vdiAttribute; ConvertStreamAttributeHdiToVdi(attribute, vdiAttribute); vdiAttributes.push_back(vdiAttribute); } int32_t ret = streamOperatorVdi_->GetStreamAttributes(vdiAttributes); std::vector().swap(attributes); for (auto attribute : vdiAttributes) { StreamAttribute hdiAttribute; ConvertStreamAttributeVdiToHdi(attribute, hdiAttribute); attributes.push_back(hdiAttribute); } return ret; } int32_t StreamOperatorService::AttachBufferQueue(int32_t streamId, const sptr &bufferProducer) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); return streamOperatorVdi_->AttachBufferQueue(streamId, bufferProducer); } int32_t StreamOperatorService::DetachBufferQueue(int32_t streamId) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); return streamOperatorVdi_->DetachBufferQueue(streamId); } int32_t StreamOperatorService::Capture(int32_t captureId, const CaptureInfo &info, bool isStreaming) { CAMERAHALPERFSYSEVENT(TIME_FOR_CAPTURE); CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); VdiCaptureInfo vdiInfo; ConvertCaptureInfoHdiToVdi(info, vdiInfo); return streamOperatorVdi_->Capture(captureId, vdiInfo, isStreaming); } int32_t StreamOperatorService::CancelCapture(int32_t captureId) { CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); return streamOperatorVdi_->CancelCapture(captureId); } int32_t StreamOperatorService::ChangeToOfflineStream(const std::vector &streamIds, const sptr &callbackObj, sptr &offlineOperator) { OHOS::sptr offlineOperatorVdi = nullptr; CHECK_IF_PTR_NULL_RETURN_VALUE(streamOperatorVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT); OHOS::sptr vdiCallbackObj = new StreamOperatorServiceCallback(callbackObj); if (vdiCallbackObj == nullptr) { CAMERA_LOGE("Change to offline stream error, vdiCallbackObj is nullptr"); return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES; } int32_t ret = streamOperatorVdi_->ChangeToOfflineStream(streamIds, vdiCallbackObj, offlineOperatorVdi); if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) { CAMERA_LOGE("Change to offline stream error, ret=%{public}d", ret); return ret; } if (offlineOperatorVdi == nullptr) { CAMERA_LOGE("Change to offline stream error, offlineOperatorVdi is nullptr"); return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES; } offlineOperator = new OfflineStreamOperatorService(offlineOperatorVdi); if (offlineOperator == nullptr) { CAMERA_LOGE("Change to offline stream error, offlineOperator is nullptr"); return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES; } return OHOS::HDI::Camera::V1_0::NO_ERROR; } } // end namespace OHOS::Camera