diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..e69de29
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..4947287
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.en.md b/README.en.md
deleted file mode 100644
index 2ab4f4e..0000000
--- a/README.en.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# multimedia_camera_standard
-
-#### Description
-Implementation of camera device management and camera capture functions | 相机设备和相机采集功能实现
-
-#### Software Architecture
-Software architecture description
-
-#### Installation
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Instructions
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Contribution
-
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-
-
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 71d1ca5..640bd43
--- a/README.md
+++ b/README.md
@@ -1,37 +1,32 @@
-# multimedia_camera_standard
+# Camera
-#### 介绍
-Implementation of camera device management and camera capture functions | 相机设备和相机采集功能实现
+- [Introduction](#section11660541593)
+- [Directory Structure](#section176641621345)
+- [Repositories Involved](#section16511040154318)
-#### 软件架构
-软件架构说明
+## Introduction
+The **camera\_standard** repository enables your application to provide camera functions. You can access and operate the camera device and develop new functions through open APIs. Common operations include preview, photographing, and video recording.
-#### 安装教程
+**Figure 1** Position in the subsystem architecture
+
-1. xxxx
-2. xxxx
-3. xxxx
+## Directory Structure
-#### 使用说明
+The structure of the repository directory is as follows:
-1. xxxx
-2. xxxx
-3. xxxx
+```
+/foundation/multimedia/camera
+├── frameworks # Framework code
+│ ├── include # Header files required by the framework
+│ └── src # Framework implementation
+├── interfaces # External APIs
+│ └── kits # External API files
+├── LICENSE # License file
+└── ohos.build # Build file
+```
-#### 参与贡献
+## Repositories Involved
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
+multimedia\_camera\_standard
-
-#### 特技
-
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README_zh.md b/README_zh.md
new file mode 100755
index 0000000..2b735fe
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,32 @@
+# Camera组件
+
+- [简介](#section11660541593)
+- [目录](#section176641621345)
+- [相关仓](#section16511040154318)
+
+## 简介
+
+相机组件支持相机业务的开发,开发者可以通过已开放的接口实现相机硬件的访问、操作和新功能开发,最常见的操作如:预览、拍照和录像等。
+
+**图 1** camera组件架构图
+
+
+## 目录
+
+仓目录结构如下:
+
+```
+/foundation/multimedia/camera_standard # 相机组件业务代码
+├── frameworks # 框架代码
+│ ├── include # 框架所需头文件
+│ └── src # 框架层实现
+├── interfaces # 外部接口层
+│ └── kits # 外部接口文件
+├── LICENSE # 证书文件
+└── ohos.build # 编译文件
+```
+
+## 相关仓
+
+媒体子系统仓:multimedia\_camera\_standard
+
diff --git a/figures/camera组件架构图.png b/figures/camera组件架构图.png
new file mode 100755
index 0000000..9bddb30
Binary files /dev/null and b/figures/camera组件架构图.png differ
diff --git a/figures/position-in-the-subsystem-architecture.png b/figures/position-in-the-subsystem-architecture.png
new file mode 100755
index 0000000..08ffc91
Binary files /dev/null and b/figures/position-in-the-subsystem-architecture.png differ
diff --git a/frameworks/innerkitsimpl/camera/BUILD.gn b/frameworks/innerkitsimpl/camera/BUILD.gn
new file mode 100644
index 0000000..e75575f
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/BUILD.gn
@@ -0,0 +1,141 @@
+# 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.
+
+import("//build/ohos.gni")
+
+SDK_LIB_DIR = rebase_path("//device/hisilicon/hispark_taurus/sdk_linux/soc/lib",
+ root_build_dir)
+CODEC_LIB_DIR = rebase_path(
+ "//device/hisilicon/hardware/media/hal/codec/hi3516dv300/llvm/ext/libs",
+ root_build_dir)
+CAMERA_LIB_DIR = rebase_path(
+ "//device/hisilicon/hardware/media/hal/camera/hi3516dv300/llvm/ohos/libs",
+ root_build_dir)
+CAMERA_LIB_PLATFORM_DIR =
+ rebase_path("//device/hisilicon/hardware/media/hal/camera/hi3516dv300/libs",
+ root_build_dir)
+FORMAT_LIB_DIR = rebase_path(
+ "//device/hisilicon/hardware/media/hal/format/hi3516dv300/llvm/ext/libs",
+ root_build_dir)
+DTCF_LIB_DIR =
+ rebase_path("//device/hisilicon/modules/middleware/source/component/dtcf",
+ root_build_dir)
+FILEFORMAT_LIB_DIR =
+ rebase_path(
+ "//device/hisilicon/modules/middleware/source/component/fileformat",
+ root_build_dir)
+RECORDER_PRO_LIB_DIR =
+ rebase_path(
+ "//device/hisilicon/modules/middleware/source/component/recorder_pro",
+ root_build_dir)
+MIDDLEWARE_COMMON_DIR =
+ rebase_path("//device/hisilicon/modules/middleware/source/common",
+ root_build_dir)
+
+ohos_shared_library("camera") {
+ install_enable = true
+ sources = [
+ "src/camera_ability.cpp",
+ "src/camera_config.cpp",
+ "src/camera_device.cpp",
+ "src/camera_impl.cpp",
+ "src/camera_kit.cpp",
+ "src/camera_manager.cpp",
+ "src/camera_service.cpp",
+ "src/event_handler.cpp",
+ "src/frame_config.cpp",
+ ]
+
+ cflags = [ "-fPIC" ]
+ cflags += [ "-Wall" ]
+ cflags_cc = cflags
+ include_dirs = [
+ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog",
+ "//device/hisilicon/hispark_taurus/sdk_linux/soc/src/mpp/cbb/based/arch/hi3516cv500/include/hi3516cv500",
+ "//device/hisilicon/hispark_taurus/sdk_linux/soc/src/mpp/cbb/include",
+ "//device/hisilicon/hispark_taurus/sdk_linux/soc/src/mpp/cbb/init/include/linux",
+ "//device/hisilicon/hispark_taurus/sdk_linux/soc/src/osal/include",
+ "//drivers/peripheral/codec/interfaces/include",
+ "//drivers/peripheral/display/interfaces/include",
+ "//foundation/graphic/standard/frameworks/surface/include",
+ "//foundation/graphic/standard/interfaces/kits/surface",
+ "//utils/native/base/include",
+ ]
+
+ lib_dirs = [ "//device/hisilicon/hispark_taurus/sdk_linux/soc/lib" ]
+
+ ldflags = [
+ "-L${SDK_LIB_DIR}",
+ "-L${CODEC_LIB_DIR}",
+ "-L${CAMERA_LIB_DIR}",
+ "-L${CAMERA_LIB_PLATFORM_DIR}",
+ "-L${FORMAT_LIB_DIR}",
+ "-L${DTCF_LIB_DIR}",
+ "-L${FILEFORMAT_LIB_DIR}",
+ "-L${RECORDER_PRO_LIB_DIR}",
+ "-L${MIDDLEWARE_COMMON_DIR}",
+ "-lsdk",
+ "-lcodec",
+ "-lcamera_hw_platform",
+ "-lhi3516cv500_base",
+ "-lhi3516cv500_chnl",
+ "-lhi3516cv500_dis",
+ "-lhi3516cv500_gdc",
+ "-lhi3516cv500_h264e",
+ "-lhi3516cv500_h265e",
+ "-lhi3516cv500_isp",
+ "-lhi3516cv500_ive",
+ "-lhi3516cv500_jpegd",
+ "-lhi3516cv500_jpege",
+ "-lhi3516cv500_rc",
+ "-lhi3516cv500_rgn",
+ "-lhi3516cv500_sys",
+ "-lhi3516cv500_vdec",
+ "-lhi3516cv500_vedu",
+ "-lhi3516cv500_venc",
+ "-lhi3516cv500_vfmw",
+ "-lhi3516cv500_vgs",
+ "-lhi3516cv500_vi",
+ "-lhi3516cv500_vo",
+ "-lhi3516cv500_vpss",
+ "-lhi3516cv500_aio",
+ "-lhi3516cv500_ai",
+ "-lhi3516cv500_ao",
+ "-lhi3516cv500_adec",
+ "-lhi3516cv500_acodec",
+ "-lhi3516cv500_aenc",
+ "-lhi3516cv500_nnie",
+ "-lhi_osal",
+ "-lhi_irq",
+ "-lhi_sensor_i2c",
+ ]
+
+ public_configs = [ ":camera_external_library_config" ]
+
+ deps = [
+ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
+ "//third_party/bounds_checking_function:libsec_static",
+ ]
+
+ external_deps = [ "ipc:ipc_core" ]
+
+ public_deps = [ "//foundation/graphic/standard:libsurface" ]
+
+ part_name = "multimedia_camera_standard"
+ subsystem_name = "multimedia"
+}
+
+config("camera_external_library_config") {
+ include_dirs = [ "//foundation/multimedia/camera_standard/frameworks/innerkitsimpl/camera/include" ]
+ include_dirs += [ "//foundation/multimedia/camera_standard/interfaces/innerkits/native/include" ]
+}
diff --git a/frameworks/innerkitsimpl/camera/include/camera_device.h b/frameworks/innerkitsimpl/camera/include/camera_device.h
new file mode 100644
index 0000000..a8c5f5a
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/camera_device.h
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_DEVICE_H
+#define OHOS_CAMERA_DEVICE_H
+
+#include
+#include
+#include
+
+#include "camera_ability.h"
+#include "camera_config.h"
+#include "codec_type.h"
+#include "frame_config.h"
+#include "hal_media.h"
+#include "surface.h"
+
+namespace OHOS {
+namespace Media {
+enum LoopState {
+ LOOP_IDLE,
+ LOOP_READY,
+ LOOP_LOOPING,
+ LOOP_STOP,
+ LOOP_ERROR,
+};
+
+class DeviceAssistant {
+public:
+ std::thread *thrd_ = nullptr;
+ LoopState state_ = LOOP_IDLE;
+ FrameConfig *fc_ = nullptr;
+
+ virtual int32_t
+ SetFrameConfig(FrameConfig &fc, std::vector &hdls, std::vector &attrs)
+ {
+ return -1;
+ }
+ virtual int32_t Start()
+ {
+ return -1;
+ }
+ virtual int32_t Stop()
+ {
+ return -1;
+ }
+};
+
+class RecordAssistant : public DeviceAssistant {
+public:
+ int32_t SetFrameConfig(FrameConfig &fc,
+ std::vector &hdls,
+ std::vector &attrs) override;
+ int32_t Start() override;
+ int32_t Stop() override;
+
+ std::vector vencHdls_;
+ std::vector> vencSurfaces_;
+ std::vector vencAttr_;
+ int32_t VideoEncIsExist(const HalVideoProcessorAttr &attr);
+ static int OnVencBufferAvailble(UINTPTR hComponent, UINTPTR dataIn, OutputInfo *buffer);
+ static CodecCallback recordCodecCb_;
+ sptr mProducerSurface;
+};
+
+class PreviewAssistant : public DeviceAssistant {
+public:
+ int32_t SetFrameConfig(FrameConfig &fc,
+ std::vector &hdls,
+ std::vector &attrs) override;
+ int32_t Start() override;
+ virtual int32_t Stop() override;
+};
+
+class CaptureAssistant : public DeviceAssistant {
+ int32_t SetFrameConfig(FrameConfig &fc,
+ std::vector &hdls,
+ std::vector &attrs) override;
+ int32_t Start() override;
+ virtual int32_t Stop() override;
+ CODEC_HANDLETYPE vencHdl_ = nullptr;
+ Surface *capSurface_ = nullptr;
+};
+
+class CameraDevice {
+public:
+ CameraDevice();
+ virtual ~CameraDevice();
+
+ int32_t Initialize(CameraAbility &ability);
+ int32_t UnInitialize();
+ int32_t SetCameraConfig(CameraConfig &cc);
+
+ int32_t TriggerLoopingCapture(FrameConfig &fc);
+ void StopLoopingCapture();
+
+ int32_t TriggerSingleCapture(FrameConfig &fc);
+
+private:
+ CameraConfig *cc_ = nullptr;
+ std::vector prcessorHdls_;
+ std::vector prcessorAttrs_;
+ RecordAssistant recordAssistant_;
+ PreviewAssistant previewAssistant_;
+ CaptureAssistant captureAssistant_;
+};
+} // namespace Media
+} // namespace OHOS
+#endif // OHOS_CAMERA_DEVICE_H
diff --git a/frameworks/innerkitsimpl/camera/include/camera_impl.h b/frameworks/innerkitsimpl/camera/include/camera_impl.h
new file mode 100644
index 0000000..ab76aea
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/camera_impl.h
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_IMPL_H
+#define OHOS_CAMERA_IMPL_H
+
+#include "camera.h"
+#include "camera_ability.h"
+#include "camera_device.h"
+#include "camera_state_callback.h"
+
+namespace OHOS {
+namespace Media {
+class CameraImpl : public Camera {
+public:
+ CameraImpl() = delete;
+ CameraImpl(std::string &id, const CameraAbility &ability);
+ virtual ~CameraImpl() = default;
+
+ std::string GetCameraId() override;
+ const CameraConfig *GetCameraConfig() const override;
+ FrameConfig *GetFrameConfig(int32_t type) override;
+
+ void Configure(CameraConfig &config) override;
+ void Release() override;
+
+ int32_t TriggerLoopingCapture(FrameConfig &frameConfig) override;
+ void StopLoopingCapture() override;
+ int32_t TriggerSingleCapture(FrameConfig &frameConfig) override;
+
+ const CameraAbility *GetAbility();
+ void OnCreate(CameraDevice &device);
+ void OnCreateFailed();
+ void RegistCb(CameraStateCallback &callback, EventHandler &handler);
+
+private:
+ std::string id_;
+ std::list frameConfigs_;
+ CameraConfig *config_ = nullptr;
+ CameraStateCallback *stateCb_ = nullptr;
+ EventHandler *handler_ = nullptr;
+ const CameraAbility *ability_ = nullptr;
+ CameraDevice *device_ = nullptr;
+};
+} // namespace Media
+} // namespace OHOS
+#endif // OHOS_CAMERA_IMPL_H
diff --git a/frameworks/innerkitsimpl/camera/include/camera_manager.h b/frameworks/innerkitsimpl/camera/include/camera_manager.h
new file mode 100644
index 0000000..4fc68a3
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/camera_manager.h
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_MANAGER_H
+#define OHOS_CAMERA_MANAGER_H
+
+#include
+#include
+
+#include "camera_ability.h"
+#include "camera_device_callback.h"
+#include "camera_state_callback.h"
+#include "event_handler.h"
+
+namespace OHOS {
+namespace Media {
+class CameraManager {
+public:
+ virtual ~CameraManager() = default;
+ static CameraManager *GetInstance();
+
+ virtual std::list GetCameraIds() = 0;
+ virtual const CameraAbility *GetCameraAbility(const std::string &cameraId)
+ {
+ return nullptr;
+ }
+ virtual void RegisterCameraDeviceCallback(CameraDeviceCallback &callback, EventHandler &handler) {}
+ virtual void UnregisterCameraDeviceCallback(const CameraDeviceCallback &callback) {}
+ virtual void CreateCamera(const std::string &cameraId, CameraStateCallback &callback, EventHandler &handler) {}
+
+protected:
+ CameraManager() {}
+};
+} // namespace Media
+} // namespace OHOS
+
+#endif // OHOS_CAMERA_MANAGER_H
diff --git a/frameworks/innerkitsimpl/camera/include/camera_service.h b/frameworks/innerkitsimpl/camera/include/camera_service.h
new file mode 100644
index 0000000..e2a5e40
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/camera_service.h
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_SERVICE_H
+#define OHOS_CAMERA_SERVICE_H
+
+#include "camera_device.h"
+#include "camera_service_callback.h"
+
+namespace OHOS {
+namespace Media {
+class CameraService {
+public:
+ virtual ~CameraService();
+ static CameraService *GetInstance();
+
+ void Initialize(CameraServiceCallback &callback);
+ const CameraAbility *GetCameraAbility(std::string &cameraId);
+ void CreateCamera(std::string cameraId);
+
+private:
+ CameraService();
+ int32_t InitCameraDevices();
+ CameraDevice *device_ = nullptr;
+ CameraAbility *ability_ = nullptr;
+ CameraServiceCallback *cameraServiceCb_ = nullptr;
+};
+} // namespace Media
+} // namespace OHOS
+
+#endif // OHOS_CAMERA_SERVICE_H
diff --git a/frameworks/innerkitsimpl/camera/include/camera_service_callback.h b/frameworks/innerkitsimpl/camera/include/camera_service_callback.h
new file mode 100644
index 0000000..7ae40d1
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/camera_service_callback.h
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_SERVICE_CALLBACK_H
+#define OHOS_CAMERA_SERVICE_CALLBACK_H
+
+#include
+#include
+
+#include "camera_device.h"
+
+namespace OHOS {
+namespace Media {
+class CameraServiceCallback {
+public:
+ CameraServiceCallback() = default;
+ virtual ~CameraServiceCallback() = default;
+
+ enum CameraStauts {
+ CAMERA_STATUS_AVAIL,
+ CAMERA_STATUS_UNAVAIL,
+ CAMERA_STATUS_CREATED,
+ CAMERA_STATUS_CREATE_FAILED
+ };
+ virtual void OnCameraServiceInitialized(const std::list &availCameraIdList) {}
+ virtual void OnCameraStatusChange(const std::string &cameraId, CameraStauts status, const CameraDevice &device) {}
+};
+} // namespace Media
+} // namespace OHOS
+
+#endif // OHOS_CAMERA_SERVICE_CALLBACK_H
diff --git a/frameworks/innerkitsimpl/camera/include/hal_display.h b/frameworks/innerkitsimpl/camera/include/hal_display.h
new file mode 100644
index 0000000..21572e9
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/hal_display.h
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#ifndef COMMON_PLATFORM_VO_H
+#define COMMON_PLATFORM_VO_H
+
+#include
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+typedef int32_t HalVideoOutputHdl;
+
+typedef struct {
+ int32_t regionPositionX;
+ int32_t regionPositionY;
+ int32_t regionWidth;
+ int32_t regionHeight;
+ uint32_t priority;
+} HalVideoOutputAttr;
+
+int32_t HalCreateVideoOutput(HalVideoOutputHdl *handle, HalVideoOutputAttr attr);
+
+int32_t HalConfigVideoOutput(HalVideoOutputHdl handle, HalVideoOutputAttr attr);
+
+int32_t HalGetVideoOutputConfig(HalVideoOutputHdl handle, HalVideoOutputAttr *attr);
+
+int32_t HalDestroyVideoOutput(HalVideoOutputHdl handle);
+
+int32_t HalStartVideoOutput(HalVideoOutputHdl handle);
+
+int32_t HalStopVideoOutput(HalVideoOutputHdl handle);
+
+int32_t HalWriteVo(HalVideoOutputHdl handle, const void *buffer);
+
+int32_t HalPlayerVoInit(HalVideoOutputHdl *handle);
+
+int32_t HalPlayerSysInit(void);
+
+void HalPlayerVoDeinit(HalVideoOutputHdl handle);
+
+int32_t HalCreateCameraVideoOutput(uint32_t deviceId, HalVideoOutputAttr *attr);
+
+int32_t HalDestroyCameraVideoOutput();
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+#endif // COMMON_PLATFORM_VO_H
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/camera/include/hal_media.h b/frameworks/innerkitsimpl/camera/include/hal_media.h
new file mode 100644
index 0000000..9de1ccc
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/include/hal_media.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_HAL_H
+#define OHOS_CAMERA_HAL_H
+
+#include "stdbool.h"
+#include "stdint.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+#define HAL_MEDIA_OK 0
+#define HAL_MEDIA_ERR 1
+
+typedef int32_t HalProcessorHdl;
+#define HAL_INVALID_PROCESSOR (-1)
+#define HAL_MAX_VPSS_NUM 10
+/* necessary and significant attr */
+typedef struct {
+ uint32_t width;
+ uint32_t height;
+ uint32_t fps;
+} HalVideoProcessorAttr;
+
+HalProcessorHdl HalCreateVideoProcessor(HalVideoProcessorAttr *attr);
+void HalCameraGetProcessorAttr(HalProcessorHdl hdls[HAL_MAX_VPSS_NUM], HalVideoProcessorAttr attrs[HAL_MAX_VPSS_NUM],
+ int32_t *size);
+uint32_t HalGetProcessorDeviceId(HalProcessorHdl hdl);
+void HalDestroyVideoProcessor();
+
+/* camera */
+int32_t HalMediaInitialize();
+int32_t HalCameraInitialize();
+void HalCameraUnInitialize();
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* End of #ifdef __cplusplus */
+#endif // OHOS_CAMERA_HAL_H
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/camera/src/camera_ability.cpp b/frameworks/innerkitsimpl/camera/src/camera_ability.cpp
new file mode 100644
index 0000000..52492b9
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_ability.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#include "camera_ability.h"
+
+#include "media_log.h"
+
+using namespace std;
+namespace OHOS {
+namespace Media {
+CameraAbility::CameraAbility() {}
+CameraAbility::~CameraAbility() {}
+
+list CameraAbility::GetSupportedSizes() const
+{
+ if (supportProperties_.find(PARAM_KEY_SIZE) != supportProperties_.end()) {
+ auto target = sizeMap_.find(PARAM_KEY_SIZE);
+ return target->second;
+ }
+ list emptyList;
+ return emptyList;
+}
+
+list CameraAbility::GetSupportParameterRange(uint32_t key) const
+{
+ switch (key) {
+ case PARAM_KEY_SIZE: {
+ auto target = sizeMap_.find(PARAM_KEY_SIZE);
+ return target->second;
+ }
+ default: {
+ list emptyList;
+ return emptyList;
+ }
+ }
+}
+
+void CameraAbility::SetSupportParameterRange(uint32_t key, list &rangeList)
+{
+ switch (key) {
+ case PARAM_KEY_SIZE:
+ supportProperties_.emplace(key);
+ sizeMap_[key] = rangeList;
+ break;
+ default:
+ break;
+ }
+}
+
+bool CameraAbility::IsParameterSupport(uint32_t key) const
+{
+ if (key != PARAM_KEY_SIZE) {
+ return false;
+ }
+ return true;
+}
+} // namespace Media
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/camera/src/camera_config.cpp b/frameworks/innerkitsimpl/camera/src/camera_config.cpp
new file mode 100644
index 0000000..4b5a80a
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_config.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+#ifndef OHOS_CAMERA_CONFIG_IMPL_H
+#define OHOS_CAMERA_CONFIG_IMPL_H
+
+#include "camera_config.h"
+#include "media_log.h"
+
+namespace OHOS {
+namespace Media {
+class CameraConfigImpl : public CameraConfig {
+public:
+ CameraConfigImpl() = default;
+ virtual ~CameraConfigImpl() = default;
+
+ void SetFrameStateCallback(const FrameStateCallback &callback, const EventHandler &handler) override
+ {
+ if (inUse_) {
+ MEDIA_ERR_LOG("This config is in use, do not support config modify.");
+ }
+
+ callback_ = (FrameStateCallback *) &callback;
+ handler_ = (EventHandler *) &handler;
+ inUse_ = true;
+ }
+
+ EventHandler *GetEventHandler() const override
+ {
+ EventHandler *evtHandler = handler_;
+ return evtHandler;
+ }
+
+ FrameStateCallback *GetFrameStateCb() const override
+ {
+ FrameStateCallback *fsCb = callback_;
+ return fsCb;
+ }
+
+private:
+ FrameStateCallback *callback_ = nullptr;
+ EventHandler *handler_ = nullptr;
+ bool inUse_ = false;
+};
+
+CameraConfig *CameraConfig::CreateCameraConfig()
+{
+ return new (std::nothrow) CameraConfigImpl();
+}
+} // namespace Media
+} // namespace OHOS
+#endif // OHOS_CAMERA_CONFIG_IMPL_H
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/camera/src/camera_device.cpp b/frameworks/innerkitsimpl/camera/src/camera_device.cpp
new file mode 100644
index 0000000..fd73db1
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_device.cpp
@@ -0,0 +1,670 @@
+/*
+ * 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.
+ */
+
+#include "camera_device.h"
+
+#include "codec_interface.h"
+#include "hal_display.h"
+#include "media_log.h"
+#include "meta_data.h"
+#include "securec.h"
+
+#include
+#include
+
+using namespace OHOS;
+using namespace OHOS::Media;
+using namespace std;
+
+namespace OHOS {
+namespace Media {
+inline PicSize Convert2CodecSize(int32_t width, int32_t height)
+{
+ struct SizeMap {
+ PicSize res_;
+ int32_t width_;
+ int32_t height_;
+ };
+ static SizeMap sizeMap[] = {
+ {Resolution_CIF, 352, 288}, {Resolution_360P, 640, 360},
+ {Resolution_D1_PAL, 720, 576}, {Resolution_D1_NTSC, 720, 480},
+ {Resolution_720P, 1280, 720}, {Resolution_1080P, 1920, 1080}
+ };
+ for (uint32_t i = 0; i < sizeof(sizeMap) / sizeof(SizeMap); i++) {
+ if (sizeMap[i].width_ == width && sizeMap[i].height_ == height) {
+ return sizeMap[i].res_;
+ }
+ }
+ return Resolution_INVALID;
+}
+
+static int32_t SetVencSource(CODEC_HANDLETYPE codecHdl, uint32_t deviceId)
+{
+ Param param = {.key = KEY_DEVICE_ID, .val = (void *)&deviceId, .size = sizeof(uint32_t)};
+ int32_t ret = CodecSetParameter(codecHdl, ¶m, 1);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Set enc source failed.(ret=%d)", ret);
+ return ret;
+ }
+ return MEDIA_OK;
+}
+
+static int32_t CreateCodecAndSet(const Param *param, uint32_t paramIndex,
+ uint32_t srcDev, const CODEC_HANDLETYPE &codecHdlRef)
+{
+ const char *name = "codec.video.hardware.encoder";
+ CODEC_HANDLETYPE *codecHdl = (CODEC_HANDLETYPE *)&codecHdlRef;
+
+ int32_t ret = CodecCreate(name, param, paramIndex, codecHdl);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Create video encoder failed.");
+ return HAL_MEDIA_ERR;
+ }
+
+ ret = SetVencSource(*codecHdl, srcDev);
+ if (ret != 0) {
+ CodecDestroy(codecHdl);
+ return HAL_MEDIA_ERR;
+ }
+
+ return HAL_MEDIA_OK;
+}
+
+static int32_t CameraCreateVideoEnc(const FrameConfig &fc,
+ const HalVideoProcessorAttr &attr, uint32_t srcDev,
+ const CODEC_HANDLETYPE &codecHdl)
+{
+ const uint32_t maxParamNum = 10;
+ uint32_t paramIndex = 0;
+ Param param[maxParamNum];
+
+ CodecType domainKind = VIDEO_ENCODER;
+ param[paramIndex].key = KEY_CODEC_TYPE;
+ param[paramIndex].val = &domainKind;
+ param[paramIndex++].size = sizeof(CodecType);
+
+ AvCodecMime codecMime = MEDIA_MIMETYPE_VIDEO_HEVC;
+ param[paramIndex].key = KEY_MIMETYPE;
+ param[paramIndex].val = &codecMime;
+ param[paramIndex++].size = sizeof(AvCodecMime);
+
+ VenCodeRcMode rcMode = VENCOD_RC_CBR;
+ param[paramIndex].key = KEY_VIDEO_RC_MODE;
+ param[paramIndex].val = &rcMode;
+ param[paramIndex++].size = sizeof(VenCodeRcMode);
+
+ VenCodeGopMode gopMode = VENCOD_GOPMODE_NORMALP;
+ param[paramIndex].key = KEY_VIDEO_GOP_MODE;
+ param[paramIndex].val = &gopMode;
+ param[paramIndex++].size = sizeof(VenCodeGopMode);
+
+ Profile profile = HEVC_MAIN_PROFILE;
+ param[paramIndex].key = KEY_VIDEO_PROFILE;
+ param[paramIndex].val = &profile;
+ param[paramIndex++].size = sizeof(Profile);
+
+ PicSize picSize = Convert2CodecSize(attr.width, attr.height);
+ MEDIA_DEBUG_LOG("picSize=%d", picSize);
+ param[paramIndex].key = KEY_VIDEO_PIC_SIZE;
+ param[paramIndex].val = &picSize;
+ param[paramIndex++].size = sizeof(PicSize);
+
+ uint32_t frameRate = attr.fps;
+ MEDIA_DEBUG_LOG("frameRate=%u", frameRate);
+ param[paramIndex].key = KEY_VIDEO_FRAME_RATE;
+ param[paramIndex].val = &frameRate;
+ param[paramIndex++].size = sizeof(uint32_t);
+
+ return CreateCodecAndSet(param, paramIndex, srcDev, codecHdl);
+}
+
+static int32_t CameraCreateJpegEnc(const FrameConfig &fc, uint32_t srcDev,
+ const HalVideoProcessorAttr &attr, const CODEC_HANDLETYPE &codecHdlRef)
+{
+ CODEC_HANDLETYPE *codecHdl = (CODEC_HANDLETYPE *)&codecHdlRef;
+ const char *videoEncName = "codec.jpeg.hardware.encoder";
+ const uint32_t maxParamNum = 5;
+ Param param[maxParamNum];
+ uint32_t paramIndex = 0;
+
+ CodecType domainKind = VIDEO_ENCODER;
+ param[paramIndex].key = KEY_CODEC_TYPE;
+ param[paramIndex].val = &domainKind;
+ param[paramIndex].size = sizeof(CodecType);
+ paramIndex++;
+
+ AvCodecMime codecMime = MEDIA_MIMETYPE_IMAGE_JPEG;
+ param[paramIndex].key = KEY_MIMETYPE;
+ param[paramIndex].val = &codecMime;
+ param[paramIndex].size = sizeof(AvCodecMime);
+ paramIndex++;
+
+ PicSize picSize = Convert2CodecSize(attr.width, attr.height);
+ param[paramIndex].key = KEY_VIDEO_PIC_SIZE;
+ param[paramIndex].val = &picSize;
+ param[paramIndex].size = sizeof(PicSize);
+ paramIndex++;
+
+ int32_t ret = CodecCreate(videoEncName, param, paramIndex, codecHdl);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("CodecCreate failed.(ret=%d)", ret);
+ return HAL_MEDIA_ERR;
+ }
+
+ int32_t qfactor = -1;
+ ((FrameConfig &) fc).GetParameter(PARAM_KEY_IMAGE_ENCODE_QFACTOR, qfactor);
+ if (qfactor != -1) {
+ MEDIA_DEBUG_LOG("qfactor=%d", qfactor);
+ Param jpegParam = {
+ .key = KEY_IMAGE_Q_FACTOR,
+ .val = &qfactor,
+ .size = sizeof(qfactor)
+ };
+ ret = CodecSetParameter(*codecHdl, &jpegParam, 1);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("CodecSetParameter set jpeg qfactor failed.(ret=%u)", ret);
+ }
+ }
+
+ ret = SetVencSource(*codecHdl, srcDev);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Set video encoder source failed.");
+ CodecDestroy(*codecHdl);
+ return HAL_MEDIA_ERR;
+ }
+
+ return HAL_MEDIA_OK;
+}
+
+static int32_t CopyCodecOutput(char *dstBuf, uint32_t *size, const OutputInfo &buffer)
+{
+ int32_t bufferSize = 0;
+ for (uint32_t i = 0; i < buffer.bufferCnt; i++) {
+ uint32_t packSize = buffer.buffers[i].length - buffer.buffers[i].offset;
+ errno_t ret = memcpy_s(dstBuf, *size, buffer.buffers[i].addr + buffer.buffers[i].offset, packSize);
+ if (ret != EOK) {
+ return HAL_MEDIA_ERR;
+ }
+ bufferSize = bufferSize + packSize;
+ *size -= packSize;
+ dstBuf += packSize;
+ }
+
+ return bufferSize;
+}
+
+static int32_t FindAvailProcessorIdx(const Surface &surface,
+ const vector &attrs)
+{
+ uint32_t surfaceWidth = stoi(((Surface &) surface).GetUserData("surface_width"));
+ uint32_t surfaceHeight = stoi(((Surface &) surface).GetUserData("surface_height"));
+ for (uint32_t i = 0; i < attrs.size(); i++) {
+ if (attrs[i].width == surfaceWidth && attrs[i].height == surfaceHeight) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+static void GetSurfaceBufferConfig(const Surface &surface, BufferRequestConfig &config)
+{
+ config.width = stoi(((Surface &) surface).GetUserData("surface_width"));
+ config.height = stoi(((Surface &) surface).GetUserData("surface_height"));
+ config.strideAlignment = stoi(((Surface &) surface).GetUserData("surface_stride_Alignment"));
+ config.format = stoi(((Surface &) surface).GetUserData("surface_format"));
+ config.usage = stoi(((Surface &) surface).GetUserData("surface_usage"));
+ config.timeout = stoi(((Surface &) surface).GetUserData("surface_timeout"));
+}
+
+int RecordAssistant::OnVencBufferAvailble(UINTPTR hComponent, UINTPTR dataIn, OutputInfo *buffer)
+{
+ const int32_t KEY_IS_SYNC_FRAME = 1; // "is-sync-frame"
+ const int32_t KEY_TIME_US = 2; // "timeUs"
+ CODEC_HANDLETYPE hdl = reinterpret_cast(hComponent);
+ RecordAssistant *assistant = reinterpret_cast(dataIn);
+ list *surfaceList = nullptr;
+
+ if (buffer == nullptr) {
+ MEDIA_ERR_LOG("Codec buffer is null");
+ return MEDIA_ERR;
+ }
+
+ for (uint32_t idx = 0; idx < assistant->vencHdls_.size(); idx++) {
+ if (assistant->vencHdls_[idx] == hdl) {
+ surfaceList = &(assistant->vencSurfaces_[idx]);
+ break;
+ }
+ }
+ if (surfaceList == nullptr || surfaceList->empty()) {
+ MEDIA_ERR_LOG("Encoder handle is illegal.");
+ return -1;
+ }
+ int32_t ret = SURFACE_ERROR_OK;
+ for (auto &surface : *surfaceList) {
+ if (surface == nullptr) {
+ continue;
+ }
+ sptr surfaceBuffer;
+ int32_t releaseFence;
+ BufferRequestConfig config;
+ GetSurfaceBufferConfig(*surface, config);
+ SurfaceError result = assistant->mProducerSurface->RequestBuffer(surfaceBuffer, releaseFence, config);
+ if (result != SURFACE_ERROR_OK) {
+ MEDIA_ERR_LOG("No available buffer in surface.");
+ ret = SURFACE_ERROR_NO_BUFFER;
+ break;
+ }
+
+ uint32_t size = surfaceBuffer->GetSize();
+ void *buf = surfaceBuffer->GetVirAddr();
+ if (buf == nullptr) {
+ MEDIA_ERR_LOG("Invalid buffer address.");
+ ret = SURFACE_ERROR_NULLPTR;
+ break;
+ }
+ int32_t copiedSize = CopyCodecOutput((char *)buf, &size, *buffer);
+ if (copiedSize == HAL_MEDIA_ERR) {
+ MEDIA_ERR_LOG("No available buffer in surface.");
+ assistant->mProducerSurface->CancelBuffer(surfaceBuffer);
+ ret = SURFACE_ERROR_NOMEM;
+ break;
+ }
+ surface->SetUserData("surface_buffer_size", to_string(copiedSize));
+ surfaceBuffer->SetInt32(KEY_IS_SYNC_FRAME,
+ (((buffer->flag & STREAM_FLAG_KEYFRAME) == 0) ? 0 : 1));
+ surfaceBuffer->SetInt64(KEY_TIME_US, buffer->timeStamp);
+ BufferFlushConfig flushConfig;
+ if (assistant->mProducerSurface->FlushBuffer(surfaceBuffer, -1, flushConfig) != 0) {
+ MEDIA_ERR_LOG("Flush surface failed.");
+ assistant->mProducerSurface->CancelBuffer(surfaceBuffer);
+ ret = SURFACE_ERROR_ERROR;
+ break;
+ }
+ }
+
+ if ((ret = CodecQueueOutput(hdl, buffer, 0, -1)) != 0) {
+ MEDIA_ERR_LOG("Codec queue output failed.");
+ }
+
+ return ret;
+}
+
+CodecCallback RecordAssistant::recordCodecCb_ = {nullptr, nullptr, RecordAssistant::OnVencBufferAvailble};
+
+int32_t RecordAssistant::SetFrameConfig(FrameConfig &fc,
+ vector &hdls,
+ vector &attrs)
+{
+ fc_ = &fc;
+
+ auto surfaceList = fc.GetSurfaces();
+ if (surfaceList.size() != 1) {
+ MEDIA_ERR_LOG("Only support one surface in frame config now.");
+ return MEDIA_ERR;
+ }
+ for (auto &surface : surfaceList) {
+ CODEC_HANDLETYPE codecHdl = nullptr;
+ int32_t ProcessorIdx = FindAvailProcessorIdx(*surface, attrs);
+ sptr producer = surface->GetProducer();
+ mProducerSurface = Surface::CreateSurfaceAsProducer(producer);
+ if (ProcessorIdx < 0) {
+ MEDIA_ERR_LOG("No suitble procesor for recording.");
+ return MEDIA_ERR;
+ }
+ uint32_t deviceId = HalGetProcessorDeviceId(hdls[ProcessorIdx]);
+ int32_t encIdx = VideoEncIsExist(attrs[deviceId]);
+ if (encIdx >= 0) {
+ vencSurfaces_[encIdx].emplace_back(surface);
+ continue;
+ }
+
+ int32_t ret = CameraCreateVideoEnc(fc, attrs[ProcessorIdx], deviceId, codecHdl);
+ if (ret != MEDIA_OK) {
+ MEDIA_ERR_LOG("Cannot create suitble video encoder.");
+ return MEDIA_ERR;
+ }
+
+ ret = CodecSetCallback(codecHdl, &recordCodecCb_, reinterpret_cast(this));
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Set codec callback failed.(ret=%d)", ret);
+ CodecDestroy(codecHdl);
+ return MEDIA_ERR;
+ }
+ vencHdls_.emplace_back(codecHdl);
+ list conList({surface});
+ vencSurfaces_.emplace_back(conList);
+ vencAttr_.emplace_back(&attrs[deviceId]);
+ }
+ state_ = LOOP_READY;
+ return MEDIA_OK;
+}
+
+int32_t RecordAssistant::Start()
+{
+ if (state_ != LOOP_READY) {
+ return MEDIA_ERR;
+ }
+
+ int32_t ret = HAL_MEDIA_OK;
+ int32_t i;
+ for (i = 0; static_cast(i) < vencHdls_.size(); i++) {
+ ret = CodecStart(vencHdls_[i]);
+ if (ret != HAL_MEDIA_OK) {
+ MEDIA_ERR_LOG("Video encoder start failed.");
+ ret = MEDIA_ERR;
+ break;
+ }
+ }
+ if (ret == MEDIA_ERR) {
+ /* rollback */
+ for (; i >= 0; i--) {
+ CodecStop(vencHdls_[i]);
+ }
+ return MEDIA_ERR;
+ }
+ state_ = LOOP_LOOPING;
+
+ MEDIA_DEBUG_LOG("Start camera recording succeed.");
+ return MEDIA_OK;
+}
+
+int32_t RecordAssistant::Stop()
+{
+ if (state_ != LOOP_LOOPING) {
+ return MEDIA_ERR;
+ }
+
+ for (uint32_t i = 0; i < vencHdls_.size(); i++) {
+ CodecStop(vencHdls_[i]);
+ CodecDestroy(vencHdls_[i]);
+ }
+ vencHdls_.clear();
+ vencAttr_.clear();
+ vencSurfaces_.clear();
+
+ state_ = LOOP_STOP;
+ return MEDIA_OK;
+}
+
+int32_t RecordAssistant::VideoEncIsExist(const HalVideoProcessorAttr &attr)
+{
+ for (uint32_t i = 0; i < vencAttr_.size(); i++) {
+ if (vencAttr_[i] == &attr) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+static void GetSurfaceRect(const Surface &surface, HalVideoOutputAttr &attr)
+{
+ attr.regionPositionX = stoi(((Surface &) surface).GetUserData("region_position_x"));
+ attr.regionPositionY = stoi(((Surface &) surface).GetUserData("region_position_y"));
+ attr.regionWidth = stoi(((Surface &) surface).GetUserData("region_width"));
+ attr.regionHeight = stoi(((Surface &) surface).GetUserData("region_height"));
+}
+
+int32_t PreviewAssistant::SetFrameConfig(FrameConfig &fc,
+ vector &hdls,
+ vector &attrs)
+{
+ fc_ = &fc;
+
+ auto surfaceList = fc.GetSurfaces();
+ if (surfaceList.size() != 1) {
+ MEDIA_ERR_LOG("Only support one surface in frame config now.");
+ return MEDIA_ERR;
+ }
+ auto surface = surfaceList.front();
+ int32_t ProcessorIdx = FindAvailProcessorIdx(*surface, attrs);
+ if (ProcessorIdx < 0) {
+ MEDIA_ERR_LOG("No suitble procesor for preview.");
+ return MEDIA_ERR;
+ }
+
+ HalVideoOutputAttr attr;
+ GetSurfaceRect(*surface, attr);
+
+ return MEDIA_OK;
+}
+
+int32_t PreviewAssistant::Start()
+{
+ // enable vo
+ return MEDIA_OK;
+}
+
+int32_t PreviewAssistant::Stop()
+{
+ return MEDIA_OK;
+}
+
+int32_t CaptureAssistant::SetFrameConfig(FrameConfig &fc,
+ vector &hdls,
+ vector &attrs)
+{
+ auto surfaceList = fc.GetSurfaces();
+ if (surfaceList.size() != 1) {
+ MEDIA_ERR_LOG("Only support one surface in frame config now.");
+ return MEDIA_ERR;
+ }
+ if (surfaceList.empty()) {
+ MEDIA_ERR_LOG("Frame config with empty surface list.");
+ return MEDIA_ERR;
+ }
+ if (surfaceList.size() > 1) {
+ MEDIA_WARNING_LOG("Capture only fullfill the first surface in frame config.");
+ }
+ Surface *surface = surfaceList.front();
+ if (surface == nullptr) {
+ MEDIA_ERR_LOG("Surface is null.");
+ return MEDIA_ERR;
+ }
+ int32_t idx = FindAvailProcessorIdx(*surface, attrs);
+ if (idx < 0) {
+ MEDIA_ERR_LOG("No suitble procesor for venc.");
+ return MEDIA_ERR;
+ }
+ uint32_t deviceId = HalGetProcessorDeviceId(hdls[idx]);
+ int32_t ret = CameraCreateJpegEnc(fc, deviceId, attrs[idx], vencHdl_);
+ if (ret != HAL_MEDIA_OK) {
+ MEDIA_ERR_LOG("Create capture venc failed.");
+ return MEDIA_ERR;
+ }
+
+ capSurface_ = surface;
+
+ state_ = LOOP_READY;
+ return MEDIA_OK;
+}
+
+/* Block method, waiting for capture completed */
+int32_t CaptureAssistant::Start()
+{
+ state_ = LOOP_LOOPING;
+ int32_t ret = CodecStart(vencHdl_);
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Start capture encoder failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+ MEDIA_DEBUG_LOG("surface = %p", capSurface_);
+
+ sptr producer = capSurface_->GetProducer();
+ sptr producerSurface = Surface::CreateSurfaceAsProducer(producer);
+ sptr surfaceBuffer;
+ int32_t releaseFence;
+ BufferRequestConfig config;
+ GetSurfaceBufferConfig(*capSurface_, config);
+ SurfaceError result = producerSurface->RequestBuffer(surfaceBuffer, releaseFence, config);
+ if (result != SURFACE_ERROR_OK) {
+ MEDIA_ERR_LOG("No available buffer in surface.");
+ return -1;
+ }
+
+ OutputInfo outInfo;
+ ret = CodecDequeueOutput(vencHdl_, 0, nullptr, &outInfo);
+ if (ret != 0) {
+ producerSurface->CancelBuffer(surfaceBuffer);
+ MEDIA_ERR_LOG("Dequeue capture frame failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+
+ uint32_t size = surfaceBuffer->GetSize();
+ void *buf = surfaceBuffer->GetVirAddr();
+ if (buf == nullptr) {
+ MEDIA_ERR_LOG("Invalid buffer address.");
+ return -1;
+ }
+ int copiedSize = CopyCodecOutput((char *)buf, &size, outInfo);
+ if (copiedSize == HAL_MEDIA_ERR) {
+ MEDIA_ERR_LOG("No available buffer in producerSurface.");
+ producerSurface->CancelBuffer(surfaceBuffer);
+ return -1;
+ }
+
+ capSurface_->SetUserData("surface_buffer_size", to_string(copiedSize));
+ BufferFlushConfig flushConfig;
+ if (producerSurface->FlushBuffer(surfaceBuffer, -1, flushConfig) != 0) {
+ MEDIA_ERR_LOG("Flush surface buffer failed.");
+ producerSurface->CancelBuffer(surfaceBuffer);
+ return -1;
+ }
+
+ CodecQueueOutput(vencHdl_, &outInfo, 0, -1); // 0:no timeout -1:no fd
+ CodecStop(vencHdl_);
+ CodecDestroy(vencHdl_);
+
+ state_ = LOOP_STOP;
+
+ return MEDIA_OK;
+}
+
+int32_t CaptureAssistant::Stop()
+{
+ MEDIA_DEBUG_LOG("No support method.");
+ return MEDIA_OK;
+}
+
+CameraDevice::CameraDevice() {}
+
+CameraDevice::~CameraDevice() {}
+
+int32_t CameraDevice::Initialize(CameraAbility &ability)
+{
+ int32_t ret = HalMediaInitialize();
+ if (ret != HAL_MEDIA_OK) {
+ MEDIA_ERR_LOG("Media Init failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+ /* Need to be Refactored when delete config file */
+ ret = HalCreateVideoProcessor(nullptr);
+ if (ret != HAL_MEDIA_OK) {
+ MEDIA_ERR_LOG("Init camera device failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+ HalVideoProcessorAttr attrs[HAL_MAX_VPSS_NUM];
+ HalProcessorHdl hdls[HAL_MAX_VPSS_NUM];
+ int32_t size;
+ list range;
+ HalCameraGetProcessorAttr(hdls, attrs, &size);
+ for (int i = 0; i < size; i++) {
+ prcessorAttrs_.emplace_back(attrs[i]);
+ prcessorHdls_.emplace_back(hdls[i]);
+ CameraPicSize tmpSize = {.width = attrs[i].width, .height = attrs[i].height};
+ range.emplace_back(tmpSize);
+ }
+ ability.SetParameterRange(PARAM_KEY_SIZE, range);
+
+ ret = CodecInit();
+ if (ret != 0) {
+ MEDIA_ERR_LOG("Codec module init failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+ MEDIA_DEBUG_LOG("Codec module init succeed.");
+
+ captureAssistant_.state_ = LOOP_READY;
+ previewAssistant_.state_ = LOOP_READY;
+ recordAssistant_.state_ = LOOP_READY;
+ return MEDIA_OK;
+}
+
+int32_t CameraDevice::UnInitialize()
+{
+ HalDestroyVideoProcessor();
+ return MEDIA_OK;
+}
+
+int32_t CameraDevice::TriggerLoopingCapture(FrameConfig &fc)
+{
+ MEDIA_DEBUG_LOG("Camera device start looping capture.");
+
+ DeviceAssistant *assistant = nullptr;
+ int fcType = fc.GetFrameConfigType();
+ switch (fcType) {
+ case FRAME_CONFIG_RECORD:
+ assistant = &recordAssistant_;
+ break;
+ case FRAME_CONFIG_PREVIEW:
+ assistant = &previewAssistant_;
+ break;
+ case FRAME_CONFIG_CAPTURE:
+ assistant = &captureAssistant_;
+ break;
+ default:
+ break;
+ }
+ if (assistant == nullptr) {
+ MEDIA_ERR_LOG("Invalid frame config type.(type=%d)", fcType);
+ return MEDIA_ERR;
+ }
+ if ((assistant->state_ == LOOP_IDLE) || (assistant->state_ == LOOP_LOOPING) ||
+ (assistant->state_ == LOOP_ERROR)) {
+ MEDIA_ERR_LOG("Device state is %d, cannot start looping capture.", assistant->state_);
+ return MEDIA_ERR;
+ }
+
+ int ret = assistant->SetFrameConfig(fc, prcessorHdls_, prcessorAttrs_);
+ if (ret != MEDIA_OK) {
+ MEDIA_ERR_LOG("Check and set frame config failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+
+ ret = assistant->Start();
+ if (ret != MEDIA_OK) {
+ MEDIA_ERR_LOG("Start looping capture failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+
+ return MEDIA_OK;
+}
+
+void CameraDevice::StopLoopingCapture()
+{
+ previewAssistant_.Stop();
+ recordAssistant_.Stop();
+}
+
+int32_t CameraDevice::TriggerSingleCapture(FrameConfig &fc)
+{
+ return TriggerLoopingCapture(fc);
+}
+
+int32_t CameraDevice::SetCameraConfig(CameraConfig &config)
+{
+ cc_ = &config;
+ return MEDIA_OK;
+}
+} // namespace Media
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/camera/src/camera_impl.cpp b/frameworks/innerkitsimpl/camera/src/camera_impl.cpp
new file mode 100644
index 0000000..fa9d3dc
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_impl.cpp
@@ -0,0 +1,183 @@
+/*
+ * 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.
+ */
+
+#include "camera_impl.h"
+#include "camera_service.h"
+#include "media_log.h"
+
+using namespace std;
+
+namespace OHOS {
+namespace Media {
+#define FREE_PTR(ptr) \
+ delete ptr; \
+ ptr = nullptr; \
+
+CameraImpl::CameraImpl(std::string &id, const CameraAbility &ability)
+{
+ id_ = id;
+ ability_ = &ability;
+}
+
+string CameraImpl::GetCameraId()
+{
+ return id_;
+}
+
+const CameraConfig *CameraImpl::GetCameraConfig() const
+{
+ return config_;
+}
+
+FrameConfig *CameraImpl::GetFrameConfig(int32_t type)
+{
+ for (auto i : frameConfigs_) {
+ if (i->GetFrameConfigType() == type) {
+ return i;
+ }
+ }
+ return nullptr;
+}
+
+void CameraImpl::Configure(CameraConfig &config)
+{
+ if (config_ != nullptr) {
+ return;
+ }
+
+ config_ = &config;
+ if (config.GetFrameStateCb() == nullptr || config.GetEventHandler() == nullptr) {
+ FREE_PTR(config_);
+ return;
+ }
+
+ int32_t ret = device_->SetCameraConfig(config);
+ if (ret != MEDIA_OK) {
+ FREE_PTR(config_);
+ handler_->Post([this, ret] { this->stateCb_->OnConfigureFailed(this->GetCameraId(), ret); });
+ return;
+ }
+ handler_->Post([this] { this->stateCb_->OnConfigured(*this); });
+}
+
+void CameraImpl::Release()
+{
+ if (config_ != nullptr) {
+ delete config_;
+ config_ = nullptr;
+ }
+ handler_->Post([this] { this->stateCb_->OnReleased(*this); });
+}
+
+int32_t CameraImpl::TriggerLoopingCapture(FrameConfig &fc)
+{
+ if (config_ == nullptr) {
+ MEDIA_ERR_LOG("Cannot find available configuration, configure the camera first.");
+ return MEDIA_INVALID_PARAM;
+ }
+ FrameConfig *curFc = GetFrameConfig(fc.GetFrameConfigType());
+ if (curFc != nullptr) {
+ MEDIA_ERR_LOG("Frame config of the input type is already existed.");
+ return MEDIA_OK;
+ }
+ int32_t ret = device_->TriggerLoopingCapture(dynamic_cast(fc));
+ if (ret != MEDIA_OK) {
+ MEDIA_ERR_LOG("Camera device start looping capture failed.(ret=%d)", ret);
+ return MEDIA_ERR;
+ }
+ frameConfigs_.emplace_back(&fc);
+
+ return MEDIA_OK;
+}
+
+void CameraImpl::StopLoopingCapture()
+{
+ device_->StopLoopingCapture();
+ FrameStateCallback *fsc = config_->GetFrameStateCb();
+ if (fsc == nullptr) {
+ return;
+ }
+ EventHandler *eventhdl = config_->GetEventHandler();
+ if (eventhdl == nullptr) {
+ return;
+ }
+
+ for (auto i : frameConfigs_) {
+ eventhdl->Post([fsc, this, i] {
+ FrameResult frameResult;
+ fsc->OnFrameFinished(*this, *i, frameResult);
+ });
+ }
+ frameConfigs_.clear();
+}
+
+int32_t CameraImpl::TriggerSingleCapture(FrameConfig &fc)
+{
+ if (config_ == nullptr) {
+ MEDIA_ERR_LOG("Cannot find available configuration, configure the camera first.");
+ return MEDIA_INVALID_PARAM;
+ }
+ int32_t ret = device_->TriggerSingleCapture(dynamic_cast(fc));
+ FrameStateCallback *fsc = config_->GetFrameStateCb();
+ if (fsc == nullptr) {
+ return MEDIA_ERR;
+ }
+ EventHandler *eventhdl = config_->GetEventHandler();
+ if (eventhdl == nullptr) {
+ return MEDIA_ERR;
+ }
+ if (ret != MEDIA_OK) {
+ eventhdl->Post([fsc, this, &fc] {
+ FrameResult frameResult;
+ fsc->OnFrameError(*this, fc, -1, frameResult);
+ });
+ return MEDIA_ERR;
+ }
+ eventhdl->Post([fsc, this, &fc] {
+ FrameResult frameResult;
+ fsc->OnFrameFinished(*this, fc, frameResult);
+ });
+ return MEDIA_OK;
+}
+
+const CameraAbility *CameraImpl::GetAbility()
+{
+ return ability_;
+}
+
+void CameraImpl::OnCreate(CameraDevice &device)
+{
+ device_ = &device;
+ if (stateCb_ == nullptr || handler_ == nullptr) {
+ return;
+ }
+ handler_->Post([this] { this->stateCb_->OnCreated(*this); });
+}
+
+void CameraImpl::OnCreateFailed()
+{
+ if (stateCb_ == nullptr || handler_ == nullptr) {
+ return;
+ }
+ handler_->Post([this] { this->stateCb_->OnCreateFailed(id_, MEDIA_ERR); });
+}
+
+void CameraImpl::RegistCb(CameraStateCallback &callback, EventHandler &handler)
+{
+ handler_ = &handler;
+ stateCb_ = &callback;
+}
+} // namespace Media
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/camera/src/camera_kit.cpp b/frameworks/innerkitsimpl/camera/src/camera_kit.cpp
new file mode 100644
index 0000000..7581038
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_kit.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+#include "camera_kit.h"
+#include "camera_manager.h"
+
+using namespace std;
+namespace OHOS {
+namespace Media {
+CameraManager *g_cameraManager = nullptr;
+CameraKit::CameraKit()
+{
+ g_cameraManager = CameraManager::GetInstance();
+}
+
+CameraKit::~CameraKit() {}
+
+CameraKit *CameraKit::GetInstance()
+{
+ static CameraKit kit;
+ return &kit;
+}
+
+list CameraKit::GetCameraIds()
+{
+ return g_cameraManager->GetCameraIds();
+}
+
+const CameraAbility *CameraKit::GetCameraAbility(const string cameraId)
+{
+ return g_cameraManager->GetCameraAbility(cameraId);
+}
+
+void CameraKit::RegisterCameraDeviceCallback(CameraDeviceCallback &callback, EventHandler &handler)
+{
+ g_cameraManager->RegisterCameraDeviceCallback(callback, handler);
+}
+
+void CameraKit::UnregisterCameraDeviceCallback(CameraDeviceCallback &callback)
+{
+ g_cameraManager->UnregisterCameraDeviceCallback(callback);
+}
+
+void CameraKit::CreateCamera(const string &cameraId, CameraStateCallback &callback, EventHandler &handler)
+{
+ g_cameraManager->CreateCamera(cameraId, callback, handler);
+}
+} // namespace Media
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/camera/src/camera_manager.cpp b/frameworks/innerkitsimpl/camera/src/camera_manager.cpp
new file mode 100644
index 0000000..f365405
--- /dev/null
+++ b/frameworks/innerkitsimpl/camera/src/camera_manager.cpp
@@ -0,0 +1,168 @@
+/*
+ * 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.
+ */
+
+#include "camera_manager.h"
+
+#include
+#include