mirror of
https://github.com/openharmony/multimedia_video_processing_engine.git
synced 2026-07-18 17:14:29 -04:00
@@ -20,6 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "frame_info.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -27,7 +28,7 @@ namespace VideoProcessingEngine {
|
||||
struct AihdrEnhancerCapability {
|
||||
ColorSpaceDescription colorspaceDesc;
|
||||
std::vector<GraphicPixelFormat> pixelFormats;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include "frame_info.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -50,7 +51,7 @@ struct ColorSpaceConverterCapability {
|
||||
}
|
||||
*/
|
||||
std::map<GraphicPixelFormat, std::vector<GraphicPixelFormat>> pixelFormatMap;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include "algorithm_common.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -27,7 +28,7 @@ namespace VideoProcessingEngine {
|
||||
struct ColorSpaceConverterDisplayCapability {
|
||||
ColorSpaceDescription inputColorspaceDesc;
|
||||
ColorSpaceDescription outputColorSpaceDesc;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "algorithm_common.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace VideoProcessingEngine {
|
||||
struct ContrastEnhancerCapability {
|
||||
std::vector<uint32_t> levels;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "algorithm_common.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace VideoProcessingEngine {
|
||||
struct DetailEnhancerCapability {
|
||||
std::vector<uint32_t> levels;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <unordered_map>
|
||||
#include "static_extension_list.h"
|
||||
#include "vpe_log.h"
|
||||
#include "extension_base.h"
|
||||
namespace {
|
||||
using LibFunctionGetRegisters = std::unordered_map<std::string,
|
||||
OHOS::Media::VideoProcessingEngine::Extension::RegisterExtensionFunc>* (*)();
|
||||
@@ -215,9 +216,9 @@ std::shared_ptr<DetailEnhancerBase> ExtensionManager::CreateDetailEnhancer(uint3
|
||||
ExtensionList ExtensionManager::LoadExtensions() const
|
||||
{
|
||||
ExtensionList extensionList {};
|
||||
LoadDynamicExtensions(extensionList);
|
||||
VPEAlgoErrCode ret = LoadStaticExtensions(extensionList);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == VPE_ALGO_ERR_OK, {}, "Load extension failed");
|
||||
LoadDynamicExtensions(extensionList);
|
||||
return extensionList;
|
||||
}
|
||||
|
||||
@@ -526,6 +527,12 @@ std::shared_ptr<ColorSpaceConverterExtension> ExtensionManager::FindColorSpaceCo
|
||||
return nullptr;
|
||||
}
|
||||
size_t idx = std::get<2>(*(iter->second.cbegin()));
|
||||
for (const auto &cap : iter->second) {
|
||||
if (std::get<0>(cap) == Rank::RANK_HIGH) {
|
||||
idx = std::get<2>(cap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::static_pointer_cast<ColorSpaceConverterExtension>(extensionList[idx]);
|
||||
}
|
||||
|
||||
@@ -557,6 +564,12 @@ std::shared_ptr<MetadataGeneratorExtension> ExtensionManager::FindMetadataGenera
|
||||
CHECK_AND_RETURN_RET_LOG(iter != metadataGeneratorCapabilityMap.cend() && !iter->second.empty(), nullptr,
|
||||
"CSC metadata generator extension is not found");
|
||||
size_t idx = std::get<2>(*(iter->second.cbegin()));
|
||||
for (const auto &cap : iter->second) {
|
||||
if (std::get<0>(cap) == Rank::RANK_HIGH) {
|
||||
idx = std::get<2>(cap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::static_pointer_cast<MetadataGeneratorExtension>(extensionList[idx]);
|
||||
}
|
||||
|
||||
@@ -596,6 +609,12 @@ std::shared_ptr<AihdrEnhancerExtension> ExtensionManager::FindAihdrEnhancerExten
|
||||
CHECK_AND_RETURN_RET_LOG(iter != aihdrEnhancerCapabilityMap.cend() && !iter->second.empty(), nullptr,
|
||||
"Aihdr enhancer extension is not found");
|
||||
size_t idx = std::get<2>(*(iter->second.cbegin()));
|
||||
for (const auto &cap : iter->second) {
|
||||
if (std::get<0>(cap) == Rank::RANK_HIGH) {
|
||||
idx = std::get<2>(cap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::static_pointer_cast<AihdrEnhancerExtension>(extensionList[idx]);
|
||||
}
|
||||
|
||||
@@ -604,7 +623,7 @@ VPEAlgoErrCode ExtensionManager::ExtractColorSpaceConverterCap(const ColorSpaceC
|
||||
{
|
||||
auto inputColorSpaceDesc = cap.inputColorSpaceDesc;
|
||||
auto outputColorSpaceDesc = cap.outputColorSpaceDesc;
|
||||
uint32_t rank = cap.rank;
|
||||
Rank rank = cap.rank;
|
||||
int32_t version = cap.version;
|
||||
for (const auto &[inputPixelFormat, outputPixelFormats] : cap.pixelFormatMap) {
|
||||
for (const auto &outputPixelFormat : outputPixelFormats) {
|
||||
@@ -631,7 +650,7 @@ VPEAlgoErrCode ExtensionManager::ExtractMetadataGeneratorCap(const MetadataGener
|
||||
MetadataGeneratorAlgoType algoType, MetadataGeneratorCapabilityMap& metadataGeneratorCapabilityMap) const
|
||||
{
|
||||
auto colorSpaceDesc = cap.colorspaceDesc;
|
||||
uint32_t rank = cap.rank;
|
||||
Rank rank = cap.rank;
|
||||
int32_t version = cap.version;
|
||||
for (const auto &pixelFormat : cap.pixelFormats) {
|
||||
auto key = std::make_tuple(colorSpaceDesc, pixelFormat, algoType);
|
||||
@@ -664,7 +683,14 @@ VPEAlgoErrCode ExtensionManager::BuildDetailEnhancerCaps(const std::shared_ptr<E
|
||||
auto realExtension = std::static_pointer_cast<DetailEnhancerExtension>(ext);
|
||||
auto capabilities = realExtension->capabilitiesBuilder();
|
||||
for (const auto &level : capabilities.levels) {
|
||||
detailEnhancerCapabilityMap.emplace(level, idx);
|
||||
auto itr = detailEnhancerCapabilityMap.find(level);
|
||||
if (itr == detailEnhancerCapabilityMap.end()) {
|
||||
detailEnhancerCapabilityMap.emplace(level, idx);
|
||||
} else {
|
||||
if (capabilities.rank == Rank::RANK_HIGH) {
|
||||
itr->second = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
@@ -673,7 +699,7 @@ VPEAlgoErrCode ExtensionManager::ExtractAihdrEnhancerCap(const AihdrEnhancerCapa
|
||||
AihdrEnhancerCapabilityMap& aihdrEnhancerCapabilityMap) const
|
||||
{
|
||||
auto colorSpaceDesc = cap.colorspaceDesc;
|
||||
uint32_t rank = cap.rank;
|
||||
Rank rank = cap.rank;
|
||||
int32_t version = cap.version;
|
||||
for (const auto &pixelFormat : cap.pixelFormats) {
|
||||
auto key = std::make_tuple(colorSpaceDesc, pixelFormat);
|
||||
|
||||
@@ -31,6 +31,11 @@ enum class ExtensionType {
|
||||
AIHDR_ENHANCER
|
||||
};
|
||||
|
||||
enum class Rank : uint32_t {
|
||||
RANK_DEFAULT = 0,
|
||||
RANK_HIGH,
|
||||
};
|
||||
|
||||
struct ExtensionInfo {
|
||||
ExtensionType type {ExtensionType::COLORSPACE_CONVERTER};
|
||||
std::string name;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace {
|
||||
using ColorSpaceConverterCapabilityMap =
|
||||
std::map<
|
||||
std::tuple<ColorSpaceDescription, GraphicPixelFormat, ColorSpaceDescription, GraphicPixelFormat>,
|
||||
std::vector<std::tuple<uint32_t, int32_t, size_t>>>;
|
||||
std::vector<std::tuple<Rank, int32_t, size_t>>>;
|
||||
using ColorSpaceConverterDisplayCapabilityMap = ColorSpaceConverterCapabilityMap;
|
||||
/*
|
||||
{
|
||||
@@ -76,12 +76,12 @@ using ColorSpaceConverterDisplayCapabilityMap = ColorSpaceConverterCapabilityMap
|
||||
using MetadataGeneratorCapabilityMap =
|
||||
std::map<
|
||||
std::tuple<ColorSpaceDescription, GraphicPixelFormat, MetadataGeneratorAlgoType>,
|
||||
std::vector<std::tuple<uint32_t, int32_t, size_t>>>;
|
||||
std::vector<std::tuple<Rank, int32_t, size_t>>>;
|
||||
using DetailEnhancerCapabilityMap = std::map<uint32_t, size_t>;
|
||||
using AihdrEnhancerCapabilityMap =
|
||||
std::map<
|
||||
std::tuple<ColorSpaceDescription, GraphicPixelFormat>,
|
||||
std::vector<std::tuple<uint32_t, int32_t, size_t>>>;
|
||||
std::vector<std::tuple<Rank, int32_t, size_t>>>;
|
||||
|
||||
using ColorSpaceConverterDisplaySet = std::set<std::shared_ptr<ColorSpaceConverterDisplayBase>>;
|
||||
using ColorSpaceConverterDisplayExtensionSet = std::set<std::shared_ptr<ColorSpaceConverterDisplayExtension>>;
|
||||
|
||||
@@ -14,9 +14,12 @@
|
||||
#ifndef VPE_FRAMEWORK_ALGORITHM_EXTENSION_MANAGER_STATIC_EXTENSION_LIST_H
|
||||
#define VPE_FRAMEWORK_ALGORITHM_EXTENSION_MANAGER_STATIC_EXTENSION_LIST_H
|
||||
|
||||
#include "skia_impl.h"
|
||||
|
||||
namespace OHOS::Media::VideoProcessingEngine::Extension {
|
||||
using RegisterExtensionFunc = void (*)(uintptr_t extensionListAddr);
|
||||
const std::unordered_map<std::string, RegisterExtensionFunc> staticExtensionsRegisterMap = {
|
||||
{ "Skia", RegisterSkiaExtensions },
|
||||
};
|
||||
} // namespace OHOS::Media::VideoProcessingEngine::Extension
|
||||
|
||||
|
||||
@@ -19,23 +19,31 @@
|
||||
#include "surface_buffer.h"
|
||||
#include "include/core/SkYUVAPixmaps.h"
|
||||
|
||||
#include "algorithm_types.h"
|
||||
#include "algorithm_errors.h"
|
||||
#include "detail_enhancer_base.h"
|
||||
#include "detail_enhancer_capability.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace VideoProcessingEngine {
|
||||
class Skia {
|
||||
class Skia : public DetailEnhancerBase {
|
||||
public:
|
||||
static AlgoErrorCode Process(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output);
|
||||
|
||||
private:
|
||||
Skia() = default;
|
||||
virtual ~Skia() = default;
|
||||
Skia(const Skia&) = delete;
|
||||
Skia& operator=(const Skia&) = delete;
|
||||
Skia(Skia&&) = delete;
|
||||
Skia& operator=(Skia&&) = delete;
|
||||
|
||||
static std::unique_ptr<DetailEnhancerBase> Create();
|
||||
static DetailEnhancerCapability BuildCapabilities();
|
||||
VPEAlgoErrCode Init() override;
|
||||
VPEAlgoErrCode Deinit() override;
|
||||
VPEAlgoErrCode SetParameter(const DetailEnhancerParameters& parameter, int type, bool flag) override;
|
||||
VPEAlgoErrCode Process(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output) override;
|
||||
};
|
||||
|
||||
void RegisterSkiaExtensions(uintptr_t extensionListAddr);
|
||||
} // VideoProcessingEngine
|
||||
} // Media
|
||||
} // OHOS
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
#include <chrono>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "detail_enhancer_extension.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "vpe_log.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Media::VideoProcessingEngine;
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace VideoProcessingEngine {
|
||||
|
||||
namespace {
|
||||
enum ImageFormatType {
|
||||
@@ -80,19 +84,19 @@ SkColorType GetRGBImageFormat(const sptr<SurfaceBuffer>& surfaceBuffer)
|
||||
return imageFormat;
|
||||
}
|
||||
|
||||
AlgoErrorCode PixmapScale(const SkPixmap& inputPixmap, SkPixmap& outputPixmap, SkSamplingOptions options)
|
||||
VPEAlgoErrCode PixmapScale(const SkPixmap& inputPixmap, SkPixmap& outputPixmap, SkSamplingOptions options)
|
||||
{
|
||||
if (!inputPixmap.scalePixels(outputPixmap, options)) {
|
||||
return ALGO_ERROR_PROCESS_FAILED;
|
||||
return VPE_ALGO_ERR_EXTENSION_PROCESS_FAILED;
|
||||
}
|
||||
return ALGO_SUCCESS;
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
|
||||
AlgoErrorCode RGBScale(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output)
|
||||
VPEAlgoErrCode RGBScale(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output)
|
||||
{
|
||||
if (input->GetWidth() <= 0 || input->GetHeight() <= 0 || output->GetWidth() <= 0 || output->GetHeight() <= 0) {
|
||||
VPE_LOGE("Invalid input or output size!");
|
||||
return ALGO_ERROR_INVALID_VALUE;
|
||||
return VPE_ALGO_ERR_INVALID_VAL;
|
||||
}
|
||||
SkImageInfo inputInfo = SkImageInfo::Make(input->GetWidth(), input->GetHeight(), GetRGBImageFormat(input),
|
||||
kPremul_SkAlphaType);
|
||||
@@ -199,19 +203,19 @@ int CreateYUVPixmap(const sptr<SurfaceBuffer>& buffer, std::array<SkPixmap, SkYU
|
||||
return numPlanes;
|
||||
}
|
||||
|
||||
AlgoErrorCode YUVPixmapScale(const std::array<SkPixmap, SkYUVAInfo::kMaxPlanes>& inputPixmap,
|
||||
VPEAlgoErrCode YUVPixmapScale(const std::array<SkPixmap, SkYUVAInfo::kMaxPlanes>& inputPixmap,
|
||||
std::array<SkPixmap, SkYUVAInfo::kMaxPlanes>& outputPixmap, SkSamplingOptions opt, int numPlanes)
|
||||
{
|
||||
for (int i = 0; i < numPlanes; i++) {
|
||||
if (!inputPixmap[i].scalePixels(outputPixmap[i], opt)) {
|
||||
VPE_LOGE("YUV scale failed!");
|
||||
return ALGO_ERROR_PROCESS_FAILED;
|
||||
return VPE_ALGO_ERR_EXTENSION_PROCESS_FAILED;
|
||||
}
|
||||
}
|
||||
return ALGO_SUCCESS;
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
|
||||
AlgoErrorCode YUVScale(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output)
|
||||
VPEAlgoErrCode YUVScale(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output)
|
||||
{
|
||||
std::array<SkPixmap, SkYUVAInfo::kMaxPlanes> inputPixmap;
|
||||
std::array<SkPixmap, SkYUVAInfo::kMaxPlanes> outputPixmap;
|
||||
@@ -219,16 +223,48 @@ AlgoErrorCode YUVScale(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& ou
|
||||
int numPlanesOutput = CreateYUVPixmap(output, outputPixmap);
|
||||
if (numPlanesInput != numPlanesOutput || numPlanesInput * numPlanesOutput == 0) {
|
||||
VPE_LOGE("Wrong YUV settings!");
|
||||
return ALGO_ERROR_INVALID_VALUE;
|
||||
return VPE_ALGO_ERR_INVALID_VAL;
|
||||
}
|
||||
SkSamplingOptions scaleOption(SkFilterMode::kNearest);
|
||||
return YUVPixmapScale(inputPixmap, outputPixmap, scaleOption, numPlanesInput);
|
||||
}
|
||||
|
||||
constexpr OHOS::Media::VideoProcessingEngine::Extension::Rank RANK = OHOS::Media::VideoProcessingEngine::Extension::Rank::RANK_DEFAULT;
|
||||
constexpr uint32_t VERSION = 0;
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<DetailEnhancerBase> Skia::Create()
|
||||
{
|
||||
return std::make_unique<Skia>();
|
||||
}
|
||||
|
||||
AlgoErrorCode Skia::Process(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output)
|
||||
DetailEnhancerCapability Skia::BuildCapabilities()
|
||||
{
|
||||
AlgoErrorCode errCode;
|
||||
std::vector<uint32_t> levels = { DETAIL_ENH_LEVEL_NONE, DETAIL_ENH_LEVEL_LOW, DETAIL_ENH_LEVEL_MEDIUM,
|
||||
DETAIL_ENH_LEVEL_HIGH_EVE, DETAIL_ENH_LEVEL_HIGH_AISR, DETAIL_ENH_LEVEL_VIDEO};
|
||||
DetailEnhancerCapability capability = { levels, RANK, VERSION };
|
||||
return capability;
|
||||
}
|
||||
|
||||
VPEAlgoErrCode Skia::Init()
|
||||
{
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
|
||||
VPEAlgoErrCode Skia::Deinit()
|
||||
{
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
|
||||
VPEAlgoErrCode Skia::SetParameter([[maybe_unused]] const DetailEnhancerParameters& parameter,
|
||||
[[maybe_unused]] int type, [[maybe_unused]] bool flag)
|
||||
{
|
||||
return VPE_ALGO_ERR_OK;
|
||||
}
|
||||
|
||||
VPEAlgoErrCode Skia::Process(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output)
|
||||
{
|
||||
VPEAlgoErrCode errCode;
|
||||
ImageFormatType imageType = GetImageType(input, output);
|
||||
if (imageType == IMAGE_FORMAT_TYPE_RGB) {
|
||||
errCode = RGBScale(input, output);
|
||||
@@ -236,7 +272,29 @@ AlgoErrorCode Skia::Process(const sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer
|
||||
errCode = YUVScale(input, output);
|
||||
} else {
|
||||
VPE_LOGE("Unknown image format!");
|
||||
errCode = ALGO_ERROR_INVALID_VALUE;
|
||||
errCode = VPE_ALGO_ERR_INVALID_VAL;
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<std::shared_ptr<Extension::ExtensionBase>> RegisterExtensions()
|
||||
{
|
||||
std::vector<std::shared_ptr<Extension::ExtensionBase>> extensions;
|
||||
|
||||
auto extension = std::make_shared<Extension::DetailEnhancerExtension>();
|
||||
CHECK_AND_RETURN_RET_LOG(extension != nullptr, extensions, "null pointer");
|
||||
extension->info = { Extension::ExtensionType::DETAIL_ENHANCER, "SKIA", "0.0.1" };
|
||||
extension->creator = Skia::Create;
|
||||
extension->capabilitiesBuilder = Skia::BuildCapabilities;
|
||||
extensions.push_back(std::static_pointer_cast<Extension::ExtensionBase>(extension));
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
void RegisterSkiaExtensions(uintptr_t extensionListAddr)
|
||||
{
|
||||
Extension::DoRegisterExtensions(extensionListAddr, RegisterExtensions);
|
||||
}
|
||||
} // VideoProcessingEngine
|
||||
} // Media
|
||||
} // OHOS
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include "frame_info.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -26,7 +27,7 @@ namespace VideoProcessingEngine {
|
||||
struct MetadataGeneratorCapability {
|
||||
ColorSpaceDescription colorspaceDesc;
|
||||
std::vector<GraphicPixelFormat> pixelFormats;
|
||||
uint32_t rank;
|
||||
Extension::Rank rank;
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user