From 6b2cf0fac0a17c511b15f795413bb176145529f7 Mon Sep 17 00:00:00 2001 From: lwx1140380 Date: Fri, 27 May 2022 09:35:09 +0800 Subject: [PATCH] camera Chinese and English comments submitted Signed-off-by: lwx1140380 --- en/device_api/hdi/camera/icamera_device.h | 162 +++++++ .../hdi/camera/icamera_device_callback.h | 78 ++++ en/device_api/hdi/camera/icamera_host.h | 157 +++++++ .../hdi/camera/icamera_host_callback.h | 86 ++++ .../hdi/camera/ioffline_stream_operator.h | 91 ++++ en/device_api/hdi/camera/istream_operator.h | 269 +++++++++++ .../hdi/camera/istream_operator_callback.h | 108 +++++ en/device_api/hdi/camera/types.h | 442 ++++++++++++++++++ zh-cn/device_api/hdi/camera/icamera_device.h | 159 +++++++ .../hdi/camera/icamera_device_callback.h | 76 +++ zh-cn/device_api/hdi/camera/icamera_host.h | 154 ++++++ .../hdi/camera/icamera_host_callback.h | 85 ++++ .../hdi/camera/ioffline_stream_operator.h | 91 ++++ .../device_api/hdi/camera/istream_operator.h | 252 ++++++++++ .../hdi/camera/istream_operator_callback.h | 110 +++++ zh-cn/device_api/hdi/camera/types.h | 436 +++++++++++++++++ 16 files changed, 2756 insertions(+) create mode 100644 en/device_api/hdi/camera/icamera_device.h create mode 100644 en/device_api/hdi/camera/icamera_device_callback.h create mode 100644 en/device_api/hdi/camera/icamera_host.h create mode 100644 en/device_api/hdi/camera/icamera_host_callback.h create mode 100644 en/device_api/hdi/camera/ioffline_stream_operator.h create mode 100644 en/device_api/hdi/camera/istream_operator.h create mode 100644 en/device_api/hdi/camera/istream_operator_callback.h create mode 100644 en/device_api/hdi/camera/types.h create mode 100644 zh-cn/device_api/hdi/camera/icamera_device.h create mode 100644 zh-cn/device_api/hdi/camera/icamera_device_callback.h create mode 100644 zh-cn/device_api/hdi/camera/icamera_host.h create mode 100644 zh-cn/device_api/hdi/camera/icamera_host_callback.h create mode 100644 zh-cn/device_api/hdi/camera/ioffline_stream_operator.h create mode 100644 zh-cn/device_api/hdi/camera/istream_operator.h create mode 100644 zh-cn/device_api/hdi/camera/istream_operator_callback.h create mode 100644 zh-cn/device_api/hdi/camera/types.h diff --git a/en/device_api/hdi/camera/icamera_device.h b/en/device_api/hdi/camera/icamera_device.h new file mode 100644 index 00000000..25b65631 --- /dev/null +++ b/en/device_api/hdi/camera/icamera_device.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file icamera_device.h + * + * @brief Declares APIs for camera device operations. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_DEVICE_CLIENT_INF_H +#define HDI_CAMERA_DEVICE_CLIENT_INF_H + +#include +#include +#include +#include "types.h" +#include "icamera_device_callback.h" +#include "istream_operator.h" +#include "istream_operator_callback.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDevice : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.Device"); + virtual ~ICameraDevice() {} + + /** + * @brief Obtains the stream operation handle. + * + * @param callback Indicates a stream callback. For details, see {@link IStreamOperatorCallback}. + * {@link OnCaptureStarted} and {@link OnCaptureEnded} are used to report the start and end of capture, + * and {@link OnCaptureError} is used to report a capture error. + * + * @param streamOperator Indicates the stream operation handle. + * + * @return Returns NO_ERROR if the operation is successful; returns + * an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetStreamOperator( + const OHOS::sptr &callback, + OHOS::sptr &streamOperator) = 0; + + /** + * @brief Updates camera device control parameters. + * + * @param settings Indicates the camera parameters, including the sensor frame rate and + * 3A parameters. 3A stands for automatic focus (AF), automatic exposure (AE), and automatic white-balance (​AWB). + * + * @return Returns NO_ERROR if the operation is successful; returns an error code + * defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode UpdateSettings(const std::shared_ptr &settings) = 0; + + /** + * @brief Sets the metadata reporting mode. + * + * @param mode Indicates the metadata reporting mode to set, which can be frame-by-frame reporting + * or reporting upon device status change. For details, see {@link ResultCallbackMode}. + * + * @return Returns NO_ERROR if the operation is successful; returns an error + * code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetResultMode(const ResultCallbackMode &mode) = 0; + + /** + * @brief Obtains enabled metadata. + * + * Metadata to be reported is enabled by calling {@link EnableResult}. + * + * @param results Indicates all enabled metadata. + * + * @return Returns NO_ERROR if the operation is successful; returns an error + * code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetEnabledResults(std::vector &results) = 0; + + /** + * @brief Enables metadata reporting. + * + * Only metadata that is enabled can be reported by using {@link OnResult}. + * + * @param results Indicates the metadata for which reporting is to be enabled. + * + * @return Returns NO_ERROR if the operation is successful; returns an error + * code defined in {@link CamRetCode} otherwise. + * + * @see DisableResult + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode EnableResult(const std::vector &results) = 0; + + /** + * @brief Disables metadata reporting. + * + * After metadata reporting is disabled, the metadata is not reported by calling {@link OnResult}. + * To enable metadata reporting, you must call {@link EnableResult}. + * + * @param results Indicates the metadata for which reporting is to be disabled. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @see EnableResult + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode DisableResult(const std::vector &results) = 0; + + /** + * @brief Closes the camera device. + * + * @see OpenCamera + * + * @since 1.0 + * @version 1.0 + */ + virtual void Close() = 0; +}; +} +#endif /** HDI_CAMERA_DEVICE_CLIENT_INF_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/icamera_device_callback.h b/en/device_api/hdi/camera/icamera_device_callback.h new file mode 100644 index 00000000..bb8ad407 --- /dev/null +++ b/en/device_api/hdi/camera/icamera_device_callback.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file icamera_device_callback.h + * + * @brief Declares callbacks for reporting camera device errors and metadata. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_DEVICE_CALLBACK_SERVER_H +#define HDI_CAMERA_DEVICE_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDeviceCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.DeviceCallback"); + virtual ~ICameraDeviceCallback() {} + +public: + /** + * @brief Called when an error occurs on the camera device. The caller needs to implement this function. + * + * @param type Indicates the error type. For details, see {@link ErrorType}. + * @param errorCode Indicates the error code. This parameter is not used currently. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnError(ErrorType type, int32_t errorCode) = 0; + + /** + * @brief Called to report metadata related to the camera device. + * For details about the reporting mode, see {@link SetResultMode}. + * + * @param timestamp Indicates the timestamp when the metadata is reported. + * @param result Indicates the metadata reported. The reported metadata is specified by {@link EnableResult}. + * You can call {@link GetEnabledResults} to obtain enabled metadata and + * call {@link DisableResult} to disable metadata reporting. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnResult(uint64_t timestamp, const std::shared_ptr &result) = 0; +}; +} +#endif /** HDI_CAMERA_DEVICE_CALLBACK_SERVER_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/icamera_host.h b/en/device_api/hdi/camera/icamera_host.h new file mode 100644 index 00000000..936e3453 --- /dev/null +++ b/en/device_api/hdi/camera/icamera_host.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file icamera_host.h + * + * @brief Management class of the camera service that provides Hardware Driver Interfaces (HDIs) for the upper layer. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_HOST_CLIENT_INF_H +#define HDI_CAMERA_HOST_CLIENT_INF_H + +#include +#include +#include +#include "icamera_device_callback.h" +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDevice; +class ICameraHostCallback; +class ICameraDeviceCallback; +class ICameraHost : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.Host"); + virtual ~ICameraHost() {} + /** + * @brief Obtains an ICameraHost instance. + * + * This function provides the entry to the camera service. You must use this function to + * obtain an ICameraHost instance before performing other operations. + * + * @param serviceName Indicates the name of the ICameraHost instance to obtain. + * Currently, the name is fixed at camera_service. + * + * @return Returns the ICameraHost instance if the operation is successful; + * @return Returns nullptr otherwise. + * + * @since 1.0 + * @version 1.0 + */ + static sptr Get(const char *serviceName); + + /** + * @brief Sets callbacks. For details about the callbacks, see {@link ICameraHostCallback}. + * + * @param callback Indicates the callbacks to set. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetCallback(const OHOS::sptr &callback) = 0; + + /** + * @brief Obtains the IDs of available camera devices. + * + * @param cameraIds Indicates the IDs of available camera devices. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetCameraIds(std::vector &cameraIds) = 0; + + /** + * @brief Obtains the abilities of a camera device. + * + * @param cameraId Indicates the ID of the camera device, which can be obtained by calling {@link GetCameraIds}. + * + * @param ability Returns the abilities of the camera device. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetCameraAbility(const std::string &cameraId, + std::shared_ptr &ability) = 0; + + /** + * @brief Opens a camera device. + * + * By calling this function, you can obtain the ICameraDevice instance and + * operate the specific camera device mapping to the instance. + * + * @param cameraId Indicates the ID of the camera device, which can be obtained by calling {@link GetCameraIds}. + * @param callback Indicates the callback related to the camera. For details, see {@link ICameraDeviceCallback}. + * @param device Indicates the ICameraDevice instance corresponding to the ID of the camera device. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode OpenCamera(const std::string &cameraId, + const OHOS::sptr &callback, + OHOS::sptr &device) = 0; + + /** + * @brief Turns on or off the flash. + * + * This function can be used only by the caller who has opened the camera device specified by cameraId. + * + * @param cameraId Indicates the ID of the camera whose flash is to be turned on or off. + * @param isEnable Specifies whether to turn on or off the flash. The value true + * means to turn on the flash, and false means the opposite. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetFlashlight(const std::string &cameraId, bool &isEnable) = 0; +}; +} +#endif /** HDI_CAMERA_HOST_CLIENT_INF_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/icamera_host_callback.h b/en/device_api/hdi/camera/icamera_host_callback.h new file mode 100644 index 00000000..3c12491c --- /dev/null +++ b/en/device_api/hdi/camera/icamera_host_callback.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file icamera_host_callback.h + * + * @brief Declares callbacks for status changes of cameras and flashes. The caller needs to implement the callbacks. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_HOST_CALLBACK_SERVER_H +#define HDI_CAMERA_HOST_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraHostCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.HostCallback"); + virtual ~ICameraHostCallback() {} + +public: + /** + * @brief Called when the camera status changes to report the latest status. + * + * @param cameraId Indicates the ID of the camera whose status changes. + * @param status Indicates the latest status of the camera. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCameraStatus(const std::string &cameraId, CameraStatus status) = 0; + + /** + * @brief Called when the flash status changes to report the latest status. + * + * @param cameraId Indicates the ID of the camera to which the flash whose status changes is bound. + * @param status Indicates the latest status of the flash. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnFlashlightStatus(const std::string &cameraId, FlashlightStatus status) = 0; + + /** + * @brief Called when the camera event occurs. + * + * @param cameraId Indicates the ID of the camera to which the camera event is bound. + * @param event Indicates the camera event type. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCameraEvent(const std::string &cameraId, CameraEvent event) = 0; +}; +} +#endif /** HDI_CAMERA_HOST_CALLBACK_SERVER_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/ioffline_stream_operator.h b/en/device_api/hdi/camera/ioffline_stream_operator.h new file mode 100644 index 00000000..f1354f26 --- /dev/null +++ b/en/device_api/hdi/camera/ioffline_stream_operator.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file ioffline_stream_operator.h + * + * @brief Declares APIs for offline stream operations. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H +#define HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IOfflineStreamOperator : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.OfflineStreamOperator"); + + virtual ~IOfflineStreamOperator() {} + + /** + * @brief Cancels a capture request. + * + * @param captureId Indicates the ID of the capture request to cancel. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CancelCapture(int captureId) = 0; + + /** + * @brief Releases offline streams. + * + * @param streamIds Indicates the IDs of the offline streams to release. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ReleaseStreams(const std::vector &streamIds) = 0; + + /** + * @brief Releases all offline streams. + * + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode Release() = 0; +}; +} +#endif /** HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/istream_operator.h b/en/device_api/hdi/camera/istream_operator.h new file mode 100644 index 00000000..2ec319d8 --- /dev/null +++ b/en/device_api/hdi/camera/istream_operator.h @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file istream_operator.h + * + * @brief Declares APIs for stream operations. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_STREAM_OPERATOR_CLIENT_INF_H +#define HDI_STREAM_OPERATOR_CLIENT_INF_H + +#include +#include +#include +#include "istream_operator_callback.h" +#include "ioffline_stream_operator.h" +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IBufferProducer; +class IStreamOperator : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.StreamOperator"); + + virtual ~IStreamOperator() {} + + /** + * @brief Checks whether a specific stream can be dynamically created. + * + * A stream is a sequence of data elements output from a bottom-layer device, processed by the current module, + * and then transmitted to an upper-layer service or application. + * The current module supports preview streams, video streams, photographing streams, and the like. + * For details, see {@link StreamIntent}. + * + * This function is used to check whether a stream or streams can be dynamically created based on the + * operation mode, configuration information, and existing streams in the current module. + * If the streams can be created without stopping the existing streams or making the upper-layer service or + * application unaware of the stopping of the existing streams, + * type is set to DYNAMIC_SUPPORTED so that the upper-layer service or application + * can directly add the new stream. + * If the streams can be created only after the upper-layer service or application stops capturing all streams, + * type is set to RE_CONFIGURED_REQUIRED. + * If the streams are not supported, type is set to NOT_SUPPORTED. + * This function must be called prior to {@link CreateStreams}. + * + * @param mode Indicates the operation mode of the streams. For details, see {@link OperationMode}. + * @param modeSetting Indicates the stream configuration parameters, including the frame rate and 3A. + * 3A stands for automatic focus (AF), automatic exposure (AE), and automatic white-balance (AWB). + * @param info Indicates the stream configuration information. For details, see {@link StreamInfo}. + * @param type Indicates the support type of the dynamically created stream. + * The supported types are defined in {@link StreamSupportType}. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode IsStreamsSupported( + OperationMode mode, + const std::shared_ptr &modeSetting, + const std::vector> &info, + StreamSupportType &type) = 0; + + /** + * @brief Creates streams. + * + * Before calling this function, you must use {@link IsStreamsSupported} to check whether the hardware + * abstraction layer (HAL) supports the streams to create. + * + * @param streamInfos Indicates the list of stream information, which is defined by {@link StreamInfo}. + * The passed stream information may be changed. Therefore, you can run {@link GetStreamAttributes} to + * obtain the latest stream attributes after the stream is created. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CreateStreams(const std::vector> &streamInfos) = 0; + + /** + * @brief Releases streams. + * + * @param streamIds Indicates the IDs of the streams to release. + * + * @return Returns NO_ERROR if the operation is successful; + * returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ReleaseStreams(const std::vector &streamIds) = 0; + + /** + * @brief Configures a stream. + * + * This function must be called after {@link CreateStreams}. + * + * @param mode Indicates the operation mode of the stream. For details, see {@link OperationMode}. + * @param modeSetting Indicates the stream configuration parameters, including the frame rate and zoom information. + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CommitStreams(OperationMode mode, + const std::shared_ptr &modeSetting) = 0; + + /** + * @brief Obtains stream attributes. + * + * @param attributes Indicates the obtained stream attributes. + * Stream information passed by the streamInfos parameter in {@link CreateStreams} + * may be overridden. Therefore, the stream attributes obtained by using this function may be + * different from the stream information passed in {@link CreateStreams}. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetStreamAttributes( + std::vector> &attributes) = 0; + + /** + * @brief Attaches a producer handle to a stream. + * + * If a producer handle has been specified during stream creation (by {@link CreateStreams}), + * you do not need to call this function. If you want to attach a new procedure handle, + * call {@link DetachBufferQueue} to detach the existing procedure handle and then + * call this function to attach the new one. + * You do not need to attach a procedure handle for IoT devices that do not support or require + * image data caching and transferring of preview streams. + * In this case, set bufferQueue_ in the {@link StreamInfo} parameter of {@link CreateStreams} + * to null, + * and set tunneledMode_ to false. + * + * @param streamId Indicates the ID of the stream to which the procedure handle is to be attached. + * @param producer Indicates the producer handle to be attached. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode AttachBufferQueue(int streamId, const OHOS::sptr &producer) = 0; + + /** + * @brief Detaches the producer handle from a stream. + * + * @param streamId Indicates the ID of the stream from which the procedure handle is to be detached. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode DetachBufferQueue(int streamId) = 0; + + /** + * @brief Captures an image. + * + * This function must be called after {@link CommitStreams}. + * There are two image capture modes: continuous capture and single capture. + * A continuous capture is performed inside the module after being triggered, + * and the consumer can continuously receive captured image data after calling this function only once. + * If this function is called again, the current capture is stopped, the capture request configuration is updated, + * and a new capture is performed. + * This mode is mainly used in preview, video recording, or continuous shooting scenarios. + * After a single capture is triggered, only one frame of image data is captured. + * This mode applies to the single shooting scenario. + * When the capture is started, {@link OnCaptureStarted} is called to notify of the start. + * To stop a continuous capture, call {@link CancelCapture}. + * When the capture ends, {@link OnCaptureEnded} is called to notify the caller of the information + * such as the number of captured frames. + * enableShutterCallback_ in {@link CaptureInfo} is used to enable the callback for each capture. + * After the callback is enabled, {@link OnFrameShutter} is called upon each capture. + * In the scenario where multiple streams are captured at the same time, this module ensures that + * the captured data of multiple streams is reported simultaneously. + * + * @param captureId Indicates the ID of the capture request. You must ensure that the ID of the + * capture request is unique when the camera is started. + * @param info Indicates the capture request configuration information. For details, see {@link CaptureInfo}. + * @param isStreaming Specifies whether to continuously capture images. + * The value true means to continuously capture images, and false means the opposite. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode Capture(int captureId, + const std::shared_ptr &info, bool isStreaming) = 0; + + /** + * @brief Cancels a capture. + * + * {@link OnCaptureEnded} is called when a continuous capture is canceled. + * + * @param captureId Indicates the ID of the capture request to cancel. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CancelCapture(int captureId) = 0; + + /** + * @brief Converts a specific stream to an offline stream. + * + * Only photographing streams can be converted into offline streams. + * Due to the limited processing capability, some devices may spend a long period of time on + * algorithm processing during photographing, causing the capture requests to stack in the module. + * Converting to an offline stream enables the bottom-layer device to close and + * the offline stream to take over for subsequent processing. + * + * @param streamIds Indicates the IDs of the streams to be converted. + * @param callback Indicates the callback for conversion to offline streams. + * @param offlineOperator Indicates the offline stream after conversion. + * + * @return Returns NO_ERROR if the operation is successful; + * @return Returns an error code defined in {@link CamRetCode} otherwise. + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ChangeToOfflineStream(const std::vector &streamIds, + OHOS::sptr &callback, + OHOS::sptr &offlineOperator) = 0; +}; +} +#endif /** HDI_STREAM_OPERATOR_CLIENT_INF_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/istream_operator_callback.h b/en/device_api/hdi/camera/istream_operator_callback.h new file mode 100644 index 00000000..cdc86080 --- /dev/null +++ b/en/device_api/hdi/camera/istream_operator_callback.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file istream_operator_callback.h + * + * @brief Declares callbacks related to {@link IStreamOperator}. The caller needs to implement these callbacks. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_STREAM_OPERATOR_CALLBACK_SERVER_H +#define HDI_STREAM_OPERATOR_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IStreamOperatorCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.StreamOperatorCallback"); + virtual ~IStreamOperatorCallback() {} + +public: + /** + * @brief Called when the capture starts. + * + * @param captureId Indicates the ID of the capture request corresponding to the callback. + * @param streamIds Indicates the IDs of the streams corresponding to the callback. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureStarted(int32_t captureId, const std::vector &streamIds) = 0; + + /** + * @brief Called when the capture ends. + * + * @param captureId Indicates the ID of the capture request corresponding to the callback. + * @param infos Indicates information related to the capture when it ends. + * + * @see OnCaptureStarted + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureEnded(int32_t captureId, + const std::vector> &infos) = 0; + + /** + * @brief Called when an error occurs during the capture. + * + * @param captureId Indicates the ID of the capture request corresponding to the callback. + * @param infos Indicates a list of capture error messages. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureError(int32_t captureId, + const std::vector> &infos) = 0; + + /** + * @brief Called when a frame is captured. + * + * This callback is enabled by using enableShutterCallback_ + * in the {@link CaptureInfo} parameter of {@link Capture}. + * When enableShutterCallback_ is set to true, + * this callback is triggered each time a frame is captured. + * + * @param captureId Indicates the ID of the capture request corresponding to the callback. + * @param streamIds Indicates the IDs of the streams corresponding to the callback. + * @param timestamp Indicates the timestamp when the callback is invoked. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnFrameShutter(int32_t captureId, + const std::vector &streamIds, uint64_t timestamp) = 0; +}; +} +#endif /** HDI_STREAM_OPERATOR_CALLBACK_SERVER_H \ No newline at end of file diff --git a/en/device_api/hdi/camera/types.h b/en/device_api/hdi/camera/types.h new file mode 100644 index 00000000..d25613ba --- /dev/null +++ b/en/device_api/hdi/camera/types.h @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief + * + * + * + * @since 1.0 + */ + +/** + * @file types.h + * + * @brief Declares data types + * used by the Hardware Driver Interfaces (HDIs) of this module. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef CAMERA_DEVICE_DRIVER_TYPES_H +#define CAMERA_DEVICE_DRIVER_TYPES_H + +#include +#include +#include +#include +#include +#include "camera_metadata_info.h" +#include "type_common.h" + +namespace OHOS::Camera { +using CameraAbility = CameraMetadata; +using CameraSetting = CameraMetadata; + +/** + * @brief Enumerates return values of the HDIs. + */ +enum CamRetCode : int32_t { + /** + * Successful call. + */ + NO_ERROR = 0, + + /** + * The camera device is busy. + */ + CAMERA_BUSY = -1, + + /** + * Insufficient resources. + */ + INSUFFICIENT_RESOURCES = -2, + + /** + * Invalid parameters. + */ + INVALID_ARGUMENT = -3, + + /** + * Unsupported function. + */ + METHOD_NOT_SUPPORTED = -4, + + /** + * The camera device is closed. + */ + CAMERA_CLOSED = -5, + + /** + * A critical error occurs at the driver layer. + */ + DEVICE_ERROR = -6, +}; + +/** + * @brief Enumerates metadata reporting modes. + */ +enum ResultCallbackMode : int32_t { + /** + * Frame-by-frame reporting + */ + PER_FRAME, + + /** + * Reporting upon device status change + */ + ON_CHANGED +}; + +/** + * @brief Enumerates stream operation modes. + */ +enum OperationMode : int32_t { + /** + * Normal + */ + NORMAL = 0, +}; + +/** + * @brief Enumerates stream types. + */ +enum StreamIntent : int32_t { + /** + * Preview streams, indicating that stream data is used for preview + */ + PREVIEW = 0, + + /** + * Video streams, indicating that stream data is used to encode and generate videos + */ + VIDEO = 1, + + /** + * Photographing streams, indicating that stream data is used to encode and generate images + */ + STILL_CAPTURE = 2, + + /** + * Stream data that is used to store thumbnails + */ + POST_VIEW = 3, + + /** + * Stream data that is used for image analysis + */ + ANALYZE = 4, + + /** + * Custom type + */ + CUSTOM = 5, +}; + +/** + * @brief Enumerates encoding types of stream data. + */ +enum EncodeType : int32_t { + /** + * Unspecified + */ + ENCODE_TYPE_NULL = 0, + + /** + * H.264 + */ + ENCODE_TYPE_H264 = 1, + + /** + * H.265 + */ + ENCODE_TYPE_H265 = 2, + + /** + * JPEG + */ + ENCODE_TYPE_JPEG = 3, +}; + +/** + * @brief Defines the stream information, which is used to pass configuration parameters during stream creation. + */ +struct StreamInfo { + /** + * Stream ID, which uniquely identifies a stream on a camera device. + */ + int streamId_; + + /** + * Image width. + */ + int width_; + + /** + * Image height. + */ + int height_; + + /** + * Image format. + */ + int format_; + + /** + * Image color space. + */ + int datasapce_; + + /** + * Stream type. + */ + StreamIntent intent_; + + /** + * Tunnel mode. The value true means that the tunnel mode is enabled, and false means the opposite. + * + * After the tunnel mode is enabled, + * the hardware abstraction layer (HAL) does not directly interact with the upper layer. + * Instead, it uses the producer handle provided by the graphics layer to transfer frame data. + * You need to disable the tunnel mode for IoT devices that do not support + * or require image data caching and forwarding of preview streams. + */ + bool tunneledMode_; + + /** + * Producer handle provided by the graphics layer. + */ + OHOS::sptr bufferQueue_; + + /** + * Minimum frame interval. + */ + int minFrameDuration_; + + /** + * Encoding type. + */ + EncodeType encodeType_; +}; + +/** + * @brief Enumerates the support types of the stream. For details about the application scenario, + * see {@link IsStreamsSupported}. + */ +enum StreamSupportType : int32_t { + /** + * The stream can be dynamically created, and the corresponding stream parameters take effect directly. + */ + DYNAMIC_SUPPORTED, + + /** + * The stream cannot be dynamically created, + * and the corresponding parameters take effect only after the existing stream is stopped and reconfigured. + */ + RE_CONFIGURED_REQUIRED, + + /** + * The stream cannot be dynamically created. + */ + NOT_SUPPORTED, +}; + +/** + * @brief Defines the stream attributes. + */ +struct StreamAttribute { + /** + * Stream ID, which uniquely identifies a stream on a camera device. + */ + int streamId_; + + /** + * Image width. + */ + int width_; + + /** + * Image height. + */ + int height_; + + /** + * New image format. + */ + int overrideFormat_; + + /** + * New image color space. + */ + int overrideDatasapce_; + + /** + * New procedure usage. + */ + int producerUsage_; + + /** + * New number of produce buffers. + */ + int producerBufferCount_; + + /** + * Maximum number of frames that can be captured in a continuous capture. + */ + int maxBatchCaptureCount_; + + /** + * Maximum number of concurrent capture requests. The default value is 1. + */ + int maxCaptureCount_; +}; + +/** + * @brief Defines the information about a capture request. + */ +struct CaptureInfo { + /** + * IDs of captured streams. + */ + std::vector streamIds_; + + /** + * Captured configuration information. + */ + std::shared_ptr captureSetting_; + + /** + * Whether to enable callback for each capture. If enabled, {@link OnFrameShutter} is called upon each capture. + */ + bool enableShutterCallback_; +}; + +/** + * @brief Enumerates camera device statuses. + */ +enum CameraStatus { + /** + * The camera device is not in position or is unavailable. + */ + UN_AVAILABLE = 0, + + /** + * The camera device is available. + */ + AVAILABLE = 1, +}; + +/** + * @brief Enumerates flash statuses. + */ +enum FlashlightStatus : uint32_t { + /** + * The flash is off. + */ + FLASHLIGHT_OFF = 0, + + /** + * The flash is on. + */ + FLASHLIGHT_ON = 1, + + /** + * The flash is unavailable. + */ + FLASHLIGHT_UNAVAILABLE = 2, +}; + +/** + * @brief Camera event. + */ +enum CameraEvent : uint32_t { + /** + * Camera device add event. + */ + CAMERA_EVENT_DEVICE_ADD = 0, + + /** + * Camera device remove event. + */ + CAMERA_EVENT_DEVICE_RMV = 1, +}; + +/** + * @brief Enumerates camera device error types, which are used by {@link OnError}. + */ +enum ErrorType : uint32_t { + /** + * A critical error occurs. The camera device needs to be closed. + */ + FATAL_ERROR = 0, + + /** + * A request timeout occurs. The camera device needs to be closed. + */ + REQUEST_TIMEOUT = 1, +}; + +/** + * @brief Defines the information about the end of packet capture, which is used by {@link OnCaptureEnded}. + */ +struct CaptureEndedInfo { + /** + * ID of a captured stream. + */ + int streamId_; + + /** + * Number of frames that have been captured when the capture ends. + */ + int frameCount_; +}; + +/** + * @brief Enumerates stream error types, which are used by {@link CaptureErrorInfo}. + */ +enum StreamError { + /** + * Unknown error + */ + UNKNOWN_ERROR = 0, + + /** + * Packet loss + */ + BUFFER_LOST = 1, +}; + +/** + * @brief Defines the stream error information, which is used by {@link OnCaptureError}. + */ +struct CaptureErrorInfo { + /** + * Stream ID + */ + int streamId_; + + /** + * Error type + */ + StreamError error_; +}; + +using MetaType = int32_t; +} +#endif /** CAMERA_DEVICE_DRIVER_TYPES_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/icamera_device.h b/zh-cn/device_api/hdi/camera/icamera_device.h new file mode 100644 index 00000000..0545e320 --- /dev/null +++ b/zh-cn/device_api/hdi/camera/icamera_device.h @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file icamera_device.h + * + * @brief Camera设备操作接口。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_DEVICE_CLIENT_INF_H +#define HDI_CAMERA_DEVICE_CLIENT_INF_H + +#include +#include +#include +#include "types.h" +#include "icamera_device_callback.h" +#include "istream_operator.h" +#include "istream_operator_callback.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDevice : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.Device"); + virtual ~ICameraDevice() {} + + /** + * @brief 获取流操作句柄。 + * + * @param callback [IN] 设置流回调接口,详细可查看 {@link IStreamOperatorCallback}, + * 用于上报捕获开始 {@link OnCaptureStarted},捕获结束 {@link OnCaptureEnded}, + * {@link OnCaptureError} 捕获错误等信息。 + * + * @param streamOperator [OUT] 返回流操作句柄。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetStreamOperator( + const OHOS::sptr &callback, + OHOS::sptr &streamOperator) = 0; + + /** + * @brief 更新设备控制参数。 + * + * @param settings [IN] Camera设置参数,包括sensor帧率,3A相关参数等。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode UpdateSettings(const std::shared_ptr &settings) = 0; + + /** + * @brief 设置metadata上报模式,逐帧上报还是设备状态变化时上报。 + * + * @param mode [IN] metadata的上报模式,逐帧上报或者设备状态变化时上报,查看 {@link ResultCallbackMode}。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetResultMode(const ResultCallbackMode &mode) = 0; + + /** + * @brief 查询使能的metadata。 + * + * {@link EnableResult} 使能需要上报的metadata之后,可通过此接口查询使能的metadata。 + * + * @param results [OUT] 所有使能的metadata。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetEnabledResults(std::vector &results) = 0; + + /** + * @brief 打开metadata上报开关。 + * + * {@link OnResult} 只上报此接口使能后的metadata。 + * + * @param results [IN] 需要打开上报开关的metadata。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see DisableResult + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode EnableResult(const std::vector &results) = 0; + + /** + * @brief 关闭metadata上报开关。 + * + * 屏蔽之后,相应的{@link OnResult}不再上报,需 {@link EnableResult} 使能之后才上报。 + * + * @param results [IN] 需要关闭上报开关的metadata。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see EnableResult + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode DisableResult(const std::vector &results) = 0; + + /** + * @brief 关闭Camera设备。 + * + * @see OpenCamera + * + * @since 1.0 + * @version 1.0 + */ + virtual void Close() = 0; +}; +} +#endif /** HDI_CAMERA_DEVICE_CLIENT_INF_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/icamera_device_callback.h b/zh-cn/device_api/hdi/camera/icamera_device_callback.h new file mode 100644 index 00000000..267eeeba --- /dev/null +++ b/zh-cn/device_api/hdi/camera/icamera_device_callback.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file icamera_device_callback.h + * + * @brief Camera设备的回调接口,主要包含camera设备发生错误时和上报metadata的回调函数。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_DEVICE_CALLBACK_SERVER_H +#define HDI_CAMERA_DEVICE_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDeviceCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.DeviceCallback"); + virtual ~ICameraDeviceCallback() {} + +public: + /** + * @brief 设备发生错误时调用,由调用者实现,用于返回错误信息给调用者。 + * + * @param type [IN] 错误类型,具体错误类型可参考 {@link ErrorType}。 + * @param errorCode [IN] 错误码,当前暂未使用。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnError(ErrorType type, int32_t errorCode) = 0; + + /** + * @brief 上报camera设备相关的metadata的回调,上报方式查看 {@link SetResultMode}。 + * + * @param timestamp [IN] metadata上报的时间戳。 + * @param result [IN] 上报的metadata,上报的metadata由 {@link EnableResult} 指定, + * 可通过 {@link GetEnabledResults} 查询,{@link DisableResult} 关闭上报开关。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnResult(uint64_t timestamp, const std::shared_ptr &result) = 0; +}; +} +#endif /** HDI_CAMERA_DEVICE_CALLBACK_SERVER_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/icamera_host.h b/zh-cn/device_api/hdi/camera/icamera_host.h new file mode 100644 index 00000000..f5d32337 --- /dev/null +++ b/zh-cn/device_api/hdi/camera/icamera_host.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file icamera_host.h + * + * @brief Camera服务的管理类,对上层提供HDI接口。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_HOST_CLIENT_INF_H +#define HDI_CAMERA_HOST_CLIENT_INF_H + +#include +#include +#include +#include "icamera_device_callback.h" +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraDevice; +class ICameraHostCallback; +class ICameraDeviceCallback; +class ICameraHost : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.Host"); + virtual ~ICameraHost() {} + /** + * @brief 获取ICameraHost实例。 + * + * 此接口为camera调用入口,需要先通过该接口获取ICameraHost实例,然后通过ICameraHost实例进行其它操作。 + * + * @param serviceName [IN] 要获取的ICameraHost实例的名称,当前实现中实例名称固定为camera_service。 + * + * @return Returns 成功返回ICameraHost实例,失败返回nullptr。 + * + * @since 1.0 + * @version 1.0 + */ + static sptr Get(const char *serviceName); + + /** + * @brief 设置ICameraHost回调接口,回调函数参考 {@link ICameraHostCallback}。 + * + * @param callback [IN] 要设置的回调函数。 + * + * @return Returns NO_ERROR 表示执行成功。 + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetCallback(const OHOS::sptr &callback) = 0; + + /** + * @brief 获取当前可用的Camera设备ID列表。 + * + * @param cameraIds [OUT] 返回当前可用的设备列表 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see GetCameraAbility + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetCameraIds(std::vector &cameraIds) = 0; + + /** + * @brief 获取Camera设备能力集合。 + * + * @param cameraId [IN] 用于指定要操作的camera设备,通过 {@link GetCameraIds} 获取。 + * + * @param ability [OUT] 返回cameraId对应Camera设备的能力集合。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetCameraAbility(const std::string &cameraId, + std::shared_ptr &ability) = 0; + + /** + * @brief 打开Camera设备。 + * + * 打开指定的Camera设备,通过此接口可以获取到ICameraDevice对象,通过ICameraDevice对象可以操作具体的Camera设备。 + * + * @param cameraId [IN] 需要打开的Camera设备ID,可通过 {@link GetCameraIds} 接口获取当前已有Camera设备列表。 + * @param callback [IN] camera设备相关的回调函数,具体参见 {@link ICameraDeviceCallback}。 + * @param device [OUT] 返回当前要打开的Camera设备ID对应的ICameraDevice对象。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode OpenCamera(const std::string &cameraId, + const OHOS::sptr &callback, + OHOS::sptr &device) = 0; + + /** + * @brief 打开或关闭闪光灯。 + * + * 该接口只能由打开cameraId指定Camera设备的调用者调用。 + * + * @param cameraId [IN] 闪光灯对应的camera设备ID。 + * @param isEnable [IN] true打开闪光灯,false关闭闪光灯。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see GetCameraIds + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode SetFlashlight(const std::string &cameraId, bool &isEnable) = 0; +}; +} +#endif /** HDI_CAMERA_HOST_CLIENT_INF_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/icamera_host_callback.h b/zh-cn/device_api/hdi/camera/icamera_host_callback.h new file mode 100644 index 00000000..873d16fa --- /dev/null +++ b/zh-cn/device_api/hdi/camera/icamera_host_callback.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file icamera_host_callback.h + * + * @brief ICameraHost的回调接口,提供Camera设备和闪关灯状态变化的回调函数,回调函数由调用者实现。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_CAMERA_HOST_CALLBACK_SERVER_H +#define HDI_CAMERA_HOST_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class ICameraHostCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.HostCallback"); + virtual ~ICameraHostCallback() {} + +public: + /** + * @brief 用于Camera设备状态变化时上报状态信息给调用者。 + * + * @param cameraId [IN] 状态发生变化的Camera设备ID。 + * @param status [IN] 最新的设备状态。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCameraStatus(const std::string &cameraId, CameraStatus status) = 0; + + /** + * @brief 用于在闪光灯状态变化时上报状态信息给调用者。 + * + * @param cameraId [IN] 状态发生变化的闪关灯所绑定的Camera设备ID。 + * @param status [IN] 最新的闪光灯状态。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnFlashlightStatus(const std::string &cameraId, FlashlightStatus status) = 0; + /** + * @brief 在相机事件发生时调用。 + * + * @param cameraId 表示相机事件绑定的相机ID。 + * @param event 表示相机事件类型。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCameraEvent(const std::string &cameraId, CameraEvent event) = 0; +}; +} +#endif /** HDI_CAMERA_HOST_CALLBACK_SERVER_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/ioffline_stream_operator.h b/zh-cn/device_api/hdi/camera/ioffline_stream_operator.h new file mode 100644 index 00000000..32a24968 --- /dev/null +++ b/zh-cn/device_api/hdi/camera/ioffline_stream_operator.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file ioffline_stream_operator.h + * + * @brief 离线流的操作接口。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H +#define HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IOfflineStreamOperator : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.OfflineStreamOperator"); + + virtual ~IOfflineStreamOperator() {} + + /** + * @brief 取消捕获请求。 + * + * @param captureId [IN] 用于标识要取消的捕获请求。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CancelCapture(int captureId) = 0; + + /** + * @brief 释放离线流。 + * + * @param streamIds 用于标识要释放的离线流集合。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ReleaseStreams(const std::vector &streamIds) = 0; + + /** + * @brief 释放所有离线流。 + * + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode Release() = 0; +}; +} +#endif /** HDI_OFFLINE_STREAM_OPERATOR_CLIENT_INF_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/istream_operator.h b/zh-cn/device_api/hdi/camera/istream_operator.h new file mode 100644 index 00000000..215aea46 --- /dev/null +++ b/zh-cn/device_api/hdi/camera/istream_operator.h @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file istream_operator.h + * + * @brief 流的操作接口。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_STREAM_OPERATOR_CLIENT_INF_H +#define HDI_STREAM_OPERATOR_CLIENT_INF_H + +#include +#include +#include +#include "istream_operator_callback.h" +#include "ioffline_stream_operator.h" +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IBufferProducer; +class IStreamOperator : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.StreamOperator"); + + virtual ~IStreamOperator() {} + + /** + * @brief 查询是否支持添加参数对应的流 + * + * 流是指从底层设备输出,经本模块内部各环节处理,最终传递到上层服务或者应用的一组数据序列 + * 本模块支持的流的类型有预览流,录像流,拍照流等,更多类型可查看 {@link StreamIntent}。 + * + * 此函数接口根据输入的运行模式和配置信息以及当前模块中正在运行的流,查询是否支持动态添加流。 + * 如果本模块支持在不停止其他流的情况下添加新流,或者即使停止其他流但上层服务或应用不感知 + * 则通过type参数返回DYNAMIC_SUPPORTED,上层服务或应用可以直接添加新流; + * 如果本模块支持添加新流但需要上层服务或应用先停止所有流的捕获,则通过type参数返回RE_CONFIGURED_REQUIRED; + * 如果不支持添加输入的新流,则返回NOT_SUPPORTED。 + * 此函数需要在调用 {@link CreateStreams} 创建流之前调用。 + * + * @param mode [IN] 流运行的模式,支持的模式参考 {@link OperationMode}。 + * @param modeSetting [IN] 流的配置,包括帧率,3A等配置信息。 + * @param info [IN] 流的配置信息,具体参考 {@link StreamInfo}。 + * @param type [OUT] 对动态配置流的支持类型,支持类型定义在 {@link StreamSupportType}。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode IsStreamsSupported( + OperationMode mode, + const std::shared_ptr &modeSetting, + const std::vector> &info, + StreamSupportType &type) = 0; + + /** + * @brief 创建流。 + * + * 此函数接口依据输入的流信息创建流,调用该接口之前需先通过 {@link IsStreamsSupported} 查询HAL是否支持要创建的流。 + * + * @param streamInfos [IN] 流信息列表,流信息定义在 {@link StreamInfo}。输入的流信息可能会被修改,需通过 + * {@link GetStreamAttributes} 获取最新的流属性。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CreateStreams(const std::vector> &streamInfos) = 0; + + /** + * @brief 释放流。 + * + * @param streamIds [IN] 要释放的流ID列表。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ReleaseStreams(const std::vector &streamIds) = 0; + + /** + * @brief 配置流。 + * + * 本接口需在调用 {@link CreateStreams} 创建流之后调用。 + * + * @param mode [IN] 流运行的模式,支持的模式定义在 {@link OperationMode}。 + * @param modeSetting [IN] 流的配置参数,包括帧率,ZOOM等信息。 + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CommitStreams(OperationMode mode, + const std::shared_ptr &modeSetting) = 0; + + /** + * @brief 获取流的属性。 + * + * @param attributes [OUT] 用于获取流的属性。在调用{@link CreateStreams} 时,通过参数streamInfos携带的流信息 + * 可能会被重写,因此通过该接口获取的流属性可能会。 + * 和 {@link CreateStreams} 输入的流信息存在差异。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode GetStreamAttributes( + std::vector> &attributes) = 0; + + /** + * @brief 绑定生产者句柄和指定流。 + * + * 如果在 {@link CreateStreams} 创建流时已经指定了生产者句柄,则不需要调用该接口。如果需要重新绑定, + * 需先调用 {@link DetachBufferQueue} 进行解绑,然后再绑定。 + * 对于一些IOT设备,可能不需要或者不支持预览流的图像数据缓存流转,那么不需要绑定生产者句柄, + * 此时在创建流时 {@link CreateStreams} 的 {@link StreamInfo} 参数的生产者句柄bufferQueue_为空,而 + * tunneledMode_需设置为false。 + * + * @param streamId [IN] 用于标识要绑定的流。 + * @param producer [IN] 生产者句柄。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see DetachBufferQueue + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode AttachBufferQueue(int streamId, const OHOS::sptr &producer) = 0; + + /** + * @brief 解除生产者句柄和指定流的绑定关系。 + * + * @param streamId [IN] 用于标识要解除绑定的流。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see AttachBufferQueue + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode DetachBufferQueue(int streamId) = 0; + + /** + * @brief 捕获图像。 + * + * 本接口必须在调用 {@link CommitStreams} 配置流之后调用。 + * 图像捕获有两种模式,分别是连续捕获和单次捕获。连续捕获即触发之后模块内部进行连续的捕获, + * 消费者可以连续收到图像数据,不需要多次调用本接口,若再次调用了本接口, + * 则停止当前捕获,更新捕获信息,再进行一次新的捕获,多用于预览、录像或者连拍场景。 + * 单次捕获即触发之后只捕获一帧图像数据,用于单次拍照场景。 + * 捕获启动时,会调用 {@link OnCaptureStarted} 来通知调用者捕获已经启动。 + * 连续捕获需调用 {@link CancelCapture} 来停止捕获。 + * 捕获结束时,会调用 {@link OnCaptureEnded} 来通知调用者捕获的帧计数等信息。 + * {@link CaptureInfo} 的 enableShutterCallback_ 使能 {@link OnFrameShutter},使能后每次捕获触发 {@link OnFrameShutter} + * 对于多个流同时捕获的场景,本模块内部保证同时上报多路流捕获数据。 + * + * @param captureId [IN] 捕获请求的唯一标识,由调用者指定,调用者需保证在Camera设备打开期间,捕获请求ID是唯一的。 + * @param info [IN] 捕获请求的参数信息,具体信息查看 {@link CaptureInfo}。 + * @param isStreaming [IN] 是否连续捕获,true表示连续捕获,否则为单次捕获。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see OnFrameShutter + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode Capture(int captureId, + const std::shared_ptr &info, bool isStreaming) = 0; + + /** + * @brief 取消捕获。 + * + * 取消连续捕获时会调用 {@link OnCaptureEnded}。 + * + * @param captureId 用于标识要取消的捕获请求 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @see Capture + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode CancelCapture(int captureId) = 0; + + /** + * @brief 将指定流转换成离线流。 + * + * 离线流只能由拍照流转换而来,其他流不支持。 + * 一些设备处理能力有限,可能导致拍照时算法处理时间较长,从而引起捕获请求堆积在模块内部,而转换为离线 + * 流之后,可关闭底层设备,由离线流接替,进行后续的处理。 + * + * @param streamIds [IN] 用于指定要转换成离线流的流集合。 + * @param callback [IN] 用于设置离线流的回调。 + * @param offlineOperator [OUT] 转换后的离线流。 + * + * @return Returns NO_ERROR 表示执行成功; + * @return Returns 其他值表示执行失败,具体错误码查看 {@link CamRetCode}。 + * + * @since 1.0 + * @version 1.0 + */ + virtual CamRetCode ChangeToOfflineStream(const std::vector &streamIds, + OHOS::sptr &callback, + OHOS::sptr &offlineOperator) = 0; +}; +} + +#endif /** HDI_STREAM_OPERATOR_CLIENT_INF_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/istream_operator_callback.h b/zh-cn/device_api/hdi/camera/istream_operator_callback.h new file mode 100644 index 00000000..ad856e8c --- /dev/null +++ b/zh-cn/device_api/hdi/camera/istream_operator_callback.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file istream_operator_callback.h + * + * @brief {@link IStreamOperator} 相关的回调,这些回调均由调用者实现。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef HDI_STREAM_OPERATOR_CALLBACK_SERVER_H +#define HDI_STREAM_OPERATOR_CALLBACK_SERVER_H + +#include +#include +#include +#include "types.h" +#include "icamera_interface.h" + +namespace OHOS::Camera { +class IStreamOperatorCallback : public ICameraInterface { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Camera.V1_0.StreamOperatorCallback"); + virtual ~IStreamOperatorCallback() {} + +public: + /** + * @brief 捕获开始回调,在捕获开始时调用。 + * + * @param captureId [IN] 用于标识回调对应的捕获请求。 + * @param streamIds [IN] 回调对应的流集合。 + * + * @see OnCaptureEnded + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureStarted(int32_t captureId, const std::vector &streamIds) = 0; + + /** + * @brief 捕获结束回调,在捕获结束时调用。 + * + * @param captureId [IN] 用于标识回调对应的捕获请求。 + * @param infos [IN] 捕获结束相关信息。 + * + * @see OnCaptureStarted + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureEnded(int32_t captureId, + const std::vector> &infos) = 0; + + /** + * @brief 捕获错误回调,在捕获过程中发生错误时调用。 + * + * @param captureId [IN] 用于标识回调对应的捕获请求。 + * @param infos [IN] 捕获错误信息列表。 + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnCaptureError(int32_t captureId, + const std::vector> &infos) = 0; + + /** + * @brief 帧捕获回调。 + * + * 通过 {@link Capture} 的输入参数 {@link CaptureInfo} 的enableShutterCallback_使能该回调, + * 使能后每次捕获均会触发此回调。 + * + * @param captureId [IN] 用于标识回调对应的捕获请求。 + * @param streamIds [IN] 回调对应的流集合。 + * @param timestamp [IN] 该接口被调用时的时间戳。 + * + * @see Capture + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnFrameShutter(int32_t captureId, + const std::vector &streamIds, uint64_t timestamp) = 0; +}; +} +#endif /** HDI_STREAM_OPERATOR_CALLBACK_SERVER_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/camera/types.h b/zh-cn/device_api/hdi/camera/types.h new file mode 100644 index 00000000..ff7bd345 --- /dev/null +++ b/zh-cn/device_api/hdi/camera/types.h @@ -0,0 +1,436 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Camera + * @{ + * + * @brief Camera模块接口定义。 + * + * camera模块涉及相机设备的操作、流的操作、离线流的操作和各种回调等。 + * + * @since 1.0 + */ + +/** + * @file types.h + * + * @brief Camera模块HDI接口使用的数据类型。 + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef CAMERA_DEVICE_DRIVER_TYPES_H +#define CAMERA_DEVICE_DRIVER_TYPES_H + +#include +#include +#include +#include +#include +#include "camera_metadata_info.h" +#include "type_common.h" + +namespace OHOS::Camera { +using CameraAbility = CameraMetadata; +using CameraSetting = CameraMetadata; + +/** + * @brief HDI接口的返回值。 + */ +enum CamRetCode : int32_t { + /** + * 调用成功。 + */ + NO_ERROR = 0, + + /** + * 设备当前忙。 + */ + CAMERA_BUSY = -1, + + /** + * 资源不足。 + */ + INSUFFICIENT_RESOURCES = -2, + + /** + * 参数错误。 + */ + INVALID_ARGUMENT = -3, + + /** + * 不支持当前调用方法。 + */ + METHOD_NOT_SUPPORTED = -4, + + /** + * Camera设备已经关闭。 + */ + CAMERA_CLOSED = -5, + + /** + * 驱动层发生严重错误。 + */ + DEVICE_ERROR = -6, +}; + +/** + * @brief metadata的上报模式。 + */ +enum ResultCallbackMode : int32_t { + /** + * 每帧上报。 + */ + PER_FRAME, + + /** + * 设备状态变化时上报。 + */ + ON_CHANGED +}; + +/** + * @brief 流的使用模式。 + */ +enum OperationMode : int32_t { + /** + * 普通模式。 + */ + NORMAL = 0, +}; + +/** + * @brief 流的类型。 + */ +enum StreamIntent : int32_t { + /** + * 流数据用于显示,即预览流。 + */ + PREVIEW = 0, + + /** + * 流数据用于编码生成录像,即录像流。 + */ + VIDEO = 1, + + /** + * 流数据用于编码生成照片,即拍照流。 + */ + STILL_CAPTURE = 2, + + /** + * 流数据用于保存缩略图。 + */ + POST_VIEW = 3, + + /** + * 流数据用于图像分析。 + */ + ANALYZE = 4, + + /** + * 自定义类型。 + */ + CUSTOM = 5, +}; + +/** + * @brief 流数据的编码类型。 + */ +enum EncodeType : int32_t { + /** + * 未设置编码类型 + */ + ENCODE_TYPE_NULL = 0, + + /** + * 编码类型为H264。 + */ + ENCODE_TYPE_H264 = 1, + + /** + * 编码类型为H265。 + */ + ENCODE_TYPE_H265 = 2, + + /** + * 编码类型为JPEG。 + */ + ENCODE_TYPE_JPEG = 3, +}; + +/** + * @brief 流信息,用于创建流时传入相关的配置参数。 + */ +struct StreamInfo { + /** + * 流的ID,用于在设备内唯一标识一条流。 + */ + int streamId_; + + /** + * 图像宽度。 + */ + int width_; + + /** + * 图像高度。 + */ + int height_; + + /** + * 图像格式。 + */ + int format_; + + /** + * 图像颜色空间。 + */ + int datasapce_; + + /** + * 流类型。 + */ + StreamIntent intent_; + + /** + * 隧道模式,值为true时开启,false关闭。 + * + * 开启隧道模式后,HAL不直接和上层交互,通过图形提供的生产者句柄来传递帧数据, + * 对于一些IOT设备,可能不需要或者不支持预览流的图像数据缓存流转,此时需要关闭隧道模式。 + */ + bool tunneledMode_; + + /** + * 图形提供的生产者句柄。 + */ + OHOS::sptr bufferQueue_; + + /** + * 最小帧间隔。 + */ + int minFrameDuration_; + + /** + * 编码类型。 + */ + EncodeType encodeType_; +}; + +/** + * @brief 动态配置流的切换方式,使用场景参考 {@link IsStreamsSupported}。 + */ +enum StreamSupportType : int32_t { + /** + * 支持动态配置流,对应的流参数直接生效。 + */ + DYNAMIC_SUPPORTED, + + /** + * 不支持动态配置流,对应的参数需要停止流然后重新配置流才能生效。 + */ + RE_CONFIGURED_REQUIRED, + + /** + * 不支持对应的流参数配置。 + */ + NOT_SUPPORTED, +}; + +/** + * @brief 流的属性。 + */ +struct StreamAttribute { + /** + * 流的ID,用于在设备内唯一标识一条流。 + */ + int streamId_; + + /** + * 图像宽度。 + */ + int width_; + + /** + * 图像高度。 + */ + int height_; + + /** + * 重写的图像格式。 + */ + int overrideFormat_; + + /** + * 重写的图像颜色空间 + */ + int overrideDatasapce_; + + /** + * 重写后的生产者的使用方式。 + */ + int producerUsage_; + + /** + * 重写后的生产者缓存数量。 + */ + int producerBufferCount_; + + /** + * 连拍支持的最大捕获帧数量。 + */ + int maxBatchCaptureCount_; + + /** + * 最大的并发捕获请求个数,默认为1。 + */ + int maxCaptureCount_; +}; + +/** + * @brief 捕获请求的相关信息。 + */ +struct CaptureInfo { + /** + * 捕获的流ID集合。 + */ + std::vector streamIds_; + + /** + * 捕获的配置信息。 + */ + std::shared_ptr captureSetting_; + + /** + * 使能捕获回调,每一次捕获后都会触发 {@link OnFrameShutter}。 + */ + bool enableShutterCallback_; +}; + +/** + * @brief Camera设备状态。 + */ +enum CameraStatus { + /** + * 设备当前不在位或者不可用。 + */ + UN_AVAILABLE = 0, + + /** + * 设备当前可用。 + */ + AVAILABLE = 1, +}; + +/** + * @brief 闪光灯状态。 + */ +enum FlashlightStatus : uint32_t { + /** + * 闪光灯关闭。 + */ + FLASHLIGHT_OFF = 0, + + /** + * 闪光灯开启。 + */ + FLASHLIGHT_ON = 1, + + /** + * 闪光灯当前不可用。 + */ + FLASHLIGHT_UNAVAILABLE = 2, +}; + +/** + * @brief Camera事件。 + */ +enum CameraEvent : uint32_t { + /** + * Camera设备增加事件。 + */ + CAMERA_EVENT_DEVICE_ADD = 0, + + /** + * Camera设备删除事件。 + */ + CAMERA_EVENT_DEVICE_RMV = 1, +}; + +/** + * @brief 设备错误类型,用于设备错误回调 {@link OnError}。 + */ +enum ErrorType : uint32_t { + /** + * 严重错误,需要关闭camera设备。 + */ + FATAL_ERROR = 0, + + /** + * 请求超时,需要关闭camera设备。 + */ + REQUEST_TIMEOUT = 1, +}; + +/** + * @brief 捕获结束相关信息,用于捕获结束回调 {@link OnCaptureEnded}。 + */ +struct CaptureEndedInfo { + /** + * 捕获的流ID。 + */ + int streamId_; + + /** + * 捕获结束时已经抓取的帧数。 + */ + int frameCount_; +}; + +/** + * @brief 流错误类型,用于流错误类型 {@link CaptureErrorInfo}。 + */ +enum StreamError { + /** + * 流未知错误。 + */ + UNKNOWN_ERROR = 0, + + /** + * 丢包。 + */ + BUFFER_LOST = 1, +}; + +/** + * @brief 流错误信息,用于回调 {@link OnCaptureError}。 + */ +struct CaptureErrorInfo { + /** + * 流Id。 + */ + int streamId_; + + /** + * 错误类型。 + */ + StreamError error_; +}; + +using MetaType = int32_t; +} +#endif /** CAMERA_DEVICE_DRIVER_TYPES_H \ No newline at end of file -- Gitee