diff --git a/multimedia/video_processing_engine/image_processing.h b/multimedia/video_processing_engine/image_processing.h new file mode 100644 index 0000000000000000000000000000000000000000..81f503ecf3b6ed252ee9cb4e6335143853346532 --- /dev/null +++ b/multimedia/video_processing_engine/image_processing.h @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2024 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 ImageProcessing + * @{ + * + * @brief Provide APIs for image quality processing. + * + * @since 12 + */ + +/** + * @file image_processing.h + * + * @brief Declare image processing functions. + * + * Provides SDR content processing for images, including color space conversion, metadata generation + * and image scaling. + * + * @library libimage_processing.so + * @syscap SystemCapability.Multimedia.VideoProcessingEngine + * @kit ImageKit + * @since 12 + */ + +#ifndef VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_H +#define VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_H + +#include +#include +#include "image_processing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize global environment for image processing. + * + * This function is optional. \n + * Typically, this function is called once when the host process is started to initialize the global environment for + * image processing, which can reduce the time of {@link OH_ImageProcessing_Create}. \n + * To deinitialize global environment, call {@link OH_ImageProcessing_DeinitializeEnvironment}. + * + * @return {@link IMAGE_PROCESSING_SUCCESS} if initialization is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INITIALIZE_FAILED} if initialization is failed. \n + * You can check if the device GPU is working properly. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_InitializeEnvironment(void); + +/** + * @brief Deinitialize global environment for image processing. + * + * This function is required if {@link OH_ImageProcessing_InitializeEnvironment} is called. Typically, this + * function is called when the host process is about to exit to deinitialize the global environment, which is + * initialized by calling {@link OH_ImageProcessing_InitializeEnvironment}. \n + * If there is some image processing instance existing, this function should not be called. \n + * If the {@link OH_ImageProcessing_InitializeEnvironment} is not called, this function should not be called. + * + * @return {@link IMAGE_PROCESSING_SUCCESS} if deinitialization is successful. \n + * {@link IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if some image processing instance is not destroyed or + * {@link OH_ImageProcessing_InitializeEnvironment} is not called. \n + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_DeinitializeEnvironment(void); + +/** + * @brief Query whether the image color space conversion is supported. + * + * @param sourceImageInfo Input image color space information pointer. + * @param destinationImageInfo Output image color space information pointer. + * @return true if the color space conversion is supported. \n + * false if the the color space conversion is unsupported. + * @since 12 + */ +bool OH_ImageProcessing_IsColorSpaceConversionSupported( + const ImageProcessing_ColorSpaceInfo* sourceImageInfo, + const ImageProcessing_ColorSpaceInfo* destinationImageInfo); + +/** + * @brief Query whether the image composition is supported. + * + * @param sourceImageInfo Input image color space information pointer. + * @param sourceGainmapInfo Input gainmap color space information pointer. + * @param destinationImageInfo Output image color space information pointer. + * @return true if the image composition is supported. \n + * false if the image composition is unsupported. + * @since 12 + */ +bool OH_ImageProcessing_IsCompositionSupported( + const ImageProcessing_ColorSpaceInfo* sourceImageInfo, + const ImageProcessing_ColorSpaceInfo* sourceGainmapInfo, + const ImageProcessing_ColorSpaceInfo* destinationImageInfo); + +/** + * @brief Query whether the image decomposition is supported. + * + * @param sourceImageInfo Input image color space information pointer. + * @param destinationImageInfo Output image color space information pointer. + * @param destinationGainmapInfo Output gainmap information pointer. + * @return true if the image decomposition is supported. \n + * false if the image decomposition is unsupported. + * @since 12 + */ +bool OH_ImageProcessing_IsDecompositionSupported( + const ImageProcessing_ColorSpaceInfo* sourceImageInfo, + const ImageProcessing_ColorSpaceInfo* destinationImageInfo, + const ImageProcessing_ColorSpaceInfo* destinationGainmapInfo); + +/** + * @brief Query whether the image metadata generation is supported. + * + * @param sourceImageInfo Input image color space information pointer. + * @return true if the image metadata generation is supported.. \n + * false if the image metadata generation is unsupported. + * @since 12 + */ +bool OH_ImageProcessing_IsMetadataGenerationSupported( + const ImageProcessing_ColorSpaceInfo* sourceImageInfo); + +/** + * @brief Create an image processing instance. + * + * @param imageProcessor Output parameter. The *imageProcessor points to a new image processing object. + * The *imageProcessor must be null before passed in. + * @param type Use IMAGE_PROCESSING_TYPE_XXX to specify the processing type. The processing type of the instance can not + * be changed. + * @return {@link IMAGE_PROCESSING_SUCCESS} if creating an image processing successfully. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the type is not supported. For example, if metadata + * generation is not supported by vendor, it returns unsupported processing. \n + * {@link IMAGE_PROCESSING_ERROR_CREATE_FAILED} if failed to create an image processing. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or *instance is not null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if type is invalid. \n + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_Create(OH_ImageProcessing** imageProcessor, int32_t type); + +/** + * @brief Destroy the image processing instance. + * + * @param imageProcessor An image processing instance pointer. It is recommended setting the + * instance pointer to null after the instance is destroyed. + * @return {@link IMAGE_PROCESSING_SUCCESS} if the instance is destroyed successfully. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_Destroy(OH_ImageProcessing* imageProcessor); + +/** + * @brief Set parameter for image processing. + * + * Add parameter identified by the specified parameter key. + * + * @param imageProcessor An image processing instance pointer. + * @param parameter The parameter for image processing. + * @return {@link IMAGE_PROCESSING_SUCCESS} if setting parameter is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the parameter is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of the parameter is invalid. For example, the parameter + * contains unsupported parameter key or value. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_SetParameter(OH_ImageProcessing* imageProcessor, + const OH_AVFormat* parameter); + +/** + * @brief Get parameter of image processing. + * + * Get parameter identified by the specified parameter key. + * + * @param imageProcessor An image processing instance pointer. + * @param parameter The parameter used by the image processing instance. + * @return {@link IMAGE_PROCESSING_SUCCESS} if getting parameter is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the parameter is null. \n + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_GetParameter(OH_ImageProcessing* imageProcessor, + OH_AVFormat* parameter); + +/** + * @brief Conversion between single-layer images. + * + * The function generate the destinationImage from sourceImage. It include the colorspace conversion from + * HDR image to SDR image, SDR image to HDR image, SDR image to SDR image and HDR image to HDR image. + * + * @param imageProcessor An image processing instance pointer. The instance should be created with + * type {@link IMAGE_PROCESSING_TYPE_COLOR_SPACE_CONVERSION}. + * @param sourceImage Input image pointer. + * @param destinationImage Output image pointer. + * @return {@link IMAGE_PROCESSING_SUCCESS} if processing image is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the image is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of image is invalid. For example, the color space + * of the image is unsupported. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the processing is not supported. \n + * {@link IMAGE_PROCESSING_ERROR_PROCESS_FAILED} if processing error occurs. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_ConvertColorSpace(OH_ImageProcessing* imageProcessor, + OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage); + +/** + * @brief Composition from dual-layer HDR images to single-layer HDR images. + * + * The function generate the destinationImage from sourceImage and sourceGainmap. + * + * @param imageProcessor An image processing instance pointer. The instance should be created with + * type {@link IMAGE_PROCESSING_TYPE_COMPOSITION}. + * @param sourceImage Input image pointer. + * @param sourceGainmap Input gainmap pointer. + * @param destinationImage Output image pointer. + * @return {@link IMAGE_PROCESSING_SUCCESS} if processing image is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the image is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of image is invalid. For example, the color space + * of the image is unsupported. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the processing is not supported. \n + * {@link IMAGE_PROCESSING_ERROR_PROCESS_FAILED} if processing error occurs. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_Compose(OH_ImageProcessing* imageProcessor, + OH_PixelmapNative* sourceImage, OH_PixelmapNative* sourceGainmap, OH_PixelmapNative* destinationImage); + +/** + * @brief Decomposition from single-layer HDR images to dual-layer HDR images. + * + * The function generate the destinationImage and destinationGainmap from sourceImage. + * + * @param imageProcessor An image processing instance pointer. The instance should be created with + * type {@link IMAGE_PROCESSING_TYPE_DECOMPOSITION}. + * @param sourceImage Input image pointer. + * @param destinationImage Output image pointer. + * @param destinationGainmap Output gainmap pointer. + * @return {@link IMAGE_PROCESSING_SUCCESS} if processing image is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the image is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of image is invalid. For example, the color space + * of the image is unsupported. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the processing is not supported. \n + * {@link IMAGE_PROCESSING_ERROR_PROCESS_FAILED} if processing error occurs. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_Decompose(OH_ImageProcessing* imageProcessor, + OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage, OH_PixelmapNative* destinationGainmap); + +/** + * @brief Metadata Generation for HDR images. + * + * The function generate metadata for the sourceImage. + * + * @param imageProcessor An image processing instance pointer. The instance should be created with + * type {@link IMAGE_PROCESSING_TYPE_METADATA_GENERATION}. + * @param sourceImage Input image pointer. + * @return {@link IMAGE_PROCESSING_SUCCESS} if processing image is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the image is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of image is invalid. For example, the color space + * of the image is unsupported. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the processing is not supported. \n + * {@link IMAGE_PROCESSING_ERROR_PROCESS_FAILED} if processing error occurs. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_GenerateMetadata(OH_ImageProcessing* imageProcessor, + OH_PixelmapNative* sourceImage); + +/** + * @brief Clarity enhancement for images. + * + * The function generate the destinationImage from sourceImage with necessary scaling operation according to the size + * preset in the sourceImage and destinationImage. Different levels of scaling methonds are provided to balance + * performance and image quality. + * + * @param imageProcessor An image processing instance pointer. The instance should be created with + * type {@link IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER}. + * @param sourceImage Input image pointer. + * @param destinationImage Output image pointer. + * @return {@link IMAGE_PROCESSING_SUCCESS} if processing image is successful. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an image processing instance. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_PARAMETER} if the image is null. \n + * {@link IMAGE_PROCESSING_ERROR_INVALID_VALUE} if some property of image is invalid. For example, the color space + * of the image is unsupported. \n + * {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the processing is not supported. \n + * {@link IMAGE_PROCESSING_ERROR_PROCESS_FAILED} if processing error occurs. \n + * {@link IMAGE_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +ImageProcessing_ErrorCode OH_ImageProcessing_EnhanceDetail(OH_ImageProcessing* imageProcessor, + OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage); +#ifdef __cplusplus +} +#endif + +#endif // VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_H +/** @} */ diff --git a/multimedia/video_processing_engine/image_processing/BUILD.gn b/multimedia/video_processing_engine/image_processing/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d3c02809beebfde8424e31739f2463172e96f3d4 --- /dev/null +++ b/multimedia/video_processing_engine/image_processing/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 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") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("image_processing_ndk_headers") { + dest_dir = "$ndk_headers_out_dir/multimedia/video_processing_engine" + sources = [ + "../image_processing.h", + "../image_processing_types.h", + ] +} + +ohos_ndk_library("libimage_processing_ndk") { + ndk_description_file = "./libimage_processing.ndk.json" + output_name = "image_processing" + output_extension = "so" + min_compact_version = "12" + system_capability = "SystemCapability.Multimedia.VideoProcessingEngine" + system_capability_headers = [ + "multimedia/video_processing_engine/image_processing_types.h", + "multimedia/video_processing_engine/image_processing.h", + ] +} diff --git a/multimedia/video_processing_engine/image_processing/libimage_processing.ndk.json b/multimedia/video_processing_engine/image_processing/libimage_processing.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..8cb58693c7d4efcb153d0f9d74ed30f96a7911a2 --- /dev/null +++ b/multimedia/video_processing_engine/image_processing/libimage_processing.ndk.json @@ -0,0 +1,87 @@ +[ + { + "first_introduced": "12", + "name": "OH_ImageProcessing_InitializeEnvironment" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_DeinitializeEnvironment" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_IsColorSpaceConversionSupported" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_IsCompositionSupported" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_IsDecompositionSupported" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_IsMetadataGenerationSupported" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_Create" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_SetParameter" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_GetParameter" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_ConvertColorSpace" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_Compose" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_Decompose" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_GenerateMetadata" + }, + { + "first_introduced": "12", + "name": "OH_ImageProcessing_EnhanceDetail" + }, + { + "first_introduced": "12", + "name": "IMAGE_PROCESSING_TYPE_COLOR_SPACE_CONVERSION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "IMAGE_PROCESSING_TYPE_COMPOSITION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "IMAGE_PROCESSING_TYPE_DECOMPOSITION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "IMAGE_PROCESSING_TYPE_METADATA_GENERATION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER", + "type": "variable" + } +] diff --git a/multimedia/video_processing_engine/image_processing_types.h b/multimedia/video_processing_engine/image_processing_types.h new file mode 100644 index 0000000000000000000000000000000000000000..46f8d249cf840376fe90f825bab5fdcbe78c28c6 --- /dev/null +++ b/multimedia/video_processing_engine/image_processing_types.h @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2024 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 ImageProcessing + * @{ + * + * @brief Provide image processing including color space conversion and metadata generation. + * + * @since 12 + */ + +/** + * @file image_processing_types.h + * + * @brief Type definitions for image processing. + * + * @library libimage_processing.so + * @syscap SystemCapability.Multimedia.VideoProcessingEngine + * @kit ImageKit + * @since 12 + */ + +#ifndef VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_TYPES_H +#define VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_TYPES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the object for image processing. + * + * Define a null pointer of OH_ImageProcessing and call {@link OH_ImageProcessing_Create} to create an image processing + * instance. The pointer should be null before creating instance. + * User can create multiple image processing instances for different processing types. + * + * @since 12 + */ +typedef struct OH_ImageProcessing OH_ImageProcessing; + +/** + * @brief Forward declaration of OH_PixelmapNative. + * + * @since 12 + */ +typedef struct OH_PixelmapNative OH_PixelmapNative; + +/** + * @brief Forward declaration of OH_AVFormat. + * + * @since 12 + */ +typedef struct OH_AVFormat OH_AVFormat; + +/** + * @brief Used to create an image processing instance for color space conversion. + * + * Color space conversion includes the conversion of single-layer HDR images to SDR images, as well as + * the color space conversion of SDR images, and the conversion of SDR images to single-layer HDR images. Some + * capabilities are supported by vendor. Use {@link OH_ImageProcessing_IsColorSpaceConversionSupported} to query if + * the conversion is supported between single-layer images. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t IMAGE_PROCESSING_TYPE_COLOR_SPACE_CONVERSION; + +/** + * @brief Used to create an image processing instance for HDR image composition. + * + * HDR image compose includes the conversion from dual-layer HDR images to single-layer HDR images. Some + * capabilities are supported by vendor. Use {@link OH_ImageProcessing_IsCompositionSupported} to + * query if the composition is supported from dual-layer HDR image to single-layer HDR image. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t IMAGE_PROCESSING_TYPE_COMPOSITION; + +/** + * @brief Used to create an image processing instance for HDR image decomposition. + * + * HDR image decompose includes the conversion from single-layer HDR images to dual-layer HDR images. Some + * capabilities are supported by vendor. Use {@link OH_ImageProcessing_IsDecompositionSupported} to + * query if the decomposition is supported from single-layer image to dual-layer HDR image. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t IMAGE_PROCESSING_TYPE_DECOMPOSITION; + +/** + * @brief Used to create an image processing instance for metadata generation. + * + * Generate HDR Vivid metadata for single-layer image. The capability is supported by vendor. If the capability is not + * supported, {@link OH_ImageProcessing_Create} returns {@link IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING}. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t IMAGE_PROCESSING_TYPE_METADATA_GENERATION; + +/** + * @brief Used to create an image processing instance for detail enhancement. + * + * Scale or resize images with the specified quality or just enhance details for rendering an image without changing + * its resolution. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER; + +/** + * @brief The key is used to specify the quality level for image detail enhancement. + * + * See {@link ImageDetailEnhancer_QualityLevel} for its value. + * Use {@link OH_ImageProcessing_SetParameter} to set the quality level. + * Use {@link OH_ImageProcessing_GetParameter} to get the current quality level. + * + * @see OH_VideoProcessing_SetParameter + * @see OH_VideoProcessing_GetParameter + * @since 12 + */ +extern const char* IMAGE_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL; + +/** + * @brief The color space information is used for color space conversion capability query. + * + * @see OH_ImageProcessing_IsColorSpaceConversionSupported + * @see OH_ImageProcessing_IsCompositionSupported + * @see OH_ImageProcessing_IsDecompositionSupported + * @since 12 + */ +typedef struct ImageProcessing_ColorSpaceInfo { + /** define metadata type */ + int32_t metadataType; + /** define color space, {@link enum OH_NativeBuffer_ColorSpace} */ + int32_t colorSpace; + /** define pixel format, {@link enum OH_NativeBuffer_Format} */ + int32_t pixelFormat; +} ImageProcessing_ColorSpaceInfo; + +/** + * @brief The quality level is used for detail enhancement. + * + * It is the value of the key parameter {@link IMAGE_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL}. + * + * @see OH_ImageProcessing_SetParameter + * @see OH_ImageProcessing_GetParameter + * @since 12 + */ +typedef enum ImageDetailEnhancer_QualityLevel { + /** No detail enhancement */ + IMAGE_DETAIL_ENHANCER_QUALITY_LEVEL_NONE, + /** A low level of detail enhancement quality but with a fast speed. It's the default level */ + IMAGE_DETAIL_ENHANCER_QUALITY_LEVEL_LOW, + /** A medium level of detail enhancement quality. Its speed is between the low setting and high setting */ + IMAGE_DETAIL_ENHANCER_QUALITY_LEVEL_MEDIUM, + /** A high level of detail enhancement quality but with a relatively slow speed */ + IMAGE_DETAIL_ENHANCER_QUALITY_LEVEL_HIGH, +} ImageDetailEnhancer_QualityLevel; + +/** + * @brief Image processing error code. + * + * @since 12 + */ +typedef enum ImageProcessing_ErrorCode { + /** @error Operation is successful. */ + IMAGE_PROCESSING_SUCCESS, + /** @error Input parameter is invalid. This error is returned for all of the following error conditions: + * 1 - Invalid input or output image buffer - The image buffer is null. + * 2 - Invalid parameter - The parameter is null. + * 3 - Invalid type - The type passed in the create function does not exist. + */ + IMAGE_PROCESSING_ERROR_INVALID_PARAMETER = 401, + /** @error Some unknown error occurred, such as GPU calculation failure or memcpy failure. */ + IMAGE_PROCESSING_ERROR_UNKNOWN = 29200001, + /** @error The global environment initialization for image processing failed, such as failure to initialize + * the GPU environment. + */ + IMAGE_PROCESSING_ERROR_INITIALIZE_FAILED, + /** @error Failed to create image processing instance. For example, + * the number of instances exceeds the upper limit. + */ + IMAGE_PROCESSING_ERROR_CREATE_FAILED, + /** @error Failed to process image buffer. For example, the processing times out. */ + IMAGE_PROCESSING_ERROR_PROCESS_FAILED, + /** @error The processing is not supported. You may call OH_ImageProcessing_IsXXXSupported + * to check whether the capability is supported. + */ + IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING, + /** @error The operation is not permitted. This may be caused by incorrect status. */ + IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED, + /** @error Out of memory. */ + IMAGE_PROCESSING_ERROR_NO_MEMORY, + /** @error The image processing instance is invalid. This may be caused by null instance. */ + IMAGE_PROCESSING_ERROR_INVALID_INSTANCE, + /** @error Input parameter is invalid. This error is returned for all of the following error conditions: + * 1 - Invalid input or output image buffer - The image buffer width(height) + * is too large or colorspace is incorrect. + * 2 - Invalid parameter - The parameter does not contain valid information, + * such as detail enhancer level is incorrect. + */ + IMAGE_PROCESSING_ERROR_INVALID_VALUE +} ImageProcessing_ErrorCode; + +#ifdef __cplusplus +} +#endif + +#endif // VIDEO_PROCESSING_ENGINE_C_API_IMAGE_PROCESSING_TYPES_H +/** @} */ diff --git a/multimedia/video_processing_engine/video_processing.h b/multimedia/video_processing_engine/video_processing.h new file mode 100644 index 0000000000000000000000000000000000000000..7c22782c6d01d5773649fc92243826d753ad495c --- /dev/null +++ b/multimedia/video_processing_engine/video_processing.h @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2024 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 VideoProcessing + * @{ + * + * @brief Provide APIs for video quality processing. + * + * @since 12 + */ + +/** + * @file video_processing.h + * + * @brief Declare video processing functions. + * + * Provides SDR content processing for videos, including color space conversion, metadata generation + * and video scaling. + * + * @library libvideo_processing.so + * @syscap SystemCapability.Multimedia.VideoProcessingEngine + * @kit MediaKit + * @since 12 + */ + +#ifndef VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_H +#define VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_H + +#include +#include +#include "video_processing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize global environment for video processing. + * + * This function is optional. \n + * Typically, this function is called once when the host process is started to initialize the global environment for + * video processing, which can reduce the time of {@link OH_VideoProcessing_Create}. \n + * To deinitialize global environment, call {@link OH_VideoProcessing_DeinitializeEnvironment}. + * + * @return {@link VIDEO_PROCESSING_SUCCESS} if initialization is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED} if initialization is failed. \n + * You can check if the device GPU is working properly. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_InitializeEnvironment(void); + +/** + * @brief Deinitialize global environment for video processing. + * + * This function is required if {@link OH_VideoProcessing_InitializeEnvironment} is called. Typically, this + * function is called when the host process is about to exit to deinitialize the global environment, which is + * initialized by calling {@link OH_VideoProcessing_InitializeEnvironment}. \n + * If there is some video processing instance existing, this function should not be called. \n + * If the {@link OH_VideoProcessing_InitializeEnvironment} is not called, this function should not be called. + * + * @return {@link VIDEO_PROCESSING_SUCCESS} if deinitialization is successful. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if some video processing instance is not destroyed or + * {@link OH_VideoProcessing_InitializeEnvironment} is not called. \n + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_DeinitializeEnvironment(void); + +/** + * @brief Query if the video color space conversion is supported. + * + * @param sourceVideoInfo Source video color space information. + * @param destinationVideoInfo Destination video color space information. + * @return true if the video color space conversion is supported. \n + * false if the video color space conversion is not supported. + * @since 12 + */ +bool OH_VideoProcessing_IsColorSpaceConversionSupported( + const VideoProcessing_ColorSpaceInfo* sourceVideoInfo, + const VideoProcessing_ColorSpaceInfo* destinationVideoInfo); + +/** + * @brief Query if the video metadata generation is supported. + * + * @param sourceVideoInfo Source video color space information. + * @return true if the video metadata generation is supported. \n + * false if the video metadata generation is not supported. + * @since 12 + */ +bool OH_VideoProcessing_IsMetadataGenerationSupported( + const VideoProcessing_ColorSpaceInfo* sourceVideoInfo); + +/** + * @brief Create a video processing instance. + * + * @param videoProcessor Output parameter. The *videoProcessor points to a new video processing object. + * The *videoProcessor must be null before passed in. + * @param type Use VIDEO_PROCESSING_TYPE_XXX to specify the processing type. The processing type of the instance can not + * be changed. + * @return {@link VIDEO_PROCESSING_SUCCESS} if creating a video processing instance successfully. \n + * {@link VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING} if the type is not supported. For example, if metadata + * generation is not supported by vendor, it returns unsupported processing. \n + * {@link VIDEO_PROCESSING_ERROR_CREATE_FAILED} if failed to create a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or *instance is not null. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if type is invalid. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_Create(OH_VideoProcessing** videoProcessor, int type); + +/** + * @brief Destroy the video processing instance. + * + * Stop the instance before destroying it. see {@link OH_VideoProcessing_Stop}. \n + * + * @param videoProcessor The video processing instance pointer to be destroyed. It is recommended setting the + * instance pointer to null after the instance is destroyed. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the instance is destroyed successfully . \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if the instance is still running. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_Destroy(OH_VideoProcessing* videoProcessor); + +/** + * @brief Register callback object. + * + * Register the callback object before starting video processing. + * + * @param videoProcessor A video processing instance pointer. + * @param callback Callback pointer to be registered. + * @param userData User's custom data pointer. + * @return {@link VIDEO_PROCESSING_SUCCESS} if callback is registered successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if callback is null. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if video processing instance is running. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_RegisterCallback(OH_VideoProcessing* videoProcessor, + const VideoProcessing_Callback* callback, void* userData); + +/** + * @brief Set the output surface for video processing. + * + * Set the output surface before starting video processing. + * + * @param videoProcessor A video processing instance pointer. + * @param window The output surface pointer. + * @return {@link VIDEO_PROCESSING_SUCCESS} if setting output surface successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if window is null. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_SetSurface(OH_VideoProcessing* videoProcessor, + const OHNativeWindow* window); + +/** + * @brief Create an input surface. + * + * Create the input surface before starting video processing. + * Call {@link OH_NativeWindow_DestroyNativeWindow} to destroy the input surface. + * + * @param videoProcessor A video processing instance pointer. + * @param window The input surface pointer. For example, it is the output surface of a video decoder. + * @return {@link VIDEO_PROCESSING_SUCCESS} if operation is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if window is null or *window is not null. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if creating surface failed, input surface is already created + * or video processing instance is running. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_GetSurface(OH_VideoProcessing* videoProcessor, OHNativeWindow** window); + +/** + * @brief Set parameter for video processing. + * + * Add parameter identified by the specified parameter key. + * + * @param videoProcessor An video processing instance pointer. + * @param parameter The parameter for video processing. + * @return {@link VIDEO_PROCESSING_SUCCESS} if setting parameter is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if the parameter is null. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_VALUE} if some property of the parameter is invalid. For example, the parameter + * contains unsupported parameter key or value. \n + * {@link VIDEO_PROCESSING_ERROR_NO_MEMORY} if memory allocation failed. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_SetParameter(OH_VideoProcessing* videoProcessor, + const OH_AVFormat* parameter); + +/** + * @brief Get parameter of video processing. + * + * Get parameter identified by the specified parameter key. + * + * @param videoProcessor An video processing instance pointer. + * @param parameter The parameter used by the video processing instance. + * @return {@link VIDEO_PROCESSING_SUCCESS} if getting parameter is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not an video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if the parameter is null. \n + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_GetParameter(OH_VideoProcessing* videoProcessor, OH_AVFormat* parameter); + +/** + * @brief Start video processing instance. + * + * After successfully calling this function, the state {@link VIDEO_PROCESSING_STATE_RUNNING} is reported by callback + * function {@link OH_VideoProcessingCallback_OnState}. + * + * @param videoProcessor A video processing instance pointer. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the operation is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if output surface is not set, input surface is not created or + * instance is already running. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_Start(OH_VideoProcessing* videoProcessor); + +/** + * @brief To stop video processing instance. + * + * After the video processing instance is stopped successfully, the state {@link VIDEO_PROCESSING_STATE_STOPPED} is + * reported by callback function {@link OH_VideoProcessing_OnState}. + * + * @param videoProcessor A video processing instance pointer. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the operation is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if instance is already stopped. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_Stop(OH_VideoProcessing* videoProcessor); + +/** + * @brief Send the output buffer out. + * + * If the callback function {@link OH_VideoProcessingCallback_OnNewOutputBuffer} is set, the buffer's index is reported + * to user by the callback function when an output buffer is ready. + * + * @param videoProcessor A video processing instance pointer. + * @param index The output buffer's index. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the operation is successful. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_INSTANCE} if instance is null or not a video processing instance. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if index is invalid. \n + * {@link VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED} if callback {@link OH_VideoProcessing_OnNewOutputBuffer} is + * not set or instance is stopped. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessing_RenderOutputBuffer(OH_VideoProcessing* videoProcessor, uint32_t index); + +/** + * @brief Create a video processing callback object. + * + * @param callback Output parameter. The *callback points to a new callback object. The *callback should be null before + * creating the callback object. + * @return {@link VIDEO_PROCESSING_SUCCESS} if callback object is created successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if callback is null or *callback is not null. \n + * {@link VIDEO_PROCESSING_ERROR_NO_MEMORY} if out of memory. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessingCallback_Create(VideoProcessing_Callback** callback); + +/** + * @brief Destroy the callback object. + * + * The callback object can be destroyed after it is registered to video processing instance. + * + * @param callback The callback object pointer. It is recommended setting the callback pointer to null after the + * callback object is destroyed. + * @return {@link VIDEO_PROCESSING_SUCCESS} if callback is successfully destroyed. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if callback is null. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessingCallback_Destroy(VideoProcessing_Callback* callback); + +/** + * @brief Bind the {@link OH_VideoProcessingCallback_OnError} callback function to callback object. + * + * @param callback A callback object pointer. + * @param onError The callback function. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the function is bound to callback object successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if the callback is null or onError is null. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnError(VideoProcessing_Callback* callback, + OH_VideoProcessingCallback_OnError onError); + +/** + * @brief Bind the {@link OH_VideoProcessingCallback_OnState} callback function to callback object. + * + * @param callback A callback object pointer. + * @param onState The callback function. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the function is bound to callback object successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if the callback is null or onState is null. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnState(VideoProcessing_Callback* callback, + OH_VideoProcessingCallback_OnState onState); + +/** + * @brief Bind the {@link OH_VideoProcessingCallback_OnNewOutputBuffer} callback function to callback object. + * + * @param callback A callback object pointer. + * @param onNewOutputBuffer The callback function. + * @return {@link VIDEO_PROCESSING_SUCCESS} if the function is bound to callback object successfully. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_PARAMETER} if the callback is null. + * @since 12 + */ +VideoProcessing_ErrorCode OH_VideoProcessingCallback_BindOnNewOutputBuffer(VideoProcessing_Callback* callback, + OH_VideoProcessingCallback_OnNewOutputBuffer onNewOutputBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_H +/** @} */ diff --git a/multimedia/video_processing_engine/video_processing/BUILD.gn b/multimedia/video_processing_engine/video_processing/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0dc56d02583cefe8084b36cea30c3d8ef7455f0a --- /dev/null +++ b/multimedia/video_processing_engine/video_processing/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 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") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("video_processing_ndk_headers") { + dest_dir = "$ndk_headers_out_dir/multimedia/video_processing_engine" + sources = [ + "../video_processing.h", + "../video_processing_types.h", + ] +} + +ohos_ndk_library("libvideo_processing_ndk") { + ndk_description_file = "./libvideo_processing.ndk.json" + output_name = "video_processing" + output_extension = "so" + min_compact_version = "12" + system_capability = "SystemCapability.Multimedia.VideoProcessingEngine" + system_capability_headers = [ + "multimedia/video_processing_engine/video_processing_types.h", + "multimedia/video_processing_engine/video_processing.h", + ] +} diff --git a/multimedia/video_processing_engine/video_processing/libvideo_processing.ndk.json b/multimedia/video_processing_engine/video_processing/libvideo_processing.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..dd2fe35ab8f4213a5d7bb16038f621ffa9c8f74c --- /dev/null +++ b/multimedia/video_processing_engine/video_processing/libvideo_processing.ndk.json @@ -0,0 +1,93 @@ +[ + { + "first_introduced": "12", + "name": "OH_VideoProcessing_InitializeEnvironment" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_DeinitializeEnvironment" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_IsColorSpaceConversionSupported" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_IsMetadataGenerationSupported" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_Create" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_RegisterCallback" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_SetSurface" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_GetSurface" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_SetParameter" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_GetParameter" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_Start" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_Stop" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessing_RenderOutputBuffer" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessingCallback_Create" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessingCallback_Destroy" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessingCallback_BindOnError" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessingCallback_BindOnState" + }, + { + "first_introduced": "12", + "name": "OH_VideoProcessingCallback_BindOnNewOutputBuffer" + }, + { + "first_introduced": "12", + "name": "VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "VIDEO_PROCESSING_TYPE_METADATA_GENERATION", + "type": "variable" + }, + { + "first_introduced": "12", + "name": "VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER", + "type": "variable" + } +] diff --git a/multimedia/video_processing_engine/video_processing_types.h b/multimedia/video_processing_engine/video_processing_types.h new file mode 100644 index 0000000000000000000000000000000000000000..51611e9ac1b501b9814cc2a06042f0c81642d7df --- /dev/null +++ b/multimedia/video_processing_engine/video_processing_types.h @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2024 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 VideoProcessing + * @{ + * + * @brief Provide video processing including color space conversion and metadata generation. + * + * @since 12 + */ + +/** + * @file video_processing_types.h + * + * @brief Type definitions for video processing. + * + * @library libvideo_processing.so + * @syscap SystemCapability.Multimedia.VideoProcessingEngine + * @kit MediaKit + * @since 12 + */ + +#ifndef VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_TYPES_H +#define VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_TYPES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the video processing object. + * + * Define a null pointer of OH_VideoProcessing and call {@link OH_VideoProcessing_Create} to create a video processing + * instance. The pointer should be null before creating instance. + * User can create multiple video processing instances for different processing types. + * + * @since 12 + */ +typedef struct OH_VideoProcessing OH_VideoProcessing; + +/** + * @brief Forward declaration of NativeWindow. + * + * @since 12 + */ +typedef struct NativeWindow OHNativeWindow; + +/** + * @brief Forward declaration of OH_AVFormat. + * + * @since 12 + */ +typedef struct OH_AVFormat OH_AVFormat; + +/** + * @brief Used to create a video processing instance for color space conversion. + * + * Some capabilities are supported by vendor. Use {@link OH_VideoProcessing_IsColorSpaceConversionSupported} to query if + * the conversion is supported. + * + * @see OH_VideoProcessing_Create + * @since 12 + */ +extern const int32_t VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION; + +/** + * @brief Used to create a video processing instance for metadata generation. + * + * Generate HDR vivid metadata for video. The capability is supported by vendor. If the capability is not supported, + * {@link OH_VideoProcessing_Create} returns {@link VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING}. + * + * @see OH_VideoProcessing_Create + * @since 12 + */ +extern const int32_t VIDEO_PROCESSING_TYPE_METADATA_GENERATION; + +/** + * @brief Used to create an video processing instance of detail enhancement. + * + * Scale or resize video with the specified quality or just enhance details for rendering without changing its + * resolution. + * + * @see OH_ImageProcessing_Create + * @since 12 + */ +extern const int32_t VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER; + +/** + * @brief The key is used to specify the quality level for video detail enhancement. + * + * See {@link VideoDetailEnhancer_QualityLevel} for its values. + * Use {@link OH_VideoProcessing_SetParameter} to set the quality level. + * Use {@link OH_VideoProcessing_GetParameter} to get the current quality level. + * + * @see OH_VideoProcessing_SetParameter + * @see OH_VideoProcessing_GetParameter + * @since 12 + */ +extern const char* VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL; + +/** + * @brief Video color space information structure of querying if video color space conversion is supported. + * + * @see OH_VideoProcessing_IsColorSpaceConversionSupported + * @since 12 + */ +typedef struct VideoProcessing_ColorSpaceInfo { + /** The metadata type of the video, see {@link enum OH_NativeBuffer_MetadataType} */ + int32_t metadataType; + /** The color space type of the video, see {@link enum OH_NativeBuffer_ColorSpace} */ + int32_t colorSpace; + /** The pixel format of the video, see {@link enum OH_NativeBuffer_Format} */ + int32_t pixelFormat; +} VideoProcessing_ColorSpaceInfo; + +/** + * @brief The quality level is used for detail enhancement. + * + * It is the value of the key parameter {@link VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL}. + * + * @see OH_VideoProcessing_SetParameter + * @see OH_VideoProcessing_GetParameter + * @since 12 + */ +typedef enum VideoDetailEnhancer_QualityLevel { + /** No detail enhancement */ + VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_NONE, + /** A low level of detail enhancement quality but with a fast speed. It's the default level */ + VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_LOW, + /** A medium level of detail enhancement quality. Its speed is between the low setting and high setting */ + VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_MEDIUM, + /** A high level of detail enhancement quality but with a relatively slow speed */ + VIDEO_DETAIL_ENHANCER_QUALITY_LEVEL_HIGH, +} VideoDetailEnhancer_QualityLevel; + +/** + * @brief Video processing error code. + * + * @since 12 + */ +typedef enum VideoProcessing_ErrorCode { + /** @error Operation is successful. */ + VIDEO_PROCESSING_SUCCESS, + /** @error Input parameter is invalid. This error is returned for all of the following error conditions: + * 1 - Invalid input or output video buffer - The video buffer is null. + * 2 - Invalid parameter - The parameter is null. + * 3 - Invalid type - The type passed in the create function does not exist. + */ + VIDEO_PROCESSING_ERROR_INVALID_PARAMETER = 401, + /** @error Some unknown error occurred, such as GPU calculation failure or memcpy failure. */ + VIDEO_PROCESSING_ERROR_UNKNOWN = 29210001, + /** @error The global environment initialization for video processing failed, such as failure to initialize + * the GPU environment. + */ + VIDEO_PROCESSING_ERROR_INITIALIZE_FAILED, + /** @error Failed to create video processing instance. For example, + * the number of instances exceeds the upper limit. + */ + VIDEO_PROCESSING_ERROR_CREATE_FAILED, + /** @error Failed to process video buffer. For example, the processing times out. */ + VIDEO_PROCESSING_ERROR_PROCESS_FAILED, + /** @error The processing is not supported. You may call OH_VideoProcessing_IsXXXSupported + * to check whether the capability is supported. + */ + VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING, + /** @error The operation is not permitted. This may be caused by incorrect status. */ + VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED, + /** @error Out of memory. */ + VIDEO_PROCESSING_ERROR_NO_MEMORY, + /** @error The video processing instance is invalid. This may be caused by null instance. */ + VIDEO_PROCESSING_ERROR_INVALID_INSTANCE, + /** @error Input parameter is invalid. This error is returned for all of the following error conditions: + * 1 - Invalid input or output video buffer - The video buffer width(height) + * is too large or colorspace is incorrect. + * 2 - Invalid parameter - The parameter does not contain valid information, + * such as detail enhancer level is incorrect. + */ + VIDEO_PROCESSING_ERROR_INVALID_VALUE +} VideoProcessing_ErrorCode; + +/** + * @brief Video processing states. + * + * The state is reported to user by callback function {@link OH_VideoProcessing_OnState}. + * + * @since 12 + */ +typedef enum VideoProcessing_State { + /** Video processing is running */ + VIDEO_PROCESSING_STATE_RUNNING, + /** Video processing is stopped */ + VIDEO_PROCESSING_STATE_STOPPED +} VideoProcessing_State; + +/** + * @brief Video processing asynchronous callback object type. + * + * Define a null pointer of VideoProcessing_Callback and call {@link OH_VideoProcessingCallback_Create} to create a + * callback object. The pointer should be null before creating the callback object. + * Register the callback to a video processing instance by calling {@link OH_VideoProcessing_RegisterCallback}. + * + * @since 12 + */ +typedef struct VideoProcessing_Callback VideoProcessing_Callback; + +/** + * @brief The callback function pointer definition for reporting error during video processing. + * + * Errors: \n + * {@link VIDEO_PROCESSING_ERROR_UNSUPPORTED_PROCESSING}, the processing is not supported. For example, the + * color space conversion according to the source and destination videos' properties is not supported. \n + * {@link VIDEO_PROCESSING_ERROR_INVALID_VALUE}, some property of the video is invalid. For example, the color space of + * the video is invalid. \n + * {@link VIDEO_PROCESSING_ERROR_NO_MEMORY}, out of memory. \n + * {@link VIDEO_PROCESSING_ERROR_PROCESS_FAILED}, some processing error occurs. \n + * For more errors, see {@link VideoProcessing_ErrorCode}. + * + * @param videoProcessor The video processing instance. + * @param error Error code reporting to user. + * @param userData User's custom data. + * @since 12 + */ +typedef void (*OH_VideoProcessingCallback_OnError)(OH_VideoProcessing* videoProcessor, + VideoProcessing_ErrorCode error, void* userData); + +/** + * @brief The callback function pointer definition for reporting video processing state. + * + * The state will be {@link VIDEO_PROCESSING_STATE_RUNNING} after {@link OH_VideoProcessing_Start} is called + * successfully. + * The state will be {@link VIDEO_PROCESSING_STATE_STOPPED} after all the buffers cached before + * {@link OH_VideoProcessing_Stop} is called are processed. + * + * @param videoProcessor The video processing instance. + * @param state see {@link VideoProcessing_State}. + * @param userData User's custom data. + * @since 12 + */ +typedef void (*OH_VideoProcessingCallback_OnState)(OH_VideoProcessing* videoProcessor, VideoProcessing_State state, + void* userData); + +/** + * @brief The callback function pointer definition for reporting a new output buffer is filled with processed data. + * + * Every new output buffer's index will report to user once the buffer is filled with processed data. Then call + * {@link OH_VideoProcessing_RenderOutputBuffer} with the buffer's index to send the output buffer out. + * If this function is not registered, the output buffer is sent out as soon as the buffer is filled with processed + * data without reporting. + * + * @param videoProcessor The video processing instance. + * @param index The index of the new output buffer. + * @param userData The user's custom data. + * @since 12 + */ +typedef void (*OH_VideoProcessingCallback_OnNewOutputBuffer)(OH_VideoProcessing* videoProcessor, uint32_t index, + void* userData); + +#ifdef __cplusplus +} +#endif + +#endif // VIDEO_PROCESSING_ENGINE_C_API_VIDEO_PROCESSING_TYPES_H +/** @} */