diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md deleted file mode 100755 index f09d98d..0000000 --- a/.gitee/ISSUE_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,13 +0,0 @@ -### 该问题是怎么引起的? - - - -### 重现步骤 - - - -### 报错信息 - - - - diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md deleted file mode 100755 index 33948fd..0000000 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,15 +0,0 @@ -### 相关的Issue - - -### 原因(目的、解决的问题等) - - -### 描述(做了什么,变更了什么) - - -### 测试用例(新增、改动、可能影响的功能) - - - - - diff --git a/BUILD.gn b/BUILD.gn deleted file mode 100755 index 509c1e5..0000000 --- a/BUILD.gn +++ /dev/null @@ -1,45 +0,0 @@ -import("//build/lite/config/component/lite_component.gni") - -shared_library("camera") { - sources = [ - "camera_ability.cpp", - "camera_config.cpp", - "camera_device.cpp", - "camera_impl.cpp", - "camera_kit.cpp", - "camera_manager.cpp", - "camera_service.cpp", - "event_handler.cpp", - "frame_config.cpp", - ] - cflags = ["-fPIC"] - cflags += ["-Wall"] - cflags_cc = cflags - include_dirs = [ - "//base/security/interfaces/kits/iam_lite", - "//foundation/multimedia/hals/camera_lite", - "//drivers/hdf/lite/hdi/codec/include" - ] - - ldflags = ["-lstdc++"] - ldflags += ["-lcodec"] - ldflags += ["-lhdi_media"] - ldflags += ["-L$ohos_root_path/$root_out_dir"] - public_configs = [":camera_external_library_config"] - deps = [ - "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", - "//base/security/services/iam_lite/pms_client:pms_client", - "//third_party/bounds_checking_function:libsec_shared", - "$ohos_vendor_adapter_dir/../../hardware:hardware_media_sdk", - "$ohos_vendor_adapter_dir/../../middleware:middleware_source_sdk", - "$ohos_vendor_adapter_dir/hals/multimedia:hdi_media", - ] - public_deps = [ - "//foundation/graphic/lite/frameworks/surface:surface", - ] -} - -config("camera_external_library_config") { - include_dirs = ["//foundation/multimedia/interfaces/kits/camera_lite"] - include_dirs += ["//foundation/multimedia/utils/lite/include"] -} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d15cfde --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# CAMERA\_LITE + +- [Introduction](#section11660541593) +- [Directory Structure](#section56984451495) +- [Usage](#section1648194512427) +- [Constraints](#section161941989596) +- [Repositories Involved](#section105062051111614) + +## Introduction + +This repository provides the camera capability. + +**Figure 1** Position of this repository \(in the dotted blue box\) in the multimedia subsystem +![](figures/position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem.png "position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem") + +## Directory Structure + +``` +/foundation/multimedia/camera_lite +├── frameworks # Framework code +└── interfaces # APIs + └── kits # External APIs +``` + +## Usage + +Build a single repository in the root directory. + +``` +# Select the development board. +hb set +# Build this repository. +hb build camera_lite +``` + +## Constraints + +C++ 11 or later + +## Repositories Involved + +/hmf/multimedia/audio\_lite + +/hmf/multimedia/media\_lite + +/hmf/multimedia/utils\_lite + +/hmf/multimedia/service\_lite + diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..a247a4f --- /dev/null +++ b/README_zh.md @@ -0,0 +1,49 @@ +# 媒体子系统CAMERA\_LITE组件 + +- [简介](#section11660541593) +- [目录](#section56984451495) +- [使用说明](#section1648194512427) +- [约束](#section161941989596) +- [相关仓](#section105062051111614) + +## 简介 + +Camera\_Lite组件提供相机能力的支持。 + +**图 1** 媒体子系统架构(蓝色虚线框是camera\_lite) +![](figures/媒体子系统架构(蓝色虚线框是camera_lite).png "媒体子系统架构(蓝色虚线框是camera_lite)") + +## 目录 + +``` +/foundation/multimedia/camera_lite +├── frameworks # 框架代码 +└── interfaces # 接口 + └── kits # 对外接口 +``` + +## 使用说明 + +单仓的编译构建,在根目录下进行整仓的构建和编译 + +``` +# 开发板选择 +hb set +# 单仓构建和编译 +hb build camera_lite +``` + +## 约束 + +C++11版本或以上 + +## 相关仓 + +/hmf/multimedia/audio\_lite + +/hmf/multimedia/media\_lite + +/hmf/multimedia/utils\_lite + +/hmf/multimedia/service\_lite + diff --git a/figures/position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem.png b/figures/position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem.png new file mode 100644 index 0000000..68f86ae Binary files /dev/null and b/figures/position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem.png differ diff --git a/figures/媒体子系统架构(蓝色虚线框是camera_lite).png b/figures/媒体子系统架构(蓝色虚线框是camera_lite).png new file mode 100644 index 0000000..e7b66db Binary files /dev/null and b/figures/媒体子系统架构(蓝色虚线框是camera_lite).png differ diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn new file mode 100644 index 0000000..9e44287 --- /dev/null +++ b/frameworks/BUILD.gn @@ -0,0 +1,43 @@ +import("//build/lite/config/component/lite_component.gni") + +shared_library("camera_lite") { + sources = [ + "camera_ability.cpp", + "camera_config.cpp", + "camera_device.cpp", + "camera_impl.cpp", + "camera_kit.cpp", + "camera_manager.cpp", + "camera_service.cpp", + "event_handler.cpp", + "frame_config.cpp", + ] + cflags = [ "-fPIC" ] + cflags += [ "-Wall" ] + cflags_cc = cflags + include_dirs = [ + "//base/security/permission/interfaces/kits/permission_lite", + "//drivers/peripheral/codec/interfaces/include", + "//foundation/multimedia/utils/lite/hals", + ] + + ldflags = [ "-lstdc++" ] + ldflags += [ "-lcodec" ] + ldflags += [ "-lhdi_media" ] + ldflags += [ "-L$ohos_root_path/$root_out_dir" ] + public_configs = [ ":camera_external_library_config" ] + deps = [ + "$ohos_vendor_adapter_dir:hardware_media_sdk", + "$ohos_vendor_adapter_dir/../modules/middleware:middleware_source_sdk", + "$ohos_vendor_adapter_dir/multimedia:libhdi_media", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/security/permission/services/permission_lite/pms_client:pms_client", + "//third_party/bounds_checking_function:libsec_shared", + ] + public_deps = [ "//foundation/graphic/surface:lite_surface" ] +} + +config("camera_external_library_config") { + include_dirs = [ "//foundation/multimedia/camera_lite/interfaces/kits" ] + include_dirs += [ "//foundation/multimedia/utils/lite/include" ] +} diff --git a/camera_ability.cpp b/frameworks/camera_ability.cpp similarity index 93% rename from camera_ability.cpp rename to frameworks/camera_ability.cpp index c911d8d..72d2296 100755 --- a/camera_ability.cpp +++ b/frameworks/camera_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/camera_config.cpp b/frameworks/camera_config.cpp similarity index 94% rename from camera_config.cpp rename to frameworks/camera_config.cpp index d1dfd7e..a205597 100755 --- a/camera_config.cpp +++ b/frameworks/camera_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/camera_device.cpp b/frameworks/camera_device.cpp similarity index 87% rename from camera_device.cpp rename to frameworks/camera_device.cpp index 18f222b..f0a1263 100755 --- a/camera_device.cpp +++ b/frameworks/camera_device.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 @@ -15,15 +15,15 @@ #include "camera_device.h" -#include -#include - #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; @@ -33,10 +33,24 @@ const int32_t KEY_TIME_US = 2; // "timeUs" namespace OHOS { namespace Media { -inline PicSize Convert2CodecSize(CameraPicSize size) +inline PicSize Convert2CodecSize(int32_t width, int32_t height) { - return (PicSize)size; + 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)}; @@ -86,7 +100,7 @@ static int32_t param[paramIndex].size = sizeof(Profile); paramIndex++; - PicSize picSize = Convert2CodecSize(attr->size); + PicSize picSize = Convert2CodecSize(attr->width, attr->height); MEDIA_DEBUG_LOG("picSize=%d", picSize); param[paramIndex].key = KEY_VIDEO_PIC_SIZE; param[paramIndex].val = &picSize; @@ -115,7 +129,8 @@ static int32_t return HAL_MEDIA_OK; } -static int32_t CameraCreateJpegEnc(uint32_t srcDev, HalVideoProcessorAttr *attr, CODEC_HANDLETYPE *codecHdl) +static int32_t + CameraCreateJpegEnc(FrameConfig &fc, uint32_t srcDev, HalVideoProcessorAttr *attr, CODEC_HANDLETYPE *codecHdl) { const char *videoEncName = "codec.jpeg.hardware.encoder"; const uint32_t maxParamNum = 5; @@ -134,7 +149,7 @@ static int32_t CameraCreateJpegEnc(uint32_t srcDev, HalVideoProcessorAttr *attr, param[paramIndex].size = sizeof(AvCodecMime); paramIndex++; - PicSize picSize = Convert2CodecSize(attr->size); + PicSize picSize = Convert2CodecSize(attr->width, attr->height); param[paramIndex].key = KEY_VIDEO_PIC_SIZE; param[paramIndex].val = &picSize; param[paramIndex].size = sizeof(PicSize); @@ -145,6 +160,21 @@ static int32_t CameraCreateJpegEnc(uint32_t srcDev, HalVideoProcessorAttr *attr, return HAL_MEDIA_ERR; } + int32_t qfactor = -1; + 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."); @@ -172,9 +202,8 @@ static int32_t CopyCodecOutput(void *dst, uint32_t *size, OutputInfo *buffer) static int32_t FindAvailProcessorIdx(Surface &surface, vector &attrs) { - CameraPicSize picSize = HalConvert2StandardSize(surface.GetWidth(), surface.GetHeight()); for (uint32_t i = 0; i < attrs.size(); i++) { - if (attrs[i].size == picSize) { + if (attrs[i].width == surface.GetWidth() && attrs[i].height == surface.GetHeight()) { return i; } } @@ -412,7 +441,7 @@ int32_t CaptureAssistant::SetFrameConfig(FrameConfig &fc, return MEDIA_ERR; } uint32_t deviceId = HalGetProcessorDeviceId(hdls[idx]); - int32_t ret = CameraCreateJpegEnc(deviceId, &attrs[idx], &vencHdl_); + int32_t ret = CameraCreateJpegEnc(fc, deviceId, &attrs[idx], &vencHdl_); if (ret != HAL_MEDIA_OK) { MEDIA_ERR_LOG("Create capture venc failed."); return MEDIA_ERR; @@ -504,7 +533,8 @@ int32_t CameraDevice::Initialize(CameraAbility &ability) for (int i = 0; i < size; i++) { prcessorAttrs_.emplace_back(attrs[i]); prcessorHdls_.emplace_back(hdls[i]); - range.emplace_back(attrs[i].size); + CameraPicSize tmpSize = {.width = attrs[i].width, .height = attrs[i].height}; + range.emplace_back(tmpSize); } ability.SetParameterRange(PARAM_KEY_SIZE, range); diff --git a/camera_device.h b/frameworks/camera_device.h similarity index 93% rename from camera_device.h rename to frameworks/camera_device.h index a64f84b..cfd8bb5 100755 --- a/camera_device.h +++ b/frameworks/camera_device.h @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_impl.cpp b/frameworks/camera_impl.cpp similarity index 94% rename from camera_impl.cpp rename to frameworks/camera_impl.cpp index 0d3a953..42971ce 100755 --- a/camera_impl.cpp +++ b/frameworks/camera_impl.cpp @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_impl.h b/frameworks/camera_impl.h similarity index 91% rename from camera_impl.h rename to frameworks/camera_impl.h index b5f66c7..9654898 100755 --- a/camera_impl.h +++ b/frameworks/camera_impl.h @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_kit.cpp b/frameworks/camera_kit.cpp similarity index 88% rename from camera_kit.cpp rename to frameworks/camera_kit.cpp index 02306b5..250ac2b 100755 --- a/camera_kit.cpp +++ b/frameworks/camera_kit.cpp @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, @@ -29,7 +29,7 @@ CameraKit::~CameraKit() {} CameraKit *CameraKit::GetInstance() { - if (CheckPermission(0, "ohos.permission.CAMERA") != GRANTED) { + if (CheckSelfPermission("ohos.permission.CAMERA") != GRANTED) { MEDIA_WARNING_LOG("Process can not access camera."); return nullptr; } diff --git a/camera_manager.cpp b/frameworks/camera_manager.cpp similarity index 94% rename from camera_manager.cpp rename to frameworks/camera_manager.cpp index c0c5e82..f046d95 100755 --- a/camera_manager.cpp +++ b/frameworks/camera_manager.cpp @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, @@ -127,6 +127,7 @@ public: auto p = cameraMapCache_.find(cameraId); if (p == cameraMapCache_.end()) { handler.Post([&callback, &cameraId] { callback.OnCreateFailed(cameraId, MEDIA_ERR); }); + return; } p->second->RegistCb(callback, handler); cameraService_->CreateCamera(cameraId); @@ -155,4 +156,4 @@ CameraManager *CameraManager::GetInstance() return &cameraManagerImpl; } } // namespace Media -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/camera_manager.h b/frameworks/camera_manager.h similarity index 90% rename from camera_manager.h rename to frameworks/camera_manager.h index 223203c..df49f44 100755 --- a/camera_manager.h +++ b/frameworks/camera_manager.h @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_service.cpp b/frameworks/camera_service.cpp similarity index 92% rename from camera_service.cpp rename to frameworks/camera_service.cpp index ba72ffc..eeb8d68 100755 --- a/camera_service.cpp +++ b/frameworks/camera_service.cpp @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_service.h b/frameworks/camera_service.h similarity index 89% rename from camera_service.h rename to frameworks/camera_service.h index 85c5700..a57fac7 100755 --- a/camera_service.h +++ b/frameworks/camera_service.h @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/camera_service_callback.h b/frameworks/camera_service_callback.h similarity index 89% rename from camera_service_callback.h rename to frameworks/camera_service_callback.h index e42b4ad..b8ada0c 100755 --- a/camera_service_callback.h +++ b/frameworks/camera_service_callback.h @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/event_handler.cpp b/frameworks/event_handler.cpp similarity index 91% rename from event_handler.cpp rename to frameworks/event_handler.cpp index 0eeb6a2..8483132 100755 --- a/event_handler.cpp +++ b/frameworks/event_handler.cpp @@ -1,10 +1,10 @@ /* - * Copyright(c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 + * 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, diff --git a/frame_config.cpp b/frameworks/frame_config.cpp similarity index 68% rename from frame_config.cpp rename to frameworks/frame_config.cpp index a56c2d9..cf17675 100755 --- a/frame_config.cpp +++ b/frameworks/frame_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 @@ -39,6 +39,23 @@ void FrameConfig::RemoveSurface(Surface &surface) surfaceList_.remove(&surface); } +void *FrameConfig::GetValue(uint32_t key) +{ + auto p = keyMap_.find(key); + return (p == keyMap_.end()) ? nullptr : (&p->second); +} + +void FrameConfig::SetValue(uint32_t key, const void *value) +{ + switch (key) { + case PARAM_KEY_IMAGE_ENCODE_QFACTOR: + keyMap_[key] = *(static_cast(value)); + break; + default: + break; + } +} + FrameConfig::FrameConfig(int32_t type) : type_(type) {} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/camera.h b/interfaces/kits/camera.h new file mode 100755 index 0000000..a18db1f --- /dev/null +++ b/interfaces/kits/camera.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2020-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 MultiMedia_Camera + * @{ + * + * @brief Defines the Camera class for camera-related operations. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera.h + * + * @brief Declares functions in the Camera class to implement camera + * operations. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_CAMERA_H +#define OHOS_CAMERA_H + +#include +#include + +#include "camera_config.h" +#include "frame_config.h" + +namespace OHOS { +namespace Media { +/** + * + * @brief Provides functions in the Camera class to implement camera operations. + * operations. + * + * + * @since 1.0 + * @version 1.0 + */ +class Camera { +public: + /** + * @brief A destructor used to delete the Camera instance. + * + */ + virtual ~Camera() = default; + + /** + * @brief Obtains the camera ID. + * + * @return Returns the camera ID if obtained; returns the "Error" string if + * the camera fails to be created. + */ + virtual std::string GetCameraId() + { + return std::string(); + } + + /** + * @brief Obtains the camera configuration. + * You can use the obtained CameraConfig object to configure the + * camera. + * @return Returns the pointer to the CameraConfig object if obtained; + * returns NULL otherwise. + */ + virtual const CameraConfig *GetCameraConfig() const + { + return nullptr; + } + + /** + * @brief Obtains the frame configuration. + * + * @param type Indicates the type of the frame configuration. + * @return Returns the pointer to the FrameConfig object if obtained; + * returns NULL otherwise. + */ + virtual FrameConfig *GetFrameConfig(int32_t type) + { + return nullptr; + } + + /** + * @brief Configures the camera using the CameraConfig object. + * + * @param config Indicates the pointer to the CameraConfig object. + */ + virtual void Configure(CameraConfig &config) {} + + /** + * @brief Triggers looping-frame capture. + * + * @param fc Indicates the frame configuration. + * @return Returns true if the looping-frame capture is successfully + * started; returns false otherwise. + */ + virtual int32_t TriggerLoopingCapture(FrameConfig &frameConfig) + { + return -1; + } + + /** + * @brief Stops looping-frame capture. + * + * @return Returns true if the looping-frame capture is successfully + * stopped; returns false otherwise. + */ + virtual void StopLoopingCapture() {} + + /** + * @brief Starts single-frame capture. The frame parameters are set through + * the FrameConfig object, and the captured image data is stored in the + * surface of the FrameConfig object. + * + * @param fc Indicates the frame configuration. + * @return Returns true if the single-frame capture is successfully + * started and the data is stored; returns false otherwise. + */ + virtual int32_t TriggerSingleCapture(FrameConfig &frameConfig) + { + return -1; + } + + /** + * @brief Releases the Camera object and associated resources. + * + */ + virtual void Release() {} + +protected: + /** + * @brief A constructor used to create a Camera instance. + * + */ + Camera() = default; +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_CAMERA_H diff --git a/interfaces/kits/camera_ability.h b/interfaces/kits/camera_ability.h new file mode 100755 index 0000000..f64226e --- /dev/null +++ b/interfaces/kits/camera_ability.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2020-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 MultiMedia_CameraAbility + * @{ + * + * @brief Defines the camera capability set for applications to achieve and access the capabilities. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera_ability.h + * + * @brief Declares functions of the CameraAbility class. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_CAMERA_ABILITY_H +#define OHOS_CAMERA_ABILITY_H + +#include "media_log.h" +#include "meta_data.h" + +#include +#include +#include +#include + +namespace OHOS { +namespace Media { +/** + * @brief Declares functions of the CameraAbility class. + * + * + * @since 1.0 + * @version 1.0 + */ +class CameraAbility { +public: + /** + * @brief A constructor used to create a CameraAbility instance. + * + */ + CameraAbility(); + + /** + * @brief A destructor used to delete the CameraAbility instance. + * + */ + virtual ~CameraAbility(); + + /** + * @brief Obtains the supported image sizes for a specified image format. + * + * @param format Indicates the image format, which can be YUV, H.265, or H.264. + * @return Returns the image size list if obtained; returns NULL otherwise. + */ + std::list GetSupportedSizes(int format) const; + + /** + * @brief Sets value ranges for a specified parameter. + * + * @param key Indicates the parameter key. + * @param rangeList Indicates the list of parameter value ranges. + * @return Returns SUCCESS if the setting is successful; returns FAIL otherwise. + */ + template int32_t SetParameterRange(uint32_t key, std::list rangeList) + { + if (IsParameterSupport(key)) { + SetSupportParameterRange(key, rangeList); + return MEDIA_OK; + } + return MEDIA_ERR; + } + + /** + * @brief Obtains the parameter value range based on a specified parameter key. + * + * @param key Indicates the parameter key. + * @return Returns the parameter value range if obtained; returns NULL otherwise. + */ + template std::list GetParameterRange(uint32_t key) const + { + if (supportProperties_.find(key) != supportProperties_.end()) { + return GetSupportParameterRange(key); + } + } + +private: + void SetSupportParameterRange(uint32_t key, std::list &rangeList); + std::list GetSupportParameterRange(uint32_t key) const; + bool IsParameterSupport(uint32_t key) const; + + std::map> SizeMap_; + std::set supportProperties_; +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_CAMERA_ABILITY_H diff --git a/interfaces/kits/camera_config.h b/interfaces/kits/camera_config.h new file mode 100755 index 0000000..f34f0e8 --- /dev/null +++ b/interfaces/kits/camera_config.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2020-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 MultiMedia_CameraConfig + * @{ + * + * @brief Defines the CameraConfig class for operations on camera configurations. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera_config.h + * + * @brief Declares functions in the CameraConfig class. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_CAMERA_CONFIG_H +#define OHOS_CAMERA_CONFIG_H + +#include "event_handler.h" +#include "frame_state_callback.h" + +namespace OHOS { +namespace Media { +/** + * + * @brief Provides functions to configure camera parameters. + * + * + * @since 1.0 + * @version 1.0 + */ +class CameraConfig { +public: + /** + * @brief A destructor used to delete the CameraAbility instance. + * + */ + virtual ~CameraConfig() {} + + /** + * @brief Creates the CameraConfig instance of this singleton class to configure + * and read the required parameters. + * + * @return Returns the CameraConfig instance if created; returns NULL otherwise. + */ + static CameraConfig *CreateCameraConfig(); + + /** + * @brief Sets a frame state callback to responds to state changes. + * + * @param callback Indicates the frame state callback. + * @param handler Indicates the event handler. + */ + virtual void SetFrameStateCallback(FrameStateCallback *callback, EventHandler *handler) {} + + /** + * @brief Obtains the EventHandler object. + * + * @return Returns the pointer to the EventHandler object if obtained; returns NULL otherwise. + */ + virtual EventHandler *GetEventHandler() const + { + return nullptr; + } + + /** + * @brief Obtains a FrameStateCallback object. + * + * @return Returns the pointer to the FrameStateCallback object if obtained; returns NULL otherwise. + */ + virtual FrameStateCallback *GetFrameStateCb() const + { + return nullptr; + } + +protected: + /** + * @brief A constructor used to create a CameraConfig instance. + * + */ + CameraConfig() {} +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_CAMERA_CONFIG_H diff --git a/interfaces/kits/camera_device_callback.h b/interfaces/kits/camera_device_callback.h new file mode 100755 index 0000000..7dd80a0 --- /dev/null +++ b/interfaces/kits/camera_device_callback.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020-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 MultiMedia_CameraDeviceCallback + * @{ + * + * @brief Defines the CameraDeviceCallback class to response to device changes. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera_device_callback.h + * + * @brief Declares functions in the CameraDeviceCallback class to response to device changes. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_CAMERA_DEVICE_CALLBACK_H +#define OHOS_CAMERA_DEVICE_CALLBACK_H + +#include + +namespace OHOS { +namespace Media { +constexpr int32_t CAMERA_DEVICE_STATE_AVAILABLE = 0; +constexpr int32_t CAMERA_DEVICE_STATE_UNAVAILABLE = 1; +/** + * + * @brief Provides functions to response to device changes. + * + * + * @since 1.0 + * @version 1.0 + */ +class CameraDeviceCallback { +public: + /** + * @brief A constructor used to create a CameraDeviceCallback instance. + * + */ + CameraDeviceCallback() = default; + + /** + * @brief A destructor used to delete the CameraDeviceCallback instance. + * + */ + virtual ~CameraDeviceCallback() = default; + + /** + * @brief Called when the camera state changes. + * + * @param cameraId Indicates the camera ID. + * @param status Indicates the camera state. + */ + virtual void OnCameraStatus(std::string cameraId, int32_t status) {} +}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/interfaces/kits/camera_kit.h b/interfaces/kits/camera_kit.h new file mode 100755 index 0000000..ce93c80 --- /dev/null +++ b/interfaces/kits/camera_kit.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2020-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 MultiMedia_CameraKit + * @{ + * + * @brief Defines the CameraKit class for using camera functionalities. + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera_kit.h + * + * @brief Declares functions in the CameraKit class. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_CAMERA_KIT_H +#define OHOS_CAMERA_KIT_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 { +/** + * + * @brief Provides functions in the CameraKit class. + * + * + * @since 1.0 + * @version 1.0 + */ +class CameraKit { +public: + /** + * @brief A destructor used to delete the CameraKit instance. + * + */ + ~CameraKit(); + /** + * @brief Obtains a single instance of the CameraKit. + * @return Returns the CameraKit instance if obtained; returns NULL otherwise. + */ + static CameraKit *GetInstance(); + + /** + * @brief Obtains IDs of cameras that are currently available. + * + * @return Returns the camera IDs if obtained; returns NULL otherwise. + */ + std::list GetCameraIds(); + + /** + * @brief Obtains the camera capability, including the resolutions and frame rates. + * + * @param cameraId Indicates the camera ID. + * @return Returns the CameraAbility object. + */ + const CameraAbility *GetCameraAbility(std::string cameraId); + + /** + * @brief Registers a camera callback for camera status changes + * and an event callback to respond to a triggered event. + * + * @param callback Indicates the camera callback to register. + * @param handler Indicates the event callback to register. + */ + void RegisterCameraDeviceCallback(CameraDeviceCallback &callback, EventHandler &handler); + + /** + * @brief Unregisters a camera callback. + * + * @param callback Indicates the camera callback to unregister. + */ + void UnregisterCameraDeviceCallback(CameraDeviceCallback &callback); + + /** + * @brief Creates a camera object. + * + * @param cameraId Indicates the camera ID. + * @param callback Indicates the camera callback. + * @param handler Indicates the event callback to register. + */ + void CreateCamera(const std::string &cameraId, CameraStateCallback &callback, EventHandler &handler); + +private: + /** + * @brief A constructor used to create a CameraDeviceCallback instance. + * + */ + CameraKit(); +}; +} // namespace Media +} // namespace OHOS + +#endif // OHOS_CAMERA_KIT_H diff --git a/interfaces/kits/camera_state_callback.h b/interfaces/kits/camera_state_callback.h new file mode 100755 index 0000000..b32fb07 --- /dev/null +++ b/interfaces/kits/camera_state_callback.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2020-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 MultiMedia_CameraStateCallback + * @{ + * + * @brief Provides callbacks for camera states to configure responses to the states. + * + * @since 1.0 + * @version 1.0 + */ + /** + * @file camera_state_callback.h + * + * @brief Declares functions in the CameraStateCallback class. + * + * @since 1.0 + * @version 1.0 + */ +#ifndef OHOS_CAMERA_STATE_CALLBACK_H +#define OHOS_CAMERA_STATE_CALLBACK_H + +#include +#include "camera.h" + +namespace OHOS { +namespace Media { +/** +* +* @brief Provides functions to response to camera states. +* +* @since 1.0 +* @version 1.0 +*/ +class CameraStateCallback { +public: + /** + * @brief A constructor used to create a CameraStateCallback instance. + * + */ + CameraStateCallback() = default; + /** + * @brief A destructor used to delete the CameraStateCallback instance. + * + */ + virtual ~CameraStateCallback() {} + /** + * @brief Called when the camera is successfully created. + * + * @param c Indicates the Camera object. + */ + virtual void OnCreated(Camera &c) {} + /** + * @brief Called when the camera fails to be created. + * + * @param cameraId Indicates the camera ID. + * @param errorCode Indicates the error code. + */ + virtual void OnCreateFailed(const std::string cameraId, int32_t errorCode) {} + /** + * @brief Called when the camera is released. + * + * @param c Indicates the Camera object. + */ + virtual void OnReleased(Camera &c) {} + /** + * @brief Called when the camera is configured. + * @param c camera Indicates the Camera object. + */ + virtual void OnConfigured(Camera &c) {} + /** + * @brief Called when the camera fails to be configured. + * + * @param c Indicates the Camera object. + * @param errorCode Indicates the error code. + */ + virtual void OnConfigureFailed(const std::string cameraId, int32_t errorCode) {} +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_CAMERA_STATE_CALLBACK_H diff --git a/interfaces/kits/event_handler.h b/interfaces/kits/event_handler.h new file mode 100755 index 0000000..906bc1c --- /dev/null +++ b/interfaces/kits/event_handler.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020-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_EVENTHANDLER_H +#define OHOS_EVENTHANDLER_H + +#include +#include +#include +#include + +namespace OHOS { +namespace Media { +class EventHandler { +public: + EventHandler(); + virtual ~EventHandler(); + /* After construct the event handler, user should check whether the thread is running before post or + * destroy this handler */ + bool IsRunning(); + + template + void Post(const F &f) + { + auto task = new PostTask(f); + std::unique_lock lock(mtx_); + msgQ_.emplace(task); + cv_.notify_all(); + } + +private: + struct EventObj { + EventObj() = default; + virtual ~EventObj(){}; + virtual void Exec(){}; + }; + + std::queue msgQ_; + std::thread *hdlThrd_; + bool running_; + std::condition_variable cv_; + std::mutex mtx_; + + template + struct PostTask : public EventObj { + PostTask(const F &f) : f_(f) {} + const F f_; + void Exec() override + { + f_(); + } + }; + + static void EventDispatch(EventHandler *hdl); +}; +} // namespace Media +} // namespace OHOS + +#endif // OHOS_EVENTHANDLER_H diff --git a/interfaces/kits/frame_config.h b/interfaces/kits/frame_config.h new file mode 100755 index 0000000..d80a0bf --- /dev/null +++ b/interfaces/kits/frame_config.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2020-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 MultiMedia_FrameConfig + * @{ + * + * @brief Defines the FrameConfig class for operations related to frame + * configurations. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file frame_config.h + * + * @brief Declares APIs of the FrameConfig class. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_FRAME_CONFIG_H +#define OHOS_FRAME_CONFIG_H + +#include "meta_data.h" +#include "surface.h" +#include +#include + +namespace OHOS { +namespace Media { +constexpr int32_t FRAME_CONFIG_PREVIEW = 0; +constexpr int32_t FRAME_CONFIG_RECORD = 1; +constexpr int32_t FRAME_CONFIG_CAPTURE = 2; +/** + * @brief Provides functions to configure frames. + * + * + * @since 1.0 + * @version 1.0 + */ +class FrameConfig { +public: + /** + * @brief A constructor used to create a FrameConfig instance. + * + */ + FrameConfig() = delete; + /** + * @brief A constructor used to create a FrameConfig instance based on the configuration mode. + * + * @param type Indicates the frame configuration mode, which can be FRAME_CONFIG_PREVIEW, + * @FRAME_CONFIG_RECORD, or FRAME_CONFIG_CAPTURE. + */ + FrameConfig(int32_t type); + + /** + * @brief A destructor used to delete the FrameConfig instance. + * + */ + ~FrameConfig() {} + + /** + * @brief Obtains the frame configuration type. + * + * @return Returns the frame configuration type if obtained; returns -1 + * otherwise. + */ + int32_t GetFrameConfigType(); + + /** + * @brief Obtains a list of shared memories (surface objects). + * + * @return Returns the list of shared memories if obtained; returns + * NULL otherwise. + * + */ + std::list GetSurfaces(); + + /** + * @brief Adds a surface (an object of shared memory). + * + * @param surface Indicates the surface to add. + */ + void AddSurface(Surface &surface); + + /** + * @brief Removes a surface (an object of shared memory). + * You can call this function to release the surface when your + * application does not need to obtain data. + * + * @param surface Indicates the surface to remove. + */ + void RemoveSurface(Surface &surface); + + /** + * @brief Sets the common parameter. + * @param key Indicates the common parameter key to set. + * @param value Indicates the common parameter value to set. + */ + template void SetParameter(uint32_t key, const T value) + { + SetValue(key, static_cast(&value)); + } + + /** + * @brief Obtains the value of a common parameter based on its key. For + * details, see {@link CAMERA_FUC_KEY}. + * @param key Indicates the common parameter key. + */ + template void GetParameter(uint32_t key, T &value) + { + T *pvalue = static_cast(GetValue(key)); + if (pvalue != nullptr) { + value = *pvalue; + } + } +private: + int32_t type_; + std::list surfaceList_; + std::map keyMap_; + void *GetValue(uint32_t key); + void SetValue(uint32_t key, const void *value); +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_FRAME_CONFIG_H diff --git a/interfaces/kits/frame_state_callback.h b/interfaces/kits/frame_state_callback.h new file mode 100755 index 0000000..6ec605a --- /dev/null +++ b/interfaces/kits/frame_state_callback.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020-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 MultiMedia_FrameStateCallback + * @{ + * + * @brief Provides callbacks for frame state changes, in which you can implement operations to response to the changes. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file camera_kit.h + * + * @brief Declares functions in the FrameStateCallback class. + * + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef OHOS_FRAME_STATE_CALLBACK_H +#define OHOS_FRAME_STATE_CALLBACK_H + +namespace OHOS { +namespace Media { +class Camera; +class FrameConfig; +class FrameResult {}; +/** + * @brief Provides functions to listen for frame states and response to the state changes. + * + * + * @since 1.0 + * @version 1.0 + */ +class FrameStateCallback { +public: + /** + * @brief A constructor used to create a FrameStateCallback instance. + * + */ + FrameStateCallback() = default; + + /** + * @brief A destructor used to delete the FrameStateCallback instance. + * + */ + ~FrameStateCallback() = default; + + /** + * @brief Called when the frame capture is finished. + * + * @param camera Indicates the camera. + * @param frameConfig Indicates the frame configuration. + * @param frameResult Indicates the capture results. + */ + virtual void OnFrameFinished(Camera &camera, FrameConfig &frameConfig, FrameResult &frameResult) {} + + /** + * @brief Called when the frame capture fails. + * + * @param camera Indicates the camera. + * @param frameConfig Indicates the frame configuration. + * @param errorCode Indicates the error code. + * @param frameResult Indicates the capture results. + */ + virtual void OnFrameError(Camera &camera, FrameConfig &frameConfig, int32_t errorCode, FrameResult &frameResult) {} +}; +} // namespace Media +} // namespace OHOS +#endif // OHOS_FRAME_STATE_CALLBACK_H diff --git a/interfaces/kits/meta_data.h b/interfaces/kits/meta_data.h new file mode 100755 index 0000000..1bf350f --- /dev/null +++ b/interfaces/kits/meta_data.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2020-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_META_DATA_H +#define OHOS_META_DATA_H + +#include "stdint.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* End of #ifdef __cplusplus */ + +typedef struct { + int32_t x; + int32_t y; + int32_t w; + int32_t h; +} CameraRect; + +typedef struct { + uint32_t width; + uint32_t height; +} CameraPicSize; + +typedef enum { + /* Frame rate */ + CAM_FRAME_FPS = 0, + /* Auto exposure mode */ + CAM_AE_MODE, + /* Auto exposure time */ + CAM_AE_EXPO_TIME, + /* Auto exposure compensation value */ + CAM_AE_COMPENSATION, + /* Auto exposure lock */ + CAM_AE_LOCK, + /* Auto exposure region */ + CAM_AE_REGIONS, + /* White balance mode */ + CAM_AWB_MODE, + /* White balance lock */ + CAM_AWB_LOCK, + /* White balance region */ + CAM_AWB_REGION, + /* Video stabilization feature */ + CAM_VIDEO_STABILIZATION_NABLE, + /* Image luminance */ + CAM_IMAGE_LUMA, + /* Image contrast */ + CAM_IMAGE_CONTRAST, + /* Image hue */ + CAM_IMAGE_HUE, + /* Image saturation */ + CAM_IMAGE_SATURATION, + /* Hot pixel correction */ + CAM_HOT_PIXEL_ENABLE, + /* Level of hot pixel correction */ + CAM_HOT_PIXEL_LEVEL, + /* Image denoising mode */ + CAM_IMAGE_DENOISE_MODE, + /* Image denoising level */ + CAM_IMAGE_DENOISE_LEVEL, +} CameraFuncKey; + +/** + @brief Enumerates parameters for image rotation and mirroring. + */ +typedef enum { + CAM_CENTER_MIRROR = 0, /**< Central mirroring */ + CAM_HORIZONTAL_MIRROR = 1, /**< Horizontal mirroring */ + CAM_VETICALLY_MIRROR = 2, /**< Vertical mirroring */ + CAM_ROTATION_90 = 3, /**< 90-degree rotation */ + CAM_ROTATION_180 = 4, /**< 180-degree rotation */ +} CameraInvertMode; + +#define PARAM_KEY_SIZE 0 +#define PARAM_KEY_IMAGE_ENCODE_QFACTOR 1 + +#define ENCODER_TYPE 0 +typedef enum { CAM_ENCODE_JPEG, CAM_ENCODE_H264, CAM_ENCODE_H265, CAM_ENCODE_FORMAT_BUTT } CameraEncodeFormat; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* End of #ifdef __cplusplus */ +#endif // OHOS_META_DATA_H \ No newline at end of file diff --git a/readme.md b/readme.md deleted file mode 100755 index 4f96f73..0000000 --- a/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -详见:https://gitee.com/openharmony/docs/blob/master/readme/媒体子系统README.md - -see: https://gitee.com/openharmony/docs/blob/master/docs-en/readme/media-subsystem.md \ No newline at end of file